UNPKG

@jsjoeio/code-server

Version:

Run VS Code on a remote server.

2 lines 15.7 kB
!function(e,t){for(var i in t)e[i]=t[i]}(exports,function(e){var t={};function i(s){if(t[s])return t[s].exports;var r=t[s]={i:s,l:!1,exports:{}};return e[s].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=e,i.c=t,i.d=function(e,t,s){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(s,r,function(t){return e[t]}.bind(null,r));return s},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=5)}([function(e,t){e.exports=require("vscode")},function(e,t){e.exports=require("path")},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var s,r,n,o,a,c=i(1),u=i(7),l=Object.prototype.toString;function d(e){return void 0!==e}function h(e){return"[object Number]"===l.call(e)}function v(e){return"[object String]"===l.call(e)}function g(e){return JSON.parse(u.readFileSync(e,"utf8"))}function f(e,t){return a&&(e="["+e.replace(/[aouei]/g,"$&$&")+"]"),0===t.length?e:e.replace(/\{(\d+)\}/g,(function(e,i){var s=i[0],r=t[s],n=e;return"string"==typeof r?n=r:"number"!=typeof r&&"boolean"!=typeof r&&null!=r||(n=String(r)),n}))}function p(e){return function(t,i){for(var s=[],r=2;r<arguments.length;r++)s[r-2]=arguments[r];return h(t)?t>=e.length?void console.error("Broken localize call found. Index out of bounds. Stacktrace is\n: "+new Error("").stack):f(e[t],s):v(i)?(console.warn("Message "+i+" didn't get externalized correctly."),f(i,s)):void console.error("Broken localize call found. Stacktrace is\n: "+new Error("").stack)}}function w(e,t){for(var i=[],s=2;s<arguments.length;s++)i[s-2]=arguments[s];return f(t,i)}function m(e,t){return n[e]=t,t}function S(e,t){var i,s,r,n=c.join(o.cacheRoot,e.id+"-"+e.hash+".json"),a=!1,l=!1;try{return i=JSON.parse(u.readFileSync(n,{encoding:"utf8",flag:"r"})),s=n,r=new Date,u.utimes(s,r,r,(function(){})),i}catch(e){if("ENOENT"===e.code)l=!0;else{if(!(e instanceof SyntaxError))throw e;console.log("Syntax error parsing message bundle: "+e.message+"."),u.unlink(n,(function(e){e&&console.error("Deleting corrupted bundle "+n+" failed.")})),a=!0}}if(!(i=function(e,t){var i=o.translationsConfig[e.id];if(i){var s=g(i).contents,r=g(c.join(t,"nls.metadata.json")),n=Object.create(null);for(var a in r){var u=r[a],l=s[e.outDir+"/"+a];if(l){for(var d=[],h=0;h<u.keys.length;h++){var f=u.keys[h],p=l[v(f)?f:f.key];void 0===p&&(p=u.messages[h]),d.push(p)}n[a]=d}else n[a]=u.messages}return n}}(e,t))||a)return i;if(l)try{u.writeFileSync(n,JSON.stringify(i),{encoding:"utf8",flag:"wx"})}catch(e){if("EEXIST"===e.code)return i;throw e}return i}function y(e){try{return function(e){var t=g(c.join(e,"nls.metadata.json")),i=Object.create(null);for(var s in t){var r=t[s];i[s]=r.messages}return i}(e)}catch(e){return void console.log("Generating default bundle from meta data failed.",e)}}function b(e,t){var i;if(!0===o.languagePackSupport&&void 0!==o.cacheRoot&&void 0!==o.languagePackId&&void 0!==o.translationsConfigFile&&void 0!==o.translationsConfig)try{i=S(e,t)}catch(e){console.log("Load or create bundle failed ",e)}if(!i){if(o.languagePackSupport)return y(t);var s=function(e){for(var t=o.locale;t;){var i=c.join(e,"nls.bundle."+t+".json");if(u.existsSync(i))return i;var s=t.lastIndexOf("-");t=s>0?t.substring(0,s):void 0}if(void 0===t){i=c.join(e,"nls.bundle.json");if(u.existsSync(i))return i}}(t);if(s)try{return g(s)}catch(e){console.log("Loading in the box message bundle failed.",e)}i=y(t)}return i}function _(e){if(!e)return w;var t=c.extname(e);if(t&&(e=e.substr(0,e.length-t.length)),o.messageFormat===s.both||o.messageFormat===s.bundle){var i=function(e){for(var t,i=c.dirname(e);t=c.join(i,"nls.metadata.header.json"),!u.existsSync(t);){var s=c.dirname(i);if(s===i){t=void 0;break}i=s}return t}(e);if(i){var r=c.dirname(i),l=n[r];if(void 0===l)try{var h=JSON.parse(u.readFileSync(i,"utf8"));try{var v=b(h,r);l=m(r,v?{header:h,nlsBundle:v}:null)}catch(e){console.error("Failed to load nls bundle",e),l=m(r,null)}}catch(e){console.error("Failed to read header file",e),l=m(r,null)}if(l){var f=e.substr(r.length+1).replace(/\\/g,"/"),S=l.nlsBundle[f];return void 0===S?(console.error("Messages for file "+e+" not found. See console for details."),function(){return"Messages not found."}):p(S)}}}if(o.messageFormat===s.both||o.messageFormat===s.file)try{var y=g(function(e){var t;if(o.cacheLanguageResolution&&t)t=t;else{if(a||!o.locale)t=".nls.json";else for(var i=o.locale;i;){var s=".nls."+i+".json";if(u.existsSync(e+s)){t=s;break}var r=i.lastIndexOf("-");r>0?i=i.substring(0,r):(t=".nls.json",i=null)}o.cacheLanguageResolution&&(t=t)}return e+t}(e));return Array.isArray(y)?p(y):d(y.messages)&&d(y.keys)?p(y.messages):(console.error("String bundle '"+e+"' uses an unsupported format."),function(){return"File bundle has unsupported format. See console for details"})}catch(e){"ENOENT"!==e.code&&console.error("Failed to load single file bundle",e)}return console.error("Failed to load message bundle for file "+e),function(){return"Failed to load message bundle. See console for details."}}!function(e){e.file="file",e.bundle="bundle",e.both="both"}(s=t.MessageFormat||(t.MessageFormat={})),function(e){e.is=function(e){var t=e;return t&&d(t.key)&&d(t.comment)}}(r||(r={})),function(){if(o={locale:void 0,languagePackSupport:!1,cacheLanguageResolution:!0,messageFormat:s.bundle},v(process.env.VSCODE_NLS_CONFIG))try{var e=JSON.parse(process.env.VSCODE_NLS_CONFIG);if(v(e.locale)&&(o.locale=e.locale.toLowerCase()),(!0===(t=e._languagePackSupport)||!1===t)&&(o.languagePackSupport=e._languagePackSupport),v(e._cacheRoot)&&(o.cacheRoot=e._cacheRoot),v(e._languagePackId)&&(o.languagePackId=e._languagePackId),v(e._translationsConfigFile)){o.translationsConfigFile=e._translationsConfigFile;try{o.translationsConfig=g(o.translationsConfigFile)}catch(t){e._corruptedFile&&u.writeFile(e._corruptedFile,"corrupted","utf8",(function(e){console.error(e)}))}}}catch(e){}var t;a="pseudo"===o.locale,void 0,n=Object.create(null)}(),t.loadMessageBundle=_,t.config=function(e){return e&&(v(e.locale)&&(o.locale=e.locale.toLowerCase(),void 0,n=Object.create(null)),void 0!==e.messageFormat&&(o.messageFormat=e.messageFormat)),a="pseudo"===o.locale,_}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PreviewStatusBarEntry=void 0;const s=i(0),r=i(4);class n extends r.Disposable{constructor(e,t,i,r){super(),this.entry=this._register(s.window.createStatusBarItem(e,i,r)),this.entry.name=t}showItem(e,t){this._showOwner=e,this.entry.text=t,this.entry.show()}hide(e){e===this._showOwner&&(this.entry.hide(),this._showOwner=void 0)}}t.PreviewStatusBarEntry=n},function(e,t,i){"use strict";function s(e){for(;e.length;){const t=e.pop();t&&t.dispose()}}Object.defineProperty(t,"__esModule",{value:!0}),t.Disposable=t.disposeAll=void 0,t.disposeAll=s;t.Disposable=class{constructor(){this._isDisposed=!1,this._disposables=[]}dispose(){this._isDisposed||(this._isDisposed=!0,s(this._disposables))}_register(e){return this._isDisposed?e.dispose():this._disposables.push(e),e}get isDisposed(){return this._isDisposed}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.activate=void 0;const s=i(0),r=i(6),n=i(8),o=i(9),a=i(10);t.activate=function(e){const t=new o.SizeStatusBarEntry;e.subscriptions.push(t);const i=new r.BinarySizeStatusBarEntry;e.subscriptions.push(i);const c=new a.ZoomStatusBarEntry;e.subscriptions.push(c);const u=new n.PreviewManager(e.extensionUri,t,i,c);e.subscriptions.push(s.window.registerCustomEditorProvider(n.PreviewManager.viewType,u,{supportsMultipleEditorsPerDocument:!0})),e.subscriptions.push(s.commands.registerCommand("imagePreview.zoomIn",()=>{var e;null===(e=u.activePreview)||void 0===e||e.zoomIn()})),e.subscriptions.push(s.commands.registerCommand("imagePreview.zoomOut",()=>{var e;null===(e=u.activePreview)||void 0===e||e.zoomOut()}))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.BinarySizeStatusBarEntry=void 0;const s=i(0),r=i(2),n=i(3),o=r.loadMessageBundle(i(1).join(__dirname,"binarySizeStatusBarEntry.ts"));class a{static formatSize(e){return e<a.KB?o(0,null,e):e<a.MB?o(1,null,(e/a.KB).toFixed(2)):e<a.GB?o(2,null,(e/a.MB).toFixed(2)):e<a.TB?o(3,null,(e/a.GB).toFixed(2)):o(4,null,(e/a.TB).toFixed(2))}}a.KB=1024,a.MB=a.KB*a.KB,a.GB=a.MB*a.KB,a.TB=a.GB*a.KB;class c extends n.PreviewStatusBarEntry{constructor(){super("status.imagePreview.binarySize",o(5,null),s.StatusBarAlignment.Right,100)}show(e,t){"number"==typeof t?super.showItem(e,a.formatSize(t)):this.hide(e)}}t.BinarySizeStatusBarEntry=c},function(e,t){e.exports=require("fs")},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PreviewManager=void 0;const s=i(0),r=i(2),n=i(4),o=r.loadMessageBundle(i(1).join(__dirname,"preview.ts"));class a{constructor(e,t,i,s){this.extensionRoot=e,this.sizeStatusBarEntry=t,this.binarySizeStatusBarEntry=i,this.zoomStatusBarEntry=s,this._previews=new Set}async openCustomDocument(e){return{uri:e,dispose:()=>{}}}async resolveCustomEditor(e,t){const i=new c(this.extensionRoot,e.uri,t,this.sizeStatusBarEntry,this.binarySizeStatusBarEntry,this.zoomStatusBarEntry);this._previews.add(i),this.setActivePreview(i),t.onDidDispose(()=>{this._previews.delete(i)}),t.onDidChangeViewState(()=>{t.active?this.setActivePreview(i):this._activePreview!==i||t.active||this.setActivePreview(void 0)})}get activePreview(){return this._activePreview}setActivePreview(e){this._activePreview=e,this.setPreviewActiveContext(!!e)}setPreviewActiveContext(e){s.commands.executeCommand("setContext","imagePreviewFocus",e)}}t.PreviewManager=a,a.viewType="imagePreview.previewEditor";class c extends n.Disposable{constructor(e,t,i,r,n,o){super(),this.extensionRoot=e,this.resource=t,this.webviewEditor=i,this.sizeStatusBarEntry=r,this.binarySizeStatusBarEntry=n,this.zoomStatusBarEntry=o,this.id=`${Date.now()}-${Math.random().toString()}`,this._previewState=1,this.emptyPngDataUri="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAEElEQVR42gEFAPr/AP///wAI/AL+Sr4t6gAAAABJRU5ErkJggg==";const a=t.with({path:t.path.replace(/\/[^\/]+?\.\w+$/,"/")});i.webview.options={enableScripts:!0,localResourceRoots:[a,e]},this._register(i.webview.onDidReceiveMessage(e=>{switch(e.type){case"size":this._imageSize=e.value,this.update();break;case"zoom":this._imageZoom=e.value,this.update();break;case"reopen-as-text":s.commands.executeCommand("vscode.openWith",t,"default",i.viewColumn)}})),this._register(o.onDidChangeScale(e=>{2===this._previewState&&this.webviewEditor.webview.postMessage({type:"setScale",scale:e.scale})})),this._register(i.onDidChangeViewState(()=>{this.update(),this.webviewEditor.webview.postMessage({type:"setActive",value:this.webviewEditor.active})})),this._register(i.onDidDispose(()=>{2===this._previewState&&(this.sizeStatusBarEntry.hide(this.id),this.binarySizeStatusBarEntry.hide(this.id),this.zoomStatusBarEntry.hide(this.id)),this._previewState=0}));const c=this._register(s.workspace.createFileSystemWatcher(t.fsPath));this._register(c.onDidChange(e=>{e.toString()===this.resource.toString()&&this.render()})),this._register(c.onDidDelete(e=>{e.toString()===this.resource.toString()&&this.webviewEditor.dispose()})),s.workspace.fs.stat(t).then(({size:e})=>{this._imageBinarySize=e,this.update()}),this.render(),this.update(),this.webviewEditor.webview.postMessage({type:"setActive",value:this.webviewEditor.active})}zoomIn(){2===this._previewState&&this.webviewEditor.webview.postMessage({type:"zoomIn"})}zoomOut(){2===this._previewState&&this.webviewEditor.webview.postMessage({type:"zoomOut"})}async render(){0!==this._previewState&&(this.webviewEditor.webview.html=await this.getWebviewContents())}update(){0!==this._previewState&&(this.webviewEditor.active?(this._previewState=2,this.sizeStatusBarEntry.show(this.id,this._imageSize||""),this.binarySizeStatusBarEntry.show(this.id,this._imageBinarySize),this.zoomStatusBarEntry.show(this.id,this._imageZoom||"fit")):(2===this._previewState&&(this.sizeStatusBarEntry.hide(this.id),this.binarySizeStatusBarEntry.hide(this.id),this.zoomStatusBarEntry.hide(this.id)),this._previewState=1))}async getWebviewContents(){const e=Date.now().toString(),t={isMac:"darwin"===process.platform,src:await this.getResourcePath(this.webviewEditor,this.resource,e)},i=Date.now().toString(),s=this.webviewEditor.webview.cspSource;return`<!DOCTYPE html>\n<html lang="en">\n<head>\n\t<meta charset="UTF-8">\n\t\x3c!-- Disable pinch zooming --\x3e\n\t<meta name="viewport"\n\t\tcontent="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">\n\t<title>Image Preview</title>\n\t<link rel="stylesheet" href="${u(this.extensionResource("/media/main.css"))}" type="text/css" media="screen" nonce="${i}">\n\t<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data: ${s}; script-src 'nonce-${i}'; style-src ${s} 'nonce-${i}';">\n\t<meta id="image-preview-settings" data-settings="${u(JSON.stringify(t))}">\n</head>\n<body class="container image scale-to-fit loading">\n\t<div class="loading-indicator"></div>\n\t<div class="image-load-error">\n\t\t<p>${o(0,null)}</p>\n\t\t<a href="#" class="open-file-link">${o(1,null)}</a>\n\t</div>\n\t<script src="${u(this.extensionResource("/media/main.js"))}" nonce="${i}"><\/script>\n</body>\n</html>`}async getResourcePath(e,t,i){if("git"===t.scheme){if(0===(await s.workspace.fs.stat(t)).size)return this.emptyPngDataUri}return t.query?e.webview.asWebviewUri(t).toString():e.webview.asWebviewUri(t).with({query:"version="+i}).toString()}extensionResource(e){return this.webviewEditor.webview.asWebviewUri(this.extensionRoot.with({path:this.extensionRoot.path+e}))}}function u(e){return e.toString().replace(/"/g,"&quot;")}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SizeStatusBarEntry=void 0;const s=i(0),r=i(2),n=i(3),o=r.loadMessageBundle(i(1).join(__dirname,"sizeStatusBarEntry.ts"));class a extends n.PreviewStatusBarEntry{constructor(){super("status.imagePreview.size",o(0,null),s.StatusBarAlignment.Right,101)}show(e,t){this.showItem(e,t)}}t.SizeStatusBarEntry=a},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ZoomStatusBarEntry=void 0;const s=i(0),r=i(2),n=i(3),o=r.loadMessageBundle(i(1).join(__dirname,"zoomStatusBarEntry.ts"));class a extends n.PreviewStatusBarEntry{constructor(){super("status.imagePreview.zoom",o(0,null),s.StatusBarAlignment.Right,102),this._onDidChangeScale=this._register(new s.EventEmitter),this.onDidChangeScale=this._onDidChangeScale.event,this._register(s.commands.registerCommand("_imagePreview.selectZoomLevel",async()=>{const e=[10,5,2,1,.5,.2,"fit"].map(e=>({label:this.zoomLabel(e),scale:e})),t=await s.window.showQuickPick(e,{placeHolder:o(1,null)});t&&this._onDidChangeScale.fire({scale:t.scale})})),this.entry.command="_imagePreview.selectZoomLevel"}show(e,t){this.showItem(e,this.zoomLabel(t))}zoomLabel(e){return"fit"===e?o(2,null):Math.round(100*e)+"%"}}t.ZoomStatusBarEntry=a}])); //# sourceMappingURL=https://ticino.blob.core.windows.net/sourcemaps/undefined/extensions/image-preview/dist/extension.js.map