diff options
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 12 | ||||
-rw-r--r-- | etherpad/src/etherpad/collab/ace/contentcollector.js | 509 | ||||
-rw-r--r-- | etherpad/src/etherpad/collab/ace/domline.js | 210 | ||||
-rw-r--r-- | etherpad/src/etherpad/collab/ace/easysync1.js | 923 | ||||
-rw-r--r-- | etherpad/src/etherpad/collab/ace/easysync2.js | 1968 | ||||
-rw-r--r-- | etherpad/src/etherpad/collab/ace/easysync2_tests.js | 877 | ||||
-rw-r--r-- | etherpad/src/etherpad/collab/ace/linestylefilter.js | 247 | ||||
-rw-r--r-- | etherpad/src/static/js/ace.js | 29 | ||||
-rw-r--r-- | etherpad/src/static/js/colorutils.js | 91 | ||||
-rw-r--r-- | etherpad/src/static/js/cssmanager_client.js | 88 | ||||
-rw-r--r-- | etherpad/src/static/js/domline_client.js | 210 | ||||
-rw-r--r-- | etherpad/src/static/js/easysync2_client.js | 1777 | ||||
-rw-r--r-- | etherpad/src/static/js/linestylefilter_client.js | 246 |
13 files changed, 12 insertions, 7175 deletions
@@ -1 +1,13 @@ *~ +etherpad/src/etherpad/collab/ace/contentcollector.js +etherpad/src/etherpad/collab/ace/domline.js +etherpad/src/etherpad/collab/ace/easysync1.js +etherpad/src/etherpad/collab/ace/easysync2.js +etherpad/src/etherpad/collab/ace/easysync2_tests.js +etherpad/src/etherpad/collab/ace/linestylefilter.js +etherpad/src/static/js/ace.js +etherpad/src/static/js/colorutils.js +etherpad/src/static/js/cssmanager_client.js +etherpad/src/static/js/domline_client.js +etherpad/src/static/js/easysync2_client.js +etherpad/src/static/js/linestylefilter_client.js diff --git a/etherpad/src/etherpad/collab/ace/contentcollector.js b/etherpad/src/etherpad/collab/ace/contentcollector.js deleted file mode 100644 index 22e552a..0000000 --- a/etherpad/src/etherpad/collab/ace/contentcollector.js +++ /dev/null @@ -1,509 +0,0 @@ -// DO NOT EDIT THIS FILE, edit infrastructure/ace/www/contentcollector.js -import("etherpad.collab.ace.easysync2.Changeset") - -/** - * Copyright 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -var _MAX_LIST_LEVEL = 8; - -function sanitizeUnicode(s) { - return s.replace(/[\uffff\ufffe\ufeff\ufdd0-\ufdef\ud800-\udfff]/g, '?'); -} - -function makeContentCollector(collectStyles, browser, apool, domInterface, - className2Author) { - browser = browser || {}; - - var dom = domInterface || { - isNodeText: function(n) { - return (n.nodeType == 3); - }, - nodeTagName: function(n) { - return n.tagName; - }, - nodeValue: function(n) { - return n.nodeValue; - }, - nodeNumChildren: function(n) { - return n.childNodes.length; - }, - nodeChild: function(n, i) { - return n.childNodes.item(i); - }, - nodeProp: function(n, p) { - return n[p]; - }, - nodeAttr: function(n, a) { - return n.getAttribute(a); - }, - optNodeInnerHTML: function(n) { - return n.innerHTML; - } - }; - - var _blockElems = { "div":1, "p":1, "pre":1, "li":1 }; - function isBlockElement(n) { - return !!_blockElems[(dom.nodeTagName(n) || "").toLowerCase()]; - } - function textify(str) { - return sanitizeUnicode( - str.replace(/[\n\r ]/g, ' ').replace(/\xa0/g, ' ').replace(/\t/g, ' ')); - } - function getAssoc(node, name) { - return dom.nodeProp(node, "_magicdom_"+name); - } - - var lines = (function() { - var textArray = []; - var attribsArray = []; - var attribsBuilder = null; - var op = Changeset.newOp('+'); - var self = { - length: function() { return textArray.length; }, - atColumnZero: function() { - return textArray[textArray.length-1] === ""; - }, - startNew: function() { - textArray.push(""); - self.flush(true); - attribsBuilder = Changeset.smartOpAssembler(); - }, - textOfLine: function(i) { return textArray[i]; }, - appendText: function(txt, attrString) { - textArray[textArray.length-1] += txt; - //dmesg(txt+" / "+attrString); - op.attribs = attrString; - op.chars = txt.length; - attribsBuilder.append(op); - }, - textLines: function() { return textArray.slice(); }, - attribLines: function() { return attribsArray; }, - // call flush only when you're done - flush: function(withNewline) { - if (attribsBuilder) { - attribsArray.push(attribsBuilder.toString()); - attribsBuilder = null; - } - } - }; - self.startNew(); - return self; - }()); - var cc = {}; - function _ensureColumnZero(state) { - if (! lines.atColumnZero()) { - _startNewLine(state); - } - } - var selection, startPoint, endPoint; - var selStart = [-1,-1], selEnd = [-1,-1]; - var blockElems = { "div":1, "p":1, "pre":1 }; - function _isEmpty(node, state) { - // consider clean blank lines pasted in IE to be empty - if (dom.nodeNumChildren(node) == 0) return true; - if (dom.nodeNumChildren(node) == 1 && - getAssoc(node, "shouldBeEmpty") && dom.optNodeInnerHTML(node) == " " - && ! getAssoc(node, "unpasted")) { - if (state) { - var child = dom.nodeChild(node, 0); - _reachPoint(child, 0, state); - _reachPoint(child, 1, state); - } - return true; - } - return false; - } - function _pointHere(charsAfter, state) { - var ln = lines.length()-1; - var chr = lines.textOfLine(ln).length; - if (chr == 0 && state.listType && state.listType != 'none') { - chr += 1; // listMarker - } - chr += charsAfter; - return [ln, chr]; - } - function _reachBlockPoint(nd, idx, state) { - if (! dom.isNodeText(nd)) _reachPoint(nd, idx, state); - } - function _reachPoint(nd, idx, state) { - if (startPoint && nd == startPoint.node && startPoint.index == idx) { - selStart = _pointHere(0, state); - } - if (endPoint && nd == endPoint.node && endPoint.index == idx) { - selEnd = _pointHere(0, state); - } - } - function _incrementFlag(state, flagName) { - state.flags[flagName] = (state.flags[flagName] || 0)+1; - } - function _decrementFlag(state, flagName) { - state.flags[flagName]--; - } - function _incrementAttrib(state, attribName) { - if (! state.attribs[attribName]) { - state.attribs[attribName] = 1; - } - else { - state.attribs[attribName]++; - } - _recalcAttribString(state); - } - function _decrementAttrib(state, attribName) { - state.attribs[attribName]--; - _recalcAttribString(state); - } - function _enterList(state, listType) { - var oldListType = state.listType; - state.listLevel = (state.listLevel || 0)+1; - if (listType != 'none') { - state.listNesting = (state.listNesting || 0)+1; - } - state.listType = listType; - _recalcAttribString(state); - return oldListType; - } - function _exitList(state, oldListType) { - state.listLevel--; - if (state.listType != 'none') { - state.listNesting--; - } - state.listType = oldListType; - _recalcAttribString(state); - } - function _enterAuthor(state, author) { - var oldAuthor = state.author; - state.authorLevel = (state.authorLevel || 0)+1; - state.author = author; - _recalcAttribString(state); - return oldAuthor; - } - function _exitAuthor(state, oldAuthor) { - state.authorLevel--; - state.author = oldAuthor; - _recalcAttribString(state); - } - function _recalcAttribString(state) { - var lst = []; - for(var a in state.attribs) { - if (state.attribs[a]) { - lst.push([a,'true']); - } - } - if (state.authorLevel > 0) { - var authorAttrib = ['author', state.author]; - if (apool.putAttrib(authorAttrib, true) >= 0) { - // require that author already be in pool - // (don't add authors from other documents, etc.) - lst.push(authorAttrib); - } - } - state.attribString = Changeset.makeAttribsString('+', lst, apool); - } - function _produceListMarker(state) { - lines.appendText('*', Changeset.makeAttribsString( - '+', [['list', state.listType], - ['insertorder', 'first']], - apool)); - } - function _startNewLine(state) { - if (state) { - var atBeginningOfLine = lines.textOfLine(lines.length()-1).length == 0; - if (atBeginningOfLine && state.listType && state.listType != 'none') { - _produceListMarker(state); - } - } - lines.startNew(); - } - cc.notifySelection = function (sel) { - if (sel) { - selection = sel; - startPoint = selection.startPoint; - endPoint = selection.endPoint; - } - }; - cc.collectContent = function (node, state) { - if (! state) { - state = {flags: {/*name -> nesting counter*/}, - attribs: {/*name -> nesting counter*/}, - attribString: ''}; - } - var isBlock = isBlockElement(node); - var isEmpty = _isEmpty(node, state); - if (isBlock) _ensureColumnZero(state); - var startLine = lines.length()-1; - _reachBlockPoint(node, 0, state); - if (dom.isNodeText(node)) { - var txt = dom.nodeValue(node); - var rest = ''; - var x = 0; // offset into original text - if (txt.length == 0) { - if (startPoint && node == startPoint.node) { - selStart = _pointHere(0, state); - } - if (endPoint && node == endPoint.node) { - selEnd = _pointHere(0, state); - } - } - while (txt.length > 0) { - var consumed = 0; - if (state.flags.preMode) { - var firstLine = txt.split('\n',1)[0]; - consumed = firstLine.length+1; - rest = txt.substring(consumed); - txt = firstLine; - } - else { /* will only run this loop body once */ } - if (startPoint && node == startPoint.node && - startPoint.index-x <= txt.length) { - selStart = _pointHere(startPoint.index-x, state); - } - if (endPoint && node == endPoint.node && - endPoint.index-x <= txt.length) { - selEnd = _pointHere(endPoint.index-x, state); - } - var txt2 = txt; - if ((! state.flags.preMode) && /^[\r\n]*$/.exec(txt)) { - // prevents textnodes containing just "\n" from being significant - // in safari when pasting text, now that we convert them to - // spaces instead of removing them, because in other cases - // removing "\n" from pasted HTML will collapse words together. - txt2 = ""; - } - var atBeginningOfLine = lines.textOfLine(lines.length()-1).length == 0; - if (atBeginningOfLine) { - // newlines in the source mustn't become spaces at beginning of line box - txt2 = txt2.replace(/^\n*/, ''); - } - if (atBeginningOfLine && state.listType && state.listType != 'none') { - _produceListMarker(state); - } - lines.appendText(textify(txt2), state.attribString); - x += consumed; - txt = rest; - if (txt.length > 0) { - _startNewLine(state); - } - } - } - else { - var tname = (dom.nodeTagName(node) || "").toLowerCase(); - if (tname == "br") { - _startNewLine(state); - } - else if (tname == "script" || tname == "style") { - // ignore - } - else if (! isEmpty) { - var styl = dom.nodeAttr(node, "style"); - var cls = dom.nodeProp(node, "className"); - - var isPre = (tname == "pre"); - if ((! isPre) && browser.safari) { - isPre = (styl && /\bwhite-space:\s*pre\b/i.exec(styl)); - } - if (isPre) _incrementFlag(state, 'preMode'); - var attribs = null; - var oldListTypeOrNull = null; - var oldAuthorOrNull = null; - if (collectStyles) { - function doAttrib(na) { - attribs = (attribs || []); - attribs.push(na); - _incrementAttrib(state, na); - } - if (tname == "b" || (styl && /\bfont-weight:\s*bold\b/i.exec(styl)) || - tname == "strong") { - doAttrib("bold"); - } - if (tname == "i" || (styl && /\bfont-style:\s*italic\b/i.exec(styl)) || - tname == "em") { - doAttrib("italic"); - } - if (tname == "u" || (styl && /\btext-decoration:\s*underline\b/i.exec(styl)) || - tname == "ins") { - doAttrib("underline"); - } - if (tname == "s" || (styl && /\btext-decoration:\s*line-through\b/i.exec(styl)) || - tname == "del") { - doAttrib("strikethrough"); - } - if (tname == "ul") { - var type; - var rr = cls && /(?:^| )list-(bullet[12345678])\b/.exec(cls); - type = rr && rr[1] || "bullet"+ - String(Math.min(_MAX_LIST_LEVEL, (state.listNesting||0)+1)); - oldListTypeOrNull = (_enterList(state, type) || 'none'); - } - else if ((tname == "div" || tname == "p") && cls && - cls.match(/(?:^| )ace-line\b/)) { - oldListTypeOrNull = (_enterList(state, type) || 'none'); - } - if (className2Author && cls) { - var classes = cls.match(/\S+/g); - if (classes && classes.length > 0) { - for(var i=0;i<classes.length;i++) { - var c = classes[i]; - var a = className2Author(c); - if (a) { - oldAuthorOrNull = (_enterAuthor(state, a) || 'none'); - break; - } - } - } - } - } - - var nc = dom.nodeNumChildren(node); - for(var i=0;i<nc;i++) { - var c = dom.nodeChild(node, i); - cc.collectContent(c, state); - } - - if (isPre) _decrementFlag(state, 'preMode'); - if (attribs) { - for(var i=0;i<attribs.length;i++) { - _decrementAttrib(state, attribs[i]); - } - } - if (oldListTypeOrNull) { - _exitList(state, oldListTypeOrNull); - } - if (oldAuthorOrNull) { - _exitAuthor(state, oldAuthorOrNull); - } - } - } - if (! browser.msie) { - _reachBlockPoint(node, 1, state); - } - if (isBlock) { - if (lines.length()-1 == startLine) { - _startNewLine(state); - } - else { - _ensureColumnZero(state); - } - } - - if (browser.msie) { - // in IE, a point immediately after a DIV appears on the next line - _reachBlockPoint(node, 1, state); - } - }; - // can pass a falsy value for end of doc - cc.notifyNextNode = function (node) { - // an "empty block" won't end a line; this addresses an issue in IE with - // typing into a blank line at the end of the document. typed text - // goes into the body, and the empty line div still looks clean. - // it is incorporated as dirty by the rule that a dirty region has - // to end a line. - if ((!node) || (isBlockElement(node) && !_isEmpty(node))) { - _ensureColumnZero(null); - } - }; - // each returns [line, char] or [-1,-1] - var getSelectionStart = function() { return selStart; }; - var getSelectionEnd = function() { return selEnd; }; - - // returns array of strings for lines found, last entry will be "" if - // last line is complete (i.e. if a following span should be on a new line). - // can be called at any point - cc.getLines = function() { return lines.textLines(); }; - - //cc.applyHints = function(hints) { - //if (hints.pastedLines) { - // - //} - //} - - cc.finish = function() { - lines.flush(); - var lineAttribs = lines.attribLines(); - var lineStrings = cc.getLines(); - - lineStrings.length--; - lineAttribs.length--; - - var ss = getSelectionStart(); - var se = getSelectionEnd(); - - function fixLongLines() { - // design mode does not deal with with really long lines! - var lineLimit = 2000; // chars - var buffer = 10; // chars allowed over before wrapping - var linesWrapped = 0; - var numLinesAfter = 0; - for(var i=lineStrings.length-1; i>=0; i--) { - var oldString = lineStrings[i]; - var oldAttribString = lineAttribs[i]; - if (oldString.length > lineLimit+buffer) { - var newStrings = []; - var newAttribStrings = []; - while (oldString.length > lineLimit) { - //var semiloc = oldString.lastIndexOf(';', lineLimit-1); - //var lengthToTake = (semiloc >= 0 ? (semiloc+1) : lineLimit); - lengthToTake = lineLimit; - newStrings.push(oldString.substring(0, lengthToTake)); - oldString = oldString.substring(lengthToTake); - newAttribStrings.push(Changeset.subattribution(oldAttribString, - 0, lengthToTake)); - oldAttribString = Changeset.subattribution(oldAttribString, - lengthToTake); - } - if (oldString.length > 0) { - newStrings.push(oldString); - newAttribStrings.push(oldAttribString); - } - function fixLineNumber(lineChar) { - if (lineChar[0] < 0) return; - var n = lineChar[0]; - var c = lineChar[1]; - if (n > i) { - n += (newStrings.length-1); - } - else if (n == i) { - var a = 0; - while (c > newStrings[a].length) { - c -= newStrings[a].length; - a++; - } - n += a; - } - lineChar[0] = n; - lineChar[1] = c; - } - fixLineNumber(ss); - fixLineNumber(se); - linesWrapped++; - numLinesAfter += newStrings.length; - - newStrings.unshift(i, 1); - lineStrings.splice.apply(lineStrings, newStrings); - newAttribStrings.unshift(i, 1); - lineAttribs.splice.apply(lineAttribs, newAttribStrings); - } - } - return {linesWrapped:linesWrapped, numLinesAfter:numLinesAfter}; - } - var wrapData = fixLongLines(); - - return { selStart: ss, selEnd: se, linesWrapped: wrapData.linesWrapped, - numLinesAfter: wrapData.numLinesAfter, - lines: lineStrings, lineAttribs: lineAttribs }; - } - - return cc; -} diff --git a/etherpad/src/etherpad/collab/ace/domline.js b/etherpad/src/etherpad/collab/ace/domline.js deleted file mode 100644 index de2e7d3..0000000 --- a/etherpad/src/etherpad/collab/ace/domline.js +++ /dev/null @@ -1,210 +0,0 @@ -// DO NOT EDIT THIS FILE, edit infrastructure/ace/www/domline.js - -/** - * Copyright 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -var domline = {}; -domline.noop = function() {}; -domline.identity = function(x) { return x; }; - -domline.addToLineClass = function(lineClass, cls) { - // an "empty span" at any point can be used to add classes to - // the line, using line:className. otherwise, we ignore - // the span. - cls.replace(/\S+/g, function (c) { - if (c.indexOf("line:") == 0) { - // add class to line - lineClass = (lineClass ? lineClass+' ' : '')+c.substring(5); - } - }); - return lineClass; -} - -// if "document" is falsy we don't create a DOM node, just -// an object with innerHTML and className -domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) { - var result = { node: null, - appendSpan: domline.noop, - prepareForAdd: domline.noop, - notifyAdded: domline.noop, - clearSpans: domline.noop, - finishUpdate: domline.noop, - lineMarker: 0 }; - - var browser = (optBrowser || {}); - var document = optDocument; - - if (document) { - result.node = document.createElement("div"); - } - else { - result.node = {innerHTML: '', className: ''}; - } - - var html = []; - var preHtml, postHtml; - var curHTML = null; - function processSpaces(s) { - return domline.processSpaces(s, doesWrap); - } - var identity = domline.identity; - var perTextNodeProcess = (doesWrap ? identity : processSpaces); - var perHtmlLineProcess = (doesWrap ? processSpaces : identity); - var lineClass = 'ace-line'; - result.appendSpan = function(txt, cls) { - if (cls.indexOf('list') >= 0) { - var listType = /(?:^| )list:(\S+)/.exec(cls); - if (listType) { - listType = listType[1]; - if (listType) { - preHtml = '<ul class="list-'+listType+'"><li>'; - postHtml = '</li></ul>'; - } - result.lineMarker += txt.length; - return; // don't append any text - } - } - var href = null; - var simpleTags = null; - if (cls.indexOf('url') >= 0) { - cls = cls.replace(/(^| )url:(\S+)/g, function(x0, space, url) { - href = url; - return space+"url"; - }); - } - if (cls.indexOf('tag') >= 0) { - cls = cls.replace(/(^| )tag:(\S+)/g, function(x0, space, tag) { - if (! simpleTags) simpleTags = []; - simpleTags.push(tag.toLowerCase()); - return space+tag; - }); - } - if ((! txt) && cls) { - lineClass = domline.addToLineClass(lineClass, cls); - } - else if (txt) { - var extraOpenTags = ""; - var extraCloseTags = ""; - if (href) { - extraOpenTags = extraOpenTags+'<a href="'+ - href.replace(/\"/g, '"')+'">'; - extraCloseTags = '</a>'+extraCloseTags; - } - if (simpleTags) { - simpleTags.sort(); - extraOpenTags = extraOpenTags+'<'+simpleTags.join('><')+'>'; - simpleTags.reverse(); - extraCloseTags = '</'+simpleTags.join('></')+'>'+extraCloseTags; - } - html.push('<span class="',cls||'','">',extraOpenTags, - perTextNodeProcess(domline.escapeHTML(txt)), - extraCloseTags,'</span>'); - } - }; - result.clearSpans = function() { - html = []; - lineClass = ''; // non-null to cause update - result.lineMarker = 0; - }; - function writeHTML() { - var newHTML = perHtmlLineProcess(html.join('')); - if (! newHTML) { - if ((! document) || (! optBrowser)) { - newHTML += ' '; - } - else if (! browser.msie) { - newHTML += '<br/>'; - } - } - if (nonEmpty) { - newHTML = (preHtml||'')+newHTML+(postHtml||''); - } - html = preHtml = postHtml = null; // free memory - if (newHTML !== curHTML) { - curHTML = newHTML; - result.node.innerHTML = curHTML; - } - if (lineClass !== null) result.node.className = lineClass; - } - result.prepareForAdd = writeHTML; - result.finishUpdate = writeHTML; - result.getInnerHTML = function() { return curHTML || ''; }; - - return result; -}; - -domline.escapeHTML = function(s) { - var re = /[&<>'"]/g; /']/; // stupid indentation thing - if (! re.MAP) { - // persisted across function calls! - re.MAP = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' - }; - } - return s.replace(re, function(c) { return re.MAP[c]; }); -}; - -domline.processSpaces = function(s, doesWrap) { - if (s.indexOf("<") < 0 && ! doesWrap) { - // short-cut - return s.replace(/ /g, ' '); - } - var parts = []; - s.replace(/<[^>]*>?| |[^ <]+/g, function(m) { parts.push(m); }); - if (doesWrap) { - var endOfLine = true; - var beforeSpace = false; - // last space in a run is normal, others are nbsp, - // end of line is nbsp - for(var i=parts.length-1;i>=0;i--) { - var p = parts[i]; - if (p == " ") { - if (endOfLine || beforeSpace) - parts[i] = ' '; - endOfLine = false; - beforeSpace = true; - } - else if (p.charAt(0) != "<") { - endOfLine = false; - beforeSpace = false; - } - } - // beginning of line is nbsp - for(var i=0;i<parts.length;i++) { - var p = parts[i]; - if (p == " ") { - parts[i] = ' '; - break; - } - else if (p.charAt(0) != "<") { - break; - } - } - } - else { - for(var i=0;i<parts.length;i++) { - var p = parts[i]; - if (p == " ") { - parts[i] = ' '; - } - } - } - return parts.join(''); -}; diff --git a/etherpad/src/etherpad/collab/ace/easysync1.js b/etherpad/src/etherpad/collab/ace/easysync1.js deleted file mode 100644 index 4f40aa0..0000000 --- a/etherpad/src/etherpad/collab/ace/easysync1.js +++ /dev/null @@ -1,923 +0,0 @@ -// DO NOT EDIT THIS FILE, edit infrastructure/ace/www/easy_sync.js - -/** - * Copyright 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -function Changeset(arg) { - - var array; - if ((typeof arg) == "string") { - // constant - array = [Changeset.MAGIC, 0, arg.length, 0, 0, arg]; - } - else if ((typeof arg) == "number") { - var n = Math.round(arg); - // delete-all on n-length text (useful for making a "builder") - array = [Changeset.MAGIC, n, 0, 0, 0, ""]; - } - else if (! arg) { - // identity on 0-length text - array = [Changeset.MAGIC, 0, 0, 0, 0, ""]; - } - else if (arg.isChangeset) { - return arg; - } - else array = arg; - - array.isChangeset = true; - - // OOP style: attach generic methods to array object, hold no state in environment - - //function error(msg) { top.console.error(msg); top.console.trace(); } - function error(msg) { var e = new Error(msg); e.easysync = true; throw e; } - function assert(b, msg) { if (! b) error("Changeset: "+String(msg)); } - function min(x, y) { return (x < y) ? x : y; } - Changeset._assert = assert; - - array.isIdentity = function() { - return this.length == 6 && this[1] == this[2] && this[3] == 0 && - this[4] == this[1] && this[5] == ""; - } - - array.eachStrip = function(func, thisObj) { - // inside "func", the method receiver will be "this" by default, - // or you can pass an object. - for(var i=0;i<this.numStrips();i++) { - var ptr = 3 + i*3; - if (func.call(thisObj || this, this[ptr], this[ptr+1], this[ptr+2], i)) - return true; - } - return false; - } - - array.numStrips = function() { return (this.length-3)/3; }; - array.oldLen = function() { return this[1]; }; - array.newLen = function() { return this[2]; }; - - array.checkRep = function() { - assert(this[0] == Changeset.MAGIC, "bad magic"); - assert(this[1] >= 0, "bad old text length"); - assert(this[2] >= 0, "bad new text length"); - assert((this.length % 3) == 0, "bad array length"); - assert(this.length >= 6, "must be at least one strip"); - var numStrips = this.numStrips(); - var oldLen = this[1]; - var newLen = this[2]; - // iterate over the "text strips" - var actualNewLen = 0; - this.eachStrip(function(startIndex, numTaken, newText, i) { - var s = startIndex, t = numTaken, n = newText; - var isFirst = (i == 0); - var isLast = (i == numStrips-1); - assert(t >= 0, "can't take negative number of chars"); - assert(isFirst || t > 0, "all strips but first must take"); - assert((t > 0) || (s == 0), "if first strip doesn't take, must have 0 startIndex"); - assert(s >= 0 && s + t <= oldLen, "bad index: "+this.toString()); - assert(t > 0 || n.length > 0 || (isFirst && isLast), "empty strip must be first and only"); - if (! isLast) { - var s2 = this[3 + i*3 + 3]; // startIndex of following strip - var gap = s2 - (s + t); - assert(gap >= 0, "overlapping or out-of-order strips: "+this.toString()); - assert(gap > 0 || n.length > 0, "touching strips with no added text"); - } - actualNewLen += t + n.length; - }); - assert(newLen == actualNewLen, "calculated new text length doesn't match"); - } - - array.applyToText = function(text) { - assert(text.length == this.oldLen(), "mismatched apply: "+text.length+" / "+this.oldLen()); - var buf = []; - this.eachStrip(function (s, t, n) { - buf.push(text.substr(s, t), n); - }); - return buf.join(''); - } - - function _makeBuilder(oldLen, supportAuthors) { - var C = Changeset(oldLen); - if (supportAuthors) { - _ensureAuthors(C); - } - return C.builder(); - } - - function _getNumInserted(C) { - var numChars = 0; - C.eachStrip(function(s,t,n) { - numChars += n.length; - }); - return numChars; - } - - function _ensureAuthors(C) { - if (! C.authors) { - C.setAuthor(); - } - return C; - } - - array.setAuthor = function(author) { - var C = this; - // authors array has even length >= 2; - // alternates [numChars1, author1, numChars2, author2]; - // all numChars > 0 unless there is exactly one, in which - // case it can be == 0. - C.authors = [_getNumInserted(C), author || '']; - return C; - } - - array.builder = function() { - // normal pattern is Changeset(oldLength).builder().appendOldText(...). ... - // builder methods mutate this! - var C = this; - // OOP style: state in environment - var self; - return self = { - appendNewText: function(str, author) { - C[C.length-1] += str; - C[2] += str.length; - - if (C.authors) { - var a = (author || ''); - var lastAuthorPtr = C.authors.length-1; - var lastAuthorLengthPtr = C.authors.length-2; - if ((!a) || a == C.authors[lastAuthorPtr]) { - C.authors[lastAuthorLengthPtr] += str.length; - } - else if (0 == C.authors[lastAuthorLengthPtr]) { - C.authors[lastAuthorLengthPtr] = str.length; - C.authors[lastAuthorPtr] = (a || C.authors[lastAuthorPtr]); - } - else { - C.authors.push(str.length, a); - } - } - - return self; - }, - appendOldText: function(startIndex, numTaken) { - if (numTaken == 0) return self; - // properties of last strip... - var s = C[C.length-3], t = C[C.length-2], n = C[C.length-1]; - if (t == 0 && n == "") { - // must be empty changeset, one strip that doesn't take old chars or add new ones - C[C.length-3] = startIndex; - C[C.length-2] = numTaken; - } - else if (n == "" && (s+t == startIndex)) { - C[C.length-2] += numTaken; // take more - } - else C.push(startIndex, numTaken, ""); // add a strip - C[2] += numTaken; - C.checkRep(); - return self; - }, - toChangeset: function() { return C; } - }; - } - - array.authorSlicer = function(outputBuilder) { - return _makeAuthorSlicer(this, outputBuilder); - } - - function _makeAuthorSlicer(changesetOrAuthorsIn, builderOut) { - // "builderOut" only needs to support appendNewText - var authors; // considered immutable - if (changesetOrAuthorsIn.isChangeset) { - authors = changesetOrAuthorsIn.authors; - } - else { - authors = changesetOrAuthorsIn; - } - - // OOP style: state in environment - var authorPtr = 0; - var charIndex = 0; - var charWithinAuthor = 0; // 0 <= charWithinAuthor <= authors[authorPtr]; max value iff atEnd - var atEnd = false; - function curAuthor() { return authors[authorPtr+1]; } - function curAuthorWidth() { return authors[authorPtr]; } - function assertNotAtEnd() { assert(! atEnd, "_authorSlicer: can't move past end"); } - function forwardInAuthor(numChars) { - charWithinAuthor += numChars; - charIndex += numChars; - } - function nextAuthor() { - assertNotAtEnd(); - assert(charWithinAuthor == curAuthorWidth(), "_authorSlicer: not at author end"); - charWithinAuthor = 0; - authorPtr += 2; - if (authorPtr == authors.length) { - atEnd = true; - } - } - - var self; - return self = { - skipChars: function(n) { - assert(n >= 0, "_authorSlicer: can't skip negative n"); - if (n == 0) return; - assertNotAtEnd(); - - var leftToSkip = n; - while (leftToSkip > 0) { - var leftInAuthor = curAuthorWidth() - charWithinAuthor; - if (leftToSkip >= leftInAuthor) { - forwardInAuthor(leftInAuthor); - leftToSkip -= leftInAuthor; - nextAuthor(); - } - else { - forwardInAuthor(leftToSkip); - leftToSkip = 0; - } - } - }, - takeChars: function(n, text) { - assert(n >= 0, "_authorSlicer: can't take negative n"); - if (n == 0) return; - assertNotAtEnd(); - assert(n == text.length, "_authorSlicer: bad text length"); - - var textLeft = text; - var leftToTake = n; - while (leftToTake > 0) { - if (curAuthorWidth() > 0 && charWithinAuthor < curAuthorWidth()) { - // at least one char to take from current author - var leftInAuthor = (curAuthorWidth() - charWithinAuthor); - assert(leftInAuthor > 0, "_authorSlicer: should have leftInAuthor > 0"); - var toTake = min(leftInAuthor, leftToTake); - assert(toTake > 0, "_authorSlicer: should have toTake > 0"); - builderOut.appendNewText(textLeft.substring(0, toTake), curAuthor()); - forwardInAuthor(toTake); - leftToTake -= toTake; - textLeft = textLeft.substring(toTake); - } - assert(charWithinAuthor <= curAuthorWidth(), "_authorSlicer: past end of author"); - if (charWithinAuthor == curAuthorWidth()) { - nextAuthor(); - } - } - }, - setBuilder: function(builder) { - builderOut = builder; - } - }; - } - - function _makeSlicer(C, output) { - // C: Changeset, output: builder from _makeBuilder - // C is considered immutable, won't change or be changed - - // OOP style: state in environment - var charIndex = 0; // 0 <= charIndex <= C.newLen(); maximum value iff atEnd - var stripIndex = 0; // 0 <= stripIndex <= C.numStrips(); maximum value iff atEnd - var charWithinStrip = 0; // 0 <= charWithinStrip < curStripWidth() - var atEnd = false; - - var authorSlicer; - if (C.authors) { - authorSlicer = _makeAuthorSlicer(C.authors, output); - } - - var ptr = 3; - function curStartIndex() { return C[ptr]; } - function curNumTaken() { return C[ptr+1]; } - function curNewText() { return C[ptr+2]; } - function curStripWidth() { return curNumTaken() + curNewText().length; } - function assertNotAtEnd() { assert(! atEnd, "_slicer: can't move past changeset end"); } - function forwardInStrip(numChars) { - charWithinStrip += numChars; - charIndex += numChars; - } - function nextStrip() { - assertNotAtEnd(); - assert(charWithinStrip == curStripWidth(), "_slicer: not at strip end"); - charWithinStrip = 0; - stripIndex++; - ptr += 3; - if (stripIndex == C.numStrips()) { - atEnd = true; - } - } - function curNumNewCharsInRange(start, end) { - // takes two indices into the current strip's combined "taken" and "new" - // chars, and returns how many "new" chars are included in the range - assert(start <= end, "_slicer: curNumNewCharsInRange given out-of-order indices"); - var nt = curNumTaken(); - var nn = curNewText().length; - var s = nt; - var e = nt+nn; - if (s < start) s = start; - if (e > end) e = end; - if (e < s) return 0; - return e-s; - } - - var self; - return self = { - skipChars: function (n) { - assert(n >= 0, "_slicer: can't skip negative n"); - if (n == 0) return; - assertNotAtEnd(); - - var leftToSkip = n; - while (leftToSkip > 0) { - var leftInStrip = curStripWidth() - charWithinStrip; - if (leftToSkip >= leftInStrip) { - forwardInStrip(leftInStrip); - - if (authorSlicer) - authorSlicer.skipChars(curNumNewCharsInRange(charWithinStrip, - charWithinStrip + leftInStrip)); - - leftToSkip -= leftInStrip; - nextStrip(); - } - else { - if (authorSlicer) - authorSlicer.skipChars(curNumNewCharsInRange(charWithinStrip, - charWithinStrip + leftToSkip)); - - forwardInStrip(leftToSkip); - leftToSkip = 0; - } - } - }, - takeChars: function (n) { - assert(n >= 0, "_slicer: can't take negative n"); - if (n == 0) return; - assertNotAtEnd(); - - var leftToTake = n; - while (leftToTake > 0) { - if (curNumTaken() > 0 && charWithinStrip < curNumTaken()) { - // at least one char to take from current strip's numTaken - var leftInTaken = (curNumTaken() - charWithinStrip); - assert(leftInTaken > 0, "_slicer: should have leftInTaken > 0"); - var toTake = min(leftInTaken, leftToTake); - assert(toTake > 0, "_slicer: should have toTake > 0"); - output.appendOldText(curStartIndex() + charWithinStrip, toTake); - forwardInStrip(toTake); - leftToTake -= toTake; - } - if (leftToTake > 0 && curNewText().length > 0 && charWithinStrip >= curNumTaken() && - charWithinStrip < curStripWidth()) { - // at least one char to take from current strip's newText - var leftInNewText = (curStripWidth() - charWithinStrip); - assert(leftInNewText > 0, "_slicer: should have leftInNewText > 0"); - var toTake = min(leftInNewText, leftToTake); - assert(toTake > 0, "_slicer: should have toTake > 0"); - var newText = curNewText().substr(charWithinStrip - curNumTaken(), toTake); - if (authorSlicer) { - authorSlicer.takeChars(newText.length, newText); - } - else { - output.appendNewText(newText); - } - forwardInStrip(toTake); - leftToTake -= toTake; - } - assert(charWithinStrip <= curStripWidth(), "_slicer: past end of strip"); - if (charWithinStrip == curStripWidth()) { - nextStrip(); - } - } - }, - skipTo: function(n) { - self.skipChars(n - charIndex); - } - }; - } - - array.slicer = function(outputBuilder) { - return _makeSlicer(this, outputBuilder); - } - - array.compose = function(next) { - assert(next.oldLen() == this.newLen(), "mismatched composition"); - - var builder = _makeBuilder(this.oldLen(), !!(this.authors || next.authors)); - var slicer = _makeSlicer(this, builder); - - var authorSlicer; - if (next.authors) { - authorSlicer = _makeAuthorSlicer(next.authors, builder); - } - - next.eachStrip(function(s, t, n) { - slicer.skipTo(s); - slicer.takeChars(t); - if (authorSlicer) { - authorSlicer.takeChars(n.length, n); - } - else { - builder.appendNewText(n); - } - }, this); - - return builder.toChangeset(); - }; - - array.traverser = function() { - return _makeTraverser(this); - } - - function _makeTraverser(C) { - var s = C[3], t = C[4], n = C[5]; - var nextIndex = 6; - var indexIntoNewText = 0; - - var authorSlicer; - if (C.authors) { - authorSlicer = _makeAuthorSlicer(C.authors, null); - } - - function advanceIfPossible() { - if (t == 0 && n == "" && nextIndex < C.length) { - s = C[nextIndex]; - t = C[nextIndex+1]; - n = C[nextIndex+2]; - nextIndex += 3; - } - } - - var self; - return self = { - numTakenChars: function() { - // if starts with taken characters, then how many, else 0 - return (t > 0) ? t : 0; - }, - numNewChars: function() { - // if starts with new characters, then how many, else 0 - return (t == 0 && n.length > 0) ? n.length : 0; - }, - takenCharsStart: function() { - return (self.numTakenChars() > 0) ? s : 0; - }, - hasMore: function() { - return self.numTakenChars() > 0 || self.numNewChars() > 0; - }, - curIndex: function() { - return indexIntoNewText; - }, - consumeTakenChars: function (x) { - assert(self.numTakenChars() > 0, "_traverser: no taken chars"); - assert(x >= 0 && x <= self.numTakenChars(), "_traverser: bad number of taken chars"); - if (x == 0) return; - if (t == x) { s = 0; t = 0; } - else { s += x; t -= x; } - indexIntoNewText += x; - advanceIfPossible(); - }, - consumeNewChars: function(x) { - return self.appendNewChars(x, null); - }, - appendNewChars: function(x, builder) { - assert(self.numNewChars() > 0, "_traverser: no new chars"); - assert(x >= 0 && x <= self.numNewChars(), "_traverser: bad number of new chars"); - if (x == 0) return ""; - var str = n.substring(0, x); - n = n.substring(x); - indexIntoNewText += x; - advanceIfPossible(); - - if (builder) { - if (authorSlicer) { - authorSlicer.setBuilder(builder); - authorSlicer.takeChars(x, str); - } - else { - builder.appendNewText(str); - } - } - else { - if (authorSlicer) authorSlicer.skipChars(x); - return str; - } - }, - consumeAvailableTakenChars: function() { - return self.consumeTakenChars(self.numTakenChars()); - }, - consumeAvailableNewChars: function() { - return self.consumeNewChars(self.numNewChars()); - }, - appendAvailableNewChars: function(builder) { - return self.appendNewChars(self.numNewChars(), builder); - } - }; - } - - array.follow = function(prev, reverseInsertOrder) { - // prev: Changeset, reverseInsertOrder: boolean - - // A.compose(B.follow(A)) is the merging of Changesets A and B, which operate on the same old text. - // It is always the same as B.compose(A.follow(B, true)). - - assert(prev.oldLen() == this.oldLen(), "mismatched follow: "+prev.oldLen()+"/"+this.oldLen()); - var builder = _makeBuilder(prev.newLen(), !! this.authors); - var a = _makeTraverser(prev); - var b = _makeTraverser(this); - while (a.hasMore() || b.hasMore()) { - if (a.numNewChars() > 0 && ! reverseInsertOrder) { - builder.appendOldText(a.curIndex(), a.numNewChars()); - a.consumeAvailableNewChars(); - } - else if (b.numNewChars() > 0) { - b.appendAvailableNewChars(builder); - } - else if (a.numNewChars() > 0 && reverseInsertOrder) { - builder.appendOldText(a.curIndex(), a.numNewChars()); - a.consumeAvailableNewChars(); - } - else if (! b.hasMore()) a.consumeAvailableTakenChars(); - else if (! a.hasMore()) b.consumeAvailableTakenChars(); - else { - var x = a.takenCharsStart(); - var y = b.takenCharsStart(); - if (x < y) a.consumeTakenChars(min(a.numTakenChars(), y-x)); - else if (y < x) b.consumeTakenChars(min(b.numTakenChars(), x-y)); - else { - var takenByBoth = min(a.numTakenChars(), b.numTakenChars()); - builder.appendOldText(a.curIndex(), takenByBoth); - a.consumeTakenChars(takenByBoth); - b.consumeTakenChars(takenByBoth); - } - } - } - return builder.toChangeset(); - } - - array.encodeToString = function(asBinary) { - var stringDataArray = []; - var numsArray = []; - if (! asBinary) numsArray.push(this[0]); - numsArray.push(this[1], this[2]); - this.eachStrip(function(s, t, n) { - numsArray.push(s, t, n.length); - stringDataArray.push(n); - }, this); - if (! asBinary) { - return numsArray.join(',')+'|'+stringDataArray.join(''); - } - else { - return "A" + Changeset.numberArrayToString(numsArray) - +escapeCrazyUnicode(stringDataArray.join('')); - } - } - - function escapeCrazyUnicode(str) { - return str.replace(/\\/g, '\\\\').replace(/[\ud800-\udfff]/g, function (c) { - return "\\u"+("0000"+c.charCodeAt(0).toString(16)).slice(-4); - }); - } - - array.applyToAttributedText = Changeset.applyToAttributedText; - - function splicesFromChanges(c) { - var splices = []; - // get a list of splices, [startChar, endChar, newText] - var traverser = c.traverser(); - var oldTextLength = c.oldLen(); - var indexIntoOldText = 0; - while (traverser.hasMore() || indexIntoOldText < oldTextLength) { - var newText = ""; - var startChar = indexIntoOldText; - var endChar = indexIntoOldText; - if (traverser.numNewChars() > 0) { - newText = traverser.consumeAvailableNewChars(); - } - if (traverser.hasMore()) { - endChar = traverser.takenCharsStart(); - indexIntoOldText = endChar + traverser.numTakenChars(); - traverser.consumeAvailableTakenChars(); - } - else { - endChar = oldTextLength; - indexIntoOldText = endChar; - } - if (endChar != startChar || newText.length > 0) { - splices.push([startChar, endChar, newText]); - } - } - return splices; - } - - array.toSplices = function() { - return splicesFromChanges(this); - } - - array.characterRangeFollowThis = function(selStartChar, selEndChar, insertionsAfter) { - var changeset = this; - // represent the selection as a changeset that replaces the selection with some finite string. - // Because insertions indicate intention, it doesn't matter what this string is, and even - // if the selectionChangeset is made to "follow" other changes it will still be the only - // insertion. - var selectionChangeset = - Changeset(changeset.oldLen()).builder().appendOldText(0, selStartChar).appendNewText( - "X").appendOldText(selEndChar, changeset.oldLen() - selEndChar).toChangeset(); - var newSelectionChangeset = selectionChangeset.follow(changeset, insertionsAfter); - var selectionSplices = newSelectionChangeset.toSplices(); - function includeChar(i) { - if (! includeChar.calledYet) { - selStartChar = i; - selEndChar = i; - includeChar.calledYet = true; - } - else { - if (i < selStartChar) selStartChar = i; - if (i > selEndChar) selEndChar = i; - } - } - for(var i=0; i<selectionSplices.length; i++) { - var s = selectionSplices[i]; - includeChar(s[0]); - includeChar(s[1]); - } - return [selStartChar, selEndChar]; - } - - return array; -} - -Changeset.MAGIC = "Changeset"; -Changeset.makeSplice = function(oldLength, spliceStart, numRemoved, stringInserted) { - oldLength = (oldLength || 0); - spliceStart = (spliceStart || 0); - numRemoved = (numRemoved || 0); - stringInserted = String(stringInserted || ""); - - var builder = Changeset(oldLength).builder(); - builder.appendOldText(0, spliceStart); - builder.appendNewText(stringInserted); - builder.appendOldText(spliceStart + numRemoved, oldLength - numRemoved - spliceStart); - return builder.toChangeset(); -}; -Changeset.identity = function(len) { - return Changeset(len).builder().appendOldText(0, len).toChangeset(); -}; -Changeset.decodeFromString = function(str) { - function error(msg) { var e = new Error(msg); e.easysync = true; throw e; } - function toHex(str) { - var a = []; - a.push("length["+str.length+"]:"); - var TRUNC=20; - for(var i=0;i<str.substring(0,TRUNC).length;i++) { - a.push(("000"+str.charCodeAt(i).toString(16)).slice(-4)); - } - if (str.length > TRUNC) a.push("..."); - return a.join(' '); - } - function unescapeCrazyUnicode(str) { - return str.replace(/\\(u....|\\)/g, function(seq) { - if (seq == "\\\\") return "\\"; - return String.fromCharCode(Number("0x"+seq.substring(2))); - }); - } - - var numData, stringData; - var binary = false; - var typ = str.charAt(0); - if (typ == "B" || typ == "A") { - var result = Changeset.numberArrayFromString(str, 1); - numData = result[0]; - stringData = result[1]; - if (typ == "A") { - stringData = unescapeCrazyUnicode(stringData); - } - binary = true; - } - else if (typ == "C") { - var barPosition = str.indexOf('|'); - numData = str.substring(0, barPosition).split(','); - stringData = str.substring(barPosition+1); - } - else { - error("Not a changeset: "+toHex(str)); - } - var stringDataOffset = 0; - var array = []; - var ptr; - if (binary) { - array.push("Changeset", numData[0], numData[1]); - var ptr = 2; - } - else { - array.push(numData[0], Number(numData[1]), Number(numData[2])); - var ptr = 3; - } - while (ptr < numData.length) { - array.push(Number(numData[ptr++]), Number(numData[ptr++])); - var newTextLength = Number(numData[ptr++]); - array.push(stringData.substr(stringDataOffset, newTextLength)); - stringDataOffset += newTextLength; - } - if (stringDataOffset != stringData.length) { - error("Extra character data beyond end of encoded string ("+toHex(str)+")"); - } - return Changeset(array); -}; - -Changeset.numberArrayToString = function(nums) { - var array = []; - function writeNum(n) { - // does not support negative numbers - var twentyEightBit = (n & 0xfffffff); - if (twentyEightBit <= 0x7fff) { - array.push(String.fromCharCode(twentyEightBit)); - } - else { - array.push(String.fromCharCode(0xa000 | (twentyEightBit >> 15), - twentyEightBit & 0x7fff)); - } - } - writeNum(nums.length); - var len = nums.length; - for(var i=0;i<len;i++) { - writeNum(nums[i]); - } - return array.join(''); -}; - -Changeset.numberArrayFromString = function(str, startIndex) { - // returns [numberArray, remainingString] - var nums = []; - var strIndex = (startIndex || 0); - function readNum() { - var n = str.charCodeAt(strIndex++); - if (n > 0x7fff) { - if (n >= 0xa000) { - n = (((n & 0x1fff) << 15) | str.charCodeAt(strIndex++)); - } - else { - // legacy format - n = (((n & 0x1fff) << 16) | str.charCodeAt(strIndex++)); - } - } - return n; - } - var len = readNum(); - for(var i=0;i<len;i++) { - nums.push(readNum()); - } - return [nums, str.substring(strIndex)]; -}; - -(function() { - function repeatString(str, times) { - if (times <= 0) return ""; - var s = repeatString(str, times >> 1); - s += s; - if (times & 1) s += str; - return s; - } - function chr(n) { return String.fromCharCode(n+48); } - function ord(c) { return c.charCodeAt(0)-48; } - function runMatcher(c) { - // Takes "A" and returns /\u0041+/g . - // Avoid creating new objects unnecessarily by caching matchers - // as properties of this function. - var re = runMatcher[c]; - if (re) return re; - re = runMatcher[c] = new RegExp("\\u"+("0000"+c.charCodeAt(0).toString(16)).slice(-4)+"+", 'g'); - return re; - } - function runLength(str, idx, c) { - var re = runMatcher(c); - re.lastIndex = idx; - var result = re.exec(str); - if (result && result[0]) { - return result[0].length; - } - return 0; - } - - // emptyObj may be a StorableObject - Changeset.initAttributedText = function(emptyObj, initialString, initialAuthor) { - var obj = emptyObj; - obj.authorMap = { 1: (initialAuthor || '') }; - obj.text = (initialString || ''); - obj.attribs = repeatString(chr(1), obj.text.length); - return obj; - }; - Changeset.gcAttributedText = function(atObj) { - // "garbage collect" the list of authors - var removedAuthors = []; - for(var a in atObj.authorMap) { - if (atObj.attribs.indexOf(chr(Number(a))) < 0) { - removedAuthors.push(atObj.authorMap[a]); - delete atObj.authorMap[a]; - } - } - return removedAuthors; - }; - Changeset.cloneAttributedText = function(emptyObj, atObj) { - var obj = emptyObj; - obj.text = atObj.text; // string - if (atObj.attribs) obj.attribs = atObj.attribs; // string - if (atObj.attribs_c) obj.attribs_c = atObj.attribs_c; // string - obj.authorMap = {}; - for(var a in atObj.authorMap) { - obj.authorMap[a] = atObj.authorMap[a]; - } - return obj; - }; - Changeset.applyToAttributedText = function(atObj, C) { - C = (C || this); - var oldText = atObj.text; - var oldAttribs = atObj.attribs; - Changeset._assert(C.isChangeset, "applyToAttributedText: 'this' is not a changeset"); - Changeset._assert(oldText.length == C.oldLen(), - "applyToAttributedText: mismatch "+oldText.length+" / "+C.oldLen()); - var textBuf = []; - var attribsBuf = []; - var authorMap = atObj.authorMap; - function authorId(author) { - for(var a in authorMap) { - if (authorMap[Number(a)] === author) { - return Number(a); - } - } - for(var i=1;i<=60000;i++) { - // don't use "in" because it's currently broken on StorableObjects - if (authorMap[i] === undefined) { - authorMap[i] = author; - return i; - } - } - } - var myBuilder = { appendNewText: function(txt, author) { - // object that acts as a "builder" in that it receives requests from - // authorSlicer to append text attributed to different authors - attribsBuf.push(repeatString(chr(authorId(author)), txt.length)); - } }; - var authorSlicer; - if (C.authors) { - authorSlicer = C.authorSlicer(myBuilder); - } - C.eachStrip(function (s, t, n) { - textBuf.push(oldText.substr(s, t), n); - attribsBuf.push(oldAttribs.substr(s, t)); - if (authorSlicer) { - authorSlicer.takeChars(n.length, n); - } - else { - myBuilder.appendNewText(n, ''); - } - }); - atObj.text = textBuf.join(''); - atObj.attribs = attribsBuf.join(''); - return atObj; - }; - Changeset.getAttributedTextCharAuthor = function(atObj, idx) { - return atObj.authorMap[ord(atObj.attribs.charAt(idx))]; - }; - Changeset.getAttributedTextCharRunLength = function(atObj, idx) { - var c = atObj.attribs.charAt(idx); - return runLength(atObj.attribs, idx, c); - }; - Changeset.eachAuthorInAttributedText = function(atObj, func) { - // call func(author, authorNum) - for(var a in atObj.authorMap) { - if (func(atObj.authorMap[a], Number(a))) break; - } - }; - Changeset.getAttributedTextAuthorByNum = function(atObj, n) { - return atObj.authorMap[n]; - }; - // Compressed attributed text can be cloned, but nothing else until uncompressed!! - Changeset.compressAttributedText = function(atObj) { - // idempotent, mutates the object, returns it - if (atObj.attribs) { - atObj.attribs_c = atObj.attribs.replace(/([\s\S])\1{0,63}/g, function(run) { - return run.charAt(0)+chr(run.length);; - }); - delete atObj.attribs; - } - return atObj; - }; - Changeset.decompressAttributedText = function(atObj) { - // idempotent, mutates the object, returns it - if (atObj.attribs_c) { - atObj.attribs = atObj.attribs_c.replace(/[\s\S][\s\S]/g, function(run) { - return repeatString(run.charAt(0), ord(run.charAt(1))); - }); - delete atObj.attribs_c; - } - return atObj; - }; -})(); diff --git a/etherpad/src/etherpad/collab/ace/easysync2.js b/etherpad/src/etherpad/collab/ace/easysync2.js deleted file mode 100644 index 0fa1ec4..0000000 --- a/etherpad/src/etherpad/collab/ace/easysync2.js +++ /dev/null @@ -1,1968 +0,0 @@ -// DO NOT EDIT THIS FILE, edit infrastructure/ace/www/easysync2.js -jimport("com.etherpad.Easysync2Support"); - -/** - * Copyright 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//var _opt = (this.Easysync2Support || null); -var _opt = null; // disable optimization for now - -function AttribPool() { - var p = {}; - p.numToAttrib = {}; // e.g. {0: ['foo','bar']} - p.attribToNum = {}; // e.g. {'foo,bar': 0} - p.nextNum = 0; - - p.putAttrib = function(attrib, dontAddIfAbsent) { - var str = String(attrib); - if (str in p.attribToNum) { - return p.attribToNum[str]; - } - if (dontAddIfAbsent) { - return -1; - } - var num = p.nextNum++; - p.attribToNum[str] = num; - p.numToAttrib[num] = [String(attrib[0]||''), - String(attrib[1]||'')]; - return num; - }; - - p.getAttrib = function(num) { - var pair = p.numToAttrib[num]; - if (! pair) return pair; - return [pair[0], pair[1]]; // return a mutable copy - }; - - p.getAttribKey = function(num) { - var pair = p.numToAttrib[num]; - if (! pair) return ''; - return pair[0]; - }; - - p.getAttribValue = function(num) { - var pair = p.numToAttrib[num]; - if (! pair) return ''; - return pair[1]; - }; - - p.eachAttrib = function(func) { - for(var n in p.numToAttrib) { - var pair = p.numToAttrib[n]; - func(pair[0], pair[1]); - } - }; - - p.toJsonable = function() { - return {numToAttrib: p.numToAttrib, nextNum: p.nextNum}; - }; - - p.fromJsonable = function(obj) { - p.numToAttrib = obj.numToAttrib; - p.nextNum = obj.nextNum; - p.attribToNum = {}; - for(var n in p.numToAttrib) { - p.attribToNum[String(p.numToAttrib[n])] = Number(n); - } - return p; - }; - - return p; -} - -var Changeset = {}; - -Changeset.error = function error(msg) { var e = new Error(msg); e.easysync = true; throw e; }; -Changeset.assert = function assert(b, msgParts) { - if (! b) { - var msg = Array.prototype.slice.call(arguments, 1).join(''); - Changeset.error("Changeset: "+msg); - } -}; - -Changeset.parseNum = function(str) { return parseInt(str, 36); }; -Changeset.numToString = function(num) { return num.toString(36).toLowerCase(); }; -Changeset.toBaseTen = function(cs) { - var dollarIndex = cs.indexOf('$'); - var beforeDollar = cs.substring(0, dollarIndex); - var fromDollar = cs.substring(dollarIndex); - return beforeDollar.replace(/[0-9a-z]+/g, function(s) { - return String(Changeset.parseNum(s)); }) + fromDollar; -}; - -Changeset.oldLen = function(cs) { - return Changeset.unpack(cs).oldLen; -}; -Changeset.newLen = function(cs) { - return Changeset.unpack(cs).newLen; -}; - -Changeset.opIterator = function(opsStr, optStartIndex) { - //print(opsStr); - var regex = /((?:\*[0-9a-z]+)*)(?:\|([0-9a-z]+))?([-+=])([0-9a-z]+)|\?|/g; - var startIndex = (optStartIndex || 0); - var curIndex = startIndex; - var prevIndex = curIndex; - function nextRegexMatch() { - prevIndex = curIndex; - var result; - if (_opt) { - result = _opt.nextOpInString(opsStr, curIndex); - if (result) { - if (result.opcode() == '?') { - Changeset.error("Hit error opcode in op stream"); - } - curIndex = result.lastIndex(); - } - } - else { - regex.lastIndex = curIndex; - result = regex.exec(opsStr); - curIndex = regex.lastIndex; - if (result[0] == '?') { - Changeset.error("Hit error opcode in op stream"); - } - } - return result; - } - var regexResult = nextRegexMatch(); - var obj = Changeset.newOp(); - function next(optObj) { - var op = (optObj || obj); - if (_opt && regexResult) { - op.attribs = regexResult.attribs(); - op.lines = regexResult.lines(); - op.chars = regexResult.chars(); - op.opcode = regexResult.opcode(); - regexResult = nextRegexMatch(); - } - else if ((! _opt) && regexResult[0]) { - op.attribs = regexResult[1]; - op.lines = Changeset.parseNum(regexResult[2] || 0); - op.opcode = regexResult[3]; - op.chars = Changeset.parseNum(regexResult[4]); - regexResult = nextRegexMatch(); - } - else { - Changeset.clearOp(op); - } - return op; - } - function hasNext() { return !! (_opt ? regexResult : regexResult[0]); } - function lastIndex() { return prevIndex; } - return {next: next, hasNext: hasNext, lastIndex: lastIndex}; -}; - -Changeset.clearOp = function(op) { - op.opcode = ''; - op.chars = 0; - op.lines = 0; - op.attribs = ''; -}; -Changeset.newOp = function(optOpcode) { - return {opcode:(optOpcode || ''), chars:0, lines:0, attribs:''}; -}; -Changeset.cloneOp = function(op) { - return {opcode: op.opcode, chars: op.chars, lines: op.lines, attribs: op.attribs}; -}; -Changeset.copyOp = function(op1, op2) { - op2.opcode = op1.opcode; - op2.chars = op1.chars; - op2.lines = op1.lines; - op2.attribs = op1.attribs; -}; -Changeset.opString = function(op) { - // just for debugging - if (! op.opcode) return 'null'; - var assem = Changeset.opAssembler(); - assem.append(op); - return assem.toString(); -}; -Changeset.stringOp = function(str) { - // just for debugging - return Changeset.opIterator(str).next(); -}; - -Changeset.checkRep = function(cs) { - // doesn't check things that require access to attrib pool (e.g. attribute order) - // or original string (e.g. newline positions) - var unpacked = Changeset.unpack(cs); - var oldLen = unpacked.oldLen; - var newLen = unpacked.newLen; - var ops = unpacked.ops; - var charBank = unpacked.charBank; - - var assem = Changeset.smartOpAssembler(); - var oldPos = 0; - var calcNewLen = 0; - var numInserted = 0; - var iter = Changeset.opIterator(ops); - while (iter.hasNext()) { - var o = iter.next(); - switch (o.opcode) { - case '=': oldPos += o.chars; calcNewLen += o.chars; break; - case '-': oldPos += o.chars; Changeset.assert(oldPos < oldLen, oldPos," >= ",oldLen," in ",cs); break; - case '+': { - calcNewLen += o.chars; numInserted += o.chars; - Changeset.assert(calcNewLen < newLen, calcNewLen," >= ",newLen," in ",cs); - break; - } - } - assem.append(o); - } - - calcNewLen += oldLen - oldPos; - charBank = charBank.substring(0, numInserted); - while (charBank.length < numInserted) { - charBank += "?"; - } - - assem.endDocument(); - var normalized = Changeset.pack(oldLen, calcNewLen, assem.toString(), charBank); - Changeset.assert(normalized == cs, normalized,' != ',cs); - - return cs; -} - -Changeset.smartOpAssembler = function() { - // Like opAssembler but able to produce conforming changesets - // from slightly looser input, at the cost of speed. - // Specifically: - // - merges consecutive operations that can be merged - // - strips final "=" - // - ignores 0-length changes - // - reorders consecutive + and - (which margingOpAssembler doesn't do) - - var minusAssem = Changeset.mergingOpAssembler(); - var plusAssem = Changeset.mergingOpAssembler(); - var keepAssem = Changeset.mergingOpAssembler(); - var assem = Changeset.stringAssembler(); - var lastOpcode = ''; - var lengthChange = 0; - - function flushKeeps() { - assem.append(keepAssem.toString()); - keepAssem.clear(); - } - - function flushPlusMinus() { - assem.append(minusAssem.toString()); - minusAssem.clear(); - assem.append(plusAssem.toString()); - plusAssem.clear(); - } - - function append(op) { - if (! op.opcode) return; - if (! op.chars) return; - - if (op.opcode == '-') { - if (lastOpcode == '=') { - flushKeeps(); - } - minusAssem.append(op); - lengthChange -= op.chars; - } - else if (op.opcode == '+') { - if (lastOpcode == '=') { - flushKeeps(); - } - plusAssem.append(op); - lengthChange += op.chars; - } - else if (op.opcode == '=') { - if (lastOpcode != '=') { - flushPlusMinus(); - } - keepAssem.append(op); - } - lastOpcode = op.opcode; - } - - function appendOpWithText(opcode, text, attribs, pool) { - var op = Changeset.newOp(opcode); - op.attribs = Changeset.makeAttribsString(opcode, attribs, pool); - var lastNewlinePos = text.lastIndexOf('\n'); - if (lastNewlinePos < 0) { - op.chars = text.length; - op.lines = 0; - append(op); - } - else { - op.chars = lastNewlinePos+1; - op.lines = text.match(/\n/g).length; - append(op); - op.chars = text.length - (lastNewlinePos+1); - op.lines = 0; - append(op); - } - } - - function toString() { - flushPlusMinus(); - flushKeeps(); - return assem.toString(); - } - - function clear() { - minusAssem.clear(); - plusAssem.clear(); - keepAssem.clear(); - assem.clear(); - lengthChange = 0; - } - - function endDocument() { - keepAssem.endDocument(); - } - - function getLengthChange() { - return lengthChange; - } - - return {append: append, toString: toString, clear: clear, endDocument: endDocument, - appendOpWithText: appendOpWithText, getLengthChange: getLengthChange }; -}; - -if (_opt) { - Changeset.mergingOpAssembler = function() { - var assem = _opt.mergingOpAssembler(); - - function append(op) { - assem.append(op.opcode, op.chars, op.lines, op.attribs); - } - function toString() { - return assem.toString(); - } - function clear() { - assem.clear(); - } - function endDocument() { - assem.endDocument(); - } - - return {append: append, toString: toString, clear: clear, endDocument: endDocument}; - }; -} -else { - Changeset.mergingOpAssembler = function() { - // This assembler can be used in production; it efficiently - // merges consecutive operations that are mergeable, ignores - // no-ops, and drops final pure "keeps". It does not re-order - // operations. - var assem = Changeset.opAssembler(); - var bufOp = Changeset.newOp(); - - // If we get, for example, insertions [xxx\n,yyy], those don't merge, - // but if we get [xxx\n,yyy,zzz\n], that merges to [xxx\nyyyzzz\n]. - // This variable stores the length of yyy and any other newline-less - // ops immediately after it. - var bufOpAdditionalCharsAfterNewline = 0; - - function flush(isEndDocument) { - if (bufOp.opcode) { - if (isEndDocument && bufOp.opcode == '=' && ! bufOp.attribs) { - // final merged keep, leave it implicit - } - else { - assem.append(bufOp); - if (bufOpAdditionalCharsAfterNewline) { - bufOp.chars = bufOpAdditionalCharsAfterNewline; - bufOp.lines = 0; - assem.append(bufOp); - bufOpAdditionalCharsAfterNewline = 0; - } - } - bufOp.opcode = ''; - } - } - function append(op) { - if (op.chars > 0) { - if (bufOp.opcode == op.opcode && bufOp.attribs == op.attribs) { - if (op.lines > 0) { - // bufOp and additional chars are all mergeable into a multi-line op - bufOp.chars += bufOpAdditionalCharsAfterNewline + op.chars; - bufOp.lines += op.lines; - bufOpAdditionalCharsAfterNewline = 0; - } - else if (bufOp.lines == 0) { - // both bufOp and op are in-line - bufOp.chars += op.chars; - } - else { - // append in-line text to multi-line bufOp - bufOpAdditionalCharsAfterNewline += op.chars; - } - } - else { - flush(); - Changeset.copyOp(op, bufOp); - } - } - } - function endDocument() { - flush(true); - } - function toString() { - flush(); - return assem.toString(); - } - function clear() { - assem.clear(); - Changeset.clearOp(bufOp); - } - return {append: append, toString: toString, clear: clear, endDocument: endDocument}; - }; -} - -if (_opt) { - Changeset.opAssembler = function() { - var assem = _opt.opAssembler(); - // this function allows op to be mutated later (doesn't keep a ref) - function append(op) { - assem.append(op.opcode, op.chars, op.lines, op.attribs); - } - function toString() { - return assem.toString(); - } - function clear() { - assem.clear(); - } - return {append: append, toString: toString, clear: clear}; - }; -} -else { - Changeset.opAssembler = function() { - var pieces = []; - // this function allows op to be mutated later (doesn't keep a ref) - function append(op) { - pieces.push(op.attribs); - if (op.lines) { - pieces.push('|', Changeset.numToString(op.lines)); - } - pieces.push(op.opcode); - pieces.push(Changeset.numToString(op.chars)); - } - function toString() { - return pieces.join(''); - } - function clear() { - pieces.length = 0; - } - return {append: append, toString: toString, clear: clear}; - }; -} - -Changeset.stringIterator = function(str) { - var curIndex = 0; - function assertRemaining(n) { - Changeset.assert(n <= remaining(), "!(",n," <= ",remaining(),")"); - } - function take(n) { - assertRemaining(n); - var s = str.substr(curIndex, n); - curIndex += n; - return s; - } - function peek(n) { - assertRemaining(n); - var s = str.substr(curIndex, n); - return s; - } - function skip(n) { - assertRemaining(n); - curIndex += n; - } - function remaining() { - return str.length - curIndex; - } - return {take:take, skip:skip, remaining:remaining, peek:peek}; -}; - -Changeset.stringAssembler = function() { - var pieces = []; - function append(x) { - pieces.push(String(x)); - } - function toString() { - return pieces.join(''); - } - return {append: append, toString: toString}; -}; - -// "lines" need not be an array as long as it supports certain calls (lines_foo inside). -Changeset.textLinesMutator = function(lines) { - // Mutates lines, an array of strings, in place. - // Mutation operations have the same constraints as changeset operations - // with respect to newlines, but not the other additional constraints - // (i.e. ins/del ordering, forbidden no-ops, non-mergeability, final newline). - // Can be used to mutate lists of strings where the last char of each string - // is not actually a newline, but for the purposes of N and L values, - // the caller should pretend it is, and for things to work right in that case, the input - // to insert() should be a single line with no newlines. - - var curSplice = [0,0]; - var inSplice = false; - // position in document after curSplice is applied: - var curLine = 0, curCol = 0; - // invariant: if (inSplice) then (curLine is in curSplice[0] + curSplice.length - {2,3}) && - // curLine >= curSplice[0] - // invariant: if (inSplice && (curLine >= curSplice[0] + curSplice.length - 2)) then - // curCol == 0 - - function lines_applySplice(s) { - lines.splice.apply(lines, s); - } - function lines_toSource() { - return lines.toSource(); - } - function lines_get(idx) { - if (lines.get) { - return lines.get(idx); - } - else { - return lines[idx]; - } - } - // can be unimplemented if removeLines's return value not needed - function lines_slice(start, end) { - if (lines.slice) { - return lines.slice(start, end); - } - else { - return []; - } - } - function lines_length() { - if ((typeof lines.length) == "number") { - return lines.length; - } - else { - return lines.length(); - } - } - - function enterSplice() { - curSplice[0] = curLine; - curSplice[1] = 0; - if (curCol > 0) { - putCurLineInSplice(); - } - inSplice = true; - } - function leaveSplice() { - lines_applySplice(curSplice); - curSplice.length = 2; - curSplice[0] = curSplice[1] = 0; - inSplice = false; - } - function isCurLineInSplice() { - return (curLine - curSplice[0] < (curSplice.length - 2)); - } - function debugPrint(typ) { - print(typ+": "+curSplice.toSource()+" / "+curLine+","+curCol+" / "+lines_toSource()); - } - function putCurLineInSplice() { - if (! isCurLineInSplice()) { - curSplice.push(lines_get(curSplice[0] + curSplice[1])); - curSplice[1]++; - } - return 2 + curLine - curSplice[0]; - } - - function skipLines(L, includeInSplice) { - if (L) { - if (includeInSplice) { - if (! inSplice) { - enterSplice(); - } - for(var i=0;i<L;i++) { - curCol = 0; - putCurLineInSplice(); - curLine++; - } - } - else { - if (inSplice) { - if (L > 1) { - leaveSplice(); - } - else { - putCurLineInSplice(); - } - } - curLine += L; - curCol = 0; - } - //print(inSplice+" / "+isCurLineInSplice()+" / "+curSplice[0]+" / "+curSplice[1]+" / "+lines.length); - /*if (inSplice && (! isCurLineInSplice()) && (curSplice[0] + curSplice[1] < lines.length)) { - print("BLAH"); - putCurLineInSplice(); - }*/ // tests case foo in remove(), which isn't otherwise covered in current impl - } - //debugPrint("skip"); - } - - function skip(N, L, includeInSplice) { - if (N) { - if (L) { - skipLines(L, includeInSplice); - } - else { - if (includeInSplice && ! inSplice) { - enterSplice(); - } - if (inSplice) { - putCurLineInSplice(); - } - curCol += N; - //debugPrint("skip"); - } - } - } - - function removeLines(L) { - var removed = ''; - if (L) { - if (! inSplice) { - enterSplice(); - } - function nextKLinesText(k) { - var m = curSplice[0] + curSplice[1]; - return lines_slice(m, m+k).join(''); - } - if (isCurLineInSplice()) { - //print(curCol); - if (curCol == 0) { - removed = curSplice[curSplice.length-1]; - // print("FOO"); // case foo - curSplice.length--; - removed += nextKLinesText(L-1); - curSplice[1] += L-1; - } - else { - removed = nextKLinesText(L-1); - curSplice[1] += L-1; - var sline = curSplice.length - 1; - removed = curSplice[sline].substring(curCol) + removed; - curSplice[sline] = curSplice[sline].substring(0, curCol) + - lines_get(curSplice[0] + curSplice[1]); - curSplice[1] += 1; - } - } - else { - removed = nextKLinesText(L); - curSplice[1] += L; - } - //debugPrint("remove"); - } - return removed; - } - - function remove(N, L) { - var removed = ''; - if (N) { - if (L) { - return removeLines(L); - } - else { - if (! inSplice) { - enterSplice(); - } - var sline = putCurLineInSplice(); - removed = curSplice[sline].substring(curCol, curCol+N); - curSplice[sline] = curSplice[sline].substring(0, curCol) + - curSplice[sline].substring(curCol+N); - //debugPrint("remove"); - } - } - return removed; - } - - function insert(text, L) { - if (text) { - if (! inSplice) { - enterSplice(); - } - if (L) { - var newLines = Changeset.splitTextLines(text); - if (isCurLineInSplice()) { - //if (curCol == 0) { - //curSplice.length--; - //curSplice[1]--; - //Array.prototype.push.apply(curSplice, newLines); - //curLine += newLines.length; - //} - //else { - var sline = curSplice.length - 1; - var theLine = curSplice[sline]; - var lineCol = curCol; - curSplice[sline] = theLine.substring(0, lineCol) + newLines[0]; - curLine++; - newLines.splice(0, 1); - Array.prototype.push.apply(curSplice, newLines); - curLine += newLines.length; - curSplice.push(theLine.substring(lineCol)); - curCol = 0; - //} - } - else { - Array.prototype.push.apply(curSplice, newLines); - curLine += newLines.length; - } - } - else { - var sline = putCurLineInSplice(); - curSplice[sline] = curSplice[sline].substring(0, curCol) + - text + curSplice[sline].substring(curCol); - curCol += text.length; - } - //debugPrint("insert"); - } - } - - function hasMore() { - //print(lines.length+" / "+inSplice+" / "+(curSplice.length - 2)+" / "+curSplice[1]); - var docLines = lines_length(); - if (inSplice) { - docLines += curSplice.length - 2 - curSplice[1]; - } - return curLine < docLines; - } - - function close() { - if (inSplice) { - leaveSplice(); - } - //debugPrint("close"); - } - - var self = {skip:skip, remove:remove, insert:insert, close:close, hasMore:hasMore, - removeLines:removeLines, skipLines: skipLines}; - return self; -}; - -Changeset.applyZip = function(in1, idx1, in2, idx2, func) { - var iter1 = Changeset.opIterator(in1, idx1); - var iter2 = Changeset.opIterator(in2, idx2); - var assem = Changeset.smartOpAssembler(); - var op1 = Changeset.newOp(); - var op2 = Changeset.newOp(); - var opOut = Changeset.newOp(); - while (op1.opcode || iter1.hasNext() || op2.opcode || iter2.hasNext()) { - if ((! op1.opcode) && iter1.hasNext()) iter1.next(op1); - if ((! op2.opcode) && iter2.hasNext()) iter2.next(op2); - func(op1, op2, opOut); - if (opOut.opcode) { - //print(opOut.toSource()); - assem.append(opOut); - opOut.opcode = ''; - } - } - assem.endDocument(); - return assem.toString(); -}; - -Changeset.unpack = function(cs) { - var headerRegex = /Z:([0-9a-z]+)([><])([0-9a-z]+)|/; - var headerMatch = headerRegex.exec(cs); - if ((! headerMatch) || (! headerMatch[0])) { - Changeset.error("Not a changeset: "+cs); - } - var oldLen = Changeset.parseNum(headerMatch[1]); - var changeSign = (headerMatch[2] == '>') ? 1 : -1; - var changeMag = Changeset.parseNum(headerMatch[3]); - var newLen = oldLen + changeSign*changeMag; - var opsStart = headerMatch[0].length; - var opsEnd = cs.indexOf("$"); - if (opsEnd < 0) opsEnd = cs.length; - return {oldLen: oldLen, newLen: newLen, ops: cs.substring(opsStart, opsEnd), - charBank: cs.substring(opsEnd+1)}; -}; - -Changeset.pack = function(oldLen, newLen, opsStr, bank) { - var lenDiff = newLen - oldLen; - var lenDiffStr = (lenDiff >= 0 ? - '>'+Changeset.numToString(lenDiff) : - '<'+Changeset.numToString(-lenDiff)); - var a = []; - a.push('Z:', Changeset.numToString(oldLen), lenDiffStr, opsStr, '$', bank); - return a.join(''); -}; - -Changeset.applyToText = function(cs, str) { - var unpacked = Changeset.unpack(cs); - Changeset.assert(str.length == unpacked.oldLen, - "mismatched apply: ",str.length," / ",unpacked.oldLen); - var csIter = Changeset.opIterator(unpacked.ops); - var bankIter = Changeset.stringIterator(unpacked.charBank); - var strIter = Changeset.stringIterator(str); - var assem = Changeset.stringAssembler(); - while (csIter.hasNext()) { - var op = csIter.next(); - switch(op.opcode) { - case '+': assem.append(bankIter.take(op.chars)); break; - case '-': strIter.skip(op.chars); break; - case '=': assem.append(strIter.take(op.chars)); break; - } - } - assem.append(strIter.take(strIter.remaining())); - return assem.toString(); -}; - -Changeset.mutateTextLines = function(cs, lines) { - var unpacked = Changeset.unpack(cs); - var csIter = Changeset.opIterator(unpacked.ops); - var bankIter = Changeset.stringIterator(unpacked.charBank); - var mut = Changeset.textLinesMutator(lines); - while (csIter.hasNext()) { - var op = csIter.next(); - switch(op.opcode) { - case '+': mut.insert(bankIter.take(op.chars), op.lines); break; - case '-': mut.remove(op.chars, op.lines); break; - case '=': mut.skip(op.chars, op.lines, (!! op.attribs)); break; - } - } - mut.close(); -}; - -Changeset.composeAttributes = function(att1, att2, resultIsMutation, pool) { - // att1 and att2 are strings like "*3*f*1c", asMutation is a boolean. - - // Sometimes attribute (key,value) pairs are treated as attribute presence - // information, while other times they are treated as operations that - // mutate a set of attributes, and this affects whether an empty value - // is a deletion or a change. - // Examples, of the form (att1Items, att2Items, resultIsMutation) -> result - // ([], [(bold, )], true) -> [(bold, )] - // ([], [(bold, )], false) -> [] - // ([], [(bold, true)], true) -> [(bold, true)] - // ([], [(bold, true)], false) -> [(bold, true)] - // ([(bold, true)], [(bold, )], true) -> [(bold, )] - // ([(bold, true)], [(bold, )], false) -> [] - - // pool can be null if att2 has no attributes. - - if ((! att1) && resultIsMutation) { - // In the case of a mutation (i.e. composing two changesets), - // an att2 composed with an empy att1 is just att2. If att1 - // is part of an attribution string, then att2 may remove - // attributes that are already gone, so don't do this optimization. - return att2; - } - if (! att2) return att1; - var atts = []; - att1.replace(/\*([0-9a-z]+)/g, function(_, a) { - atts.push(pool.getAttrib(Changeset.parseNum(a))); - return ''; - }); - att2.replace(/\*([0-9a-z]+)/g, function(_, a) { - var pair = pool.getAttrib(Changeset.parseNum(a)); - var found = false; - for(var i=0;i<atts.length;i++) { - var oldPair = atts[i]; - if (oldPair[0] == pair[0]) { - if (pair[1] || resultIsMutation) { - oldPair[1] = pair[1]; - } - else { - atts.splice(i, 1); - } - found = true; - break; - } - } - if ((! found) && (pair[1] || resultIsMutation)) { - atts.push(pair); - } - return ''; - }); - atts.sort(); - var buf = Changeset.stringAssembler(); - for(var i=0;i<atts.length;i++) { - buf.append('*'); - buf.append(Changeset.numToString(pool.putAttrib(atts[i]))); - } - //print(att1+" / "+att2+" / "+buf.toString()); - return buf.toString(); -}; - -Changeset._slicerZipperFunc = function(attOp, csOp, opOut, pool) { - // attOp is the op from the sequence that is being operated on, either an - // attribution string or the earlier of two changesets being composed. - // pool can be null if definitely not needed. - - //print(csOp.toSource()+" "+attOp.toSource()+" "+opOut.toSource()); - if (attOp.opcode == '-') { - Changeset.copyOp(attOp, opOut); - attOp.opcode = ''; - } - else if (! attOp.opcode) { - Changeset.copyOp(csOp, opOut); - csOp.opcode = ''; - } - else { - switch (csOp.opcode) { - case '-': { - if (csOp.chars <= attOp.chars) { - // delete or delete part - if (attOp.opcode == '=') { - opOut.opcode = '-'; - opOut.chars = csOp.chars; - opOut.lines = csOp.lines; - opOut.attribs = ''; - } - attOp.chars -= csOp.chars; - attOp.lines -= csOp.lines; - csOp.opcode = ''; - if (! attOp.chars) { - attOp.opcode = ''; - } - } - else { - // delete and keep going - if (attOp.opcode == '=') { - opOut.opcode = '-'; - opOut.chars = attOp.chars; - opOut.lines = attOp.lines; - opOut.attribs = ''; - } - csOp.chars -= attOp.chars; - csOp.lines -= attOp.lines; - attOp.opcode = ''; - } - break; - } - case '+': { - // insert - Changeset.copyOp(csOp, opOut); - csOp.opcode = ''; - break; - } - case '=': { - if (csOp.chars <= attOp.chars) { - // keep or keep part - opOut.opcode = attOp.opcode; - opOut.chars = csOp.chars; - opOut.lines = csOp.lines; - opOut.attribs = Changeset.composeAttributes(attOp.attribs, csOp.attribs, - attOp.opcode == '=', pool); - csOp.opcode = ''; - attOp.chars -= csOp.chars; - attOp.lines -= csOp.lines; - if (! attOp.chars) { - attOp.opcode = ''; - } - } - else { - // keep and keep going - opOut.opcode = attOp.opcode; - opOut.chars = attOp.chars; - opOut.lines = attOp.lines; - opOut.attribs = Changeset.composeAttributes(attOp.attribs, csOp.attribs, - attOp.opcode == '=', pool); - attOp.opcode = ''; - csOp.chars -= attOp.chars; - csOp.lines -= attOp.lines; - } - break; - } - case '': { - Changeset.copyOp(attOp, opOut); - attOp.opcode = ''; - break; - } - } - } -}; - -Changeset.applyToAttribution = function(cs, astr, pool) { - var unpacked = Changeset.unpack(cs); - - return Changeset.applyZip(astr, 0, unpacked.ops, 0, function(op1, op2, opOut) { - return Changeset._slicerZipperFunc(op1, op2, opOut, pool); - }); -}; - -/*Changeset.oneInsertedLineAtATimeOpIterator = function(opsStr, optStartIndex, charBank) { - var iter = Changeset.opIterator(opsStr, optStartIndex); - var bankIndex = 0; - -};*/ - -Changeset.mutateAttributionLines = function(cs, lines, pool) { - //dmesg(cs); - //dmesg(lines.toSource()+" ->"); - - var unpacked = Changeset.unpack(cs); - var csIter = Changeset.opIterator(unpacked.ops); - var csBank = unpacked.charBank; - var csBankIndex = 0; - // treat the attribution lines as text lines, mutating a line at a time - var mut = Changeset.textLinesMutator(lines); - - var lineIter = null; - function isNextMutOp() { - return (lineIter && lineIter.hasNext()) || mut.hasMore(); - } - function nextMutOp(destOp) { - if ((!(lineIter && lineIter.hasNext())) && mut.hasMore()) { - var line = mut.removeLines(1); - lineIter = Changeset.opIterator(line); - } - if (lineIter && lineIter.hasNext()) { - lineIter.next(destOp); - } - else { - destOp.opcode = ''; - } - } - var lineAssem = null; - function outputMutOp(op) { - //print("outputMutOp: "+op.toSource()); - if (! lineAssem) { - lineAssem = Changeset.mergingOpAssembler(); - } - lineAssem.append(op); - if (op.lines > 0) { - Changeset.assert(op.lines == 1, "Can't have op.lines of ",op.lines," in attribution lines"); - // ship it to the mut - mut.insert(lineAssem.toString(), 1); - lineAssem = null; - } - } - - var csOp = Changeset.newOp(); - var attOp = Changeset.newOp(); - var opOut = Changeset.newOp(); - while (csOp.opcode || csIter.hasNext() || attOp.opcode || isNextMutOp()) { - if ((! csOp.opcode) && csIter.hasNext()) { - csIter.next(csOp); - } - //print(csOp.toSource()+" "+attOp.toSource()+" "+opOut.toSource()); - //print(csOp.opcode+"/"+csOp.lines+"/"+csOp.attribs+"/"+lineAssem+"/"+lineIter+"/"+(lineIter?lineIter.hasNext():null)); - //print("csOp: "+csOp.toSource()); - if ((! csOp.opcode) && (! attOp.opcode) && - (! lineAssem) && (! (lineIter && lineIter.hasNext()))) { - break; // done - } - else if (csOp.opcode == '=' && csOp.lines > 0 && (! csOp.attribs) && (! attOp.opcode) && - (! lineAssem) && (! (lineIter && lineIter.hasNext()))) { - // skip multiple lines; this is what makes small changes not order of the document size - mut.skipLines(csOp.lines); - //print("skipped: "+csOp.lines); - csOp.opcode = ''; - } - else if (csOp.opcode == '+') { - if (csOp.lines > 1) { - var firstLineLen = csBank.indexOf('\n', csBankIndex) + 1 - csBankIndex; - Changeset.copyOp(csOp, opOut); - csOp.chars -= firstLineLen; - csOp.lines--; - opOut.lines = 1; - opOut.chars = firstLineLen; - } - else { - Changeset.copyOp(csOp, opOut); - csOp.opcode = ''; - } - outputMutOp(opOut); - csBankIndex += opOut.chars; - opOut.opcode = ''; - } - else { - if ((! attOp.opcode) && isNextMutOp()) { - nextMutOp(attOp); - } - //print("attOp: "+attOp.toSource()); - Changeset._slicerZipperFunc(attOp, csOp, opOut, pool); - if (opOut.opcode) { - outputMutOp(opOut); - opOut.opcode = ''; - } - } - } - - Changeset.assert(! lineAssem, "line assembler not finished"); - mut.close(); - - //dmesg("-> "+lines.toSource()); -}; - -Changeset.joinAttributionLines = function(theAlines) { - var assem = Changeset.mergingOpAssembler(); - for(var i=0;i<theAlines.length;i++) { - var aline = theAlines[i]; - var iter = Changeset.opIterator(aline); - while (iter.hasNext()) { - assem.append(iter.next()); - } - } - return assem.toString(); -}; - -Changeset.splitAttributionLines = function(attrOps, text) { - var iter = Changeset.opIterator(attrOps); - var assem = Changeset.mergingOpAssembler(); - var lines = []; - var pos = 0; - - function appendOp(op) { - assem.append(op); - if (op.lines > 0) { - lines.push(assem.toString()); - assem.clear(); - } - pos += op.chars; - } - - while (iter.hasNext()) { - var op = iter.next(); - var numChars = op.chars; - var numLines = op.lines; - while (numLines > 1) { - var newlineEnd = text.indexOf('\n', pos)+1; - Changeset.assert(newlineEnd > 0, "newlineEnd <= 0 in splitAttributionLines"); - op.chars = newlineEnd - pos; - op.lines = 1; - appendOp(op); - numChars -= op.chars; - numLines -= op.lines; - } - if (numLines == 1) { - op.chars = numChars; - op.lines = 1; - } - appendOp(op); - } - - return lines; -}; - -Changeset.splitTextLines = function(text) { - return text.match(/[^\n]*(?:\n|[^\n]$)/g); -}; - -Changeset.compose = function(cs1, cs2, pool) { - var unpacked1 = Changeset.unpack(cs1); - var unpacked2 = Changeset.unpack(cs2); - var len1 = unpacked1.oldLen; - var len2 = unpacked1.newLen; - Changeset.assert(len2 == unpacked2.oldLen, "mismatched composition"); - var len3 = unpacked2.newLen; - var bankIter1 = Changeset.stringIterator(unpacked1.charBank); - var bankIter2 = Changeset.stringIterator(unpacked2.charBank); - var bankAssem = Changeset.stringAssembler(); - - var newOps = Changeset.applyZip(unpacked1.ops, 0, unpacked2.ops, 0, function(op1, op2, opOut) { - //var debugBuilder = Changeset.stringAssembler(); - //debugBuilder.append(Changeset.opString(op1)); - //debugBuilder.append(','); - //debugBuilder.append(Changeset.opString(op2)); - //debugBuilder.append(' / '); - - var op1code = op1.opcode; - var op2code = op2.opcode; - if (op1code == '+' && op2code == '-') { - bankIter1.skip(Math.min(op1.chars, op2.chars)); - } - Changeset._slicerZipperFunc(op1, op2, opOut, pool); - if (opOut.opcode == '+') { - if (op2code == '+') { - bankAssem.append(bankIter2.take(opOut.chars)); - } - else { - bankAssem.append(bankIter1.take(opOut.chars)); - } - } - - //debugBuilder.append(Changeset.opString(op1)); - //debugBuilder.append(','); - //debugBuilder.append(Changeset.opString(op2)); - //debugBuilder.append(' -> '); - //debugBuilder.append(Changeset.opString(opOut)); - //print(debugBuilder.toString()); - }); - - return Changeset.pack(len1, len3, newOps, bankAssem.toString()); -}; - -Changeset.attributeTester = function(attribPair, pool) { - // returns a function that tests if a string of attributes - // (e.g. *3*4) contains a given attribute key,value that - // is already present in the pool. - if (! pool) { - return never; - } - var attribNum = pool.putAttrib(attribPair, true); - if (attribNum < 0) { - return never; - } - else { - var re = new RegExp('\\*'+Changeset.numToString(attribNum)+ - '(?!\\w)'); - return function(attribs) { - return re.test(attribs); - }; - } - function never(attribs) { return false; } -}; - -Changeset.identity = function(N) { - return Changeset.pack(N, N, "", ""); -}; - -Changeset.makeSplice = function(oldFullText, spliceStart, numRemoved, newText, optNewTextAPairs, pool) { - var oldLen = oldFullText.length; - - if (spliceStart >= oldLen) { - spliceStart = oldLen - 1; - } - if (numRemoved > oldFullText.length - spliceStart - 1) { - numRemoved = oldFullText.length - spliceStart - 1; - } - var oldText = oldFullText.substring(spliceStart, spliceStart+numRemoved); - var newLen = oldLen + newText.length - oldText.length; - - var assem = Changeset.smartOpAssembler(); - assem.appendOpWithText('=', oldFullText.substring(0, spliceStart)); - assem.appendOpWithText('-', oldText); - assem.appendOpWithText('+', newText, optNewTextAPairs, pool); - assem.endDocument(); - return Changeset.pack(oldLen, newLen, assem.toString(), newText); -}; - -Changeset.toSplices = function(cs) { - // get a list of splices, [startChar, endChar, newText] - - var unpacked = Changeset.unpack(cs); - var splices = []; - - var oldPos = 0; - var iter = Changeset.opIterator(unpacked.ops); - var charIter = Changeset.stringIterator(unpacked.charBank); - var inSplice = false; - while (iter.hasNext()) { - var op = iter.next(); - if (op.opcode == '=') { - oldPos += op.chars; - inSplice = false; - } - else { - if (! inSplice) { - splices.push([oldPos, oldPos, ""]); - inSplice = true; - } - if (op.opcode == '-') { - oldPos += op.chars; - splices[splices.length-1][1] += op.chars; - } - else if (op.opcode == '+') { - splices[splices.length-1][2] += charIter.take(op.chars); - } - } - } - - return splices; -}; - -Changeset.characterRangeFollow = function(cs, startChar, endChar, insertionsAfter) { - var newStartChar = startChar; - var newEndChar = endChar; - var splices = Changeset.toSplices(cs); - var lengthChangeSoFar = 0; - for(var i=0;i<splices.length;i++) { - var splice = splices[i]; - var spliceStart = splice[0] + lengthChangeSoFar; - var spliceEnd = splice[1] + lengthChangeSoFar; - var newTextLength = splice[2].length; - var thisLengthChange = newTextLength - (spliceEnd - spliceStart); - - if (spliceStart <= newStartChar && spliceEnd >= newEndChar) { - // splice fully replaces/deletes range - // (also case that handles insertion at a collapsed selection) - if (insertionsAfter) { - newStartChar = newEndChar = spliceStart; - } - else { - newStartChar = newEndChar = spliceStart + newTextLength; - } - } - else if (spliceEnd <= newStartChar) { - // splice is before range - newStartChar += thisLengthChange; - newEndChar += thisLengthChange; - } - else if (spliceStart >= newEndChar) { - // splice is after range - } - else if (spliceStart >= newStartChar && spliceEnd <= newEndChar) { - // splice is inside range - newEndChar += thisLengthChange; - } - else if (spliceEnd < newEndChar) { - // splice overlaps beginning of range - newStartChar = spliceStart + newTextLength; - newEndChar += thisLengthChange; - } - else { - // splice overlaps end of range - newEndChar = spliceStart; - } - - lengthChangeSoFar += thisLengthChange; - } - - return [newStartChar, newEndChar]; -}; - -Changeset.moveOpsToNewPool = function(cs, oldPool, newPool) { - // works on changeset or attribution string - var dollarPos = cs.indexOf('$'); - if (dollarPos < 0) { - dollarPos = cs.length; - } - var upToDollar = cs.substring(0, dollarPos); - var fromDollar = cs.substring(dollarPos); - // order of attribs stays the same - return upToDollar.replace(/\*([0-9a-z]+)/g, function(_, a) { - var oldNum = Changeset.parseNum(a); - var pair = oldPool.getAttrib(oldNum); - var newNum = newPool.putAttrib(pair); - return '*'+Changeset.numToString(newNum); - }) + fromDollar; -}; - -Changeset.makeAttribution = function(text) { - var assem = Changeset.smartOpAssembler(); - assem.appendOpWithText('+', text); - return assem.toString(); -}; - -// callable on a changeset, attribution string, or attribs property of an op -Changeset.eachAttribNumber = function(cs, func) { - var dollarPos = cs.indexOf('$'); - if (dollarPos < 0) { - dollarPos = cs.length; - } - var upToDollar = cs.substring(0, dollarPos); - - upToDollar.replace(/\*([0-9a-z]+)/g, function(_, a) { - func(Changeset.parseNum(a)); - return ''; - }); -}; - -// callable on a changeset, attribution string, or attribs property of an op, -// though it may easily create adjacent ops that can be merged. -Changeset.filterAttribNumbers = function(cs, filter) { - return Changeset.mapAttribNumbers(cs, filter); -}; - -Changeset.mapAttribNumbers = function(cs, func) { - var dollarPos = cs.indexOf('$'); - if (dollarPos < 0) { - dollarPos = cs.length; - } - var upToDollar = cs.substring(0, dollarPos); - - var newUpToDollar = upToDollar.replace(/\*([0-9a-z]+)/g, function(s, a) { - var n = func(Changeset.parseNum(a)); - if (n === true) { - return s; - } - else if ((typeof n) === "number") { - return '*'+Changeset.numToString(n); - } - else { - return ''; - } - }); - - return newUpToDollar + cs.substring(dollarPos); -}; - -Changeset.makeAText = function(text, attribs) { - return { text: text, attribs: (attribs || Changeset.makeAttribution(text)) }; -}; - -Changeset.applyToAText = function(cs, atext, pool) { - return { text: Changeset.applyToText(cs, atext.text), - attribs: Changeset.applyToAttribution(cs, atext.attribs, pool) }; -}; - -Changeset.cloneAText = function(atext) { - return { text: atext.text, attribs: atext.attribs }; -}; - -Changeset.copyAText = function(atext1, atext2) { - atext2.text = atext1.text; - atext2.attribs = atext1.attribs; -}; - -Changeset.appendATextToAssembler = function(atext, assem) { - // intentionally skips last newline char of atext - var iter = Changeset.opIterator(atext.attribs); - var op = Changeset.newOp(); - while (iter.hasNext()) { - iter.next(op); - if (! iter.hasNext()) { - // last op, exclude final newline - if (op.lines <= 1) { - op.lines = 0; - op.chars--; - if (op.chars) { - assem.append(op); - } - } - else { - var nextToLastNewlineEnd = - atext.text.lastIndexOf('\n', atext.text.length-2) + 1; - var lastLineLength = atext.text.length - nextToLastNewlineEnd - 1; - op.lines--; - op.chars -= (lastLineLength + 1); - assem.append(op); - op.lines = 0; - op.chars = lastLineLength; - if (op.chars) { - assem.append(op); - } - } - } - else { - assem.append(op); - } - } -}; - -Changeset.prepareForWire = function(cs, pool) { - var newPool = new AttribPool(); - var newCs = Changeset.moveOpsToNewPool(cs, pool, newPool); - return {translated: newCs, pool: newPool}; -}; - -Changeset.isIdentity = function(cs) { - var unpacked = Changeset.unpack(cs); - return unpacked.ops == "" && unpacked.oldLen == unpacked.newLen; -}; - -Changeset.opAttributeValue = function(op, key, pool) { - return Changeset.attribsAttributeValue(op.attribs, key, pool); -}; - -Changeset.attribsAttributeValue = function(attribs, key, pool) { - var value = ''; - if (attribs) { - Changeset.eachAttribNumber(attribs, function(n) { - if (pool.getAttribKey(n) == key) { - value = pool.getAttribValue(n); - } - }); - } - return value; -}; - -Changeset.builder = function(oldLen) { - var assem = Changeset.smartOpAssembler(); - var o = Changeset.newOp(); - var charBank = Changeset.stringAssembler(); - - var self = { - // attribs are [[key1,value1],[key2,value2],...] or '*0*1...' (no pool needed in latter case) - keep: function(N, L, attribs, pool) { - o.opcode = '='; - o.attribs = (attribs && - Changeset.makeAttribsString('=', attribs, pool)) || ''; - o.chars = N; - o.lines = (L || 0); - assem.append(o); - return self; - }, - keepText: function(text, attribs, pool) { - assem.appendOpWithText('=', text, attribs, pool); - return self; - }, - insert: function(text, attribs, pool) { - assem.appendOpWithText('+', text, attribs, pool); - charBank.append(text); - return self; - }, - remove: function(N, L) { - o.opcode = '-'; - o.attribs = ''; - o.chars = N; - o.lines = (L || 0); - assem.append(o); - return self; - }, - toString: function() { - assem.endDocument(); - var newLen = oldLen + assem.getLengthChange(); - return Changeset.pack(oldLen, newLen, assem.toString(), - charBank.toString()); - } - }; - - return self; -}; - -Changeset.makeAttribsString = function(opcode, attribs, pool) { - // makeAttribsString(opcode, '*3') or makeAttribsString(opcode, [['foo','bar']], myPool) work - if (! attribs) { - return ''; - } - else if ((typeof attribs) == "string") { - return attribs; - } - else if (pool && attribs && attribs.length) { - if (attribs.length > 1) { - attribs = attribs.slice(); - attribs.sort(); - } - var result = []; - for(var i=0;i<attribs.length;i++) { - var pair = attribs[i]; - if (opcode == '=' || (opcode == '+' && pair[1])) { - result.push('*'+Changeset.numToString(pool.putAttrib(pair))); - } - } - return result.join(''); - } -}; - -// like "substring" but on a single-line attribution string -Changeset.subattribution = function(astr, start, optEnd) { - var iter = Changeset.opIterator(astr, 0); - var assem = Changeset.smartOpAssembler(); - var attOp = Changeset.newOp(); - var csOp = Changeset.newOp(); - var opOut = Changeset.newOp(); - - function doCsOp() { - if (csOp.chars) { - while (csOp.opcode && (attOp.opcode || iter.hasNext())) { - if (! attOp.opcode) iter.next(attOp); - - if (csOp.opcode && attOp.opcode && csOp.chars >= attOp.chars && - attOp.lines > 0 && csOp.lines <= 0) { - csOp.lines++; - } - - Changeset._slicerZipperFunc(attOp, csOp, opOut, null); - if (opOut.opcode) { - assem.append(opOut); - opOut.opcode = ''; - } - } - } - } - - csOp.opcode = '-'; - csOp.chars = start; - - doCsOp(); - - if (optEnd === undefined) { - if (attOp.opcode) { - assem.append(attOp); - } - while (iter.hasNext()) { - iter.next(attOp); - assem.append(attOp); - } - } - else { - csOp.opcode = '='; - csOp.chars = optEnd - start; - doCsOp(); - } - - return assem.toString(); -}; - -Changeset.inverse = function(cs, lines, alines, pool) { - // lines and alines are what the changeset is meant to apply to. - // They may be arrays or objects with .get(i) and .length methods. - // They include final newlines on lines. - function lines_get(idx) { - if (lines.get) { - return lines.get(idx); - } - else { - return lines[idx]; - } - } - function lines_length() { - if ((typeof lines.length) == "number") { - return lines.length; - } - else { - return lines.length(); - } - } - function alines_get(idx) { - if (alines.get) { - return alines.get(idx); - } - else { - return alines[idx]; - } - } - function alines_length() { - if ((typeof alines.length) == "number") { - return alines.length; - } - else { - return alines.length(); - } - } - - var curLine = 0; - var curChar = 0; - var curLineOpIter = null; - var curLineOpIterLine; - var curLineNextOp = Changeset.newOp('+'); - - var unpacked = Changeset.unpack(cs); - var csIter = Changeset.opIterator(unpacked.ops); - var builder = Changeset.builder(unpacked.newLen); - - function consumeAttribRuns(numChars, func/*(len, attribs, endsLine)*/) { - - if ((! curLineOpIter) || (curLineOpIterLine != curLine)) { - // create curLineOpIter and advance it to curChar - curLineOpIter = Changeset.opIterator(alines_get(curLine)); - curLineOpIterLine = curLine; - var indexIntoLine = 0; - var done = false; - while (! done) { - curLineOpIter.next(curLineNextOp); - if (indexIntoLine + curLineNextOp.chars >= curChar) { - curLineNextOp.chars -= (curChar - indexIntoLine); - done = true; - } - else { - indexIntoLine += curLineNextOp.chars; - } - } - } - - while (numChars > 0) { - if ((! curLineNextOp.chars) && (! curLineOpIter.hasNext())) { - curLine++; - curChar = 0; - curLineOpIterLine = curLine; - curLineNextOp.chars = 0; - curLineOpIter = Changeset.opIterator(alines_get(curLine)); - } - if (! curLineNextOp.chars) { - curLineOpIter.next(curLineNextOp); - } - var charsToUse = Math.min(numChars, curLineNextOp.chars); - func(charsToUse, curLineNextOp.attribs, - charsToUse == curLineNextOp.chars && curLineNextOp.lines > 0); - numChars -= charsToUse; - curLineNextOp.chars -= charsToUse; - curChar += charsToUse; - } - - if ((! curLineNextOp.chars) && (! curLineOpIter.hasNext())) { - curLine++; - curChar = 0; - } - } - - function skip(N, L) { - if (L) { - curLine += L; - curChar = 0; - } - else { - if (curLineOpIter && curLineOpIterLine == curLine) { - consumeAttribRuns(N, function() {}); - } - else { - curChar += N; - } - } - } - - function nextText(numChars) { - var len = 0; - var assem = Changeset.stringAssembler(); - var firstString = lines_get(curLine).substring(curChar); - len += firstString.length; - assem.append(firstString); - - var lineNum = curLine+1; - while (len < numChars) { - var nextString = lines_get(lineNum); - len += nextString.length; - assem.append(nextString); - lineNum++; - } - - return assem.toString().substring(0, numChars); - } - - function cachedStrFunc(func) { - var cache = {}; - return function(s) { - if (! cache[s]) { - cache[s] = func(s); - } - return cache[s]; - }; - } - - var attribKeys = []; - var attribValues = []; - while (csIter.hasNext()) { - var csOp = csIter.next(); - if (csOp.opcode == '=') { - if (csOp.attribs) { - attribKeys.length = 0; - attribValues.length = 0; - Changeset.eachAttribNumber(csOp.attribs, function(n) { - attribKeys.push(pool.getAttribKey(n)); - attribValues.push(pool.getAttribValue(n)); - }); - var undoBackToAttribs = cachedStrFunc(function(attribs) { - var backAttribs = []; - for(var i=0;i<attribKeys.length;i++) { - var appliedKey = attribKeys[i]; - var appliedValue = attribValues[i]; - var oldValue = Changeset.attribsAttributeValue(attribs, appliedKey, pool); - if (appliedValue != oldValue) { - backAttribs.push([appliedKey, oldValue]); - } - } - return Changeset.makeAttribsString('=', backAttribs, pool); - }); - consumeAttribRuns(csOp.chars, function(len, attribs, endsLine) { - builder.keep(len, endsLine ? 1 : 0, undoBackToAttribs(attribs)); - }); - } - else { - skip(csOp.chars, csOp.lines); - builder.keep(csOp.chars, csOp.lines); - } - } - else if (csOp.opcode == '+') { - builder.remove(csOp.chars, csOp.lines); - } - else if (csOp.opcode == '-') { - var textBank = nextText(csOp.chars); - var textBankIndex = 0; - consumeAttribRuns(csOp.chars, function(len, attribs, endsLine) { - builder.insert(textBank.substr(textBankIndex, len), attribs); - textBankIndex += len; - }); - } - } - - return Changeset.checkRep(builder.toString()); -}; - -// %CLIENT FILE ENDS HERE% - -Changeset.follow = function(cs1, cs2, reverseInsertOrder, pool) { - var unpacked1 = Changeset.unpack(cs1); - var unpacked2 = Changeset.unpack(cs2); - var len1 = unpacked1.oldLen; - var len2 = unpacked2.oldLen; - Changeset.assert(len1 == len2, "mismatched follow"); - var chars1 = Changeset.stringIterator(unpacked1.charBank); - var chars2 = Changeset.stringIterator(unpacked2.charBank); - - var oldLen = unpacked1.newLen; - var oldPos = 0; - var newLen = 0; - - var hasInsertFirst = Changeset.attributeTester(['insertorder','first'], - pool); - - var newOps = Changeset.applyZip(unpacked1.ops, 0, unpacked2.ops, 0, function(op1, op2, opOut) { - if (op1.opcode == '+' || op2.opcode == '+') { - var whichToDo; - if (op2.opcode != '+') { - whichToDo = 1; - } - else if (op1.opcode != '+') { - whichToDo = 2; - } - else { - // both + - var firstChar1 = chars1.peek(1); - var firstChar2 = chars2.peek(1); - var insertFirst1 = hasInsertFirst(op1.attribs); - var insertFirst2 = hasInsertFirst(op2.attribs); - if (insertFirst1 && ! insertFirst2) { - whichToDo = 1; - } - else if (insertFirst2 && ! insertFirst1) { - whichToDo = 2; - } - // insert string that doesn't start with a newline first so as not to break up lines - else if (firstChar1 == '\n' && firstChar2 != '\n') { - whichToDo = 2; - } - else if (firstChar1 != '\n' && firstChar2 == '\n') { - whichToDo = 1; - } - // break symmetry: - else if (reverseInsertOrder) { - whichToDo = 2; - } - else { - whichToDo = 1; - } - } - if (whichToDo == 1) { - chars1.skip(op1.chars); - opOut.opcode = '='; - opOut.lines = op1.lines; - opOut.chars = op1.chars; - opOut.attribs = ''; - op1.opcode = ''; - } - else { - // whichToDo == 2 - chars2.skip(op2.chars); - Changeset.copyOp(op2, opOut); - op2.opcode = ''; - } - } - else if (op1.opcode == '-') { - if (! op2.opcode) { - op1.opcode = ''; - } - else { - if (op1.chars <= op2.chars) { - op2.chars -= op1.chars; - op2.lines -= op1.lines; - op1.opcode = ''; - if (! op2.chars) { - op2.opcode = ''; - } - } - else { - op1.chars -= op2.chars; - op1.lines -= op2.lines; - op2.opcode = ''; - } - } - } - else if (op2.opcode == '-') { - Changeset.copyOp(op2, opOut); - if (! op1.opcode) { - op2.opcode = ''; - } - else if (op2.chars <= op1.chars) { - // delete part or all of a keep - op1.chars -= op2.chars; - op1.lines -= op2.lines; - op2.opcode = ''; - if (! op1.chars) { - op1.opcode = ''; - } - } - else { - // delete all of a keep, and keep going - opOut.lines = op1.lines; - opOut.chars = op1.chars; - op2.lines -= op1.lines; - op2.chars -= op1.chars; - op1.opcode = ''; - } - } - else if (! op1.opcode) { - Changeset.copyOp(op2, opOut); - op2.opcode = ''; - } - else if (! op2.opcode) { - Changeset.copyOp(op1, opOut); - op1.opcode = ''; - } - else { - // both keeps - opOut.opcode = '='; - opOut.attribs = Changeset.followAttributes(op1.attribs, op2.attribs, pool); - if (op1.chars <= op2.chars) { - opOut.chars = op1.chars; - opOut.lines = op1.lines; - op2.chars -= op1.chars; - op2.lines -= op1.lines; - op1.opcode = ''; - if (! op2.chars) { - op2.opcode = ''; - } - } - else { - opOut.chars = op2.chars; - opOut.lines = op2.lines; - op1.chars -= op2.chars; - op1.lines -= op2.lines; - op2.opcode = ''; - } - } - switch (opOut.opcode) { - case '=': oldPos += opOut.chars; newLen += opOut.chars; break; - case '-': oldPos += opOut.chars; break; - case '+': newLen += opOut.chars; break; - } - }); - newLen += oldLen - oldPos; - - return Changeset.pack(oldLen, newLen, newOps, unpacked2.charBank); -}; - -Changeset.followAttributes = function(att1, att2, pool) { - // The merge of two sets of attribute changes to the same text - // takes the lexically-earlier value if there are two values - // for the same key. Otherwise, all key/value changes from - // both attribute sets are taken. This operation is the "follow", - // so a set of changes is produced that can be applied to att1 - // to produce the merged set. - if ((! att2) || (! pool)) return ''; - if (! att1) return att2; - var atts = []; - att2.replace(/\*([0-9a-z]+)/g, function(_, a) { - atts.push(pool.getAttrib(Changeset.parseNum(a))); - return ''; - }); - att1.replace(/\*([0-9a-z]+)/g, function(_, a) { - var pair1 = pool.getAttrib(Changeset.parseNum(a)); - for(var i=0;i<atts.length;i++) { - var pair2 = atts[i]; - if (pair1[0] == pair2[0]) { - if (pair1[1] <= pair2[1]) { - // winner of merge is pair1, delete this attribute - atts.splice(i, 1); - } - break; - } - } - return ''; - }); - // we've only removed attributes, so they're already sorted - var buf = Changeset.stringAssembler(); - for(var i=0;i<atts.length;i++) { - buf.append('*'); - buf.append(Changeset.numToString(pool.putAttrib(atts[i]))); - } - return buf.toString(); -}; diff --git a/etherpad/src/etherpad/collab/ace/easysync2_tests.js b/etherpad/src/etherpad/collab/ace/easysync2_tests.js deleted file mode 100644 index 7a23dc0..0000000 --- a/etherpad/src/etherpad/collab/ace/easysync2_tests.js +++ /dev/null @@ -1,877 +0,0 @@ -// DO NOT EDIT THIS FILE, edit infrastructure/ace/www/easysync2_tests.js -import("etherpad.collab.ace.easysync2.*") - -/** - * Copyright 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -function runTests() { - - function print(str) { - java.lang.System.out.println(str); - } - - function assert(code, optMsg) { - if (! eval(code)) throw new Error("FALSE: "+(optMsg || code)); - } - function literal(v) { - if ((typeof v) == "string") { - return '"'+v.replace(/[\\\"]/g, '\\$1').replace(/\n/g, '\\n')+'"'; - } - else return v.toSource(); - } - function assertEqualArrays(a, b) { - assert(literal(a)+".toSource() == "+literal(b)+".toSource()"); - } - function assertEqualStrings(a, b) { - assert(literal(a)+" == "+literal(b)); - } - - function throughIterator(opsStr) { - var iter = Changeset.opIterator(opsStr); - var assem = Changeset.opAssembler(); - while (iter.hasNext()) { - assem.append(iter.next()); - } - return assem.toString(); - } - - function throughSmartAssembler(opsStr) { - var iter = Changeset.opIterator(opsStr); - var assem = Changeset.smartOpAssembler(); - while (iter.hasNext()) { - assem.append(iter.next()); - } - assem.endDocument(); - return assem.toString(); - } - - (function() { - print("> throughIterator"); - var x = '-c*3*4+6|3=az*asdf0*1*2*3+1=1-1+1*0+1=1-1+1|c=c-1'; - assert("throughIterator("+literal(x)+") == "+literal(x)); - })(); - - (function() { - print("> throughSmartAssembler"); - var x = '-c*3*4+6|3=az*asdf0*1*2*3+1=1-1+1*0+1=1-1+1|c=c-1'; - assert("throughSmartAssembler("+literal(x)+") == "+literal(x)); - })(); - - function applyMutations(mu, arrayOfArrays) { - arrayOfArrays.forEach(function (a) { - var result = mu[a[0]].apply(mu, a.slice(1)); - if (a[0] == 'remove' && a[3]) { - assertEqualStrings(a[3], result); - } - }); - } - - function mutationsToChangeset(oldLen, arrayOfArrays) { - var assem = Changeset.smartOpAssembler(); - var op = Changeset.newOp(); - var bank = Changeset.stringAssembler(); - var oldPos = 0; - var newLen = 0; - arrayOfArrays.forEach(function (a) { - if (a[0] == 'skip') { - op.opcode = '='; - op.chars = a[1]; - op.lines = (a[2] || 0); - assem.append(op); - oldPos += op.chars; - newLen += op.chars; - } - else if (a[0] == 'remove') { - op.opcode = '-'; - op.chars = a[1]; - op.lines = (a[2] || 0); - assem.append(op); - oldPos += op.chars; - } - else if (a[0] == 'insert') { - op.opcode = '+'; - bank.append(a[1]); - op.chars = a[1].length; - op.lines = (a[2] || 0); - assem.append(op); - newLen += op.chars; - } - }); - newLen += oldLen - oldPos; - assem.endDocument(); - return Changeset.pack(oldLen, newLen, assem.toString(), - bank.toString()); - } - - function runMutationTest(testId, origLines, muts, correct) { - print("> runMutationTest#"+testId); - var lines = origLines.slice(); - var mu = Changeset.textLinesMutator(lines); - applyMutations(mu, muts); - mu.close(); - assertEqualArrays(correct, lines); - - var inText = origLines.join(''); - var cs = mutationsToChangeset(inText.length, muts); - lines = origLines.slice(); - Changeset.mutateTextLines(cs, lines); - assertEqualArrays(correct, lines); - - var correctText = correct.join(''); - //print(literal(cs)); - var outText = Changeset.applyToText(cs, inText); - assertEqualStrings(correctText, outText); - } - - runMutationTest(1, ["apple\n", "banana\n", "cabbage\n", "duffle\n", "eggplant\n"], - [['remove',1,0,"a"],['insert',"tu"],['remove',1,0,"p"],['skip',4,1],['skip',7,1], - ['insert',"cream\npie\n",2],['skip',2],['insert',"bot"],['insert',"\n",1], - ['insert',"bu"],['skip',3],['remove',3,1,"ge\n"],['remove',6,0,"duffle"]], - ["tuple\n","banana\n","cream\n","pie\n", "cabot\n","bubba\n","eggplant\n"]); - - runMutationTest(2, ["apple\n", "banana\n", "cabbage\n", "duffle\n", "eggplant\n"], - [['remove',1,0,"a"],['remove',1,0,"p"],['insert',"tu"],['skip',11,2], - ['insert',"cream\npie\n",2],['skip',2],['insert',"bot"],['insert',"\n",1], - ['insert',"bu"],['skip',3],['remove',3,1,"ge\n"],['remove',6,0,"duffle"]], - ["tuple\n","banana\n","cream\n","pie\n", "cabot\n","bubba\n","eggplant\n"]); - - runMutationTest(3, ["apple\n", "banana\n", "cabbage\n", "duffle\n", "eggplant\n"], - [['remove',6,1,"apple\n"],['skip',15,2],['skip',6],['remove',1,1,"\n"], - ['remove',8,0,"eggplant"],['skip',1,1]], - ["banana\n","cabbage\n","duffle\n"]); - - runMutationTest(4, ["15\n"], - [['skip',1],['insert',"\n2\n3\n4\n",4],['skip',2,1]], - ["1\n","2\n","3\n","4\n","5\n"]); - - runMutationTest(5, ["1\n","2\n","3\n","4\n","5\n"], - [['skip',1],['remove',7,4,"\n2\n3\n4\n"],['skip',2,1]], - ["15\n"]); - - runMutationTest(6, ["123\n","abc\n","def\n","ghi\n","xyz\n"], - [['insert',"0"],['skip',4,1],['skip',4,1],['remove',8,2,"def\nghi\n"],['skip',4,1]], - ["0123\n", "abc\n", "xyz\n"]); - - runMutationTest(7, ["apple\n", "banana\n", "cabbage\n", "duffle\n", "eggplant\n"], - [['remove',6,1,"apple\n"],['skip',15,2,true],['skip',6,0,true],['remove',1,1,"\n"], - ['remove',8,0,"eggplant"],['skip',1,1,true]], - ["banana\n","cabbage\n","duffle\n"]); - - function poolOrArray(attribs) { - if (attribs.getAttrib) { - return attribs; // it's already an attrib pool - } - else { - // assume it's an array of attrib strings to be split and added - var p = new AttribPool(); - attribs.forEach(function (kv) { p.putAttrib(kv.split(',')); }); - return p; - } - } - - function runApplyToAttributionTest(testId, attribs, cs, inAttr, outCorrect) { - print("> applyToAttribution#"+testId); - var p = poolOrArray(attribs); - var result = Changeset.applyToAttribution( - Changeset.checkRep(cs), inAttr, p); - assertEqualStrings(outCorrect, result); - } - - // turn c<b>a</b>ctus\n into a<b>c</b>tusabcd\n - runApplyToAttributionTest(1, ['bold,', 'bold,true'], - "Z:7>3-1*0=1*1=1=3+4$abcd", - "+1*1+1|1+5", "+1*1+1|1+8"); - - // turn "david\ngreenspan\n" into "<b>david\ngreen</b>\n" - runApplyToAttributionTest(2, ['bold,', 'bold,true'], - "Z:g<4*1|1=6*1=5-4$", - "|2+g", "*1|1+6*1+5|1+1"); - - (function() { - print("> mutatorHasMore"); - var lines = ["1\n", "2\n", "3\n", "4\n"]; - var mu; - - mu = Changeset.textLinesMutator(lines); - assert(mu.hasMore()+' == true'); - mu.skip(8,4); - assert(mu.hasMore()+' == false'); - mu.close(); - assert(mu.hasMore()+' == false'); - - // still 1,2,3,4 - mu = Changeset.textLinesMutator(lines); - assert(mu.hasMore()+' == true'); - mu.remove(2,1); - assert(mu.hasMore()+' == true'); - mu.skip(2,1); - assert(mu.hasMore()+' == true'); - mu.skip(2,1); - assert(mu.hasMore()+' == true'); - mu.skip(2,1); - assert(mu.hasMore()+' == false'); - mu.insert("5\n", 1); - assert(mu.hasMore()+' == false'); - mu.close(); - assert(mu.hasMore()+' == false'); - - // 2,3,4,5 now - mu = Changeset.textLinesMutator(lines); - assert(mu.hasMore()+' == true'); - mu.remove(6,3); - assert(mu.hasMore()+' == true'); - mu.remove(2,1); - assert(mu.hasMore()+' == false'); - mu.insert("hello\n", 1); - assert(mu.hasMore()+' == false'); - mu.close(); - assert(mu.hasMore()+' == false'); - - })(); - - function runMutateAttributionTest(testId, attribs, cs, alines, outCorrect) { - print("> runMutateAttributionTest#"+testId); - var p = poolOrArray(attribs); - var alines2 = Array.prototype.slice.call(alines); - var result = Changeset.mutateAttributionLines( - Changeset.checkRep(cs), alines2, p); - assertEqualArrays(outCorrect, alines2); - - print("> runMutateAttributionTest#"+testId+".applyToAttribution"); - function removeQuestionMarks(a) { return a.replace(/\?/g, ''); } - var inMerged = Changeset.joinAttributionLines(alines.map(removeQuestionMarks)); - var correctMerged = Changeset.joinAttributionLines(outCorrect.map(removeQuestionMarks)); - var mergedResult = Changeset.applyToAttribution(cs, inMerged, p); - assertEqualStrings(correctMerged, mergedResult); - } - - // turn 123\n 456\n 789\n into 123\n 4<b>5</b>6\n 789\n - runMutateAttributionTest(1, ["bold,true"], "Z:c>0|1=4=1*0=1$", ["|1+4", "|1+4", "|1+4"], - ["|1+4", "+1*0+1|1+2", "|1+4"]); - - // make a document bold - runMutateAttributionTest(2, ["bold,true"], "Z:c>0*0|3=c$", ["|1+4", "|1+4", "|1+4"], - ["*0|1+4", "*0|1+4", "*0|1+4"]); - - // clear bold on document - runMutateAttributionTest(3, ["bold,","bold,true"], "Z:c>0*0|3=c$", - ["*1+1+1*1+1|1+1", "+1*1+1|1+2", "*1+1+1*1+1|1+1"], - ["|1+4", "|1+4", "|1+4"]); - - // add a character on line 3 of a document with 5 blank lines, and make sure - // the optimization that skips purely-kept lines is working; if any attribution string - // with a '?' is parsed it will cause an error. - runMutateAttributionTest(4, ['foo,bar','line,1','line,2','line,3','line,4','line,5'], - "Z:5>1|2=2+1$x", - ["?*1|1+1", "?*2|1+1", "*3|1+1", "?*4|1+1", "?*5|1+1"], - ["?*1|1+1", "?*2|1+1", "+1*3|1+1", "?*4|1+1", "?*5|1+1"]); - - var testPoolWithChars = (function() { - var p = new AttribPool(); - p.putAttrib(['char','newline']); - for(var i=1;i<36;i++) { - p.putAttrib(['char',Changeset.numToString(i)]); - } - p.putAttrib(['char','']); - return p; - })(); - - // based on runMutationTest#1 - runMutateAttributionTest(5, testPoolWithChars, - "Z:11>7-2*t+1*u+1|2=b|2+a=2*b+1*o+1*t+1*0|1+1*b+1*u+1=3|1-3-6$"+ - "tucream\npie\nbot\nbu", - ["*a+1*p+2*l+1*e+1*0|1+1", - "*b+1*a+1*n+1*a+1*n+1*a+1*0|1+1", - "*c+1*a+1*b+2*a+1*g+1*e+1*0|1+1", - "*d+1*u+1*f+2*l+1*e+1*0|1+1", - "*e+1*g+2*p+1*l+1*a+1*n+1*t+1*0|1+1"], - ["*t+1*u+1*p+1*l+1*e+1*0|1+1", - "*b+1*a+1*n+1*a+1*n+1*a+1*0|1+1", - "|1+6", - "|1+4", - "*c+1*a+1*b+1*o+1*t+1*0|1+1", - "*b+1*u+1*b+2*a+1*0|1+1", - "*e+1*g+2*p+1*l+1*a+1*n+1*t+1*0|1+1"]); - - // based on runMutationTest#3 - runMutateAttributionTest(6, testPoolWithChars, - "Z:11<f|1-6|2=f=6|1-1-8$", - ["*a|1+6", "*b|1+7", "*c|1+8", "*d|1+7", "*e|1+9"], - ["*b|1+7", "*c|1+8", "*d+6*e|1+1"]); - - // based on runMutationTest#4 - runMutateAttributionTest(7, testPoolWithChars, - "Z:3>7=1|4+7$\n2\n3\n4\n", - ["*1+1*5|1+2"], - ["*1+1|1+1","|1+2","|1+2","|1+2","*5|1+2"]); - - // based on runMutationTest#5 - runMutateAttributionTest(8, testPoolWithChars, - "Z:a<7=1|4-7$", - ["*1|1+2","*2|1+2","*3|1+2","*4|1+2","*5|1+2"], - ["*1+1*5|1+2"]); - - // based on runMutationTest#6 - runMutateAttributionTest(9, testPoolWithChars, - "Z:k<7*0+1*10|2=8|2-8$0", - ["*1+1*2+1*3+1|1+1","*a+1*b+1*c+1|1+1", - "*d+1*e+1*f+1|1+1","*g+1*h+1*i+1|1+1","?*x+1*y+1*z+1|1+1"], - ["*0+1|1+4", "|1+4", "?*x+1*y+1*z+1|1+1"]); - - runMutateAttributionTest(10, testPoolWithChars, - "Z:6>4=1+1=1+1|1=1+1=1*0+1$abcd", - ["|1+3", "|1+3"], - ["|1+5", "+2*0+1|1+2"]); - - - runMutateAttributionTest(11, testPoolWithChars, - "Z:s>1|1=4=6|1+1$\n", - ["*0|1+4", "*0|1+8", "*0+5|1+1", "*0|1+1", "*0|1+5", "*0|1+1", "*0|1+1", "*0|1+1", "|1+1"], - ["*0|1+4", "*0+6|1+1", "*0|1+2", "*0+5|1+1", "*0|1+1", "*0|1+5", "*0|1+1", "*0|1+1", "*0|1+1", "|1+1"]); - - function randomInlineString(len, rand) { - var assem = Changeset.stringAssembler(); - for(var i=0;i<len;i++) { - assem.append(String.fromCharCode(rand.nextInt(26) + 97)); - } - return assem.toString(); - } - - function randomMultiline(approxMaxLines, approxMaxCols, rand) { - var numParts = rand.nextInt(approxMaxLines*2)+1; - var txt = Changeset.stringAssembler(); - txt.append(rand.nextInt(2) ? '\n' : ''); - for(var i=0;i<numParts;i++) { - if ((i % 2) == 0) { - if (rand.nextInt(10)) { - txt.append(randomInlineString(rand.nextInt(approxMaxCols)+1, rand)); - } - else { - txt.append('\n'); - } - } - else { - txt.append('\n'); - } - } - return txt.toString(); - } - - function randomStringOperation(numCharsLeft, rand) { - var result; - switch(rand.nextInt(9)) { - case 0: { - // insert char - result = {insert: randomInlineString(1, rand)}; - break; - } - case 1: { - // delete char - result = {remove: 1}; - break; - } - case 2: { - // skip char - result = {skip: 1}; - break; - } - case 3: { - // insert small - result = {insert: randomInlineString(rand.nextInt(4)+1, rand)}; - break; - } - case 4: { - // delete small - result = {remove: rand.nextInt(4)+1}; - break; - } - case 5: { - // skip small - result = {skip: rand.nextInt(4)+1}; - break; - } - case 6: { - // insert multiline; - result = {insert: randomMultiline(5, 20, rand)}; - break; - } - case 7: { - // delete multiline - result = {remove: Math.round(numCharsLeft * rand.nextDouble() * rand.nextDouble()) }; - break; - } - case 8: { - // skip multiline - result = {skip: Math.round(numCharsLeft * rand.nextDouble() * rand.nextDouble()) }; - break; - } - case 9: { - // delete to end - result = {remove: numCharsLeft}; - break; - } - case 10: { - // skip to end - result = {skip: numCharsLeft}; - break; - } - } - var maxOrig = numCharsLeft - 1; - if ('remove' in result) { - result.remove = Math.min(result.remove, maxOrig); - } - else if ('skip' in result) { - result.skip = Math.min(result.skip, maxOrig); - } - return result; - } - - function randomTwoPropAttribs(opcode, rand) { - // assumes attrib pool like ['apple,','apple,true','banana,','banana,true'] - if (opcode == '-' || rand.nextInt(3)) { - return ''; - } - else if (rand.nextInt(3)) { - if (opcode == '+' || rand.nextInt(2)) { - return '*'+Changeset.numToString(rand.nextInt(2)*2+1); - } - else { - return '*'+Changeset.numToString(rand.nextInt(2)*2); - } - } - else { - if (opcode == '+' || rand.nextInt(4) == 0) { - return '*1*3'; - } - else { - return ['*0*2', '*0*3', '*1*2'][rand.nextInt(3)]; - } - } - } - - function randomTestChangeset(origText, rand, withAttribs) { - var charBank = Changeset.stringAssembler(); - var textLeft = origText; // always keep final newline - var outTextAssem = Changeset.stringAssembler(); - var opAssem = Changeset.smartOpAssembler(); - var oldLen = origText.length; - - var nextOp = Changeset.newOp(); - function appendMultilineOp(opcode, txt) { - nextOp.opcode = opcode; - if (withAttribs) { - nextOp.attribs = randomTwoPropAttribs(opcode, rand); - } - txt.replace(/\n|[^\n]+/g, function (t) { - if (t == '\n') { - nextOp.chars = 1; - nextOp.lines = 1; - opAssem.append(nextOp); - } - else { - nextOp.chars = t.length; - nextOp.lines = 0; - opAssem.append(nextOp); - } - return ''; - }); - } - - function doOp() { - var o = randomStringOperation(textLeft.length, rand); - if (o.insert) { - var txt = o.insert; - charBank.append(txt); - outTextAssem.append(txt); - appendMultilineOp('+', txt); - } - else if (o.skip) { - var txt = textLeft.substring(0, o.skip); - textLeft = textLeft.substring(o.skip); - outTextAssem.append(txt); - appendMultilineOp('=', txt); - } - else if (o.remove) { - var txt = textLeft.substring(0, o.remove); - textLeft = textLeft.substring(o.remove); - appendMultilineOp('-', txt); - } - } - - while (textLeft.length > 1) doOp(); - for(var i=0;i<5;i++) doOp(); // do some more (only insertions will happen) - - var outText = outTextAssem.toString()+'\n'; - opAssem.endDocument(); - var cs = Changeset.pack(oldLen, outText.length, opAssem.toString(), charBank.toString()); - Changeset.checkRep(cs); - return [cs, outText]; - } - - function testCompose(randomSeed) { - var rand = new java.util.Random(randomSeed); - print("> testCompose#"+randomSeed); - - var p = new AttribPool(); - - var startText = randomMultiline(10, 20, rand)+'\n'; - - var x1 = randomTestChangeset(startText, rand); - var change1 = x1[0]; - var text1 = x1[1]; - - var x2 = randomTestChangeset(text1, rand); - var change2 = x2[0]; - var text2 = x2[1]; - - var x3 = randomTestChangeset(text2, rand); - var change3 = x3[0]; - var text3 = x3[1]; - - //print(literal(Changeset.toBaseTen(startText))); - //print(literal(Changeset.toBaseTen(change1))); - //print(literal(Changeset.toBaseTen(change2))); - var change12 = Changeset.checkRep(Changeset.compose(change1, change2, p)); - var change23 = Changeset.checkRep(Changeset.compose(change2, change3, p)); - var change123 = Changeset.checkRep(Changeset.compose(change12, change3, p)); - var change123a = Changeset.checkRep(Changeset.compose(change1, change23, p)); - assertEqualStrings(change123, change123a); - - assertEqualStrings(text2, Changeset.applyToText(change12, startText)); - assertEqualStrings(text3, Changeset.applyToText(change23, text1)); - assertEqualStrings(text3, Changeset.applyToText(change123, startText)); - } - - for(var i=0;i<30;i++) testCompose(i); - - (function simpleComposeAttributesTest() { - print("> simpleComposeAttributesTest"); - var p = new AttribPool(); - p.putAttrib(['bold','']); - p.putAttrib(['bold','true']); - var cs1 = Changeset.checkRep("Z:2>1*1+1*1=1$x"); - var cs2 = Changeset.checkRep("Z:3>0*0|1=3$"); - var cs12 = Changeset.checkRep(Changeset.compose(cs1, cs2, p)); - assertEqualStrings("Z:2>1+1*0|1=2$x", cs12); - })(); - - (function followAttributesTest() { - var p = new AttribPool(); - p.putAttrib(['x','']); - p.putAttrib(['x','abc']); - p.putAttrib(['x','def']); - p.putAttrib(['y','']); - p.putAttrib(['y','abc']); - p.putAttrib(['y','def']); - - function testFollow(a, b, afb, bfa, merge) { - assertEqualStrings(afb, Changeset.followAttributes(a, b, p)); - assertEqualStrings(bfa, Changeset.followAttributes(b, a, p)); - assertEqualStrings(merge, Changeset.composeAttributes(a, afb, true, p)); - assertEqualStrings(merge, Changeset.composeAttributes(b, bfa, true, p)); - } - - testFollow('', '', '', '', ''); - testFollow('*0', '', '', '*0', '*0'); - testFollow('*0', '*0', '', '', '*0'); - testFollow('*0', '*1', '', '*0', '*0'); - testFollow('*1', '*2', '', '*1', '*1'); - testFollow('*0*1', '', '', '*0*1', '*0*1'); - testFollow('*0*4', '*2*3', '*3', '*0', '*0*3'); - testFollow('*0*4', '*2', '', '*0*4', '*0*4'); - })(); - - function testFollow(randomSeed) { - var rand = new java.util.Random(randomSeed + 1000); - print("> testFollow#"+randomSeed); - - var p = new AttribPool(); - - var startText = randomMultiline(10, 20, rand)+'\n'; - - var cs1 = randomTestChangeset(startText, rand)[0]; - var cs2 = randomTestChangeset(startText, rand)[0]; - - var afb = Changeset.checkRep(Changeset.follow(cs1, cs2, false, p)); - var bfa = Changeset.checkRep(Changeset.follow(cs2, cs1, true, p)); - - var merge1 = Changeset.checkRep(Changeset.compose(cs1, afb)); - var merge2 = Changeset.checkRep(Changeset.compose(cs2, bfa)); - - assertEqualStrings(merge1, merge2); - } - - for(var i=0;i<30;i++) testFollow(i); - - function testSplitJoinAttributionLines(randomSeed) { - var rand = new java.util.Random(randomSeed + 2000); - print("> testSplitJoinAttributionLines#"+randomSeed); - - var doc = randomMultiline(10, 20, rand)+'\n'; - - function stringToOps(str) { - var assem = Changeset.mergingOpAssembler(); - var o = Changeset.newOp('+'); - o.chars = 1; - for(var i=0;i<str.length;i++) { - var c = str.charAt(i); - o.lines = (c == '\n' ? 1 : 0); - o.attribs = (c == 'a' || c == 'b' ? '*'+c : ''); - assem.append(o); - } - return assem.toString(); - } - - var theJoined = stringToOps(doc); - var theSplit = doc.match(/[^\n]*\n/g).map(stringToOps); - - assertEqualArrays(theSplit, Changeset.splitAttributionLines(theJoined, doc)); - assertEqualStrings(theJoined, Changeset.joinAttributionLines(theSplit)); - } - - for(var i=0;i<10;i++) testSplitJoinAttributionLines(i); - - (function testMoveOpsToNewPool() { - print("> testMoveOpsToNewPool"); - - var pool1 = new AttribPool(); - var pool2 = new AttribPool(); - - pool1.putAttrib(['baz','qux']); - pool1.putAttrib(['foo','bar']); - - pool2.putAttrib(['foo','bar']); - - assertEqualStrings(Changeset.moveOpsToNewPool('Z:1>2*1+1*0+1$ab', pool1, pool2), 'Z:1>2*0+1*1+1$ab'); - assertEqualStrings(Changeset.moveOpsToNewPool('*1+1*0+1', pool1, pool2), '*0+1*1+1'); - })(); - - - (function testMakeSplice() { - print("> testMakeSplice"); - - var t = "a\nb\nc\n"; - var t2 = Changeset.applyToText(Changeset.makeSplice(t, 5, 0, "def"), t); - assertEqualStrings("a\nb\ncdef\n", t2); - - })(); - - (function testToSplices() { - print("> testToSplices"); - - var cs = Changeset.checkRep('Z:z>9*0=1=4-3+9=1|1-4-4+1*0+a$123456789abcdefghijk'); - var correctSplices = [[5, 8, "123456789"], [9, 17, "abcdefghijk"]]; - assertEqualArrays(correctSplices, Changeset.toSplices(cs)); - })(); - - function testCharacterRangeFollow(testId, cs, oldRange, insertionsAfter, correctNewRange) { - print("> testCharacterRangeFollow#"+testId); - - var cs = Changeset.checkRep(cs); - assertEqualArrays(correctNewRange, Changeset.characterRangeFollow(cs, oldRange[0], oldRange[1], - insertionsAfter)); - - } - - testCharacterRangeFollow(1, 'Z:z>9*0=1=4-3+9=1|1-4-4+1*0+a$123456789abcdefghijk', - [7, 10], false, [14, 15]); - testCharacterRangeFollow(2, "Z:bc<6|x=b4|2-6$", [400, 407], false, [400, 401]); - testCharacterRangeFollow(3, "Z:4>0-3+3$abc", [0,3], false, [3,3]); - testCharacterRangeFollow(4, "Z:4>0-3+3$abc", [0,3], true, [0,0]); - testCharacterRangeFollow(5, "Z:5>1+1=1-3+3$abcd", [1,4], false, [5,5]); - testCharacterRangeFollow(6, "Z:5>1+1=1-3+3$abcd", [1,4], true, [2,2]); - testCharacterRangeFollow(7, "Z:5>1+1=1-3+3$abcd", [0,6], false, [1,7]); - testCharacterRangeFollow(8, "Z:5>1+1=1-3+3$abcd", [0,3], false, [1,2]); - testCharacterRangeFollow(9, "Z:5>1+1=1-3+3$abcd", [2,5], false, [5,6]); - testCharacterRangeFollow(10, "Z:2>1+1$a", [0,0], false, [1,1]); - testCharacterRangeFollow(11, "Z:2>1+1$a", [0,0], true, [0,0]); - - (function testOpAttributeValue() { - print("> testOpAttributeValue"); - - var p = new AttribPool(); - p.putAttrib(['name','david']); - p.putAttrib(['color','green']); - - assertEqualStrings("david", Changeset.opAttributeValue(Changeset.stringOp('*0*1+1'), 'name', p)); - assertEqualStrings("david", Changeset.opAttributeValue(Changeset.stringOp('*0+1'), 'name', p)); - assertEqualStrings("", Changeset.opAttributeValue(Changeset.stringOp('*1+1'), 'name', p)); - assertEqualStrings("", Changeset.opAttributeValue(Changeset.stringOp('+1'), 'name', p)); - assertEqualStrings("green", Changeset.opAttributeValue(Changeset.stringOp('*0*1+1'), 'color', p)); - assertEqualStrings("green", Changeset.opAttributeValue(Changeset.stringOp('*1+1'), 'color', p)); - assertEqualStrings("", Changeset.opAttributeValue(Changeset.stringOp('*0+1'), 'color', p)); - assertEqualStrings("", Changeset.opAttributeValue(Changeset.stringOp('+1'), 'color', p)); - })(); - - function testAppendATextToAssembler(testId, atext, correctOps) { - print("> testAppendATextToAssembler#"+testId); - - var assem = Changeset.smartOpAssembler(); - Changeset.appendATextToAssembler(atext, assem); - assertEqualStrings(correctOps, assem.toString()); - } - - testAppendATextToAssembler(1, {text:"\n", attribs:"|1+1"}, ""); - testAppendATextToAssembler(2, {text:"\n\n", attribs:"|2+2"}, "|1+1"); - testAppendATextToAssembler(3, {text:"\n\n", attribs:"*x|2+2"}, "*x|1+1"); - testAppendATextToAssembler(4, {text:"\n\n", attribs:"*x|1+1|1+1"}, "*x|1+1"); - testAppendATextToAssembler(5, {text:"foo\n", attribs:"|1+4"}, "+3"); - testAppendATextToAssembler(6, {text:"\nfoo\n", attribs:"|2+5"}, "|1+1+3"); - testAppendATextToAssembler(7, {text:"\nfoo\n", attribs:"*x|2+5"}, "*x|1+1*x+3"); - testAppendATextToAssembler(8, {text:"\n\n\nfoo\n", attribs:"|2+2*x|2+5"}, "|2+2*x|1+1*x+3"); - - function testMakeAttribsString(testId, pool, opcode, attribs, correctString) { - print("> testMakeAttribsString#"+testId); - - var p = poolOrArray(pool); - var str = Changeset.makeAttribsString(opcode, attribs, p); - assertEqualStrings(correctString, str); - } - - testMakeAttribsString(1, ['bold,'], '+', [['bold','']], ''); - testMakeAttribsString(2, ['abc,def','bold,'], '=', [['bold','']], '*1'); - testMakeAttribsString(3, ['abc,def','bold,true'], '+', [['abc','def'],['bold','true']], '*0*1'); - testMakeAttribsString(4, ['abc,def','bold,true'], '+', [['bold','true'],['abc','def']], '*0*1'); - - function testSubattribution(testId, astr, start, end, correctOutput) { - print("> testSubattribution#"+testId); - - var str = Changeset.subattribution(astr, start, end); - assertEqualStrings(correctOutput, str); - } - - testSubattribution(1, "+1", 0, 0, ""); - testSubattribution(2, "+1", 0, 1, "+1"); - testSubattribution(3, "+1", 0, undefined, "+1"); - testSubattribution(4, "|1+1", 0, 0, ""); - testSubattribution(5, "|1+1", 0, 1, "|1+1"); - testSubattribution(6, "|1+1", 0, undefined, "|1+1"); - testSubattribution(7, "*0+1", 0, 0, ""); - testSubattribution(8, "*0+1", 0, 1, "*0+1"); - testSubattribution(9, "*0+1", 0, undefined, "*0+1"); - testSubattribution(10, "*0|1+1", 0, 0, ""); - testSubattribution(11, "*0|1+1", 0, 1, "*0|1+1"); - testSubattribution(12, "*0|1+1", 0, undefined, "*0|1+1"); - testSubattribution(13, "*0+2+1*1+3", 0, 1, "*0+1"); - testSubattribution(14, "*0+2+1*1+3", 0, 2, "*0+2"); - testSubattribution(15, "*0+2+1*1+3", 0, 3, "*0+2+1"); - testSubattribution(16, "*0+2+1*1+3", 0, 4, "*0+2+1*1+1"); - testSubattribution(17, "*0+2+1*1+3", 0, 5, "*0+2+1*1+2"); - testSubattribution(18, "*0+2+1*1+3", 0, 6, "*0+2+1*1+3"); - testSubattribution(19, "*0+2+1*1+3", 0, 7, "*0+2+1*1+3"); - testSubattribution(20, "*0+2+1*1+3", 0, undefined, "*0+2+1*1+3"); - testSubattribution(21, "*0+2+1*1+3", 1, undefined, "*0+1+1*1+3"); - testSubattribution(22, "*0+2+1*1+3", 2, undefined, "+1*1+3"); - testSubattribution(23, "*0+2+1*1+3", 3, undefined, "*1+3"); - testSubattribution(24, "*0+2+1*1+3", 4, undefined, "*1+2"); - testSubattribution(25, "*0+2+1*1+3", 5, undefined, "*1+1"); - testSubattribution(26, "*0+2+1*1+3", 6, undefined, ""); - testSubattribution(27, "*0+2+1*1|1+3", 0, 1, "*0+1"); - testSubattribution(28, "*0+2+1*1|1+3", 0, 2, "*0+2"); - testSubattribution(29, "*0+2+1*1|1+3", 0, 3, "*0+2+1"); - testSubattribution(30, "*0+2+1*1|1+3", 0, 4, "*0+2+1*1+1"); - testSubattribution(31, "*0+2+1*1|1+3", 0, 5, "*0+2+1*1+2"); - testSubattribution(32, "*0+2+1*1|1+3", 0, 6, "*0+2+1*1|1+3"); - testSubattribution(33, "*0+2+1*1|1+3", 0, 7, "*0+2+1*1|1+3"); - testSubattribution(34, "*0+2+1*1|1+3", 0, undefined, "*0+2+1*1|1+3"); - testSubattribution(35, "*0+2+1*1|1+3", 1, undefined, "*0+1+1*1|1+3"); - testSubattribution(36, "*0+2+1*1|1+3", 2, undefined, "+1*1|1+3"); - testSubattribution(37, "*0+2+1*1|1+3", 3, undefined, "*1|1+3"); - testSubattribution(38, "*0+2+1*1|1+3", 4, undefined, "*1|1+2"); - testSubattribution(39, "*0+2+1*1|1+3", 5, undefined, "*1|1+1"); - testSubattribution(40, "*0+2+1*1|1+3", 1, 5, "*0+1+1*1+2"); - testSubattribution(41, "*0+2+1*1|1+3", 2, 6, "+1*1|1+3"); - testSubattribution(42, "*0+2+1*1+3", 2, 6, "+1*1+3"); - - function testFilterAttribNumbers(testId, cs, filter, correctOutput) { - print("> testFilterAttribNumbers#"+testId); - - var str = Changeset.filterAttribNumbers(cs, filter); - assertEqualStrings(correctOutput, str); - } - - testFilterAttribNumbers(1, "*0*1+1+2+3*1+4*2+5*0*2*1*b*c+6", - function(n) { return (n%2) == 0; }, - "*0+1+2+3+4*2+5*0*2*c+6"); - testFilterAttribNumbers(2, "*0*1+1+2+3*1+4*2+5*0*2*1*b*c+6", - function(n) { return (n%2) == 1; }, - "*1+1+2+3*1+4+5*1*b+6"); - - function testInverse(testId, cs, lines, alines, pool, correctOutput) { - print("> testInverse#"+testId); - - pool = poolOrArray(pool); - var str = Changeset.inverse(Changeset.checkRep(cs), lines, alines, pool); - assertEqualStrings(correctOutput, str); - } - - // take "FFFFTTTTT" and apply "-FT--FFTT", the inverse of which is "--F--TT--" - testInverse(1, "Z:9>0=1*0=1*1=1=2*0=2*1|1=2$", null, ["+4*1+5"], ['bold,','bold,true'], - "Z:9>0=2*0=1=2*1=2$"); - - function testMutateTextLines(testId, cs, lines, correctLines) { - print("> testMutateTextLines#"+testId); - - var a = lines.slice(); - Changeset.mutateTextLines(cs, a); - assertEqualArrays(correctLines, a); - } - - testMutateTextLines(1, "Z:4<1|1-2-1|1+1+1$\nc", ["a\n", "b\n"], ["\n", "c\n"]); - testMutateTextLines(2, "Z:4>0|1-2-1|2+3$\nc\n", ["a\n", "b\n"], ["\n", "c\n", "\n"]); - - function testInverseRandom(randomSeed) { - var rand = new java.util.Random(randomSeed + 3000); - print("> testInverseRandom#"+randomSeed); - - var p = poolOrArray(['apple,','apple,true','banana,','banana,true']); - - var startText = randomMultiline(10, 20, rand)+'\n'; - var alines = Changeset.splitAttributionLines(Changeset.makeAttribution(startText), startText); - var lines = startText.slice(0,-1).split('\n').map(function(s) { return s+'\n'; }); - - var stylifier = randomTestChangeset(startText, rand, true)[0]; - - //print(alines.join('\n')); - Changeset.mutateAttributionLines(stylifier, alines, p); - //print(stylifier); - //print(alines.join('\n')); - Changeset.mutateTextLines(stylifier, lines); - - var changeset = randomTestChangeset(lines.join(''), rand, true)[0]; - var inverseChangeset = Changeset.inverse(changeset, lines, alines, p); - - var origLines = lines.slice(); - var origALines = alines.slice(); - - Changeset.mutateTextLines(changeset, lines); - Changeset.mutateAttributionLines(changeset, alines, p); - //print(origALines.join('\n')); - //print(changeset); - //print(inverseChangeset); - //print(origLines.map(function(s) { return '1: '+s.slice(0,-1); }).join('\n')); - //print(lines.map(function(s) { return '2: '+s.slice(0,-1); }).join('\n')); - //print(alines.join('\n')); - Changeset.mutateTextLines(inverseChangeset, lines); - Changeset.mutateAttributionLines(inverseChangeset, alines, p); - //print(lines.map(function(s) { return '3: '+s.slice(0,-1); }).join('\n')); - - assertEqualArrays(origLines, lines); - assertEqualArrays(origALines, alines); - } - - for(var i=0;i<30;i++) testInverseRandom(i); -}
\ No newline at end of file diff --git a/etherpad/src/etherpad/collab/ace/linestylefilter.js b/etherpad/src/etherpad/collab/ace/linestylefilter.js deleted file mode 100644 index ffc8034..0000000 --- a/etherpad/src/etherpad/collab/ace/linestylefilter.js +++ /dev/null @@ -1,247 +0,0 @@ -// DO NOT EDIT THIS FILE, edit infrastructure/ace/www/linestylefilter.js -import("etherpad.collab.ace.easysync2.Changeset"); - -/** - * Copyright 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// requires: easysync2.Changeset - -var linestylefilter = {}; - -linestylefilter.ATTRIB_CLASSES = { - 'bold':'tag:b', - 'italic':'tag:i', - 'underline':'tag:u', - 'strikethrough':'tag:s' -}; - -linestylefilter.getAuthorClassName = function(author) { - return "author-"+author.replace(/[^a-y0-9]/g, function(c) { - if (c == ".") return "-"; - return 'z'+c.charCodeAt(0)+'z'; - }); -}; - -// lineLength is without newline; aline includes newline, -// but may be falsy if lineLength == 0 -linestylefilter.getLineStyleFilter = function(lineLength, aline, - textAndClassFunc, apool) { - - if (lineLength == 0) return textAndClassFunc; - - var nextAfterAuthorColors = textAndClassFunc; - - var authorColorFunc = (function() { - var lineEnd = lineLength; - var curIndex = 0; - var extraClasses; - var leftInAuthor; - - function attribsToClasses(attribs) { - var classes = ''; - Changeset.eachAttribNumber(attribs, function(n) { - var key = apool.getAttribKey(n); - if (key) { - var value = apool.getAttribValue(n); - if (value) { - if (key == 'author') { - classes += ' '+linestylefilter.getAuthorClassName(value); - } - else if (key == 'list') { - classes += ' list:'+value; - } - else if (linestylefilter.ATTRIB_CLASSES[key]) { - classes += ' '+linestylefilter.ATTRIB_CLASSES[key]; - } - } - } - }); - return classes.substring(1); - } - - var attributionIter = Changeset.opIterator(aline); - var nextOp, nextOpClasses; - function goNextOp() { - nextOp = attributionIter.next(); - nextOpClasses = (nextOp.opcode && attribsToClasses(nextOp.attribs)); - } - goNextOp(); - function nextClasses() { - if (curIndex < lineEnd) { - extraClasses = nextOpClasses; - leftInAuthor = nextOp.chars; - goNextOp(); - while (nextOp.opcode && nextOpClasses == extraClasses) { - leftInAuthor += nextOp.chars; - goNextOp(); - } - } - } - nextClasses(); - - return function(txt, cls) { - while (txt.length > 0) { - if (leftInAuthor <= 0) { - // prevent infinite loop if something funny's going on - return nextAfterAuthorColors(txt, cls); - } - var spanSize = txt.length; - if (spanSize > leftInAuthor) { - spanSize = leftInAuthor; - } - var curTxt = txt.substring(0, spanSize); - txt = txt.substring(spanSize); - nextAfterAuthorColors(curTxt, (cls&&cls+" ")+extraClasses); - curIndex += spanSize; - leftInAuthor -= spanSize; - if (leftInAuthor == 0) { - nextClasses(); - } - } - }; - })(); - return authorColorFunc; -}; - -linestylefilter.getAtSignSplitterFilter = function(lineText, - textAndClassFunc) { - var at = /@/g; - at.lastIndex = 0; - var splitPoints = null; - var execResult; - while ((execResult = at.exec(lineText))) { - if (! splitPoints) { - splitPoints = []; - } - splitPoints.push(execResult.index); - } - - if (! splitPoints) return textAndClassFunc; - - return linestylefilter.textAndClassFuncSplitter(textAndClassFunc, - splitPoints); -}; - -linestylefilter.REGEX_WORDCHAR = /[\u0030-\u0039\u0041-\u005A\u0061-\u007A\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u0100-\u1FFF\u3040-\u9FFF\uF900-\uFDFF\uFE70-\uFEFE\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFDC]/; -linestylefilter.REGEX_URLCHAR = new RegExp('('+/[-:@a-zA-Z0-9_.,~%+\/\\?=&#;()$]/.source+'|'+linestylefilter.REGEX_WORDCHAR.source+')'); -linestylefilter.REGEX_URL = new RegExp(/(?:(?:https?|s?ftp|ftps|file|smb|afp|nfs|(x-)?man|gopher|txmt):\/\/|mailto:)/.source+linestylefilter.REGEX_URLCHAR.source+'*(?![:.,;])'+linestylefilter.REGEX_URLCHAR.source, 'g'); - -linestylefilter.getURLFilter = function(lineText, textAndClassFunc) { - linestylefilter.REGEX_URL.lastIndex = 0; - var urls = null; - var splitPoints = null; - var execResult; - while ((execResult = linestylefilter.REGEX_URL.exec(lineText))) { - if (! urls) { - urls = []; - splitPoints = []; - } - var startIndex = execResult.index; - var url = execResult[0]; - urls.push([startIndex, url]); - splitPoints.push(startIndex, startIndex + url.length); - } - - if (! urls) return textAndClassFunc; - - function urlForIndex(idx) { - for(var k=0; k<urls.length; k++) { - var u = urls[k]; - if (idx >= u[0] && idx < u[0]+u[1].length) { - return u[1]; - } - } - return false; - } - - var handleUrlsAfterSplit = (function() { - var curIndex = 0; - return function(txt, cls) { - var txtlen = txt.length; - var newCls = cls; - var url = urlForIndex(curIndex); - if (url) { - newCls += " url:"+url; - } - textAndClassFunc(txt, newCls); - curIndex += txtlen; - }; - })(); - - return linestylefilter.textAndClassFuncSplitter(handleUrlsAfterSplit, - splitPoints); -}; - -linestylefilter.textAndClassFuncSplitter = function(func, splitPointsOpt) { - var nextPointIndex = 0; - var idx = 0; - - // don't split at 0 - while (splitPointsOpt && - nextPointIndex < splitPointsOpt.length && - splitPointsOpt[nextPointIndex] == 0) { - nextPointIndex++; - } - - function spanHandler(txt, cls) { - if ((! splitPointsOpt) || nextPointIndex >= splitPointsOpt.length) { - func(txt, cls); - idx += txt.length; - } - else { - var splitPoints = splitPointsOpt; - var pointLocInSpan = splitPoints[nextPointIndex] - idx; - var txtlen = txt.length; - if (pointLocInSpan >= txtlen) { - func(txt, cls); - idx += txt.length; - if (pointLocInSpan == txtlen) { - nextPointIndex++; - } - } - else { - if (pointLocInSpan > 0) { - func(txt.substring(0, pointLocInSpan), cls); - idx += pointLocInSpan; - } - nextPointIndex++; - // recurse - spanHandler(txt.substring(pointLocInSpan), cls); - } - } - } - return spanHandler; -}; - -// domLineObj is like that returned by domline.createDomLine -linestylefilter.populateDomLine = function(textLine, aline, apool, - domLineObj) { - // remove final newline from text if any - var text = textLine; - if (text.slice(-1) == '\n') { - text = text.substring(0, text.length-1); - } - - function textAndClassFunc(tokenText, tokenClass) { - domLineObj.appendSpan(tokenText, tokenClass); - } - - var func = textAndClassFunc; - func = linestylefilter.getURLFilter(text, func); - func = linestylefilter.getLineStyleFilter(text.length, aline, - func, apool); - func(text, ''); -}; diff --git a/etherpad/src/static/js/ace.js b/etherpad/src/static/js/ace.js deleted file mode 100644 index 7f19d37..0000000 --- a/etherpad/src/static/js/ace.js +++ /dev/null @@ -1,29 +0,0 @@ -Ace2Editor.registry={nextId:1};function Ace2Editor(){var K="Ace2Editor";var F=Ace2Editor;var B={};var A={editor:B,id:(F.registry.nextId++)}; -var D=false;var E=[];function C(R,Q){return function(){var T=this;var S=arguments;function U(){R.apply(T,S); -}if(Q){Q.apply(T,S);}if(D){U();}else{E.push(U);}};}function I(){for(var Q=0;Q<E.length;Q++){E[Q]();}E=[]; -}F.registry[A.id]=A;B.importText=C(function(R,Q){A.ace_importText(R,Q);});B.importAText=C(function(R,S,Q){A.ace_importAText(R,S,Q); -});B.exportText=function(){if(!D){return"(awaiting init)\n";}return A.ace_exportText();};B.getFrame=function(){return A.frame||null; -};B.focus=C(function(){A.ace_focus();});B.adjustSize=C(function(){var R=A.frame.parentNode;var Q=R.clientHeight; -A.frame.style.height=(Q?Q+"px":R.style.height);A.ace_editorChangedSize();});B.setEditable=C(function(Q){A.ace_setEditable(Q); -});B.getFormattedCode=function(){return A.ace_getFormattedCode();};B.setOnKeyPress=C(function(Q){A.ace_setOnKeyPress(Q); -});B.setOnKeyDown=C(function(Q){A.ace_setOnKeyDown(Q);});B.setNotifyDirty=C(function(Q){A.ace_setNotifyDirty(Q); -});B.setProperty=C(function(Q,R){A.ace_setProperty(Q,R);});B.getDebugProperty=function(Q){return A.ace_getDebugProperty(Q); -};B.setBaseText=C(function(Q){A.ace_setBaseText(Q);});B.setBaseAttributedText=C(function(R,Q){A.ace_setBaseAttributedText(R,Q); -});B.applyChangesToBase=C(function(R,Q,S){A.ace_applyChangesToBase(R,Q,S);});B.prepareUserChangeset=function(){if(!D){return null; -}return A.ace_prepareUserChangeset();};B.applyPreparedChangesetToBase=C(function(){A.ace_applyPreparedChangesetToBase(); -});B.setUserChangeNotificationCallback=C(function(Q){A.ace_setUserChangeNotificationCallback(Q);});B.setAuthorInfo=C(function(R,Q){A.ace_setAuthorInfo(R,Q); -});B.setAuthorSelectionRange=C(function(R,S,Q){A.ace_setAuthorSelectionRange(R,S,Q);});B.getUnhandledErrors=function(){if(!D){return[]; -}return A.ace_getUnhandledErrors();};B.execCommand=C(function(R,Q){A.ace_execCommand(R,Q);});var H=function(Q){return'<link rel="stylesheet" type="text/css" href="'+Q+'"/>'; -};var J=function(Q){return'\x3cscript type="text/javascript" src="'+Q+'">\x3c/script>';};var M=J;var N=H; -var L=function(Q){return'\'<link rel="stylesheet" type="text/css" href="'+Q+"\"/>'";};var G=function(Q){return'\'\\x3cscript type="text/javascript" src="'+Q+"\">\\x3c/script>'"; -};var P=G;var O=L;B.destroy=C(function(){A.ace_dispose();A.frame.parentNode.removeChild(A.frame);delete F.registry[A.id]; -A=null;});B.init=function(Q,S,R){B.importText(S);A.onEditorReady=function(){D=true;I();R();};(function(){var W='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; -var T=["'"+W+"<html><head>'"];T.push(("('<style type=\"text/css\">'+'body{margin:0;white-space:nowrap;}#outerdocbody{background-color:#fff;}body.grayedout{background-color:#eee!important;}#innerdocbody{font-size:12px;font-family:monospace;line-height:16px;}body.doesWrap{white-space:normal;}#innerdocbody{padding-top:1px;padding-right:10px;padding-bottom:8px;padding-left:1px;overflow:hidden;background-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==);}#sidediv{font-size:11px;font-family:monospace;line-height:16px;padding-top:8px;padding-right:3px;position:absolute;width:20px;top:0;left:0;cursor:default;color:white;}#sidedivinner{text-align:right;}.sidedivdelayed{background-color:#eee;color:#888!important;border-right:1px solid #999;}.sidedivhidden{display:none;}#outerdocbody iframe{display:block;position:relative;left:32px;top:7px;border:0;width:1px;height:1px;}#outerdocbody .hotrect{border:1px solid #999;position:absolute;}body.mozilla,body.safari{display:table-cell;}body.doesWrap{display:block!important;}.safari div{padding-right:1px;}p{margin:0;}#linemetricsdiv{position:absolute;left:-1000px;top:-1000px;color:white;z-index:-1;font-size:12px;font-family:monospace;}#overlaysdiv{position:absolute;left:-1000px;top:-1000px;}.syntax .c{color:#bd3f00;font-style:italic;}.syntax .o{font-weight:bold;}.syntax .p{font-weight:bold;}.syntax .k{color:blue;}.syntax .kc{color:purple;}.syntax .mf{color:purple;}.syntax .mh{color:purple;}.syntax .mi{color:purple;}.syntax .sr{color:purple;}.syntax .s2{color:purple;}.syntax .s1{color:purple;}.syntax .sd{color:purple;}.syntax .cs{color:#0a3;font-weight:bold;font-style:italic;}.syntax .err{color:#c00;font-weight:bold;text-decoration:underline;}.syntax .nt{font-weight:bold;}.syntax .nc{color:#336;}.syntax .nf{color:#336;}.syntax .nd{color:#999;}.syntax .m{color:purple;}.syntax .nb{color:purple;}.syntax .cp{color:#bd3f00;}.syntax .flash{background-color:#adf!important;}.syntax .flashbad{background-color:#f55!important;}html{cursor:text;}span{cursor:auto;}a{cursor:pointer!important;}ul,ol,li{padding:0;margin:0;}ul{margin-left:1.5em;}ul ul{margin-left:0!important;}ul.list-bullet1{margin-left:1.5em;}ul.list-bullet2{margin-left:3em;}ul.list-bullet3{margin-left:4.5em;}ul.list-bullet4{margin-left:6em;}ul.list-bullet5{margin-left:7.5em;}ul.list-bullet6{margin-left:9em;}ul.list-bullet7{margin-left:10.5em;}ul.list-bullet8{margin-left:12em;}ul{list-style-type:disc;}ul.list-bullet1{list-style-type:disc;}ul.list-bullet2{list-style-type:circle;}ul.list-bullet3{list-style-type:square;}ul.list-bullet4{list-style-type:disc;}ul.list-bullet5{list-style-type:circle;}ul.list-bullet6{list-style-type:square;}ul.list-bullet7{list-style-type:disc;}ul.list-bullet8{list-style-type:circle;}'+'\\x3c/style>')")); -T.push(('(\'\\x3cscript type="text/javascript">//<!--\\n\'+\'function isNodeText(A){return(A.nodeType==3);}function object(B){var A=function(){};A.prototype=B;return new A();\\n}function extend(C,A){for(var B in A){C[B]=A[B];}return C;}function forEach(B,D){for(var A=0;A\\x3cB.length;\\nA++){var C=D(B[A],A);if(C){break;}}}function map(C,D){var B=[];for(var A=0;A\\x3cC.length;A++){if(D){B.push(D(C[A],A));\\n}else{B.push(C[A]);}}return B;}function filter(B,D){var C=[];for(var A=0;A\\x3cB.length;A++){if(D(B[A],A)){C.push(B[A]);\\n}}return C;}function isArray(A){return A&&typeof A==="object"&&!(A.propertyIsEnumerable("length"))&&typeof A.length==="number";\\n}var userAgent=navigator.userAgent.toLowerCase();var browser={version:(userAgent.match(/.+(?:rv|it|ra|ie)[\\\\\\x2f: ]([\\\\d.]+)/)||[])[1],safari:/webkit/.test(userAgent),opera:/opera/.test(userAgent),msie:/msie/.test(userAgent)&&!/opera/.test(userAgent),mozilla:/mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent),windows:/windows/.test(userAgent)};\\nfunction getAssoc(B,A){return B["_magicdom_"+A];}function setAssoc(C,A,B){C["_magicdom_"+A]=B;}function binarySearch(A,E){if(A\\x3c1){return 0;\\n}if(E(0)){return 0;}if(!E(A-1)){return A;}var D=0;var B=A-1;while((B-D)>1){var C=Math.floor((D+B)/2);\\nif(E(C)){B=C;}else{D=C;}}return B;}function binarySearchInfinite(C,B){var A=0;while(!B(A)){A+=C;}return binarySearch(A,B);\\n}function htmlPrettyEscape(A){return A.replace(/&/g,"&").replace(/\\x3c/g,"<").replace(/>/g,">").replace(/\\\\r?\\\\n/g,"\\\\\\\\n");\\n}function newSkipList(){var H=window.PROFILER;if(!H){H=function(){return{start:G,mark:G,literal:G,end:G,cancel:G};\\n};}function G(){}var B={key:null,levels:1,upPtrs:[null],downPtrs:[null],downSkips:[1],downSkipWidths:[0]};\\nvar E={key:null,levels:1,upPtrs:[null],downPtrs:[null],downSkips:[null],downSkipWidths:[null]};var A=0;\\nvar D=0;var I={};B.downPtrs[0]=E;E.upPtrs[0]=B;function J(Z){var W=B.levels;var T=W-1;var X=-1,b=0;var V=new Array(W);\\nvar Y=new Array(W);var a=new Array(W);V[T]=B;Y[T]=-1;a[T]=0;while(T>=0){var U=V[T];while(U.downPtrs[T]&&(X+U.downSkips[T]\\x3cZ)){X+=U.downSkips[T];\\nb+=U.downSkipWidths[T];U=U.downPtrs[T];}V[T]=U;Y[T]=X;a[T]=b;T--;if(T>=0){V[T]=U;}}return{nodes:V,idxs:Y,loc:Z,widthSkips:a,toString:function(){return"getPoint("+Z+")";\\n}};}function P(W){var V=0;var T=B;var U=B.levels-1;while(U>=0&&T.downPtrs[U]){while(T.downPtrs[U]&&(V+T.downSkipWidths[U]\\x3c=W)){V+=T.downSkipWidths[U];\\nT=T.downPtrs[U];}U--;}if(T===B){return(B.downPtrs[0]||null);}else{if(T===E){return(W==D?(E.upPtrs[0]||null):null);\\n}}return T;}function K(T){return(T&&T.width)||0;}function N(V,f,h){var X=H("insertKey",false);var W={key:f,levels:0,upPtrs:[],downPtrs:[],downSkips:[],downSkipWidths:[]};\\nX.mark("donealloc");var Y=V.nodes;var e=V.idxs;var k=V.loc;var j=V.widthSkips[0]+V.nodes[0].downSkipWidths[0];\\nvar a=K(h);X.mark("loop1");while(W.levels==0||Math.random()\\x3c0.01){var T=W.levels;W.levels++;if(T==Y.length){Y[T]=B;\\ne[T]=-1;B.levels++;E.levels++;B.downPtrs[T]=E;E.upPtrs[T]=B;B.downSkips[T]=A+1;B.downSkipWidths[T]=D;\\nV.widthSkips[T]=0;}var Z=W;var U=Y[T];var d=U.downPtrs[T];var b=k-e[T];var g=U.downSkips[T]+1-b;U.downSkips[T]=b;\\nU.downPtrs[T]=Z;Z.downSkips[T]=g;Z.upPtrs[T]=U;Z.downPtrs[T]=d;d.upPtrs[T]=Z;var c=j-V.widthSkips[T];\\nvar i=U.downSkipWidths[T]+a-c;U.downSkipWidths[T]=c;Z.downSkipWidths[T]=i;}X.mark("loop2");X.literal(Y.length,"PNL");\\nfor(var T=W.levels;T\\x3cY.length;T++){var U=Y[T];U.downSkips[T]++;U.downSkipWidths[T]+=a;}X.mark("map");\\nI["$KEY$"+f]=W;A++;D+=a;X.end();}function O(T){return T.nodes[0].downPtrs[0];}function S(U){U.loc++;for(var T=0;\\nT\\x3cU.nodes.length;T++){if(U.idxs[T]+U.nodes[T].downSkips[T]\\x3cU.loc){U.idxs[T]+=U.nodes[T].downSkips[T];\\nU.widthSkips[T]+=U.nodes[T].downSkipWidths[T];U.nodes[T]=U.nodes[T].downPtrs[T];}}}function M(W){var V=W.nodes[0].downPtrs[0];\\nvar X=K(V.entry);for(var T=0;T\\x3cW.nodes.length;T++){if(T\\x3cV.levels){var U=V.upPtrs[T];var Y=V.downPtrs[T];\\nvar a=U.downSkips[T]+V.downSkips[T]-1;U.downPtrs[T]=Y;Y.upPtrs[T]=U;U.downSkips[T]=a;var Z=U.downSkipWidths[T]+V.downSkipWidths[T]-X;\\nU.downSkipWidths[T]=Z;}else{var U=W.nodes[T];var Y=U.downPtrs[T];U.downSkips[T]--;U.downSkipWidths[T]-=X;\\n}}delete I["$KEY$"+V.key];A--;D-=X;}function R(V){var X=V.downSkipWidths[0];var Y=K(V.entry);var W=Y-X;\\nvar U=V;var T=0;while(T\\x3cU.levels){U.downSkipWidths[T]+=W;T++;while(T>=U.levels&&U.upPtrs[T-1]){U=U.upPtrs[T-1];\\n}}D+=W;}function L(X,W){var V=(W?0:-1);var T=X;while(T!==B){var U=T.levels-1;T=T.upPtrs[U];if(W){V+=T.downSkipWidths[U];\\n}else{V+=T.downSkips[U];}}return V;}function F(T){return I["$KEY$"+T];}function Q(Y){var U=B;var T=B.levels-1;\\nvar W=-1;function X(Z){if(Z===B){return false;}else{if(Z===E){return true;}else{return Y(Z.entry);}}}while(T>=0){var V=U.downPtrs[T];\\nwhile(!X(V)){W+=U.downSkips[T];U=V;V=U.downPtrs[T];}T--;}return W+1;}var C={length:function(){return A;\\n},atIndex:function(T){if(T\\x3c0){console.warn("atIndex("+T+")");}if(T>=A){console.warn("atIndex("+T+">="+A+")");\\n}return O(J(T)).entry;},splice:function(T,W,V){if(T\\x3c0){console.warn("splice("+T+", ...)");}if(T+W>A){console.warn("splice("+T+", "+W+", ...), N="+A);\\nconsole.warn("%s %s %s",typeof T,typeof W,typeof A);console.trace();}if(!V){V=[];}var Y=J(T);for(var U=0;\\nU\\x3cW;U++){M(Y);}for(var U=(V.length-1);U>=0;U--){var X=V[U];N(Y,X.key,X);var Z=F(X.key);Z.entry=X;}},next:function(T){return F(T.key).downPtrs[0].entry||null;\\n},prev:function(T){return F(T.key).upPtrs[0].entry||null;},push:function(T){C.splice(A,0,[T]);},slice:function(T,U){if(T===undefined){T=0;\\n}else{if(T\\x3c0){T+=A;}}if(U===undefined){U=A;}else{if(U\\x3c0){U+=A;}}if(T\\x3c0){T=0;}if(T>A){T=A;}if(U\\x3c0){U=0;\\n}if(U>A){U=A;}dmesg(String([T,U,A]));if(U\\x3c=T){return[];}var V=C.atIndex(T);var X=[V];for(var W=1;W\\x3c(U-T);\\nW++){V=C.next(V);X.push(V);}return X;},atKey:function(T){return F(T).entry;},indexOfKey:function(T){return L(F(T));\\n},indexOfEntry:function(T){return C.indexOfKey(T.key);},containsKey:function(T){return !!(F(T));},atOffset:function(T){return P(T).entry;\\n},keyAtOffset:function(T){return C.atOffset(T).key;},offsetOfKey:function(T){return L(F(T),true);},offsetOfEntry:function(T){return C.offsetOfKey(T.key);\\n},setEntryWidth:function(T,U){T.width=U;R(F(T.key));},totalWidth:function(){return D;},offsetOfIndex:function(T){if(T\\x3c0){return 0;\\n}if(T>=A){return D;}return C.offsetOfEntry(C.atIndex(T));},indexOfOffset:function(T){if(T\\x3c=0){return 0;\\n}if(T>=D){return A;}return C.indexOfEntry(C.atOffset(T));},search:function(T){return Q(T);},debugGetPoint:J,debugDepth:function(){return B.levels;\\n}};return C;}function makeVirtualLineView(B){var E=20;var D=null;function G(){return B.textContent.length;\\n}function F(){if(!D){var J=C();J.forwardByWhile(E);D=J;}return D.getVirtualLine()+1;}function H(L){var J=C();\\nJ.forwardByWhile(E,null,L);var K=J.getVirtualLine();J.backwardByWhile(8,function(){return J.getVirtualLine()==K;\\n});J.forwardByWhile(1,function(){return J.getVirtualLine()!=K;});var M=J.getOffset();return{vline:K,offset:(L-M)};\\n}function I(Q,P){var J=C();J.binarySearch(function(){return J.getVirtualLine()>=Q;});var M=J.getOffset();\\nvar L=J.getVirtualLine();J.forwardByWhile(E,null,M+P);J.backwardByWhile(1,function(){return J.getVirtualLine()!=L;\\n},M);var K=J.getOffset();var N=K-M;if(N\\x3cP&&L==(F()-1)){var O=G();N+=O-K;K=O;}return{vline:L,offset:N,lineChar:K};\\n}return{getNumVirtualLines:F,getVLineAndOffsetForChar:H,getCharForVLineAndOffset:I,makeCharSeeker:function(){return C();\\n}};function A(J){J=J.firstChild;while(J&&J.firstChild){J=J.firstChild;}if(J.data){return J;}return null;\\n}function C(){function T(a,b){var Z=a.parentNode;var f=(a.nodeValue.charAt(b)===" ");if(f){if(b==0){if(Z.previousSibling&&A(Z.previousSibling)){a=A(Z.previousSibling);\\nb=a.length-1;Z=a.parentNode;}else{return{top:Z.offsetTop,left:Z.offsetLeft};}}else{b--;}}var c=document.createElement("SPAN");\\nvar e=a.nodeValue;var d=document.createDocumentFragment();d.appendChild(document.createTextNode(e.substring(0,b)));\\nc.appendChild(document.createTextNode(e.substr(b,1)));d.appendChild(c);d.appendChild(document.createTextNode(e.substring(b+1)));\\nZ.replaceChild(d,a);var g={top:c.offsetTop,left:c.offsetLeft+(f?c.offsetWidth:0),height:c.offsetHeight};\\nwhile(Z.firstChild){Z.removeChild(Z.firstChild);}Z.appendChild(a);return g;}var Y=B.textContent;var O=Y.length;\\nvar M=null;var J=0;var L=0;var P;var N;var V;var X=0;function Q(){var Z=M;if(!Z){Z=B.firstChild;}else{Z=Z.nextSibling;\\n}while(Z&&!A(Z)){Z=Z.nextSibling;}return Z;}function S(){var Z=M;if(!Z){Z=B.lastChild;}else{Z=Z.previousSibling;\\n}while(Z&&!A(Z)){Z=Z.previousSibling;}return Z;}var K;if(O>0){M=Q();var R=T(A(M),0);V=R.height;P=R.top;\\nN=R.left;function W(b,a){var Z=T(b,a);X+=Math.round((Z.top-P)/V);P=Z.top;N=Z.left;}K={forward:function(e){var c=J;\\nvar Z=J+e;if(Z>(O-1)){Z=O-1;}while(J\\x3cZ){var d=A(M).length;var a=d-L;if(J+a>Z||!Q()){var b=Z-J;if(b>=a){b=a-1;\\n}J+=b;L+=b;break;}else{J+=a;L=0;M=Q();}}W(A(M),L);return J-c;},backward:function(c){var b=J;var Z=J-c;\\nif(Z\\x3c0){Z=0;}while(J>Z){if(J-L\\x3c=Z||!S()){var a=J-Z;if(a>L){a=L;}J-=a;L-=a;break;}else{J-=L+1;M=S();L=A(M).length-1;\\n}}W(A(M),L);return b-J;},getVirtualLine:function(){return X;},getLeftCoord:function(){return N;}};}else{N=B.offsetLeft;\\nK={forward:function(Z){return 0;},backward:function(Z){return 0;},getVirtualLine:function(){return 0;\\n},getLeftCoord:function(){return N;}};}K.getOffset=function(){return J;};K.getLineLength=function(){return O;\\n};K.toString=function(){return"seeker[curChar: "+J+"("+Y.charAt(J)+"), left: "+K.getLeftCoord()+", vline: "+K.getVirtualLine()+"]";\\n};function U(c,j,e,a){var b=null;var i=((typeof e)=="function");var h=e;var g=((typeof a)=="number");\\nvar d=a;while(b!==0&&((!i)||h())){var Z=j;if(g){var f=(c?J-d:d-J);if(f\\x3cZ){Z=f;}}if(Z\\x3c0){break;}b=(c?K.backward(Z):K.forward(Z));\\n}}K.forwardByWhile=function(Z,b,a){U(false,Z,b,a);};K.backwardByWhile=function(Z,b,a){U(true,Z,b,a);};\\nK.binarySearch=function(Z){var b=Z;var a=function(){return !Z();};K.forwardByWhile(20,a);K.backwardByWhile(20,b);\\nK.forwardByWhile(10,a);K.backwardByWhile(5,b);K.forwardByWhile(1,a);return K.getOffset()+(Z()?0:1);};\\nreturn K;}}var _opt=null;function AttribPool(){var A={};A.numToAttrib={};A.attribToNum={};A.nextNum=0;\\nA.putAttrib=function(C,E){var D=String(C);if(D in A.attribToNum){return A.attribToNum[D];}if(E){return -1;\\n}var B=A.nextNum++;A.attribToNum[D]=B;A.numToAttrib[B]=[String(C[0]||""),String(C[1]||"")];return B;};\\nA.getAttrib=function(C){var B=A.numToAttrib[C];if(!B){return B;}return[B[0],B[1]];};A.getAttribKey=function(C){var B=A.numToAttrib[C];\\nif(!B){return"";}return B[0];};A.getAttribValue=function(C){var B=A.numToAttrib[C];if(!B){return"";}return B[1];\\n};A.eachAttrib=function(C){for(var D in A.numToAttrib){var B=A.numToAttrib[D];C(B[0],B[1]);}};A.toJsonable=function(){return{numToAttrib:A.numToAttrib,nextNum:A.nextNum};\\n};A.fromJsonable=function(B){A.numToAttrib=B.numToAttrib;A.nextNum=B.nextNum;A.attribToNum={};for(var C in A.numToAttrib){A.attribToNum[String(A.numToAttrib[C])]=Number(C);\\n}return A;};return A;}var Changeset={};Changeset.error=function error(B){var A=new Error(B);A.easysync=true;\\nthrow A;};Changeset.assert=function assert(A,C){if(!A){var B=Array.prototype.slice.call(arguments,1).join("");\\nChangeset.error("Changeset: "+B);}};Changeset.parseNum=function(A){return parseInt(A,36);};Changeset.numToString=function(A){return A.toString(36).toLowerCase();\\n};Changeset.toBaseTen=function(A){var B=A.indexOf("$");var D=A.substring(0,B);var C=A.substring(B);return D.replace(/[0-9a-z]+/g,function(E){return String(Changeset.parseNum(E));\\n})+C;};Changeset.oldLen=function(A){return Changeset.unpack(A).oldLen;};Changeset.newLen=function(A){return Changeset.unpack(A).newLen;\\n};Changeset.opIterator=function(E,K){var D=/((?:\\\\*[0-9a-z]+)*)(?:\\\\|([0-9a-z]+))?([-+=])([0-9a-z]+)|\\\\?|/g;\\nvar L=(K||0);var B=L;var F=B;function C(){F=B;var M;if(_opt){M=_opt.nextOpInString(E,B);if(M){if(M.opcode()=="?"){Changeset.error("Hit error opcode in op stream");\\n}B=M.lastIndex();}}else{D.lastIndex=B;M=D.exec(E);B=D.lastIndex;if(M[0]=="?"){Changeset.error("Hit error opcode in op stream");\\n}}return M;}var A=C();var H=Changeset.newOp();function I(N){var M=(N||H);if(_opt&&A){M.attribs=A.attribs();\\nM.lines=A.lines();M.chars=A.chars();M.opcode=A.opcode();A=C();}else{if((!_opt)&&A[0]){M.attribs=A[1];\\nM.lines=Changeset.parseNum(A[2]||0);M.opcode=A[3];M.chars=Changeset.parseNum(A[4]);A=C();}else{Changeset.clearOp(M);\\n}}return M;}function G(){return !!(_opt?A:A[0]);}function J(){return F;}return{next:I,hasNext:G,lastIndex:J};\\n};Changeset.clearOp=function(A){A.opcode="";A.chars=0;A.lines=0;A.attribs="";};Changeset.newOp=function(A){return{opcode:(A||""),chars:0,lines:0,attribs:""};\\n};Changeset.cloneOp=function(A){return{opcode:A.opcode,chars:A.chars,lines:A.lines,attribs:A.attribs};\\n};Changeset.copyOp=function(B,A){A.opcode=B.opcode;A.chars=B.chars;A.lines=B.lines;A.attribs=B.attribs;\\n};Changeset.opString=function(B){if(!B.opcode){return"null";}var A=Changeset.opAssembler();A.append(B);\\nreturn A.toString();};Changeset.stringOp=function(A){return Changeset.opIterator(A).next();};Changeset.checkRep=function(C){var G=Changeset.unpack(C);\\nvar F=G.oldLen;var J=G.newLen;var M=G.ops;var E=G.charBank;var I=Changeset.smartOpAssembler();var D=0;\\nvar B=0;var H=0;var K=Changeset.opIterator(M);while(K.hasNext()){var A=K.next();switch(A.opcode){case"=":D+=A.chars;\\nB+=A.chars;break;case"-":D+=A.chars;Changeset.assert(D\\x3cF,D," >= ",F," in ",C);break;case"+":B+=A.chars;\\nH+=A.chars;Changeset.assert(B\\x3cJ,B," >= ",J," in ",C);break;}I.append(A);}B+=F-D;E=E.substring(0,H);while(E.length\\x3cH){E+="?";\\n}I.endDocument();var L=Changeset.pack(F,B,I.toString(),E);Changeset.assert(L==C,L," != ",C);return C;\\n};Changeset.smartOpAssembler=function(){var G=Changeset.mergingOpAssembler();var E=Changeset.mergingOpAssembler();\\nvar B=Changeset.mergingOpAssembler();var A=Changeset.stringAssembler();var C="";var F=0;function H(){A.append(B.toString());\\nB.clear();}function I(){A.append(G.toString());G.clear();A.append(E.toString());E.clear();}function D(O){if(!O.opcode){return;\\n}if(!O.chars){return;}if(O.opcode=="-"){if(C=="="){H();}G.append(O);F-=O.chars;}else{if(O.opcode=="+"){if(C=="="){H();\\n}E.append(O);F+=O.chars;}else{if(O.opcode=="="){if(C!="="){I();}B.append(O);}}}C=O.opcode;}function M(R,P,T,S){var O=Changeset.newOp(R);\\nO.attribs=Changeset.makeAttribsString(R,T,S);var Q=P.lastIndexOf("\\\\n");if(Q\\x3c0){O.chars=P.length;O.lines=0;\\nD(O);}else{O.chars=Q+1;O.lines=P.match(/\\\\n/g).length;D(O);O.chars=P.length-(Q+1);O.lines=0;D(O);}}function K(){I();\\nH();return A.toString();}function N(){G.clear();E.clear();B.clear();A.clear();F=0;}function L(){B.endDocument();\\n}function J(){return F;}return{append:D,toString:K,clear:N,endDocument:L,appendOpWithText:M,getLengthChange:J};\\n};if(_opt){Changeset.mergingOpAssembler=function(){var A=_opt.mergingOpAssembler();function C(F){A.append(F.opcode,F.chars,F.lines,F.attribs);\\n}function E(){return A.toString();}function B(){A.clear();}function D(){A.endDocument();}return{append:C,toString:E,clear:B,endDocument:D};\\n};}else{Changeset.mergingOpAssembler=function(){var C=Changeset.opAssembler();var A=Changeset.newOp();\\nvar B=0;function D(I){if(A.opcode){if(I&&A.opcode=="="&&!A.attribs){}else{C.append(A);if(B){A.chars=B;\\nA.lines=0;C.append(A);B=0;}}A.opcode="";}}function F(I){if(I.chars>0){if(A.opcode==I.opcode&&A.attribs==I.attribs){if(I.lines>0){A.chars+=B+I.chars;\\nA.lines+=I.lines;B=0;}else{if(A.lines==0){A.chars+=I.chars;}else{B+=I.chars;}}}else{D();Changeset.copyOp(I,A);\\n}}}function G(){D(true);}function H(){D();return C.toString();}function E(){C.clear();Changeset.clearOp(A);\\n}return{append:F,toString:H,clear:E,endDocument:G};};}if(_opt){Changeset.opAssembler=function(){var A=_opt.opAssembler();\\nfunction C(E){A.append(E.opcode,E.chars,E.lines,E.attribs);}function D(){return A.toString();}function B(){A.clear();\\n}return{append:C,toString:D,clear:B};};}else{Changeset.opAssembler=function(){var A=[];function C(E){A.push(E.attribs);\\nif(E.lines){A.push("|",Changeset.numToString(E.lines));}A.push(E.opcode);A.push(Changeset.numToString(E.chars));\\n}function D(){return A.join("");}function B(){A.length=0;}return{append:C,toString:D,clear:B};};}Changeset.stringIterator=function(D){var A=0;\\nfunction B(H){Changeset.assert(H\\x3c=C(),"!(",H," \\x3c= ",C(),")");}function F(H){B(H);var I=D.substr(A,H);\\nA+=H;return I;}function E(H){B(H);var I=D.substr(A,H);return I;}function G(H){B(H);A+=H;}function C(){return D.length-A;\\n}return{take:F,skip:G,remaining:C,peek:E};};Changeset.stringAssembler=function(){var A=[];function B(D){A.push(String(D));\\n}function C(){return A.join("");}return{append:B,toString:C};};Changeset.textLinesMutator=function(C){var A=[0,0];\\nvar D=false;var E=0,B=0;function O(X){C.splice.apply(C,X);}function S(){return C.toSource();}function J(X){if(C.get){return C.get(X);\\n}else{return C[X];}}function U(Y,X){if(C.slice){return C.slice(Y,X);}else{return[];}}function T(){if((typeof C.length)=="number"){return C.length;\\n}else{return C.length();}}function G(){A[0]=E;A[1]=0;if(B>0){F();}D=true;}function K(){O(A);A.length=2;\\nA[0]=A[1]=0;D=false;}function H(){return(E-A[0]\\x3c(A.length-2));}function W(X){print(X+": "+A.toSource()+" / "+E+","+B+" / "+S());\\n}function F(){if(!H()){A.push(J(A[0]+A[1]));A[1]++;}return 2+E-A[0];}function L(X,Z){if(X){if(Z){if(!D){G();\\n}for(var Y=0;Y\\x3cX;Y++){B=0;F();E++;}}else{if(D){if(X>1){K();}else{F();}}E+=X;B=0;}}}function R(Z,Y,X){if(Z){if(Y){L(Y,X);\\n}else{if(X&&!D){G();}if(D){F();}B+=Z;}}}function I(X){var Y="";if(X){if(!D){G();}function a(c){var b=A[0]+A[1];\\nreturn U(b,b+c).join("");}if(H()){if(B==0){Y=A[A.length-1];A.length--;Y+=a(X-1);A[1]+=X-1;}else{Y=a(X-1);\\nA[1]+=X-1;var Z=A.length-1;Y=A[Z].substring(B)+Y;A[Z]=A[Z].substring(0,B)+J(A[0]+A[1]);A[1]+=1;}}else{Y=a(X);\\nA[1]+=X;}}return Y;}function V(Y,Z){var a="";if(Y){if(Z){return I(Z);}else{if(!D){G();}var X=F();a=A[X].substring(B,B+Y);\\nA[X]=A[X].substring(0,B)+A[X].substring(B+Y);}}return a;}function M(Z,c){if(Z){if(!D){G();}if(c){var X=Changeset.splitTextLines(Z);\\nif(H()){var Y=A.length-1;var a=A[Y];var b=B;A[Y]=a.substring(0,b)+X[0];E++;X.splice(0,1);Array.prototype.push.apply(A,X);\\nE+=X.length;A.push(a.substring(b));B=0;}else{Array.prototype.push.apply(A,X);E+=X.length;}}else{var Y=F();\\nA[Y]=A[Y].substring(0,B)+Z+A[Y].substring(B);B+=Z.length;}}}function N(){var X=T();if(D){X+=A.length-2-A[1];\\n}return E\\x3cX;}function P(){if(D){K();}}var Q={skip:R,remove:V,insert:M,close:P,hasMore:N,removeLines:I,skipLines:L};\\nreturn Q;};Changeset.applyZip=function(I,K,H,J,G){var F=Changeset.opIterator(I,K);var E=Changeset.opIterator(H,J);\\nvar D=Changeset.smartOpAssembler();var A=Changeset.newOp();var C=Changeset.newOp();var B=Changeset.newOp();\\nwhile(A.opcode||F.hasNext()||C.opcode||E.hasNext()){if((!A.opcode)&&F.hasNext()){F.next(A);}if((!C.opcode)&&E.hasNext()){E.next(C);\\n}G(A,C,B);if(B.opcode){D.append(B);B.opcode="";}}D.endDocument();return D.toString();};Changeset.unpack=function(B){var G=/Z:([0-9a-z]+)([>\\x3c])([0-9a-z]+)|/;\\nvar A=G.exec(B);if((!A)||(!A[0])){Changeset.error("Not a changeset: "+B);}var D=Changeset.parseNum(A[1]);\\nvar E=(A[2]==">")?1:-1;var H=Changeset.parseNum(A[3]);var F=D+E*H;var I=A[0].length;var C=B.indexOf("$");\\nif(C\\x3c0){C=B.length;}return{oldLen:D,newLen:F,ops:B.substring(I,C),charBank:B.substring(C+1)};};Changeset.pack=function(C,G,F,D){var A=G-C;\\nvar E=(A>=0?">"+Changeset.numToString(A):"\\x3c"+Changeset.numToString(-A));var B=[];B.push("Z:",Changeset.numToString(C),E,F,"$",D);\\nreturn B.join("");};Changeset.applyToText=function(H,E){var C=Changeset.unpack(H);Changeset.assert(E.length==C.oldLen,"mismatched apply: ",E.length," / ",C.oldLen);\\nvar F=Changeset.opIterator(C.ops);var G=Changeset.stringIterator(C.charBank);var B=Changeset.stringIterator(E);\\nvar A=Changeset.stringAssembler();while(F.hasNext()){var D=F.next();switch(D.opcode){case"+":A.append(G.take(D.chars));\\nbreak;case"-":B.skip(D.chars);break;case"=":A.append(B.take(D.chars));break;}}A.append(B.take(B.remaining()));\\nreturn A.toString();};Changeset.mutateTextLines=function(G,F){var C=Changeset.unpack(G);var D=Changeset.opIterator(C.ops);\\nvar E=Changeset.stringIterator(C.charBank);var B=Changeset.textLinesMutator(F);while(D.hasNext()){var A=D.next();\\nswitch(A.opcode){case"+":B.insert(E.take(A.chars),A.lines);break;case"-":B.remove(A.chars,A.lines);break;\\ncase"=":B.skip(A.chars,A.lines,(!!A.attribs));break;}}B.close();};Changeset.composeAttributes=function(G,F,E,D){if((!G)&&E){return F;\\n}if(!F){return G;}var A=[];G.replace(/\\\\*([0-9a-z]+)/g,function(I,H){A.push(D.getAttrib(Changeset.parseNum(H)));\\nreturn"";});F.replace(/\\\\*([0-9a-z]+)/g,function(M,L){var H=D.getAttrib(Changeset.parseNum(L));var K=false;\\nfor(var I=0;I\\x3cA.length;I++){var J=A[I];if(J[0]==H[0]){if(H[1]||E){J[1]=H[1];}else{A.splice(I,1);}K=true;\\nbreak;}}if((!K)&&(H[1]||E)){A.push(H);}return"";});A.sort();var B=Changeset.stringAssembler();for(var C=0;\\nC\\x3cA.length;C++){B.append("*");B.append(Changeset.numToString(D.putAttrib(A[C])));}return B.toString();\\n};Changeset._slicerZipperFunc=function(A,B,C,D){if(A.opcode=="-"){Changeset.copyOp(A,C);A.opcode="";}else{if(!A.opcode){Changeset.copyOp(B,C);\\nB.opcode="";}else{switch(B.opcode){case"-":if(B.chars\\x3c=A.chars){if(A.opcode=="="){C.opcode="-";C.chars=B.chars;\\nC.lines=B.lines;C.attribs="";}A.chars-=B.chars;A.lines-=B.lines;B.opcode="";if(!A.chars){A.opcode="";\\n}}else{if(A.opcode=="="){C.opcode="-";C.chars=A.chars;C.lines=A.lines;C.attribs="";}B.chars-=A.chars;\\nB.lines-=A.lines;A.opcode="";}break;case"+":Changeset.copyOp(B,C);B.opcode="";break;case"=":if(B.chars\\x3c=A.chars){C.opcode=A.opcode;\\nC.chars=B.chars;C.lines=B.lines;C.attribs=Changeset.composeAttributes(A.attribs,B.attribs,A.opcode=="=",D);\\nB.opcode="";A.chars-=B.chars;A.lines-=B.lines;if(!A.chars){A.opcode="";}}else{C.opcode=A.opcode;C.chars=A.chars;\\nC.lines=A.lines;C.attribs=Changeset.composeAttributes(A.attribs,B.attribs,A.opcode=="=",D);A.opcode="";\\nB.chars-=A.chars;B.lines-=A.lines;}break;case"":Changeset.copyOp(A,C);A.opcode="";break;}}}};Changeset.applyToAttribution=function(D,C,B){var A=Changeset.unpack(D);\\nreturn Changeset.applyZip(C,0,A.ops,0,function(F,E,G){return Changeset._slicerZipperFunc(F,E,G,B);});\\n};Changeset.mutateAttributionLines=function(N,Q,O){var I=Changeset.unpack(N);var H=Changeset.opIterator(I.ops);\\nvar M=I.charBank;var G=0;var F=Changeset.textLinesMutator(Q);var B=null;function L(){return(B&&B.hasNext())||F.hasMore();\\n}function P(R){if((!(B&&B.hasNext()))&&F.hasMore()){var S=F.removeLines(1);B=Changeset.opIterator(S);\\n}if(B&&B.hasNext()){B.next(R);}else{R.opcode="";}}var D=null;function J(R){if(!D){D=Changeset.mergingOpAssembler();\\n}D.append(R);if(R.lines>0){Changeset.assert(R.lines==1,"Can\\\'t have op.lines of ",R.lines," in attribution lines");\\nF.insert(D.toString(),1);D=null;}}var A=Changeset.newOp();var E=Changeset.newOp();var C=Changeset.newOp();\\nwhile(A.opcode||H.hasNext()||E.opcode||L()){if((!A.opcode)&&H.hasNext()){H.next(A);}if((!A.opcode)&&(!E.opcode)&&(!D)&&(!(B&&B.hasNext()))){break;\\n}else{if(A.opcode=="="&&A.lines>0&&(!A.attribs)&&(!E.opcode)&&(!D)&&(!(B&&B.hasNext()))){F.skipLines(A.lines);\\nA.opcode="";}else{if(A.opcode=="+"){if(A.lines>1){var K=M.indexOf("\\\\n",G)+1-G;Changeset.copyOp(A,C);A.chars-=K;\\nA.lines--;C.lines=1;C.chars=K;}else{Changeset.copyOp(A,C);A.opcode="";}J(C);G+=C.chars;C.opcode="";}else{if((!E.opcode)&&L()){P(E);\\n}Changeset._slicerZipperFunc(E,A,C,O);if(C.opcode){J(C);C.opcode="";}}}}}Changeset.assert(!D,"line assembler not finished");\\nF.close();};Changeset.joinAttributionLines=function(D){var C=Changeset.mergingOpAssembler();for(var A=0;\\nA\\x3cD.length;A++){var E=D[A];var B=Changeset.opIterator(E);while(B.hasNext()){C.append(B.next());}}return C.toString();\\n};Changeset.splitAttributionLines=function(J,K){var G=Changeset.opIterator(J);var C=Changeset.mergingOpAssembler();\\nvar I=[];var D=0;function E(L){C.append(L);if(L.lines>0){I.push(C.toString());C.clear();}D+=L.chars;}while(G.hasNext()){var A=G.next();\\nvar F=A.chars;var B=A.lines;while(B>1){var H=K.indexOf("\\\\n",D)+1;Changeset.assert(H>0,"newlineEnd \\x3c= 0 in splitAttributionLines");\\nA.chars=H-D;A.lines=1;E(A);F-=A.chars;B-=A.lines;}if(B==1){A.chars=F;A.lines=1;}E(A);}return I;};Changeset.splitTextLines=function(A){return A.match(/[^\\\\n]*(?:\\\\n|[^\\\\n]$)/g);\\n};Changeset.compose=function(J,H,L){var B=Changeset.unpack(J);var A=Changeset.unpack(H);var K=B.oldLen;\\nvar I=B.newLen;Changeset.assert(I==A.oldLen,"mismatched composition");var G=A.newLen;var D=Changeset.stringIterator(B.charBank);\\nvar E=Changeset.stringIterator(A.charBank);var C=Changeset.stringAssembler();var F=Changeset.applyZip(B.ops,0,A.ops,0,function(O,N,M){var Q=O.opcode;\\nvar P=N.opcode;if(Q=="+"&&P=="-"){D.skip(Math.min(O.chars,N.chars));}Changeset._slicerZipperFunc(O,N,M,L);\\nif(M.opcode=="+"){if(P=="+"){C.append(E.take(M.chars));}else{C.append(D.take(M.chars));}}});return Changeset.pack(K,G,F,C.toString());\\n};Changeset.attributeTester=function(D,B){if(!B){return C;}var A=B.putAttrib(D,true);if(A\\x3c0){return C;\\n}else{var E=new RegExp("\\\\\\\\*"+Changeset.numToString(A)+"(?!\\\\\\\\w)");return function(F){return E.test(F);\\n};}function C(F){return false;}};Changeset.identity=function(A){return Changeset.pack(A,A,"","");};Changeset.makeSplice=function(B,A,F,E,H,J){var D=B.length;\\nif(A>=D){A=D-1;}if(F>B.length-A-1){F=B.length-A-1;}var G=B.substring(A,A+F);var I=D+E.length-G.length;\\nvar C=Changeset.smartOpAssembler();C.appendOpWithText("=",B.substring(0,A));C.appendOpWithText("-",G);\\nC.appendOpWithText("+",E,H,J);C.endDocument();return Changeset.pack(D,I,C.toString(),E);};Changeset.toSplices=function(G){var F=Changeset.unpack(G);\\nvar B=[];var C=0;var E=Changeset.opIterator(F.ops);var H=Changeset.stringIterator(F.charBank);var D=false;\\nwhile(E.hasNext()){var A=E.next();if(A.opcode=="="){C+=A.chars;D=false;}else{if(!D){B.push([C,C,""]);\\nD=true;}if(A.opcode=="-"){C+=A.chars;B[B.length-1][1]+=A.chars;}else{if(A.opcode=="+"){B[B.length-1][2]+=H.take(A.chars);\\n}}}}return B;};Changeset.characterRangeFollow=function(M,N,L,K){var C=N;var A=L;var J=Changeset.toSplices(M);\\nvar H=0;for(var G=0;G\\x3cJ.length;G++){var F=J[G];var B=F[0]+H;var E=F[1]+H;var I=F[2].length;var D=I-(E-B);\\nif(B\\x3c=C&&E>=A){if(K){C=A=B;}else{C=A=B+I;}}else{if(E\\x3c=C){C+=D;A+=D;}else{if(B>=A){}else{if(B>=C&&E\\x3c=A){A+=D;\\n}else{if(E\\x3cA){C=B+I;A+=D;}else{A=B;}}}}}H+=D;}return[C,A];};Changeset.moveOpsToNewPool=function(A,F,C){var B=A.indexOf("$");\\nif(B\\x3c0){B=A.length;}var D=A.substring(0,B);var E=A.substring(B);return D.replace(/\\\\*([0-9a-z]+)/g,function(K,G){var H=Changeset.parseNum(G);\\nvar J=F.getAttrib(H);var I=C.putAttrib(J);return"*"+Changeset.numToString(I);})+E;};Changeset.makeAttribution=function(B){var A=Changeset.smartOpAssembler();\\nA.appendOpWithText("+",B);return A.toString();};Changeset.eachAttribNumber=function(A,D){var B=A.indexOf("$");\\nif(B\\x3c0){B=A.length;}var C=A.substring(0,B);C.replace(/\\\\*([0-9a-z]+)/g,function(F,E){D(Changeset.parseNum(E));\\nreturn"";});};Changeset.filterAttribNumbers=function(B,A){return Changeset.mapAttribNumbers(B,A);};Changeset.mapAttribNumbers=function(A,E){var B=A.indexOf("$");\\nif(B\\x3c0){B=A.length;}var D=A.substring(0,B);var C=D.replace(/\\\\*([0-9a-z]+)/g,function(H,G){var F=E(Changeset.parseNum(G));\\nif(F===true){return H;}else{if((typeof F)==="number"){return"*"+Changeset.numToString(F);}else{return"";\\n}}});return C+A.substring(B);};Changeset.makeAText=function(A,B){return{text:A,attribs:(B||Changeset.makeAttribution(A))};\\n};Changeset.applyToAText=function(A,B,C){return{text:Changeset.applyToText(A,B.text),attribs:Changeset.applyToAttribution(A,B.attribs,C)};\\n};Changeset.cloneAText=function(A){return{text:A.text,attribs:A.attribs};};Changeset.copyAText=function(A,B){B.text=A.text;\\nB.attribs=A.attribs;};Changeset.appendATextToAssembler=function(C,B){var D=Changeset.opIterator(C.attribs);\\nvar A=Changeset.newOp();while(D.hasNext()){D.next(A);if(!D.hasNext()){if(A.lines\\x3c=1){A.lines=0;A.chars--;\\nif(A.chars){B.append(A);}}else{var F=C.text.lastIndexOf("\\\\n",C.text.length-2)+1;var E=C.text.length-F-1;\\nA.lines--;A.chars-=(E+1);B.append(A);A.lines=0;A.chars=E;if(A.chars){B.append(A);}}}else{B.append(A);\\n}}};Changeset.prepareForWire=function(C,B){var A=new AttribPool();var D=Changeset.moveOpsToNewPool(C,B,A);\\nreturn{translated:D,pool:A};};Changeset.isIdentity=function(B){var A=Changeset.unpack(B);return A.ops==""&&A.oldLen==A.newLen;\\n};Changeset.opAttributeValue=function(C,B,A){return Changeset.attribsAttributeValue(C.attribs,B,A);};\\nChangeset.attribsAttributeValue=function(C,D,A){var B="";if(C){Changeset.eachAttribNumber(C,function(E){if(A.getAttribKey(E)==D){B=A.getAttribValue(E);\\n}});}return B;};Changeset.builder=function(D){var B=Changeset.smartOpAssembler();var A=Changeset.newOp();\\nvar E=Changeset.stringAssembler();var C={keep:function(I,G,F,H){A.opcode="=";A.attribs=(F&&Changeset.makeAttribsString("=",F,H))||"";\\nA.chars=I;A.lines=(G||0);B.append(A);return C;},keepText:function(H,G,F){B.appendOpWithText("=",H,G,F);\\nreturn C;},insert:function(F,H,G){B.appendOpWithText("+",F,H,G);E.append(F);return C;},remove:function(G,F){A.opcode="-";\\nA.attribs="";A.chars=G;A.lines=(F||0);B.append(A);return C;},toString:function(){B.endDocument();var F=D+B.getLengthChange();\\nreturn Changeset.pack(D,F,B.toString(),E.toString());}};return C;};Changeset.makeAttribsString=function(E,A,D){if(!A){return"";\\n}else{if((typeof A)=="string"){return A;}else{if(D&&A&&A.length){if(A.length>1){A=A.slice();A.sort();\\n}var C=[];for(var B=0;B\\x3cA.length;B++){var F=A[B];if(E=="="||(E=="+"&&F[1])){C.push("*"+Changeset.numToString(D.putAttrib(F)));\\n}}return C.join("");}}}};Changeset.subattribution=function(I,F,H){var E=Changeset.opIterator(I,0);var D=Changeset.smartOpAssembler();\\nvar A=Changeset.newOp();var B=Changeset.newOp();var C=Changeset.newOp();function G(){if(B.chars){while(B.opcode&&(A.opcode||E.hasNext())){if(!A.opcode){E.next(A);\\n}if(B.opcode&&A.opcode&&B.chars>=A.chars&&A.lines>0&&B.lines\\x3c=0){B.lines++;}Changeset._slicerZipperFunc(A,B,C,null);\\nif(C.opcode){D.append(C);C.opcode="";}}}}B.opcode="-";B.chars=F;G();if(H===undefined){if(A.opcode){D.append(A);\\n}while(E.hasNext()){E.next(A);D.append(A);}}else{B.opcode="=";B.chars=H-F;G();}return D.toString();};\\nChangeset.inverse=function(U,F,G,J){function P(a){if(F.get){return F.get(a);}else{return F[a];}}function Z(){if((typeof F.length)=="number"){return F.length;\\n}else{return F.length();}}function Q(a){if(G.get){return G.get(a);}else{return G[a];}}function Y(){if((typeof G.length)=="number"){return G.length;\\n}else{return G.length();}}var C=0;var E=0;var D=null;var I;var A=Changeset.newOp("+");var R=Changeset.unpack(U);\\nvar N=Changeset.opIterator(R.ops);var H=Changeset.builder(R.newLen);function M(c,e){if((!D)||(I!=C)){D=Changeset.opIterator(Q(C));\\nI=C;var b=0;var d=false;while(!d){D.next(A);if(b+A.chars>=E){A.chars-=(E-b);d=true;}else{b+=A.chars;}}}while(c>0){if((!A.chars)&&(!D.hasNext())){C++;\\nE=0;I=C;A.chars=0;D=Changeset.opIterator(Q(C));}if(!A.chars){D.next(A);}var a=Math.min(c,A.chars);e(a,A.attribs,a==A.chars&&A.lines>0);\\nc-=a;A.chars-=a;E+=a;}if((!A.chars)&&(!D.hasNext())){C++;E=0;}}function X(b,a){if(a){C+=a;E=0;}else{if(D&&I==C){M(b,function(){});\\n}else{E+=b;}}}function S(e){var a=0;var b=Changeset.stringAssembler();var c=P(C).substring(E);a+=c.length;\\nb.append(c);var f=C+1;while(a\\x3ce){var d=P(f);a+=d.length;b.append(d);f++;}return b.toString().substring(0,e);\\n}function W(b){var a={};return function(c){if(!a[c]){a[c]=b(c);}return a[c];};}var K=[];var L=[];while(N.hasNext()){var B=N.next();\\nif(B.opcode=="="){if(B.attribs){K.length=0;L.length=0;Changeset.eachAttribNumber(B.attribs,function(a){K.push(J.getAttribKey(a));\\nL.push(J.getAttribValue(a));});var T=W(function(f){var d=[];for(var a=0;a\\x3cK.length;a++){var c=K[a];var e=L[a];\\nvar b=Changeset.attribsAttributeValue(f,c,J);if(e!=b){d.push([c,b]);}}return Changeset.makeAttribsString("=",d,J);\\n});M(B.chars,function(a,c,b){H.keep(a,b?1:0,T(c));});}else{X(B.chars,B.lines);H.keep(B.chars,B.lines);\\n}}else{if(B.opcode=="+"){H.remove(B.chars,B.lines);}else{if(B.opcode=="-"){var V=S(B.chars);var O=0;M(B.chars,function(a,b,c){H.insert(V.substr(O,a),b);\\nO+=a;});}}}}return Changeset.checkRep(H.toString());};Changeset.follow=function(N,L,K,G){var C=Changeset.unpack(N);\\nvar B=Changeset.unpack(L);var O=C.oldLen;var M=B.oldLen;Changeset.assert(O==M,"mismatched follow");var I=Changeset.stringIterator(C.charBank);\\nvar H=Changeset.stringIterator(B.charBank);var F=C.newLen;var D=0;var A=0;var E=Changeset.attributeTester(["insertorder","first"],G);\\nvar J=Changeset.applyZip(C.ops,0,B.ops,0,function(Q,P,R){if(Q.opcode=="+"||P.opcode=="+"){var S;if(P.opcode!="+"){S=1;\\n}else{if(Q.opcode!="+"){S=2;}else{var V=I.peek(1);var T=H.peek(1);var W=E(Q.attribs);var U=E(P.attribs);\\nif(W&&!U){S=1;}else{if(U&&!W){S=2;}else{if(V=="\\\\n"&&T!="\\\\n"){S=2;}else{if(V!="\\\\n"&&T=="\\\\n"){S=1;}else{if(K){S=2;\\n}else{S=1;}}}}}}}if(S==1){I.skip(Q.chars);R.opcode="=";R.lines=Q.lines;R.chars=Q.chars;R.attribs="";Q.opcode="";\\n}else{H.skip(P.chars);Changeset.copyOp(P,R);P.opcode="";}}else{if(Q.opcode=="-"){if(!P.opcode){Q.opcode="";\\n}else{if(Q.chars\\x3c=P.chars){P.chars-=Q.chars;P.lines-=Q.lines;Q.opcode="";if(!P.chars){P.opcode="";}}else{Q.chars-=P.chars;\\nQ.lines-=P.lines;P.opcode="";}}}else{if(P.opcode=="-"){Changeset.copyOp(P,R);if(!Q.opcode){P.opcode="";\\n}else{if(P.chars\\x3c=Q.chars){Q.chars-=P.chars;Q.lines-=P.lines;P.opcode="";if(!Q.chars){Q.opcode="";}}else{R.lines=Q.lines;\\nR.chars=Q.chars;P.lines-=Q.lines;P.chars-=Q.chars;Q.opcode="";}}}else{if(!Q.opcode){Changeset.copyOp(P,R);\\nP.opcode="";}else{if(!P.opcode){Changeset.copyOp(Q,R);Q.opcode="";}else{R.opcode="=";R.attribs=Changeset.followAttributes(Q.attribs,P.attribs,G);\\nif(Q.chars\\x3c=P.chars){R.chars=Q.chars;R.lines=Q.lines;P.chars-=Q.chars;P.lines-=Q.lines;Q.opcode="";if(!P.chars){P.opcode="";\\n}}else{R.chars=P.chars;R.lines=P.lines;Q.chars-=P.chars;Q.lines-=P.lines;P.opcode="";}}}}}}switch(R.opcode){case"=":D+=R.chars;\\nA+=R.chars;break;case"-":D+=R.chars;break;case"+":A+=R.chars;break;}});A+=F-D;return Changeset.pack(F,A,J,B.charBank);\\n};Changeset.followAttributes=function(F,E,B){if((!E)||(!B)){return"";}if(!F){return E;}var A=[];E.replace(/\\\\*([0-9a-z]+)/g,function(H,G){A.push(B.getAttrib(Changeset.parseNum(G)));\\nreturn"";});F.replace(/\\\\*([0-9a-z]+)/g,function(K,J){var I=B.getAttrib(Changeset.parseNum(J));for(var G=0;\\nG\\x3cA.length;G++){var H=A[G];if(I[0]==H[0]){if(I[1]\\x3c=H[1]){A.splice(G,1);}break;}}return"";});var C=Changeset.stringAssembler();\\nfor(var D=0;D\\x3cA.length;D++){C.append("*");C.append(Changeset.numToString(B.putAttrib(A[D])));}return C.toString();\\n};function makeCSSManager(I){function E(N){var M=document.styleSheets;for(var K=0;K\\x3cM.length;K++){var L=M[K];\\nif(L.title==N){return L;}}return null;}var A=E(I);function C(){return(A.cssRules||A.rules);}function H(K){if(A.deleteRule){A.deleteRule(K);\\n}else{A.removeRule(K);}}function F(L,K){if(A.insertRule){A.insertRule(K+" {}",L);}else{A.addRule(K,null,L);\\n}}var B=[];function D(L){for(var K=0;K\\x3cB.length;K++){if(B[K]==L){return K;}}return -1;}function G(K){var L=D(K);\\nif(L\\x3c0){F(0,K);B.splice(0,0,K);L=0;}return C().item(L).style;}function J(L){var K=D(L);if(K>=0){H(K);\\nB.splice(K,1);}}return{selectorStyle:G,removeSelectorStyle:J,info:function(){return B.length+":"+C().length;\\n}};}var colorutils={};colorutils.css2triple=function(C){var B=colorutils.css2sixhex(C);function A(D){return Number("0x"+D)/255;\\n}return[A(B.substr(0,2)),A(B.substr(2,2)),A(B.substr(4,2))];};colorutils.css2sixhex=function(E){var A=/[0-9a-fA-F]+/.exec(E)[0];\\nif(A.length!=6){var C=A.charAt(0);var B=A.charAt(1);var D=A.charAt(2);A=C+C+B+B+D+D;}return A;};colorutils.triple2css=function(B){function A(D){var C=colorutils.clamp(Math.round(D*255),0,255);\\nreturn("0"+C.toString(16)).slice(-2);}return"#"+A(B[0])+A(B[1])+A(B[2]);};colorutils.clamp=function(A,C,B){return A\\x3cC?C:(A>B?B:A);\\n};colorutils.min3=function(C,B,A){return(C\\x3cB)?(C\\x3cA?C:A):(B\\x3cA?B:A);};colorutils.max3=function(C,B,A){return(C>B)?(C>A?C:A):(B>A?B:A);\\n};colorutils.colorMin=function(A){return colorutils.min3(A[0],A[1],A[2]);};colorutils.colorMax=function(A){return colorutils.max3(A[0],A[1],A[2]);\\n};colorutils.scale=function(B,A,C){return colorutils.clamp(A+B*(C-A),0,1);};colorutils.unscale=function(B,A,C){return colorutils.clamp((B-A)/(C-A),0,1);\\n};colorutils.scaleColor=function(C,B,A){return[colorutils.scale(C[0],B,A),colorutils.scale(C[1],B,A),colorutils.scale(C[2],B,A)];\\n};colorutils.unscaleColor=function(C,B,A){return[colorutils.unscale(C[0],B,A),colorutils.unscale(C[1],B,A),colorutils.unscale(C[2],B,A)];\\n};colorutils.luminosity=function(A){return A[0]*0.3+A[1]*0.59+A[2]*0.11;};colorutils.saturate=function(A){var C=colorutils.colorMin(A);\\nvar B=colorutils.colorMax(A);if(B-C\\x3c=0){return[1,1,1];}return colorutils.unscaleColor(A,C,B);};colorutils.blend=function(C,B,A){return[colorutils.scale(A,C[0],B[0]),colorutils.scale(A,C[1],B[1]),colorutils.scale(A,C[2],B[2])];\\n};undoModule=(function(){var A=(function(){var M=[];var O=0;var Q="undoableEvent";var N="externalChange";\\nfunction P(){M.length=0;M.push({elementType:Q,eventType:"bottom"});O=1;}P();function T(Y){var X=extend({},Y);\\nX.elementType=Q;M.push(X);O++;}function U(Y){var X=M.length-1;if(M[X].elementType==N){M[X].changeset=Changeset.compose(M[X].changeset,Y,D());\\n}else{M.push({elementType:N,changeset:Y});}}function R(e){var c=M.length-1-e;var X=M.length-1;while(X>c||M[X].elementType==N){if(M[X].elementType==N){var Z=M[X];\\nvar Y=M[X-1];if(Y.backset){var b=Z.changeset;var d=Y.backset;Y.backset=Changeset.follow(b,Y.backset,false,D());\\nZ.changeset=Changeset.follow(d,Z.changeset,true,D());if((typeof Y.selStart)=="number"){var a=Changeset.characterRangeFollow(b,Y.selStart,Y.selEnd);\\nY.selStart=a[0];Y.selEnd=a[1];if(Y.selStart==Y.selEnd){Y.selFocusAtStart=false;}}}M[X-1]=Z;M[X]=Y;if(X>=2&&M[X-2].elementType==N){Z.changeset=Changeset.compose(M[X-2].changeset,Z.changeset,D());\\nM.splice(X-2,1);X--;}}else{X--;}}}function W(X){R(X);return M[M.length-1-X];}function V(){return O;}function S(){R(0);\\nO--;return M.pop();}return{numEvents:V,popEvent:S,pushEvent:T,pushExternalChange:U,clearStack:P,getNthFromTop:W};\\n})();var B=0;function J(){A.clearStack();B=0;}function H(O,P){var M=0;var N=0;while(M>=0&&M\\x3cO.length){M=O.indexOf(P,M);\\nif(M>=0){N++;M++;}}return N;}function C(M,N){return H(Changeset.unpack(M).ops,N);}function K(N,M){if(!N){return M;\\n}if(!M){return N;}var U=C(N,"+");var T=C(M,"+");var R=C(N,"-");var Q=C(M,"-");if(U==1&&T==1&&R==0&&Q==0){var O=Changeset.compose(N,M,D());\\nvar S=C(O,"+");var P=C(O,"-");if(S==1&&P==0){return O;}}else{if(U==0&&T==0&&R==1&&Q==1){var O=Changeset.compose(N,M,D());\\nvar S=C(O,"+");var P=C(O,"-");if(S==0&&P==1){return O;}}}return null;}function I(M){var N=A.getNthFromTop(0);\\nfunction P(){if((typeof M.selStart)=="number"){N.selStart=M.selStart;N.selEnd=M.selEnd;N.selFocusAtStart=M.selFocusAtStart;\\n}}if((!M.backset)||Changeset.isIdentity(M.backset)){P();}else{var O=false;if(N.eventType==M.eventType){var Q=K(M.backset,N.backset);\\nif(Q){N.backset=Q;P();O=true;}}if(!O){A.pushEvent(M);}B=0;}}function G(M){if(M&&!Changeset.isIdentity(M)){A.pushExternalChange(M);\\n}}function E(M){if((typeof M.selStart)!="number"){return null;}else{return{selStart:M.selStart,selEnd:M.selEnd,selFocusAtStart:M.selFocusAtStart};\\n}}function F(M){if(B\\x3cA.numEvents()-1){var O=A.getNthFromTop(B);var N=A.getNthFromTop(B+1);var P=M(O.backset,E(N));\\nA.pushEvent(P);B+=2;}else{M();}}function L(M){if(B>=2){var O=A.getNthFromTop(0);var N=A.getNthFromTop(1);\\nM(O.backset,E(N));A.popEvent();B-=2;}else{M();}}function D(){return undoModule.apool;}return{clearHistory:J,reportEvent:I,reportExternalChange:G,performUndo:F,performRedo:L,enabled:true,apool:null};\\n})();var _MAX_LIST_LEVEL=8;function sanitizeUnicode(A){return A.replace(/[\\\\uffff\\\\ufffe\\\\ufeff\\\\ufdd0-\\\\ufdef\\\\ud800-\\\\udfff]/g,"?");\\n}function makeContentCollector(h,H,M,Y,U){H=H||{};var B=Y||{isNodeText:function(k){return(k.nodeType==3);\\n},nodeTagName:function(k){return k.tagName;},nodeValue:function(k){return k.nodeValue;},nodeNumChildren:function(k){return k.childNodes.length;\\n},nodeChild:function(l,k){return l.childNodes.item(k);},nodeProp:function(l,k){return l[k];},nodeAttr:function(l,k){return l.getAttribute(k);\\n},optNodeInnerHTML:function(k){return k.innerHTML;}};var i={div:1,p:1,pre:1,li:1};function R(k){return !!i[(B.nodeTagName(k)||"").toLowerCase()];\\n}function e(k){return sanitizeUnicode(k.replace(/[\\\\n\\\\r ]/g," ").replace(/\\\\xa0/g," ").replace(/\\\\t/g," "));\\n}function Q(l,k){return B.nodeProp(l,"_magicdom_"+k);}var A=(function(){var k=[];var o=[];var l=null;\\nvar n=Changeset.newOp("+");var m={length:function(){return k.length;},atColumnZero:function(){return k[k.length-1]==="";\\n},startNew:function(){k.push("");m.flush(true);l=Changeset.smartOpAssembler();},textOfLine:function(p){return k[p];\\n},appendText:function(p,q){k[k.length-1]+=p;n.attribs=q;n.chars=p.length;l.append(n);},textLines:function(){return k.slice();\\n},attribLines:function(){return o;},flush:function(p){if(l){o.push(l.toString());l=null;}}};m.startNew();\\nreturn m;}());var E={};function O(k){if(!A.atColumnZero()){K(k);}}var N,D,C;var J=[-1,-1],I=[-1,-1];var j={div:1,p:1,pre:1};\\nfunction S(k,l){if(B.nodeNumChildren(k)==0){return true;}if(B.nodeNumChildren(k)==1&&Q(k,"shouldBeEmpty")&&B.optNodeInnerHTML(k)==" "&&!Q(k,"unpasted")){if(l){var m=B.nodeChild(k,0);\\nL(m,0,l);L(m,1,l);}return true;}return false;}function F(n,m){var l=A.length()-1;var k=A.textOfLine(l).length;\\nif(k==0&&m.listType&&m.listType!="none"){k+=1;}k+=n;return[l,k];}function P(k,l,m){if(!B.isNodeText(k)){L(k,l,m);\\n}}function L(m,k,l){if(D&&m==D.node&&D.index==k){J=F(0,l);}if(C&&m==C.node&&C.index==k){I=F(0,l);}}function b(k,l){k.flags[l]=(k.flags[l]||0)+1;\\n}function W(k,l){k.flags[l]--;}function X(k,l){if(!k.attribs[l]){k.attribs[l]=1;}else{k.attribs[l]++;\\n}G(k);}function f(k,l){k.attribs[l]--;G(k);}function T(k,l){var m=k.listType;k.listLevel=(k.listLevel||0)+1;\\nif(l!="none"){k.listNesting=(k.listNesting||0)+1;}k.listType=l;G(k);return m;}function d(k,l){k.listLevel--;\\nif(k.listType!="none"){k.listNesting--;}k.listType=l;G(k);}function c(k,m){var l=k.author;k.authorLevel=(k.authorLevel||0)+1;\\nk.author=m;G(k);return l;}function g(k,l){k.authorLevel--;k.author=l;G(k);}function G(k){var l=[];for(var m in k.attribs){if(k.attribs[m]){l.push([m,"true"]);\\n}}if(k.authorLevel>0){var n=["author",k.author];if(M.putAttrib(n,true)>=0){l.push(n);}}k.attribString=Changeset.makeAttribsString("+",l,M);\\n}function V(k){A.appendText("*",Changeset.makeAttribsString("+",[["list",k.listType],["insertorder","first"]],M));\\n}function K(k){if(k){var l=A.textOfLine(A.length()-1).length==0;if(l&&k.listType&&k.listType!="none"){V(k);\\n}}A.startNew();}E.notifySelection=function(k){if(k){N=k;D=N.startPoint;C=N.endPoint;}};E.collectContent=function(l,k){if(!k){k={flags:{},attribs:{},attribString:""};\\n}var AF=R(l);var AK=S(l,k);if(AF){O(k);}var AL=A.length()-1;P(l,0,k);if(B.isNodeText(l)){var n=B.nodeValue(l);\\nvar AG="";var s=0;if(n.length==0){if(D&&l==D.node){J=F(0,k);}if(C&&l==C.node){I=F(0,k);}}while(n.length>0){var AA=0;\\nif(k.flags.preMode){var AE=n.split("\\\\n",1)[0];AA=AE.length+1;AG=n.substring(AA);n=AE;}else{}if(D&&l==D.node&&D.index-s\\x3c=n.length){J=F(D.index-s,k);\\n}if(C&&l==C.node&&C.index-s\\x3c=n.length){I=F(C.index-s,k);}var t=n;if((!k.flags.preMode)&&/^[\\\\r\\\\n]*$/.exec(n)){t="";\\n}var AC=A.textOfLine(A.length()-1).length==0;if(AC){t=t.replace(/^\\\\n*/,"");}if(AC&&k.listType&&k.listType!="none"){V(k);\\n}A.appendText(e(t),k.attribString);s+=AA;n=AG;if(n.length>0){K(k);}}}else{var m=(B.nodeTagName(l)||"").toLowerCase();\\nif(m=="br"){K(k);}else{if(m=="script"||m=="style"){}else{if(!AK){var o=B.nodeAttr(l,"style");var q=B.nodeProp(l,"className");\\nvar w=(m=="pre");if((!w)&&H.safari){w=(o&&/\\\\bwhite-space:\\\\s*pre\\\\b/i.exec(o));}if(w){b(k,"preMode");}var r=null;\\nvar v=null;var AB=null;if(h){function u(x){r=(r||[]);r.push(x);X(k,x);}if(m=="b"||(o&&/\\\\bfont-weight:\\\\s*bold\\\\b/i.exec(o))||m=="strong"){u("bold");\\n}if(m=="i"||(o&&/\\\\bfont-style:\\\\s*italic\\\\b/i.exec(o))||m=="em"){u("italic");}if(m=="u"||(o&&/\\\\btext-decoration:\\\\s*underline\\\\b/i.exec(o))||m=="ins"){u("underline");\\n}if(m=="s"||(o&&/\\\\btext-decoration:\\\\s*line-through\\\\b/i.exec(o))||m=="del"){u("strikethrough");}if(m=="ul"){var z;\\nvar AD=q&&/(?:^| )list-(bullet[12345678])\\\\b/.exec(q);z=AD&&AD[1]||"bullet"+String(Math.min(_MAX_LIST_LEVEL,(k.listNesting||0)+1));\\nv=(T(k,z)||"none");}else{if((m=="div"||m=="p")&&q&&q.match(/(?:^| )ace-line\\\\b/)){v=(T(k,z)||"none");}}if(U&&q){var y=q.match(/\\\\S+/g);\\nif(y&&y.length>0){for(var p=0;p\\x3cy.length;p++){var AH=y[p];var AI=U(AH);if(AI){AB=(c(k,AI)||"none");break;\\n}}}}}var AJ=B.nodeNumChildren(l);for(var p=0;p\\x3cAJ;p++){var AH=B.nodeChild(l,p);E.collectContent(AH,k);\\n}if(w){W(k,"preMode");}if(r){for(var p=0;p\\x3cr.length;p++){f(k,r[p]);}}if(v){d(k,v);}if(AB){g(k,AB);}}}}}if(!H.msie){P(l,1,k);\\n}if(AF){if(A.length()-1==AL){K(k);}else{O(k);}}if(H.msie){P(l,1,k);}};E.notifyNextNode=function(k){if((!k)||(R(k)&&!S(k))){O(null);\\n}};var a=function(){return J;};var Z=function(){return I;};E.getLines=function(){return A.textLines();\\n};E.finish=function(){A.flush();var l=A.attribLines();var k=E.getLines();k.length--;l.length--;var n=a();\\nvar o=Z();function p(){var v=2000;var z=10;var x=0;var w=0;for(var q=k.length-1;q>=0;q--){var s=k[q];\\nvar u=l[q];if(s.length>v+z){var r=[];var t=[];while(s.length>v){lengthToTake=v;r.push(s.substring(0,lengthToTake));\\ns=s.substring(lengthToTake);t.push(Changeset.subattribution(u,0,lengthToTake));u=Changeset.subattribution(u,lengthToTake);\\n}if(s.length>0){r.push(s);t.push(u);}function y(AA){if(AA[0]\\x3c0){return;}var AB=AA[0];var AD=AA[1];if(AB>q){AB+=(r.length-1);\\n}else{if(AB==q){var AC=0;while(AD>r[AC].length){AD-=r[AC].length;AC++;}AB+=AC;}}AA[0]=AB;AA[1]=AD;}y(n);\\ny(o);x++;w+=r.length;r.unshift(q,1);k.splice.apply(k,r);t.unshift(q,1);l.splice.apply(l,t);}}return{linesWrapped:x,numLinesAfter:w};\\n}var m=p();return{selStart:n,selEnd:o,linesWrapped:m.linesWrapped,numLinesAfter:m.numLinesAfter,lines:k,lineAttribs:l};\\n};return E;}function makeChangesetTracker(K,A,J){var D=Changeset.makeAText("\\\\n");var B=null;var C=Changeset.identity(1);\\nvar F=false;var E=false;var G=null;var H=null;function L(){if(G&&H===null){H=K.setTimeout(function(){try{G();\\n}finally{H=null;}},0);}}var I;return I={isTracking:function(){return F;},setBaseText:function(M){I.setBaseAttributedText(Changeset.makeAText(M),null);\\n},setBaseAttributedText:function(M,N){J.withCallbacks("setBaseText",function(P){F=true;D=Changeset.cloneAText(M);\\nif(N){var O=(new AttribPool()).fromJsonable(N);D.attribs=Changeset.moveOpsToNewPool(D.attribs,O,A);}B=null;\\nC=Changeset.identity(M.text.length);E=true;try{P.setDocumentAttributedText(M);}finally{E=false;}});},composeUserChangeset:function(M){if(!F){return;\\n}if(E){return;}if(Changeset.isIdentity(M)){return;}C=Changeset.compose(C,M,A);L();},applyChangesToBase:function(M,O,N){if(!F){return;\\n}J.withCallbacks("applyChangesToBase",function(V){if(N){var U=(new AttribPool()).fromJsonable(N);M=Changeset.moveOpsToNewPool(M,U,A);\\n}D=Changeset.applyToAText(M,D,A);var P=M;if(B){var Q=B;B=Changeset.follow(M,Q,false,A);P=Changeset.follow(Q,M,true,A);\\n}var R=true;var S=C;C=Changeset.follow(P,S,R,A);var T=Changeset.follow(S,P,!R,A);var W=true;E=true;try{V.applyChangesetToDocument(T,W);\\n}finally{E=false;}});},prepareUserChangeset:function(){var M;if(B){M=Changeset.compose(B,C,A);}else{if(Changeset.isIdentity(C)){M=null;\\n}else{M=C;}}var N=null;if(M){B=M;C=Changeset.identity(Changeset.newLen(M));N=M;}var P=null;if(N){var O=Changeset.prepareForWire(N,A);\\nP=O.pool.toJsonable();N=O.translated;}var Q={changeset:N,apool:P};return Q;},applyPreparedChangesetToBase:function(){if(!B){throw new Error("applySubmittedChangesToBase: no submitted changes to apply");\\n}D=Changeset.applyToAText(B,D,A);B=null;},setUserChangeNotificationCallback:function(M){G=M;},hasUncommittedChanges:function(){return !!(B||(!Changeset.isIdentity(C)));\\n}};}var linestylefilter={};linestylefilter.ATTRIB_CLASSES={bold:"tag:b",italic:"tag:i",underline:"tag:u",strikethrough:"tag:s"};\\nlinestylefilter.getAuthorClassName=function(A){return"author-"+A.replace(/[^a-y0-9]/g,function(B){if(B=="."){return"-";\\n}return"z"+B.charCodeAt(0)+"z";});};linestylefilter.getLineStyleFilter=function(B,E,A,D){if(B==0){return A;\\n}var C=A;var F=(function(){var N=B;var L=0;var J;var G;function P(R){var Q="";Changeset.eachAttribNumber(R,function(U){var S=D.getAttribKey(U);\\nif(S){var T=D.getAttribValue(U);if(T){if(S=="author"){Q+=" "+linestylefilter.getAuthorClassName(T);}else{if(S=="list"){Q+=" list:"+T;\\n}else{if(linestylefilter.ATTRIB_CLASSES[S]){Q+=" "+linestylefilter.ATTRIB_CLASSES[S];}}}}}});return Q.substring(1);\\n}var O=Changeset.opIterator(E);var H,I;function K(){H=O.next();I=(H.opcode&&P(H.attribs));}K();function M(){if(L\\x3cN){J=I;\\nG=H.chars;K();while(H.opcode&&I==J){G+=H.chars;K();}}}M();return function(Q,S){while(Q.length>0){if(G\\x3c=0){return C(Q,S);\\n}var R=Q.length;if(R>G){R=G;}var T=Q.substring(0,R);Q=Q.substring(R);C(T,(S&&S+" ")+J);L+=R;G-=R;if(G==0){M();\\n}}};})();return F;};linestylefilter.getAtSignSplitterFilter=function(E,C){var B=/@/g;B.lastIndex=0;var A=null;\\nvar D;while((D=B.exec(E))){if(!A){A=[];}A.push(D.index);}if(!A){return C;}return linestylefilter.textAndClassFuncSplitter(C,A);\\n};linestylefilter.REGEX_WORDCHAR=/[\\\\u0030-\\\\u0039\\\\u0041-\\\\u005A\\\\u0061-\\\\u007A\\\\u00C0-\\\\u00D6\\\\u00D8-\\\\u00F6\\\\u00F8-\\\\u00FF\\\\u0100-\\\\u1FFF\\\\u3040-\\\\u9FFF\\\\uF900-\\\\uFDFF\\\\uFE70-\\\\uFEFE\\\\uFF10-\\\\uFF19\\\\uFF21-\\\\uFF3A\\\\uFF41-\\\\uFF5A\\\\uFF66-\\\\uFFDC]/;\\nlinestylefilter.REGEX_URLCHAR=new RegExp("("+/[-:@a-zA-Z0-9_.,~%+\\\\\\x2f\\\\\\\\?=&#;()$]/.source+"|"+linestylefilter.REGEX_WORDCHAR.source+")");\\nlinestylefilter.REGEX_URL=new RegExp(/(?:(?:https?|s?ftp|ftps|file|smb|afp|nfs|(x-)?man|gopher|txmt):\\\\\\x2f\\\\\\x2f|mailto:)/.source+linestylefilter.REGEX_URLCHAR.source+"*(?![:.,;])"+linestylefilter.REGEX_URLCHAR.source,"g");\\nlinestylefilter.getURLFilter=function(I,F){linestylefilter.REGEX_URL.lastIndex=0;var A=null;var C=null;\\nvar B;while((B=linestylefilter.REGEX_URL.exec(I))){if(!A){A=[];C=[];}var D=B.index;var E=B[0];A.push([D,E]);\\nC.push(D,D+E.length);}if(!A){return F;}function G(L){for(var K=0;K\\x3cA.length;K++){var J=A[K];if(L>=J[0]&&L\\x3cJ[0]+J[1].length){return J[1];\\n}}return false;}var H=(function(){var J=0;return function(K,N){var O=K.length;var M=N;var L=G(J);if(L){M+=" url:"+L;\\n}F(K,M);J+=O;};})();return linestylefilter.textAndClassFuncSplitter(H,C);};linestylefilter.textAndClassFuncSplitter=function(D,B){var A=0;\\nvar C=0;while(B&&A\\x3cB.length&&B[A]==0){A++;}function E(F,H){if((!B)||A>=B.length){D(F,H);C+=F.length;}else{var J=B;\\nvar G=J[A]-C;var I=F.length;if(G>=I){D(F,H);C+=F.length;if(G==I){A++;}}else{if(G>0){D(F.substring(0,G),H);\\nC+=G;}A++;E(F.substring(G),H);}}}return E;};linestylefilter.populateDomLine=function(F,D,E,G){var A=F;\\nif(A.slice(-1)=="\\\\n"){A=A.substring(0,A.length-1);}function C(H,I){G.appendSpan(H,I);}var B=C;B=linestylefilter.getURLFilter(A,B);\\nB=linestylefilter.getLineStyleFilter(A.length,D,B,E);B(A,"");};var domline={};domline.noop=function(){};\\ndomline.identity=function(A){return A;};domline.addToLineClass=function(A,B){B.replace(/\\\\S+/g,function(C){if(C.indexOf("line:")==0){A=(A?A+" ":"")+C.substring(5);\\n}});return A;};domline.createDomLine=function(N,H,J,O){var A={node:null,appendSpan:domline.noop,prepareForAdd:domline.noop,notifyAdded:domline.noop,clearSpans:domline.noop,finishUpdate:domline.noop,lineMarker:0};\\nvar M=(J||{});var G=O;if(G){A.node=G.createElement("div");}else{A.node={innerHTML:"",className:""};}var D=[];\\nvar F,E;var C=null;function K(R){return domline.processSpaces(R,H);}var L=domline.identity;var Q=(H?L:K);\\nvar P=(H?K:L);var B="ace-line";A.appendSpan=function(W,R){if(R.indexOf("list")>=0){var U=/(?:^| )list:(\\\\S+)/.exec(R);\\nif(U){U=U[1];if(U){F=\\\'\\x3cul class="list-\\\'+U+\\\'">\\x3cli>\\\';E="\\x3c/li>\\x3c/ul>";}A.lineMarker+=W.length;return;}}var X=null;\\nvar S=null;if(R.indexOf("url")>=0){R=R.replace(/(^| )url:(\\\\S+)/g,function(a,Z,Y){X=Y;return Z+"url";});\\n}if(R.indexOf("tag")>=0){R=R.replace(/(^| )tag:(\\\\S+)/g,function(a,Z,Y){if(!S){S=[];}S.push(Y.toLowerCase());\\nreturn Z+Y;});}if((!W)&&R){B=domline.addToLineClass(B,R);}else{if(W){var T="";var V="";if(X){T=T+\\\'\\x3ca href="\\\'+X.replace(/\\\\"/g,""")+\\\'">\\\';\\nV="\\x3c/a>"+V;}if(S){S.sort();T=T+"\\x3c"+S.join(">\\x3c")+">";S.reverse();V="\\x3c/"+S.join(">\\x3c/")+">"+V;}D.push(\\\'\\x3cspan class="\\\',R||"",\\\'">\\\',T,Q(domline.escapeHTML(W)),V,"\\x3c/span>");\\n}}};A.clearSpans=function(){D=[];B="";A.lineMarker=0;};function I(){var R=P(D.join(""));if(!R){if((!G)||(!J)){R+=" ";\\n}else{if(!M.msie){R+="\\x3cbr/>";}}}if(N){R=(F||"")+R+(E||"");}D=F=E=null;if(R!==C){C=R;A.node.innerHTML=C;\\n}if(B!==null){A.node.className=B;}}A.prepareForAdd=I;A.finishUpdate=I;A.getInnerHTML=function(){return C||"";\\n};return A;};domline.escapeHTML=function(B){var A=/[&\\x3c>\\\'"]/g;/\\\']/;if(!A.MAP){A.MAP={"&":"&","\\x3c":"<",">":">",\\\'"\\\':""","\\\'":"'"};\\n}return B.replace(A,function(C){return A.MAP[C];});};domline.processSpaces=function(F,G){if(F.indexOf("\\x3c")\\x3c0&&!G){return F.replace(/ /g," ");\\n}var B=[];F.replace(/\\x3c[^>]*>?| |[^ \\x3c]+/g,function(H){B.push(H);});if(G){var D=true;var E=false;for(var A=B.length-1;\\nA>=0;A--){var C=B[A];if(C==" "){if(D||E){B[A]=" ";}D=false;E=true;}else{if(C.charAt(0)!="\\x3c"){D=false;\\nE=false;}}}for(var A=0;A\\x3cB.length;A++){var C=B[A];if(C==" "){B[A]=" ";break;}else{if(C.charAt(0)!="\\x3c"){break;\\n}}}}else{for(var A=0;A\\x3cB.length;A++){var C=B[A];if(C==" "){B[A]=" ";}}}return B.join("");};\'+\'//-->\\n\\x3c/script>\')')); -T.push(('(\'\\x3cscript type="text/javascript">//<!--\\n\'+\'function OUTER(Cj){var AK=false;var B4=false;var Ad=" ";var BW=8;var BO=4;var CC=4;var Ah=20;var Bj=8;\\nvar BS=8;var BU=[];var e="";var BL=false;var D=parent.editorInfo;var g=window.frameElement;var F=g.ace_outerWin;\\ng.ace_outerWin=null;var T=g.nextSibling;var w=T.nextSibling;var Cb=w.nextSibling;BX();var Au=function(i){};\\nvar Ar=function(i){return true;};var An=function(){};var A={lines:newSkipList(),selStart:null,selEnd:null,selFocusAtStart:false,alltext:"",alines:[],apool:new AttribPool()};\\nif(undoModule.enabled){undoModule.apool=A.apool;}var B,E;var k=true;var K=true;var AP=true;var AX=true;\\nvar p=Ah+BO+BS;var Aj=Bj;var Bo=0,CQ=0;var S=(AK&&top.console);if(!S){var Al=["log","debug","info","warn","error","assert","dir","dirxml","group","groupEnd","time","timeEnd","count","trace","profile","profileEnd"];\\nS={};for(var Ag=0;Ag\\x3cAl.length;++Ag){S[Al[Ag]]=function(){};}}var O=window.PROFILER;if(!O){O=function(){return{start:I,mark:I,literal:I,end:I,cancel:I};\\n};}function I(){}function Ce(i){return i;}var v=I;window.dmesg=I;var N=parent;var AQ="monospace";var u=12;\\nfunction AV(){return Math.round(u*4/3);}var W=null;function Bh(){W=makeCSSManager("dynamicsyntax");}var M=makeChangesetTracker(N,A.apool,{withCallbacks:function(i,Cp){Y(i,function(){G(1);\\nCp({setDocumentAttributedText:function(Cq){Aa(Cq);},applyChangesetToDocument:function(Cs,Cr){var Cq=C.editEvent.eventType;\\nC.startNewEvent("nonundoable");b(Cs,Cr);C.startNewEvent(Cq);}});});}});var Ao={};function CV(i,Cp){if((typeof i)!="string"){throw new Error("setAuthorInfo: author ("+i+") is not a string");\\n}if(!Cp){delete Ao[i];if(W){W.removeSelectorStyle(Av(BP(i)));}}else{Ao[i]=Cp;if(Cp.bgcolor){if(W){var Cq=Cp.bgcolor;\\nif((typeof Cp.fade)=="number"){Cq=BZ(Cq,Cp.fade);}W.selectorStyle(Av(BP(i))).backgroundColor=Cq;}}}}function BP(i){return"author-"+i.replace(/[^a-y0-9]/g,function(Cp){if(Cp=="."){return"-";\\n}return"z"+Cp.charCodeAt(0)+"z";});}function Bd(i){if(i.substring(0,7)=="author-"){return i.substring(7).replace(/[a-y0-9]+|-|z.+?z/g,function(Cp){if(Cp=="-"){return".";\\n}else{if(Cp.charAt(0)=="z"){return String.fromCharCode(Number(Cp.slice(1,-1)));}else{return Cp;}}});}return null;\\n}function Av(i){return".authorColors ."+i;}function AS(){if(W){var Cp=w.offsetHeight;var Cq=AV();var i=0;\\nvar Cs=0;if(Cp\\x3cCq){i=Math.ceil((Cq-Cp)/2);Cs=Cq-Cp-i;}var Cr=W.selectorStyle("#innerdocbody span");Cr.paddingTop=Cs+"px";\\nCr.paddingBottom=i+"px";}}function Ci(Cp){var i=colorutils.css2triple(Cp);i=colorutils.saturate(i);i=colorutils.scaleColor(i,0,0.5/colorutils.luminosity(i));\\nreturn colorutils.triple2css(i);}function BZ(Cp,Cq){var i=colorutils.css2triple(Cp);i=colorutils.blend(i,[1,1,1],Cq);\\nreturn colorutils.triple2css(i);}function By(i){N.setTimeout(function(){alert(i);},0);}var C=null;function a(Cq,Cx){if(BL){return;\\n}if(C){S.error("Can\\\'t enter callstack "+Cq+", already in "+C.type);}var Ct=false;function Cw(){Ct=true;\\nS.profile();}function Cr(Cz){return{eventType:Cz,backset:null};}function Cs(Cz){if(A.selStart&&A.selEnd){var C2=A.lines.offsetOfIndex(A.selStart[0])+A.selStart[1];\\nvar C1=A.lines.offsetOfIndex(A.selEnd[0])+A.selEnd[1];Cz.selStart=C2;Cz.selEnd=C1;Cz.selFocusAtStart=A.selFocusAtStart;\\n}if(undoModule.enabled){var C0=false;try{if(Cz.eventType=="setup"||Cz.eventType=="importText"||Cz.eventType=="setBaseText"){undoModule.clearHistory();\\n}else{if(Cz.eventType=="nonundoable"){if(Cz.changeset){undoModule.reportExternalChange(Cz.changeset);\\n}}else{undoModule.reportEvent(Cz);}}C0=true;}finally{if(!C0){undoModule.enabled=false;}}}}function Cy(C1,C0){var Cz=C.editEvent;\\nif(!C0){Cs(Cz);}C.editEvent=Cr(C1);return Cz;}C={type:Cq,docTextChanged:false,selectionAffected:false,userChangedSelection:false,domClean:false,profileRest:Cw,isUserChange:false,repChanged:false,editEvent:Cr(Cq),startNewEvent:Cy};\\nvar Cu=false;var Cv;try{Cv=Cx();Cu=true;}catch(Cp){BU.push({error:Cp,time:+new Date()});v(Cp.toString());\\nthrow Cp;}finally{var i=C;if(Cu){Cs(i.editEvent);if(i.domClean&&i.type!="setup"){if(i.isUserChange){if(i.repChanged){AG.notifyChange();\\n}else{AG.notifyTick();}}Be.recolorLines();if(i.selectionAffected){Ba();}if((i.docTextChanged||i.userChangedSelection)&&i.type!="applyChangesToBase"){CP();\\n}if(i.docTextChanged&&i.type.indexOf("importText")\\x3c0){An();}}}else{if(C.type=="idleWorkTimer"){H.atLeast(1000);\\n}}C=null;if(Ct){S.profileEnd();}}return Cv;}function Y(Cp,i){if(!C){a(Cp,i);}else{i();}}function Af(i){if(A.lines.containsKey(i)){var Cp=A.lines.offsetOfKey(i);\\nvar Cq=A.lines.atKey(i).width;AU(Cp,Cp+Cq);}}function AL(i){return A.lines.atOffset(i).key;}var Be=(function(){var i={};\\nvar Cp={};Cp.setCharNeedsRecoloring=function(Cq){if(Cq>=A.alltext.length){Cq=A.alltext.length-1;}i[AL(Cq)]=true;\\n};Cp.setCharRangeNeedsRecoloring=function(Cs,Cr){if(Cs>=A.alltext.length){Cs=A.alltext.length-1;}if(Cr>=A.alltext.length){Cr=A.alltext.length-1;\\n}var Cu=A.lines.atOffset(Cs);var Ct=A.lines.atOffset(Cr).key;i[Ct]=true;var Cq=Cu;while(Cq&&Cq.key!=Ct){i[Cq.key]=true;\\nCq=A.lines.next(Cq);}};Cp.recolorLines=function(){for(var Cq in i){Af(Cq);}i={};};return Cp;})();var AG=(function(){var i={};\\ni.notifyTick=function(){Cr(false);};i.notifyChange=function(){Cr(true);};i.shouldNormalizeOnChar=function(Ct){if(Cq.active){return true;\\n}Ct=String.fromCharCode(Ct);return !!(Cp[Ct]);};var Cq={active:false,whichChars:null,whichLineKeys:null,expireTime:null};\\nvar Cp={"(":1,")":-1,"[":2,"]":-2,"{":3,"}":-3};var Cs=/[{}\\\\[\\\\]()]/g;function Cr(C0){function C5(C8){var C7=BI();\\nvar DA=100;var C9=3000;if(C7[0]>C8-DA){C7[0]=C8-DA;}if(C7[0]\\x3cC8-C9){C7[0]=C8-C9;}if(C7[0]\\x3c0){C7[0]=0;\\n}if(C7[1]\\x3cC8+DA){C7[1]=C8+DA;}if(C7[1]>C8+C9){C7[1]=C8+C9;}if(C7[1]>A.lines.totalWidth()){C7[1]=A.lines.totalWidth();\\n}return C7;}function C6(DH,DC){var C8=C5(DH);var DF=A.alltext.substring(C8[0],C8[1]);var DG=DF.replace(Cs,"(");\\nvar C7=DH-C8[0];var DE=[];var DA=false;var DB=false;function DI(){if(C7\\x3c0){return;}if(DC){C7++;}else{C7--;\\n}if(C7\\x3c0||C7>=DF.length){C7=-1;}if(C7>=0){if(DC){C7=DG.indexOf("(",C7);}else{C7=DG.lastIndexOf("(",C7);\\n}}}while((!DA)&&(C7>=0)){if(BH(C7+C8[0])=="p"){var DJ=Cp[DF.charAt(C7)];var DD=DC;var C9=DJ;if(C9\\x3c0){DD=!DD;\\nC9=-C9;}if(DD){DE.push(C9);}else{var DK=DE.pop();if(DK!=C9){DA=true;DB=false;}else{if(DE.length==0){DA=true;\\nDB=true;}}}}if((!DA)&&(C7>=0)){DI();}}if(!DA){return null;}return{chr:(C7+C8[0]),good:DB};}var Ct=Cq;\\nvar Cu=null;var Cw=null;if(Ct.active&&(C0||(R()>Ct.expireTime))){Cw=Ct.whichLineKeys;Ct.active=false;\\n}if((!Ct.active)&&C0&&U()&&t()>0){var Cv=A7();if(Cv>0&&BH(Cv-1)=="p"){var Cz=A.alltext.charAt(Cv-1);if(Cp[Cz]){var C2=(Cp[Cz]>0);\\nvar Cx=C6(Cv-1,C2);if(Cx){var Cy=Cx.chr;var C4=Cx.good;Ct.active=true;Cu={};Cu[Cv-1]="flash";Cu[Cy]=(C4?"flash":"flashbad");\\nCt.whichLineKeys=[];Ct.whichLineKeys.push(AL(Cv-1));Ct.whichLineKeys.push(AL(Cy));Ct.expireTime=R()+4000;\\nnewlyActive=true;}}}}if(Cw){Af(Cw[0]);Af(Cw[1]);}if(Ct.active&&Cu){function C3(C8,C7,C9,DB){var DA=Cu[DB];\\nif(C7){C9(C8,C7+" "+DA);}else{C9(C8,C7);}}for(var C1 in Cu){AU((+C1),(+C1)+1,null,C3);}}}return i;})();\\nfunction B8(){BL=true;if(H){H.never();}BF();}function BN(){return;function Cp(){throw new Error("checkALines");\\n}if(A.alines.length!=A.lines.length()){Cp();}for(var Cq=0;Cq\\x3cA.alines.length;Cq++){var Cu=A.alines[Cq];\\nvar Cv=A.lines.atIndex(Cq).text+"\\\\n";var Cw=Cv.length;var Cr=Changeset.opIterator(Cu);var Ct=0;while(Cr.hasNext()){var Cs=Cr.next();\\nCt+=Cs.chars;if(Cr.hasNext()){if(Cs.lines!=0){Cp();}}else{if(Cs.lines!=1){Cp();}}}if(Ct!=Cw){Cp();}}}function CD(i){K=i;\\nvar Cp="doesWrap";Q(B,"doesWrap",K);N.setTimeout(function(){Y("setWraps",function(){G(7);BY();h();});\\n},0);}function CK(i){var Cp=AX;AX=!!i;if(i!=Cp){if(!i){Y("setStyled",function(){G(12);var Cq=[];for(var Cr in Ac){Cq.push([Cr,""]);\\n}A2(0,A.alltext.length,Cq);});}}}function Bv(i){AQ=i;B.style.fontFamily=AQ;w.style.fontFamily=AQ;N.setTimeout(function(){AS();\\n},0);}function Bl(i){u=i;B.style.fontSize=u+"px";B.style.lineHeight=AV()+"px";T.style.lineHeight=AV()+"px";\\nw.style.fontSize=u+"px";N.setTimeout(function(){AS();},0);}function BY(){AU(0,A.alltext.length);}function BG(i){k=i;\\nif(!k){Az(false);}else{Az(true);}Q(B,"static",!k);}function Ax(){BG(k);}function CA(i,Cs,Cq){var Cp;if(Cq){if(i.charAt(i.length-1)!="\\\\n"){throw new Error("new raw text must end with newline");\\n}if(/[\\\\r\\\\t\\\\xa0]/.exec(i)){throw new Error("new raw text must not contain CR, tab, or nbsp");}Cp=i.substring(0,i.length-1).split("\\\\n");\\n}else{Cp=map(i.split("\\\\n"),CH);}var Cr="\\\\n";if(Cp.length>0){Cr=Cp.join("\\\\n")+"\\\\n";}Y("importText"+(Cs?"Undoable":""),function(){Bb(Cr);\\n});if(Cq&&A.alltext!=i){throw new Error("mismatch error setting raw text in importText");}}function B9(i,Cp,Cr){i=Changeset.cloneAText(i);\\nif(Cp){var Cq=(new AttribPool()).fromJsonable(Cp);i.attribs=Changeset.moveOpsToNewPool(i.attribs,Cq,A.apool);\\n}Y("importText"+(Cr?"Undoable":""),function(){Aa(i);});}function Aa(Cq){G(8);var Cs=A.lines.totalWidth();\\nvar Cr=A.lines.length();var Cu=A.lines.offsetOfIndex(Cr-1);var Ct=A.lines.atIndex(Cr-1).text.length;var Cp=Changeset.smartOpAssembler();\\nvar i=Changeset.newOp("-");i.chars=Cu;i.lines=Cr-1;Cp.append(i);i.chars=Ct;i.lines=0;Cp.append(i);Changeset.appendATextToAssembler(Cq,Cp);\\nvar Cv=Cs+Cp.getLengthChange();var Cw=Changeset.checkRep(Changeset.pack(Cs,Cv,Cp.toString(),Cq.text.slice(0,-1)));\\nb(Cw);d([0,A.lines.atIndex(0).lineMarker],[0,A.lines.atIndex(0).lineMarker]);H.atMost(100);if(A.alltext!=Cq.text){v(htmlPrettyEscape(A.alltext));\\nv(htmlPrettyEscape(Cq.text));throw new Error("mismatch error setting raw text in setDocAText");}}function Bb(i){Aa(Changeset.makeAText(i));\\n}function CW(){var Cp=A.alltext;var i=Cp.length;if(i>0){i--;}return Cp.substring(0,i);}function CL(){if(C&&!C.domClean){Y("exportText",function(){G(2);\\n});}return CW();}function B7(){h();}function Bn(i){Ar=i;}function Bq(i){Au=i;}function Bp(i){An=i;}function Bm(){if(C&&!C.domClean){Y("getFormattedCode",q);\\n}var Cp=[];if(A.lines.length()>0){var i=A.lines.atIndex(0);while(i){var Cq=i.domInfo;Cp.push((Cq&&Cq.getInnerHTML())||domline.processSpaces(domline.escapeHTML(i.text),K)||" ");\\ni=A.lines.next(i);}}return\\\'\\x3cdiv class="syntax">\\x3cdiv>\\\'+Cp.join("\\x3c/div>\\\\n\\x3cdiv>")+"\\x3c/div>\\x3c/div>";}var AZ={bold:function(){c("bold");\\n},italic:function(){c("italic");},underline:function(){c("underline");},strikethrough:function(){c("strikethrough");\\n},undo:function(){s("undo");},redo:function(){s("redo");},clearauthorship:function(i){if((!(A.selStart&&A.selEnd))||U()){if(i){i();\\n}else{A2(0,A.alltext.length,[["author",""]]);}}else{Bi("author","");}},insertunorderedlist:As,indent:function(){if(!AT(false)){As();\\n}},outdent:function(){AT(true);}};function CR(i){i=i.toLowerCase();var Cp=Array.prototype.slice.call(arguments,1);\\nif(AZ[i]){a(i,function(){G(9);AZ[i].apply(AZ,Cp);});}}D.ace_focus=Bc;D.ace_importText=CA;D.ace_importAText=B9;\\nD.ace_exportText=CL;D.ace_editorChangedSize=B7;D.ace_setOnKeyPress=Bn;D.ace_setOnKeyDown=Bq;D.ace_setNotifyDirty=Bp;\\nD.ace_dispose=B8;D.ace_getFormattedCode=Bm;D.ace_setEditable=BG;D.ace_execCommand=CR;D.ace_setProperty=function(Cq,i){var Cp=Cq.toLowerCase();\\nif(Cp=="wraps"){CD(i);}else{if(Cp=="showsauthorcolors"){Q(B,"authorColors",!!i);}else{if(Cp=="showsuserselections"){Q(B,"userSelections",!!i);\\n}else{if(Cp=="showslinenumbers"){AP=!!i;Q(T,"sidedivhidden",!AP);h();}else{if(Cp=="grayedout"){Q(F.document.body,"grayedout",!!i);\\n}else{if(Cp=="dmesg"){v=i;window.dmesg=i;}else{if(Cp=="userauthor"){e=String(i);}else{if(Cp=="styled"){CK(i);\\n}else{if(Cp=="textface"){Bv(i);}else{if(Cp=="textsize"){Bl(i);}}}}}}}}}}};D.ace_setBaseText=function(i){M.setBaseText(i);\\n};D.ace_setBaseAttributedText=function(Cp,i){AS();M.setBaseAttributedText(Cp,i);};D.ace_applyChangesToBase=function(Cq,i,Cp){M.applyChangesToBase(Cq,i,Cp);\\n};D.ace_prepareUserChangeset=function(){return M.prepareUserChangeset();};D.ace_applyPreparedChangesetToBase=function(){M.applyPreparedChangesetToBase();\\n};D.ace_setUserChangeNotificationCallback=function(i){M.setUserChangeNotificationCallback(i);};D.ace_setAuthorInfo=function(i,Cp){CV(i,Cp);\\n};D.ace_setAuthorSelectionRange=function(Cp,Cq,i){M.setAuthorSelectionRange(Cp,Cq,i);};D.ace_getUnhandledErrors=function(){return BU.slice();\\n};D.ace_getDebugProperty=function(i){if(i=="debugger"){window["eval"]("debugger");}else{if(i=="rep"){return A;\\n}else{if(i=="window"){return window;}else{if(i=="document"){return document;}}}}return undefined;};function R(){return(new Date()).getTime();\\n}function AC(Cs){var Cq=R();var Ct=0;var i=false;var Cr=false;var Cp=function(){if(i){if((!Cr)){Cr=true;\\n}return true;}var Cu=R()-Cq;if(Cu>Cs){i=true;return true;}else{Ct=Cu;return false;}};Cp.elapsed=function(){return R()-Cq;\\n};return Cp;}function CZ(Cs){var i=null;var Cp=0;function Cr(){if(i){N.clearTimeout(i);i=null;}}function Cq(Cv){Cr();\\nCp=Cv;var Cu=Cv-R();if(Cu\\x3c0){Cu=0;}i=N.setTimeout(Ct,Cu);}function Ct(){i=null;Cs();}return{atMost:function(Cv){var Cu=R()+Cv;\\nif((!i)||Cp>Cu){Cq(Cu);}},atLeast:function(Cv){var Cu=R()+Cv;if((!i)||Cp\\x3cCu){Cq(Cu);}},never:function(){Cr();\\n}};}function G(i){q(AC(0));}function A8(){var i=A8;var Cr=(i.failures||0);if(Cr\\x3c5){var Cq=AC(40);var Cs=q(Cq);\\nif(Cq()){i.failures=Cr+1;}return true;}else{var Cp=(i.skipCount||0);Cp++;if(Cp==20){Cp=0;i.failures=0;\\n}i.skipCount=Cp;}return false;}var H=CZ(function(){if(!k){return;}if(r){H.atLeast(500);return;}a("idleWorkTimer",function(){var i=AC(250);\\nvar Cq=false;var Cr=false;try{q(i);if(i()){return;}CN();if(i()){return;}var Ct=BI();var Cs=[0,A.lines.totalWidth()];\\nCq=true;Cr=true;}finally{if(Cr){H.atMost(1000);}else{if(Cq){H.atMost(500);}else{var Cp=Math.round(i.elapsed()/2);\\nif(Cp\\x3c100){Cp=100;}H.atMost(Cp);}}}});});var B1=1;function L(Cp){var i=Cp.id;if(i){return i;}return(Cp.id="magicdomid"+(B1++));\\n}function AU(Cr,Cx,Cs,Cv){if(Cx\\x3c=Cr){return;}if(Cr\\x3c0||Cr>=A.lines.totalWidth()){return;}var i=A.lines.atOffset(Cr);\\nvar Cp=A.lines.offsetOfEntry(i);var Cq=A.lines.indexOfEntry(i);var Cw=false;var Cy=null;var C1=null;Cs=(Cs||I);\\nvar Cu;var Ct=function(C2,C3){i.domInfo.appendSpan(C2,C3);};if(Cv){var C0=Ct;Ct=function(C2,C3){Cv(C2,C3,C0,Cu);\\nCu+=C2.length;};}while(i&&Cp\\x3cCx&&!Cs()){var Cz=Cp+i.width;Cu=Cp;i.domInfo.clearSpans();BJ(i,Ct,Cp);i.domInfo.finishUpdate();\\nz(i.lineNode);if(A.selStart&&A.selStart[0]==Cq||A.selEnd&&A.selEnd[0]==Cq){Cw=true;}if(Cy===null){Cy=Cq;\\n}C1=Cq;Cp=Cz;i=A.lines.next(i);Cq++;}if(Cw){C.selectionAffected=true;}}function BJ(Cq,Cs,Cw){var Cr=Cw;\\nif((typeof Cr)!="number"){Cr=A.lines.offsetOfEntry(Cq);}var Cp=Cq.text;var Cx=Cq.width;if(Cp.length==0){var Ct=linestylefilter.getLineStyleFilter(0,"",Cs,A.apool);\\nCt("","");}else{var Cy=0;var i=Cs;i=linestylefilter.getURLFilter(Cp,i);if(browser.msie){i=linestylefilter.getAtSignSplitterFilter(Cp,i);\\n}var Cu=A.lines.indexOfEntry(Cq);var Cv=A.alines[Cu];i=linestylefilter.getLineStyleFilter(Cp.length,Cv,i,A.apool);\\ni(Cp,"");}}function BH(i){return"";}var AE;function A4(){AE={cleanNodesNearChanges:{}};}A4();function l(Cq){var i=O("getCleanNodeByKey",false);\\ni.extra=0;var Cp=E.getElementById(Cq);while(Cp&&V(Cp)){i.extra++;Cp.id="";Cp=E.getElementById(Cq);}i.literal(i.extra,"extra");\\ni.end();return Cp;}function y(Cs){var i;var Cu;if(!V(Cs)){i=Cs;var Ct=i.previousSibling;var Cr=i.nextSibling;\\nCu=((Ct&&V(Ct))||(Cr&&V(Cr)));}else{var Cp=Cs.previousSibling;while(Cp&&V(Cp)){Cp=Cp.previousSibling;\\n}if(Cp){i=Cp;}else{var Cq=Cs.nextSibling;while(Cq&&V(Cq)){Cq=Cq.nextSibling;}if(Cq){i=Cq;}}if(!i){return;\\n}Cu=true;}if(Cu){AE.cleanNodesNearChanges["$"+L(i)]=true;}else{var Cx=L(i);var Ct=i.previousSibling;var Cr=i.nextSibling;\\nvar C1=((Ct&&L(Ct))||null);var C0=((Cr&&L(Cr))||null);var Cv=A.lines.prev(A.lines.atKey(Cx));var Cw=A.lines.next(A.lines.atKey(Cx));\\nvar Cz=((Cv&&Cv.key)||null);var Cy=((Cw&&Cw.key)||null);if(C1!=Cz||C0!=Cy){AE.cleanNodesNearChanges["$"+L(i)]=true;\\n}}}function Aw(){if(C.observedSelection){return;}C.observedSelection=true;var Cs=O("getSelection",false);\\nvar Cq=Ae();Cs.end();if(Cq){function Cr(Ct){if((!Ct)||Ct==B){return null;}while(Ct.parentNode!=B){Ct=Ct.parentNode;\\n}return Ct;}var Cp=Cr(Cq.startPoint.node);var i=Cr(Cq.endPoint.node);if(Cp){y(Cp);}if(i&&Cp!=i){y(i);\\n}}}function BV(){if(B.getElementsByTagName){var Cr=B.getElementsByTagName("style");for(var Cq=0;Cq\\x3cCr.length;\\nCq++){var Cp=Cr[Cq];while(Cp.parentNode&&Cp.parentNode!=B){Cp=Cp.parentNode;}if(Cp.parentNode==B){y(Cp);\\n}}}}function q(C9){if(C.domClean){return false;}r=false;C.isUserChange=true;C9=(C9||function(){return false;\\n});if(AK&&top.DONT_INCORP||window.DEBUG_DONT_INCORP){return false;}var Cq=O("incorp",false);if(!B.firstChild){B.innerHTML="\\x3cdiv>\\x3c!-- -->\\x3c/div>";\\n}Cq.mark("obs");Aw();BV();Cq.mark("dirty");var Cy=BK();var DN=true;var C5=0;var Cp,Ct;while(C5\\x3cCy.length){Cp=Cy[C5][0];\\nCt=Cy[C5][1];if(!((Cp==0||l(A.lines.atIndex(Cp-1).key))&&(Ct==A.lines.length()||l(A.lines.atIndex(Ct).key)))){DN=false;\\nbreak;}C5++;}if(!DN){var DS=B.childNodes.length;for(var C0=0;C0\\x3cDS;C0++){var C7=B.childNodes.item(C0);\\nif((C7.tagName)&&((!C7.id)||(!A.lines.containsKey(C7.id)))){y(C7);}}Cy=BK();}A4();Cq.mark("getsel");var Cv=Ae();\\nvar Cs,Cr;var DE=0;var C6=[];var C3=0;var C8=[];Cq.mark("ranges");Cq.literal(Cy.length,"numdirt");var DI=[];\\nwhile(DE\\x3cCy.length){var DG=Cy[DE];Cp=DG[0];Ct=DG[1];var C1=(((Cp==0)&&B.firstChild)||l(A.lines.atIndex(Cp-1).key).nextSibling);\\nC1=(C1&&V(C1)&&C1);var Cu=(((Ct==A.lines.length())&&B.lastChild)||l(A.lines.atIndex(Ct).key).previousSibling);\\nCu=(Cu&&V(Cu)&&Cu);if(C1&&Cu){var Cz=makeContentCollector(AX,browser,A.apool,null,Bd);Cz.notifySelection(Cv);\\nvar DJ=[];for(var Cx=C1;Cx&&!(Cx.previousSibling&&Cx.previousSibling==Cu);Cx=Cx.nextSibling){if(browser.msie){try{Cx.createTextRange().execCommand("unlink",false,null);\\n}catch(DR){}}Cz.collectContent(Cx);DJ.push(Cx);}Cz.notifyNextNode(Cu.nextSibling);var Cw=Cz.getLines();\\nif((Cw.length\\x3c=1||Cw[Cw.length-1]!=="")&&Cu.nextSibling){Ct++;var DF=Cu.nextSibling;Cz.collectContent(DF);\\nC8.push(DF);Cz.notifyNextNode(DF.nextSibling);}var C2=Cz.finish();var DA=C2.selStart;var DB=C2.selEnd;\\nCw=C2.lines;var DP=C2.lineAttribs;var DC=C2.linesWrapped;if(DC>0){By("Editor warning: "+DC+" long line"+(DC==1?" was":"s were")+" hard-wrapped into "+C2.numLinesAfter+" lines.");\\n}if(DA[0]>=0){Cs=[DA[0]+Cp+C3,DA[1]];}if(DB[0]>=0){Cr=[DB[0]+Cp+C3,DB[1]];}var DL=[];var DO=Cu;var DH=new Array(Cw.length);\\nfor(var C0=0;C0\\x3cCw.length;C0++){var DQ=Cw[C0];var DK=AN(DQ);DL.push(DK);DH[C0]=DK.domInfo;}DI.push([DO,DH]);\\nforEach(DJ,function(i){C8.push(i);});var DD={};if(Cs){DD.selStart=Cs;}if(Cr){DD.selEnd=Cr;}C6.push([Cp+C3,Ct-Cp,DL,DP,DD]);\\nC3+=(Cw.length-(Ct-Cp));}else{if(Ct>Cp){C6.push([Cp+C3,Ct-Cp,[],[]]);}}DE++;}var DM=(C6.length>0);Cq.mark("splice");\\nforEach(C6,function(i){CI(i[0],i[1],i[2],i[3],i[4]);});Cq.mark("insert");forEach(DI,function(i){AH(i[0],i[1],C9);\\n});Cq.mark("del");forEach(C8,function(i){i.parentNode.removeChild(i);});Cq.mark("findsel");if(Cv&&!Cs){Cs=Aq(Cv.startPoint);\\n}if(Cv&&!Cr){Cr=Aq(Cv.endPoint);}var C4=A.lines.length();if(Cs&&Cs[0]>=C4){Cs[0]=C4-1;Cs[1]=A.lines.atIndex(Cs[0]).text.length;\\n}if(Cr&&Cr[0]>=C4){Cr[0]=C4-1;Cr[1]=A.lines.atIndex(Cr[0]).text.length;}Cq.mark("repsel");BR(Cs,Cr,Cv&&Cv.focusAtStart);\\nCq.mark("browsel");if(Cv&&(DM||U())){C.selectionAffected=true;}C.domClean=true;Cq.mark("fixview");h();\\nCq.end("END");return DM;}function Cc(Cp){var i=E.createElement("DIV");i.appendChild(Cp);return i.innerHTML;\\n}var Ac={bold:true,italic:true,underline:true,strikethrough:true,list:true};var CF={insertorder:true,author:true};\\nfunction A0(i){return !!Ac[i];}function Ck(i){return(!!Ac[i])||(!!CF[i]);}function AH(Cq,i,Cr){Cr=(Cr||function(){return false;\\n});var Cp;var Cs;if(i.length\\x3c1){return;}var Cu=A.lines.atKey(L(i[0].node));var Ct=A.lines.atKey(L(i[i.length-1].node));\\nvar Cv=A.lines.offsetOfEntry(Cu);var Cw=A.lines.offsetOfEntry(Ct)+Ct.width;forEach(i,function(C0){var Cx=O("insertLine",false);\\nvar Cz=C0.node;var C1=L(Cz);var Cy;Cx.mark("findEntry");if(Cp){var C2=A.lines.next(Cp);if(C2&&C2.key==C1){Cy=C2;\\nCs+=Cp.width;}}if(!Cy){Cx.literal(1,"nonopt");Cy=A.lines.atKey(C1);Cs=A.lines.offsetOfKey(C1);}else{Cx.literal(0,"nonopt");\\n}Cp=Cy;Cx.mark("spans");BJ(Cy,function(C3,C4){C0.appendSpan(C3,C4);},Cs,Cr());Cx.mark("addLine");C0.prepareForAdd();\\nCy.lineMarker=C0.lineMarker;if(!Cq){B.insertBefore(Cz,B.firstChild);}else{B.insertBefore(Cz,Cq.nextSibling);\\n}Cq=Cz;C0.notifyAdded();Cx.mark("markClean");z(Cz);Cx.end();});}function U(){return(A.selStart&&A.selEnd&&A.selStart[0]==A.selEnd[0]&&A.selStart[1]==A.selEnd[1]);\\n}function m(){return A.selStart[0];}function t(){return A.selStart[1];}function A7(){return A.lines.offsetOfIndex(m())+t();\\n}function CE(){if(U()&&t()==0&&m()>0){var i=m();var Ct=A.lines.atIndex(i);var Cs=A.lines.prev(Ct);var Cq=Cs.text;\\nvar Cp=/^ *(?:)/.exec(Cq)[0];if(/[\\\\[\\\\(\\\\{]\\\\s*$/.exec(Cq)){Cp+=Ad;}var Cr=Changeset.builder(A.lines.totalWidth()).keep(A.lines.offsetOfIndex(i),i).insert(Cp,[["author",e]],A.apool).toString();\\nb(Cr);d([i,Cp.length],[i,Cp.length]);}}function Bk(Cr){var Cq=A.lines.atIndex(Cr).lineNode;var i=Cq.firstChild;\\nwhile(AF(i)&&i.firstChild){i=i.firstChild;}var Cp;if(isNodeText(i)){i.nodeValue=" "+i.nodeValue;Cp=i;\\n}else{Cp=E.createTextNode(" ");i.parentNode.insertBefore(Cp,i);}z(Cq);return{unhack:function(){if(Cp.nodeValue==" "){Cp.parentNode.removeChild(Cp);\\n}else{Cp.nodeValue=Cp.nodeValue.substring(1);}z(Cq);}};}function Am(Cv){var Cw=Cv[0];var Cp=Cv[1];var Ct=A.lines.atIndex(Cw);\\nCp-=Ct.lineMarker;if(Cp\\x3c0){Cp=0;}var Cr=Ct.lineNode;var i=Cr;var Cq=false;if(Cp==0){var Cu=0;if(browser.msie&&Cw==(A.lines.length()-1)&&Cr.childNodes.length==0){Cu=1;\\n}return{node:Cr,index:Cu,maxIndex:1};}while(!(i==Cr&&Cq)){if(Cq){if(i.nextSibling){i=i.nextSibling;Cq=false;\\n}else{i=i.parentNode;}}else{if(isNodeText(i)){var Cs=i.nodeValue.length;if(Cp\\x3c=Cs){return{node:i,index:Cp,maxIndex:Cs};\\n}Cp-=Cs;Cq=true;}else{if(i.firstChild){i=i.firstChild;}else{Cq=true;}}}}return{node:Cr,index:1,maxIndex:1};\\n}function BD(i){return i.innerText||i.textContent||i.nodeValue||"";}function Aq(Cq){if(Cq.node==B){if(Cq.index==0){return[0,0];\\n}else{var Ct=A.lines.length();var Cw=A.lines.atIndex(Ct-1);return[Ct-1,Cw.text.length];}}else{var i=Cq.node;\\nvar Cp=0;if(isNodeText(i)){Cp=Cq.index;}else{if(Cq.index>0){Cp=BD(i).length;}}var Cr,Cs;while((Cr=i.parentNode)!=B){if((Cs=i.previousSibling)){i=Cs;\\nCp+=BD(i).length;}else{i=Cr;}}if(i.id==""){S.debug("BAD");}if(i.firstChild&&AF(i.firstChild)){Cp+=1;}var Cu=A.lines.atKey(i.id);\\nvar Cv=A.lines.indexOfEntry(Cu);return[Cv,Cp];}}function AN(Cq){var Cp=CS(Cq.length>0);var i=Cp.node;\\nreturn{key:L(i),text:Cq,lineNode:i,domInfo:Cp,lineMarker:0};}function Co(i){return Changeset.oldLen(i)==A.alltext.length;\\n}function b(Cp,Cr){Ap(Cp,Cr);var i=null;if(A.selStart&&A.selEnd){var Cv=A.lines.offsetOfIndex(A.selStart[0])+A.selStart[1];\\nvar Cs=A.lines.offsetOfIndex(A.selEnd[0])+A.selEnd[1];var Cq=Changeset.characterRangeFollow(Cp,Cv,Cs,Cr);\\ni=[Cq[0],Cq[1],A.selFocusAtStart];}var Cu={splice:function(Cx,Cw,Cy){Ct(Cx,Cw,map(Array.prototype.slice.call(arguments,2),function(Cz){return Cz.slice(0,-1);\\n}),null);},get:function(Cw){return A.lines.atIndex(Cw).text+"\\\\n";},length:function(){return A.lines.length();\\n},slice_notused:function(Cx,Cw){return map(A.lines.slice(Cx,Cw),function(Cy){return Cy.text+"\\\\n";});}};\\nChangeset.mutateTextLines(Cp,Cu);BN();if(i){d(P(i[0]),P(i[1]),i[2]);}function Ct(Cw,Cx,C4,Cz){Cz=(Cz||AC(50));\\nvar C1=[];if(Cx>0){var C0=A.lines.atIndex(Cw);for(var C3=0;C3\\x3cCx;C3++){C1.push(C0.key);C0=A.lines.next(C0);\\n}}var C2=map(C4,AN);AJ(Cw,Cx,C2);var Cy;if(Cw>0){Cy=l(A.lines.atIndex(Cw-1).key);}else{Cy=null;}AH(Cy,map(C2,function(C5){return C5.domInfo;\\n}),Cz);forEach(C1,function(C6){var C5=E.getElementById(C6);C5.parentNode.removeChild(C5);});if((A.selStart&&A.selStart[0]>=Cw&&A.selStart[0]\\x3c=Cw+Cx)||(A.selEnd&&A.selEnd[0]>=Cw&&A.selEnd[0]\\x3c=Cw+Cx)){C.selectionAffected=true;\\n}}}function Bz(Cw){return true;var Cs=Changeset.opIterator(Changeset.unpack(Cw).ops);var Cp=0;var Cr=0;\\nvar Cq=0;while(Cs.hasNext()){var i=Cs.next();if(i.opcode=="-"||i.opcode=="="){Cp+=i.chars;if(i.lines){Cr+=i.lines;\\nCq=0;}else{Cq+=i.chars;}}var Ct=A.lines.indexOfOffset(Cp);var Cv=A.lines.offsetOfIndex(Ct);var Cu=Cp-Cv;\\nif(Cu!=Cq||Ct!=Cr){return false;}}return true;}function Ap(i,Cq){Changeset.checkRep(i);if(Changeset.oldLen(i)!=A.alltext.length){throw new Error("doRepApplyChangeset length mismatch: "+Changeset.oldLen(i)+"/"+A.alltext.length);\\n}if(!Bz(i)){throw new Error("doRepApplyChangeset line break mismatch");}(function Cp(Cs){var Cr=C.editEvent;\\nif(Cr.eventType=="nonundoable"){if(!Cr.changeset){Cr.changeset=Cs;}else{Cr.changeset=Changeset.compose(Cr.changeset,Cs,A.apool);\\n}}else{var Ct=Changeset.inverse(Cs,{get:function(Cu){return A.lines.atIndex(Cu).text+"\\\\n";},length:function(){return A.lines.length();\\n}},A.alines,A.apool);if(!Cr.backset){Cr.backset=Ct;}else{Cr.backset=Changeset.compose(Ct,Cr.backset,A.apool);\\n}}})(i);Changeset.mutateAttributionLines(i,A.alines,A.apool);if(M.isTracking()){M.composeUserChangeset(i);\\n}}function P(i){var Cp=A.lines.atOffset(i);var Cq=A.lines.offsetOfEntry(Cp);var Cr=A.lines.indexOfEntry(Cp);\\nreturn[Cr,i-Cq];}function BA(Cq,Cp,i){if(Cq==Cp&&i.length==0){return;}if(Cp==A.alltext.length){if(Cq==Cp){Cq--;\\nCp--;i="\\\\n"+i.substring(0,i.length-1);}else{if(i.length==0){Cq--;Cp--;}else{Cp--;i=i.substring(0,i.length-1);\\n}}}f(P(Cq),P(Cp),i);}function f(Cp,Cq,Cs){var i=Changeset.builder(A.lines.totalWidth());At(i,Cp);BQ(i,Cp,Cq);\\ni.insert(Cs,[["author",e]],A.apool);var Cr=i.toString();b(Cr);}function A2(Cq,i,Cp){if(i>=A.alltext.length){i=A.alltext.length-1;\\n}AB(P(Cq),P(i),Cp);}function AB(Cp,Cq,Cs){var i=Changeset.builder(A.lines.totalWidth());At(i,Cp);AR(i,Cp,Cq,Cs,A.apool);\\nvar Cr=i.toString();b(Cr);}function At(Cp,i){var Cq=A.lines.offsetOfIndex(i[0]);Cp.keep(Cq,i[0]);Cp.keep(i[1]);\\n}function BQ(Cq,Cp,i){var Cs=A.lines.offsetOfIndex(Cp[0]);var Cr=A.lines.offsetOfIndex(i[0]);if(i[0]>Cp[0]){Cq.remove(Cr-Cs-Cp[1],i[0]-Cp[0]);\\nCq.remove(i[1]);}else{Cq.remove(i[1]-Cp[1]);}}function AR(Cq,Cp,i,Cs,Cr){var Cu=A.lines.offsetOfIndex(Cp[0]);\\nvar Ct=A.lines.offsetOfIndex(i[0]);if(i[0]>Cp[0]){Cq.keep(Ct-Cu-Cp[1],i[0]-Cp[0],Cs,Cr);Cq.keep(i[1],0,Cs,Cr);\\n}else{Cq.keep(i[1]-Cp[1],0,Cs,Cr);}}function Bi(i,Cp){if(!(A.selStart&&A.selEnd)){return;}AB(A.selStart,A.selEnd,[[i,Cp]]);\\n}function c(Cq){if(!(A.selStart&&A.selEnd)){return;}var Cp=true;var C1=Changeset.makeAttribsString("+",[[Cq,"true"]],A.apool);\\nvar C2=new RegExp(C1.replace(/\\\\*/g,"\\\\\\\\*")+"(\\\\\\\\*|$)");function C0(C3){return C2.test(C3);}var Cx=A.selStart[0];\\nvar Cu=A.selEnd[0];for(var i=Cx;i\\x3c=Cu;i++){var Cs=Changeset.opIterator(A.alines[i]);var Cz=0;var Cw=0;\\nvar Cr=A.lines.atIndex(i).text.length;if(i==Cx){Cw=A.selStart[1];}if(i==Cu){Cr=A.selEnd[1];}while(Cs.hasNext()){var Cv=Cs.next();\\nvar Cy=Cz;var Ct=Cy+Cv.chars;if(!C0(Cv.attribs)){if(!(Ct\\x3c=Cw||Cy>=Cr)){Cp=false;break;}}Cz=Ct;}if(!Cp){break;\\n}}if(Cp){AB(A.selStart,A.selEnd,[[Cq,""]]);}else{AB(A.selStart,A.selEnd,[[Cq,"true"]]);}}function AY(i){if(!(A.selStart&&A.selEnd)){return;\\n}f(A.selStart,A.selEnd,i);}function AJ(i,Cq,Cp){forEach(Cp,function(Cx){Cx.width=Cx.text.length+1;});\\nvar Cs=A.lines.offsetOfIndex(i);var Ct=A.lines.offsetOfIndex(i+Cq);var Cu=A.lines.offsetOfIndex(i);var Cw=A.lines.offsetOfIndex(i+Cq);\\nA.lines.splice(i,Cq,Cp);C.docTextChanged=true;C.repChanged=true;var Cv=A.lines.offsetOfIndex(i+Cp.length);\\nvar Cr=map(Cp,function(Cx){return Cx.text+"\\\\n";}).join("");A.alltext=A.alltext.substring(0,Cs)+Cr+A.alltext.substring(Ct,A.alltext.length);\\n}function CI(Cv,C6,DE,DO,Cr){var DF=A.lines.offsetOfIndex(Cv);var DK=A.lines.offsetOfIndex(Cv+C6);var DJ=A.lines.offsetOfIndex(Cv);\\nvar DI,DM;if(Cr&&Cr.selStart){DI=A.lines.offsetOfIndex(Cr.selStart[0])+Cr.selStart[1]-DJ;}if(Cr&&Cr.selEnd){DM=A.lines.offsetOfIndex(Cr.selEnd[0])+Cr.selEnd[1]-DJ;\\n}var Cs=map(DE,function(DU){return DU.text+"\\\\n";}).join("");var C1=A.alltext.substring(DF,DK);var DG=A.alines.slice(Cv,Cv+C6).join("");\\nvar C0=DO.join("|1+1")+"|1+1";var DC=B6(C1,Cs,DG,C0,DI,DM);var Cz=DC[0];var Cx=DC[1];var Cq=C1.substring(Cz,C1.length-Cx);\\nvar i=Cs.substring(Cz,Cs.length-Cx);var Cp=DF+Cz;var Ct=DK-Cx;var Cw=false;if(Cq.charAt(Cq.length-1)=="\\\\n"&&i.charAt(i.length-1)=="\\\\n"){Cq=Cq.slice(0,-1);\\ni=i.slice(0,-1);Ct--;Cx++;}if(Cq.length==0&&Cp==A.alltext.length&&i.length>0){Cp--;Ct--;i="\\\\n"+i.slice(0,-1);\\nCw=true;}if(Ct==A.alltext.length&&Cq.length>0&&i.length==0){if(A.alltext.charAt(Cp-1)=="\\\\n"){Cp--;Ct--;\\n}}if(!(Cq.length==0&&i.length==0)){var DR=A.alltext;var DT=DR.length;var C4=A.lines.indexOfOffset(Cp);\\nvar DA=A.lines.offsetOfIndex(C4);function C8(){var DU=Changeset.builder(DT);DU.keep(DA,C4);DU.keep(Cp-DA);\\nreturn DU;}function Cy(Db,Da){var DW=Changeset.opIterator(Db);var DU=0;var DX=Cz;var DZ=Cs.length-Cx-(Cw?1:0);\\nwhile(DW.hasNext()){var DY=DW.next();var DV=DU+DY.chars;if(!(DV\\x3c=DX||DU>=DZ)){Da(Math.max(DX,DU),Math.min(DZ,DV),DY.attribs);\\n}DU=DV;}}var DP=(i==Cq);var C5;if(DP){var DN=BT(function(DU){return Changeset.mapAttribNumbers(DU,function(DW){var DV=A.apool.getAttribKey(DW);\\nif(A0(DV)){return A.apool.putAttrib([DV,""]);}return false;});});var C3=C8();if(Cw){C3.keep(1,1);}Cy(DG,function(DW,DU,DV){C3.keepText(Cs.substring(DW,DU),DN(DV));\\n});var DS=C3.toString();var C2=C8();if(Cw){C2.keep(1,1);}Cy(C0,function(DW,DU,DV){C2.keepText(Cs.substring(DW,DU),DV);\\n});var DQ=C2.toString();C5=Changeset.compose(DS,DQ,A.apool);}else{var Cu=C8();var DH=A.lines.indexOfOffset(Ct);\\nvar C9=A.lines.offsetOfIndex(DH);if(C9>Cp){Cu.remove(C9-Cp,DH-C4);Cu.remove(Ct-C9);}else{Cu.remove(Ct-Cp);\\n}var DL=false;var DD=Changeset.makeAttribsString("+",(e?[["author",e]]:[]),A.apool);var DB=BT(function(DU){if(DL){return Changeset.composeAttributes(DD,DU,true,A.apool);\\n}else{return Changeset.composeAttributes(DU,DD,true,A.apool);}});var C7="";Cy(C0,function(DX,DW,DV){var DU=Changeset.attribsAttributeValue(DV,"author",A.apool);\\nif(DU&&DU!=C7){if(!C7){C7=DU;}else{DL=true;}}});if(Cw){Cu.insert("\\\\n",DB(""));}Cy(C0,function(DW,DU,DV){Cu.insert(Cs.substring(DW,DU),DB(DV));\\n});C5=Cu.toString();}Ap(C5);}AJ(Cv,C6,DE);BN();}function BT(Cp){var i={};return function(Cq){if(!i[Cq]){i[Cq]=Cp(Cq);\\n}return i[Cq];};}function B6(Cv,Cw,C6,C7,DA,Cx){function Cy(DB){return A0(A.apool.getAttribKey(DB));}function C5(DF){var DC=[];\\nvar DE=[];var DB=Changeset.opIterator(DF);while(DB.hasNext()){var DD=DB.next();DC.push(DD.chars);DE.push(DD.attribs);\\n}return[DC,DE];}function Ct(DF,DE){var DD=DF[0];var DG=DF[1];var DB=(DE?DD.length-1:0);var DC=0;return function DH(){while(DC>=DD[DB]){if(DE){DB--;\\n}else{DB++;}DC=0;}var DI=DG[DB];DC++;return DI;};}var Cs=Cv.length;var Cr=Cw.length;var C2=Math.min(Cs,Cr);\\nvar C3=C5(Changeset.filterAttribNumbers(C6,Cy));var C1=C5(Changeset.filterAttribNumbers(C7,Cy));var Cp=0;\\nvar C9=Ct(C3,false);var C8=Ct(C1,false);while(Cp\\x3cC2){if(Cv.charAt(Cp)==Cw.charAt(Cp)&&C9()==C8()){Cp++;\\n}else{break;}}var i=0;var C0=Ct(C3,true);var C4=Ct(C1,true);while(i\\x3cC2){if(i==0){C0();C4();i++;}else{if(Cv.charAt(Cs-1-i)==Cw.charAt(Cr-1-i)&&C0()==C4()){i++;\\n}else{break;}}}var Cq=-1;if((typeof Cx)=="number"){Cq=Cr-Cx;}if(Cp+i>Cs){var Cu=Cs-Cp;var Cz=i;if(Cq>=Cu&&Cq\\x3c=Cz){i=Cq;\\n}else{i=Cu;}Cp=Cs-i;}if(Cp+i>Cr){var Cu=Cr-Cp;var Cz=i;if(Cq>=Cu&&Cq\\x3c=Cz){i=Cq;}else{i=Cu;}Cp=Cr-i;}return[Cp,i];\\n}function A3(Cp,i){if(!Cp){return !i;}if(!i){return !Cp;}return(Cp[0]==i[0]&&Cp[1]==i[1]);}function d(Cq,i,Cp){if(BR(Cq,i,Cp)){C.selectionAffected=true;\\n}}function BR(Cp,i,Cq){Cq=!!Cq;var Cr=(Cq&&((!Cp)||(!i)||(Cp[0]!=i[0])||(Cp[1]!=i[1])));if((!A3(A.selStart,Cp))||(!A3(A.selEnd,i))||(A.selFocusAtStart!=Cr)){A.selStart=Cp;\\nA.selEnd=i;A.selFocusAtStart=Cr;if(AA){AA.notifySelectionChanged();}C.repChanged=true;return true;}return false;\\n}function CS(Cs){if(browser.msie&&(!Cs)){var i={node:null,appendSpan:I,prepareForAdd:I,notifyAdded:I,clearSpans:I,finishUpdate:I,lineMarker:0};\\nvar Cq=E.createElement("div");i.node=Cq;i.notifyAdded=function(){Cq.innerHTML="";setAssoc(Cq,"shouldBeEmpty",true);\\nsetAssoc(Cq,"unpasted",{});};var Cp="ace-line";i.appendSpan=function(Cu,Ct){if((!Cu)&&Ct){Cp=domline.addToLineClass(Cp,Ct);\\n}};i.clearSpans=function(){Cp="";};function Cr(){if(Cp!==null){Cq.className=Cp;}}i.prepareForAdd=Cr;i.finishUpdate=Cr;\\ni.getInnerHTML=function(){return"";};return i;}else{return domline.createDomLine(Cs,K,browser,E);}}function CH(i){return i.replace(/[\\\\n\\\\r ]/g," ").replace(/\\\\xa0/g," ").replace(/\\\\t/g," ");\\n}var Br={div:1,p:1,pre:1,li:1,ol:1,ul:1};function AF(i){return !!Br[(i.tagName||"").toLowerCase()];}function BK(){var i=O("getDirtyRanges",false);\\ni.forIndices=0;i.consecutives=0;i.corrections=0;var Cs={};var Cq=A.lines.length();function Cu(C7){if(Cs[C7]===undefined){i.forIndices++;\\nvar C8;if(C7\\x3c0||C7>=Cq){C8=true;}else{var C9=A.lines.atIndex(C7).key;C8=(l(C9)||false);}Cs[C7]=C8;}return Cs[C7];\\n}var Cv={};function Cw(C7){if(Cv[C7]===undefined){i.consecutives++;Cv[C7]=(function(){var C9=Cu(C7-1);\\nvar C8=Cu(C7);if((!C9)||(!C8)){return false;}if((C9===true)&&(C8===true)){return !B.firstChild;}if((C9===true)&&C8.previousSibling){return false;\\n}if((C8===true)&&C9.nextSibling){return false;}if((C9===true)||(C8===true)){return true;}return C9.nextSibling==C8;\\n})();}return Cv[C7];}function Cx(C7){return !!Cu(C7);}var Cp=[[-1,Cq+1]];function C4(C7){var C8=-1;forEach(Cp,function(C9,DA){if(C7>=C9[1]){return false;\\n}if(C7\\x3cC9[0]){return true;}C8=DA;return true;});return C8;}function C3(C7,C8){var DA=Cp[C7][0];var C9=Cp[C7][1];\\nif((DA+1)==C9){Cp.splice(C7,1);}else{if(C8==DA){Cp[C7][0]++;}else{if(C8==(C9-1)){Cp[C7][1]--;}else{Cp.splice(C7,1,[DA,C8],[C8+1,C9]);\\n}}}}function Ct(C7,C8){var DA=Cp[C7][0];var C9=Cp[C7][1];Cp.splice(C7,1,[DA,C8],[C8,C9]);}var Cz={};function C1(C7){if(Cz[C7]){return true;\\n}i.corrections++;Cz[C7]=true;var C8=C4(C7);var DA=Cx(C7);if(C8\\x3c0){if(DA){S.debug("somehow lost clean line");\\n}return true;}if(!DA){C3(C8,C7);return false;}else{var DC=Cp[C8][0];var DB=Cp[C8][1];var C9=false;if(DC\\x3cC7&&Cx(C7-1)&&!Cw(C7)){Ct(C8,C7);\\nC9=true;}if(DB>(C7+1)&&Cx(C7+1)&&!Cw(C7+1)){Ct(C8,C7+1);C9=true;}return !C9;}}function Cy(C9,DA){var C8=0;\\nvar C7=C9;while(C8\\x3cDA&&C7>=0){if(C1(C7)){C8++;}else{C8=0;}C7--;}C8=0;C7=C9;while(C8\\x3cDA&&C7\\x3cCq){if(C1(C7)){C8++;\\n}else{C8=0;}C7++;}}if(Cq==0){i.cancel();if(!Cw(0)){Ct(0,0);}}else{i.mark("topbot");Cy(0,1);Cy(Cq-1,1);\\ni.mark("obs");for(var C6 in AE.cleanNodesNearChanges){var C2=C6.substring(1);if(A.lines.containsKey(C2)){var C5=A.lines.indexOfKey(C2);\\nCy(C5,2);}}i.mark("stats&calc");i.literal(i.forIndices,"byidx");i.literal(i.consecutives,"cons");i.literal(i.corrections,"corr");\\n}var C0=[];for(var Cr=0;Cr\\x3cCp.length-1;Cr++){C0.push([Cp[Cr][1],Cp[Cr+1][0]]);}i.end();return C0;}function z(Cp){var i={};\\ni.nodeId=L(Cp);i.knownHTML=Cp.innerHTML;if(browser.msie){i.knownText=Cp.innerText;}setAssoc(Cp,"dirtiness",i);\\n}function V(i){var Cq=O("cleanCheck",false);if(i.parentNode!=B){return true;}var Cp=getAssoc(i,"dirtiness");\\nif(!Cp){return true;}if(i.id!==Cp.nodeId){return true;}if(browser.msie){if(i.innerText!==Cp.knownText){return true;\\n}}if(i.innerHTML!==Cp.knownHTML){return true;}Cq.end();return false;}function A1(Ct,Cs){var Cq=Ct.lineNode;\\nvar Cp=Cq.offsetTop;var Cr=Cq.offsetHeight;var i=(Cs||{});i.top=Cp;i.bottom=(Cp+Cr);return i;}function B5(){var i=Ab();\\nvar Cq=F.document;var Cp=Cq.documentElement.clientHeight;return{top:i,bottom:(i+Cp)};}function Bs(){var Cq=B5();\\nvar Cr={};var Cp=A.lines.search(function(Cs){return A1(Cs,Cr).bottom>Cq.top;});var i=A.lines.search(function(Cs){return A1(Cs,Cr).top>=Cq.bottom;\\n});if(i\\x3cCp){i=Cp;}return[Cp,i];}function BI(){var i=Bs();return[A.lines.offsetOfIndex(i[0]),A.lines.offsetOfIndex(i[1])];\\n}function CY(Cp){a("handleClick",function(){H.atMost(200);});if((!Cp.ctrlKey)&&(Cp.button!=2)&&(Cp.button!=3)){function Cq(Ct){return(Ct.tagName||"").toLowerCase()=="a"&&Ct.href;\\n}var i=Cp.target;while(i&&i.parentNode&&!Cq(i)){i=i.parentNode;}if(i&&Cq(i)){try{var Cr=window.open(i.href,"_blank");\\nCr.focus();}catch(Cs){}Cp.preventDefault();}}}function Bu(){if(!(A.selStart&&A.selEnd)){return;}var i=A.selStart[0];\\nvar Cp=X(i);AY("\\\\n");if(Cp){if(i+1\\x3cA.lines.length()){Bg(i+1,Cp);}}else{CE();}}function AT(Cw){if(!(A.selStart&&A.selEnd)){return false;\\n}var Cq,Cv;Cq=A.selStart[0];Cv=Math.max(Cq,A.selEnd[0]-((A.selEnd[1]==0)?1:0));var Cr=[];var Cs=false;\\nfor(var Cp=Cq;Cp\\x3c=Cv;Cp++){var i=X(Cp);if(i){i=/([a-z]+)([12345678])/.exec(i);if(i){Cs=true;var Cx=i[1];\\nvar Ct=Number(i[2]);var Cu=Math.max(1,Math.min(BW,Ct+(Cw?-1:1)));if(Ct!=Cu){Cr.push([Cp,Cx+Cu]);}}}}if(Cr.length>0){AI(Cr);\\n}return Cs;}function Bw(i){if(!AT(i)){AY(Ad);}}function A5(C4){var Cu=C4||{};var Cw=false;if(A.selStart){if(U()){var Cv=m();\\nvar Ct=t();var Cp=A.lines.atIndex(Cv);var C0=Cp.text;var Cx=Cp.lineMarker;if(/^ +$/.exec(C0.substring(Cx,Ct))){var C3=Ct-Cx;\\nvar C1=Ad.length;var Cz=((C3-1)%C1)+1;f([Cv,Ct-Cz],[Cv,Ct],"");Cw=true;}}if(!Cw){if(U()){var i=m();var Cp=A.lines.atIndex(i);\\nif(t()\\x3c=Cp.lineMarker){var C6="delete_newline";var C2=(i>0?X(i-1):"");var C5=X(i);var Cq=(i>0&&A.lines.atIndex(i-1));\\nvar Cy=(Cq&&Cq.text.length==Cq.lineMarker);if(C5){if(Cy&&!C2){f([i-1,Cq.text.length],[i,0],"");}else{f([i,0],[i,Cp.lineMarker],"");\\n}}else{if(i>0){f([i-1,Cq.text.length],[i,0],"");}}}else{var Cr=A7();if(Cr>0){if(Cu.metaKey||Cu.ctrlKey||Cu.altKey){var Cs=Cr-1;\\nwhile(Cs>Cp.lineMarker&&n(A.alltext.charAt(Cs-1))){Cs--;}BA(Cs,Cr,"");}else{BA(Cr-1,Cr,"");}}}}else{AY("");\\n}}}}var Bf=/[\\\\u0030-\\\\u0039\\\\u0041-\\\\u005A\\\\u0061-\\\\u007A\\\\u00C0-\\\\u00D6\\\\u00D8-\\\\u00F6\\\\u00F8-\\\\u00FF\\\\u0100-\\\\u1FFF\\\\u3040-\\\\u9FFF\\\\uF900-\\\\uFDFF\\\\uFE70-\\\\uFEFE\\\\uFF10-\\\\uFF19\\\\uFF21-\\\\uFF3A\\\\uFF41-\\\\uFF5A\\\\uFF66-\\\\uFFDC]/;\\nvar CU=/\\\\s/;function n(i){return !!Bf.exec(i);}function Cf(i){return !!CU.exec(i);}function x(Cu,Cv,Cr){var Cp=Cv;\\nfunction Ct(){if(Cr){return Cu.charAt(Cp);}else{return Cu.charAt(Cp-1);}}function Cs(){if(Cr){Cp++;}else{Cp--;\\n}}function Cq(){if(Cr){return Cp>=Cu.length;}else{return Cp\\x3c=0;}}if(browser.windows&&Cr){while((!Cq())&&n(Ct())){Cs();\\n}while((!Cq())&&!n(Ct())){Cs();}}else{while((!Cq())&&!n(Ct())){Cs();}while((!Cq())&&n(Ct())){Cs();}}return Cp;\\n}function AM(i){if(AK&&top.DONT_INCORP){return;}if(!k){return;}var Cq=i.type;var Cw=i.charCode;var Cr=i.keyCode;\\nvar Cs="";if(i.altKey){Cs=Cs+"A";}if(i.ctrlKey){Cs=Cs+"C";}if(i.shiftKey){Cs=Cs+"S";}if(i.metaKey){Cs=Cs+"M";\\n}var Cz="";if(Cs){Cz=Cs+"-";}var Ct=i.which;var Cy=((!Cw)&&((Cq=="keyup")||(Cq=="keydown"))&&(Cr==16||Cr==17||Cr==18||Cr==20||Cr==224||Cr==91));\\nif(Cy){return;}var Cp=false;var Cv=((browser.msie||browser.safari)?(Cq=="keydown"):(Cq=="keypress"));\\nvar Cu=((browser.msie||browser.safari)?(Cq=="keydown"):(Cq=="keypress"));var Cx=false;a("handleKeyEvent",function(){if(Cq=="keypress"||(Cv&&Cr==13)){if(!Ar(i)){i.preventDefault();\\nCx=true;}}else{if(Cq=="keydown"){Au(i);}}if(!Cx){if(Cv&&Cr==8){G(3);i.preventDefault();A5(i);Cp=true;\\n}if((!Cp)&&Cv&&Cr==13){G(4);i.preventDefault();Bu();N.setTimeout(function(){F.scrollBy(-100,0);},0);Cp=true;\\n}if((!Cp)&&Cv&&Cr==9&&!(i.metaKey||i.ctrlKey)){G(5);i.preventDefault();Bw(i.shiftKey);Cp=true;}if((!Cp)&&Cu&&String.fromCharCode(Ct).toLowerCase()=="z"&&(i.metaKey||i.ctrlKey)){G(6);\\ni.preventDefault();if(i.shiftKey){s("redo");}else{s("undo");}Cp=true;}if((!Cp)&&Cu&&String.fromCharCode(Ct).toLowerCase()=="y"&&(i.metaKey||i.ctrlKey)){G(10);\\ni.preventDefault();s("redo");Cp=true;}if((!Cp)&&Cu&&String.fromCharCode(Ct).toLowerCase()=="b"&&(i.metaKey||i.ctrlKey)){G(13);\\ni.preventDefault();c("bold");Cp=true;}if((!Cp)&&Cu&&String.fromCharCode(Ct).toLowerCase()=="i"&&(i.metaKey||i.ctrlKey)){G(14);\\ni.preventDefault();c("italic");Cp=true;}if((!Cp)&&Cu&&String.fromCharCode(Ct).toLowerCase()=="u"&&(i.metaKey||i.ctrlKey)){G(15);\\ni.preventDefault();c("underline");Cp=true;}if((!Cp)&&Cu&&String.fromCharCode(Ct).toLowerCase()=="h"&&(i.ctrlKey)){G(20);\\ni.preventDefault();A5();Cp=true;}if(AA&&AA.handleKeyEvent(i)){i.preventDefault();Cp=true;}}if(Cq=="keydown"){H.atLeast(500);\\n}else{if(Cq=="keypress"){if((!Cp)&&AG.shouldNormalizeOnChar(Cw)){H.atMost(0);}else{H.atLeast(500);}}else{if(Cq=="keyup"){var C0=200;\\nH.atLeast(C0);H.atMost(C0);}}}var C2=(browser.mozilla&&i.altKey&&Cw==0&&Cr==0);var C1=(browser.safari&&i.altKey&&Cr==229);\\nif(AD||C2||C1){H.atLeast(3000);AD=true;}if((!Cp)&&(!AD)&&(!r)){if(Cq!="keyup"||!A8()){Aw();}}if(Cq=="keyup"){AD=false;\\n}});}var AD=false;function s(Cp){if(undoModule.enabled){var i;if(Cp=="undo"){i="performUndo";}if(Cp=="redo"){i="performRedo";\\n}if(i){var Cq=C.editEvent.eventType;C.startNewEvent(Cp);undoModule[i](function(Cs,Cr){if(Cs){b(Cs);}if(Cr){d(P(Cr.selStart),P(Cr.selEnd),Cr.selFocusAtStart);\\n}var Ct=C.startNewEvent(Cq,true);return Ct;});}}}function Ba(){var i=A.selStart,Cp=A.selEnd;if(!(i&&Cp)){AW(null);\\nreturn;}var Cr=(false&&browser.mozilla&&i&&Cp&&i[0]==Cp[0]&&i[1]==A.lines.atIndex(i[0]).lineMarker&&Cp[1]==A.lines.atIndex(Cp[0]).lineMarker&&Bk(i[0]));\\nvar Cq={};var Cs=[i[0],i[1]];if(Cr){Cs[1]+=1;}Cq.startPoint=Am(Cs);var Ct=[Cp[0],Cp[1]];if(Cr){Ct[1]+=1;\\n}Cq.endPoint=Am(Ct);Cq.focusAtStart=!!A.selFocusAtStart;AW(Cq);if(Cr){Cr.unhack();}}function Ca(){return map(A.lines.slice(),function(Cq){var Cp=Cq.text;\\nvar i;if(Cp.length==0){i=\\\'\\x3cspan style="color: #aaa">--\\x3c/span>\\\';}else{i=htmlPrettyEscape(Cp);}return"\\x3cdiv>\\x3ccode>"+i+"\\x3c/div>\\x3c/code>";\\n}).join("");}function j(i){if(isNodeText(i)){return i.nodeValue.length;}else{return 1;}}function CX(){var i;\\ntry{i=E.selection;}catch(Cq){}if(!i){return false;}var Cp;try{Cp=i.createRange();}catch(Cq){}if(!Cp){return false;\\n}var Cr=Cp.parentElement();if(Cr.ownerDocument!=E){return false;}return true;}function Ae(){if(browser.msie){var i;\\ntry{i=E.selection;}catch(Cx){}if(!i){return null;}var Cr;try{Cr=i.createRange();}catch(Cx){}if(!Cr){return null;\\n}var C0=Cr.parentElement();if(C0.ownerDocument!=E){return null;}function C1(){return E.body.createTextRange();\\n}function Cv(C3){var C2=C1();C2.moveToElementText(C3);return C2;}function Ct(C6){var C2=C6.parentElement();\\nvar C5=-1;var C8=C2.childNodes.length;var C7=Cv(C2);if(C6.compareEndPoints("StartToStart",C7)==0){return{node:C2,index:0,maxIndex:1};\\n}else{if(C6.compareEndPoints("EndToEnd",C7)==0){if(AF(C2)&&C2.nextSibling){return{node:C2.nextSibling,index:0,maxIndex:1};\\n}return{node:C2,index:1,maxIndex:1};}else{if(C2.childNodes.length==0){return{node:C2,index:0,maxIndex:1};\\n}}}for(var C3=0;C3\\x3cC2.childNodes.length;C3++){var DD=C2.childNodes.item(C3);if(!isNodeText(DD)){var DA=Cv(DD);\\nvar DE=C6.compareEndPoints("StartToStart",DA);var DH=C6.compareEndPoints("EndToEnd",DA);if(DE>=0&&DH\\x3c=0){var DG=0;\\nif(DE>0){DG=1;}return{node:DD,index:DG,maxIndex:1};}else{if(DH>0){if(C3>C5){C5=C3;C7.setEndPoint("StartToEnd",DA);\\n}}else{if(DE\\x3c0){if(C3\\x3cC8){C8=C3;C7.setEndPoint("EndToStart",DA);}}}}}}if((C8-C5)==1){if(C5>=0){return{node:C2.childNodes.item(C5),index:1,maxIndex:1};\\n}else{return{node:C2.childNodes.item(C8),index:0,maxIndex:1};}}var DF=0;var C9=C6.duplicate();var DI=binarySearchInfinite(40,function(DL){var DK=DL-DF;\\nvar DJ=Math.abs(C9.move("character",-DK));if(C9.move("character",-1)){C9.move("character",1);}if(DK\\x3c0){DF-=DJ;\\n}else{DF+=DJ;}return(C9.compareEndPoints("StartToStart",C7)\\x3c=0);});var DB=C5+1;var DC=DI;while(DB\\x3cC8){var C4=C2.childNodes.item(DB);\\nif(DC\\x3c=C4.nodeValue.length){return{node:C4,index:DC,maxIndex:C4.nodeValue.length};}DC-=C4.nodeValue.length;\\nDB++;}var C4=C2.childNodes.item(DB-1);return{node:C4,index:C4.nodeValue.length,maxIndex:C4.nodeValue.length};\\n}var Cq={};if(Cr.compareEndPoints("StartToEnd",Cr)==0){var Cs=Ct(Cr);Cq.startPoint=Cs;Cq.endPoint={node:Cs.node,index:Cs.index,maxIndex:Cs.maxIndex};\\n}else{var Cu=Cr.duplicate();Cu.collapse(true);var Cw=Cr.duplicate();Cw.collapse(false);Cq.startPoint=Ct(Cu);\\nCq.endPoint=Ct(Cw);}return Cq;}else{var i=window.getSelection();if(i&&i.type!="None"&&i.rangeCount!==0){var Cp=i.getRangeAt(0);\\nfunction Cz(C2){while(C2&&!(C2.tagName&&C2.tagName.toLowerCase()=="body")){C2=C2.parentNode;}return !!C2;\\n}function Cy(C7,C6){if(!Cz(C7)){return{node:B,index:0,maxIndex:1};}var C2=C7;var C5=C2.childNodes.length;\\nif(isNodeText(C2)){return{node:C2,index:C6,maxIndex:C2.nodeValue.length};}else{if(C5==0){return{node:C2,index:0,maxIndex:1};\\n}else{if(C6==C5){var C3=C2.childNodes.item(C5-1);var C4=j(C3);return{node:C3,index:C4,maxIndex:C4};}else{var C3=C2.childNodes.item(C6);\\nvar C4=j(C3);return{node:C3,index:0,maxIndex:C4};}}}}var Cq={};Cq.startPoint=Cy(Cp.startContainer,Cp.startOffset);\\nCq.endPoint=Cy(Cp.endContainer,Cp.endOffset);Cq.focusAtStart=(((Cp.startContainer!=Cp.endContainer)||(Cp.startOffset!=Cp.endOffset))&&i.anchorNode&&(i.anchorNode==Cp.endContainer)&&(i.anchorOffset==Cp.endOffset));\\nreturn Cq;}else{return null;}}}function AW(i){function Cv(C5){return{node:C5.node,index:C5.index,maxIndex:C5.maxIndex};\\n}if(browser.msie){E.body.scrollHeight;function Cz(C6,C5){while(C5.firstChild&&!isNodeText(C5.firstChild)){C5=C5.firstChild;\\n}C6.moveToElementText(C5);}function C4(){return E.body.createTextRange();}function Cs(C5,C6){if(isNodeText(C6)){if(C6.previousSibling&&!isNodeText(C6.previousSibling)){Cx(C5,C6.previousSibling);\\n}else{Cs(C5,C6.parentNode);}}else{Cz(C5,C6);if(C5.move("character",1)){C5.move("character",-1);}C5.collapse(true);\\n}}function Cx(C5,C6){if(isNodeText(C6)){Cs(C5,C6);C5.move("character",C6.nodeValue.length);}else{Cz(C5,C6);\\nC5.collapse(false);}}function Cy(C7){var C5=C4();var C6=C7.node;if(isNodeText(C6)){Cs(C5,C6);C5.move("character",C7.index);\\n}else{if(C7.index==0){Cs(C5,C6);}else{Cx(C5,C6);}}return C5;}if(i){if(!CX()){return;}var C1=Cv(i.startPoint);\\nvar Cp=Cv(i.endPoint);if(Cp.index==Cp.maxIndex&&Cp.node.nextSibling){Cp.node=Cp.node.nextSibling;Cp.index=0;\\nCp.maxIndex=j(Cp.node);}var Cr=Cy(C1);Cr.setEndPoint("EndToEnd",Cy(Cp));function C3(C7){var C6;try{C6=E.selection;\\n}catch(C8){}if(!C6){return false;}var C5=C6.createRange();if(C5.parentElement().ownerDocument!=E){return false;\\n}if(C7.compareEndPoints("StartToStart",C5)!==0){return false;}if(C7.compareEndPoints("EndToEnd",C5)!==0){return false;\\n}return true;}if(!C3(Cr)){Cr.select();}}else{try{E.selection.empty();}catch(C2){}}}else{var Cw;function C0(C8){var C5=Cv(C8);\\nif(Cw){function C7(){while(C5.node.childNodes.length>0){if(C5.index==0){C5.node=C5.node.firstChild;C5.maxIndex=j(C5.node);\\n}else{if(C5.index==C5.maxIndex){C5.node=C5.node.lastChild;C5.maxIndex=j(C5.node);C5.index=C5.maxIndex;\\n}else{break;}}}}if(isNodeText(C5.node)&&C5.index==C5.maxIndex){var C6=C5.node;while((!C6.nextSibling)&&(C6!=B)&&(C6.parentNode!=B)){C6=C6.parentNode;\\n}if(C6.nextSibling&&(!((typeof C6.nextSibling.tagName)=="string"&&C6.nextSibling.tagName.toLowerCase()=="br"))&&(C6!=C5.node)&&(C6!=B)&&(C6.parentNode!=B)){C5.node=C6.nextSibling;\\nC5.maxIndex=j(C5.node);C5.index=0;C7();}}if(!isNodeText(C5.node)){C7();}}if(isNodeText(C5.node)){return{container:C5.node,offset:C5.index};\\n}else{return{container:C5.node.parentNode,offset:Bx(C5.node)+C5.index};}}var Cq=window.getSelection();\\nif(Cq){Cq.removeAllRanges();if(i){Cw=(i.startPoint.node===i.endPoint.node&&i.startPoint.index===i.endPoint.index);\\nvar Ct=C0(i.startPoint);var Cu=C0(i.endPoint);if((!Cw)&&i.focusAtStart&&Cq.collapse&&Cq.extend){Cq.collapse(Cu.container,Cu.offset);\\nCq.extend(Ct.container,Ct.offset);}else{var Cr=E.createRange();Cr.setStart(Ct.container,Ct.offset);Cr.setEnd(Cu.container,Cu.offset);\\nCq.removeAllRanges();Cq.addRange(Cr);}}}}}function Bx(i){var Cp=0;while(i.previousSibling){Cp++;i=i.previousSibling;\\n}return Cp;}function h(){if(AO()==0||Ak()==0){return;}function Cp(C3,C4,i){if(C3[C4]!=i){C3[C4]=i;}}var Cx=T.firstChild.offsetWidth;\\nvar Cs=Cx+CC;if(Cs\\x3cAh){Cs=Ah;}p=BS;if(AP){p+=Cs+BO;}Cp(g.style,"left",p+"px");Cp(T.style,"width",Cs+"px");\\nfor(var Cv=0;Cv\\x3c2;Cv++){var Cq=B.clientHeight;var Cr=(browser.msie?B.createTextRange().boundingWidth:B.clientWidth);\\nvar Ct=Ak()-Bo-Aj;var Cu=AO()-p-CQ;if(Cq\\x3cCt){Cq=Ct;if(browser.msie){Cp(F.document.documentElement.style,"overflowY","auto");\\n}}else{if(browser.msie){Cp(F.document.documentElement.style,"overflowY","scroll");}}if(K){Cr=Cu;}else{if(Cr\\x3cCu){Cr=Cu;\\n}}if(Cq>32000){Cq=32000;}if(Cr>32000){Cr=32000;}Cp(g.style,"height",Cq+"px");Cp(g.style,"width",Cr+"px");\\nCp(T.style,"height",Cq+"px");}if(browser.mozilla){if(!K){var Cy=B;var Cw=Ct+"px";Cp(Cy.style,"height",Cw);\\n}else{Cp(B.style,"height","");}}var C2=BB();var C1=Ab();var C0=F;var Cz=20;Ax();o(T,"sidedivdelayed");\\n}function BE(){var Cp=F;var Cq=F.document;if(typeof(Cp.pageYOffset)=="number"){return{x:Cp.pageXOffset,y:Cp.pageYOffset};\\n}var i=Cq.documentElement;if(i&&typeof(i.scrollTop)=="number"){return{x:i.scrollLeft,y:i.scrollTop};}}function BB(){return BE().x;\\n}function Ab(){return BE().y;}function Cm(i){F.scrollTo(i,Ab());}function Cl(i){F.scrollTo(BB(),i);}function Ch(i,Cp){F.scrollTo(i,Cp);\\n}var BM=[];function BF(){forEach(BM,function(i){i();});}J(window,"load",CB);function Az(i){try{function Cp(Cs,Cu,Ct){if(String(Cs[Cu]).toLowerCase()!=Ct){Cs[Cu]=Ct;\\nreturn true;}return false;}if(browser.msie||browser.safari){Cp(B,"contentEditable",(i?"true":"false"));\\n}else{var Cq=Cp(E,"designMode",(i?"on":"off"));if(Cq&&i&&browser.opera){A9();}}return true;}catch(Cr){return false;\\n}}var Cg=null;function B3(Cp){var i=window.clipboardData&&window.clipboardData.getData("Text");if(i&&E.selection){}}var r=false;\\nfunction A6(i){if(i.type=="compositionstart"){r=true;}else{if(i.type=="compositionend"){r=false;}}}function A9(){J(window,"unload",BF);\\nJ(document,"keydown",AM);J(document,"keypress",AM);J(document,"keyup",AM);J(document,"click",CY);J(B,"blur",CJ);\\nif(browser.msie){J(document,"click",CM);}if(browser.msie){J(B,"paste",B3);}if((!browser.msie)&&document.documentElement){J(document.documentElement,"compositionstart",A6);\\nJ(document.documentElement,"compositionend",A6);}}function CM(i){if((i.target.tagName||"").toLowerCase()!="html"){return;\\n}if(!(i.pageY>B.clientHeight)){return;}a("handleOuterClick",function(){G(11);if(U()){var Cp=A.lines.length()-1;\\nvar Cq=A.lines.atIndex(Cp).text.length;d([Cp,Cq],[Cp,Cq]);}});}function BC(Cq,i){var Cp=[];(Cq.className||"").replace(/\\\\S+/g,function(Cr){if((!i)||(i(Cr))){Cp.push(Cr);\\n}});return Cp;}function Ay(i,Cp){i.className=Cp.join(" ");}function o(Cq,Cp){var i=false;var Cr=BC(Cq,function(Cs){if(Cs==Cp){i=true;\\n}return true;});if(!i){Cr.push(Cp);Ay(Cq,Cr);}}function CG(Cp,Cq){var i=false;var Cr=BC(Cp,function(Cs){if(Cs==Cq){i=true;\\nreturn false;}return true;});if(i){Ay(Cp,Cr);}}function Q(Cp,i,Cq){if(Cq){o(Cp,i);}else{CG(Cp,i);}}function CB(){E=document;\\na("setup",function(){var Cp=E.getElementById("innerdocbody");B=Cp;if(browser.mozilla){o(B,"mozilla");\\n}if(browser.safari){o(B,"safari");}if(browser.msie){o(B,"msie");}if(browser.msie){try{E.execCommand("BackgroundImageCache",false,true);\\n}catch(Cq){}}Q(B,"authorColors",true);Q(B,"doesWrap",K);Bh();Ax();while(B.firstChild){B.removeChild(B.firstChild);\\n}var i=AN("");AJ(0,A.lines.length(),[i]);AH(null,[i.domInfo],null);A.alines=Changeset.splitAttributionLines(Changeset.makeAttribution("\\\\n"),"\\\\n");\\nA9();});N.setTimeout(function(){parent.readyFunc();},0);B4=true;}function Bc(){window.focus();}function CJ(i){if(browser.msie){AW(null);\\n}}function J(Cp,Cq,i){var Cr;if((typeof i._wrapper)!="function"){i._wrapper=function(Cs){i(CO(Cs||window.event||{}));\\n};}var Cr=i._wrapper;if(Cp.addEventListener){Cp.addEventListener(Cq,Cr,false);}else{Cp.attachEvent("on"+Cq,Cr);\\n}BM.push(function(){B2(Cp,Cq,i);});}function B2(i,Cq,Cr){var Cp=Cr._wrapper;if(i.removeEventListener){i.removeEventListener(Cq,Cp,false);\\n}else{i.detachEvent("on"+Cq,Cp);}}function B0(Cw){var Cp=Cw.node;var Ct=Cw.index;function Cq(C0){return C0.offsetLeft;\\n}function Cr(C0){return C0.offsetLeft+C0.offsetWidth;}if(!isNodeText(Cp)){if(Ct==0){return Cq(Cp);}else{return Cr(Cp);\\n}}else{var Cs=Ct;var Cv=Cp.nodeValue.length-Ct;var i;for(i=Cp.previousSibling;i&&isNodeText(i);i=i.previousSibling){Cs+=i.nodeValue;\\n}var Cu=(i?Cr(i):Cq(Cp.parentNode));for(i=Cp.nextSibling;i&&isNodeText(i);i=i.nextSibling){Cv+=i.nodeValue;\\n}var Cz=(i?Cq(i):Cr(Cp.parentNode));var Cx=(Cs/(Cs+Cv));var Cy=Cu+Cx*(Cz-Cu);return Math.round(Cy);}}function Cd(){var i=F;\\nvar Cp=i.document;if(i.innerHeight&&i.scrollMaxY){return i.innerHeight+i.scrollMaxY;}else{if(Cp.body.scrollHeight>Cp.body.offsetHeight){return Cp.body.scrollHeight;\\n}else{return Cp.body.offsetHeight;}}}function Cn(){var i=F;var Cp=i.document;if(i.innerWidth&&i.scrollMaxX){return i.innerWidth+i.scrollMaxX;\\n}else{if(Cp.body.scrollWidth>Cp.body.offsetWidth){return Cp.body.scrollWidth;}else{return Cp.body.offsetWidth;\\n}}}function Ak(){var Cp=F;var Cq=Cp.document;var i;if(browser.opera){i=Cp.innerHeight;}else{i=Cq.documentElement.clientHeight;\\n}if(i){return i;}return Number(D.frame.parentNode.style.height.replace(/[^0-9]/g,"")||0);}function AO(){var Cp=F;\\nvar i=Cp.document;return i.documentElement.clientWidth;}function Bt(Cp){var i=F;var Cs=F.document;var Cq=Cp.offsetTop+Aj-i.scrollY;\\nvar Cr=i.scrollY+Ak()-(Cp.offsetTop+Aj+Cp.offsetHeight);if(Cq\\x3c0){i.scrollBy(0,Cq);}else{if(Cr\\x3c0){i.scrollBy(0,-Cr);\\n}}}function CT(Cp){var i=F;var Cs=F.document;Cp+=p;var Cq=Cp-i.scrollX;var Cr=i.scrollX+AO()-Cp;if(Cq\\x3c0){i.scrollBy(Cq,0);\\n}else{if(Cr\\x3c0){i.scrollBy(-Cr+1,0);}}}function CP(){if(!A.selStart){return;}h();var Cq=(A.selFocusAtStart?A.selStart[0]:A.selEnd[0]);\\nBt(A.lines.atIndex(Cq).lineNode);if(!K){var i=Ae();if(i){var Cr=(i.focusAtStart?i.startPoint:i.endPoint);\\nvar Cp=B0(Cr);CT(Cp);h();}}}function X(Cq){var Cp=A.alines[Cq];if(Cp){var i=Changeset.opIterator(Cp);\\nif(i.hasNext()){return Changeset.opAttributeValue(i.next(),"list",A.apool)||"";}}return"";}function Bg(Cp,i){AI([[Cp,i]]);\\n}function AI(Cw){var Cp=[0,0];var Cq=Changeset.builder(A.lines.totalWidth());for(var Ct=0;Ct\\x3cCw.length;\\nCt++){var Cv=Cw[Ct];var Cs=Cv[0];var Cr=Cv[1];AR(Cq,Cp,(Cp=[Cs,0]));if(X(Cs)){if(Cr){AR(Cq,Cp,(Cp=[Cs,1]),[["list",Cr]],A.apool);\\n}else{BQ(Cq,Cp,(Cp=[Cs,1]));}}else{if(Cr){Cq.insert("*",[["author",e],["insertorder","first"],["list",Cr]],A.apool);\\n}}}var Cu=Cq.toString();if(!Changeset.isIdentity(Cu)){b(Cu);}}function As(){if(!(A.selStart&&A.selEnd)){return;\\n}var Cp,Cq;Cp=A.selStart[0];Cq=Math.max(Cp,A.selEnd[0]-((A.selEnd[1]==0)?1:0));var Ct=true;for(var i=Cp;\\ni\\x3c=Cq;i++){if(!X(i)){Ct=false;break;}}var Cs=[];for(var i=Cp;i\\x3c=Cq;i++){var Cr=X(i);Cs.push([i,Ct?"":(Cr?Cr:"bullet1")]);\\n}AI(Cs);}var AA=(browser.mozilla&&(function(){var i=0;var Cp=false;function Cr(Cu){var Ct=A.lines.atIndex(Cu).lineNode;\\nwhile(Ct.firstChild&&AF(Ct.firstChild)){Ct=Ct.firstChild;}return makeVirtualLineView(Ct);}function Cs(Ct,Cu){return[Ct,Cu-A.lines.atIndex(Ct).lineMarker];\\n}function Cq(Ct,Cu){return[Ct,Cu+A.lines.atIndex(Ct).lineMarker];}return{notifySelectionChanged:function(){if(!Cp){i=0;\\n}},handleKeyEvent:function(C0){if(C0.type!="keypress"){return false;}var Cw=C0.keyCode;if(Cw\\x3c37||Cw>40){return false;\\n}q();if(!(A.selStart&&A.selEnd)){return true;}var Cx=(C0.altKey?"byWord":(C0.ctrlKey?"byWord":(C0.metaKey?"toEnd":"normal")));\\nvar Cu=Cs(A.selStart[0],A.selStart[1]);var Ct=Cs(A.selEnd[0],A.selEnd[1]);var DB=U();if(A.selFocusAtStart){var DK=Cu;\\nCu=Ct;Ct=DK;}var DH=38,DJ=40,C7=37,DE=39;var C8=false;if(DB&&!C0.shiftKey){Cu=Ct;}else{if((!DB)&&(!C0.shiftKey)){if(Cw==C7){if(A.selFocusAtStart){Cu=Ct;\\n}else{Ct=Cu;}if(Cx=="normal"){C8=true;}}else{if(Cw==DE){if(A.selFocusAtStart){Ct=Cu;}else{Cu=Ct;}if(Cx=="normal"){C8=true;\\n}}else{Cu=Ct;}}}}if(!C8){function C1(DN){var DM=A.lines.atIndex(DN);return DM.text.length-DM.lineMarker;\\n}function C4(DN){var DM=A.lines.atIndex(DN);return DM.text.substring(DM.lineMarker);}if(Cw==DH||Cw==DJ){var Cy=(Cw==DH);\\nvar C3=((Cy&&Ct[0])||((!Cy)&&Ct[0]\\x3cA.lines.length()-1));var C6,C2,DA=false;if(K){C6=Cr(Ct[0]);C2=C6.getVLineAndOffsetForChar(Ct[1]);\\nDA=((Cy&&C2.vline>0)||((!Cy)&&C2.vline\\x3c(C6.getNumVirtualLines()-1)));}var DL;if(Cx=="toEnd"){if(Cy){Ct[0]=0;\\nCt[1]=0;}else{Ct[0]=A.lines.length()-1;Ct[1]=C1(Ct[0]);}}else{if(Cx=="byWord"){if(Cy){if(Ct[1]==0&&C3){Ct[0]--;\\nCt[1]=0;}else{Ct[1]=0;}}else{var Cz=C1(Ct[0]);if(browser.windows){if(C3){Ct[0]++;Ct[1]=0;}else{Ct[1]=Cz;\\n}}else{if(Ct[1]==Cz&&C3){Ct[0]++;Ct[1]=C1(Ct[0]);}else{Ct[1]=Cz;}}}i=0;}else{if(DA){var C5=C2.vline;var Cv=C2.offset;\\nif(Cy){C5--;}else{C5++;}if(i>Cv){Cv=i;}else{i=Cv;}var DF=C6.getCharForVLineAndOffset(C5,Cv);Ct[1]=DF.lineChar;\\n}else{if(C3){if(Cy){Ct[0]--;}else{Ct[0]++;}var Cv=Ct[1];if(K){Cv=C2.offset;}if(i>Cv){Cv=i;}else{i=Cv;\\n}if(K){var DG=Cr(Ct[0]);var C5=(Cy?DG.getNumVirtualLines()-1:0);var DF=DG.getCharForVLineAndOffset(C5,Cv);\\nCt[1]=DF.lineChar;}else{var Cz=C1(Ct[0]);if(Cv>Cz){Cv=Cz;}Ct[1]=Cv;}}else{if(Cy){Ct[1]=0;}else{Ct[1]=C1(Ct[0]);\\n}i=0;}}}}}else{if(Cw==C7||Cw==DE){var DI=(Cw==C7);if(DI){if(Cx=="toEnd"){Ct[1]=0;}else{if(Ct[1]>0){if(Cx=="byWord"){Ct[1]=x(C4(Ct[0]),Ct[1],false);\\n}else{Ct[1]--;}}else{if(Ct[0]>0){Ct[0]--;Ct[1]=C1(Ct[0]);if(Cx=="byWord"){Ct[1]=x(C4(Ct[0]),Ct[1],false);\\n}}}}}else{var Cz=C1(Ct[0]);if(Cx=="toEnd"){Ct[1]=Cz;}else{if(Ct[1]\\x3cCz){if(Cx=="byWord"){Ct[1]=x(C4(Ct[0]),Ct[1],true);\\n}else{Ct[1]++;}}else{if(Ct[0]\\x3cA.lines.length()-1){Ct[0]++;Ct[1]=0;if(Cx=="byWord"){Ct[1]=x(C4(Ct[0]),Ct[1],true);\\n}}}}}i=0;}}}var C9=((Ct[0]\\x3cCu[0])||(Ct[0]==Cu[0]&&Ct[1]\\x3cCu[1]));var DD=(C9?Ct:Cu);var DC=(C9?Cu:Ct);Cp=true;\\nd(Cq(DD[0],DD[1]),Cq(DC[0],DC[1]),C9);Cp=false;C.userChangedSelection=true;return true;}};})());function CO(i){var Cp=i;\\ni=extend({},Cp);i.preventDefault=function(){if(Cp.preventDefault){Cp.preventDefault();}Cp.returnValue=false;\\n};i.stopPropagation=function(){if(Cp.stopPropagation){Cp.stopPropagation();}Cp.cancelBubble=true;};if(!i.target&&i.srcElement){i.target=i.srcElement;\\n}if(browser.safari&&i.target.nodeType==3){i.target=Cp.target.parentNode;}if(!i.relatedTarget&&i.fromElement){i.relatedTarget=i.fromElement==i.target?i.toElement:i.fromElement;\\n}if(i.pageX==null&&i.clientX!=null){var Cq=document.documentElement,Cr=document.body;i.pageX=i.clientX+(Cq&&Cq.scrollLeft||Cr.scrollLeft||0);\\ni.pageY=i.clientY+(Cq&&Cq.scrollTop||Cr.scrollTop||0);}if(!i.which&&(i.charCode||i.keyCode)){i.which=i.charCode||i.keyCode;\\n}if(!i.metaKey&&i.ctrlKey){i.metaKey=i.ctrlKey;}if(!i.which&&i.button){i.which=(i.button&1?1:(i.button&2?3:(i.button&4?2:0)));\\n}return i;}var Z;var Ai;function BX(){Z=1;T.innerHTML=\\\'\\x3ctable border="0" cellpadding="0" cellspacing="0" align="right">\\x3ctr>\\x3ctd id="sidedivinner">\\x3cdiv>1\\x3c/div>\\x3c/td>\\x3c/tr>\\x3c/table>\\\';\\nAi=F.document.getElementById("sidedivinner");}function CN(){var Cq=A.lines.length();if(Cq\\x3c1){Cq=1;}if(Cq!=Z){var Cr=Ai;\\nvar Cv=F.document;while(Z\\x3cCq){Z++;var Cw=Z;var Ct=Cv.createElement("DIV");Ct.appendChild(Cv.createTextNode(String(Cw)));\\nCr.appendChild(Ct);}while(Z>Cq){Cr.removeChild(Cr.lastChild);Z--;}}if(C&&C.domClean){var Cp=Ai.firstChild;\\nvar i=E.body.firstChild;while(Cp&&i){var Cs=(i.clientHeight||i.offsetHeight);if(i.nextSibling){Cs=i.nextSibling.offsetTop-i.offsetTop;\\n}if(Cs){var Cu=Cs+"px";if(Cp.style.height!=Cu){Cp.style.height=Cu;}}Cp=Cp.nextSibling;i=i.nextSibling;\\n}}}}OUTER(this);\'+\'//-->\\n\\x3c/script>\')')); -T.push('\'\\n<style type="text/css" title="dynamicsyntax"></style>\\n\'');T.push('\'</head><body id="innerdocbody" class="syntax" spellcheck="false"> </body></html>\''); -var X='editorId = "'+A.id+'"; editorInfo = parent.'+K+'.registry[editorId]; window.onload = function() { window.onload = null; setTimeout(function() { var iframe = document.createElement("IFRAME"); iframe.scrolling = "no"; var outerdocbody = document.getElementById("outerdocbody"); iframe.frameBorder = 0; iframe.allowTransparency = true; outerdocbody.insertBefore(iframe, outerdocbody.firstChild); iframe.ace_outerWin = window; readyFunc = function() { editorInfo.onEditorReady(); readyFunc = null; editorInfo = null; }; var doc = iframe.contentWindow.document; doc.open(); doc.write('+T.join("+")+"); doc.close(); }, 0); }"; -var Y=[W,"<html><head>",('<style type="text/css">body{margin:0;white-space:nowrap;}#outerdocbody{background-color:#fff;}body.grayedout{background-color:#eee!important;}#innerdocbody{font-size:12px;font-family:monospace;line-height:16px;}body.doesWrap{white-space:normal;}#innerdocbody{padding-top:1px;padding-right:10px;padding-bottom:8px;padding-left:1px;overflow:hidden;background-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==);}#sidediv{font-size:11px;font-family:monospace;line-height:16px;padding-top:8px;padding-right:3px;position:absolute;width:20px;top:0;left:0;cursor:default;color:white;}#sidedivinner{text-align:right;}.sidedivdelayed{background-color:#eee;color:#888!important;border-right:1px solid #999;}.sidedivhidden{display:none;}#outerdocbody iframe{display:block;position:relative;left:32px;top:7px;border:0;width:1px;height:1px;}#outerdocbody .hotrect{border:1px solid #999;position:absolute;}body.mozilla,body.safari{display:table-cell;}body.doesWrap{display:block!important;}.safari div{padding-right:1px;}p{margin:0;}#linemetricsdiv{position:absolute;left:-1000px;top:-1000px;color:white;z-index:-1;font-size:12px;font-family:monospace;}#overlaysdiv{position:absolute;left:-1000px;top:-1000px;}</style>'),'<link rel="stylesheet" type="text/css" href="data:text/css,"/>',"\x3cscript>",X,"\x3c/script>",'</head><body id="outerdocbody"><div id="sidediv"><!-- --></div><div id="linemetricsdiv">x</div><div id="overlaysdiv"><!-- --></div></body></html>']; -var U=document.createElement("IFRAME");U.frameBorder=0;A.frame=U;document.getElementById(Q).appendChild(U); -var V=U.contentWindow.document;V.open();V.write(Y.join(""));V.close();B.adjustSize();})();};return B; -}
\ No newline at end of file diff --git a/etherpad/src/static/js/colorutils.js b/etherpad/src/static/js/colorutils.js deleted file mode 100644 index e745f8e..0000000 --- a/etherpad/src/static/js/colorutils.js +++ /dev/null @@ -1,91 +0,0 @@ -// DO NOT EDIT THIS FILE, edit infrastructure/ace/www/colorutils.js - -/** - * Copyright 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -var colorutils = {}; - -// "#ffffff" or "#fff" or "ffffff" or "fff" to [1.0, 1.0, 1.0] -colorutils.css2triple = function(cssColor) { - var sixHex = colorutils.css2sixhex(cssColor); - function hexToFloat(hh) { - return Number("0x"+hh)/255; - } - return [hexToFloat(sixHex.substr(0,2)), - hexToFloat(sixHex.substr(2,2)), - hexToFloat(sixHex.substr(4,2))]; -} - -// "#ffffff" or "#fff" or "ffffff" or "fff" to "ffffff" -colorutils.css2sixhex = function(cssColor) { - var h = /[0-9a-fA-F]+/.exec(cssColor)[0]; - if (h.length != 6) { - var a = h.charAt(0); - var b = h.charAt(1); - var c = h.charAt(2); - h = a+a+b+b+c+c; - } - return h; -} - -// [1.0, 1.0, 1.0] -> "#ffffff" -colorutils.triple2css = function(triple) { - function floatToHex(n) { - var n2 = colorutils.clamp(Math.round(n*255), 0, 255); - return ("0"+n2.toString(16)).slice(-2); - } - return "#" + floatToHex(triple[0]) + - floatToHex(triple[1]) + floatToHex(triple[2]); -} - - -colorutils.clamp = function(v,bot,top) { return v < bot ? bot : (v > top ? top : v); }; -colorutils.min3 = function(a,b,c) { return (a < b) ? (a < c ? a : c) : (b < c ? b : c); }; -colorutils.max3 = function(a,b,c) { return (a > b) ? (a > c ? a : c) : (b > c ? b : c); }; -colorutils.colorMin = function(c) { return colorutils.min3(c[0], c[1], c[2]); }; -colorutils.colorMax = function(c) { return colorutils.max3(c[0], c[1], c[2]); }; -colorutils.scale = function(v, bot, top) { return colorutils.clamp(bot + v*(top-bot), 0, 1); }; -colorutils.unscale = function(v, bot, top) { return colorutils.clamp((v-bot)/(top-bot), 0, 1); }; - -colorutils.scaleColor = function(c, bot, top) { - return [colorutils.scale(c[0], bot, top), - colorutils.scale(c[1], bot, top), - colorutils.scale(c[2], bot, top)]; -} - -colorutils.unscaleColor = function(c, bot, top) { - return [colorutils.unscale(c[0], bot, top), - colorutils.unscale(c[1], bot, top), - colorutils.unscale(c[2], bot, top)]; -} - -colorutils.luminosity = function(c) { - // rule of thumb for RGB brightness; 1.0 is white - return c[0]*0.30 + c[1]*0.59 + c[2]*0.11; -} - -colorutils.saturate = function(c) { - var min = colorutils.colorMin(c); - var max = colorutils.colorMax(c); - if (max - min <= 0) return [1.0, 1.0, 1.0]; - return colorutils.unscaleColor(c, min, max); -} - -colorutils.blend = function(c1, c2, t) { - return [colorutils.scale(t, c1[0], c2[0]), - colorutils.scale(t, c1[1], c2[1]), - colorutils.scale(t, c1[2], c2[2])]; -} diff --git a/etherpad/src/static/js/cssmanager_client.js b/etherpad/src/static/js/cssmanager_client.js deleted file mode 100644 index 04ed641..0000000 --- a/etherpad/src/static/js/cssmanager_client.js +++ /dev/null @@ -1,88 +0,0 @@ -// DO NOT EDIT THIS FILE, edit infrastructure/ace/www/cssmanager.js - -/** - * Copyright 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -function makeCSSManager(emptyStylesheetTitle) { - - function getSheetByTitle(title) { - var allSheets = document.styleSheets; - for(var i=0;i<allSheets.length;i++) { - var s = allSheets[i]; - if (s.title == title) { - return s; - } - } - return null; - } - - /*function getSheetTagByTitle(title) { - var allStyleTags = document.getElementsByTagName("style"); - for(var i=0;i<allStyleTags.length;i++) { - var t = allStyleTags[i]; - if (t.title == title) { - return t; - } - } - return null; - }*/ - - var browserSheet = getSheetByTitle(emptyStylesheetTitle); - //var browserTag = getSheetTagByTitle(emptyStylesheetTitle); - function browserRules() { return (browserSheet.cssRules || browserSheet.rules); } - function browserDeleteRule(i) { - if (browserSheet.deleteRule) browserSheet.deleteRule(i); - else browserSheet.removeRule(i); - } - function browserInsertRule(i, selector) { - if (browserSheet.insertRule) browserSheet.insertRule(selector+' {}', i); - else browserSheet.addRule(selector, null, i); - } - var selectorList = []; - - function indexOfSelector(selector) { - for(var i=0;i<selectorList.length;i++) { - if (selectorList[i] == selector) { - return i; - } - } - return -1; - } - - function selectorStyle(selector) { - var i = indexOfSelector(selector); - if (i < 0) { - // add selector - browserInsertRule(0, selector); - selectorList.splice(0, 0, selector); - i = 0; - } - return browserRules().item(i).style; - } - - function removeSelectorStyle(selector) { - var i = indexOfSelector(selector); - if (i >= 0) { - browserDeleteRule(i); - selectorList.splice(i, 1); - } - } - - return {selectorStyle:selectorStyle, removeSelectorStyle:removeSelectorStyle, - info: function() { - return selectorList.length+":"+browserRules().length; - }}; -} diff --git a/etherpad/src/static/js/domline_client.js b/etherpad/src/static/js/domline_client.js deleted file mode 100644 index de2e7d3..0000000 --- a/etherpad/src/static/js/domline_client.js +++ /dev/null @@ -1,210 +0,0 @@ -// DO NOT EDIT THIS FILE, edit infrastructure/ace/www/domline.js - -/** - * Copyright 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -var domline = {}; -domline.noop = function() {}; -domline.identity = function(x) { return x; }; - -domline.addToLineClass = function(lineClass, cls) { - // an "empty span" at any point can be used to add classes to - // the line, using line:className. otherwise, we ignore - // the span. - cls.replace(/\S+/g, function (c) { - if (c.indexOf("line:") == 0) { - // add class to line - lineClass = (lineClass ? lineClass+' ' : '')+c.substring(5); - } - }); - return lineClass; -} - -// if "document" is falsy we don't create a DOM node, just -// an object with innerHTML and className -domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) { - var result = { node: null, - appendSpan: domline.noop, - prepareForAdd: domline.noop, - notifyAdded: domline.noop, - clearSpans: domline.noop, - finishUpdate: domline.noop, - lineMarker: 0 }; - - var browser = (optBrowser || {}); - var document = optDocument; - - if (document) { - result.node = document.createElement("div"); - } - else { - result.node = {innerHTML: '', className: ''}; - } - - var html = []; - var preHtml, postHtml; - var curHTML = null; - function processSpaces(s) { - return domline.processSpaces(s, doesWrap); - } - var identity = domline.identity; - var perTextNodeProcess = (doesWrap ? identity : processSpaces); - var perHtmlLineProcess = (doesWrap ? processSpaces : identity); - var lineClass = 'ace-line'; - result.appendSpan = function(txt, cls) { - if (cls.indexOf('list') >= 0) { - var listType = /(?:^| )list:(\S+)/.exec(cls); - if (listType) { - listType = listType[1]; - if (listType) { - preHtml = '<ul class="list-'+listType+'"><li>'; - postHtml = '</li></ul>'; - } - result.lineMarker += txt.length; - return; // don't append any text - } - } - var href = null; - var simpleTags = null; - if (cls.indexOf('url') >= 0) { - cls = cls.replace(/(^| )url:(\S+)/g, function(x0, space, url) { - href = url; - return space+"url"; - }); - } - if (cls.indexOf('tag') >= 0) { - cls = cls.replace(/(^| )tag:(\S+)/g, function(x0, space, tag) { - if (! simpleTags) simpleTags = []; - simpleTags.push(tag.toLowerCase()); - return space+tag; - }); - } - if ((! txt) && cls) { - lineClass = domline.addToLineClass(lineClass, cls); - } - else if (txt) { - var extraOpenTags = ""; - var extraCloseTags = ""; - if (href) { - extraOpenTags = extraOpenTags+'<a href="'+ - href.replace(/\"/g, '"')+'">'; - extraCloseTags = '</a>'+extraCloseTags; - } - if (simpleTags) { - simpleTags.sort(); - extraOpenTags = extraOpenTags+'<'+simpleTags.join('><')+'>'; - simpleTags.reverse(); - extraCloseTags = '</'+simpleTags.join('></')+'>'+extraCloseTags; - } - html.push('<span class="',cls||'','">',extraOpenTags, - perTextNodeProcess(domline.escapeHTML(txt)), - extraCloseTags,'</span>'); - } - }; - result.clearSpans = function() { - html = []; - lineClass = ''; // non-null to cause update - result.lineMarker = 0; - }; - function writeHTML() { - var newHTML = perHtmlLineProcess(html.join('')); - if (! newHTML) { - if ((! document) || (! optBrowser)) { - newHTML += ' '; - } - else if (! browser.msie) { - newHTML += '<br/>'; - } - } - if (nonEmpty) { - newHTML = (preHtml||'')+newHTML+(postHtml||''); - } - html = preHtml = postHtml = null; // free memory - if (newHTML !== curHTML) { - curHTML = newHTML; - result.node.innerHTML = curHTML; - } - if (lineClass !== null) result.node.className = lineClass; - } - result.prepareForAdd = writeHTML; - result.finishUpdate = writeHTML; - result.getInnerHTML = function() { return curHTML || ''; }; - - return result; -}; - -domline.escapeHTML = function(s) { - var re = /[&<>'"]/g; /']/; // stupid indentation thing - if (! re.MAP) { - // persisted across function calls! - re.MAP = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' - }; - } - return s.replace(re, function(c) { return re.MAP[c]; }); -}; - -domline.processSpaces = function(s, doesWrap) { - if (s.indexOf("<") < 0 && ! doesWrap) { - // short-cut - return s.replace(/ /g, ' '); - } - var parts = []; - s.replace(/<[^>]*>?| |[^ <]+/g, function(m) { parts.push(m); }); - if (doesWrap) { - var endOfLine = true; - var beforeSpace = false; - // last space in a run is normal, others are nbsp, - // end of line is nbsp - for(var i=parts.length-1;i>=0;i--) { - var p = parts[i]; - if (p == " ") { - if (endOfLine || beforeSpace) - parts[i] = ' '; - endOfLine = false; - beforeSpace = true; - } - else if (p.charAt(0) != "<") { - endOfLine = false; - beforeSpace = false; - } - } - // beginning of line is nbsp - for(var i=0;i<parts.length;i++) { - var p = parts[i]; - if (p == " ") { - parts[i] = ' '; - break; - } - else if (p.charAt(0) != "<") { - break; - } - } - } - else { - for(var i=0;i<parts.length;i++) { - var p = parts[i]; - if (p == " ") { - parts[i] = ' '; - } - } - } - return parts.join(''); -}; diff --git a/etherpad/src/static/js/easysync2_client.js b/etherpad/src/static/js/easysync2_client.js deleted file mode 100644 index 043099c..0000000 --- a/etherpad/src/static/js/easysync2_client.js +++ /dev/null @@ -1,1777 +0,0 @@ -// DO NOT EDIT THIS FILE, edit infrastructure/ace/www/easysync2.js - -/** - * Copyright 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//var _opt = (this.Easysync2Support || null); -var _opt = null; // disable optimization for now - -function AttribPool() { - var p = {}; - p.numToAttrib = {}; // e.g. {0: ['foo','bar']} - p.attribToNum = {}; // e.g. {'foo,bar': 0} - p.nextNum = 0; - - p.putAttrib = function(attrib, dontAddIfAbsent) { - var str = String(attrib); - if (str in p.attribToNum) { - return p.attribToNum[str]; - } - if (dontAddIfAbsent) { - return -1; - } - var num = p.nextNum++; - p.attribToNum[str] = num; - p.numToAttrib[num] = [String(attrib[0]||''), - String(attrib[1]||'')]; - return num; - }; - - p.getAttrib = function(num) { - var pair = p.numToAttrib[num]; - if (! pair) return pair; - return [pair[0], pair[1]]; // return a mutable copy - }; - - p.getAttribKey = function(num) { - var pair = p.numToAttrib[num]; - if (! pair) return ''; - return pair[0]; - }; - - p.getAttribValue = function(num) { - var pair = p.numToAttrib[num]; - if (! pair) return ''; - return pair[1]; - }; - - p.eachAttrib = function(func) { - for(var n in p.numToAttrib) { - var pair = p.numToAttrib[n]; - func(pair[0], pair[1]); - } - }; - - p.toJsonable = function() { - return {numToAttrib: p.numToAttrib, nextNum: p.nextNum}; - }; - - p.fromJsonable = function(obj) { - p.numToAttrib = obj.numToAttrib; - p.nextNum = obj.nextNum; - p.attribToNum = {}; - for(var n in p.numToAttrib) { - p.attribToNum[String(p.numToAttrib[n])] = Number(n); - } - return p; - }; - - return p; -} - -var Changeset = {}; - -Changeset.error = function error(msg) { var e = new Error(msg); e.easysync = true; throw e; }; -Changeset.assert = function assert(b, msgParts) { - if (! b) { - var msg = Array.prototype.slice.call(arguments, 1).join(''); - Changeset.error("Changeset: "+msg); - } -}; - -Changeset.parseNum = function(str) { return parseInt(str, 36); }; -Changeset.numToString = function(num) { return num.toString(36).toLowerCase(); }; -Changeset.toBaseTen = function(cs) { - var dollarIndex = cs.indexOf('$'); - var beforeDollar = cs.substring(0, dollarIndex); - var fromDollar = cs.substring(dollarIndex); - return beforeDollar.replace(/[0-9a-z]+/g, function(s) { - return String(Changeset.parseNum(s)); }) + fromDollar; -}; - -Changeset.oldLen = function(cs) { - return Changeset.unpack(cs).oldLen; -}; -Changeset.newLen = function(cs) { - return Changeset.unpack(cs).newLen; -}; - -Changeset.opIterator = function(opsStr, optStartIndex) { - //print(opsStr); - var regex = /((?:\*[0-9a-z]+)*)(?:\|([0-9a-z]+))?([-+=])([0-9a-z]+)|\?|/g; - var startIndex = (optStartIndex || 0); - var curIndex = startIndex; - var prevIndex = curIndex; - function nextRegexMatch() { - prevIndex = curIndex; - var result; - if (_opt) { - result = _opt.nextOpInString(opsStr, curIndex); - if (result) { - if (result.opcode() == '?') { - Changeset.error("Hit error opcode in op stream"); - } - curIndex = result.lastIndex(); - } - } - else { - regex.lastIndex = curIndex; - result = regex.exec(opsStr); - curIndex = regex.lastIndex; - if (result[0] == '?') { - Changeset.error("Hit error opcode in op stream"); - } - } - return result; - } - var regexResult = nextRegexMatch(); - var obj = Changeset.newOp(); - function next(optObj) { - var op = (optObj || obj); - if (_opt && regexResult) { - op.attribs = regexResult.attribs(); - op.lines = regexResult.lines(); - op.chars = regexResult.chars(); - op.opcode = regexResult.opcode(); - regexResult = nextRegexMatch(); - } - else if ((! _opt) && regexResult[0]) { - op.attribs = regexResult[1]; - op.lines = Changeset.parseNum(regexResult[2] || 0); - op.opcode = regexResult[3]; - op.chars = Changeset.parseNum(regexResult[4]); - regexResult = nextRegexMatch(); - } - else { - Changeset.clearOp(op); - } - return op; - } - function hasNext() { return !! (_opt ? regexResult : regexResult[0]); } - function lastIndex() { return prevIndex; } - return {next: next, hasNext: hasNext, lastIndex: lastIndex}; -}; - -Changeset.clearOp = function(op) { - op.opcode = ''; - op.chars = 0; - op.lines = 0; - op.attribs = ''; -}; -Changeset.newOp = function(optOpcode) { - return {opcode:(optOpcode || ''), chars:0, lines:0, attribs:''}; -}; -Changeset.cloneOp = function(op) { - return {opcode: op.opcode, chars: op.chars, lines: op.lines, attribs: op.attribs}; -}; -Changeset.copyOp = function(op1, op2) { - op2.opcode = op1.opcode; - op2.chars = op1.chars; - op2.lines = op1.lines; - op2.attribs = op1.attribs; -}; -Changeset.opString = function(op) { - // just for debugging - if (! op.opcode) return 'null'; - var assem = Changeset.opAssembler(); - assem.append(op); - return assem.toString(); -}; -Changeset.stringOp = function(str) { - // just for debugging - return Changeset.opIterator(str).next(); -}; - -Changeset.checkRep = function(cs) { - // doesn't check things that require access to attrib pool (e.g. attribute order) - // or original string (e.g. newline positions) - var unpacked = Changeset.unpack(cs); - var oldLen = unpacked.oldLen; - var newLen = unpacked.newLen; - var ops = unpacked.ops; - var charBank = unpacked.charBank; - - var assem = Changeset.smartOpAssembler(); - var oldPos = 0; - var calcNewLen = 0; - var numInserted = 0; - var iter = Changeset.opIterator(ops); - while (iter.hasNext()) { - var o = iter.next(); - switch (o.opcode) { - case '=': oldPos += o.chars; calcNewLen += o.chars; break; - case '-': oldPos += o.chars; Changeset.assert(oldPos < oldLen, oldPos," >= ",oldLen," in ",cs); break; - case '+': { - calcNewLen += o.chars; numInserted += o.chars; - Changeset.assert(calcNewLen < newLen, calcNewLen," >= ",newLen," in ",cs); - break; - } - } - assem.append(o); - } - - calcNewLen += oldLen - oldPos; - charBank = charBank.substring(0, numInserted); - while (charBank.length < numInserted) { - charBank += "?"; - } - - assem.endDocument(); - var normalized = Changeset.pack(oldLen, calcNewLen, assem.toString(), charBank); - Changeset.assert(normalized == cs, normalized,' != ',cs); - - return cs; -} - -Changeset.smartOpAssembler = function() { - // Like opAssembler but able to produce conforming changesets - // from slightly looser input, at the cost of speed. - // Specifically: - // - merges consecutive operations that can be merged - // - strips final "=" - // - ignores 0-length changes - // - reorders consecutive + and - (which margingOpAssembler doesn't do) - - var minusAssem = Changeset.mergingOpAssembler(); - var plusAssem = Changeset.mergingOpAssembler(); - var keepAssem = Changeset.mergingOpAssembler(); - var assem = Changeset.stringAssembler(); - var lastOpcode = ''; - var lengthChange = 0; - - function flushKeeps() { - assem.append(keepAssem.toString()); - keepAssem.clear(); - } - - function flushPlusMinus() { - assem.append(minusAssem.toString()); - minusAssem.clear(); - assem.append(plusAssem.toString()); - plusAssem.clear(); - } - - function append(op) { - if (! op.opcode) return; - if (! op.chars) return; - - if (op.opcode == '-') { - if (lastOpcode == '=') { - flushKeeps(); - } - minusAssem.append(op); - lengthChange -= op.chars; - } - else if (op.opcode == '+') { - if (lastOpcode == '=') { - flushKeeps(); - } - plusAssem.append(op); - lengthChange += op.chars; - } - else if (op.opcode == '=') { - if (lastOpcode != '=') { - flushPlusMinus(); - } - keepAssem.append(op); - } - lastOpcode = op.opcode; - } - - function appendOpWithText(opcode, text, attribs, pool) { - var op = Changeset.newOp(opcode); - op.attribs = Changeset.makeAttribsString(opcode, attribs, pool); - var lastNewlinePos = text.lastIndexOf('\n'); - if (lastNewlinePos < 0) { - op.chars = text.length; - op.lines = 0; - append(op); - } - else { - op.chars = lastNewlinePos+1; - op.lines = text.match(/\n/g).length; - append(op); - op.chars = text.length - (lastNewlinePos+1); - op.lines = 0; - append(op); - } - } - - function toString() { - flushPlusMinus(); - flushKeeps(); - return assem.toString(); - } - - function clear() { - minusAssem.clear(); - plusAssem.clear(); - keepAssem.clear(); - assem.clear(); - lengthChange = 0; - } - - function endDocument() { - keepAssem.endDocument(); - } - - function getLengthChange() { - return lengthChange; - } - - return {append: append, toString: toString, clear: clear, endDocument: endDocument, - appendOpWithText: appendOpWithText, getLengthChange: getLengthChange }; -}; - -if (_opt) { - Changeset.mergingOpAssembler = function() { - var assem = _opt.mergingOpAssembler(); - - function append(op) { - assem.append(op.opcode, op.chars, op.lines, op.attribs); - } - function toString() { - return assem.toString(); - } - function clear() { - assem.clear(); - } - function endDocument() { - assem.endDocument(); - } - - return {append: append, toString: toString, clear: clear, endDocument: endDocument}; - }; -} -else { - Changeset.mergingOpAssembler = function() { - // This assembler can be used in production; it efficiently - // merges consecutive operations that are mergeable, ignores - // no-ops, and drops final pure "keeps". It does not re-order - // operations. - var assem = Changeset.opAssembler(); - var bufOp = Changeset.newOp(); - - // If we get, for example, insertions [xxx\n,yyy], those don't merge, - // but if we get [xxx\n,yyy,zzz\n], that merges to [xxx\nyyyzzz\n]. - // This variable stores the length of yyy and any other newline-less - // ops immediately after it. - var bufOpAdditionalCharsAfterNewline = 0; - - function flush(isEndDocument) { - if (bufOp.opcode) { - if (isEndDocument && bufOp.opcode == '=' && ! bufOp.attribs) { - // final merged keep, leave it implicit - } - else { - assem.append(bufOp); - if (bufOpAdditionalCharsAfterNewline) { - bufOp.chars = bufOpAdditionalCharsAfterNewline; - bufOp.lines = 0; - assem.append(bufOp); - bufOpAdditionalCharsAfterNewline = 0; - } - } - bufOp.opcode = ''; - } - } - function append(op) { - if (op.chars > 0) { - if (bufOp.opcode == op.opcode && bufOp.attribs == op.attribs) { - if (op.lines > 0) { - // bufOp and additional chars are all mergeable into a multi-line op - bufOp.chars += bufOpAdditionalCharsAfterNewline + op.chars; - bufOp.lines += op.lines; - bufOpAdditionalCharsAfterNewline = 0; - } - else if (bufOp.lines == 0) { - // both bufOp and op are in-line - bufOp.chars += op.chars; - } - else { - // append in-line text to multi-line bufOp - bufOpAdditionalCharsAfterNewline += op.chars; - } - } - else { - flush(); - Changeset.copyOp(op, bufOp); - } - } - } - function endDocument() { - flush(true); - } - function toString() { - flush(); - return assem.toString(); - } - function clear() { - assem.clear(); - Changeset.clearOp(bufOp); - } - return {append: append, toString: toString, clear: clear, endDocument: endDocument}; - }; -} - -if (_opt) { - Changeset.opAssembler = function() { - var assem = _opt.opAssembler(); - // this function allows op to be mutated later (doesn't keep a ref) - function append(op) { - assem.append(op.opcode, op.chars, op.lines, op.attribs); - } - function toString() { - return assem.toString(); - } - function clear() { - assem.clear(); - } - return {append: append, toString: toString, clear: clear}; - }; -} -else { - Changeset.opAssembler = function() { - var pieces = []; - // this function allows op to be mutated later (doesn't keep a ref) - function append(op) { - pieces.push(op.attribs); - if (op.lines) { - pieces.push('|', Changeset.numToString(op.lines)); - } - pieces.push(op.opcode); - pieces.push(Changeset.numToString(op.chars)); - } - function toString() { - return pieces.join(''); - } - function clear() { - pieces.length = 0; - } - return {append: append, toString: toString, clear: clear}; - }; -} - -Changeset.stringIterator = function(str) { - var curIndex = 0; - function assertRemaining(n) { - Changeset.assert(n <= remaining(), "!(",n," <= ",remaining(),")"); - } - function take(n) { - assertRemaining(n); - var s = str.substr(curIndex, n); - curIndex += n; - return s; - } - function peek(n) { - assertRemaining(n); - var s = str.substr(curIndex, n); - return s; - } - function skip(n) { - assertRemaining(n); - curIndex += n; - } - function remaining() { - return str.length - curIndex; - } - return {take:take, skip:skip, remaining:remaining, peek:peek}; -}; - -Changeset.stringAssembler = function() { - var pieces = []; - function append(x) { - pieces.push(String(x)); - } - function toString() { - return pieces.join(''); - } - return {append: append, toString: toString}; -}; - -// "lines" need not be an array as long as it supports certain calls (lines_foo inside). -Changeset.textLinesMutator = function(lines) { - // Mutates lines, an array of strings, in place. - // Mutation operations have the same constraints as changeset operations - // with respect to newlines, but not the other additional constraints - // (i.e. ins/del ordering, forbidden no-ops, non-mergeability, final newline). - // Can be used to mutate lists of strings where the last char of each string - // is not actually a newline, but for the purposes of N and L values, - // the caller should pretend it is, and for things to work right in that case, the input - // to insert() should be a single line with no newlines. - - var curSplice = [0,0]; - var inSplice = false; - // position in document after curSplice is applied: - var curLine = 0, curCol = 0; - // invariant: if (inSplice) then (curLine is in curSplice[0] + curSplice.length - {2,3}) && - // curLine >= curSplice[0] - // invariant: if (inSplice && (curLine >= curSplice[0] + curSplice.length - 2)) then - // curCol == 0 - - function lines_applySplice(s) { - lines.splice.apply(lines, s); - } - function lines_toSource() { - return lines.toSource(); - } - function lines_get(idx) { - if (lines.get) { - return lines.get(idx); - } - else { - return lines[idx]; - } - } - // can be unimplemented if removeLines's return value not needed - function lines_slice(start, end) { - if (lines.slice) { - return lines.slice(start, end); - } - else { - return []; - } - } - function lines_length() { - if ((typeof lines.length) == "number") { - return lines.length; - } - else { - return lines.length(); - } - } - - function enterSplice() { - curSplice[0] = curLine; - curSplice[1] = 0; - if (curCol > 0) { - putCurLineInSplice(); - } - inSplice = true; - } - function leaveSplice() { - lines_applySplice(curSplice); - curSplice.length = 2; - curSplice[0] = curSplice[1] = 0; - inSplice = false; - } - function isCurLineInSplice() { - return (curLine - curSplice[0] < (curSplice.length - 2)); - } - function debugPrint(typ) { - print(typ+": "+curSplice.toSource()+" / "+curLine+","+curCol+" / "+lines_toSource()); - } - function putCurLineInSplice() { - if (! isCurLineInSplice()) { - curSplice.push(lines_get(curSplice[0] + curSplice[1])); - curSplice[1]++; - } - return 2 + curLine - curSplice[0]; - } - - function skipLines(L, includeInSplice) { - if (L) { - if (includeInSplice) { - if (! inSplice) { - enterSplice(); - } - for(var i=0;i<L;i++) { - curCol = 0; - putCurLineInSplice(); - curLine++; - } - } - else { - if (inSplice) { - if (L > 1) { - leaveSplice(); - } - else { - putCurLineInSplice(); - } - } - curLine += L; - curCol = 0; - } - //print(inSplice+" / "+isCurLineInSplice()+" / "+curSplice[0]+" / "+curSplice[1]+" / "+lines.length); - /*if (inSplice && (! isCurLineInSplice()) && (curSplice[0] + curSplice[1] < lines.length)) { - print("BLAH"); - putCurLineInSplice(); - }*/ // tests case foo in remove(), which isn't otherwise covered in current impl - } - //debugPrint("skip"); - } - - function skip(N, L, includeInSplice) { - if (N) { - if (L) { - skipLines(L, includeInSplice); - } - else { - if (includeInSplice && ! inSplice) { - enterSplice(); - } - if (inSplice) { - putCurLineInSplice(); - } - curCol += N; - //debugPrint("skip"); - } - } - } - - function removeLines(L) { - var removed = ''; - if (L) { - if (! inSplice) { - enterSplice(); - } - function nextKLinesText(k) { - var m = curSplice[0] + curSplice[1]; - return lines_slice(m, m+k).join(''); - } - if (isCurLineInSplice()) { - //print(curCol); - if (curCol == 0) { - removed = curSplice[curSplice.length-1]; - // print("FOO"); // case foo - curSplice.length--; - removed += nextKLinesText(L-1); - curSplice[1] += L-1; - } - else { - removed = nextKLinesText(L-1); - curSplice[1] += L-1; - var sline = curSplice.length - 1; - removed = curSplice[sline].substring(curCol) + removed; - curSplice[sline] = curSplice[sline].substring(0, curCol) + - lines_get(curSplice[0] + curSplice[1]); - curSplice[1] += 1; - } - } - else { - removed = nextKLinesText(L); - curSplice[1] += L; - } - //debugPrint("remove"); - } - return removed; - } - - function remove(N, L) { - var removed = ''; - if (N) { - if (L) { - return removeLines(L); - } - else { - if (! inSplice) { - enterSplice(); - } - var sline = putCurLineInSplice(); - removed = curSplice[sline].substring(curCol, curCol+N); - curSplice[sline] = curSplice[sline].substring(0, curCol) + - curSplice[sline].substring(curCol+N); - //debugPrint("remove"); - } - } - return removed; - } - - function insert(text, L) { - if (text) { - if (! inSplice) { - enterSplice(); - } - if (L) { - var newLines = Changeset.splitTextLines(text); - if (isCurLineInSplice()) { - //if (curCol == 0) { - //curSplice.length--; - //curSplice[1]--; - //Array.prototype.push.apply(curSplice, newLines); - //curLine += newLines.length; - //} - //else { - var sline = curSplice.length - 1; - var theLine = curSplice[sline]; - var lineCol = curCol; - curSplice[sline] = theLine.substring(0, lineCol) + newLines[0]; - curLine++; - newLines.splice(0, 1); - Array.prototype.push.apply(curSplice, newLines); - curLine += newLines.length; - curSplice.push(theLine.substring(lineCol)); - curCol = 0; - //} - } - else { - Array.prototype.push.apply(curSplice, newLines); - curLine += newLines.length; - } - } - else { - var sline = putCurLineInSplice(); - curSplice[sline] = curSplice[sline].substring(0, curCol) + - text + curSplice[sline].substring(curCol); - curCol += text.length; - } - //debugPrint("insert"); - } - } - - function hasMore() { - //print(lines.length+" / "+inSplice+" / "+(curSplice.length - 2)+" / "+curSplice[1]); - var docLines = lines_length(); - if (inSplice) { - docLines += curSplice.length - 2 - curSplice[1]; - } - return curLine < docLines; - } - - function close() { - if (inSplice) { - leaveSplice(); - } - //debugPrint("close"); - } - - var self = {skip:skip, remove:remove, insert:insert, close:close, hasMore:hasMore, - removeLines:removeLines, skipLines: skipLines}; - return self; -}; - -Changeset.applyZip = function(in1, idx1, in2, idx2, func) { - var iter1 = Changeset.opIterator(in1, idx1); - var iter2 = Changeset.opIterator(in2, idx2); - var assem = Changeset.smartOpAssembler(); - var op1 = Changeset.newOp(); - var op2 = Changeset.newOp(); - var opOut = Changeset.newOp(); - while (op1.opcode || iter1.hasNext() || op2.opcode || iter2.hasNext()) { - if ((! op1.opcode) && iter1.hasNext()) iter1.next(op1); - if ((! op2.opcode) && iter2.hasNext()) iter2.next(op2); - func(op1, op2, opOut); - if (opOut.opcode) { - //print(opOut.toSource()); - assem.append(opOut); - opOut.opcode = ''; - } - } - assem.endDocument(); - return assem.toString(); -}; - -Changeset.unpack = function(cs) { - var headerRegex = /Z:([0-9a-z]+)([><])([0-9a-z]+)|/; - var headerMatch = headerRegex.exec(cs); - if ((! headerMatch) || (! headerMatch[0])) { - Changeset.error("Not a changeset: "+cs); - } - var oldLen = Changeset.parseNum(headerMatch[1]); - var changeSign = (headerMatch[2] == '>') ? 1 : -1; - var changeMag = Changeset.parseNum(headerMatch[3]); - var newLen = oldLen + changeSign*changeMag; - var opsStart = headerMatch[0].length; - var opsEnd = cs.indexOf("$"); - if (opsEnd < 0) opsEnd = cs.length; - return {oldLen: oldLen, newLen: newLen, ops: cs.substring(opsStart, opsEnd), - charBank: cs.substring(opsEnd+1)}; -}; - -Changeset.pack = function(oldLen, newLen, opsStr, bank) { - var lenDiff = newLen - oldLen; - var lenDiffStr = (lenDiff >= 0 ? - '>'+Changeset.numToString(lenDiff) : - '<'+Changeset.numToString(-lenDiff)); - var a = []; - a.push('Z:', Changeset.numToString(oldLen), lenDiffStr, opsStr, '$', bank); - return a.join(''); -}; - -Changeset.applyToText = function(cs, str) { - var unpacked = Changeset.unpack(cs); - Changeset.assert(str.length == unpacked.oldLen, - "mismatched apply: ",str.length," / ",unpacked.oldLen); - var csIter = Changeset.opIterator(unpacked.ops); - var bankIter = Changeset.stringIterator(unpacked.charBank); - var strIter = Changeset.stringIterator(str); - var assem = Changeset.stringAssembler(); - while (csIter.hasNext()) { - var op = csIter.next(); - switch(op.opcode) { - case '+': assem.append(bankIter.take(op.chars)); break; - case '-': strIter.skip(op.chars); break; - case '=': assem.append(strIter.take(op.chars)); break; - } - } - assem.append(strIter.take(strIter.remaining())); - return assem.toString(); -}; - -Changeset.mutateTextLines = function(cs, lines) { - var unpacked = Changeset.unpack(cs); - var csIter = Changeset.opIterator(unpacked.ops); - var bankIter = Changeset.stringIterator(unpacked.charBank); - var mut = Changeset.textLinesMutator(lines); - while (csIter.hasNext()) { - var op = csIter.next(); - switch(op.opcode) { - case '+': mut.insert(bankIter.take(op.chars), op.lines); break; - case '-': mut.remove(op.chars, op.lines); break; - case '=': mut.skip(op.chars, op.lines, (!! op.attribs)); break; - } - } - mut.close(); -}; - -Changeset.composeAttributes = function(att1, att2, resultIsMutation, pool) { - // att1 and att2 are strings like "*3*f*1c", asMutation is a boolean. - - // Sometimes attribute (key,value) pairs are treated as attribute presence - // information, while other times they are treated as operations that - // mutate a set of attributes, and this affects whether an empty value - // is a deletion or a change. - // Examples, of the form (att1Items, att2Items, resultIsMutation) -> result - // ([], [(bold, )], true) -> [(bold, )] - // ([], [(bold, )], false) -> [] - // ([], [(bold, true)], true) -> [(bold, true)] - // ([], [(bold, true)], false) -> [(bold, true)] - // ([(bold, true)], [(bold, )], true) -> [(bold, )] - // ([(bold, true)], [(bold, )], false) -> [] - - // pool can be null if att2 has no attributes. - - if ((! att1) && resultIsMutation) { - // In the case of a mutation (i.e. composing two changesets), - // an att2 composed with an empy att1 is just att2. If att1 - // is part of an attribution string, then att2 may remove - // attributes that are already gone, so don't do this optimization. - return att2; - } - if (! att2) return att1; - var atts = []; - att1.replace(/\*([0-9a-z]+)/g, function(_, a) { - atts.push(pool.getAttrib(Changeset.parseNum(a))); - return ''; - }); - att2.replace(/\*([0-9a-z]+)/g, function(_, a) { - var pair = pool.getAttrib(Changeset.parseNum(a)); - var found = false; - for(var i=0;i<atts.length;i++) { - var oldPair = atts[i]; - if (oldPair[0] == pair[0]) { - if (pair[1] || resultIsMutation) { - oldPair[1] = pair[1]; - } - else { - atts.splice(i, 1); - } - found = true; - break; - } - } - if ((! found) && (pair[1] || resultIsMutation)) { - atts.push(pair); - } - return ''; - }); - atts.sort(); - var buf = Changeset.stringAssembler(); - for(var i=0;i<atts.length;i++) { - buf.append('*'); - buf.append(Changeset.numToString(pool.putAttrib(atts[i]))); - } - //print(att1+" / "+att2+" / "+buf.toString()); - return buf.toString(); -}; - -Changeset._slicerZipperFunc = function(attOp, csOp, opOut, pool) { - // attOp is the op from the sequence that is being operated on, either an - // attribution string or the earlier of two changesets being composed. - // pool can be null if definitely not needed. - - //print(csOp.toSource()+" "+attOp.toSource()+" "+opOut.toSource()); - if (attOp.opcode == '-') { - Changeset.copyOp(attOp, opOut); - attOp.opcode = ''; - } - else if (! attOp.opcode) { - Changeset.copyOp(csOp, opOut); - csOp.opcode = ''; - } - else { - switch (csOp.opcode) { - case '-': { - if (csOp.chars <= attOp.chars) { - // delete or delete part - if (attOp.opcode == '=') { - opOut.opcode = '-'; - opOut.chars = csOp.chars; - opOut.lines = csOp.lines; - opOut.attribs = ''; - } - attOp.chars -= csOp.chars; - attOp.lines -= csOp.lines; - csOp.opcode = ''; - if (! attOp.chars) { - attOp.opcode = ''; - } - } - else { - // delete and keep going - if (attOp.opcode == '=') { - opOut.opcode = '-'; - opOut.chars = attOp.chars; - opOut.lines = attOp.lines; - opOut.attribs = ''; - } - csOp.chars -= attOp.chars; - csOp.lines -= attOp.lines; - attOp.opcode = ''; - } - break; - } - case '+': { - // insert - Changeset.copyOp(csOp, opOut); - csOp.opcode = ''; - break; - } - case '=': { - if (csOp.chars <= attOp.chars) { - // keep or keep part - opOut.opcode = attOp.opcode; - opOut.chars = csOp.chars; - opOut.lines = csOp.lines; - opOut.attribs = Changeset.composeAttributes(attOp.attribs, csOp.attribs, - attOp.opcode == '=', pool); - csOp.opcode = ''; - attOp.chars -= csOp.chars; - attOp.lines -= csOp.lines; - if (! attOp.chars) { - attOp.opcode = ''; - } - } - else { - // keep and keep going - opOut.opcode = attOp.opcode; - opOut.chars = attOp.chars; - opOut.lines = attOp.lines; - opOut.attribs = Changeset.composeAttributes(attOp.attribs, csOp.attribs, - attOp.opcode == '=', pool); - attOp.opcode = ''; - csOp.chars -= attOp.chars; - csOp.lines -= attOp.lines; - } - break; - } - case '': { - Changeset.copyOp(attOp, opOut); - attOp.opcode = ''; - break; - } - } - } -}; - -Changeset.applyToAttribution = function(cs, astr, pool) { - var unpacked = Changeset.unpack(cs); - - return Changeset.applyZip(astr, 0, unpacked.ops, 0, function(op1, op2, opOut) { - return Changeset._slicerZipperFunc(op1, op2, opOut, pool); - }); -}; - -/*Changeset.oneInsertedLineAtATimeOpIterator = function(opsStr, optStartIndex, charBank) { - var iter = Changeset.opIterator(opsStr, optStartIndex); - var bankIndex = 0; - -};*/ - -Changeset.mutateAttributionLines = function(cs, lines, pool) { - //dmesg(cs); - //dmesg(lines.toSource()+" ->"); - - var unpacked = Changeset.unpack(cs); - var csIter = Changeset.opIterator(unpacked.ops); - var csBank = unpacked.charBank; - var csBankIndex = 0; - // treat the attribution lines as text lines, mutating a line at a time - var mut = Changeset.textLinesMutator(lines); - - var lineIter = null; - function isNextMutOp() { - return (lineIter && lineIter.hasNext()) || mut.hasMore(); - } - function nextMutOp(destOp) { - if ((!(lineIter && lineIter.hasNext())) && mut.hasMore()) { - var line = mut.removeLines(1); - lineIter = Changeset.opIterator(line); - } - if (lineIter && lineIter.hasNext()) { - lineIter.next(destOp); - } - else { - destOp.opcode = ''; - } - } - var lineAssem = null; - function outputMutOp(op) { - //print("outputMutOp: "+op.toSource()); - if (! lineAssem) { - lineAssem = Changeset.mergingOpAssembler(); - } - lineAssem.append(op); - if (op.lines > 0) { - Changeset.assert(op.lines == 1, "Can't have op.lines of ",op.lines," in attribution lines"); - // ship it to the mut - mut.insert(lineAssem.toString(), 1); - lineAssem = null; - } - } - - var csOp = Changeset.newOp(); - var attOp = Changeset.newOp(); - var opOut = Changeset.newOp(); - while (csOp.opcode || csIter.hasNext() || attOp.opcode || isNextMutOp()) { - if ((! csOp.opcode) && csIter.hasNext()) { - csIter.next(csOp); - } - //print(csOp.toSource()+" "+attOp.toSource()+" "+opOut.toSource()); - //print(csOp.opcode+"/"+csOp.lines+"/"+csOp.attribs+"/"+lineAssem+"/"+lineIter+"/"+(lineIter?lineIter.hasNext():null)); - //print("csOp: "+csOp.toSource()); - if ((! csOp.opcode) && (! attOp.opcode) && - (! lineAssem) && (! (lineIter && lineIter.hasNext()))) { - break; // done - } - else if (csOp.opcode == '=' && csOp.lines > 0 && (! csOp.attribs) && (! attOp.opcode) && - (! lineAssem) && (! (lineIter && lineIter.hasNext()))) { - // skip multiple lines; this is what makes small changes not order of the document size - mut.skipLines(csOp.lines); - //print("skipped: "+csOp.lines); - csOp.opcode = ''; - } - else if (csOp.opcode == '+') { - if (csOp.lines > 1) { - var firstLineLen = csBank.indexOf('\n', csBankIndex) + 1 - csBankIndex; - Changeset.copyOp(csOp, opOut); - csOp.chars -= firstLineLen; - csOp.lines--; - opOut.lines = 1; - opOut.chars = firstLineLen; - } - else { - Changeset.copyOp(csOp, opOut); - csOp.opcode = ''; - } - outputMutOp(opOut); - csBankIndex += opOut.chars; - opOut.opcode = ''; - } - else { - if ((! attOp.opcode) && isNextMutOp()) { - nextMutOp(attOp); - } - //print("attOp: "+attOp.toSource()); - Changeset._slicerZipperFunc(attOp, csOp, opOut, pool); - if (opOut.opcode) { - outputMutOp(opOut); - opOut.opcode = ''; - } - } - } - - Changeset.assert(! lineAssem, "line assembler not finished"); - mut.close(); - - //dmesg("-> "+lines.toSource()); -}; - -Changeset.joinAttributionLines = function(theAlines) { - var assem = Changeset.mergingOpAssembler(); - for(var i=0;i<theAlines.length;i++) { - var aline = theAlines[i]; - var iter = Changeset.opIterator(aline); - while (iter.hasNext()) { - assem.append(iter.next()); - } - } - return assem.toString(); -}; - -Changeset.splitAttributionLines = function(attrOps, text) { - var iter = Changeset.opIterator(attrOps); - var assem = Changeset.mergingOpAssembler(); - var lines = []; - var pos = 0; - - function appendOp(op) { - assem.append(op); - if (op.lines > 0) { - lines.push(assem.toString()); - assem.clear(); - } - pos += op.chars; - } - - while (iter.hasNext()) { - var op = iter.next(); - var numChars = op.chars; - var numLines = op.lines; - while (numLines > 1) { - var newlineEnd = text.indexOf('\n', pos)+1; - Changeset.assert(newlineEnd > 0, "newlineEnd <= 0 in splitAttributionLines"); - op.chars = newlineEnd - pos; - op.lines = 1; - appendOp(op); - numChars -= op.chars; - numLines -= op.lines; - } - if (numLines == 1) { - op.chars = numChars; - op.lines = 1; - } - appendOp(op); - } - - return lines; -}; - -Changeset.splitTextLines = function(text) { - return text.match(/[^\n]*(?:\n|[^\n]$)/g); -}; - -Changeset.compose = function(cs1, cs2, pool) { - var unpacked1 = Changeset.unpack(cs1); - var unpacked2 = Changeset.unpack(cs2); - var len1 = unpacked1.oldLen; - var len2 = unpacked1.newLen; - Changeset.assert(len2 == unpacked2.oldLen, "mismatched composition"); - var len3 = unpacked2.newLen; - var bankIter1 = Changeset.stringIterator(unpacked1.charBank); - var bankIter2 = Changeset.stringIterator(unpacked2.charBank); - var bankAssem = Changeset.stringAssembler(); - - var newOps = Changeset.applyZip(unpacked1.ops, 0, unpacked2.ops, 0, function(op1, op2, opOut) { - //var debugBuilder = Changeset.stringAssembler(); - //debugBuilder.append(Changeset.opString(op1)); - //debugBuilder.append(','); - //debugBuilder.append(Changeset.opString(op2)); - //debugBuilder.append(' / '); - - var op1code = op1.opcode; - var op2code = op2.opcode; - if (op1code == '+' && op2code == '-') { - bankIter1.skip(Math.min(op1.chars, op2.chars)); - } - Changeset._slicerZipperFunc(op1, op2, opOut, pool); - if (opOut.opcode == '+') { - if (op2code == '+') { - bankAssem.append(bankIter2.take(opOut.chars)); - } - else { - bankAssem.append(bankIter1.take(opOut.chars)); - } - } - - //debugBuilder.append(Changeset.opString(op1)); - //debugBuilder.append(','); - //debugBuilder.append(Changeset.opString(op2)); - //debugBuilder.append(' -> '); - //debugBuilder.append(Changeset.opString(opOut)); - //print(debugBuilder.toString()); - }); - - return Changeset.pack(len1, len3, newOps, bankAssem.toString()); -}; - -Changeset.attributeTester = function(attribPair, pool) { - // returns a function that tests if a string of attributes - // (e.g. *3*4) contains a given attribute key,value that - // is already present in the pool. - if (! pool) { - return never; - } - var attribNum = pool.putAttrib(attribPair, true); - if (attribNum < 0) { - return never; - } - else { - var re = new RegExp('\\*'+Changeset.numToString(attribNum)+ - '(?!\\w)'); - return function(attribs) { - return re.test(attribs); - }; - } - function never(attribs) { return false; } -}; - -Changeset.identity = function(N) { - return Changeset.pack(N, N, "", ""); -}; - -Changeset.makeSplice = function(oldFullText, spliceStart, numRemoved, newText, optNewTextAPairs, pool) { - var oldLen = oldFullText.length; - - if (spliceStart >= oldLen) { - spliceStart = oldLen - 1; - } - if (numRemoved > oldFullText.length - spliceStart - 1) { - numRemoved = oldFullText.length - spliceStart - 1; - } - var oldText = oldFullText.substring(spliceStart, spliceStart+numRemoved); - var newLen = oldLen + newText.length - oldText.length; - - var assem = Changeset.smartOpAssembler(); - assem.appendOpWithText('=', oldFullText.substring(0, spliceStart)); - assem.appendOpWithText('-', oldText); - assem.appendOpWithText('+', newText, optNewTextAPairs, pool); - assem.endDocument(); - return Changeset.pack(oldLen, newLen, assem.toString(), newText); -}; - -Changeset.toSplices = function(cs) { - // get a list of splices, [startChar, endChar, newText] - - var unpacked = Changeset.unpack(cs); - var splices = []; - - var oldPos = 0; - var iter = Changeset.opIterator(unpacked.ops); - var charIter = Changeset.stringIterator(unpacked.charBank); - var inSplice = false; - while (iter.hasNext()) { - var op = iter.next(); - if (op.opcode == '=') { - oldPos += op.chars; - inSplice = false; - } - else { - if (! inSplice) { - splices.push([oldPos, oldPos, ""]); - inSplice = true; - } - if (op.opcode == '-') { - oldPos += op.chars; - splices[splices.length-1][1] += op.chars; - } - else if (op.opcode == '+') { - splices[splices.length-1][2] += charIter.take(op.chars); - } - } - } - - return splices; -}; - -Changeset.characterRangeFollow = function(cs, startChar, endChar, insertionsAfter) { - var newStartChar = startChar; - var newEndChar = endChar; - var splices = Changeset.toSplices(cs); - var lengthChangeSoFar = 0; - for(var i=0;i<splices.length;i++) { - var splice = splices[i]; - var spliceStart = splice[0] + lengthChangeSoFar; - var spliceEnd = splice[1] + lengthChangeSoFar; - var newTextLength = splice[2].length; - var thisLengthChange = newTextLength - (spliceEnd - spliceStart); - - if (spliceStart <= newStartChar && spliceEnd >= newEndChar) { - // splice fully replaces/deletes range - // (also case that handles insertion at a collapsed selection) - if (insertionsAfter) { - newStartChar = newEndChar = spliceStart; - } - else { - newStartChar = newEndChar = spliceStart + newTextLength; - } - } - else if (spliceEnd <= newStartChar) { - // splice is before range - newStartChar += thisLengthChange; - newEndChar += thisLengthChange; - } - else if (spliceStart >= newEndChar) { - // splice is after range - } - else if (spliceStart >= newStartChar && spliceEnd <= newEndChar) { - // splice is inside range - newEndChar += thisLengthChange; - } - else if (spliceEnd < newEndChar) { - // splice overlaps beginning of range - newStartChar = spliceStart + newTextLength; - newEndChar += thisLengthChange; - } - else { - // splice overlaps end of range - newEndChar = spliceStart; - } - - lengthChangeSoFar += thisLengthChange; - } - - return [newStartChar, newEndChar]; -}; - -Changeset.moveOpsToNewPool = function(cs, oldPool, newPool) { - // works on changeset or attribution string - var dollarPos = cs.indexOf('$'); - if (dollarPos < 0) { - dollarPos = cs.length; - } - var upToDollar = cs.substring(0, dollarPos); - var fromDollar = cs.substring(dollarPos); - // order of attribs stays the same - return upToDollar.replace(/\*([0-9a-z]+)/g, function(_, a) { - var oldNum = Changeset.parseNum(a); - var pair = oldPool.getAttrib(oldNum); - var newNum = newPool.putAttrib(pair); - return '*'+Changeset.numToString(newNum); - }) + fromDollar; -}; - -Changeset.makeAttribution = function(text) { - var assem = Changeset.smartOpAssembler(); - assem.appendOpWithText('+', text); - return assem.toString(); -}; - -// callable on a changeset, attribution string, or attribs property of an op -Changeset.eachAttribNumber = function(cs, func) { - var dollarPos = cs.indexOf('$'); - if (dollarPos < 0) { - dollarPos = cs.length; - } - var upToDollar = cs.substring(0, dollarPos); - - upToDollar.replace(/\*([0-9a-z]+)/g, function(_, a) { - func(Changeset.parseNum(a)); - return ''; - }); -}; - -// callable on a changeset, attribution string, or attribs property of an op, -// though it may easily create adjacent ops that can be merged. -Changeset.filterAttribNumbers = function(cs, filter) { - return Changeset.mapAttribNumbers(cs, filter); -}; - -Changeset.mapAttribNumbers = function(cs, func) { - var dollarPos = cs.indexOf('$'); - if (dollarPos < 0) { - dollarPos = cs.length; - } - var upToDollar = cs.substring(0, dollarPos); - - var newUpToDollar = upToDollar.replace(/\*([0-9a-z]+)/g, function(s, a) { - var n = func(Changeset.parseNum(a)); - if (n === true) { - return s; - } - else if ((typeof n) === "number") { - return '*'+Changeset.numToString(n); - } - else { - return ''; - } - }); - - return newUpToDollar + cs.substring(dollarPos); -}; - -Changeset.makeAText = function(text, attribs) { - return { text: text, attribs: (attribs || Changeset.makeAttribution(text)) }; -}; - -Changeset.applyToAText = function(cs, atext, pool) { - return { text: Changeset.applyToText(cs, atext.text), - attribs: Changeset.applyToAttribution(cs, atext.attribs, pool) }; -}; - -Changeset.cloneAText = function(atext) { - return { text: atext.text, attribs: atext.attribs }; -}; - -Changeset.copyAText = function(atext1, atext2) { - atext2.text = atext1.text; - atext2.attribs = atext1.attribs; -}; - -Changeset.appendATextToAssembler = function(atext, assem) { - // intentionally skips last newline char of atext - var iter = Changeset.opIterator(atext.attribs); - var op = Changeset.newOp(); - while (iter.hasNext()) { - iter.next(op); - if (! iter.hasNext()) { - // last op, exclude final newline - if (op.lines <= 1) { - op.lines = 0; - op.chars--; - if (op.chars) { - assem.append(op); - } - } - else { - var nextToLastNewlineEnd = - atext.text.lastIndexOf('\n', atext.text.length-2) + 1; - var lastLineLength = atext.text.length - nextToLastNewlineEnd - 1; - op.lines--; - op.chars -= (lastLineLength + 1); - assem.append(op); - op.lines = 0; - op.chars = lastLineLength; - if (op.chars) { - assem.append(op); - } - } - } - else { - assem.append(op); - } - } -}; - -Changeset.prepareForWire = function(cs, pool) { - var newPool = new AttribPool(); - var newCs = Changeset.moveOpsToNewPool(cs, pool, newPool); - return {translated: newCs, pool: newPool}; -}; - -Changeset.isIdentity = function(cs) { - var unpacked = Changeset.unpack(cs); - return unpacked.ops == "" && unpacked.oldLen == unpacked.newLen; -}; - -Changeset.opAttributeValue = function(op, key, pool) { - return Changeset.attribsAttributeValue(op.attribs, key, pool); -}; - -Changeset.attribsAttributeValue = function(attribs, key, pool) { - var value = ''; - if (attribs) { - Changeset.eachAttribNumber(attribs, function(n) { - if (pool.getAttribKey(n) == key) { - value = pool.getAttribValue(n); - } - }); - } - return value; -}; - -Changeset.builder = function(oldLen) { - var assem = Changeset.smartOpAssembler(); - var o = Changeset.newOp(); - var charBank = Changeset.stringAssembler(); - - var self = { - // attribs are [[key1,value1],[key2,value2],...] or '*0*1...' (no pool needed in latter case) - keep: function(N, L, attribs, pool) { - o.opcode = '='; - o.attribs = (attribs && - Changeset.makeAttribsString('=', attribs, pool)) || ''; - o.chars = N; - o.lines = (L || 0); - assem.append(o); - return self; - }, - keepText: function(text, attribs, pool) { - assem.appendOpWithText('=', text, attribs, pool); - return self; - }, - insert: function(text, attribs, pool) { - assem.appendOpWithText('+', text, attribs, pool); - charBank.append(text); - return self; - }, - remove: function(N, L) { - o.opcode = '-'; - o.attribs = ''; - o.chars = N; - o.lines = (L || 0); - assem.append(o); - return self; - }, - toString: function() { - assem.endDocument(); - var newLen = oldLen + assem.getLengthChange(); - return Changeset.pack(oldLen, newLen, assem.toString(), - charBank.toString()); - } - }; - - return self; -}; - -Changeset.makeAttribsString = function(opcode, attribs, pool) { - // makeAttribsString(opcode, '*3') or makeAttribsString(opcode, [['foo','bar']], myPool) work - if (! attribs) { - return ''; - } - else if ((typeof attribs) == "string") { - return attribs; - } - else if (pool && attribs && attribs.length) { - if (attribs.length > 1) { - attribs = attribs.slice(); - attribs.sort(); - } - var result = []; - for(var i=0;i<attribs.length;i++) { - var pair = attribs[i]; - if (opcode == '=' || (opcode == '+' && pair[1])) { - result.push('*'+Changeset.numToString(pool.putAttrib(pair))); - } - } - return result.join(''); - } -}; - -// like "substring" but on a single-line attribution string -Changeset.subattribution = function(astr, start, optEnd) { - var iter = Changeset.opIterator(astr, 0); - var assem = Changeset.smartOpAssembler(); - var attOp = Changeset.newOp(); - var csOp = Changeset.newOp(); - var opOut = Changeset.newOp(); - - function doCsOp() { - if (csOp.chars) { - while (csOp.opcode && (attOp.opcode || iter.hasNext())) { - if (! attOp.opcode) iter.next(attOp); - - if (csOp.opcode && attOp.opcode && csOp.chars >= attOp.chars && - attOp.lines > 0 && csOp.lines <= 0) { - csOp.lines++; - } - - Changeset._slicerZipperFunc(attOp, csOp, opOut, null); - if (opOut.opcode) { - assem.append(opOut); - opOut.opcode = ''; - } - } - } - } - - csOp.opcode = '-'; - csOp.chars = start; - - doCsOp(); - - if (optEnd === undefined) { - if (attOp.opcode) { - assem.append(attOp); - } - while (iter.hasNext()) { - iter.next(attOp); - assem.append(attOp); - } - } - else { - csOp.opcode = '='; - csOp.chars = optEnd - start; - doCsOp(); - } - - return assem.toString(); -}; - -Changeset.inverse = function(cs, lines, alines, pool) { - // lines and alines are what the changeset is meant to apply to. - // They may be arrays or objects with .get(i) and .length methods. - // They include final newlines on lines. - function lines_get(idx) { - if (lines.get) { - return lines.get(idx); - } - else { - return lines[idx]; - } - } - function lines_length() { - if ((typeof lines.length) == "number") { - return lines.length; - } - else { - return lines.length(); - } - } - function alines_get(idx) { - if (alines.get) { - return alines.get(idx); - } - else { - return alines[idx]; - } - } - function alines_length() { - if ((typeof alines.length) == "number") { - return alines.length; - } - else { - return alines.length(); - } - } - - var curLine = 0; - var curChar = 0; - var curLineOpIter = null; - var curLineOpIterLine; - var curLineNextOp = Changeset.newOp('+'); - - var unpacked = Changeset.unpack(cs); - var csIter = Changeset.opIterator(unpacked.ops); - var builder = Changeset.builder(unpacked.newLen); - - function consumeAttribRuns(numChars, func/*(len, attribs, endsLine)*/) { - - if ((! curLineOpIter) || (curLineOpIterLine != curLine)) { - // create curLineOpIter and advance it to curChar - curLineOpIter = Changeset.opIterator(alines_get(curLine)); - curLineOpIterLine = curLine; - var indexIntoLine = 0; - var done = false; - while (! done) { - curLineOpIter.next(curLineNextOp); - if (indexIntoLine + curLineNextOp.chars >= curChar) { - curLineNextOp.chars -= (curChar - indexIntoLine); - done = true; - } - else { - indexIntoLine += curLineNextOp.chars; - } - } - } - - while (numChars > 0) { - if ((! curLineNextOp.chars) && (! curLineOpIter.hasNext())) { - curLine++; - curChar = 0; - curLineOpIterLine = curLine; - curLineNextOp.chars = 0; - curLineOpIter = Changeset.opIterator(alines_get(curLine)); - } - if (! curLineNextOp.chars) { - curLineOpIter.next(curLineNextOp); - } - var charsToUse = Math.min(numChars, curLineNextOp.chars); - func(charsToUse, curLineNextOp.attribs, - charsToUse == curLineNextOp.chars && curLineNextOp.lines > 0); - numChars -= charsToUse; - curLineNextOp.chars -= charsToUse; - curChar += charsToUse; - } - - if ((! curLineNextOp.chars) && (! curLineOpIter.hasNext())) { - curLine++; - curChar = 0; - } - } - - function skip(N, L) { - if (L) { - curLine += L; - curChar = 0; - } - else { - if (curLineOpIter && curLineOpIterLine == curLine) { - consumeAttribRuns(N, function() {}); - } - else { - curChar += N; - } - } - } - - function nextText(numChars) { - var len = 0; - var assem = Changeset.stringAssembler(); - var firstString = lines_get(curLine).substring(curChar); - len += firstString.length; - assem.append(firstString); - - var lineNum = curLine+1; - while (len < numChars) { - var nextString = lines_get(lineNum); - len += nextString.length; - assem.append(nextString); - lineNum++; - } - - return assem.toString().substring(0, numChars); - } - - function cachedStrFunc(func) { - var cache = {}; - return function(s) { - if (! cache[s]) { - cache[s] = func(s); - } - return cache[s]; - }; - } - - var attribKeys = []; - var attribValues = []; - while (csIter.hasNext()) { - var csOp = csIter.next(); - if (csOp.opcode == '=') { - if (csOp.attribs) { - attribKeys.length = 0; - attribValues.length = 0; - Changeset.eachAttribNumber(csOp.attribs, function(n) { - attribKeys.push(pool.getAttribKey(n)); - attribValues.push(pool.getAttribValue(n)); - }); - var undoBackToAttribs = cachedStrFunc(function(attribs) { - var backAttribs = []; - for(var i=0;i<attribKeys.length;i++) { - var appliedKey = attribKeys[i]; - var appliedValue = attribValues[i]; - var oldValue = Changeset.attribsAttributeValue(attribs, appliedKey, pool); - if (appliedValue != oldValue) { - backAttribs.push([appliedKey, oldValue]); - } - } - return Changeset.makeAttribsString('=', backAttribs, pool); - }); - consumeAttribRuns(csOp.chars, function(len, attribs, endsLine) { - builder.keep(len, endsLine ? 1 : 0, undoBackToAttribs(attribs)); - }); - } - else { - skip(csOp.chars, csOp.lines); - builder.keep(csOp.chars, csOp.lines); - } - } - else if (csOp.opcode == '+') { - builder.remove(csOp.chars, csOp.lines); - } - else if (csOp.opcode == '-') { - var textBank = nextText(csOp.chars); - var textBankIndex = 0; - consumeAttribRuns(csOp.chars, function(len, attribs, endsLine) { - builder.insert(textBank.substr(textBankIndex, len), attribs); - textBankIndex += len; - }); - } - } - - return Changeset.checkRep(builder.toString()); -}; diff --git a/etherpad/src/static/js/linestylefilter_client.js b/etherpad/src/static/js/linestylefilter_client.js deleted file mode 100644 index df35c3c..0000000 --- a/etherpad/src/static/js/linestylefilter_client.js +++ /dev/null @@ -1,246 +0,0 @@ -// DO NOT EDIT THIS FILE, edit infrastructure/ace/www/linestylefilter.js - -/** - * Copyright 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// requires: easysync2.Changeset - -var linestylefilter = {}; - -linestylefilter.ATTRIB_CLASSES = { - 'bold':'tag:b', - 'italic':'tag:i', - 'underline':'tag:u', - 'strikethrough':'tag:s' -}; - -linestylefilter.getAuthorClassName = function(author) { - return "author-"+author.replace(/[^a-y0-9]/g, function(c) { - if (c == ".") return "-"; - return 'z'+c.charCodeAt(0)+'z'; - }); -}; - -// lineLength is without newline; aline includes newline, -// but may be falsy if lineLength == 0 -linestylefilter.getLineStyleFilter = function(lineLength, aline, - textAndClassFunc, apool) { - - if (lineLength == 0) return textAndClassFunc; - - var nextAfterAuthorColors = textAndClassFunc; - - var authorColorFunc = (function() { - var lineEnd = lineLength; - var curIndex = 0; - var extraClasses; - var leftInAuthor; - - function attribsToClasses(attribs) { - var classes = ''; - Changeset.eachAttribNumber(attribs, function(n) { - var key = apool.getAttribKey(n); - if (key) { - var value = apool.getAttribValue(n); - if (value) { - if (key == 'author') { - classes += ' '+linestylefilter.getAuthorClassName(value); - } - else if (key == 'list') { - classes += ' list:'+value; - } - else if (linestylefilter.ATTRIB_CLASSES[key]) { - classes += ' '+linestylefilter.ATTRIB_CLASSES[key]; - } - } - } - }); - return classes.substring(1); - } - - var attributionIter = Changeset.opIterator(aline); - var nextOp, nextOpClasses; - function goNextOp() { - nextOp = attributionIter.next(); - nextOpClasses = (nextOp.opcode && attribsToClasses(nextOp.attribs)); - } - goNextOp(); - function nextClasses() { - if (curIndex < lineEnd) { - extraClasses = nextOpClasses; - leftInAuthor = nextOp.chars; - goNextOp(); - while (nextOp.opcode && nextOpClasses == extraClasses) { - leftInAuthor += nextOp.chars; - goNextOp(); - } - } - } - nextClasses(); - - return function(txt, cls) { - while (txt.length > 0) { - if (leftInAuthor <= 0) { - // prevent infinite loop if something funny's going on - return nextAfterAuthorColors(txt, cls); - } - var spanSize = txt.length; - if (spanSize > leftInAuthor) { - spanSize = leftInAuthor; - } - var curTxt = txt.substring(0, spanSize); - txt = txt.substring(spanSize); - nextAfterAuthorColors(curTxt, (cls&&cls+" ")+extraClasses); - curIndex += spanSize; - leftInAuthor -= spanSize; - if (leftInAuthor == 0) { - nextClasses(); - } - } - }; - })(); - return authorColorFunc; -}; - -linestylefilter.getAtSignSplitterFilter = function(lineText, - textAndClassFunc) { - var at = /@/g; - at.lastIndex = 0; - var splitPoints = null; - var execResult; - while ((execResult = at.exec(lineText))) { - if (! splitPoints) { - splitPoints = []; - } - splitPoints.push(execResult.index); - } - - if (! splitPoints) return textAndClassFunc; - - return linestylefilter.textAndClassFuncSplitter(textAndClassFunc, - splitPoints); -}; - -linestylefilter.REGEX_WORDCHAR = /[\u0030-\u0039\u0041-\u005A\u0061-\u007A\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u0100-\u1FFF\u3040-\u9FFF\uF900-\uFDFF\uFE70-\uFEFE\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFDC]/; -linestylefilter.REGEX_URLCHAR = new RegExp('('+/[-:@a-zA-Z0-9_.,~%+\/\\?=&#;()$]/.source+'|'+linestylefilter.REGEX_WORDCHAR.source+')'); -linestylefilter.REGEX_URL = new RegExp(/(?:(?:https?|s?ftp|ftps|file|smb|afp|nfs|(x-)?man|gopher|txmt):\/\/|mailto:)/.source+linestylefilter.REGEX_URLCHAR.source+'*(?![:.,;])'+linestylefilter.REGEX_URLCHAR.source, 'g'); - -linestylefilter.getURLFilter = function(lineText, textAndClassFunc) { - linestylefilter.REGEX_URL.lastIndex = 0; - var urls = null; - var splitPoints = null; - var execResult; - while ((execResult = linestylefilter.REGEX_URL.exec(lineText))) { - if (! urls) { - urls = []; - splitPoints = []; - } - var startIndex = execResult.index; - var url = execResult[0]; - urls.push([startIndex, url]); - splitPoints.push(startIndex, startIndex + url.length); - } - - if (! urls) return textAndClassFunc; - - function urlForIndex(idx) { - for(var k=0; k<urls.length; k++) { - var u = urls[k]; - if (idx >= u[0] && idx < u[0]+u[1].length) { - return u[1]; - } - } - return false; - } - - var handleUrlsAfterSplit = (function() { - var curIndex = 0; - return function(txt, cls) { - var txtlen = txt.length; - var newCls = cls; - var url = urlForIndex(curIndex); - if (url) { - newCls += " url:"+url; - } - textAndClassFunc(txt, newCls); - curIndex += txtlen; - }; - })(); - - return linestylefilter.textAndClassFuncSplitter(handleUrlsAfterSplit, - splitPoints); -}; - -linestylefilter.textAndClassFuncSplitter = function(func, splitPointsOpt) { - var nextPointIndex = 0; - var idx = 0; - - // don't split at 0 - while (splitPointsOpt && - nextPointIndex < splitPointsOpt.length && - splitPointsOpt[nextPointIndex] == 0) { - nextPointIndex++; - } - - function spanHandler(txt, cls) { - if ((! splitPointsOpt) || nextPointIndex >= splitPointsOpt.length) { - func(txt, cls); - idx += txt.length; - } - else { - var splitPoints = splitPointsOpt; - var pointLocInSpan = splitPoints[nextPointIndex] - idx; - var txtlen = txt.length; - if (pointLocInSpan >= txtlen) { - func(txt, cls); - idx += txt.length; - if (pointLocInSpan == txtlen) { - nextPointIndex++; - } - } - else { - if (pointLocInSpan > 0) { - func(txt.substring(0, pointLocInSpan), cls); - idx += pointLocInSpan; - } - nextPointIndex++; - // recurse - spanHandler(txt.substring(pointLocInSpan), cls); - } - } - } - return spanHandler; -}; - -// domLineObj is like that returned by domline.createDomLine -linestylefilter.populateDomLine = function(textLine, aline, apool, - domLineObj) { - // remove final newline from text if any - var text = textLine; - if (text.slice(-1) == '\n') { - text = text.substring(0, text.length-1); - } - - function textAndClassFunc(tokenText, tokenClass) { - domLineObj.appendSpan(tokenText, tokenClass); - } - - var func = textAndClassFunc; - func = linestylefilter.getURLFilter(text, func); - func = linestylefilter.getLineStyleFilter(text.length, aline, - func, apool); - func(text, ''); -}; |