bespin.tiki.register("::text_editor",{name:"text_editor",dependencies:{undomanager:"0.0.0",settings:"0.0.0",canon:"0.0.0",rangeutils:"0.0.0",traits:"0.0.0",theme_manager:"0.0.0",keyboard:"0.0.0",edit_session:"0.0.0",syntax_manager:"0.0.0"}});
bespin.tiki.module("text_editor:commands/editing",function(q,k){var l=q("settings").settings,j=q("rangeutils:utils/range");k.backspace=function(d){d.view.performBackspaceOrDelete(true)};k.deleteCommand=function(d){d.view.performBackspaceOrDelete(false)};k.deleteLines=function(d){if(!d.model.readOnly)if(d.model.lines.length!=1){var b=d.view;b.groupChanges(function(){var a=b.getSelectedRange(),i=d.model.lines,e=i.length-1,g;g=a.start.row==e?{col:i[e-1].length,row:e-1}:{col:0,row:a.start.row};b.replaceCharacters({start:g,
end:a.end.row==e?{col:i[e].length,row:e}:{col:0,row:a.end.row+1}},"");b.moveCursorTo(g)})}};var h=function(d,b){var a=b.getSelectedRange().start;d=/^\s*/.exec(d.lines[a.row].substring(0,a.col));b.insertText("\n"+d)};k.insertText=function(d,b){d.view.insertText(b.text)};k.newline=function(d){h(d.model,d.view)};k.joinLines=function(d){var b=d.model;if(!b.readOnly){var a=d.view;d=a.getSelectedRange();var i=b.lines,e=d.end.row;i.length!=e&&a.groupChanges(function(){a.replaceCharacters({start:{col:i[e].length,
row:e},end:{col:/^\s*/.exec(i[e+1])[0].length,row:e+1}},"")})}};k.openLine=function(d){if(!d.model.readOnly){var b=d.model;d=d.view;var a=d.getSelectedRange().end.row;d.moveCursorTo({row:a,col:b.lines[a].length});h(b,d)}};k.tab=function(d){var b=d.view;b.groupChanges(function(){var a=l.get("tabstop"),i=b.getSelectedRange(),e="";if(j.isZeroLength(i)){var g=d.model.lines[i.start.row].substring(i.start.col).match(/^\s*/)[0].length;a=a-(i.start.col+g)%a;for(var o=0;o<a;o++)e+=" ";b.replaceCharacters({start:i.start,
end:i.start},e);b.moveCursorTo({col:i.start.col+a+g,row:i.end.row})}else{for(o=0;o<a;o++)e+=" ";for(o=i.start.row-1;o++<i.end.row;){g=o==i.start.row?i.start.col:0;b.replaceCharacters({start:{row:o,col:g},end:{row:o,col:g}},e)}b.setSelection({start:i.start,end:{col:i.end.col+a,row:i.end.row}})}}.bind(this))};k.untab=function(d){var b=d.view;b.groupChanges(function(){var a=l.get("tabstop"),i=b.getSelectedRange(),e=d.model.lines,g=0;if(j.isZeroLength(i)){g=Math.min(e[i.start.row].substring(0,i.start.col).match(/\s*$/)[0].length,
(i.start.col-a)%a||a);b.replaceCharacters({start:{col:i.start.col-g,row:i.start.row},end:i.start},"");b.moveCursorTo({row:i.start.row,col:i.end.col-g})}else{for(var o,f=i.start.row-1;f++<i.end.row;){o=f==i.start.row?i.start.col:0;g=Math.min(e[f].substring(o).match(/^\s*/)[0].length,a);b.replaceCharacters({start:{row:f,col:o},end:{row:f,col:o+g}},"")}b.setSelection({start:{row:i.start.row,col:i.start.col},end:{row:i.end.row,col:i.end.col-g}})}}.bind(this))}});
bespin.tiki.module("text_editor:commands/editor",function(q,k){q("bespin:plugins");var l=q("settings").settings;k.findCommand=function(h,d,b){if("value"in d){h=h.view;var a=h.editor.searchController,i=h.getSelectedRange(),e="";a.setSearchText(d.value,false);if(a=a.findNext(i.end,true)){h.setSelection(a,true);h.focus()}else e+="<i>No matches found</i><br>";e+='Searching for "'+d.value+'"';b.done(e)}else h.commandLine.setInput("find ")};k.findNextCommand=function(h){h=h.view;var d=h.editor.searchController,
b=h.getSelectedRange();if(d=d.findNext(b.end,true)){h.setSelection(d,true);h.focus()}};k.findPrevCommand=function(h){h=h.view;var d=h.editor.searchController,b=h.getSelectedRange();if(d=d.findPrevious(b.start,true)){h.setSelection(d,true);h.focus()}};k.gotoCommand=function(h,d){if("line"in d){h=h.view;h.moveCursorTo({row:d.line-1,col:0});h.focus()}else h.commandLine.setInput("goto ")};var j=function(h,d){var b=h.view,a=b.getSelectedCharacters();d=d(a);b=b.getSelectedRange();h.model.replaceCharacters(b,
d)};k.replaceCommand=function(h,d){j(h,function(b){return b.replace(d.search+"/g",d.replace)})};k.entabCommand=function(h){tabstop=l.get("tabstop");j(h,function(d){return d.replace(" {"+tabstop+"}","\t")})};k.detabCommand=function(h){tabstop=l.get("tabstop");j(h,function(d){return d.replace("\t",(new Array(tabstop+1)).join(" "))})};k.trimCommand=function(h,d){j(h,function(b){b=b.split("\n");b=b.map(function(a){if(d.side==="left"||d.side==="both")a=a.replace(/^\s+/,"");if(d.side==="right"||d.side===
"both")a=a.replace(/\s+$/,"");return a});return b.join("\n")})};k.ucCommand=function(h){j(h,function(d){return d.toUpperCase()})};k.lcCommand=function(h){j(h,function(d){return d.toLowerCase()})}});
bespin.tiki.module("text_editor:commands/movement",function(q,k){q("rangeutils:utils/range");k.moveDown=function(a){a.view.moveDown()};k.moveLeft=function(a){a.view.moveLeft()};k.moveRight=function(a){a.view.moveRight()};k.moveUp=function(a){a.view.moveUp()};k.selectDown=function(a){a.view.selectDown()};k.selectLeft=function(a){a.view.selectLeft()};k.selectRight=function(a){a.view.selectRight()};k.selectUp=function(a){a.view.selectUp()};var l=function(a,i,e){var g=a.view;a=a.model.lines;var o=g.getSelectedRange(true);
e=e?o.end.row:a.length-1;g.moveCursorTo({row:e,col:a[e].length},i)};k.moveLineEnd=function(a){l(a,false,true)};k.selectLineEnd=function(a){l(a,true,true)};k.moveDocEnd=function(a){l(a,false,false)};k.selectDocEnd=function(a){l(a,true,false)};var j=function(a,i,e){a=a.view;var g=a.getSelectedRange(true);a.moveCursorTo({row:e?g.end.row:0,col:0},i)};k.moveLineStart=function(a){j(a,false,true)};k.selectLineStart=function(a){j(a,true,true)};k.moveDocStart=function(a){j(a,false,false)};k.selectDocStart=
function(a){j(a,true,false)};var h=function(a,i,e,g,o){var f=0,m=false;if(g<0){e--;if(o)f=1}for(;e<i.length&&e>-1;){if(o=a.isDelimiter(i[e]))f++;else m=true;if((o||f>1)&&m)break;e+=g}g<0&&e++;return e},d=function(a,i){var e=a.view;a=a.model.lines;var g=e.getSelectedRange(true).end,o=g.row;g=g.col;var f=a[o],m=false;if(g>=f.length){o++;m=true;if(o<a.length){g=0;f=a[o]}else f=""}g=h(e,f,g,1,m);e.moveCursorTo({row:o,col:g},i)},b=function(a,i){var e=a.view;a=a.model.lines;var g=e.getSelectedRange(true).end,
o=g.row;g=g.col;var f=a[o],m=false;if(g>f.length)g=f.length;else if(g==0){o--;m=true;if(o>-1){f=a[o];g=f.length}else f=""}g=h(e,f,g,-1,m);e.moveCursorTo({row:o,col:g},i)};k.moveNextWord=function(a){d(a,false)};k.selectNextWord=function(a){d(a,true)};k.movePreviousWord=function(a){b(a,false)};k.selectPreviousWord=function(a){b(a,true)};k.selectAll=function(a){a.view.selectAll()}});
bespin.tiki.module("text_editor:commands/scrolling",function(q,k){k.scrollDocStart=function(l){l.view.scrollToPosition({col:0,row:0})};k.scrollDocEnd=function(l){l.view.scrollToPosition(l.model.range.end)};k.scrollPageDown=function(l){l.view.scrollPageDown()};k.scrollPageUp=function(l){l.view.scrollPageUp()}});
bespin.tiki.module("text_editor:controllers/layoutmanager",function(q,k){var l=q("bespin:util/util"),j=q("events").Event;q("rangeutils:utils/range");var h=q("syntax_manager").SyntaxManager,d=q("models/textstorage").TextStorage,b=q("bespin:plugins").catalog,a=q("settings").settings,i=q("bespin:util/scratchcanvas"),e={};q=function(){var g=a.get("fontsize"),o=a.get("fontface");o=g+"px "+o;for(var f=i.get(),m="",s=0;s<100;s++)m+="M";o=f.measureStringWidth(o,m)/100;e.characterWidth=o;e.lineHeight=Math.floor(g*
1.6);e.lineAscent=Math.floor(g*1.3)};q();b.registerExtension("settingChange",{match:"font[size|face]",pointer:q});k.LayoutManager=function(g){this.changedTextAtRow=new j;this.invalidatedRects=new j;this.fontDimension=e;if(g.textStorage){g._textStorage=g.textStorage;delete g.textStorage}else this._textStorage=new d;l.mixin(this,g);this._textStorage.changed.add(this.textStorageChanged.bind(this));this.textLines=[{characters:"",colors:[{start:0,end:0,color:"plain"}]}];this.syntaxManager=g=new h(this);
g.syntaxChanged.add(this._syntaxChanged.bind(this));this._size={width:0,height:0};this.sizeChanged=new j;this._height=0;this._recomputeEntireLayout()};k.LayoutManager.prototype={_maximumWidth:0,_textStorage:null,_size:null,sizeChanged:null,_theme:{},margin:{left:5,bottom:6,top:0,right:12},pluginCatalog:b,syntaxManager:null,textLines:null,_computeInvalidRects:function(g,o){var f=this.characterRectForPosition(g.start),m={x:f.x,y:f.y,width:Number.MAX_VALUE,height:f.height};return g.end.row===o.end.row?
[m]:[m,{x:0,y:f.y+e.lineHeight,width:Number.MAX_VALUE,height:Number.MAX_VALUE}]},_lastCharacterPosition:function(){return{row:this.textLines.length-1,col:this._maximumWidth}},_recalculateMaximumWidth:function(){var g=0;this.textLines.forEach(function(o){o=o.characters.length;if(g<o)g=o});this._maximumWidth=g;this.size={width:g,height:this.textLines.length}},_recomputeEntireLayout:function(){var g=this._textStorage.range;this._recomputeLayoutForRanges(g,g)},_recomputeLayoutForRanges:function(g,o){for(var f=
g.start.row,m=g.end.row,s=o.end.row,n=s-f+1,t=this._textStorage.lines,u=this._theme.plain,w=[],p=0;p<n;p++)w[p]={characters:t[f+p],colors:[{start:0,end:null,color:u}]};this.textLines=l.replace(this.textLines,f,m-f+1,w);this._recalculateMaximumWidth();m=this.textLines.length;n=this.syntaxManager;if(this._height!==m)this._height=m;n.invalidateRow(f);this.updateTextRows(f,s+1);this.changedTextAtRow(this,f);this.invalidatedRects(this,this._computeInvalidRects(g,o))},_syntaxChanged:function(g,o){this.updateTextRows(g,
o);this.invalidatedRects(this,this.rectsForRange({start:{row:g,col:0},end:{row:o,col:0}}))},boundingRect:function(){return this.rectsForRange({start:{row:0,col:0},end:{row:this.textLines.length-1,col:this._maximumWidth}})[0]},characterAtPoint:function(g){var o=this.margin,f=g.x-o.left,m=e.characterWidth,s=this._textStorage;g=s.clampPosition({row:Math.floor((g.y-o.top)/e.lineHeight),col:Math.floor(f/m)});s=s.lines[g.row].length;g.partialFraction=f<0||g.col===s?0:f%m/m;return g},characterRangeForBoundingRect:function(g){var o=
e.lineHeight,f=e.characterWidth,m=this.margin,s=g.x-m.left;m=g.y-m.top;return{start:{row:Math.max(Math.floor(m/o),0),col:Math.max(Math.floor(s/f),0)},end:{row:Math.floor((m+g.height-1)/o),col:Math.floor((s+g.width-1)/f)+1}}},characterRectForPosition:function(g){return this.rectsForRange({start:g,end:{row:g.row,col:g.col+1}})[0]},lineRectForRow:function(g){return this.rectsForRange({start:{row:g,col:0},end:{row:g,col:this._maximumWidth}})[0]},rectForPosition:function(g){var o=this.margin,f=e.characterWidth,
m=e.lineHeight;return{x:o.left+f*g.col,y:o.top+m*g.row,width:f,height:m}},rectsForRange:function(g){var o=e.characterWidth,f=e.lineHeight,m=this._maximumWidth,s=this.margin,n=g.start,t=g.end;g=n.row;var u=n.col;n=t.row;t=t.col;if(g===n)return[{x:s.left+o*u,y:s.top+f*g,width:o*(t-u),height:f}];var w=[],p;if(u===0)p=g;else{p=g+1;w.push({x:s.left+o*u,y:s.top+f*g,width:99999,height:f})}if(t===0)m=n-1;else if(t===m)m=n;else{m=n-1;w.push({x:s.left,y:s.top+f*n,width:o*t,height:f})}w.push({x:s.left,y:s.top+
f*p,width:99999,height:f*(m-p+1)});return w},textStorageChanged:function(g,o){this._recomputeLayoutForRanges(g,o)},updateTextRows:function(g,o){var f=this.textLines;o=this.syntaxManager.getAttrsForRows(g,o);for(var m=0;m<o.length;m++)f[g+m].colors=o[m]}};Object.defineProperties(k.LayoutManager.prototype,{size:{set:function(g){if(g.width!==this._size.width||g.height!==this._size.height){this.sizeChanged(g);this._size=g}},get:function(){return this._size}},textStorage:{get:function(){return this._textStorage}}})});
bespin.tiki.module("text_editor:controllers/search",function(q,k){var l=q("bespin:util/util");q("rangeutils:utils/range");q("bespin:console");k.EditorSearchController=function(j){this.editor=j};k.EditorSearchController.prototype={editor:null,_escapeString:/(\/|\.|\*|\+|\?|\||\(|\)|\[|\]|\{|\}|\\)/g,_findMatchesInString:function(j){var h=[],d=this.searchRegExp,b;for(d.lastIndex=0;;){b=d.exec(j);if(b===null)break;h.push(b);d.lastIndex=b.index+b[0].length}return h},_makeRange:function(j,h){return{start:{row:h,
col:j.index},end:{row:h,col:j.index+j[0].length}}},isRegExp:null,searchRegExp:null,searchText:null,setSearchText:function(j,h){this.searchRegExp=h?new RegExp(j):new RegExp(j.replace(this._escapeString,"\\$1"),"gi");this.isRegExp=h;this.searchText=j},findNext:function(j,h){var d=this.searchRegExp;if(l.none(d))return null;j=j||this.editor.textView.getSelectedRange().end;var b=this.editor.layoutManager.textStorage.lines,a;d.lastIndex=j.col;var i;for(i=j.row;i<b.length;i++){a=d.exec(b[i]);if(!l.none(a))return this._makeRange(a,
i)}if(!h)return null;for(i=0;i<=j.row;i++){a=d.exec(b[i]);if(!l.none(a))return this._makeRange(a,i)}return null},findPrevious:function(j,h){if(l.none(this.searchRegExp))return null;j=j||this.editor.textView.getSelectedRange().start;var d=this.editor.buffer.layoutManager.textStorage.lines,b;b=this._findMatchesInString(d[j.row].substring(0,j.col));if(b.length!==0)return this._makeRange(b[b.length-1],j.row);var a;for(a=j.row-1;a!==-1;a--){b=this._findMatchesInString(d[a]);if(b.length!==0)return this._makeRange(b[b.length-
1],a)}if(!h)return null;for(a=d.length-1;a>=j.row;a--){b=this._findMatchesInString(d[a]);if(b.length!==0)return this._makeRange(b[b.length-1],a)}return null}}});
bespin.tiki.module("text_editor:controllers/undo",function(q,k){var l=q("bespin:console").console;k.EditorUndoController=function(j){this.editor=j;j=this.textView=j.textView;j.beganChangeGroup.add(function(h,d){this._beginTransaction();this._record.selectionBefore=d}.bind(this));j.endedChangeGroup.add(function(h,d){this._record.selectionAfter=d;this._endTransaction()}.bind(this));j.replacedCharacters.add(function(h,d,b){if(!this._inTransaction)throw new Error("UndoController.textViewReplacedCharacters() called outside a transaction");
this._record.patches.push({oldCharacters:this._deletedCharacters,oldRange:d,newCharacters:b,newRange:this.editor.layoutManager.textStorage.resultingRangeForReplacement(d,b.split("\n"))});this._deletedCharacters=null}.bind(this));j.willReplaceRange.add(function(h,d){if(!this._inTransaction)throw new Error("UndoController.textViewWillReplaceRange() called outside a transaction");this._deletedCharacters=this.editor.layoutManager.textStorage.getCharacters(d)}.bind(this))};k.EditorUndoController.prototype=
{_inTransaction:false,_record:null,textView:null,_beginTransaction:function(){if(this._inTransaction){l.trace();throw new Error("UndoController._beginTransaction() called with a transaction already in place");}this._inTransaction=true;this._record={patches:[]}},_endTransaction:function(){if(!this._inTransaction)throw new Error("UndoController._endTransaction() called without a transaction in place");this.editor.buffer.undoManager.registerUndo(this,this._record);this._record=null;this._inTransaction=
false},_tryApplyingPatches:function(j){var h=this.editor.layoutManager.textStorage;j.forEach(function(d){h.replaceCharacters(d.oldRange,d.newCharacters)});return true},_undoOrRedo:function(j,h){if(this._inTransaction)throw new Error("UndoController._undoOrRedo() called while in a transaction");if(!this._tryApplyingPatches(j))return false;this.textView.setSelection(h,true);return true},redo:function(j){var h=j.patches.concat();h.reverse();return this._undoOrRedo(h,j.selectionAfter)},undo:function(j){return this._undoOrRedo(j.patches.map(function(h){return{oldCharacters:h.newCharacters,
oldRange:h.newRange,newCharacters:h.oldCharacters,newRange:h.oldRange}}),j.selectionBefore)}};k.undoManagerCommand=function(j,h,d){j.editor.buffer.undoManager[d.commandExt.name]()}});
bespin.tiki.module("text_editor:models/buffer",function(q,k){var l=q("canon:environment").global,j=q("bespin:util/util"),h=q("bespin:promise").Promise,d=q("models/textstorage").TextStorage,b=q("controllers/layoutmanager").LayoutManager,a=q("undomanager").UndoManager;k.Buffer=function(i,e){this._file=i;this._model=new d(e);this._layoutManager=new b({textStorage:this._model});this.undoManager=new a;if(i)this.reload().then(function(){this._updateSyntaxManagerInitialContext()}.bind(this));else{this.loadPromise=
new h;this.loadPromise.resolve()}e=l.session?l.session.history:null;var g,o,f;if(e&&i&&(g=e.getHistoryForPath(i.path))){o=g.selection;f=g.scroll}this._selectedRange=o||{start:{row:0,col:0},end:{row:0,col:0}};this._scrollOffset=f||{x:0,y:0}};k.Buffer.prototype={undoManager:null,loadPromise:null,_scrollOffset:null,_selectedRange:null,_selectedRangeEndVirtual:null,_layoutManager:null,_file:null,_model:null,save:function(){return this._file.saveContents(this._model.value)},saveAs:function(i){var e=new h;
i.saveContents(this._model.value).then(function(){this._file=i;this._updateSyntaxManagerInitialContext();e.resolve()}.bind(this),function(g){e.reject(g)});return e},reload:function(){var i=this,e;return this.loadPromise=e=this._file.loadContents().then(function(g){i._model.value=g})},_updateSyntaxManagerInitialContext:function(){var i=this._file.extension();this._layoutManager.syntaxManager.setSyntaxFromFileExt(i===null?"":i)},untitled:function(){return j.none(this._file)}};Object.defineProperties(k.Buffer.prototype,
{layoutManager:{get:function(){return this._layoutManager}},syntaxManager:{get:function(){}},file:{get:function(){return this._file}},model:{get:function(){return this._model}}})});
bespin.tiki.module("text_editor:models/textstorage",function(q,k){var l=q("events").Event,j=q("bespin:util/util");q=function(h){this._lines=h!==null&&h!==undefined?h.split("\n"):[""];this.changed=new l;return this};q.prototype={_lines:null,readOnly:false,clampPosition:function(h){var d=this._lines,b=h.row;if(b<0)return{row:0,col:0};else if(b>=d.length)return this.range.end;h=Math.max(0,Math.min(h.col,d[b].length));return{row:b,col:h}},clampRange:function(h){var d=this.clampPosition(h.start);h=this.clampPosition(h.end);
return{start:d,end:h}},deleteCharacters:function(h){this.replaceCharacters(h,"")},displacePosition:function(h,d){var b=d>0,a=this._lines,i=a.length;for(d=Math.abs(d);d!==0;d--)if(b){var e=a[h.row].length;if(h.row===i-1&&h.col===e)return h;h=h.col===e?{row:h.row+1,col:0}:{row:h.row,col:h.col+1}}else{if(h.row===0&&h.col==0)return h;if(h.col===0){a=this._lines;h={row:h.row-1,col:a[h.row-1].length}}else h={row:h.row,col:h.col-1}}return h},getCharacters:function(h){var d=this._lines,b=h.start,a=h.end,
i=b.row;h=a.row;var e=b.col;b=a.col;if(i===h)return d[i].substring(e,b);a=d[i].substring(e);i=d.slice(i+1,h);d=d[h].substring(0,b);return[a].concat(i,d).join("\n")},getLines:function(){return this._lines},getRange:function(){var h=this._lines,d=h.length-1;return{start:{row:0,col:0},end:{row:d,col:h[d].length}}},getValue:function(){return this._lines.join("\n")},insertCharacters:function(h,d){this.replaceCharacters({start:h,end:h},d)},replaceCharacters:function(h,d){if(this.readOnly)throw new Error("Attempt to modify a read-only text storage object");
var b=d.split("\n"),a=b.length,i=this.resultingRangeForReplacement(h,b),e=h.start,g=h.end,o=e.row,f=g.row,m=this._lines;b[0]=m[o].substring(0,e.col)+b[0];b[a-1]+=m[f].substring(g.col);this._lines=j.replace(m,o,f-o+1,b);this.changed(h,i,d)},resultingRangeForReplacement:function(h,d){var b=d.length;h=h.start;return{start:h,end:{row:h.row+b-1,col:(b===1?h.col:0)+d[b-1].length}}},setLines:function(h){this.setValue(h.join("\n"))},setValue:function(h){this.replaceCharacters(this.range,h)}};k.TextStorage=
q;Object.defineProperties(k.TextStorage.prototype,{lines:{get:function(){return this.getLines()},set:function(h){return this.setLines(h)}},range:{get:function(){return this.getRange()}},value:{get:function(){return this.getValue()},set:function(h){this.setValue(h)}}})});
bespin.tiki.module("text_editor:utils/rect",function(q,k){k._distanceFromBounds=function(l,j,h){if(l<j)return l-j;if(l>=h)return l-h;return 0};k.merge=function(l){var j;do{j=false;for(var h=[],d=0;d<l.length;d++){var b=l[d];h.push(b);for(var a=d+1;a<l.length;a++){var i=l[a];if(k.rectsSideBySide(b,i)||k.rectsIntersect(b,i)){l.splice(a,1);h[h.length-1]=k.unionRects(b,i);j=true;break}}}l=h}while(j);return l};k.offsetFromRect=function(l,j){return{x:k._distanceFromBounds(j.x,l.x,k.maxX(l)),y:k._distanceFromBounds(j.y,
l.y,k.maxY(l))}};k.rectsIntersect=function(l,j){l=k.intersectRects(l,j);return l.width!==0&&l.height!==0};k.rectsSideBySide=function(l,j){if(l.x==j.x&&l.width==j.width)return l.y<j.y?l.y+l.height==j.y:j.y+j.height==l.y;else if(l.y==j.y&&l.height==j.height)return l.x<j.x?l.x+l.width==j.x:j.x+j.width==l.x;return false};k.intersectRects=function(l,j){l={x:Math.max(k.minX(l),k.minX(j)),y:Math.max(k.minY(l),k.minY(j)),width:Math.min(k.maxX(l),k.maxX(j)),height:Math.min(k.maxY(l),k.maxY(j))};l.width=Math.max(0,
l.width-l.x);l.height=Math.max(0,l.height-l.y);return l};k.minX=function(l){return l.x||0};k.maxX=function(l){return(l.x||0)+(l.width||0)};k.minY=function(l){return l.y||0};k.maxY=function(l){return(l.y||0)+(l.height||0)};k.pointInRect=function(l,j){return l.x>=k.minX(j)&&l.y>=k.minY(j)&&l.x<=k.maxX(j)&&l.y<=k.maxY(j)};k.unionRects=function(l,j){l={x:Math.min(k.minX(l),k.minX(j)),y:Math.min(k.minY(l),k.minY(j)),width:Math.max(k.maxX(l),k.maxX(j)),height:Math.max(k.maxY(l),k.maxY(j))};l.width=Math.max(0,
l.width-l.x);l.height=Math.max(0,l.height-l.y);return l};k.rectsEqual=function(l,j,h){if(!l||!j)return l==j;if(!h&&h!==0)h=0.1;if(l.y!=j.y&&Math.abs(l.y-j.y)>h)return false;if(l.x!=j.x&&Math.abs(l.x-j.x)>h)return false;if(l.width!=j.width&&Math.abs(l.width-j.width)>h)return false;if(l.height!=j.height&&Math.abs(l.height-j.height)>h)return false;return true}});
bespin.tiki.module("text_editor:views/canvas",function(q,k){var l=q("bespin:util/util"),j=q("utils/rect"),h=q("events").Event;k.CanvasView=function(d,b,a){if(d){this._preventDownsize=b||false;this._clearOnFullInvalid=a||false;this._clippingFrame=this._frame={x:0,y:0,width:0,height:0};this._invalidRects=[];b=document.createElement("canvas");b.setAttribute("style","position: absolute");b.innerHTML="canvas tag not supported by your browser";d.appendChild(b);this.domNode=b;this.clippingChanged=new h;
this.clippingChanged.add(this.clippingFrameChanged.bind(this))}};k.CanvasView.prototype={domNode:null,clippingChanged:null,_canvasContext:null,_canvasId:null,_invalidRects:null,_lastRedrawTime:null,_redrawTimer:null,_clippingFrame:null,_preventDownsize:false,_clearOnFullInvalid:false,_frame:null,_getContext:function(){if(this._canvasContext===null)this._canvasContext=this.domNode.getContext("2d");return this._canvasContext},computeWithClippingFrame:function(d,b){var a=this.clippingFrame;return{x:d+
a.x,y:b+a.y}},minimumRedrawDelay:1E3/30,clippingFrameChanged:function(){this.invalidate()},drawRect:function(){},render:function(){if(!(this._renderTimer||this._redrawTimer))this._renderTimer=setTimeout(this._tryRedraw.bind(this),0)},invalidate:function(){this._invalidRects="all";this.render()},invalidateRect:function(d){var b=this._invalidRects;if(b!=="all"){b.push(d);this.render()}},_tryRedraw:function(){this._renderTimer=null;var d=(new Date).getTime(),b=this._lastRedrawTime,a=this.minimumRedrawDelay;
if(b===null||d-b>=a)this._redraw();else if(this._redrawTimer===null)this._redrawTimer=window.setTimeout(this._redraw.bind(this),a)},_redraw:function(){var d=this.clippingFrame;d={x:Math.round(d.x),y:Math.round(d.y),width:d.width,height:d.height};var b=this._getContext();b.save();b.translate(-d.x,-d.y);var a=this._invalidRects;if(a==="all"){this._clearOnFullInvalid&&b.clearRect(0,0,this.domNode.width,this.domNode.height);this.drawRect(d,b)}else j.merge(a).forEach(function(i){i=j.intersectRects(i,d);
if(i.width!==0&&i.height!==0){b.save();var e=i.x,g=i.y,o=i.width,f=i.height;b.beginPath();b.moveTo(e,g);b.lineTo(e+o,g);b.lineTo(e+o,g+f);b.lineTo(e,g+f);b.closePath();b.clip();this.drawRect(i,b);b.restore()}},this);b.restore();this._invalidRects=[];this._redrawTimer=null;this._lastRedrawTime=(new Date).getTime()}};Object.defineProperties(k.CanvasView.prototype,{clippingFrame:{get:function(){return this._clippingFrame},set:function(d){d=l.mixin(l.clone(this._clippingFrame),d);if(this._clippingFrame===
null||!j.rectsEqual(d,this._clippingFrame)){this._clippingFrame=d;this.clippingChanged()}}},frame:{get:function(){return this._frame},set:function(d){var b=this.domNode,a=b.style,i=this._preventDownsize,e=b.width,g=b.height;a=b.style;a.left=d.x+"px";a.top=d.y+"px";var o,f;if(d.width!==e)if(d.width<e)i||(o=true);else o=true;if(d.height!==g)if(d.height<g)i||(f=true);else f=true;if(o)this.domNode.width=d.width;if(f)this.domNode.height=d.height;this._frame=d;this.clippingFrame={width:d.width,height:d.height}}}})});
bespin.tiki.module("text_editor:views/editor",function(q,k){var l=q("bespin:util/util"),j=q("bespin:plugins").catalog,h=q("events").Event,d=q("settings").settings;q("bespin:util/scratchcanvas");var b=q("rangeutils:utils/range"),a=q("views/text").TextView,i=q("views/gutter").GutterView;q("controllers/layoutmanager");var e=q("controllers/search").EditorSearchController,g=q("models/buffer").Buffer,o=q("views/scroller"),f=o.ScrollerCanvasView,m=q("controllers/undo").EditorUndoController,s={};q=function(n){var t=
j.plugins.text_editor.provides,u=t.length,w={};if(n){n=n.themestyles;if(n.currentThemeVariables&&n.currentThemeVariables.text_editor)w=n.currentThemeVariables.text_editor}for(;u--;)if(t[u].ep==="themevariable"){n=l.mixin(l.clone(t[u].defaultValue),w[t[u].name]);switch(t[u].name){case "gutter":case "editor":case "scroller":case "highlighter":s[t[u].name]=n}}};q();j.registerExtension("themeChange",{pointer:q});k.EditorView=function(n){this.elementAppended=new h;var t=this.element=this.container=document.createElement("div");
t.style.overflow="hidden";t.style.position="relative";this.scrollOffsetChanged=new h;this.willChangeBuffer=new h;this.selectionChanged=new h;this.textChanged=new h;this.gutterView=new i(t,this);this.textView=new a(t,this);var u=this.verticalScroller=new f(this,o.LAYOUT_VERTICAL),w=this.horizontalScroller=new f(this,o.LAYOUT_HORIZONTAL);this.editorUndoController=new m(this);this.searchController=new e(this);this._textViewSize=this._oldSize={width:0,height:0};this._themeData=s;this.buffer=new g(null,
n);this.elementAppended.add(function(){this._font=d.get("fontsize")+"px "+d.get("fontface");j.registerExtension("themeChange",{pointer:this._themeVariableChange.bind(this)});j.registerExtension("settingChange",{match:"font[size|face]",pointer:this._fontSettingChanged.bind(this)});j.registerExtension("dimensionsChanged",{pointer:this.dimensionsChanged.bind(this)});this._dontRecomputeLayout=false;this._recomputeLayout();t.addEventListener(l.isMozilla?"DOMMouseScroll":"mousewheel",this._onMouseWheel.bind(this),
false);u.valueChanged.add(function(p){this.scrollOffset={y:p}}.bind(this));w.valueChanged.add(function(p){this.scrollOffset={x:p}}.bind(this));this.scrollOffsetChanged.add(function(p){this._updateScrollOffsetChanged(p)}.bind(this))}.bind(this))};k.EditorView.prototype={elementAppended:null,textChanged:null,selectionChanged:null,scrollOffsetChanged:null,willChangeBuffer:null,_textViewSize:null,_textLinesCount:0,_gutterViewWidth:0,_oldSize:null,_buffer:null,_dontRecomputeLayout:true,_themeData:null,
_layoutManagerSizeChanged:function(n){this._textViewSize={width:n.width*this.layoutManager.fontDimension.characterWidth,height:n.height*this.layoutManager.fontDimension.lineHeight};if(this._textLinesCount!==n.height){this.gutterView.computeWidth()!==this._gutterViewWidth?this._recomputeLayout(true):this.gutterView.invalidate();this._textLinesLength=n.height}this._updateScrollers();this.scrollOffset={}},_updateScrollers:function(){if(!this._dontRecomputeLayout){var n=this.textViewPaddingFrame,t=this._textViewSize.width,
u=this._textViewSize.height,w=this.scrollOffset,p=this.verticalScroller,r=this.horizontalScroller;if(u<n.height)p.isVisible=false;else{p.isVisible=true;p.proportion=n.height/u;p.maximum=u-n.height;p.value=w.y}if(t<n.width)r.isVisible=false;else{r.isVisible=true;r.proportion=n.width/t;r.maximum=t-n.width;r.value=w.x}}},_onMouseWheel:function(n){var t=0;if(n.wheelDelta)t=-n.wheelDelta;else if(n.detail)t=n.detail*40;var u=true;if(n.axis){if(n.axis==n.HORIZONTAL_AXIS)u=false}else if(n.wheelDeltaY||n.wheelDeltaX){if(n.wheelDeltaX==
n.wheelDelta)u=false}else if(n.shiftKey)u=false;u?this.scrollBy(0,t):this.scrollBy(t*5,0);l.stopEvent(n)},scrollTo:function(n){this.scrollOffset=n},scrollBy:function(n,t){this.scrollOffset={x:this.scrollOffset.x+n,y:this.scrollOffset.y+t}},_recomputeLayout:function(n){if(!this._dontRecomputeLayout){var t=this.container.offsetWidth,u=this.container.offsetHeight;if(!(!n&&t==this._oldSize.width&&u==this._oldSize.height)){this._oldSize={width:t,height:u};n=this._gutterViewWidth=this.gutterView.computeWidth();
this.gutterView.frame={x:0,y:0,width:n,height:u};this.textView.frame={x:n,y:0,width:t-n,height:u};var w=this._themeData.scroller.padding,p=this._themeData.scroller.thickness;this.horizontalScroller.frame={x:n+w,y:u-(p+w),width:t-(n+2*w+p),height:p};this.verticalScroller.frame={x:t-(w+p),y:w,width:p,height:u-(2*w+p)};this.scrollOffset={};this._updateScrollers();this.gutterView.invalidate();this.textView.invalidate();this.verticalScroller.invalidate();this.horizontalScroller.invalidate()}}},dimensionsChanged:function(){this._recomputeLayout()},
_font:null,_fontSettingChanged:function(){this._font=d.get("fontsize")+"px "+d.get("fontface");this.layoutManager._recalculateMaximumWidth();this._layoutManagerSizeChanged(this.layoutManager.size);this.textView.invalidate()},_themeVariableChange:function(){this._recomputeLayout(true)},_updateScrollOffsetChanged:function(n){this.verticalScroller.value=n.y;this.horizontalScroller.value=n.x;this.textView.clippingFrame={x:n.x,y:n.y};this.gutterView.clippingFrame={y:n.y};this._updateScrollers();this.gutterView.invalidate();
this.textView.invalidate()},replace:function(n,t,u){if(!b.isRange(n))throw new Error('replace(): expected range but found "'+n+"'");if(!l.isString(t))throw new Error('replace(): expected text string but found "'+text+'"');var w=b.normalizeRange(n),p=this.textView,r=p.getSelectedRange(false);return p.groupChanges(function(){p.replaceCharacters(w,t);if(u)p.setSelection(r);else{var v=t.split("\n");v=v.length>1?{row:n.start.row+v.length-1,col:v[v.length-1].length}:b.addPositions(n.start,{row:0,col:t.length});
p.moveCursorTo(v)}})},getText:function(n){if(!b.isRange(n))throw new Error('getText(): expected range but found "'+n+'"');return this.layoutManager.textStorage.getCharacters(b.normalizeRange(n))},setLineNumber:function(n){if(!l.isNumber(n))throw new Error("setLineNumber(): lineNumber must be a number");this.textView.moveCursorTo({row:n-1,col:0})},setCursor:function(n){if(!b.isPosition(n))throw new Error('setCursor(): expected position but found "'+n+'"');this.textView.moveCursorTo(n)},changeGroup:function(n){return this.textView.groupChanges(function(){n(this)}.bind(this))}};
Object.defineProperties(k.EditorView.prototype,{themeData:{get:function(){return this._themeData},set:function(){throw new Error("themeData can't be changed directly. Use themeManager.");}},font:{get:function(){return this._font},set:function(){throw new Error("font can't be changed directly. Use settings fontsize and fontface.");}},buffer:{set:function(n){if(n!==this._buffer){if(!n.loadPromise.isResolved())throw new Error("set bufffer: the newBuffer has to be loaded!");if(this._buffer!==null){this.layoutManager.sizeChanged.remove(this);
this.layoutManager.textStorage.changed.remove(this);this.textView.selectionChanged.remove(this)}this.willChangeBuffer(n);j.publish(this,"editorChange","buffer",n);this.layoutManager=n.layoutManager;this._buffer=n;var t=this.layoutManager,u=this.textView;t.sizeChanged.add(this,this._layoutManagerSizeChanged.bind(this));t.textStorage.changed.add(this,this.textChanged.bind(this));u.selectionChanged.add(this,this.selectionChanged.bind(this));this.textView.setSelection(n._selectedRange,false);this.scrollOffsetChanged(n._scrollOffset);
this.layoutManager.sizeChanged(this.layoutManager.size);this._recomputeLayout()}},get:function(){return this._buffer}},frame:{get:function(){return{width:this.container.offsetWidth,height:this.container.offsetHeight}}},textViewPaddingFrame:{get:function(){var n=l.clone(this.textView.frame),t=this.textView.padding;n.width-=t.left+t.right;n.height-=t.top+t.bottom;return n}},scrollOffset:{set:function(n){if(n.x===undefined)n.x=this.scrollOffset.x;if(n.y===undefined)n.y=this.scrollOffset.y;var t=this.textViewPaddingFrame;
if(n.y<0)n.y=0;else if(this._textViewSize.height<t.height)n.y=0;else if(n.y+t.height>this._textViewSize.height)n.y=this._textViewSize.height-t.height;if(n.x<0)n.x=0;else if(this._textViewSize.width<t.width)n.x=0;else if(n.x+t.width>this._textViewSize.width)n.x=this._textViewSize.width-t.width;if(!(n.x===this.scrollOffset.x&&n.y===this.scrollOffset.y)){this.buffer._scrollOffset=n;this.scrollOffsetChanged(n);j.publish(this,"editorChange","scrollOffset",n)}},get:function(){return this.buffer._scrollOffset}},
readOnly:{get:function(){return this._buffer.model.readOnly},set:function(n){this._buffer.model.readOnly=n}},focus:{get:function(){return this.textView.hasFocus},set:function(n){if(!l.isBoolean(n))throw new Error('set focus: expected boolean but found "'+n+'"');this.textView.hasFocus=n}},selection:{get:function(){return l.clone(this.textView.getSelectedRange(false))},set:function(n){if(!b.isRange(n))throw new Error("set selection: position/selection must be supplied");this.textView.setSelection(n)}},
selectedText:{get:function(){return this.getText(this.selection)},set:function(n){if(!l.isString(n))throw new Error('set selectedText: expected string but found "'+n+'"');return this.replace(this.selection,n)}},value:{get:function(){return this.layoutManager.textStorage.value},set:function(n){if(!l.isString(n))throw new Error('set value: expected string but found "'+n+'"');return this.replace(this.layoutManager.textStorage.range,n,false)}},syntax:{get:function(){return this.layoutManager.syntaxManager.getSyntax()},
set:function(n){if(!l.isString(n))throw new Error('set syntax: expected string but found "'+newValue+'"');return this.layoutManager.syntaxManager.setSyntax(n)}}})});
bespin.tiki.module("text_editor:views/gutter",function(q,k){var l=q("bespin:util/util"),j=q("views/canvas").CanvasView;k.GutterView=function(h,d){j.call(this,h,true);this.editor=d};k.GutterView.prototype=new j;l.mixin(k.GutterView.prototype,{drawRect:function(h,d){var b=this.editor.themeData.gutter;d.fillStyle=b.backgroundColor;d.fillRect(h.x,h.y,h.width,h.height);d.save();d.translate(b.paddingLeft,0);var a=this.editor.layoutManager,i=a.characterRangeForBoundingRect(h);h=Math.min(i.end.row,a.textLines.length-
1);var e=a.fontDimension.lineAscent;d.fillStyle=b.color;d.font=this.editor.font;for(b=i.start.row;b<=h;b++)d.fillText(""+(b+1),-0.5,a.lineRectForRow(b).y+e-0.5);d.restore()},computeWidth:function(){var h=this.editor.themeData.gutter,d=this.editor.layoutManager;return d.fontDimension.characterWidth*(""+d.textLines.length).length+(h.paddingLeft+h.paddingRight)}})});
bespin.tiki.module("text_editor:views/scroller",function(q,k){var l=q("bespin:util/util"),j=q("events").Event,h=q("bespin:console").console,d=q("utils/rect"),b=q("views/canvas").CanvasView,a=k.LAYOUT_HORIZONTAL=0,i=k.LAYOUT_VERTICAL=1;k.ScrollerCanvasView=function(e,g){b.call(this,e.container,true,true);this.editor=e;this.layoutDirection=g;e=function(o,f,m){m=m||this.domNode;m.addEventListener(o,function(s){f.call(this,s);l.stopEvent(s)}.bind(this),false)}.bind(this);e("mouseover",this.mouseEntered);
e("mouseout",this.mouseExited);e("mousedown",this.mouseDown);e("mouseup",this.mouseUp,window);e("mousemove",this.mouseMove,window);this.valueChanged=new j};k.ScrollerCanvasView.prototype=new b;l.mixin(k.ScrollerCanvasView.prototype,{lineHeight:20,proportion:0,layoutDirection:i,_isVisible:false,_maximum:0,_value:0,valueChanged:null,padding:{left:0,bottom:0,top:0,right:0},_mouseDownScreenPoint:null,_mouseDownValue:null,_isMouseOver:false,_scrollTimer:null,_mouseEventPosition:null,_mouseOverHandle:false,
_drawNib:function(e){var g=this.editor.themeData.scroller,o,f;o=g.nibStyle;f=g.nibArrowStyle;g=g.nibStrokeStyle;var m=Math.floor(7.5);e.fillStyle=o;e.beginPath();e.arc(0,0,Math.floor(7.5),0,Math.PI*2,true);e.closePath();e.fill();e.strokeStyle=g;e.stroke();e.fillStyle=f;e.beginPath();e.moveTo(0,-m+3);e.lineTo(-m+3,m-5);e.lineTo(m-3,m-5);e.closePath();e.fill()},_drawNibs:function(e,g){var o=this._getClientThickness(),f=this._value,m=this._maximum,s=this._isHighlighted();if(s||f!==0){e.save();e.translate(8,
o/2);e.rotate(Math.PI*1.5);e.moveTo(0,0);this._drawNib(e,g);e.restore()}if(s||f!==m){e.save();e.translate(this._getClientLength()-8,o/2);e.rotate(Math.PI*0.5);e.moveTo(0,0);this._drawNib(e,g);e.restore()}},_getClientFrame:function(){var e=this.frame,g=this.padding;return{x:g.left,y:g.top,width:e.width-(g.left+g.right),height:e.height-(g.top+g.bottom)}},_getClientLength:function(){var e=this._getClientFrame();switch(this.layoutDirection){case a:return e.width;case i:return e.height;default:h.error("unknown layout direction");
return null}},_getClientThickness:function(){var e=this.padding,g=this.editor.themeData.scroller.thickness;switch(this.layoutDirection){case i:return g-(e.left+e.right);case a:return g-(e.top+e.bottom);default:h.error("unknown layout direction");return null}},_getFrameLength:function(){switch(this.layoutDirection){case a:return this.frame.width;case i:return this.frame.height;default:h.error("unknown layout direction");return null}},_getGutterFrame:function(){var e=this._getClientFrame(),g=this._getClientThickness();
switch(this.layoutDirection){case i:return{x:e.x,y:e.y+15,width:g,height:Math.max(0,e.height-30)};case a:return{x:e.x+15,y:e.y,width:Math.max(0,e.width-30),height:g};default:h.error("unknown layout direction");return null}},_getGutterLength:function(){var e=this._getGutterFrame(),g;switch(this.layoutDirection){case a:g=e.width;break;case i:g=e.height;break;default:h.error("unknown layout direction");break}return g},_getHandleFrame:function(){var e=this._getGutterFrame(),g=this._getHandleOffset(),
o=this._getHandleLength();switch(this.layoutDirection){case i:return{x:e.x,y:e.y+g,width:e.width,height:o};case a:return{x:e.x+g,y:e.y,width:o,height:e.height}}},_getHandleLength:function(){var e=this._getGutterLength();return Math.max(e*this.proportion,20)},_getHandleOffset:function(){var e=this._maximum;if(e===0)return 0;var g=this._getGutterLength(),o=this._getHandleLength();return(g-o)*this._value/e},_isHighlighted:function(){return this._isMouseOver===true||this._mouseDownScreenPoint!==null},
_segmentForMouseEvent:function(e){e={x:e.layerX,y:e.layerY};var g=this._getClientFrame(),o=this.padding;if(!d.pointInRect(e,g))return null;var f=this.layoutDirection;switch(f){case a:if(e.x-o.left<15)return"nib-start";else if(e.x>=g.width-15)return"nib-end";break;case i:if(e.y-o.top<15)return"nib-start";else if(e.y>=g.height-15)return"nib-end";break;default:h.error("unknown layout direction");break}o=this._getHandleFrame();if(d.pointInRect(e,o))return"handle";switch(f){case a:if(e.x<o.x)return"gutter-before";
else if(e.x>=o.x+o.width)return"gutter-after";break;case i:if(e.y<o.y)return"gutter-before";else if(e.y>=o.y+o.height)return"gutter-after";break;default:h.error("unknown layout direction");break}h.error("_segmentForMouseEvent: point ",e," outside view with handle frame ",o," and client frame ",g);return null},adjustFrame:function(){var e=this.frame;this.set("layout",{left:0,top:0,width:e.width,height:e.height})},drawRect:function(e,g){if(this._isVisible){var o=this._isHighlighted();e=this.editor.themeData.scroller;
var f=o?e.fullAlpha:e.particalAlpha,m=this.frame;g.clearRect(0,0,m.width,m.height);g.save();m=this.padding;g.translate(m.left,m.top);this._getHandleFrame();m=this._getGutterLength();var s=this._getClientThickness(),n=s/2,t=this.layoutDirection,u=this._getHandleOffset()+15,w=this._getHandleLength();if(t===i){g.translate(s+1,0);g.rotate(Math.PI*0.5)}if(!(m<=w)){g.globalAlpha=f;if(o){o=this._getClientLength();g.fillStyle=e.trackFillStyle;g.fillRect(8.5,0.5,o-16,s-1);g.strokeStyle=e.trackStrokeStyle;
g.strokeRect(8.5,0.5,o-16,s-1)}o=function(){g.beginPath();g.arc(u+n+0.5,n,n-0.5,Math.PI/2,3*Math.PI/2,false);g.arc(u+w-n-0.5,n,n-0.5,3*Math.PI/2,Math.PI/2,false);g.lineTo(u+n+0.5,s-0.5);g.closePath()};o();m=g.createLinearGradient(u,0,u,s);m.addColorStop(0,e.barFillGradientTopStart);m.addColorStop(0.4,e.barFillGradientTopStop);m.addColorStop(0.41,e.barFillStyle);m.addColorStop(0.8,e.barFillGradientBottomStart);m.addColorStop(1,e.barFillGradientBottomStop);g.fillStyle=m;g.fill();g.save();g.clip();g.fillStyle=
e.barFillStyle;g.beginPath();g.moveTo(u+n*0.4,n*0.6);g.lineTo(u+n*0.9,s*0.4);g.lineTo(u,s*0.4);g.closePath();g.fill();g.beginPath();g.moveTo(u+w-n*0.4,0+n*0.6);g.lineTo(u+w-n*0.9,0+s*0.4);g.lineTo(u+w,0+s*0.4);g.closePath();g.fill();g.restore();g.save();o();g.strokeStyle=e.trackStrokeStyle;g.stroke();g.restore();this._drawNibs(g,f);g.restore()}}},_repeatAction:function(e,g){if(e()!==false){var o=function(){this._repeatAction(e,100)}.bind(this);this._scrollTimer=setTimeout(o,g)}},_scrollByDelta:function(e){this.value=
this._value+e},_scrollUpOneLine:function(){this._scrollByDelta(-this.lineHeight);return true},_scrollDownOneLine:function(){this._scrollByDelta(this.lineHeight);return true},_scrollPage:function(){switch(this._segmentForMouseEvent(this._mouseEventPosition)){case "gutter-before":this._scrollByDelta(this._getGutterLength()*-1);break;case "gutter-after":this._scrollByDelta(this._getGutterLength());break;case null:break;default:return false}return true},mouseDown:function(e){this._mouseEventPosition=
e;this._mouseOverHandle=false;this._getGutterLength();switch(this._segmentForMouseEvent(e)){case "nib-start":this._repeatAction(this._scrollUpOneLine.bind(this),500);break;case "nib-end":this._repeatAction(this._scrollDownOneLine.bind(this),500);break;case "gutter-before":this._repeatAction(this._scrollPage.bind(this),500);break;case "gutter-after":this._repeatAction(this._scrollPage.bind(this),500);break;case "handle":break;default:h.error("_segmentForMouseEvent returned an unknown value");break}switch(this.layoutDirection){case a:this._mouseDownScreenPoint=
e.pageX;break;case i:this._mouseDownScreenPoint=e.pageY;break;default:h.error("unknown layout direction");break}},mouseMove:function(e){if(this._mouseDownScreenPoint!==null){if(this._segmentForMouseEvent(e)=="handle"||this._mouseOverHandle===true){this._mouseOverHandle=true;if(this._scrollTimer!==null){clearTimeout(this._scrollTimer);this._scrollTimer=null}var g;switch(this.layoutDirection){case a:g=e.pageX;break;case i:g=e.pageY;break;default:h.error("unknown layout direction");break}var o=g-this._mouseDownScreenPoint,
f=this._maximum,m=this._value,s=this._getGutterLength(),n=this._getHandleLength();this.value=m+f*o/(s-n);this._mouseDownScreenPoint=g}this._mouseEventPosition=e}},mouseEntered:function(){this._isMouseOver=true;this.invalidate()},mouseExited:function(){this._isMouseOver=false;this.invalidate()},mouseUp:function(){this._mouseDownValue=this._mouseDownScreenPoint=null;if(this._scrollTimer){clearTimeout(this._scrollTimer);this._scrollTimer=null}this.invalidate()}});Object.defineProperties(k.ScrollerCanvasView.prototype,
{isVisible:{set:function(e){if(this._isVisible!==e){this._isVisible=e;this.domNode.style.display=e?"block":"none";e&&this.invalidate()}}},maximum:{set:function(e){if(this._value>this._maximum)this._value=this._maximum;if(e!==this._maximum){this._maximum=e;this.invalidate()}}},value:{set:function(e){if(e<0)e=0;else if(e>this._maximum)e=this._maximum;if(e!==this._value){this._value=e;this.valueChanged(e);this.invalidate()}}}})});
bespin.tiki.module("text_editor:views/text",function(q,k){var l=q("bespin:plugins").catalog,j=q("bespin:util/util"),h=q("events").Event,d=q("views/canvas").CanvasView;q("controllers/layoutmanager");var b=q("rangeutils:utils/range"),a=q("utils/rect"),i=q("views/textinput").TextInput,e=q("keyboard:keyboard").keyboardManager,g=q("bespin:console").console,o=q("settings").settings;k.TextView=function(f,m){d.call(this,f,true);this.editor=m;this.textInput=new i(f,this);this.padding={top:0,bottom:30,left:0,
right:30};this.clippingChanged.add(this.clippingFrameChanged.bind(this));f=this.domNode;f.style.cursor="text";f.addEventListener("mousedown",this.mouseDown.bind(this),false);f.addEventListener("mousemove",this.mouseMove.bind(this),false);window.addEventListener("mouseup",this.mouseUp.bind(this),false);m.willChangeBuffer.add(this.editorWillChangeBuffer.bind(this));this.selectionChanged=new h;this.beganChangeGroup=new h;this.endedChangeGroup=new h;this.willReplaceRange=new h;this.replacedCharacters=
new h};k.TextView.prototype=new d;j.mixin(k.TextView.prototype,{_dragPoint:null,_dragTimer:null,_enclosingScrollView:null,_inChangeGroup:false,_insertionPointBlinkTimer:null,_insertionPointVisible:true,_keyBuffer:"",_keyMetaBuffer:"",_keyState:"start",_hasFocus:false,_mouseIsDown:false,selectionChanged:null,beganChangeGroup:null,endedChangeGroup:null,willReplaceRange:null,replacedCharacters:null,editorWillChangeBuffer:function(f){if(this.editor.layoutManager){var m=this.editor.layoutManager;m.invalidatedRects.remove(this);
m.changedTextAtRow.remove(this)}m=f.layoutManager;m.invalidatedRects.add(this,this.layoutManagerInvalidatedRects.bind(this));m.changedTextAtRow.add(this,this.layoutManagerChangedTextAtRow.bind(this))},didFocus:function(){this._setFocus(true,true)},didBlur:function(){this._setFocus(false,true)},_drag:function(){var f=this._dragPoint,m=a.offsetFromRect(this.clippingFrame,f);this.moveCursorTo(this._selectionPositionForPoint({x:f.x-m.x,y:f.y-m.y}),true)},_drawInsertionPoint:function(f,m){if(this._insertionPointVisible){var s=
this.editor.layoutManager.characterRectForPosition(this.editor.buffer._selectedRange.start);f=Math.floor(s.x);var n=s.y,t=Math.ceil(s.width);s=s.height;m.save();var u=this.editor.themeData.editor;if(this._hasFocus){m.strokeStyle=u.cursorColor;m.beginPath();m.moveTo(f+0.5,n);m.lineTo(f+0.5,n+s);m.closePath();m.stroke()}else{m.fillStyle=u.unfocusedCursorBackgroundColor;m.fillRect(f+0.5,n,t-0.5,s);m.strokeStyle=u.unfocusedCursorColor;m.strokeRect(f+0.5,n+0.5,t-1,s-1)}m.restore()}},_drawLines:function(f,
m){var s=this.editor.layoutManager,n=s.textLines,t=s.fontDimension.lineAscent,u=this.editor.themeData.highlighter;m.save();m.font=this.editor.font;var w=s.characterRangeForBoundingRect(f),p=w.start;w=w.end;for(var r=w.row,v=p.row;v<=r;v++){var x=n[v];if(!j.none(x)){var C=x.characters,E=C.length,D=Math.min(w.col,E),G=p.col;if(!(G>=E)){x=x.colors;if(x==null)x=[];for(E=0;E<x.length&&G<x[E].start;)E++;for(var H=E<x.length?x[E].start:G;H<D;){f=x[E];G=f!=null?f.end:D;f=f!=null?f.tag:"plain";f=u.hasOwnProperty(f)?
u[f]:"red";m.fillStyle=f;f=s.characterRectForPosition({row:v,col:H});H=C.substring(H,G);m.fillText(H,f.x,f.y+t);H=G;E++}}}}m.restore()},_drawSelectionHighlight:function(f,m){f=this.editor.themeData.editor;f=this._hasFocus?f.selectedTextBackgroundColor:f.unfocusedCursorBackgroundColor;var s=this.editor.layoutManager;m.save();var n=b.normalizeRange(this.editor.buffer._selectedRange);m.fillStyle=f;s.rectsForRange(n).forEach(function(t){m.fillRect(t.x,t.y,t.width,t.height)});m.restore()},_drawSelection:function(f,
m){this._rangeIsInsertionPoint(this.editor.buffer._selectedRange)?this._drawInsertionPoint(f,m):this._drawSelectionHighlight(f,m)},_getVirtualSelection:function(f){var m=this.editor.buffer._selectedRange,s=this.editor.buffer._selectedRangeEndVirtual;return{start:f&&s?s:m.start,end:s||m.end}},_invalidateSelection:function(){var f=function(n){return{x:n.x-1,y:n.y,width:n.width+2,height:n.height}},m=this.editor.layoutManager,s=b.normalizeRange(this.editor.buffer._selectedRange);if(this._rangeIsInsertionPoint(s)){m=
m.characterRectForPosition(s.start);this.invalidateRect(f(m))}else m.rectsForRange(s).forEach(function(n){this.invalidateRect(f(n))},this)},_isReadOnly:function(){return this.editor.layoutManager.textStorage.readOnly},_keymappingChanged:function(){this._keyBuffer="";this._keyState="start"},_performVerticalKeyboardSelection:function(f){var m=this.editor.buffer._selectedRangeEndVirtual;this.moveCursorTo(b.addPositions(m!==null?m:this.editor.buffer._selectedRange.end,{row:f,col:0}),true,true)},_rangeIsInsertionPoint:function(f){return b.isZeroLength(f)},
_rearmInsertionPointBlinkTimer:function(){this._insertionPointVisible||this.blinkInsertionPoint();this._insertionPointBlinkTimer!==null&&clearInterval(this._insertionPointBlinkTimer);this._insertionPointBlinkTimer=setInterval(this.blinkInsertionPoint.bind(this),750)},_repositionSelection:function(){var f=this.editor.layoutManager.textLines,m=f.length,s=this.editor.buffer._selectedRange,n=Math.min(s.start.row,m-1);m=Math.min(s.end.row,m-1);var t=f[m];this.setSelection({start:{row:n,col:Math.min(s.start.col,
f[n].characters.length)},end:{row:m,col:Math.min(s.end.col,t.characters.length)}})},_scrollPage:function(f){this.editor.scrollBy(0,(this.clippingFrame.height+this.editor.layoutManager.fontDimension.lineAscent)*(f?-1:1))},_scrollWhileDragging:function(){var f=this._dragPoint;f=this.computeWithClippingFrame(f.layerX,f.layerY);j.mixin(this._dragPoint,f);this._drag()},_selectionPositionForPoint:function(f){f=this.editor.layoutManager.characterAtPoint(f);return f.partialFraction<0.5?f:b.addPositions(f,
{row:0,col:1})},_syntaxManagerUpdatedSyntaxForRows:function(f,m){if(f!==m){var s=this.editor.layoutManager;s.updateTextRows(f,m);s.rectsForRange({start:{row:f,col:0},end:{row:m,col:0}}).forEach(this.invalidateRect,this)}},blinkInsertionPoint:function(){this._insertionPointVisible=!this._insertionPointVisible;this._invalidateSelection()},copy:function(){return this.getSelectedCharacters()},cut:function(){var f=this.getSelectedCharacters();f!=""&&this.performBackspaceOrDelete(false);return f},drawRect:function(f,
m){m.fillStyle=this.editor.themeData.editor.backgroundColor;m.fillRect(f.x,f.y,f.width,f.height);this._drawSelection(f,m);this._drawLines(f,m)},focus:function(){this.textInput.focus()},getSelectedCharacters:function(){return this._rangeIsInsertionPoint(this.editor.buffer._selectedRange)?"":this.editor.layoutManager.textStorage.getCharacters(b.normalizeRange(this.editor.buffer._selectedRange))},getSelectedRange:function(f){return f?this.editor.buffer._selectedRange:b.normalizeRange(this.editor.buffer._selectedRange)},
groupChanges:function(f){if(this._isReadOnly())return false;if(this._inChangeGroup){f();return true}this._inChangeGroup=true;this.beganChangeGroup(this,this.editor.buffer._selectedRange);try{f()}catch(m){g.error("Error in groupChanges(): "+m);this._inChangeGroup=false;this.endedChangeGroup(this,this.editor.buffer._selectedRange);return false}finally{this._inChangeGroup=false;this.endedChangeGroup(this,this.editor.buffer._selectedRange);return true}},insertText:function(f){if(this._isReadOnly())return false;
this.groupChanges(function(){var m=b.normalizeRange(this.editor.buffer._selectedRange);this.replaceCharacters(m,f);var s=f.split("\n");this.moveCursorTo(s.length>1?{row:m.start.row+s.length-1,col:s[s.length-1].length}:b.addPositions(m.start,{row:0,col:f.length}))}.bind(this));return true},isDelimiter:function(f){return"\"',;.!~@#$%^&*?[]<>():/\\-+ \t".indexOf(f)!==-1},keyDown:function(f){if(f.charCode===0||f._charCode===0)return e.processKeyEvent(f,this,{isTextView:true});else if(f.keyCode===9)f.preventDefault();
else return false},layoutManagerChangedTextAtRow:function(){this._repositionSelection()},layoutManagerInvalidatedRects:function(f,m){m.forEach(this.invalidateRect,this)},mouseDown:function(f){j.stopEvent(f);this._mouseIsDown=this.hasFocus=true;var m=this.computeWithClippingFrame(f.layerX,f.layerY);j.mixin(m,{layerX:f.layerX,layerY:f.layerY});switch(f.detail){case 1:var s=this._selectionPositionForPoint(m);this.moveCursorTo(s,f.shiftKey);break;case 2:s=this._selectionPositionForPoint(m);var n=this.editor.layoutManager.textStorage.lines[s.row];
if(n.length===0)return true;s.col-=s.col==n.length?1:0;var t=!this.isDelimiter(n[s.col]),u=this,w=function(p,r){for(;p>-1&&p<n.length;p+=r)if(u.isDelimiter(n[p])===t)break;return p+(r==1?0:1)};f=w(s.col,-1);w=w(s.col,1);this.moveCursorTo({row:s.row,col:f});this.moveCursorTo({row:s.row,col:w},true);break;case 3:f=this.editor.layoutManager.textStorage.lines;s=this._selectionPositionForPoint(m);this.setSelection({start:{row:s.row,col:0},end:{row:s.row,col:f[s.row].length}});break}this._dragPoint=m;this._dragTimer=
setInterval(this._scrollWhileDragging.bind(this),100)},mouseMove:function(f){if(this._mouseIsDown){this._dragPoint=this.computeWithClippingFrame(f.layerX,f.layerY);j.mixin(this._dragPoint,{layerX:f.layerX,layerY:f.layerY});this._drag()}},mouseUp:function(){this._mouseIsDown=false;if(this._dragTimer!==null){clearInterval(this._dragTimer);this._dragTimer=null}},moveCursorTo:function(f,m,s){var n=this.editor.layoutManager.textStorage,t=n.clampPosition(f);this.setSelection({start:m?this.editor.buffer._selectedRange.start:
t,end:t});if(s){m=n.lines.length;s=f.row;n=f.col;this.editor.buffer._selectedRangeEndVirtual=s>0&&s<m?f:{row:s<1?0:m-1,col:n}}else this.editor.buffer._selectedRangeEndVirtual=null;this.scrollToPosition(this.editor.buffer._selectedRange.end)},moveDown:function(){var f=this._getVirtualSelection();f=b.normalizeRange(f);f=this._rangeIsInsertionPoint(this.editor.buffer._selectedRange)?f.end:{row:f.end.row,col:f.start.col};f=b.addPositions(f,{row:1,col:0});this.moveCursorTo(f,false,true)},moveLeft:function(){var f=
b.normalizeRange(this.editor.buffer._selectedRange);this._rangeIsInsertionPoint(f)?this.moveCursorTo(this.editor.layoutManager.textStorage.displacePosition(f.start,-1)):this.moveCursorTo(f.start)},moveRight:function(){var f=b.normalizeRange(this.editor.buffer._selectedRange);this._rangeIsInsertionPoint(f)?this.moveCursorTo(this.editor.layoutManager.textStorage.displacePosition(f.end,1)):this.moveCursorTo(f.end)},moveUp:function(){var f=b.normalizeRange(this._getVirtualSelection(true));position=b.addPositions({row:f.start.row,
col:this._getVirtualSelection().end.col},{row:-1,col:0});this.moveCursorTo(position,false,true)},parentViewFrameChanged:function(){arguments.callee.base.apply(this,arguments);this._resize()},replaceCharacters:function(f,m){if(this._isReadOnly())return false;this.groupChanges(function(){f=b.normalizeRange(f);this.willReplaceRange(this,f);this.editor.layoutManager.textStorage.replaceCharacters(f,m);this.replacedCharacters(this,f,m)}.bind(this));return true},performBackspaceOrDelete:function(f){if(this._isReadOnly())return false;
var m=this.editor.layoutManager.textStorage,s=m.lines,n="";n=0;var t=o.get("tabstop"),u=this.getSelectedRange();if(b.isZeroLength(u))if(f){f=u.start;n=s[f.row];n=n.substring(0,f.col).match(/\s*$/)[0].length<t||(f.col-t)%t!=0?1:t;u={start:m.displacePosition(f,n*-1),end:u.end}}else{f=u.end;n=s[f.row];n=n.substring(f.col).match(/^\s*/)[0].length<t?1:t;u={start:u.start,end:m.displacePosition(u.end,n)}}this.groupChanges(function(){this.replaceCharacters(u,"");this.moveCursorTo(u.start)}.bind(this));return true},
resetKeyBuffers:function(){this._keyMetaBuffer=this._keyBuffer=""},scrollPageDown:function(){this._scrollPage(false)},scrollPageUp:function(){this._scrollPage(true)},scrollToPosition:function(f){var m=this.editor.layoutManager.characterRectForPosition(f);f=m.x;var s=m.y,n=m.width;m=m.height;var t=this.clippingFrame,u=t.x,w=t.y,p=this.padding,r=t.width-p.right;t=t.height-p.bottom;this.editor.scrollTo({x:f>=u+30&&f+n<u+r?u:f-r/2+n/2,y:s>=w&&s+m<w+t?w:s-t/2+m/2})},selectAll:function(){var f=this.editor.layoutManager.textStorage.lines,
m=f.length-1;this.setSelection({start:{row:0,col:0},end:{row:m,col:f[m].length}})},selectDown:function(){this._performVerticalKeyboardSelection(1)},selectLeft:function(){this.moveCursorTo(this.editor.layoutManager.textStorage.displacePosition(this.editor.buffer._selectedRange.end,-1),true)},selectRight:function(){this.moveCursorTo(this.editor.layoutManager.textStorage.displacePosition(this.editor.buffer._selectedRange.end,1),true)},selectUp:function(){this._performVerticalKeyboardSelection(-1)},setSelection:function(f,
m){var s=this.editor.layoutManager.textStorage;f=s.clampRange(f);if(!b.equal(f,this.editor.buffer._selectedRange)){this._invalidateSelection();this.editor.buffer._selectedRange=f=s.clampRange(f);this._invalidateSelection();this._hasFocus&&this._rearmInsertionPointBlinkTimer();m&&this.scrollToPosition(f.end);this.selectionChanged(f);l.publish(this.editor,"editorChange","selection",f)}},textInserted:function(f){if(f!=="\n")if(!e.processKeyInput(f,this,{isTextView:true,isCommandKey:false})){this.insertText(f);
this.resetKeyBuffers()}},_setFocus:function(f,m){if(f!=this._hasFocus)if(this._hasFocus=f){this._rearmInsertionPointBlinkTimer();this._invalidateSelection();m||this.textInput.focus()}else{if(this._insertionPointBlinkTimer){clearInterval(this._insertionPointBlinkTimer);this._insertionPointBlinkTimer=null}this._insertionPointVisible=true;this._invalidateSelection();m||this.textInput.blur()}}});Object.defineProperties(k.TextView.prototype,{hasFocus:{get:function(){return this._hasFocus},set:function(f){this._setFocus(f,
false)}}})});
bespin.tiki.module("text_editor:views/textinput",function(q,k){var l=q("bespin:util/util");q("events");var j=q("keyboard:keyutil");k.TextInput=function(h,d){var b=this.domNode=document.createElement("textarea");b.setAttribute("style","position: absolute; z-index: -99999; top: -999px; left: -999px; width: 0px; height: 0px");h.appendChild(b);this.delegate=d;this._attachEvents()};k.TextInput.prototype={_composing:false,domNode:null,delegate:null,_textFieldChanged:function(){if(!(this._composing||this._ignore)){var h=
this.domNode,d=h.value;if(d!=""){h.value="";this._textInserted(d)}}},_copy:function(){var h=false,d=this.delegate;if(d&&d.copy)h=d.copy();return h},_cut:function(){var h=false,d=this.delegate;if(d&&d.cut)h=d.cut();return h},_textInserted:function(h){var d=this.delegate;d&&d.textInserted&&d.textInserted(h)},_setValueAndSelect:function(h){var d=this.domNode;d.value=h;d.select()},focus:function(){this.domNode.focus()},blur:function(){this.domNode.blur()},_attachEvents:function(){var h=this.domNode,d=
this;h.addEventListener("focus",function(){d.delegate&&d.delegate.didFocus&&d.delegate.didFocus()},false);h.addEventListener("blur",function(){d.delegate&&d.delegate.didBlur&&d.delegate.didBlur()},false);j.addKeyDownListener(h,function(g){return d.delegate&&d.delegate.keyDown?d.delegate.keyDown(g):false});if(l.isWebKit){l.isChrome||h.addEventListener("compositionend",function(g){d._textInserted(g.data)},false);h.addEventListener("textInput",function(g){d._textInserted(g.data)},false);h.addEventListener("paste",
function(g){d._textInserted(g.clipboardData.getData("text/plain"));g.preventDefault()},false)}else{var b=d._textFieldChanged.bind(d);h.addEventListener("keydown",function(){window.setTimeout(b,0)},false);h.addEventListener("keypress",b,false);h.addEventListener("keyup",b,false);h.addEventListener("compositionstart",function(){d._composing=true},false);h.addEventListener("compositionend",function(){d._composing=false;d._textFieldChanged()},false);h.addEventListener("paste",function(){d._setValueAndSelect("");
window.setTimeout(function(){d._textFieldChanged()},0)},false)}var a=function(g){g=g.type.indexOf("copy")!=-1?d._copy():d._cut();d._setValueAndSelect(g)};if(l.isWebKit&&!l.isChrome&&l.isMac){var i=(new Date).getTime(),e=function(g){var o=g.type.indexOf("cut")!=-1;if(!(o&&(new Date).getTime()-i<10)){a(g);if(o)i=(new Date).getTime()}};h.addEventListener("beforecopy",e,false);h.addEventListener("beforecut",e,false)}else{e=false;if(l.isMozilla)e=function(g){a(g);d._ignore=true;window.setTimeout(function(){d._setValueAndSelect("");
d._ignore=false},0)};h.addEventListener("copy",e||a,false);h.addEventListener("cut",e||a,false)}}}});bespin.tiki.module("text_editor:index",function(){});bespin.tiki.register("::undomanager",{name:"undomanager",dependencies:{}});
bespin.tiki.module("undomanager:index",function(q,k){q=q("bespin:util/util");k.UndoManager=function(){};q.mixin(k.UndoManager.prototype,{_redoStack:[],_undoStack:[],_undoOrRedo:function(l,j,h){if(j.length===0)return false;j=j.pop();if(!j.target[l](j.context)){this._redoStack=[];this._undoStack=[];return false}h.push(j);return true},redo:function(){return this._undoOrRedo("redo",this._redoStack,this._undoStack)},registerUndo:function(l,j){this._redoStack=[];this._undoStack.push({target:l,context:j})},
undo:function(){return this._undoOrRedo("undo",this._undoStack,this._redoStack)}});k.global=new k.UndoManager;k.undoManagerCommand=function(l,j,h){k.global[h.commandExt.name]()}});bespin.tiki.register("::embedded",{name:"embedded",dependencies:{theme_manager:"0.0.0",text_editor:"0.0.0",appconfig:"0.0.0",edit_session:"0.0.0",screen_theme:"0.0.0"}});bespin.tiki.module("embedded:index",function(){});bespin.tiki.register("::traits",{name:"traits",dependencies:{}});
bespin.tiki.module("traits:index",function(q,k){k.Trait=function(){function l(z){var y=function(){throw new Error("Conflicting property: "+z);};D(y.prototype);return D(y)}function j(){return D({value:undefined,enumerable:false,required:true})}function h(z){z=l(z);return p?D({get:z,set:z,enumerable:false,conflict:true}):D({value:z,enumerable:false,conflict:true})}function d(z,y){return z===y?z!==0||1/z===1/y:z!==z&&y!==y}function b(z,y){return z.conflict&&y.conflict?true:z.get===y.get&&z.set===y.set&&
d(z.value,y.value)&&z.enumerable===y.enumerable&&z.required===y.required&&z.conflict===y.conflict}function a(z,y){return D(v(z,y))}function i(z){var y={};E(z,function(A){y[A]=true});return D(y)}function e(z){var y={};E(G(z),function(A){var B=H(z,A);if(B.value===M)B=j(A);else if(typeof B.value==="function"){B.method=true;"prototype"in B.value&&D(B.value.prototype)}else{B.get&&B.get.prototype&&D(B.get.prototype);B.set&&B.set.prototype&&D(B.set.prototype)}y[A]=B});return y}function g(){var z=C(arguments,
0),y={};E(z,function(A){E(G(A),function(B){var F=A[B];if(x(y,B)&&!y[B].required)F.required||b(y[B],F)||(y[B]=h(B));else y[B]=F})});return D(y)}function o(z,y){var A=i(z),B={};E(G(y),function(F){B[F]=!x(A,F)||y[F].required?y[F]:j(F)});return D(B)}function f(){var z=C(arguments,0),y={};E(z,function(A){E(G(A),function(B){var F=A[B];if(!x(y,B)||y[B].required)y[B]=F})});return D(y)}function m(z,y){var A={};E(G(y),function(B){if(x(z,B)&&!y[B].required){var F=z[B];A[F]=x(A,F)&&!A[F].required?h(F):y[B];x(A,
B)||(A[B]=j(B))}else if(x(A,B))y[B].required||(A[B]=h(B));else A[B]=y[B]});return D(A)}function s(z,y){var A={},B=[];for(var F in z)if(x(z,F))if(z[F])A[F]=z[F];else B.push(F);return m(A,o(B,y))}function n(z,y){var A=J(z),B={};E(G(y),function(F){var I=y[F];if(I.required&&!(F in z))throw new Error("Missing required property: "+F);else if(I.conflict)throw new Error("Remaining conflicting property: "+F);else B[F]="value"in I?I.method?{value:a(I.value,A),enumerable:I.enumerable,configurable:I.configurable,
writable:I.writable}:I:{get:I.get?a(I.get,A):undefined,set:I.set?a(I.set,A):undefined,enumerable:I.enumerable,configurable:I.configurable,writable:I.writable}});K(A,B);return D(A)}function t(z,y){return n(Object.prototype,e(z),y)}function u(z,y){var A=G(z),B=G(y);if(A.length!==B.length)return false;for(var F=0;F<A.length;F++){B=A[F];if(!y[B]||!b(z[B],y[B]))return false}return true}function w(z){return e(z)}var p=!!Object.defineProperty,r=Function.prototype.call,v=Function.prototype.bind?function(z,
y){return Function.prototype.bind.call(z,y)}:function(z,y){function A(){return z.apply(y,arguments)}return A},x=v(r,Object.prototype.hasOwnProperty),C=v(r,Array.prototype.slice),E=Array.prototype.forEach?v(r,Array.prototype.forEach):function(z,y){for(var A=0,B=z.length;A<B;A++)y(z[A])},D=Object.freeze||function(z){return z},G=Object.getOwnPropertyNames||function(z){var y=[];for(var A in z)x(z,A)&&y.push(A);return y},H=Object.getOwnPropertyDescriptor||function(z,y){return{value:z[y],enumerable:true,
writable:true,configurable:true}},L=Object.defineProperty||function(z,y,A){z[y]=A.value},K=Object.defineProperties||function(z,y){for(var A in y)x(y,A)&&L(z,A,y[A])},J=Object.create||function(z,y){function A(){}A.prototype=z||Object.prototype;z=new A;y&&K(z,y);return z};r=Object.getOwnProperties||function(z){var y={};E(G(z),function(A){y[A]=H(z,A)});return y};var M=D({toString:function(){return"<Trait.required>"}});if(!Object.create)Object.create=J;if(!Object.getOwnProperties)Object.getOwnProperties=
r;w.required=D(M);w.compose=D(g);w.resolve=D(s);w.override=D(f);w.create=D(n);w.eqv=D(u);w.object=D(t);return D(w)}()});bespin.tiki.register("::less",{name:"less",dependencies:{}});
bespin.tiki.module("less:index",function(q,k){function l(b){if(b instanceof d.Dimension)return parseFloat(b.unit=="%"?b.value/100:b.value);else if(typeof b==="number")return b;else throw{error:"RuntimeError",message:"color functions take numbers as parameters"};}function j(b){return Math.min(1,Math.max(0,b))}if(!Array.isArray)Array.isArray=function(b){return Object.prototype.toString.call(b)==="[object Array]"||b instanceof Array};if(!Array.prototype.forEach)Array.prototype.forEach=function(b,a){for(var i=
this.length>>>0,e=0;e<i;e++)e in this&&b.call(a,this[e],e,this)};if(!Array.prototype.map)Array.prototype.map=function(b,a){for(var i=this.length>>>0,e=new Array(i),g=0;g<i;g++)if(g in this)e[g]=b.call(a,this[g],g,this);return e};if(!Array.prototype.filter)Array.prototype.filter=function(b,a){for(var i=[],e=0;e<this.length;e++)b.call(a,this[e])&&i.push(this[e]);return i};if(!Array.prototype.reduce)Array.prototype.reduce=function(b){var a=this.length>>>0,i=0;if(a===0&&arguments.length===1)throw new TypeError;
if(arguments.length>=2)var e=arguments[1];else{do{if(i in this){e=this[i++];break}if(++i>=a)throw new TypeError;}while(1)}for(;i<a;i++)if(i in this)e=b.call(null,e,this[i],i,this);return e};if(!Array.prototype.indexOf)Array.prototype.indexOf=function(b,a){var i=this.length;a=a||0;if(!i)return-1;if(a>=i)return-1;if(a<0)a+=i;for(;a<i;a++)if(Object.prototype.hasOwnProperty.call(this,a))if(b===this[a])return a;return-1};if(!Object.keys)Object.keys=function(b){var a=[];for(var i in b)Object.prototype.hasOwnProperty.call(b,
i)&&a.push(i);return a};if(!String.prototype.trim)String.prototype.trim=function(){return String(this).replace(/^\s\s*/,"").replace(/\s\s*$/,"")};if(typeof q!=="undefined")var h=k,d={};else h=d={};h.Parser=function(b){function a(p){var r,v,x;if(p instanceof Function)return p.call(n.parsers);else if(typeof p==="string"){r=e.charAt(g)===p?p:null;v=1}else{if(g>=s+m[o].length&&o<m.length-1)s+=m[o++].length;p.lastIndex=x=g-s;if(r=p.exec(m[o])){v=r[0].length;if(p.lastIndex-v!==x)return}}if(r){g+=v;for(v=
s+m[o].length;g<=v;){p=e.charCodeAt(g);if(!(p===32||p===10||p===9))break;g++}return typeof r==="string"?r:r.length===1?r[0]:r}}function i(p){var r;if(typeof p==="string")return e.charAt(g)===p;else{p.lastIndex=g;if((r=p.exec(e))&&p.lastIndex-r[0].length===g)return r}}var e,g,o,f,m,s,n,t=this,u=function(){},w=this.imports={paths:b&&b.paths||[],queue:[],files:{},push:function(p,r){var v=this;this.queue.push(p);h.Parser.importer(p,this.paths,function(x){v.queue.splice(v.queue.indexOf(p),1);v.files[p]=
x;r(x);v.queue.length===0&&u()})}};this.env=b||{};this.optimization="optimization"in this.env?this.env.optimization:1;return n={imports:w,parse:function(p,r){var v,x,C=null;g=o=s=f=0;m=[];e=p.replace(/\r\n/g,"\n");if(t.optimization>0){e=e.replace(/\/\*(?:[^*]|\*+[^\/*])*\*+\//g,function(G){return t.optimization>1?"":G.replace(/\n(\s*\n)+/g,"\n")});m=e.split(/^(?=\n)/mg)}else m=[e];v=new d.Ruleset([],a(this.parsers.primary));v.root=true;v.toCSS=function(G){var H,L;return function(){try{return G.call(this)}catch(K){L=
e.split("\n");H=(e.slice(0,K.index).match(/\n/g)||"").length+1;for(var J=K.index,M=-1;J>=0&&e.charAt(J)!=="\n";J--)M++;throw{name:"NameError",message:K.message,line:H,column:M,extract:[L[H-2],L[H-1],L[H]]};}}}(v.toCSS);if(g<e.length-1){g=f;x=e.split("\n");p=(e.slice(0,g).match(/\n/g)||"").length+1;for(var E=g,D=-1;E>=0&&e.charAt(E)!=="\n";E--)D++;C={name:"ParseError",message:"Syntax Error on line "+p,filename:b.filename,line:p,column:D,extract:[x[p-2],x[p-1],x[p]]}}if(this.imports.queue.length>0)u=
function(){r(C,v)};else r(C,v)},parsers:{primary:function(){for(var p,r=[];p=a(this.mixin.definition)||a(this.rule)||a(this.ruleset)||a(this.mixin.call)||a(this.comment)||a(/[\n\s]+/g)||a(this.directive);)r.push(p);return r},comment:function(){var p;if(e.charAt(g)==="/")return(p=a(/\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/g))?new d.Comment(p):a(/\/\/.*/g)},entities:{quoted:function(){var p;if(!(e.charAt(g)!=='"'&&e.charAt(g)!=="'"))if(p=a(/"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'/g))return new d.Quoted(p[0],
p[1]||p[2])},keyword:function(){var p;if(p=a(/[A-Za-z-]+/g))return new d.Keyword(p)},call:function(){var p,r;if(p=a(/([a-zA-Z0-9_-]+|%)\(/g)){if(p[1].toLowerCase()==="alpha")return a(this.alpha);r=a(this.entities.arguments);if(a(")"))if(p)return new d.Call(p[1],r)}},arguments:function(){for(var p=[],r;r=a(this.expression);){p.push(r);if(!a(","))break}return p},literal:function(){return a(this.entities.dimension)||a(this.entities.color)||a(this.entities.quoted)},url:function(){var p;if(!(e.charAt(g)!==
"u"||!a(/url\(/g))){p=a(this.entities.quoted)||a(/[-a-zA-Z0-9_%@$\/.&=:;#+?]+/g);if(!a(")"))throw new Error("missing closing ) for url()");return new d.URL(p.value?p:new d.Anonymous(p))}},variable:function(){var p,r=g;if(e.charAt(g)==="@"&&(p=a(/@[a-zA-Z0-9_-]+/g)))return new d.Variable(p,r)},color:function(){var p;if(e.charAt(g)==="#"&&(p=a(/#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})/g)))return new d.Color(p[1])},dimension:function(){var p;p=e.charCodeAt(g);if(!(p>57||p<45||p===47))if(p=a(/(-?[0-9]*\.?[0-9]+)(px|%|em|pc|ex|in|deg|s|ms|pt|cm|mm)?/g))return new d.Dimension(p[1],
p[2])}},variable:function(){var p;if(e.charAt(g)==="@"&&(p=a(/(@[a-zA-Z0-9_-]+)\s*:/g)))return p[1]},shorthand:function(){var p,r;if(i(/[@\w.-]+\/[@\w.-]+/g))if((p=a(this.entity))&&a("/")&&(r=a(this.entity)))return new d.Shorthand(p,r)},mixin:{call:function(){for(var p=[],r,v,x,C=g;r=a(/[#.][a-zA-Z0-9_-]+/g);){p.push(new d.Element(v,r));v=a(">")}a("(")&&(x=a(this.entities.arguments))&&a(")");if(p.length>0&&(a(";")||i("}")))return new d.mixin.Call(p,x,C)},definition:function(){var p,r=[],v,x;if(!(e.charAt(g)!==
"."||i(/[^{]*(;|})/g)))if(p=a(/([#.][a-zA-Z0-9_-]+)\s*\(/g)){for(p=p[1];v=a(/@[\w-]+/g)||a(this.entities.literal)||a(this.entities.keyword);){if(v[0]==="@")if(a(":"))if(x=a(this.expression))r.push({name:v,value:x});else throw new Error("Expected value");else r.push({name:v});else r.push({value:v});if(!a(","))break}if(!a(")"))throw new Error("Expected )");if(v=a(this.block))return new d.mixin.Definition(p,r,v)}}},entity:function(){return a(this.entities.literal)||a(this.entities.variable)||a(this.entities.url)||
a(this.entities.call)||a(this.entities.keyword)},end:function(){return a(";")||i("}")},alpha:function(){var p;if(a(/opacity=/gi))if(p=a(/[0-9]+/g)||a(this.entities.variable)){if(!a(")"))throw new Error("missing closing ) for alpha()");return new d.Alpha(p)}},element:function(){var p;c=a(this.combinator);if(p=a(/[.#:]?[a-zA-Z0-9_-]+/g)||a("*")||a(this.attribute)||a(/\([^)@]+\)/g))return new d.Element(c,p)},combinator:function(){var p;return(p=a(/[+>~]/g)||a("&")||a(/::/g))?new d.Combinator(p):new d.Combinator(e.charAt(g-
1)===" "?" ":null)},selector:function(){for(var p,r=[];p=a(this.element);)r.push(p);if(r.length>0)return new d.Selector(r)},tag:function(){return a(/[a-zA-Z][a-zA-Z-]*[0-9]?/g)||a("*")},attribute:function(){var p="",r,v,x;if(a("[")){if(r=a(/[a-z-]+/g)||a(this.entities.quoted))p=(x=a(/[|~*$^]?=/g))&&(v=a(this.entities.quoted)||a(/[\w-]+/g))?[r,x,v.toCSS?v.toCSS():v].join(""):r;if(a("]"))if(p)return"["+p+"]"}},block:function(){var p;if(a("{")&&(p=a(this.primary))&&a("}"))return p},ruleset:function(){var p=
[],r,v,x=g;if(r=i(/([a-z.#: _-]+)[\s\n]*\{/g)){g+=r[0].length-1;p=[new d.Selector([new d.Element(null,r[1])])]}else{for(;r=a(this.selector);){p.push(r);if(!a(","))break}r&&a(this.comment)}if(p.length>0&&(v=a(this.block)))return new d.Ruleset(p,v);else{f=g;g=x}},rule:function(){var p,r=g;if(name=a(this.property)||a(this.variable)){if(name.charAt(0)!="@"&&(match=i(/([^@+\/*(;{}-]*);/g))){g+=match[0].length-1;p=new d.Anonymous(match[1])}else p=name==="font"?a(this.font):a(this.value);if(a(this.end))return new d.Rule(name,
p,r);else{f=g;g=r}}},"import":function(){var p;if(a(/@import\s+/g)&&(p=a(this.entities.quoted)||a(this.entities.url))&&a(";"))return new d.Import(p,w)},directive:function(){var p,r,v;if(e.charAt(g)==="@")if(r=a(this["import"]))return r;else if(p=a(/@media|@page/g)){v=a(/[^{]+/g).trim();if(r=a(this.block))return new d.Directive(p+" "+v,r)}else if(p=a(/@[-a-z]+/g))if(p==="@font-face"){if(r=a(this.block))return new d.Directive(p,r)}else if((r=a(this.entity))&&a(";"))return new d.Directive(p,r)},font:function(){for(var p=
[],r=[],v;v=a(this.shorthand)||a(this.entity);)r.push(v);p.push(new d.Expression(r));if(a(","))for(;v=a(this.expression);){p.push(v);if(!a(","))break}return new d.Value(p,a(this.important))},value:function(){for(var p,r=[];p=a(this.expression);){r.push(p);if(!a(","))break}p=a(this.important);if(r.length>0)return new d.Value(r,p)},important:function(){return a(/!\s*important/g)},sub:function(){var p;if(a("(")&&(p=a(this.expression))&&a(")"))return p},multiplication:function(){var p,r,v,x;if(p=a(this.operand)){for(;(v=
a(/[\/*]/g))&&(r=a(this.operand));)x=new d.Operation(v,[x||p,r]);return x||p}},addition:function(){var p,r,v,x;if(p=a(this.multiplication)){for(;(v=a(/[-+]\s+/g)||e.charAt(g-1)!=" "&&a(/[-+]/g))&&(r=a(this.multiplication));)x=new d.Operation(v,[x||p,r]);return x||p}},operand:function(){return a(this.sub)||a(this.entities.dimension)||a(this.entities.color)||a(this.entities.variable)},expression:function(){for(var p,r=[];p=a(this.addition)||a(this.entity);)r.push(p);if(r.length>0)return new d.Expression(r)},
property:function(){var p;if(p=a(/(\*?-?[-a-z_0-9]+)\s*:/g))return p[1]}}}};h.Parser.importer=null;d.functions={rgb:function(b,a,i){return this.rgba(b,a,i,1)},rgba:function(b,a,i,e){b=[b,a,i].map(function(g){return l(g)});e=l(e);return new d.Color(b,e)},hsl:function(b,a,i){return this.hsla(b,a,i,1)},hsla:function(b,a,i,e){function g(m){m=m<0?m+1:m>1?m-1:m;return m*6<1?f+(o-f)*m*6:m*2<1?o:m*3<2?f+(o-f)*(2/3-m)*6:f}b=(l(b)%360+360)%360/360;a=l(a);i=l(i);e=l(e);var o=i<=0.5?i*(a+1):i+a-i*a,f=i*2-o;return this.rgba(g(b+
1/3)*255,g(b)*255,g(b-1/3)*255,e)},opacity:function(b,a){l(a);return new d.Color(b.rgb,l(a))},saturate:function(b,a){b=b.toHSL();b.s+=a.value/100;b.s=j(b.s);return this.hsl(b.h,b.s,b.l)},desaturate:function(b,a){b=b.toHSL();b.s-=a.value/100;b.s=j(b.s);return this.hsl(b.h,b.s,b.l)},lighten:function(b,a){b=b.toHSL();b.l*=1+a.value/100;b.l=j(b.l);return this.hsl(b.h,b.s,b.l)},darken:function(b,a){b=b.toHSL();b.l*=1-a.value/100;b.l=j(b.l);return this.hsl(b.h,b.s,b.l)},greyscale:function(b){return this.desaturate(b,
new d.Dimension(100))},e:function(b){return new d.Anonymous(b)},"%":function(b){for(var a=Array.prototype.slice.call(arguments,1),i=b.content,e=0;e<a.length;e++)i=i.replace(/%s/,a[e].content).replace(/%[da]/,a[e].toCSS());i=i.replace(/%%/g,"%");return new d.Quoted('"'+i+'"',i)}};d.Alpha=function(b){this.value=b};d.Alpha.prototype={toCSS:function(){return"alpha(opacity="+this.value.toCSS()+")"},eval:function(){return this}};d.Anonymous=function(b){this.value=b.content||b};d.Anonymous.prototype={toCSS:function(){return this.value},
eval:function(){return this}};d.Call=function(b,a){this.name=b;this.args=a};d.Call.prototype={eval:function(b){var a=this.args.map(function(i){return i.eval(b)});return this.name in d.functions?d.functions[this.name].apply(d.functions,a):new d.Anonymous(this.name+"("+a.map(function(i){return i.toCSS()}).join(", ")+")")},toCSS:function(b){return this.eval(b).toCSS()}};d.Color=function(b,a){if(Array.isArray(b)){this.rgb=b;this.alpha=a}else this.rgb=b.length==6?b.match(/.{2}/g).map(function(i){return parseInt(i,
16)}):b.split("").map(function(i){return parseInt(i+i,16)})};d.Color.prototype={eval:function(){return this},toCSS:function(){return this.alpha&&this.alpha<1?"rgba("+this.rgb.concat(this.alpha).join(", ")+")":"#"+this.rgb.map(function(b){b=Math.round(b);b=(b>255?255:b<0?0:b).toString(16);return b.length===1?"0"+b:b}).join("")},operate:function(b,a){var i=[];a instanceof d.Color||(a=a.toColor());for(var e=0;e<3;e++)i[e]=d.operate(b,this.rgb[e],a.rgb[e]);return new d.Color(i)},toHSL:function(){var b=
this.rgb[0]/255,a=this.rgb[1]/255,i=this.rgb[2]/255,e=Math.max(b,a,i),g=Math.min(b,a,i),o,f=(e+g)/2,m=e-g;if(e===g)o=g=0;else{g=f>0.5?m/(2-e-g):m/(e+g);switch(e){case b:o=(a-i)/m+(a<i?6:0);break;case a:o=(i-b)/m+2;break;case i:o=(b-a)/m+4;break}o/=6}return{h:o*360,s:g,l:f}}};d.Comment=function(b){this.value=b};d.Comment.prototype={toCSS:function(){return this.value}};d.Dimension=function(b,a){this.value=parseFloat(b);this.unit=a||null};d.Dimension.prototype={eval:function(){return this},toColor:function(){return new d.Color([this.value,
this.value,this.value])},toCSS:function(){return this.value+this.unit},operate:function(b,a){return new d.Dimension(d.operate(b,this.value,a.value),this.unit||a.unit)}};d.Directive=function(b,a){this.name=b;if(Array.isArray(a))this.ruleset=new d.Ruleset([],a);else this.value=a};d.Directive.prototype={toCSS:function(b,a){if(this.ruleset){this.ruleset.root=true;return this.name+" {\n  "+this.ruleset.toCSS(b,a).trim().replace(/\n/g,"\n  ")+"\n}\n"}else return this.name+" "+this.value.toCSS()+";\n"},
eval:function(b){b.frames.unshift(this);this.ruleset&&this.ruleset.evalRules(b);b.frames.shift();return this},variable:function(b){return d.Ruleset.prototype.variable.call(this.ruleset,b)},find:function(){return d.Ruleset.prototype.find.apply(this.ruleset,arguments)},rulesets:function(){return d.Ruleset.prototype.rulesets.apply(this.ruleset)}};d.Element=function(b,a){this.combinator=b instanceof d.Combinator?b:new d.Combinator(b);this.value=a.trim()};d.Element.prototype.toCSS=function(){return this.combinator.toCSS()+
this.value};d.Combinator=function(b){this.value=b===" "?" ":b?b.trim():""};d.Combinator.prototype.toCSS=function(){switch(this.value){case "":return"";case " ":return" ";case "&":return"";case ":":return" :";case "::":return"::";case "+":return" + ";case "~":return" ~ ";case ">":return" > "}};d.Expression=function(b){this.value=b};d.Expression.prototype={eval:function(b){return this.value.length>1?new d.Expression(this.value.map(function(a){return a.eval(b)})):this.value[0].eval(b)},toCSS:function(){return this.value.map(function(b){return b.toCSS()}).join(" ")}};
d.Import=function(b,a){var i=this;this._path=b;this.path=b instanceof d.Quoted?/\.(le?|c)ss$/.test(b.content)?b.content:b.content+".less":b.value.content||b.value;(this.css=/css$/.test(this.path))||a.push(this.path,function(e){i.root=e})};d.Import.prototype={toCSS:function(){return this.css?"@import "+this._path.toCSS()+";\n":""},eval:function(){if(this.css)return this;else{for(var b=0;b<this.root.rules.length;b++)this.root.rules[b]instanceof d.Import&&Array.prototype.splice.apply(this.root.rules,
[b,1].concat(this.root.rules[b].eval()));return this.root.rules}}};d.Keyword=function(b){this.value=b};d.Keyword.prototype={eval:function(){return this},toCSS:function(){return this.value}};d.mixin={};d.mixin.Call=function(b,a,i){this.selector=new d.Selector(b);this.arguments=a;this.index=i};d.mixin.Call.prototype={eval:function(b){for(var a,i=[],e=false,g=0;g<b.frames.length;g++)if((a=b.frames[g].find(this.selector)).length>0){for(g=0;g<a.length;g++)if(a[g].match(this.arguments,b))try{Array.prototype.push.apply(i,
a[g].eval(this.arguments,b).rules);e=true}catch(o){throw{message:o.message,index:this.index};}if(e)return i;else throw{message:"No matching definition was found for `"+this.selector.toCSS().trim()+"("+this.arguments.map(function(f){return f.toCSS()}).join(", ")+")`",index:this.index};}throw{message:this.selector.toCSS().trim()+" is undefined",index:this.index};}};d.mixin.Definition=function(b,a,i){this.name=b;this.selectors=[new d.Selector([new d.Element(null,b)])];this.params=a;this.arity=a.length;
this.rules=i;this._lookups={};this.required=a.reduce(function(e,g){return g.name&&!g.value?e+1:e},0)};d.mixin.Definition.prototype={toCSS:function(){return""},variable:function(b){return d.Ruleset.prototype.variable.call(this,b)},find:function(){return d.Ruleset.prototype.find.apply(this,arguments)},rulesets:function(){return d.Ruleset.prototype.rulesets.apply(this)},eval:function(b,a){for(var i=new d.Ruleset(null,[]),e=0,g;e<this.params.length;e++)if(this.params[e].name)if(g=b&&b[e]||this.params[e].value)i.rules.unshift(new d.Rule(this.params[e].name,
g.eval(a)));else throw{message:"wrong number of arguments for "+this.name+" ("+b.length+" for "+this.arity+")"};return(new d.Ruleset(null,this.rules)).evalRules({frames:[this,i].concat(a.frames)})},match:function(b,a){var i=b&&b.length||0;if(i<this.required)return false;for(var e=0;e<Math.min(i,this.arity);e++)if(!this.params[e].name)if(!b[e].wildcard)if(b[e].eval(a).toCSS()!=this.params[e].value.eval(a).toCSS())return false;return true}};d.Operation=function(b,a){this.op=b.trim();this.operands=a};
d.Operation.prototype.eval=function(b){var a=this.operands[0].eval(b);b=this.operands[1].eval(b);var i;if(a instanceof d.Dimension&&b instanceof d.Color)if(this.op==="*"||this.op==="+"){i=b;b=a;a=i}else throw{name:"OperationError",message:"Can't substract or divide a color from a number"};return a.operate(this.op,b)};d.operate=function(b,a,i){switch(b){case "+":return a+i;case "-":return a-i;case "*":return a*i;case "/":return a/i}};d.Quoted=function(b,a){this.value=b;this.content=a};d.Quoted.prototype=
{toCSS:function(){return this.value},eval:function(){return this}};d.Rule=function(b,a,i){this.name=b;this.value=a instanceof d.Value?a:new d.Value([a]);this.index=i;this.variable=b.charAt(0)==="@"?true:false};d.Rule.prototype.toCSS=function(){return this.variable?"":this.name+": "+this.value.toCSS()+";"};d.Rule.prototype.eval=function(b){return new d.Rule(this.name,this.value.eval(b))};d.Value=function(b){this.value=b;this.is="value"};d.Value.prototype={eval:function(b){return this.value.length===
1?this.value[0].eval(b):new d.Value(this.value.map(function(a){return a.eval(b)}))},toCSS:function(){return this.value.map(function(b){return b.toCSS()}).join(", ")}};d.Shorthand=function(b,a){this.a=b;this.b=a};d.Shorthand.prototype={toCSS:function(b){return this.a.toCSS(b)+"/"+this.b.toCSS(b)},eval:function(){return this}};d.Ruleset=function(b,a){this.selectors=b;this.rules=a;this._lookups={}};d.Ruleset.prototype={eval:function(){return this},evalRules:function(b){var a=[];this.rules.forEach(function(i){if(i.evalRules)a.push(i.evalRules(b));
else i instanceof d.mixin.Call?Array.prototype.push.apply(a,i.eval(b)):a.push(i.eval(b))});this.rules=a;return this},match:function(b){return!b||b.length===0},variable:function(b){return this._variables?this._variables[b]:(this._variables=this.rules.reduce(function(a,i){if(i instanceof d.Rule&&i.variable===true)a[i.name]=i;return a},{}))[b]},rulesets:function(){return this._rulesets?this._rulesets:(this._rulesets=this.rules.filter(function(b){if(b instanceof d.Ruleset||b instanceof d.mixin.Definition)return b}))},
find:function(b,a){a=a||this;var i=[],e=b.toCSS();if(e in this._lookups)return this._lookups[e];this.rulesets().forEach(function(g){if(g!==a)for(var o=0;o<g.selectors.length;o++)if(b.match(g.selectors[o])){b.elements.length>1?Array.prototype.push.apply(i,g.find(new d.Selector(b.elements.slice(1)),a)):i.push(g);break}});return this._lookups[e]=i},toCSS:function(b,a){var i=[],e=[],g=[],o=[];if(this.root){b=[];a={frames:[]};for(var f=0;f<this.rules.length;f++)this.rules[f]instanceof d.Import&&Array.prototype.splice.apply(this.rules,
[f,1].concat(this.rules[f].eval(a)))}else if(b.length===0)o=this.selectors.map(function(s){return[s]});else for(f=0;f<this.selectors.length;f++)for(var m=0;m<b.length;m++)o.push(b[m].concat([this.selectors[f]]));a.frames.unshift(this);for(f=0;f<this.rules.length;f++)this.rules[f]instanceof d.mixin.Call&&Array.prototype.splice.apply(this.rules,[f,1].concat(this.rules[f].eval(a)));for(f=0;f<this.rules.length;f++){b=this.rules[f];if(b instanceof d.Directive)g.push(b.eval(a).toCSS(o,a));else if(b.rules)g.push(b.toCSS(o,
a));else if(b instanceof d.Comment)this.root?g.push(b.toCSS()):e.push(b.toCSS());else if(b.toCSS&&!b.variable)e.push(b.eval(a).toCSS());else b.value&&!b.variable&&e.push(b.value.toString())}g=g.join("");if(this.root)i.push(e.join("\n"));else if(e.length>0){o=o.map(function(s){return s.map(function(n){return n.toCSS()}).join("").trim()}).join(o.length>3?",\n":", ");i.push(o," {\n  "+e.join("\n  ")+"\n}\n")}i.push(g);a.frames.shift();return i.join("")}};d.Selector=function(b){this.elements=b;if(this.elements[0].combinator.value===
"")this.elements[0].combinator.value=" "};d.Selector.prototype.match=function(b){return this.elements[0].value===b.elements[0].value?true:false};d.Selector.prototype.toCSS=function(){if(this._css)return this._css;return this._css=this.elements.map(function(b){return typeof b==="string"?" "+b.trim():b.toCSS()}).join("")};d.URL=function(b){this.value=b};d.URL.prototype={toCSS:function(){return"url("+this.value.toCSS()+")"},eval:function(){return this}};d.Variable=function(b,a){this.name=b;this.index=
a};d.Variable.prototype={eval:function(b){var a,i,e=this.name;if(a=d.find(b.frames,function(g){if(i=g.variable(e))return i.value.eval(b)}))return a;else throw{message:"variable "+this.name+" is undefined",index:this.index};}};d.find=function(b,a){for(var i=0,e;i<b.length;i++)if(e=a.call(b,b[i]))return e;return null};(function(){function b(n){for(var t=0;t<m.length;t++)a(m[t],n)}function a(n,t){var u=typeof localStorage!=="undefined"&&localStorage.getItem(n.href),w=u&&JSON.parse(u);e(n.href,function(p,
r){if(w&&(new Date(r)).valueOf()===(new Date(w.timestamp)).valueOf()){i(w.css,n);t(null,n,{local:true})}else(new h.Parser({optimization:3})).parse(p,function(v,x){if(v)return f(v,n.href);try{t(x,n,{local:false,lastModified:r})}catch(C){f(C,n.href)}})},function(p){throw new Error("Couldn't load "+n.href+" ("+p+")");})}function i(n,t,u){var w=document.createElement("style");w.type="text/css";w.media="screen";w.title="less-sheet";if(t){w.title=t.title||t.href.match(/(?:^|\/)([-\w]+)\.[a-z]+$/i)[1];u&&
typeof localStorage!=="undefined"&&localStorage.setItem(t.href,JSON.stringify({timestamp:u,css:n}))}if(w.styleSheet)w.styleSheet.cssText=n;else w.appendChild(document.createTextNode(n));document.getElementsByTagName("head")[0].appendChild(w)}function e(n,t,u){var w=g();if(window.location.protocol==="file:"){w.open("GET",n,false);w.send(null);w.status===0?t(w.responseText):u(w.status)}else{w.open("GET",n,true);w.onreadystatechange=function(){if(w.readyState==4)if(w.status>=200&&w.status<300)t(w.responseText,
w.getResponseHeader("Last-Modified"));else typeof u==="function"&&u(w.status)};w.send(null)}}function g(){if(window.XMLHttpRequest)return new XMLHttpRequest;else try{return new ActiveXObject("MSXML2.XMLHTTP.3.0")}catch(n){o("less: browser doesn't support AJAX.");return null}}function o(n){h.env=="development"&&typeof console!=="undefined"&&console.log(n)}function f(n,t){var u=document.createElement("div"),w;u.id="less-error-message";u.innerHTML="<h3>"+(n.message||"There is an error in your .less file")+
'</h3><p><a href="'+t+'">'+t+"</a> on line "+n.line+", column "+(n.column+1)+":</p>"+'<div>\n<pre class="ctx"><span>[-1]</span>{0}</pre>\n<pre><span>[0]</span>{current}</pre>\n<pre class="ctx"><span>[1]</span>{2}</pre>\n</div>'.replace(/\[(-?\d)\]/g,function(p,r){return n.line+parseInt(r)}).replace(/\{(\d)\}/g,function(p,r){return n.extract[parseInt(r)]}).replace(/\{current\}/,n.extract[1].slice(0,n.column)+'<span class="error">'+n.extract[1].slice(n.column)+"</span>");i("#less-error-message span {margin-right: 15px;}#less-error-message pre {color: #ee4444;padding: 4px 0;margin: 0;}#less-error-message pre.ctx {color: #dd7777;}#less-error-message h3 {padding: 15px 0 5px 0;margin: 0;}#less-error-message a {color: #10a}#less-error-message .error {color: red;font-weight: bold;padding-bottom: 2px;border-bottom: 1px dashed red;}");
u.style.cssText="font-family: Arial, sans-serif;border: 1px solid #e00;background-color: #eee;border-radius: 5px;color: #e00;padding: 15px;margin-bottom: 15px";if(h.env=="development")w=setInterval(function(){if(document.body){document.body.insertBefore(u,document.body.childNodes[0]);clearInterval(w)}},10)}var m=[];h.env=location.hostname=="127.0.0.1"||location.hostname=="0.0.0.0"||location.hostname=="localhost"||location.protocol=="file:"?"development":"production";var s=setInterval(function(){if(document.body){if(!document.querySelectorAll&&
typeof jQuery==="undefined")o("No selector method found");else m=(document.querySelectorAll||jQuery).call(document,'link[rel="stylesheet/less"]');clearInterval(s);b(function(n,t,u){i(n.toCSS(),t,u.lastModified);u.local?o("less: loading "+t.href+" from local storage."):o("less: parsed "+t.href+" successfully.")})}},10);if(h.env==="development")refreshTimer=setInterval(function(){/!refresh/.test(location.hash)&&b(function(n,t,u){i(n.toCSS(),t,u)})},1E3);h.Parser.importer=function(n,t,u){a({href:n,title:n},
function(w){u(w)})}})()});bespin.tiki.register("::appconfig",{name:"appconfig",dependencies:{jquery:"0.0.0",canon:"0.0.0",settings:"0.0.0"}});
bespin.tiki.module("appconfig:index",function(q,k){var l=q("jquery").$,j=q("settings").settings,h=q("bespin:plugins").catalog,d=q("bespin:promise").group,b=q("bespin:promise").Promise,a=q("bespin:console").console,i=q("bespin:util/stacktrace").Trace,e=q("bespin:util/util");k.launch=function(f){var m=new b;l("#_bespin_loading").remove();f=f||{};k.normalizeConfig(f);var s=f.objects;for(var n in s)h.registerObject(n,s[n]);for(var t in f.settings)j.set(t,f.settings[t]);var u=function(){var p=q("canon:environment").global,
r=p.editor;if(r){f.lineNumber&&r.setLineNumber(f.lineNumber);if(f.stealFocus)r.focus=true;if(f.readOnly)r.readOnly=f.readOnly;if(f.syntax)r.syntax=f.syntax}if(r=h.getObject("commandLine"))p.commandLine=r;h.publish(this,"appLaunched");m.resolve(p)}.bind(this),w=new b;w.then(function(){s.loginController?h.createObject("loginController").then(function(p){p.showLogin().then(function(r){f.objects.session.arguments.push(r);k.launchEditor(f).then(u,m.reject.bind(m))})}):k.launchEditor(f).then(u,m.reject.bind(m))},
function(p){m.reject(p)});h.plugins.theme_manager?bespin.tiki.require.ensurePackage("::theme_manager",function(){var p=q("theme_manager");f.theme.basePlugin&&p.setBasePlugin(f.theme.basePlugin);f.theme.standard&&p.setStandardTheme(f.theme.standard);p.startParsing().then(function(){w.resolve()},function(r){w.reject(r)})}):w.resolve();return m};k.normalizeConfig=function(f){if(f.objects===undefined)f.objects={};if(f.autoload===undefined)f.autoload=[];if(f.theme===undefined)f.theme={};if(!f.theme.basePlugin&&
h.plugins.screen_theme)f.theme.basePlugin="screen_theme";if(!f.initialContent)f.initialContent="";if(!f.settings)f.settings={};if(!f.objects.notifier&&h.plugins.notifier)f.objects.notifier={};if(!f.objects.loginController&&h.plugins.userident)f.objects.loginController={};if(!f.objects.fileHistory&&h.plugins.file_history)f.objects.fileHistory={factory:"file_history",arguments:["session"],objects:{"0":"session"}};if(!f.objects.server&&h.plugins.bespin_server){f.objects.server={factory:"bespin_server"};
f.objects.filesource={factory:"bespin_filesource",arguments:["server"],objects:{"0":"server"}}}if(!f.objects.files&&h.plugins.filesystem&&f.objects.filesource)f.objects.files={arguments:["filesource"],objects:{"0":"filesource"}};if(!f.objects.editor)f.objects.editor={factory:"text_editor",arguments:[f.initialContent]};if(!f.objects.session)f.objects.session={arguments:["editor"],objects:{"0":"editor"}};if(!f.objects.commandLine&&h.plugins.command_line)f.objects.commandLine={};if(f.gui===undefined)f.gui=
{};var m={};for(var s in f.gui){var n=f.gui[s];if(n.component)m[n.component]=true}if(!f.gui.center&&f.objects.editor&&!m.editor)f.gui.center={component:"editor"};if(!f.gui.south&&f.objects.commandLine&&!m.commandLine)f.gui.south={component:"commandLine"}};k.launchEditor=function(f){var m=new b;if(f===null){a.error("Cannot start editor without a configuration!");m.reject("Cannot start editor without a configuration!");return m}g(f).then(function(){o(f,m)},function(s){a.error("Error while creating objects");
(new i(s)).log();m.reject(s)});return m};var g=function(f){var m=[];for(var s in f.objects)m.push(h.createObject(s));return d(m)},o=function(f,m){var s=document.createElement("div");s.setAttribute("class","container");var n=document.createElement("div");n.setAttribute("class","center-container");s.appendChild(n);var t=f.element||document.body;e.addClass(t,"bespin");t.appendChild(s);for(var u in f.gui){var w=f.gui[u],p=h.getObject(w.component);if(!p){f="Cannot find object "+w.component+" to attach to the Bespin UI";
a.error(f);m.reject(f);return}t=p.element;if(!t){f="Component "+w.component+' does not have an "element" attribute to attach to the Bespin UI';a.error(f);m.reject(f);return}l(t).addClass(u);u=="west"||u=="east"||u=="center"?n.appendChild(t):s.appendChild(t);p.elementAppended&&p.elementAppended()}m.resolve()}});bespin.tiki.register("::settings",{name:"settings",dependencies:{types:"0.0.0"}});
bespin.tiki.module("settings:commands",function(q,k){q("bespin:plugins");var l=q("settings").settings;k.setCommand=function(j,h,d){var b;if(h.setting)if(h.value===undefined)b="<strong>"+h.setting+"</strong> = "+l.get(h.setting);else{b="Setting: <strong>"+h.setting+"</strong> = "+h.value;l.set(h.setting,h.value)}else{j=l._list();b="";j.sort(function(a,i){return a.key<i.key?-1:a.key==i.key?0:1});j.forEach(function(a){b+='<a class="setting" href="https://wiki.mozilla.org/Labs/Bespin/Settings#'+a.key+
'" title="View external documentation on setting: '+a.key+'" target="_blank">'+a.key+"</a> = "+a.value+"<br/>"})}d.done(b)};k.unsetCommand=function(j,h,d){l.resetValue(h.setting);d.done("Reset "+h.setting+" to default: "+l.get(h.setting))}});
bespin.tiki.module("settings:cookie",function(q,k){var l=q("bespin:util/cookie");k.CookiePersister=function(){};k.CookiePersister.prototype={loadInitialValues:function(j){j._loadDefaultValues().then(function(){var h=l.get("settings");j._loadFromObject(JSON.parse(h))}.bind(this))},persistValue:function(j){try{var h={};j._getSettingNames().forEach(function(a){h[a]=j.get(a)});var d=JSON.stringify(h);l.set("settings",d)}catch(b){console.error("Unable to JSONify the settings! "+b)}}}});
bespin.tiki.module("settings:index",function(q,k){var l=q("bespin:plugins").catalog,j=q("bespin:console").console,h=q("bespin:promise").Promise,d=q("bespin:promise").group,b=q("types:types");k.addSetting=function(a){q("settings").settings.addSetting(a)};k.getSettings=function(){return l.getExtensions("setting")};k.getTypeSpecFromAssignment=function(a){var i=a.assignments;a="text";if(i){var e=null;i.forEach(function(g){if(g.param.name==="setting")e=g});if(e)if((i=e.value)&&i!=="")if(i=l.getExtensionByKey("setting",
i))a=i.type}return a};k.MemorySettings=function(){};k.MemorySettings.prototype={_values:{},_deactivated:{},setPersister:function(a){(this._persister=a)&&a.loadInitialValues(this)},get:function(a){return this._values[a]},set:function(a,i){var e=l.getExtensionByKey("setting",a);if(e)if(typeof i=="string"&&e.type=="string")this._values[a]=i;else{var g=false;b.fromString(i,e.type).then(function(o){g=true;this._values[a]=o;l.publish(this,"settingChange",a,o)}.bind(this),function(o){j.error("Error setting",
a,": ",o)});if(!g){j.warn("About to set string version of ",a,"delaying typed set.");this._values[a]=i}}else{j.warn("Setting not defined: ",a,i);this._deactivated[a]=i}this._persistValue(a,i);return this},addSetting:function(a){if(a.name){!a.defaultValue===undefined&&j.error("Setting.defaultValue == undefined",a);b.isValid(a.defaultValue,a.type).then(function(i){i||j.warn("!Setting.isValid(Setting.defaultValue)",a);this.set(a.name,this._deactivated[a.name]||a.defaultValue)}.bind(this),function(i){j.error("Type error ",
i," ignoring setting ",a)})}else j.error("Setting.name == undefined. Ignoring.",a)},resetValue:function(a){var i=l.getExtensionByKey("setting",a);i?this.set(a,i.defaultValue):j.log("ignore resetValue on ",a)},resetAll:function(){this._getSettingNames().forEach(function(a){this.resetValue(a)}.bind(this))},_getSettingNames:function(){var a=[];l.getExtensions("setting").forEach(function(i){a.push(i.name)});return a},_list:function(){var a=[];this._getSettingNames().forEach(function(i){a.push({key:i,
value:this.get(i)})}.bind(this));return a},_persistValue:function(a,i){var e=this._persister;e&&e.persistValue(this,a,i)},_loadInitialValues:function(){var a=this._persister;a?a.loadInitialValues(this):this._loadDefaultValues()},_loadDefaultValues:function(){return this._loadFromObject(this._defaultValues())},_loadFromObject:function(a){var i=[],e=function(s){return function(n){this.set(s,n)}};for(var g in a)if(a.hasOwnProperty(g)){var o=a[g],f=l.getExtensionByKey("setting",g);if(f){o=b.fromString(o,
f.type);f=e(g);o.then(f);i.push(o)}}var m=new h;d(i).then(function(){m.resolve()});return m},_saveToObject:function(){var a=[],i={};this._getSettingNames().forEach(function(g){var o=this.get(g),f=l.getExtensionByKey("setting",g);if(f){o=b.toString(o,f.type);o.then(function(m){i[g]=m});a.push(o)}}.bind(this));var e=new h;d(a).then(function(){e.resolve(i)});return e},_defaultValues:function(){var a={};l.getExtensions("setting").forEach(function(i){a[i.name]=i.defaultValue});return a}};k.settings=new k.MemorySettings});
bespin.tiki.register("::canon",{name:"canon",dependencies:{events:"0.0.0",settings:"0.0.0"}});
bespin.tiki.module("canon:environment",function(q,k){var l=q("bespin:util/util"),j=q("bespin:console").console,h=q("bespin:plugins").catalog,d=q("settings").settings;k.Environment=function(){this.commandLine=null;window.addEventListener("resize",this.dimensionsChanged.bind(this),false)};Object.defineProperties(k.Environment.prototype,{settings:{value:{set:function(b,a){if(l.none(b))throw new Error("setSetting(): key must be supplied");if(l.none(a))throw new Error("setSetting(): value must be supplied");
d.set(b,a)},get:function(b){if(l.none(b))throw new Error("getSetting(): key must be supplied");return d.get(b)}}},dimensionsChanged:{value:function(){h.publish(this,"dimensionsChanged")}},session:{get:function(){return h.getObject("session")}},view:{get:function(){if(!this.session)return null;return this.session.currentView}},editor:{get:function(){if(!this.session)return null;return this.session.currentView.editor}},contexts:{get:function(){if(!this.view)return[];var b=this.view.editor.layoutManager.syntaxManager,
a=this.view.getSelectedRange().start;return b.contextsAtPosition(a)}},buffer:{get:function(){if(this.session)return this.view.editor.buffer;else j.error("command attempted to get buffer but there's no session")}},model:{get:function(){if(this.buffer)return this.view.editor.layoutManager.textStorage;else j.error("Session has no current buffer")}},file:{get:function(){if(this.buffer)return this.buffer.file;else j.error("Session has no current buffer")}},files:{get:function(){return h.getObject("files")}}});
k.global=new k.Environment});
bespin.tiki.module("canon:history",function(q,k){var l=q("bespin:util/stacktrace").Trace,j=q("bespin:plugins").catalog;k.requests=[];k.addRequestOutput=function(h){for(k.requests.push(h);k.requests.length>100;)k.requests.shiftObject();j.publish(this,"addedRequestOutput",null,h)};k.execute=function(h,d,b){if(b.command)try{b.command(h,d,b)}catch(a){h=new l(a,true);console.group("Error executing command '"+b.typed+"'");console.log("command=",b.commandExt);console.log("args=",d);console.error(a);h.log(3);
console.groupEnd();b.doneWithError(a)}else b.doneWithError("Command not found.")}});
bespin.tiki.module("canon:request",function(q,k){var l=q("events").Event,j=q("canon:history");k.Request=function(h){h=h||{};this.command=h.command;this.commandExt=h.commandExt;this.args=h.args;this.typed=h.typed;this._begunOutput=false;this.start=new Date;this.end=null;this.error=this.completed=false;this.changed=new l};k.Request.prototype._beginOutput=function(){this._begunOutput=true;this.outputs=[];j.addRequestOutput(this)};k.Request.prototype.doneWithError=function(h){this.error=true;this.done(h)};
k.Request.prototype.async=function(){this._begunOutput||this._beginOutput()};k.Request.prototype.output=function(h){this._begunOutput||this._beginOutput();if(typeof h!=="string"&&!(h instanceof Node))h=h.toString();this.outputs.push(h);this.changed();return this};k.Request.prototype.done=function(h){this.completed=true;this.end=new Date;this.duration=this.end.getTime()-this.start.getTime();h?this.output(h):this.changed()}});bespin.tiki.module("canon:index",function(){});
bespin.tiki.register("::edit_session",{name:"edit_session",dependencies:{events:"0.0.0"}});
bespin.tiki.module("edit_session:index",function(q,k){q("bespin:promise");q("bespin:plugins");q("bespin:util/util");q("events");k.EditSession=function(){};k.EditSession.prototype={_currentView:null,currentUser:null,history:null,getCompletePath:function(l){if(l==null)l="";if(l==null||l.substring(0,1)!="/"){var j;if(this._currentView&&this._currentView.buffer)j=this._currentView.buffer;var h;if(j)h=j.file;l=h?h.parentdir()+l:"/"+l}return l}};Object.defineProperties(k.EditSession.prototype,{currentView:{set:function(l){if(l!==
this._currentView)this._currentView=l},get:function(){return this._currentView}}});k.createSession=function(l,j){var h=new k.EditSession;if(l)h.currentView=l.textView;if(j)h.currentUser=j;return h}});bespin.tiki.register("::rangeutils",{name:"rangeutils",dependencies:{}});
bespin.tiki.module("rangeutils:utils/range",function(q,k){var l=q("bespin:util/util");k.addPositions=function(j,h){return{row:j.row+h.row,col:j.col+h.col}};k.cloneRange=function(j){var h=j.start;j=j.end;return{start:{row:h.row,col:h.col},end:{row:j.row,col:j.col}}};k.comparePositions=function(j,h){var d=j.row-h.row;return d===0?j.col-h.col:d};k.equal=function(j,h){return k.comparePositions(j.start,h.start)===0&&k.comparePositions(j.end,h.end)===0};k.extendRange=function(j,h){var d=j.end;return{start:j.start,
end:{row:d.row+h.row,col:d.col+h.col}}};k.intersectRangeSets=function(j,h){j=l.clone(j);h=l.clone(h);for(var d=[];j.length>0&&h.length>0;){var b=j.shift(),a=h.shift(),i=k.comparePositions(b.start,a.start),e=k.comparePositions(b.end,a.end);if(k.comparePositions(b.end,a.start)<0){d.push(b);h.unshift(a)}else if(k.comparePositions(a.end,b.start)<0){d.push(a);j.unshift(b)}else if(i<0){d.push({start:b.start,end:a.start});j.unshift({start:a.start,end:b.end});h.unshift(a)}else if(i===0)if(e<0)h.unshift({start:b.end,
end:a.end});else e>0&&j.unshift({start:a.end,end:b.end});else if(i>0){d.push({start:a.start,end:b.start});j.unshift(b);h.unshift({start:b.start,end:a.end})}}return d.concat(j,h)};k.isZeroLength=function(j){return j.start.row===j.end.row&&j.start.col===j.end.col};k.maxPosition=function(j,h){return k.comparePositions(j,h)>0?j:h};k.normalizeRange=function(j){return this.comparePositions(j.start,j.end)<0?j:{start:j.end,end:j.start}};k.rangeSetBoundaries=function(j){return{start:j[0].start,end:j[j.length-
1].end}};k.toString=function(j){var h=j.start;j=j.end;return"[ "+h.row+", "+h.col+" "+j.row+","+ +j.col+" ]"};k.unionRanges=function(j,h){return{start:j.start.row<h.start.row||j.start.row===h.start.row&&j.start.col<h.start.col?j.start:h.start,end:j.end.row>h.end.row||j.end.row===h.end.row&&j.end.col>h.end.col?j.end:h.end}};k.isPosition=function(j){return!l.none(j)&&!l.none(j.row)&&!l.none(j.col)};k.isRange=function(j){return!l.none(j)&&k.isPosition(j.start)&&k.isPosition(j.end)}});
bespin.tiki.module("rangeutils:index",function(){});bespin.tiki.register("::theme_manager",{name:"theme_manager",dependencies:{jquery:"0.0.0",settings:"0.0.0",events:"0.0.0",less:"0.0.0"}});
bespin.tiki.module("theme_manager:index",function(q,k){q("bespin:promise");var l=q("bespin:plugins").catalog;q("events");var j=q("themestyles"),h=q("settings").settings,d=null,b=null;k.themestyles=j;k.themeSettingChanged=function(a,i,e){var g=l.getExtensionByKey("theme",e);if(e==="standard"||!e||!g){g=null;if(b!==null)g=l.getExtensionByKey("theme",b)}if(g)g.load().then(function(o){d&&j.unregisterThemeStyles(d);j.currentThemeVariables=o();d=g;j.parseGlobalVariables();j.reparse();g.url&&j.registerThemeStyles(g);
l.publish(k,"themeChange")});else if(d){j.unregisterThemeStyles(d);d=null;j.currentThemeVariables=null;j.parseGlobalVariables();j.reparse();l.publish(this,"themeChange")}};l.registerExtension("settingChange",{match:"theme",pointer:k.themeSettingChanged.bind(k)});k.setStandardTheme=function(a){b=a;a!==h.get("theme")&&k.themeSettingChanged(this)};k.setBasePlugin=function(a){j.basePluginName=a};k.startParsing=function(){j.preventParsing=false;return j.reparse()};k.registerTheme=function(a){var i=h.get("theme");
a.name===i&&k.themeSettingChanged(this,"theme",a.name)};k.unregisterTheme=function(a){a.name===h.get("theme")&&k.themeSettingChanged(this)};k.appLaunched=function(){l.publish(k,"themeChange")}});
bespin.tiki.module("theme_manager:themestyles",function(q,k){var l=q("bespin:util/util"),j=q("bespin:plugins").catalog,h=q("bespin:console").console,d=q("bespin:promise").Promise,b=q("bespin:promise").group,a=q("jquery").$,i=new (q("less").Parser)({optimization:3}),e=1;k.currentThemeVariables=null;k.basePluginName=null;k.preventParsing=true;var g="";k.globalThemeVariables={};var o={},f={},m=function(r){var v={},x=[],C=function(E,D){x.push(E);if(typeof D!="object")v[x.join("_")]=D;else for(prop in D)C(prop,
D[prop]);x.pop()};C("global",r);return v},s={},n={font:"arial, lucida, helvetica, sans-serif",font_size:"14px",line_height:"1.8em",color:"#DAD4BA",text_shadow:"1px 1px rgba(0, 0, 0, 0.4)",error_color:"#F99",header_color:"white",link_color:"#ACF",control:{color:"#E1B41F",border:"1px solid rgba(0, 0, 0, 0.2)",border_radius:"0.25em",background:"rgba(0, 0, 0, 0.2)",active:{color:"#FF9600",border:"1px solid #E1B41F",inset_color:"#ff9600",background:"rgba(0, 0, 0, 0.2)"}},pane:{h1:{font:"'MuseoSans', Helvetica",
font_size:"2.8em",color:"white"},color:"#DAD4BA",text_shadow:"1px 1px rgba(0, 0, 0, 0.4)",link_color:"white",background:"#45443C",border_radius:".5em"},form:{color:"white",text_shadow:"1px 1px rgba(0, 0, 0, 0.4)",font:"'Lucida Sans','Lucida Grande',Verdana,Arial,sans-serif",font_size:"@global_font_size",line_height:"@global_line_height"},button:{color:"white",background:"#3E6CB9"},container:{background:"#1E1916",border:"1px solid black"},selectable:{color:"white",border:"0px solid transparent",background:"transparent",
active:{color:"black",border:"0px solid transparent",background:"#FF8E00"},hover:{color:"black",border:"0px solid transparent",background:"#FF8E00"}},hint:{color:"#AAA",active:{color:"black"},hover:{color:"black"}},accelerator:{color:"#996633",active:{color:"black"},hover:{color:"black"}},menu:{border_color:"black",inset_color_right:"#1E1916",inset_color_top_left:"#3E3936",background:"transparent"}};n=m(n);k.getPluginThemeVariables=function(r){var v=j.plugins[r];if(!v)return null;var x={};if(k.currentThemeVariables&&
k.currentThemeVariables[r])x=k.currentThemeVariables[r];v.provides.forEach(function(C){if(C.ep==="themevariable"){var E=C.name;x[E]=x[E]||C.defaultValue}});return x};k.parseGlobalVariables=function(){var r={},v="",x=k.currentThemeVariables;l.mixin(r,n);x&&x.global&&l.mixin(r,m(x.global));k.globalThemeVariables=r;for(prop in r)v+="@"+prop+":"+r[prop]+";";g=v};k.parseGlobalVariables();var t=function(r,v,x){if(o[v])styleElem=document.getElementById("_bespin_theme_style_"+o[v]);else{styleElem=document.createElement("style");
styleElem.setAttribute("id","_bespin_theme_style_"+e);o[v]=e;e++;document.body.appendChild(styleElem)}i.parse(g+x+f[v],function(C,E){if(C){C="Error less parsing "+v+" "+C.message;h.error(C);r.reject(C)}else{try{var D=E.toCSS()}catch(G){C="Error less parsing "+v+" "+G;h.error(C);r.reject(C);return}if(styleElem&&styleElem.firstChild)styleElem.firstChild.textContent=D;else{C=document.createTextNode(D);styleElem.appendChild(C)}r.resolve()}})},u={};k.parsePlugin=function(r){if(k.preventParsing)return(new d).resolve();
var v=j.plugins[r];if(!v)throw"reparsePlugin: plugin "+r+" is not defined!";if(!u[r]){u[r]=new d;setTimeout(function(){var x=k.getPluginThemeVariables(r),C="";for(prop in x)C+="@"+prop+":"+x[prop]+";";x=new d;x.then(function(E){u[this.name].resolve(E);u[this.name]=null}.bind(this),function(){u[this.name].reject(data);u[this.name]=null}.bind(this));t(x,r,C)}.bind(v),0)}return u[r]};var w=function(r,v,x,C){x=x.replace(/url\(['"]*([^'")]*)(['"]*)\)/g,"url("+r+"$1)");f[v]+=x;C&&C.resolve()},p=null;k.registerThemeStyles=
function(r){var v=r.getPluginName(),x=j.getResourceURL(v);if(!(r.url instanceof Array))r.url=[r.url];f[v]="";var C=[],E=k.preventParsing;r.url.forEach(function(D){if(s[v]&&s[v][D])w(x,v,s[v][D]);else{var G=new d;C.push(G);a.ajax({url:x+D+"?"+(new Date).getTime(),success:function(H){w(x,v,H,G)},error:function(){h.error("registerLessFile: Could not load "+x+D);G.resolve()}})}});if(C.length===0)k.parsePlugin(v);else{E||b(C).then(function(){k.parsePlugin(v)});if(p!==null)C=C.concat(p);p=b(C)}};k.reparse=
function(){var r=new d;if(k.preventParsing)return r.resolve();p?p.then(function(){var v=[],x=k.basePluginName;x!==null&&f[x]&&v.push(k.parsePlugin(x));for(var C in f)C!==x&&v.push(k.parsePlugin(C));b(v).then(r.resolve.bind(r),r.reject.bind(r))},function(v){r.reject(v)}):r.resolve();return r};k.unregisterThemeStyles=function(r){r=r.getPluginName();if(o[r]){var v=document.getElementById("_bespin_theme_style_"+o[r]);v.parentNode.removeChild(v);delete o[r];delete f[r]}}});
bespin.tiki.register("::screen_theme",{name:"screen_theme",dependencies:{}});bespin.tiki.module("screen_theme:index",function(){});bespin.tiki.register("::keyboard",{name:"keyboard",dependencies:{canon:"0.0.0",settings:"0.0.0"}});
bespin.tiki.module("keyboard:keyboard",function(q,k){var l=q("bespin:plugins").catalog;q("bespin:console");q("bespin:util/stacktrace");var j=q("bespin:util/util"),h=q("settings").settings,d=q("keyboard:keyutil"),b=q("canon:history"),a=q("canon:request").Request,i=q("canon:environment");k.buildFlags=function(e,g){g.context=e.contexts[0];return g};q=function(){};j.mixin(q.prototype,{_customKeymappingCache:{states:{}},processKeyEvent:function(e,g,o){e=d.commandCodes(e,true)[0];if(j.none(e))return false;
k.buildFlags(i.global,o);o.isCommandKey=true;return this._matchCommand(e,g,o)},processKeyInput:function(e,g,o){o.isCommandKey=false;return this._matchCommand(e,g,o)},_matchCommand:function(e,g,o){var f=this._findCommandExtension(e,g,o);if(f&&f.commandExt!=="no command"){o.isTextView&&g.resetKeyBuffers();var m=f.commandExt;m.load(function(s){s=new a({command:s,commandExt:m});b.execute(i.global,f.args,s)});return true}return f&&f.commandExt==="no command"?true:false},_buildBindingsRegex:function(e){e.forEach(function(g){if(j.none(g.key))if(Array.isArray(g.regex)){g.key=
new RegExp("^"+g.regex[1]+"$");g.regex=new RegExp(g.regex.join("")+"$")}else g.regex=new RegExp(g.regex+"$");else g.key=new RegExp("^"+g.key+"$")})},_buildKeymappingRegex:function(e){for(state in e.states)this._buildBindingsRegex(e.states[state]);e._convertedRegExp=true},_findCommandExtension:function(e,g,o){if(o.isTextView){var f=g._keyState;if(!o.isCommandKey||e.indexOf("alt_")===-1){g._keyBuffer+=e.replace(/ctrl_meta|meta/,"ctrl");g._keyMetaBuffer+=e}var m=[this._customKeymappingCache];m=m.concat(l.getExtensions("keymapping"));
for(var s=0;s<m.length;s++)if(!j.none(m[s].states[f])){j.none(m[s]._convertedRegExp)&&this._buildKeymappingRegex(m[s]);var n=this._bindingsMatch(e,o,g,m[s]);if(!j.none(n))return n}}g=l.getExtensions("command");var t=null;f={};e=e.replace(/ctrl_meta|meta/,"ctrl");g.some(function(u){if(this._commandMatches(u,e,o)){t=u;return true}return false}.bind(this));return j.none(t)?null:{commandExt:t,args:f}},_bindingsMatch:function(e,g,o,f){var m,s=null,n={},t;t=j.none(f.hasMetaKey)?o._keyMetaBuffer:o._keyBuffer;
if(e.indexOf("alt_")===0&&g.isCommandKey)t+=e;f.states[o._keyState].some(function(u){if(u.key&&!u.key.test(e))return false;if(u.regex&&!(m=u.regex.exec(t)))return false;if(u.disallowMatches)for(var w=0;w<u.disallowMatches.length;w++)if(m[u.disallowMatches[w]])return true;if(!k.flagsMatch(u.predicates,g))return false;if(u.exec){s=l.getExtensionByKey("command",u.exec);if(j.none(s))throw new Error("Can't find command "+u.exec+" in state="+o._keyState+", symbolicName="+e);if(u.params){var p;u.params.forEach(function(r){p=
!j.none(r.match)&&!j.none(m)?m[r.match]||r.defaultValue:r.defaultValue;if(r.type==="number")p=parseInt(p);n[r.name]=p})}o.resetKeyBuffers()}if(u.then){o._keyState=u.then;o.resetKeyBuffers()}if(j.none(s))s="no command";return true});if(j.none(s))return null;return{commandExt:s,args:n}},_commandMatches:function(e,g,o){var f=e.key;if(!f)return false;if(!k.flagsMatch(e.predicates,o))return false;if(typeof f==="string"){if(f!=g)return false;return true}if(!Array.isArray(f)){f=[f];e.key=f}for(e=0;e<f.length;e++){var m=
f[e];if(typeof m==="string"){if(m==g)return true}else if(m.key==g)return k.flagsMatch(m.predicates,o)}return false},_customKeymappingChanged:function(){var e=this._customKeymappingCache=JSON.parse(h.get("customKeymapping"));e.states=e.states||{};for(state in e.states)this._buildBindingsRegex(e.states[state])}});k.flagsMatch=function(e,g){if(j.none(e))return true;if(!g)return false;for(var o in e)if(g[o]!==e[o])return false;return true};k.keyboardManager=new q});
bespin.tiki.module("keyboard:keyutil",function(q,k){var l=q("bespin:util/util");k.KeyHelper=function(){var h={MODIFIER_KEYS:{16:"shift",17:"ctrl",18:"alt",224:"meta"},FUNCTION_KEYS:{8:"backspace",9:"tab",13:"return",19:"pause",27:"escape",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",44:"printscreen",45:"insert",46:"delete",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"numlock",145:"scrolllock"},PRINTABLE_KEYS:{32:" ",
48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",107:"+",109:"-",110:".",188:",",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:'"'},PRINTABLE_KEYS_CHARCODE:{},KEY:{}};for(var d in h.PRINTABLE_KEYS){var b=h.PRINTABLE_KEYS[d];h.PRINTABLE_KEYS_CHARCODE[b.charCodeAt(0)]=d;if(b.toUpperCase()!=
b)h.PRINTABLE_KEYS_CHARCODE[b.toUpperCase().charCodeAt(0)]=d}for(d in h.FUNCTION_KEYS){b=h.FUNCTION_KEYS[d].toUpperCase();h.KEY[b]=parseInt(d,10)}return h}();var j=function(h){return!!(h.altKey||h.ctrlKey||h.metaKey||h.charCode!==h.which&&k.KeyHelper.FUNCTION_KEYS[h.which])};k.commandCodes=function(h,d){var b=h._keyCode||h.keyCode,a=h._charCode===undefined?h.charCode:h._charCode,i=null,e=null,g="",o=true;if(b===0&&h.which===0)return false;if(a!==0)return false;if(k.KeyHelper.MODIFIER_KEYS[a])return[k.KeyHelper.MODIFIER_KEYS[a],
null];if(b){i=k.KeyHelper.FUNCTION_KEYS[b];if(!i&&(h.altKey||h.ctrlKey||h.metaKey)){i=k.KeyHelper.PRINTABLE_KEYS[b];if(b>47&&b<58)o=h.altKey}if(i){if(h.altKey)g+="alt_";if(h.ctrlKey)g+="ctrl_";if(h.metaKey)g+="meta_"}else if(h.ctrlKey||h.metaKey)return false}if(!i){b=h.which;e=i=String.fromCharCode(b);b=i.toLowerCase();if(h.metaKey){g="meta_";i=b}else i=null}if(h.shiftKey&&i&&o)g+="shift_";if(i)i=g+i;if(!d&&i)i=i.replace(/ctrl_meta|meta/,"ctrl");return[i,e]};k.addKeyDownListener=function(h,d){var b=
function(a){var i=d(a);i&&l.stopEvent(a);return i};h.addEventListener("keydown",function(a){if(l.isMozilla)if(k.KeyHelper.FUNCTION_KEYS[a.keyCode])return true;else if((a.ctrlKey||a.metaKey)&&k.KeyHelper.PRINTABLE_KEYS[a.keyCode])return true;if(j(a))return b(a);return true},false);h.addEventListener("keypress",function(a){if(l.isMozilla)if(k.KeyHelper.FUNCTION_KEYS[a.keyCode])return b(a);else if((a.ctrlKey||a.metaKey)&&k.KeyHelper.PRINTABLE_KEYS_CHARCODE[a.charCode]){a._keyCode=k.KeyHelper.PRINTABLE_KEYS_CHARCODE[a.charCode];
a._charCode=0;return b(a)}if(a.charCode!==undefined&&a.charCode===0)return true;return b(a)},false)}});bespin.tiki.module("keyboard:index",function(){});bespin.tiki.register("::worker_manager",{name:"worker_manager",dependencies:{events:"0.0.0",underscore:"0.0.0"}});
bespin.tiki.module("worker_manager:index",function(q,k){function l(d){var b=/^([^#:]+)(?::([^#:]+))?#([^#:]+)$/.exec(d);if(b==null)throw new Error('WorkerManager: invalid pointer specification: "'+d+'"');d=b[1];var a=b[3];b=d+":"+(b[2]!=null?b[2]:"index");var i=bespin!=null&&bespin.base!=null?bespin.base:"",e=new Worker(i+"BespinEmbedded.js");e.onmessage=this._onMessage.bind(this);e.onerror=this._onError.bind(this);e.postMessage(JSON.stringify({op:"load",base:i,pkg:d,module:b,target:a}));this._worker=
e;this._currentId=0}if(window==null)throw new Error('The "worker_manager" plugin can only be loaded in the browser, not a web worker. Use "worker" instead.');q("bespin:plugins");var j=q("bespin:console").console;q("events");var h=q("bespin:promise").Promise;l.prototype={_onError:function(d){j.error("Web worker failed at file "+d.filename+":"+d.lineno)},_onMessage:function(d){d=JSON.parse(d.data);switch(d.op){case "finish":if(d.id===this._currentId){var b=this._promise;this._promise=null;b.resolve(d.result)}break;
case "log":j[d.method].apply(j,d.args);break}},_promise:null,kill:function(){var d=this._promise;if(d!=null){d.reject("killed");this._promise=null}this._worker.terminate();this._worker=null},send:function(d,b){var a=this._promise;if(a!=null){a.reject("interrupted");this._currentId++}a=this._currentId;var i=new h;this._promise=i;this._worker.postMessage(JSON.stringify({op:"invoke",id:a,method:d,args:b}));return i}};k.WorkerManager=l});bespin.tiki.register("::events",{name:"events",dependencies:{traits:"0.0.0"}});
bespin.tiki.module("events:index",function(q,k){k.Event=function(){var l=[],j=function(){var h=arguments;l.forEach(function(d){d.func.apply(null,h)})};j.add=function(){arguments.length==1?l.push({ref:arguments[0],func:arguments[0]}):l.push({ref:arguments[0],func:arguments[1]})};j.remove=function(h){l=l.filter(function(d){return h!==d.ref})};j.removeAll=function(){l=[]};return j}});bespin.tiki.register("::types",{name:"types",dependencies:{}});
bespin.tiki.module("types:basic",function(q,k){var l=q("bespin:plugins").catalog,j=q("bespin:console").console,h=q("bespin:promise").Promise;k.text={isValid:function(d){return typeof d=="string"},toString:function(d){return d},fromString:function(d){return d}};k.number={isValid:function(d){if(isNaN(d))return false;if(d===null)return false;if(d===undefined)return false;if(d===Infinity)return false;return typeof d=="number"},toString:function(d){if(!d)return null;return""+d},fromString:function(d){if(!d)return null;
var b=parseInt(d,10);if(isNaN(b))throw new Error("Can't convert \""+d+'" to a number.');return b}};k.bool={isValid:function(d){return typeof d=="boolean"},toString:function(d){return""+d},fromString:function(d){if(d===null)return null;if(!d.toLowerCase)return!!d;var b=d.toLowerCase();if(b=="true")return true;else if(b=="false")return false;return!!d}};k.object={isValid:function(d){return typeof d=="object"},toString:function(d){return JSON.stringify(d)},fromString:function(d){return JSON.parse(d)}};
k.selection={isValid:function(d,b){if(typeof d!="string")return false;if(!b.data){j.error("Missing data on selection type extension. Skipping");return true}var a=false;b.data.forEach(function(i){if(d==i)a=true});return a},toString:function(d){return d},fromString:function(d){return d},resolveTypeSpec:function(d,b){var a=new h;if(b.data){d.data=b.data;a.resolve()}else if(b.pointer)l.loadObjectForPropertyPath(b.pointer).then(function(i){i=i(b);if(typeof i.then==="function")i.then(function(e){d.data=
e;a.resolve()});else{d.data=i;a.resolve()}},function(i){a.reject(i)});else{j.warn("Missing data/pointer for selection",b);a.resolve()}return a}}});
bespin.tiki.module("types:types",function(q,k){function l(b){var a=new d,i=h.getExtensionByKey("type",b.name);i?a.resolve({ext:i,typeSpec:b}):a.reject(new Error("Unknown type: "+b.name));return a}function j(b){if(typeof b==="string")return l({name:b});if(typeof b==="object")if(b.name==="deferred"){var a=new d;k.undeferTypeSpec(b).then(function(i){j(i).then(function(e){a.resolve(e)},function(e){a.reject(e)})});return a}else return l(b);throw new Error("Unknown typeSpec type: "+typeof b);}var h=q("bespin:plugins").catalog;
q("bespin:console");var d=q("bespin:promise").Promise;k.getSimpleName=function(b){if(!b)throw new Error("null|undefined is not a valid typeSpec");if(typeof b=="string")return b;if(typeof b=="object"){if(!b.name)throw new Error("Missing name member to typeSpec");return b.name}throw new Error("Not a typeSpec: "+b);};k.equals=function(b,a){return k.getSimpleName(b)==k.getSimpleName(a)};k.undeferTypeSpec=function(b){var a=new d;if(!b.pointer){a.reject(new Error("Missing deferred pointer"));return a}h.loadObjectForPropertyPath(b.pointer).then(function(i){i=
i(b);typeof i.then==="function"?i.then(function(e){a.resolve(e)},function(e){a.reject(e)}):a.resolve(i)},function(i){a.reject(i)});return a};k.resolveType=function(b){var a=new d;j(b).then(function(i){i.ext.load(function(e){typeof e.resolveTypeSpec==="function"?e.resolveTypeSpec(i.ext,i.typeSpec).then(function(){a.resolve({type:e,ext:i.ext})},function(g){a.reject(g)}):a.resolve({type:e,ext:i.ext})})},function(i){a.reject(i)});return a};k.fromString=function(b,a){var i=new d;k.resolveType(a).then(function(e){i.resolve(e.type.fromString(b,
e.ext))});return i};k.toString=function(b,a){var i=new d;k.resolveType(a).then(function(e){i.resolve(e.type.toString(b,e.ext))});return i};k.isValid=function(b,a){var i=new d;k.resolveType(a).then(function(e){i.resolve(e.type.isValid(b,e.ext))});return i}});bespin.tiki.module("types:index",function(){});bespin.tiki.register("::syntax_manager",{name:"syntax_manager",dependencies:{worker_manager:"0.0.0",events:"0.0.0",underscore:"0.0.0",syntax_directory:"0.0.0"}});
bespin.tiki.module("syntax_manager:index",function(q,k){function l(e,g,o,f){for(;e.length<g;)e.push(d(f).clone());g=[g,o.length].concat(o);Array.prototype.splice.apply(e,g);return e}function j(e,g){this._syntaxInfo=e;this._syntaxManager=g;this._invalidRow=0;this._states=[];this._active=false}function h(e){this.layoutManager=e;this.syntaxChanged=new b;this._contextRanges=this._invalidRows=this._context=null;this._attrs=[];this._syntax="plain";this._reset()}var d=q("underscore")._,b=q("events").Event,
a=q("worker_manager").WorkerManager;q("bespin:console");q("rangeutils:utils/range");var i=q("syntax_directory").syntaxDirectory;j.prototype={_annotationFinished:function(e,g,o){if(this._active){this._syntaxManager.mergeAttrs(e,o.attrs);l(this._states,e,o.states);if(g>=this._getRowCount()){this._invalidRow=null;this._active=false}else{this._invalidRow=g;this.annotate()}}},_createWorker:function(){var e=this._syntaxInfo;if(e==null)return false;var g=new a("syntax_worker#syntaxWorker");this._worker=
g;g.send("loadSyntax",[e.name]);return true},_getRowCount:function(){return this._syntaxManager.getTextLines().length},annotate:function(){if(this._invalidRow==null)throw new Error("Attempt to annotate without any invalid row");if(this._worker==null)if(!this._createWorker())return;var e=this._syntaxManager.getTextLines(),g=this._invalidRow,o=g===0?this.getName()+":start":this._states[g],f=Math.min(e.length,g+100);e=e.slice(g,f);this._active=true;var m={start:{row:g,col:0},end:{row:f-1,col:d(e).last().length}};
this._worker.send("annotate",[o,e,m]).then(d(this._annotationFinished).bind(this,g,f))},contextsAtPosition:function(){var e=this._syntaxInfo;if(e==null)return["plain"];return[e.name]},cut:function(e){var g=this._getRowCount();if(e<0||e>=g)throw new Error("Attempt to cut the context at an invalid row");if(!(this._invalidRow!=null&&this._invalidRow<e)){this._invalidRow=e;this._active=false}},getName:function(){return this._syntaxInfo.name},kill:function(){var e=this._worker;if(e!=null){e.kill();this._worker=
null}}};h.prototype={_getTextStorage:function(){return this.layoutManager.textStorage},_reset:function(){var e=this._context;if(e!=null){e.kill();this._context=null}e=this._syntax;e=e==="plain"?null:i.get(e);this._context=e=new j(e,this);e.annotate()},syntaxChanged:null,contextsAtPosition:function(e){return this._context.contextsAtPosition(e)},getAttrsForRows:function(e,g){return this._attrs.slice(e,g)},getTextLines:function(){return this._getTextStorage().lines},invalidateRow:function(e){var g=this._context;
g.cut(e);g.annotate()},mergeAttrs:function(e,g){l(this._attrs,e,g,[]);this.syntaxChanged(e,e+g.length)},setSyntax:function(e){this._syntax=i.hasSyntax(e)?e:"plain";this._reset()},getSyntax:function(){return this._syntax},setSyntaxFromFileExt:function(e){return this.setSyntax(i.syntaxForFileExt(e))}};k.SyntaxManager=h});
(function(){var q=bespin.tiki.require("jquery").$;q(document).ready(function(){bespin.tiki.require("bespin:plugins").catalog.loadMetadata({text_editor:{resourceURL:"resources/text_editor/",description:"Canvas-based text editor component and many common editing commands",dependencies:{undomanager:"0.0",settings:"0.0",canon:"0.0",rangeutils:"0.0",traits:"0.0",theme_manager:"0.0.0",keyboard:"0.0",edit_session:"0.0",syntax_manager:"0.0"},testmodules:["tests/controllers/testLayoutmanager","tests/models/testTextstorage",
"tests/testScratchcanvas","tests/utils/testRect"],provides:[{action:"new",pointer:"views/editor#EditorView",ep:"factory",name:"text_editor"},{pointer:"views/editor#EditorView",ep:"appcomponent",name:"editor_view"},{predicates:{isTextView:true},pointer:"commands/editing#backspace",ep:"command",key:"backspace",name:"backspace"},{predicates:{isTextView:true},pointer:"commands/editing#deleteCommand",ep:"command",key:"delete",name:"delete"},{description:"Delete all lines currently selected",key:"ctrl_d",
predicates:{isTextView:true},pointer:"commands/editing#deleteLines",ep:"command",name:"deletelines"},{description:"Create a new, empty line below the current one",key:"ctrl_return",predicates:{isTextView:true},pointer:"commands/editing#openLine",ep:"command",name:"openline"},{description:"Join the current line with the following",key:"ctrl_shift_j",predicates:{isTextView:true},pointer:"commands/editing#joinLines",ep:"command",name:"openline"},{params:[{defaultValue:"",type:"text",name:"text",description:"The text to insert"}],
pointer:"commands/editing#insertText",ep:"command",name:"insertText"},{predicates:{isTextView:true},pointer:"commands/editing#newline",ep:"command",key:"return",name:"newline"},{predicates:{isTextView:true},pointer:"commands/editing#tab",ep:"command",key:"tab",name:"tab"},{predicates:{isTextView:true},pointer:"commands/editing#untab",ep:"command",key:"shift_tab",name:"untab"},{predicates:{isTextView:true},ep:"command",name:"move"},{description:"Search for text within this buffer",params:[{type:"text",
name:"value",description:"string to search for"}],key:"ctrl_f",pointer:"commands/editor#findCommand",ep:"command",name:"find"},{description:"Repeat the last search (forward)",pointer:"commands/editor#findNextCommand",ep:"command",key:"ctrl_g",name:"findnext"},{description:"Repeat the last search (backward)",pointer:"commands/editor#findPrevCommand",ep:"command",key:"ctrl_shift_g",name:"findprev"},{predicates:{isTextView:true},pointer:"commands/movement#moveDown",ep:"command",key:"down",name:"move down"},
{predicates:{isTextView:true},pointer:"commands/movement#moveLeft",ep:"command",key:"left",name:"move left"},{predicates:{isTextView:true},pointer:"commands/movement#moveRight",ep:"command",key:"right",name:"move right"},{predicates:{isTextView:true},pointer:"commands/movement#moveUp",ep:"command",key:"up",name:"move up"},{predicates:{isTextView:true},ep:"command",name:"select"},{predicates:{isTextView:true},pointer:"commands/movement#selectDown",ep:"command",key:"shift_down",name:"select down"},
{predicates:{isTextView:true},pointer:"commands/movement#selectLeft",ep:"command",key:"shift_left",name:"select left"},{predicates:{isTextView:true},pointer:"commands/movement#selectRight",ep:"command",key:"shift_right",name:"select right"},{predicates:{isTextView:true},pointer:"commands/movement#selectUp",ep:"command",key:"shift_up",name:"select up"},{predicates:{isTextView:true},pointer:"commands/movement#moveLineEnd",ep:"command",key:["end","ctrl_right"],name:"move lineend"},{predicates:{isTextView:true},
pointer:"commands/movement#selectLineEnd",ep:"command",key:["shift_end","ctrl_shift_right"],name:"select lineend"},{predicates:{isTextView:true},pointer:"commands/movement#moveDocEnd",ep:"command",key:"ctrl_down",name:"move docend"},{predicates:{isTextView:true},pointer:"commands/movement#selectDocEnd",ep:"command",key:"ctrl_shift_down",name:"select docend"},{predicates:{isTextView:true},pointer:"commands/movement#moveLineStart",ep:"command",key:["home","ctrl_left"],name:"move linestart"},{predicates:{isTextView:true},
pointer:"commands/movement#selectLineStart",ep:"command",key:["shift_home","ctrl_shift_left"],name:"select linestart"},{predicates:{isTextView:true},pointer:"commands/movement#moveDocStart",ep:"command",key:"ctrl_up",name:"move docstart"},{predicates:{isTextView:true},pointer:"commands/movement#selectDocStart",ep:"command",key:"ctrl_shift_up",name:"select docstart"},{predicates:{isTextView:true},pointer:"commands/movement#moveNextWord",ep:"command",key:["alt_right"],name:"move nextword"},{predicates:{isTextView:true},
pointer:"commands/movement#selectNextWord",ep:"command",key:["alt_shift_right"],name:"select nextword"},{predicates:{isTextView:true},pointer:"commands/movement#movePreviousWord",ep:"command",key:["alt_left"],name:"move prevword"},{predicates:{isTextView:true},pointer:"commands/movement#selectPreviousWord",ep:"command",key:["alt_shift_left"],name:"select prevword"},{predicates:{isTextView:true},pointer:"commands/movement#selectAll",ep:"command",key:["ctrl_a","meta_a"],name:"select all"},{predicates:{isTextView:true},
ep:"command",name:"scroll"},{predicates:{isTextView:true},pointer:"commands/scrolling#scrollDocStart",ep:"command",key:"ctrl_home",name:"scroll start"},{predicates:{isTextView:true},pointer:"commands/scrolling#scrollDocEnd",ep:"command",key:"ctrl_end",name:"scroll end"},{predicates:{isTextView:true},pointer:"commands/scrolling#scrollPageDown",ep:"command",key:"pagedown",name:"scroll down"},{predicates:{isTextView:true},pointer:"commands/scrolling#scrollPageUp",ep:"command",key:"pageup",name:"scroll up"},
{pointer:"commands/editor#lcCommand",description:"Change all selected text to lowercase",withKey:"CMD SHIFT L",ep:"command",name:"lc"},{pointer:"commands/editor#detabCommand",description:"Convert tabs to spaces.",params:[{defaultValue:null,type:"text",name:"tabsize",description:"Optionally, specify a tab size. (Defaults to setting.)"}],ep:"command",name:"detab"},{pointer:"commands/editor#entabCommand",description:"Convert spaces to tabs.",params:[{defaultValue:null,type:"text",name:"tabsize",description:"Optionally, specify a tab size. (Defaults to setting.)"}],
ep:"command",name:"entab"},{description:"move it! make the editor head to a line number.",params:[{type:"text",name:"line",description:"add the line number to move to in the file"}],key:"ctrl_l",pointer:"commands/editor#gotoCommand",ep:"command",name:"goto"},{pointer:"commands/editor#trimCommand",description:"trim trailing or leading whitespace from each line in selection",params:[{defaultValue:"both",type:{data:[{name:"left"},{name:"right"},{name:"both"}],name:"selection"},name:"side",description:"Do we trim from the left, right or both"}],
ep:"command",name:"trim"},{pointer:"commands/editor#ucCommand",description:"Change all selected text to uppercase",withKey:"CMD SHIFT U",ep:"command",name:"uc"},{predicates:{isTextView:true},pointer:"controllers/undo#undoManagerCommand",ep:"command",key:["ctrl_shift_z"],name:"redo"},{predicates:{isTextView:true},pointer:"controllers/undo#undoManagerCommand",ep:"command",key:["ctrl_z"],name:"undo"},{description:"The distance in characters between each tab",defaultValue:8,type:"number",ep:"setting",
name:"tabstop"},{description:"Customize the keymapping",defaultValue:"{}",type:"text",ep:"setting",name:"customKeymapping"},{description:"The keymapping to use",defaultValue:"standard",type:"text",ep:"setting",name:"keymapping"},{description:"The editor font size in pixels",defaultValue:14,type:"number",ep:"setting",name:"fontsize"},{description:"The editor font face",defaultValue:"Monaco, Lucida Console, monospace",type:"text",ep:"setting",name:"fontface"},{defaultValue:{color:"#e5c138",paddingLeft:5,
backgroundColor:"#4c4a41",paddingRight:10},ep:"themevariable",name:"gutter"},{defaultValue:{color:"#e6e6e6",selectedTextBackgroundColor:"#526da5",backgroundColor:"#2a211c",cursorColor:"#879aff",unfocusedCursorBackgroundColor:"#73171e",unfocusedCursorColor:"#ff0033"},ep:"themevariable",name:"editor"},{defaultValue:{comment:"#666666",directive:"#999999",keyword:"#42A8ED",plain:"#e6e6e6",error:"#ff0000",operator:"#88BBFF",identifier:"#D841FF",string:"#039A0A"},ep:"themevariable",name:"highlighter"},
{defaultValue:{nibStrokeStyle:"rgb(150, 150, 150)",fullAlpha:1,barFillStyle:"rgb(0, 0, 0)",particalAlpha:0.3,barFillGradientBottomStop:"rgb(44, 44, 44)",backgroundStyle:"#2A211C",thickness:17,padding:5,trackStrokeStyle:"rgb(150, 150, 150)",nibArrowStyle:"rgb(255, 255, 255)",barFillGradientBottomStart:"rgb(22, 22, 22)",barFillGradientTopStop:"rgb(40, 40, 40)",barFillGradientTopStart:"rgb(90, 90, 90)",nibStyle:"rgb(100, 100, 100)",trackFillStyle:"rgba(50, 50, 50, 0.8)"},ep:"themevariable",name:"scroller"},
{description:"Event: Notify when something within the editor changed.",params:[{required:true,name:"pointer",description:"Function that is called whenever a change happened."}],ep:"extensionpoint",name:"editorChange"}],type:"plugins/supported",name:"text_editor"},less:{resourceURL:"resources/less/",description:"Leaner CSS",contributors:[],author:"Alexis Sellier <self@cloudhead.net>",url:"http://lesscss.org",version:"1.0.11",dependencies:{},testmodules:[],provides:[],keywords:["css","parser","lesscss",
"browser"],type:"plugins/thirdparty",name:"less"},canon:{resourceURL:"resources/canon/",name:"canon",environments:{main:true,worker:false},dependencies:{events:"0.0",settings:"0.0"},testmodules:[],provides:[{indexOn:"name",description:"A command is a bit of functionality with optional typed arguments which can do something small like moving the cursor around the screen, or large like cloning a project from VCS.",ep:"extensionpoint",name:"command"},{description:"An extension point to be called whenever a new command begins output.",
ep:"extensionpoint",name:"addedRequestOutput"},{description:"A dimensionsChanged is a way to be notified of changes to the dimension of Bespin",ep:"extensionpoint",name:"dimensionsChanged"},{description:"How many typed commands do we recall for reference?",defaultValue:50,type:"number",ep:"setting",name:"historyLength"},{action:"create",pointer:"history#InMemoryHistory",ep:"factory",name:"history"}],type:"plugins/supported",description:"Manages commands"},traits:{resourceURL:"resources/traits/",description:"Traits library, traitsjs.org",
dependencies:{},testmodules:[],provides:[],type:"plugins/thirdparty",name:"traits"},keyboard:{resourceURL:"resources/keyboard/",description:"Keyboard shortcuts",dependencies:{canon:"0.0",settings:"0.0"},testmodules:["tests/testKeyboard"],provides:[{description:"A keymapping defines how keystrokes are interpreted.",params:[{required:true,name:"states",description:"Holds the states and all the informations about the keymapping. See docs: pluginguide/keymapping"}],ep:"extensionpoint",name:"keymapping"},
{pointer:"keyboard#keyboardManager._customKeymappingChanged",ep:"settingChanged",key:"customKeymapping"}],type:"plugins/supported",name:"keyboard"},worker_manager:{resourceURL:"resources/worker_manager/",description:"Manages a web worker on the browser side",dependencies:{events:"0.0.0",underscore:"0.0.0"},testmodules:[],type:"plugins/supported",name:"worker_manager"},edit_session:{resourceURL:"resources/edit_session/",description:"Ties together the files being edited with the views on screen",dependencies:{events:"0.0.0"},
testmodules:["tests/testSession"],provides:[{action:"call",pointer:"#createSession",ep:"factory",name:"session"}],type:"plugins/supported",name:"edit_session"},syntax_manager:{resourceURL:"resources/syntax_manager/",name:"syntax_manager",environments:{main:true,worker:false},dependencies:{worker_manager:"0.0.0",events:"0.0.0",underscore:"0.0.0",syntax_directory:"0.0.0"},testmodules:[],provides:[{indexOn:"name",ep:"extensionpoint",name:"fileextension"}],type:"plugins/supported",description:"Provides syntax highlighting services for the editor"},
undomanager:{resourceURL:"resources/undomanager/",description:"Manages undoable events",testmodules:["tests/testUndomanager"],provides:[{pointer:"#undoManagerCommand",ep:"command",key:["ctrl_shift_z"],name:"redo"},{pointer:"#undoManagerCommand",ep:"command",key:["ctrl_z"],name:"undo"}],type:"plugins/supported",name:"undomanager"},rangeutils:{testmodules:["tests/test"],type:"plugins/supported",resourceURL:"resources/rangeutils/",description:"Utility functions for dealing with ranges of text",name:"rangeutils"},
stylesheet:{resourceURL:"resources/stylesheet/",name:"stylesheet",environments:{worker:true},dependencies:{standard_syntax:"0.0.0"},testmodules:[],provides:[{pointer:"#CSSSyntax",ep:"syntax",fileexts:["css","less"],name:"css"}],type:"plugins/supported",description:"CSS syntax highlighter"},html:{resourceURL:"resources/html/",name:"html",environments:{worker:true},dependencies:{standard_syntax:"0.0.0"},testmodules:[],provides:[{pointer:"#HTMLSyntax",ep:"syntax",fileexts:["htm","html"],name:"html"}],
type:"plugins/supported",description:"HTML syntax highlighter"},events:{resourceURL:"resources/events/",description:"Dead simple event implementation",dependencies:{traits:"0.0"},testmodules:["tests/test"],provides:[],type:"plugins/supported",name:"events"},javascript:{resourceURL:"resources/javascript/",name:"javascript",environments:{worker:true},dependencies:{standard_syntax:"0.0.0"},testmodules:[],provides:[{pointer:"#JSSyntax",ep:"syntax",fileexts:["js","json"],name:"js"}],type:"plugins/supported",
description:"JavaScript syntax highlighter"},theme_manager:{resourceURL:"resources/theme_manager/",name:"theme_manager",environments:{main:true,worker:false},dependencies:{jquery:"0.0.0",settings:"0.0.0",events:"0.0.0",less:"0.0.0"},testmodules:[],provides:[{description:"(Less)files holding the CSS style information for the UI.",unregister:"themestyles#unregisterThemeStyles",register:"themestyles#registerThemeStyles",params:[{required:true,name:"url",description:"Name of the ThemeStylesFile - can also be an array of files."}],
ep:"extensionpoint",name:"themestyles"},{description:"Event: Notify when the theme(styles) changed.",params:[{required:true,name:"pointer",description:"Function that is called whenever the theme is changed."}],ep:"extensionpoint",name:"themeChange"},{indexOn:"name",description:"A theme is a way change the look of the application.",unregister:"index#unregisterTheme",register:"index#registerTheme",params:[{required:false,name:"url",description:"Name of a ThemeStylesFile that holds theme specific CSS rules - can also be an array of files."},
{required:true,name:"pointer",description:"Function that returns the ThemeData"}],ep:"extensionpoint",name:"theme"},{defaultValue:"standard",description:"The theme plugin's name to use. If set to 'standard' no theme will be used",type:"text",ep:"setting",name:"theme"},{pointer:"#appLaunched",ep:"appLaunched"}],type:"plugins/supported",description:"Handles colors in Bespin"},standard_syntax:{resourceURL:"resources/standard_syntax/",description:"Easy-to-use basis for syntax engines",environments:{worker:true},
dependencies:{syntax_worker:"0.0.0",syntax_directory:"0.0.0",underscore:"0.0.0"},testmodules:[],type:"plugins/supported",name:"standard_syntax"},types:{resourceURL:"resources/types/",description:"Defines parameter types for commands",testmodules:["tests/testBasic","tests/testTypes"],provides:[{indexOn:"name",description:"Commands can accept various arguments that the user enters or that are automatically supplied by the environment. Those arguments have types that define how they are supplied or completed. The pointer points to an object with methods convert(str value) and getDefault(). Both functions have `this` set to the command's `takes` parameter. If getDefault is not defined, the default on the command's `takes` is used, if there is one. The object can have a noInput property that is set to true to reflect that this type is provided directly by the system. getDefault must be defined in that case.",
ep:"extensionpoint",name:"type"},{description:"Text that the user needs to enter.",pointer:"basic#text",ep:"type",name:"text"},{description:"A JavaScript number",pointer:"basic#number",ep:"type",name:"number"},{description:"A true/false value",pointer:"basic#bool",ep:"type",name:"boolean"},{description:"An object that converts via JavaScript",pointer:"basic#object",ep:"type",name:"object"},{description:"A string that is constrained to be one of a number of pre-defined values",pointer:"basic#selection",
ep:"type",name:"selection"},{description:"A type which we don't understand from the outset, but which we hope context can help us with",ep:"type",name:"deferred"}],type:"plugins/supported",name:"types"},embedded:{testmodules:[],dependencies:{theme_manager:"0.0.0",text_editor:"0.0.0",appconfig:"0.0.0",edit_session:"0.0.0",screen_theme:"0.0.0"},resourceURL:"resources/embedded/",name:"embedded",type:"plugins/supported"},settings:{resourceURL:"resources/settings/",description:"Infrastructure and commands for managing user preferences",
dependencies:{types:"0.0"},testmodules:[],provides:[{description:"Storage for the customizable Bespin settings",pointer:"index#settings",ep:"appcomponent",name:"settings"},{indexOn:"name",description:"A setting is something that the application offers as a way to customize how it works",register:"index#addSetting",ep:"extensionpoint",name:"setting"},{description:"A settingChange is a way to be notified of changes to a setting",ep:"extensionpoint",name:"settingChange"},{pointer:"commands#setCommand",
description:"define and show settings",params:[{defaultValue:null,type:{pointer:"settings:index#getSettings",name:"selection"},name:"setting",description:"The name of the setting to display or alter"},{defaultValue:null,type:{pointer:"settings:index#getTypeSpecFromAssignment",name:"deferred"},name:"value",description:"The new value for the chosen setting"}],ep:"command",name:"set"},{pointer:"commands#unsetCommand",description:"unset a setting entirely",params:[{type:{pointer:"settings:index#getSettings",
name:"selection"},name:"setting",description:"The name of the setting to return to defaults"}],ep:"command",name:"unset"}],type:"plugins/supported",name:"settings"},appconfig:{resourceURL:"resources/appconfig/",description:"Instantiates components and displays the GUI based on configuration.",dependencies:{jquery:"0.0.0",canon:"0.0.0",settings:"0.0.0"},testmodules:[],provides:[{description:"Event: Fired when the app is completely launched.",ep:"extensionpoint",name:"appLaunched"}],type:"plugins/supported",
name:"appconfig"},syntax_worker:{resourceURL:"resources/syntax_worker/",description:"Coordinates multiple syntax engines",environments:{worker:true},dependencies:{syntax_directory:"0.0.0",underscore:"0.0.0"},testmodules:[],type:"plugins/supported",name:"syntax_worker"},screen_theme:{resourceURL:"resources/screen_theme/",description:"Bespins standard theme basePlugin",dependencies:{},testmodules:[],provides:[{url:["theme.less"],ep:"themestyles"},{defaultValue:"@global_font",ep:"themevariable",name:"container_font"},
{defaultValue:"@global_font_size",ep:"themevariable",name:"container_font_size"},{defaultValue:"@global_container_background",ep:"themevariable",name:"container_bg"},{defaultValue:"@global_color",ep:"themevariable",name:"container_color"},{defaultValue:"@global_line_height",ep:"themevariable",name:"container_line_height"},{defaultValue:"@global_pane_background",ep:"themevariable",name:"pane_bg"},{defaultValue:"@global_pane_border_radius",ep:"themevariable",name:"pane_border_radius"},{defaultValue:"@global_form_font",
ep:"themevariable",name:"form_font"},{defaultValue:"@global_form_font_size",ep:"themevariable",name:"form_font_size"},{defaultValue:"@global_form_line_height",ep:"themevariable",name:"form_line_height"},{defaultValue:"@global_form_color",ep:"themevariable",name:"form_color"},{defaultValue:"@global_form_text_shadow",ep:"themevariable",name:"form_text_shadow"},{defaultValue:"@global_pane_link_color",ep:"themevariable",name:"pane_a_color"},{defaultValue:"@global_font",ep:"themevariable",name:"pane_font"},
{defaultValue:"@global_font_size",ep:"themevariable",name:"pane_font_size"},{defaultValue:"@global_pane_text_shadow",ep:"themevariable",name:"pane_text_shadow"},{defaultValue:"@global_pane_h1_font",ep:"themevariable",name:"pane_h1_font"},{defaultValue:"@global_pane_h1_font_size",ep:"themevariable",name:"pane_h1_font_size"},{defaultValue:"@global_pane_h1_color",ep:"themevariable",name:"pane_h1_color"},{defaultValue:"@global_font_size * 1.8",ep:"themevariable",name:"pane_line_height"},{defaultValue:"@global_pane_color",
ep:"themevariable",name:"pane_color"},{defaultValue:"@global_text_shadow",ep:"themevariable",name:"pane_text_shadow"},{defaultValue:"@global_font",ep:"themevariable",name:"button_font"},{defaultValue:"@global_font_size",ep:"themevariable",name:"button_font_size"},{defaultValue:"@global_button_color",ep:"themevariable",name:"button_color"},{defaultValue:"@global_button_background",ep:"themevariable",name:"button_bg"},{defaultValue:"@button_bg - #063A27",ep:"themevariable",name:"button_bg2"},{defaultValue:"@button_bg - #194A5E",
ep:"themevariable",name:"button_border"},{defaultValue:"@global_control_background",ep:"themevariable",name:"control_bg"},{defaultValue:"@global_control_color",ep:"themevariable",name:"control_color"},{defaultValue:"@global_control_border",ep:"themevariable",name:"control_border"},{defaultValue:"@global_control_border_radius",ep:"themevariable",name:"control_border_radius"},{defaultValue:"@global_control_active_background",ep:"themevariable",name:"control_active_bg"},{defaultValue:"@global_control_active_border",
ep:"themevariable",name:"control_active_border"},{defaultValue:"@global_control_active_color",ep:"themevariable",name:"control_active_color"},{defaultValue:"@global_control_active_inset_color",ep:"themevariable",name:"control_active_inset_color"}],type:"plugins/supported",name:"screen_theme"}})})})();
(function(){var q=bespin.tiki.require("jquery").$,k=function(l,j,h){l=l.style[h]||document.defaultView.getComputedStyle(l,"").getPropertyValue(h);if(!l||l=="auto"||l=="intrinsic")l=j.style[h];return l};bespin.useBespin=function(l,j){var h=bespin.tiki.require("bespin:util/util"),d={},b=d.settings;j=j||{};for(var a in j)d[a]=j[a];j=d.settings;if(b!==undefined)for(a in b)if(j[a]===undefined)d.settings[a]=b[a];var i=null,e=new (bespin.tiki.require("bespin:promise").Promise);bespin.tiki.require.ensurePackage("::appconfig",
function(){var g=bespin.tiki.require("appconfig");if(h.isString(l))l=document.getElementById(l);if(h.none(d.initialContent))d.initialContent=l.value||l.innerHTML;l.innerHTML="";if(l.type=="textarea"){var o=l.parentNode,f=document.createElement("div"),m=function(){var n="position:relative;";["margin-top","margin-left","margin-right","margin-bottom"].forEach(function(w){n+=w+":"+k(l,f,w)+";"});var t=k(l,f,"width"),u=k(l,f,"height");n+="height:"+u+";width:"+t+";";n+="display:inline-block;";f.setAttribute("style",
n)};window.addEventListener("resize",m,false);m();for(l.nextSibling?o.insertBefore(f,l.nextSibling):o.appendChild(f);o.tagName!="BODY";){if(o.tagName=="FORM"){var s=o.onsubmit;o.onsubmit=function(n){l.value=i.editor.value;l.innerHTML=i.editor.value;s&&s.call(this,n)};break}o=o.parentNode}l.style.display="none";d.element=f;if(!h.none(l.getAttribute("readonly")))d.readOnly=true}else d.element=l;g.launch(d).then(function(n){i=n;e.resolve(n)})});return e};q(document).ready(function(){for(var l=[],j=document.querySelectorAll(".bespin"),
h=0;h<j.length;h++){var d=j[h],b=d.getAttribute("data-bespinoptions")||"{}";b=bespin.useBespin(d,JSON.parse(b));b.then(function(a){d.bespin=a},function(a){throw new Error("Launch failed: "+a);});l.push(b)}if(window.onBespinLoad){j=bespin.tiki.require("bespin:promise").group;j(l).then(function(){window.onBespinLoad()},function(){throw new Error("At least one Bespin failed to launch!");})}})})();
