monaco-editor实现各种代码编辑器及代码对比效果示例代码
代码语言:html
所属分类:其他
代码描述:monaco-editor实现各种代码编辑器及代码对比效果示例代码,演示了各种编程语言的代码编辑器效果,包括亮色、暗色主题皮肤切换,以及两段代码的对比效果。
代码标签: monaco-editor 各种 代码 编辑器 代码 对比 效果 示例代 码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="viewport" content="width=device-width" /> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/bootstrap.3.3.4.css"> <style> body{padding:54px 0 40px 0;overflow-y:scroll}body.home{padding-top:0}.navbar-search .search-query,body,button,input,select,textarea{font:400 14px/1.4em 'Segoe UI','Open Sans',Calibri,Candara,Arial,sans-serif}.navbar .nav{float:left;margin-right:0}a{color:#06c;cursor:pointer}h1,h2,h3,h4,h5,h6{letter-spacing:-.01em;margin:0;line-height:normal}h1,h2{font-family:'Segoe UI Light','Segoe UI','Open Sans',Calibri,Candara,Arial,sans-serif;font-weight:300}h1{font-size:72px;letter-spacing:-.02em}.hero-unit h1{font-size:48px}h2{font-size:26px}h3{font-size:26px}h4{font-size:16px}h1 small,h2 small,h3 small,h4 small,h5 small,h6 small{color:#999}.alert h1,.alert h2,.alert h3,.alert h4,.alert h5,.alert h6,.alert-heading{color:inherit}.alert-info{color:#3a87ad;background-color:#d9edf7}.navbar-inverse .navbar-inner{background-color:#68217a;-webkit-filter:none;filter:none}.navbar-inverse.home .navbar-inner{background-color:transparent}.navbar-inverse .btn-navbar{background:0 0;margin-top:14px}.navbar-inverse .btn-navbar.active,.navbar-inverse .btn-navbar.disabled,.navbar-inverse .btn-navbar:active,.navbar-inverse .btn-navbar:focus,.navbar-inverse .btn-navbar:hover,.navbar-inverse .btn-navbar[disabled]{background:#442359}.btn-primary{background-color:#0072c6}.home .hero-unit{margin-top:-54px;position:relative;z-index:100}.hero-unit{font-weight:400}.hero-unit h1{margin:0 0 6px}.nav-tabs>li>a{color:#999}.nav-tabs>li>a:hover{color:#555}.nav-tabs>.active>a,.nav-tabs>.active>a:focus,.nav-tabs>.active>a:hover{color:#0072c6}body>section>.container{padding-top:12px}.masthead{background-color:#0072c6;color:#fff}.masthead .hero-unit{padding:30px 0 0;background:0 0}.navbar.home{position:relative;z-index:500}.navbar .nav>li>a{text-shadow:none;padding-top:18px;font-size:14px;text-transform:uppercase}.navbar-inverse .nav-collapse .nav>li>a{color:#fff;padding-left:0}.navbar-inverse .nav>li>a.nav-item:focus,.navbar-inverse .nav>li>a.nav-item:hover{background-color:rgba(0,0,0,.12)}.navbar-inverse .nav .active>a.nav-item,.navbar-inverse .nav .active>a.nav-item:focus,.navbar-inverse .nav .active>a.nav-item:hover{color:#fff;background-color:rgba(0,0,0,.24);-webkit-box-shadow:none;box-shadow:none}.navbar .logo{padding:16px 12px 0 0;height:35px;display:block;float:left}.navbar .logo a{color:#fff;font-size:24px;letter-spacing:-1px}.navbar-fixed-top{z-index:500}.flgroup:after{content:'';display:block;visibility:hidden;height:0;clear:both}@media (min-width:1200px){h1,h2{letter-spacing:-.04em}.hero-unit h1{font-size:72px}h2{font-size:36px}}#gh-link{display:none;position:fixed;top:0;right:0;border:0;margin:0;z-index:1000}@media (min-width:980px){#gh-link{display:block}}@media (min-width:980px){.navbar .nav{float:right}.navbar-inverse .nav-collapse .nav>li>a{padding-left:15px}}@media (min-width:768px) and (max-width:979px){h1{letter-spacing:-.02em}}@media (max-width:979px){body{padding:inherit}.navbar-fixed-bottom,.navbar-fixed-top,.navbar-static-top{margin-right:inherit;margin-left:inherit;margin-bottom:0}.navbar-fixed-top .navbar-inner{padding:0 20px}.navbar .container{width:724px}}@media (max-width:767px){.navbar .container{width:100%}}@media (max-width:480px){.navbar .logo a{display:none}} </style> <style> .try .drops{margin:0;list-style:none;float:right}.try .drops li{float:left;width:auto;height:auto;text-indent:0;font-size:26px;line-height:normal;margin:0 12px;cursor:pointer}.try .drops li a:focus,.try .drops li a:hover{text-decoration:none}.try .drops li h4{color:#999}.try .drops li.active h4,.try .drops li.active:hover h4{color:#0072c6}.try .drops li:hover h4{color:rgba(0,114,198,.5)}.try .editor.row{padding:18px 0}.try .row h4{padding-bottom:6px}.try .tile{position:relative;height:72px;border:1px solid #ddd;text-align:right;overflow:hidden;cursor:pointer;-webkit-box-shadow:0 1px 3px rgba(0,0,0,.055);-moz-box-shadow:0 1px 3px rgba(0,0,0,.055);box-shadow:0 1px 3px rgba(0,0,0,.055);-webkit-box-sizing:border-box;-o-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;box-sizing:border-box}.try .tile:hover{-webkit-box-shadow:0 1px 5px rgba(0,0,0,.25);-moz-box-shadow:0 1px 5px rgba(0,0,0,.25);box-shadow:0 1px 5px rgba(0,0,0,.25)}.try .tile h4{margin:0;position:absolute;right:12px;bottom:12px;z-index:1}.try .tile .glyph{position:absolute;left:12px;bottom:-6px;background:url('../img/cloud.png') no-repeat;background-size:80px 43px;height:43px;width:80px;opacity:.5;transition:opacity .5s ease,bottom .5s ease;-webkit-transition:opacity .5s ease,bottom .5s ease}.try .tile:hover .glyph{opacity:1;bottom:-2px}.try .editor.row h4 small{color:#555}.try .editor.row .control-label{display:inline-block;position:relative;top:-4px;margin-right:4px}.try .editor.row .monaco-editor .find-widget input[type=text]{margin-bottom:0;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;-webkit-transition:none;-moz-transition:none;-o-transition:none;transition:none}.try .editor.row .monaco-editor .find-widget .monaco-checkbox .label{min-height:20px;min-width:20px}.try .editor.row .monaco-editor .find-widget .close{float:none;opacity:1}.try .editor .editor-frame{position:relative}.try .editor .editor-frame #diff-editor,.try .editor .editor-frame #editor{height:400px;margin-bottom:10px;border:1px solid #eee}.try .editor .editor-frame .loading{position:absolute;height:100%;width:100%;background-color:rgba(255,255,255,.5);margin:0 auto;display:none;z-index:100}.try .editor .editor-frame .progress{width:50%;margin:15% auto 0}.try .editor .editor-frame .progress .bar{width:100%;background-color:#4bb1cf}.try .editor .editor-frame #diff-editor .alert,.try .editor .editor-frame #editor .alert{margin:18% auto 0;width:30%;text-align:center;color:#b94a48;background-color:#f2dede;border-color:#eed3d7}.try .editor #diff-editor .monaco-editor .row,.try .editor #editor .monaco-editor .row{margin-left:0}.try .editor .vs.monaco-editor .context-view.monaco-menu-container a{color:#646465}.try .editor .vs-dark.monaco-editor .context-view.monaco-menu-container a{color:#bbb}@media (min-width:1200px){.try .editor .row{margin-left:0}}@media (max-width:767px){.try .container{margin:0 24px}.try .tile h4{right:6px}.try .editor>.span9 .row .span4{float:left;width:50%}.try .editor h4{margin-top:0}}@media (max-width:520px){.try .editor>.span3 h4,.try .editor>.span3 p{display:none}}@media (max-width:320px){.try .editor>.span9{display:none}}.monaco-editor .container:before,.monaco-editor .row:before{content:'';display:inherit}.monaco-editor .container:after,.monaco-editor .row:after{clear:inherit}.monaco-editor .container{width:auto;margin:inherit;padding:inherit}.monaco-editor .close{float:none;font-size:inherit;font-weight:inherit;line-height:inherit;color:inherit;text-shadow:inherit;opacity:inherit;filter:inherit}.monaco-editor .row{margin:inherit}.monaco-editor .invisible{visibility:visible} </style> </head> <body> <pre data-preload="index/samples/sample.typescript.txt" style="display:none">/* Game of Life * Implemented in TypeScript * To learn more about TypeScript, please visit http://www.typescriptlang.org/ */ namespace Conway { export class Cell { public row: number; public col: number; public live: boolean; constructor(row: number, col: number, live: boolean) { this.row = row; this.col = col; this.live = live; } } export class GameOfLife { private gridSize: number; private canvasSize: number; private lineColor: string; private liveColor: string; private deadColor: string; private initialLifeProbability: number; private animationRate: number; private cellSize: number; private context: CanvasRenderingContext2D; private world; constructor() { this.gridSize = 50; this.canvasSize = 600; this.lineColor = '#cdcdcd'; this.liveColor = '#666'; this.deadColor = '#eee'; this.initialLifeProbability = 0.5; this.animationRate = 60; this.cellSize = 0; this.world = this.createWorld(); this.circleOfLife(); } public createWorld() { return this.travelWorld( (cell : Cell) => { cell.live = Math.random() < this.initialLifeProbability; return cell; }); } public circleOfLife() : void { this.world = this.travelWorld( (cell: Cell) => { cell = this.world[cell.row][cell.col]; this.draw(cell); return this.resolveNextGeneration(cell); }); setTimeout( () => {this.circleOfLife()}, this.animationRate); } public resolveNextGeneration(cell : Cell) { var count = this.countNeighbors(cell); var newCell = new Cell(cell.row, cell.col, cell.live); if(count < 2 || count > 3) newCell.live = false; else if(count == 3) newCell.live = true; return newCell; } public countNeighbors(cell : Cell) { var neighbors = 0; for(var row = -1; row <=1; row++) { for(var col = -1; col <= 1; col++) { if(row == 0 && col == 0) continue; if(this.isAlive(cell.row + row, cell.col + col)) { neighbors++; } } } return neighbors; } public isAlive(row : number, col : number) { if(row < 0 || col < 0 || row >= this.gridSize || col >= this.gridSize) return false; return this.world[row][col].live; } public travelWorld(callback) { var result = []; for(var row = 0; row < this.gridSize; row++) { var rowData = []; for(var col = 0; col < this.gridSize; col++) { rowData.push(callback(new Cell(row, col, false))); } result.push(rowData); } return result; } public draw(cell : Cell) { if(this.context == null) this.context = this.createDrawingContext(); if(this.cellSize == 0) this.cellSize = this.canvasSize/this.gridSize; this.context.strokeStyle = this.lineColor; this.context.strokeRect(cell.row * this.cellSize, cell.col*this.cellSize, this.cellSize, this.cellSize); this.context.fillStyle = cell.live ? this.liveColor : this.deadColor; this.context.fillRect(cell.row * this.cellSize, cell.col*this.cellSize, this.cellSize, this.cellSize); } public createDrawingContext() { var canvas = <HTMLCanvasElement> document.getElementById('conway-canvas'); if(canvas == null) { canvas = document.createElement('canvas'); canvas.id = 'conway-canvas'; canvas.width = this.canvasSize; canvas.height = this.canvasSize; document.body.appendChild(canvas); } return canvas.getContext('2d'); } } } var game = new Conway.GameOfLife(); </pre> <pre data-preload="index/samples/diff.lhs.txt" style="display:none"> /* © Microsoft. All rights reserved. This library is supported for use in Windows Tailored Apps only. Build: 6.2.8100.0 Version: 0.5 */ (function (global, undefined) { "use strict"; undefinedVariable = {}; undefinedVariable.prop = 5; function initializeProperties(target, members) { var keys = Object.keys(members); var properties; var i, len; for (i = 0, len = keys.length; i < len; i++) { var key = keys[i]; var enumerable = key.charCodeAt(0) !== /*_*/95; var member = members[key]; if (member && typeof member === 'object') { if (member.value !== undefined || typeof member.get === 'function' || typeof member.set === 'function') { if (member.enumerable === undefined) { member.enumerable = enumerable; } properties = properties || {}; properties[key] = member; continue; } } // These next lines will be deleted if (!enumerable) { properties = properties || {}; properties[key] = { value: member, enumerable: enumerable, configurable: true, writable: true } continue; } target[key] = member; } if (properties) { Object.defineProperties(target, properties); } } (function (rootNamespace) { // Create the rootNamespace in the global namespace if (!global[rootNamespace]) { global[rootNamespace] = Object.create(Object.prototype); } // Cache the rootNamespace we just created in a local variable var _rootNamespace = global[rootNamespace]; if (!_rootNamespace.Namespace) { _rootNamespace.Namespace = Object.create(Object.prototype); } function defineWithParent(parentNamespace, name, members) { /// <summary locid="1"> /// Defines a new namespace with the specified name, under the specified parent namespace. /// </summary> /// <param name="parentNamespace" type="Object" locid="2"> /// The parent namespace which will contain the new namespace. /// </param> /// <param name="name" type="String" locid="3"> /// Name of the new namespace. /// </param> /// <param name="members" type="Object" locid="4"> /// Members in the new namespace. /// </param> /// <returns locid="5"> /// The newly defined namespace. /// </returns> var currentNamespace = parentNamespace, namespaceFragments = name.split("."); for (var i = 0, len = namespaceFragments.length; i < len; i++) { var namespaceName = namespaceFragments[i]; if (!currentNamespace[namespaceName]) { Object.defineProperty(currentNamespace, namespaceName, { value: {}, writable: false, enumerable: true, configurable: true } ); } currentNamespace = currentNamespace[namespaceName]; } if (members) { initializeProperties(currentNamespace, members); } return currentNamespace; } function define(name, members) { /// <summary locid="6"> /// Defines a new namespace with the specified name. /// </summary> /// <param name="name" type="String" locid="7"> /// Name of the namespace. This could be a dot-separated nested name. /// </param> /// <param name="members" type="Object" locid="4"> /// Members in the new namespace. /// </param> /// <returns locid="5"> /// The newly defined namespace. /// </returns> return defineWithParent(global, name, members); } // Establish members of the "WinJS.Namespace" namespace Object.defineProperties(_rootNamespace.Namespace, { defineWithParent: { value: defineWithParent, writable: true, enumerable: true }, define: { value: define, writable: true, enumerable: true } }); })("WinJS"); (function (WinJS) { function define(constructor, instanceMembers, staticMembers) { /// <summary locid="8"> /// Defines a class using the given constructor and with the specified instance members. /// </summary> /// <param name="constructor" type="Function" locid="9"> /// A constructor function that will be used to instantiate this class. /// </param> /// <param name="instanceMembers" type="Object" locid="10"> /// The set of instance fields, properties and methods to be made available on the class. /// </param> /// <param name="staticMembers" type="Object" locid="11"> /// The set of static fields, properties and methods to be made available on the class. /// </param> /// <returns type="Function" locid="12"> /// The newly defined class. /// </returns> constructor = constructor || function () { }; if (instanceMembers) { initializeProperties(constructor.prototype, instanceMembers); } if (staticMembers) { initializeProperties(constructor, staticMembers); } return constructor; } function derive(baseClass, constructor, instanceMembers, staticMembers) { /// <summary locid="13"> /// Uses prototypal inheritance to create a sub-class based on the supplied baseClass parameter. /// </summary> /// <param name="baseClass" type="Function" locid="14"> /// The class to inherit from. /// </param> /// <param name="constructor" type="Function" locid="9"> /// A constructor function that will be used to instantiate this class. /// </param> /// <param name="instanceMembers" type="Object" locid="10"> /// The set of instance fields, properties and methods to be made available on the class. /// </param> /// <param name="staticMembers" type="Object" locid="11"> /// The set of static fields, properties and methods to be made available on the class. /// </param> /// <returns type="Function" locid="12"> /// The newly defined class. /// </returns> if (baseClass) { constructor = constructor || function () { }; var basePrototype = baseClass.prototype; constructor.prototype = Object.create(basePrototype); Object.defineProperty(constructor.prototype, "_super", { value: basePrototype }); Object.defineProperty(constructor.prototype, "constructor", { value: constructor }); if (instanceMembers) { initializeProperties(constructor.prototype, instanceMembers); } if (staticMembers) { initializeProperties(constructor, staticMembers); } return constructor; } else { return define(constructor, instanceMembers, staticMembers); } } function mix(constructor) { /// <summary locid="15"> /// Defines a class using the given constructor and the union of the set of instance members /// specified by all the mixin objects. The mixin parameter list can be of variable length. /// </summary> /// <param name="constructor" locid="9"> /// A constructor function that will be used to instantiate this class. /// </param> /// <returns locid="12"> /// The newly defined class. /// </returns> constructor = constructor || function () { }; var i, len; for (i = 0, len = arguments.length; i < len; i++) { initializeProperties(constructor.prototype, arguments[i]); } return constructor; } // Establish members of "WinJS.Class" namespace WinJS.Namespace.define("WinJS.Class", { define: define, derive: derive, mix: mix }); })(WinJS); })(this);</pre> <pre data-preload="index/samples/diff.rhs.txt" style="display:none"> /* © Microsoft. All rights reserved. This library is supported for use in Windows Tailored Apps only. Build: 6.2.8100.0 Version: 0.5 */ // Here are some inserted lines // with some extra comments (function (global, undefined) { "use strict"; var definedVariable.........完整代码请登录后点击上方下载按钮下载查看
网友评论0