custom-electron-titlebar 3.2.5 → 3.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/.vscode/launch.json +49 -0
  2. package/.vscode/tasks.json +34 -0
  3. package/README.md +15 -24
  4. package/_config.yml +1 -0
  5. package/{lib → build}/browser/browser.d.ts +0 -0
  6. package/{lib → build}/browser/browser.js +1 -0
  7. package/build/browser/browser.js.map +1 -0
  8. package/{lib → build}/browser/event.d.ts +0 -0
  9. package/{lib → build}/browser/event.js +3 -1
  10. package/build/browser/event.js.map +1 -0
  11. package/{lib → build}/browser/iframe.d.ts +0 -0
  12. package/{lib/base → build}/browser/iframe.js +1 -0
  13. package/build/browser/iframe.js.map +1 -0
  14. package/{lib → build}/browser/keyboardEvent.d.ts +0 -0
  15. package/{lib → build}/browser/keyboardEvent.js +1 -0
  16. package/build/browser/keyboardEvent.js.map +1 -0
  17. package/{lib → build}/browser/mouseEvent.d.ts +0 -0
  18. package/{lib → build}/browser/mouseEvent.js +1 -0
  19. package/build/browser/mouseEvent.js.map +1 -0
  20. package/{lib → build}/common/arrays.d.ts +0 -0
  21. package/{lib → build}/common/arrays.js +1 -0
  22. package/build/common/arrays.js.map +1 -0
  23. package/{lib → build}/common/async.d.ts +0 -0
  24. package/{lib → build}/common/async.js +1 -0
  25. package/build/common/async.js.map +1 -0
  26. package/{lib → build}/common/charCode.d.ts +0 -0
  27. package/{lib/base → build}/common/charCode.js +1 -0
  28. package/build/common/charCode.js.map +1 -0
  29. package/{lib → build}/common/color.d.ts +0 -0
  30. package/{lib → build}/common/color.js +1 -0
  31. package/build/common/color.js.map +1 -0
  32. package/{lib → build}/common/dom.d.ts +0 -0
  33. package/{lib → build}/common/dom.js +17 -14
  34. package/build/common/dom.js.map +1 -0
  35. package/{lib → build}/common/event.d.ts +0 -0
  36. package/{lib → build}/common/event.js +2 -1
  37. package/build/common/event.js.map +1 -0
  38. package/{lib → build}/common/iterator.d.ts +0 -0
  39. package/{lib → build}/common/iterator.js +1 -0
  40. package/build/common/iterator.js.map +1 -0
  41. package/{lib → build}/common/keyCodes.d.ts +0 -0
  42. package/{lib → build}/common/keyCodes.js +1 -0
  43. package/build/common/keyCodes.js.map +1 -0
  44. package/{lib → build}/common/lifecycle.d.ts +0 -0
  45. package/{lib → build}/common/lifecycle.js +1 -0
  46. package/build/common/lifecycle.js.map +1 -0
  47. package/{lib → build}/common/linkedList.d.ts +0 -0
  48. package/{lib → build}/common/linkedList.js +1 -0
  49. package/build/common/linkedList.js.map +1 -0
  50. package/{lib → build}/common/platform.d.ts +0 -0
  51. package/{lib → build}/common/platform.js +1 -0
  52. package/build/common/platform.js.map +1 -0
  53. package/{lib → build}/index.d.ts +0 -0
  54. package/{lib → build}/index.js +1 -0
  55. package/build/index.js.map +1 -0
  56. package/{lib → build}/menu/menu.d.ts +0 -0
  57. package/{lib → build}/menu/menu.js +39 -38
  58. package/build/menu/menu.js.map +1 -0
  59. package/{lib → build}/menu/menuitem.d.ts +10 -2
  60. package/{lib → build}/menu/menuitem.js +71 -29
  61. package/build/menu/menuitem.js.map +1 -0
  62. package/{lib → build}/menubar.d.ts +0 -0
  63. package/{lib → build}/menubar.js +38 -34
  64. package/build/menubar.js.map +1 -0
  65. package/{lib → build}/themebar.d.ts +0 -0
  66. package/{lib → build}/themebar.js +31 -2
  67. package/build/themebar.js.map +1 -0
  68. package/{lib → build}/titlebar.d.ts +0 -0
  69. package/{lib → build}/titlebar.js +72 -59
  70. package/build/titlebar.js.map +1 -0
  71. package/package.json +13 -7
  72. package/lib/base/browser/browser.d.ts +0 -25
  73. package/lib/base/browser/browser.js +0 -117
  74. package/lib/base/browser/canIUse.d.ts +0 -18
  75. package/lib/base/browser/canIUse.js +0 -63
  76. package/lib/base/browser/dom.d.ts +0 -230
  77. package/lib/base/browser/dom.js +0 -1080
  78. package/lib/base/browser/event.d.ts +0 -12
  79. package/lib/base/browser/event.js +0 -28
  80. package/lib/base/browser/iframe.d.ts +0 -33
  81. package/lib/base/browser/keyboardEvent.d.ts +0 -40
  82. package/lib/base/browser/keyboardEvent.js +0 -256
  83. package/lib/base/browser/mouseEvent.d.ts +0 -69
  84. package/lib/base/browser/mouseEvent.js +0 -146
  85. package/lib/base/common/arrays.d.ts +0 -149
  86. package/lib/base/common/arrays.js +0 -549
  87. package/lib/base/common/async.d.ts +0 -259
  88. package/lib/base/common/async.js +0 -728
  89. package/lib/base/common/cancellation.d.ts +0 -29
  90. package/lib/base/common/cancellation.js +0 -114
  91. package/lib/base/common/charCode.d.ts +0 -415
  92. package/lib/base/common/color.d.ts +0 -163
  93. package/lib/base/common/color.js +0 -495
  94. package/lib/base/common/errors.d.ts +0 -65
  95. package/lib/base/common/errors.js +0 -164
  96. package/lib/base/common/event.d.ts +0 -248
  97. package/lib/base/common/event.js +0 -703
  98. package/lib/base/common/functional.d.ts +0 -1
  99. package/lib/base/common/functional.js +0 -21
  100. package/lib/base/common/iterator.d.ts +0 -16
  101. package/lib/base/common/iterator.js +0 -82
  102. package/lib/base/common/keyCodes.d.ts +0 -268
  103. package/lib/base/common/keyCodes.js +0 -292
  104. package/lib/base/common/lifecycle.d.ts +0 -67
  105. package/lib/base/common/lifecycle.js +0 -234
  106. package/lib/base/common/linkedList.d.ts +0 -16
  107. package/lib/base/common/linkedList.js +0 -128
  108. package/lib/base/common/network.d.ts +0 -65
  109. package/lib/base/common/network.js +0 -124
  110. package/lib/base/common/path.d.ts +0 -39
  111. package/lib/base/common/path.js +0 -1407
  112. package/lib/base/common/platform.d.ts +0 -53
  113. package/lib/base/common/platform.js +0 -176
  114. package/lib/base/common/process.d.ts +0 -5
  115. package/lib/base/common/process.js +0 -18
  116. package/lib/base/common/sequence.d.ts +0 -27
  117. package/lib/base/common/sequence.js +0 -32
  118. package/lib/base/common/uri.d.ts +0 -153
  119. package/lib/base/common/uri.js +0 -612
  120. package/lib/browser/iframe.js +0 -109
  121. package/lib/common/charCode.js +0 -6
  122. package/lib/menu.d.ts +0 -53
  123. package/lib/menu.js +0 -532
  124. package/lib/menuitem.d.ts +0 -46
  125. package/lib/menuitem.js +0 -295
  126. package/lib/vs/base/browser/browser.d.ts +0 -25
  127. package/lib/vs/base/browser/browser.js +0 -117
  128. package/lib/vs/base/browser/canIUse.d.ts +0 -18
  129. package/lib/vs/base/browser/canIUse.js +0 -63
  130. package/lib/vs/base/browser/dom.d.ts +0 -230
  131. package/lib/vs/base/browser/dom.js +0 -1080
  132. package/lib/vs/base/browser/event.d.ts +0 -12
  133. package/lib/vs/base/browser/event.js +0 -28
  134. package/lib/vs/base/browser/iframe.d.ts +0 -33
  135. package/lib/vs/base/browser/iframe.js +0 -109
  136. package/lib/vs/base/browser/keyboardEvent.d.ts +0 -40
  137. package/lib/vs/base/browser/keyboardEvent.js +0 -256
  138. package/lib/vs/base/browser/mouseEvent.d.ts +0 -69
  139. package/lib/vs/base/browser/mouseEvent.js +0 -146
  140. package/lib/vs/base/common/arrays.d.ts +0 -149
  141. package/lib/vs/base/common/arrays.js +0 -549
  142. package/lib/vs/base/common/async.d.ts +0 -259
  143. package/lib/vs/base/common/async.js +0 -728
  144. package/lib/vs/base/common/cancellation.d.ts +0 -29
  145. package/lib/vs/base/common/cancellation.js +0 -114
  146. package/lib/vs/base/common/charCode.d.ts +0 -415
  147. package/lib/vs/base/common/charCode.js +0 -6
  148. package/lib/vs/base/common/color.d.ts +0 -163
  149. package/lib/vs/base/common/color.js +0 -495
  150. package/lib/vs/base/common/errors.d.ts +0 -65
  151. package/lib/vs/base/common/errors.js +0 -164
  152. package/lib/vs/base/common/event.d.ts +0 -248
  153. package/lib/vs/base/common/event.js +0 -703
  154. package/lib/vs/base/common/functional.d.ts +0 -1
  155. package/lib/vs/base/common/functional.js +0 -21
  156. package/lib/vs/base/common/iterator.d.ts +0 -16
  157. package/lib/vs/base/common/iterator.js +0 -82
  158. package/lib/vs/base/common/keyCodes.d.ts +0 -268
  159. package/lib/vs/base/common/keyCodes.js +0 -292
  160. package/lib/vs/base/common/lifecycle.d.ts +0 -67
  161. package/lib/vs/base/common/lifecycle.js +0 -234
  162. package/lib/vs/base/common/linkedList.d.ts +0 -16
  163. package/lib/vs/base/common/linkedList.js +0 -128
  164. package/lib/vs/base/common/network.d.ts +0 -65
  165. package/lib/vs/base/common/network.js +0 -124
  166. package/lib/vs/base/common/path.d.ts +0 -39
  167. package/lib/vs/base/common/path.js +0 -1407
  168. package/lib/vs/base/common/platform.d.ts +0 -53
  169. package/lib/vs/base/common/platform.js +0 -176
  170. package/lib/vs/base/common/process.d.ts +0 -5
  171. package/lib/vs/base/common/process.js +0 -18
  172. package/lib/vs/base/common/sequence.d.ts +0 -27
  173. package/lib/vs/base/common/sequence.js +0 -32
  174. package/lib/vs/base/common/uri.d.ts +0 -153
  175. package/lib/vs/base/common/uri.js +0 -612
@@ -1,612 +0,0 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the MIT License. See License.txt in the project root for license information.
5
- *--------------------------------------------------------------------------------------------*/
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.uriToFsPath = exports.URI = void 0;
27
- const platform_1 = require("vs/base/common/platform");
28
- const paths = __importStar(require("vs/base/common/path"));
29
- const _schemePattern = /^\w[\w\d+.-]*$/;
30
- const _singleSlashStart = /^\//;
31
- const _doubleSlashStart = /^\/\//;
32
- function _validateUri(ret, _strict) {
33
- // scheme, must be set
34
- if (!ret.scheme && _strict) {
35
- throw new Error(`[UriError]: Scheme is missing: {scheme: "", authority: "${ret.authority}", path: "${ret.path}", query: "${ret.query}", fragment: "${ret.fragment}"}`);
36
- }
37
- // scheme, https://tools.ietf.org/html/rfc3986#section-3.1
38
- // ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
39
- if (ret.scheme && !_schemePattern.test(ret.scheme)) {
40
- throw new Error('[UriError]: Scheme contains illegal characters.');
41
- }
42
- // path, http://tools.ietf.org/html/rfc3986#section-3.3
43
- // If a URI contains an authority component, then the path component
44
- // must either be empty or begin with a slash ("/") character. If a URI
45
- // does not contain an authority component, then the path cannot begin
46
- // with two slash characters ("//").
47
- if (ret.path) {
48
- if (ret.authority) {
49
- if (!_singleSlashStart.test(ret.path)) {
50
- throw new Error('[UriError]: If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character');
51
- }
52
- }
53
- else {
54
- if (_doubleSlashStart.test(ret.path)) {
55
- throw new Error('[UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")');
56
- }
57
- }
58
- }
59
- }
60
- // for a while we allowed uris *without* schemes and this is the migration
61
- // for them, e.g. an uri without scheme and without strict-mode warns and falls
62
- // back to the file-scheme. that should cause the least carnage and still be a
63
- // clear warning
64
- function _schemeFix(scheme, _strict) {
65
- if (!scheme && !_strict) {
66
- return 'file';
67
- }
68
- return scheme;
69
- }
70
- // implements a bit of https://tools.ietf.org/html/rfc3986#section-5
71
- function _referenceResolution(scheme, path) {
72
- // the slash-character is our 'default base' as we don't
73
- // support constructing URIs relative to other URIs. This
74
- // also means that we alter and potentially break paths.
75
- // see https://tools.ietf.org/html/rfc3986#section-5.1.4
76
- switch (scheme) {
77
- case 'https':
78
- case 'http':
79
- case 'file':
80
- if (!path) {
81
- path = _slash;
82
- }
83
- else if (path[0] !== _slash) {
84
- path = _slash + path;
85
- }
86
- break;
87
- }
88
- return path;
89
- }
90
- const _empty = '';
91
- const _slash = '/';
92
- const _regexp = /^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
93
- /**
94
- * Uniform Resource Identifier (URI) http://tools.ietf.org/html/rfc3986.
95
- * This class is a simple parser which creates the basic component parts
96
- * (http://tools.ietf.org/html/rfc3986#section-3) with minimal validation
97
- * and encoding.
98
- *
99
- * ```txt
100
- * foo://example.com:8042/over/there?name=ferret#nose
101
- * \_/ \______________/\_________/ \_________/ \__/
102
- * | | | | |
103
- * scheme authority path query fragment
104
- * | _____________________|__
105
- * / \ / \
106
- * urn:example:animal:ferret:nose
107
- * ```
108
- */
109
- class URI {
110
- /**
111
- * @internal
112
- */
113
- constructor(schemeOrData, authority, path, query, fragment, _strict = false) {
114
- if (typeof schemeOrData === 'object') {
115
- this.scheme = schemeOrData.scheme || _empty;
116
- this.authority = schemeOrData.authority || _empty;
117
- this.path = schemeOrData.path || _empty;
118
- this.query = schemeOrData.query || _empty;
119
- this.fragment = schemeOrData.fragment || _empty;
120
- // no validation because it's this URI
121
- // that creates uri components.
122
- // _validateUri(this);
123
- }
124
- else {
125
- this.scheme = _schemeFix(schemeOrData, _strict);
126
- this.authority = authority || _empty;
127
- this.path = _referenceResolution(this.scheme, path || _empty);
128
- this.query = query || _empty;
129
- this.fragment = fragment || _empty;
130
- _validateUri(this, _strict);
131
- }
132
- }
133
- static isUri(thing) {
134
- if (thing instanceof URI) {
135
- return true;
136
- }
137
- if (!thing) {
138
- return false;
139
- }
140
- return typeof thing.authority === 'string'
141
- && typeof thing.fragment === 'string'
142
- && typeof thing.path === 'string'
143
- && typeof thing.query === 'string'
144
- && typeof thing.scheme === 'string'
145
- && typeof thing.fsPath === 'function'
146
- && typeof thing.with === 'function'
147
- && typeof thing.toString === 'function';
148
- }
149
- // ---- filesystem path -----------------------
150
- /**
151
- * Returns a string representing the corresponding file system path of this URI.
152
- * Will handle UNC paths, normalizes windows drive letters to lower-case, and uses the
153
- * platform specific path separator.
154
- *
155
- * * Will *not* validate the path for invalid characters and semantics.
156
- * * Will *not* look at the scheme of this URI.
157
- * * The result shall *not* be used for display purposes but for accessing a file on disk.
158
- *
159
- *
160
- * The *difference* to `URI#path` is the use of the platform specific separator and the handling
161
- * of UNC paths. See the below sample of a file-uri with an authority (UNC path).
162
- *
163
- * ```ts
164
- const u = URI.parse('file://server/c$/folder/file.txt')
165
- u.authority === 'server'
166
- u.path === '/shares/c$/file.txt'
167
- u.fsPath === '\\server\c$\folder\file.txt'
168
- ```
169
- *
170
- * Using `URI#path` to read a file (using fs-apis) would not be enough because parts of the path,
171
- * namely the server name, would be missing. Therefore `URI#fsPath` exists - it's sugar to ease working
172
- * with URIs that represent files on disk (`file` scheme).
173
- */
174
- get fsPath() {
175
- // if (this.scheme !== 'file') {
176
- // console.warn(`[UriError] calling fsPath with scheme ${this.scheme}`);
177
- // }
178
- return uriToFsPath(this, false);
179
- }
180
- // ---- modify to new -------------------------
181
- with(change) {
182
- if (!change) {
183
- return this;
184
- }
185
- let { scheme, authority, path, query, fragment } = change;
186
- if (scheme === undefined) {
187
- scheme = this.scheme;
188
- }
189
- else if (scheme === null) {
190
- scheme = _empty;
191
- }
192
- if (authority === undefined) {
193
- authority = this.authority;
194
- }
195
- else if (authority === null) {
196
- authority = _empty;
197
- }
198
- if (path === undefined) {
199
- path = this.path;
200
- }
201
- else if (path === null) {
202
- path = _empty;
203
- }
204
- if (query === undefined) {
205
- query = this.query;
206
- }
207
- else if (query === null) {
208
- query = _empty;
209
- }
210
- if (fragment === undefined) {
211
- fragment = this.fragment;
212
- }
213
- else if (fragment === null) {
214
- fragment = _empty;
215
- }
216
- if (scheme === this.scheme
217
- && authority === this.authority
218
- && path === this.path
219
- && query === this.query
220
- && fragment === this.fragment) {
221
- return this;
222
- }
223
- return new Uri(scheme, authority, path, query, fragment);
224
- }
225
- // ---- parse & validate ------------------------
226
- /**
227
- * Creates a new URI from a string, e.g. `http://www.msft.com/some/path`,
228
- * `file:///usr/home`, or `scheme:with/path`.
229
- *
230
- * @param value A string which represents an URI (see `URI#toString`).
231
- */
232
- static parse(value, _strict = false) {
233
- const match = _regexp.exec(value);
234
- if (!match) {
235
- return new Uri(_empty, _empty, _empty, _empty, _empty);
236
- }
237
- return new Uri(match[2] || _empty, percentDecode(match[4] || _empty), percentDecode(match[5] || _empty), percentDecode(match[7] || _empty), percentDecode(match[9] || _empty), _strict);
238
- }
239
- /**
240
- * Creates a new URI from a file system path, e.g. `c:\my\files`,
241
- * `/usr/home`, or `\\server\share\some\path`.
242
- *
243
- * The *difference* between `URI#parse` and `URI#file` is that the latter treats the argument
244
- * as path, not as stringified-uri. E.g. `URI.file(path)` is **not the same as**
245
- * `URI.parse('file://' + path)` because the path might contain characters that are
246
- * interpreted (# and ?). See the following sample:
247
- * ```ts
248
- const good = URI.file('/coding/c#/project1');
249
- good.scheme === 'file';
250
- good.path === '/coding/c#/project1';
251
- good.fragment === '';
252
- const bad = URI.parse('file://' + '/coding/c#/project1');
253
- bad.scheme === 'file';
254
- bad.path === '/coding/c'; // path is now broken
255
- bad.fragment === '/project1';
256
- ```
257
- *
258
- * @param path A file system path (see `URI#fsPath`)
259
- */
260
- static file(path) {
261
- let authority = _empty;
262
- // normalize to fwd-slashes on windows,
263
- // on other systems bwd-slashes are valid
264
- // filename character, eg /f\oo/ba\r.txt
265
- if (platform_1.isWindows) {
266
- path = path.replace(/\\/g, _slash);
267
- }
268
- // check for authority as used in UNC shares
269
- // or use the path as given
270
- if (path[0] === _slash && path[1] === _slash) {
271
- const idx = path.indexOf(_slash, 2);
272
- if (idx === -1) {
273
- authority = path.substring(2);
274
- path = _slash;
275
- }
276
- else {
277
- authority = path.substring(2, idx);
278
- path = path.substring(idx) || _slash;
279
- }
280
- }
281
- return new Uri('file', authority, path, _empty, _empty);
282
- }
283
- static from(components) {
284
- return new Uri(components.scheme, components.authority, components.path, components.query, components.fragment);
285
- }
286
- /**
287
- * Join a URI path with path fragments and normalizes the resulting path.
288
- *
289
- * @param uri The input URI.
290
- * @param pathFragment The path fragment to add to the URI path.
291
- * @returns The resulting URI.
292
- */
293
- static joinPath(uri, ...pathFragment) {
294
- if (!uri.path) {
295
- throw new Error(`[UriError]: cannot call joinPaths on URI without path`);
296
- }
297
- let newPath;
298
- if (platform_1.isWindows && uri.scheme === 'file') {
299
- newPath = URI.file(paths.win32.join(uriToFsPath(uri, true), ...pathFragment)).path;
300
- }
301
- else {
302
- newPath = paths.posix.join(uri.path, ...pathFragment);
303
- }
304
- return uri.with({ path: newPath });
305
- }
306
- // ---- printing/externalize ---------------------------
307
- /**
308
- * Creates a string representation for this URI. It's guaranteed that calling
309
- * `URI.parse` with the result of this function creates an URI which is equal
310
- * to this URI.
311
- *
312
- * * The result shall *not* be used for display purposes but for externalization or transport.
313
- * * The result will be encoded using the percentage encoding and encoding happens mostly
314
- * ignore the scheme-specific encoding rules.
315
- *
316
- * @param skipEncoding Do not encode the result, default is `false`
317
- */
318
- toString(skipEncoding = false) {
319
- return _asFormatted(this, skipEncoding);
320
- }
321
- toJSON() {
322
- return this;
323
- }
324
- static revive(data) {
325
- if (!data) {
326
- // @ts-ignore
327
- return data;
328
- }
329
- else if (data instanceof URI) {
330
- return data;
331
- }
332
- else {
333
- const result = new Uri(data);
334
- result._formatted = data.external;
335
- result._fsPath = data._sep === _pathSepMarker ? data.fsPath : null;
336
- return result;
337
- }
338
- }
339
- }
340
- exports.URI = URI;
341
- const _pathSepMarker = platform_1.isWindows ? 1 : undefined;
342
- // This class exists so that URI is compatibile with vscode.Uri (API).
343
- class Uri extends URI {
344
- constructor() {
345
- super(...arguments);
346
- this._formatted = null;
347
- this._fsPath = null;
348
- }
349
- get fsPath() {
350
- if (!this._fsPath) {
351
- this._fsPath = uriToFsPath(this, false);
352
- }
353
- return this._fsPath;
354
- }
355
- toString(skipEncoding = false) {
356
- if (!skipEncoding) {
357
- if (!this._formatted) {
358
- this._formatted = _asFormatted(this, false);
359
- }
360
- return this._formatted;
361
- }
362
- else {
363
- // we don't cache that
364
- return _asFormatted(this, true);
365
- }
366
- }
367
- toJSON() {
368
- const res = {
369
- $mid: 1
370
- };
371
- // cached state
372
- if (this._fsPath) {
373
- res.fsPath = this._fsPath;
374
- res._sep = _pathSepMarker;
375
- }
376
- if (this._formatted) {
377
- res.external = this._formatted;
378
- }
379
- // uri components
380
- if (this.path) {
381
- res.path = this.path;
382
- }
383
- if (this.scheme) {
384
- res.scheme = this.scheme;
385
- }
386
- if (this.authority) {
387
- res.authority = this.authority;
388
- }
389
- if (this.query) {
390
- res.query = this.query;
391
- }
392
- if (this.fragment) {
393
- res.fragment = this.fragment;
394
- }
395
- return res;
396
- }
397
- }
398
- // reserved characters: https://tools.ietf.org/html/rfc3986#section-2.2
399
- const encodeTable = {
400
- [58 /* Colon */]: '%3A',
401
- [47 /* Slash */]: '%2F',
402
- [63 /* QuestionMark */]: '%3F',
403
- [35 /* Hash */]: '%23',
404
- [91 /* OpenSquareBracket */]: '%5B',
405
- [93 /* CloseSquareBracket */]: '%5D',
406
- [64 /* AtSign */]: '%40',
407
- [33 /* ExclamationMark */]: '%21',
408
- [36 /* DollarSign */]: '%24',
409
- [38 /* Ampersand */]: '%26',
410
- [39 /* SingleQuote */]: '%27',
411
- [40 /* OpenParen */]: '%28',
412
- [41 /* CloseParen */]: '%29',
413
- [42 /* Asterisk */]: '%2A',
414
- [43 /* Plus */]: '%2B',
415
- [44 /* Comma */]: '%2C',
416
- [59 /* Semicolon */]: '%3B',
417
- [61 /* Equals */]: '%3D',
418
- [32 /* Space */]: '%20',
419
- };
420
- function encodeURIComponentFast(uriComponent, allowSlash) {
421
- let res = undefined;
422
- let nativeEncodePos = -1;
423
- for (let pos = 0; pos < uriComponent.length; pos++) {
424
- const code = uriComponent.charCodeAt(pos);
425
- // unreserved characters: https://tools.ietf.org/html/rfc3986#section-2.3
426
- if ((code >= 97 /* a */ && code <= 122 /* z */)
427
- || (code >= 65 /* A */ && code <= 90 /* Z */)
428
- || (code >= 48 /* Digit0 */ && code <= 57 /* Digit9 */)
429
- || code === 45 /* Dash */
430
- || code === 46 /* Period */
431
- || code === 95 /* Underline */
432
- || code === 126 /* Tilde */
433
- || (allowSlash && code === 47 /* Slash */)) {
434
- // check if we are delaying native encode
435
- if (nativeEncodePos !== -1) {
436
- res += encodeURIComponent(uriComponent.substring(nativeEncodePos, pos));
437
- nativeEncodePos = -1;
438
- }
439
- // check if we write into a new string (by default we try to return the param)
440
- if (res !== undefined) {
441
- res += uriComponent.charAt(pos);
442
- }
443
- }
444
- else {
445
- // encoding needed, we need to allocate a new string
446
- if (res === undefined) {
447
- res = uriComponent.substr(0, pos);
448
- }
449
- // check with default table first
450
- const escaped = encodeTable[code];
451
- if (escaped !== undefined) {
452
- // check if we are delaying native encode
453
- if (nativeEncodePos !== -1) {
454
- res += encodeURIComponent(uriComponent.substring(nativeEncodePos, pos));
455
- nativeEncodePos = -1;
456
- }
457
- // append escaped variant to result
458
- res += escaped;
459
- }
460
- else if (nativeEncodePos === -1) {
461
- // use native encode only when needed
462
- nativeEncodePos = pos;
463
- }
464
- }
465
- }
466
- if (nativeEncodePos !== -1) {
467
- res += encodeURIComponent(uriComponent.substring(nativeEncodePos));
468
- }
469
- return res !== undefined ? res : uriComponent;
470
- }
471
- function encodeURIComponentMinimal(path) {
472
- let res = undefined;
473
- for (let pos = 0; pos < path.length; pos++) {
474
- const code = path.charCodeAt(pos);
475
- if (code === 35 /* Hash */ || code === 63 /* QuestionMark */) {
476
- if (res === undefined) {
477
- res = path.substr(0, pos);
478
- }
479
- res += encodeTable[code];
480
- }
481
- else {
482
- if (res !== undefined) {
483
- res += path[pos];
484
- }
485
- }
486
- }
487
- return res !== undefined ? res : path;
488
- }
489
- /**
490
- * Compute `fsPath` for the given uri
491
- */
492
- function uriToFsPath(uri, keepDriveLetterCasing) {
493
- let value;
494
- if (uri.authority && uri.path.length > 1 && uri.scheme === 'file') {
495
- // unc path: file://shares/c$/far/boo
496
- value = `//${uri.authority}${uri.path}`;
497
- }
498
- else if (uri.path.charCodeAt(0) === 47 /* Slash */
499
- && (uri.path.charCodeAt(1) >= 65 /* A */ && uri.path.charCodeAt(1) <= 90 /* Z */ || uri.path.charCodeAt(1) >= 97 /* a */ && uri.path.charCodeAt(1) <= 122 /* z */)
500
- && uri.path.charCodeAt(2) === 58 /* Colon */) {
501
- if (!keepDriveLetterCasing) {
502
- // windows drive letter: file:///c:/far/boo
503
- value = uri.path[1].toLowerCase() + uri.path.substr(2);
504
- }
505
- else {
506
- value = uri.path.substr(1);
507
- }
508
- }
509
- else {
510
- // other path
511
- value = uri.path;
512
- }
513
- if (platform_1.isWindows) {
514
- value = value.replace(/\//g, '\\');
515
- }
516
- return value;
517
- }
518
- exports.uriToFsPath = uriToFsPath;
519
- /**
520
- * Create the external version of a uri
521
- */
522
- function _asFormatted(uri, skipEncoding) {
523
- const encoder = !skipEncoding
524
- ? encodeURIComponentFast
525
- : encodeURIComponentMinimal;
526
- let res = '';
527
- let { scheme, authority, path, query, fragment } = uri;
528
- if (scheme) {
529
- res += scheme;
530
- res += ':';
531
- }
532
- if (authority || scheme === 'file') {
533
- res += _slash;
534
- res += _slash;
535
- }
536
- if (authority) {
537
- let idx = authority.indexOf('@');
538
- if (idx !== -1) {
539
- // <user>@<auth>
540
- const userinfo = authority.substr(0, idx);
541
- authority = authority.substr(idx + 1);
542
- idx = userinfo.indexOf(':');
543
- if (idx === -1) {
544
- res += encoder(userinfo, false);
545
- }
546
- else {
547
- // <user>:<pass>@<auth>
548
- res += encoder(userinfo.substr(0, idx), false);
549
- res += ':';
550
- res += encoder(userinfo.substr(idx + 1), false);
551
- }
552
- res += '@';
553
- }
554
- authority = authority.toLowerCase();
555
- idx = authority.indexOf(':');
556
- if (idx === -1) {
557
- res += encoder(authority, false);
558
- }
559
- else {
560
- // <auth>:<port>
561
- res += encoder(authority.substr(0, idx), false);
562
- res += authority.substr(idx);
563
- }
564
- }
565
- if (path) {
566
- // lower-case windows drive letters in /C:/fff or C:/fff
567
- if (path.length >= 3 && path.charCodeAt(0) === 47 /* Slash */ && path.charCodeAt(2) === 58 /* Colon */) {
568
- const code = path.charCodeAt(1);
569
- if (code >= 65 /* A */ && code <= 90 /* Z */) {
570
- path = `/${String.fromCharCode(code + 32)}:${path.substr(3)}`; // "/c:".length === 3
571
- }
572
- }
573
- else if (path.length >= 2 && path.charCodeAt(1) === 58 /* Colon */) {
574
- const code = path.charCodeAt(0);
575
- if (code >= 65 /* A */ && code <= 90 /* Z */) {
576
- path = `${String.fromCharCode(code + 32)}:${path.substr(2)}`; // "/c:".length === 3
577
- }
578
- }
579
- // encode the rest of the path
580
- res += encoder(path, true);
581
- }
582
- if (query) {
583
- res += '?';
584
- res += encoder(query, false);
585
- }
586
- if (fragment) {
587
- res += '#';
588
- res += !skipEncoding ? encodeURIComponentFast(fragment, false) : fragment;
589
- }
590
- return res;
591
- }
592
- // --- decode
593
- function decodeURIComponentGraceful(str) {
594
- try {
595
- return decodeURIComponent(str);
596
- }
597
- catch {
598
- if (str.length > 3) {
599
- return str.substr(0, 3) + decodeURIComponentGraceful(str.substr(3));
600
- }
601
- else {
602
- return str;
603
- }
604
- }
605
- }
606
- const _rEncodedAsHex = /(%[0-9A-Za-z][0-9A-Za-z])+/g;
607
- function percentDecode(str) {
608
- if (!str.match(_rEncodedAsHex)) {
609
- return str;
610
- }
611
- return str.replace(_rEncodedAsHex, (match) => decodeURIComponentGraceful(match));
612
- }