monaco-editor-core 0.53.0 → 0.54.0-dev-20250909

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 (29) hide show
  1. package/esm/nls.messages.de.js +1 -1
  2. package/esm/nls.messages.es.js +1 -1
  3. package/esm/nls.messages.fr.js +1 -1
  4. package/esm/nls.messages.it.js +1 -1
  5. package/esm/nls.messages.ja.js +1 -1
  6. package/esm/nls.messages.ko.js +1 -1
  7. package/esm/nls.messages.ru.js +1 -1
  8. package/esm/nls.messages.zh-cn.js +1 -1
  9. package/esm/nls.messages.zh-tw.js +1 -1
  10. package/esm/vs/base/browser/domSanitize.js +18 -8
  11. package/esm/vs/base/browser/domSanitize.js.map +1 -1
  12. package/esm/vs/base/browser/domStylesheets.js +3 -0
  13. package/esm/vs/base/browser/domStylesheets.js.map +1 -1
  14. package/esm/vs/base/browser/ui/codicons/codicon/codicon.ttf +0 -0
  15. package/esm/vs/base/browser/ui/dropdown/dropdown.js +1 -2
  16. package/esm/vs/base/browser/ui/dropdown/dropdown.js.map +1 -1
  17. package/esm/vs/base/common/async.js +6 -0
  18. package/esm/vs/base/common/async.js.map +1 -1
  19. package/esm/vs/editor/browser/controller/editContext/native/screenReaderContentRich.js +23 -13
  20. package/esm/vs/editor/browser/controller/editContext/native/screenReaderContentRich.js.map +1 -1
  21. package/esm/vs/editor/common/config/editorOptions.js +1 -1
  22. package/esm/vs/editor/common/config/editorOptions.js.map +1 -1
  23. package/esm/vs/editor/common/viewModel/screenReaderSimpleModel.js.map +1 -1
  24. package/esm/vs/editor/contrib/linesOperations/browser/linesOperations.js +5 -4
  25. package/esm/vs/editor/contrib/linesOperations/browser/linesOperations.js.map +1 -1
  26. package/esm/vs/platform/actions/browser/actionViewItemService.js.map +1 -1
  27. package/esm/vs/platform/actions/browser/toolbar.js +3 -3
  28. package/esm/vs/platform/actions/browser/toolbar.js.map +1 -1
  29. package/package.json +2 -2
@@ -1,6 +1,6 @@
1
1
  /*!-----------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Version: 0.53.0(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
3
+ * Version: 0.54.0-dev-20250909(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
4
4
  * Released under the MIT license
5
5
  * https://github.com/microsoft/vscode/blob/main/LICENSE.txt
6
6
  *-----------------------------------------------------------*/
@@ -1,6 +1,6 @@
1
1
  /*!-----------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Version: 0.53.0(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
3
+ * Version: 0.54.0-dev-20250909(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
4
4
  * Released under the MIT license
5
5
  * https://github.com/microsoft/vscode/blob/main/LICENSE.txt
6
6
  *-----------------------------------------------------------*/
@@ -1,6 +1,6 @@
1
1
  /*!-----------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Version: 0.53.0(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
3
+ * Version: 0.54.0-dev-20250909(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
4
4
  * Released under the MIT license
5
5
  * https://github.com/microsoft/vscode/blob/main/LICENSE.txt
6
6
  *-----------------------------------------------------------*/
@@ -1,6 +1,6 @@
1
1
  /*!-----------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Version: 0.53.0(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
3
+ * Version: 0.54.0-dev-20250909(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
4
4
  * Released under the MIT license
5
5
  * https://github.com/microsoft/vscode/blob/main/LICENSE.txt
6
6
  *-----------------------------------------------------------*/
@@ -1,6 +1,6 @@
1
1
  /*!-----------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Version: 0.53.0(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
3
+ * Version: 0.54.0-dev-20250909(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
4
4
  * Released under the MIT license
5
5
  * https://github.com/microsoft/vscode/blob/main/LICENSE.txt
6
6
  *-----------------------------------------------------------*/
@@ -1,6 +1,6 @@
1
1
  /*!-----------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Version: 0.53.0(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
3
+ * Version: 0.54.0-dev-20250909(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
4
4
  * Released under the MIT license
5
5
  * https://github.com/microsoft/vscode/blob/main/LICENSE.txt
6
6
  *-----------------------------------------------------------*/
@@ -1,6 +1,6 @@
1
1
  /*!-----------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Version: 0.53.0(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
3
+ * Version: 0.54.0-dev-20250909(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
4
4
  * Released under the MIT license
5
5
  * https://github.com/microsoft/vscode/blob/main/LICENSE.txt
6
6
  *-----------------------------------------------------------*/
@@ -1,6 +1,6 @@
1
1
  /*!-----------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Version: 0.53.0(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
3
+ * Version: 0.54.0-dev-20250909(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
4
4
  * Released under the MIT license
5
5
  * https://github.com/microsoft/vscode/blob/main/LICENSE.txt
6
6
  *-----------------------------------------------------------*/
@@ -1,6 +1,6 @@
1
1
  /*!-----------------------------------------------------------
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Version: 0.53.0(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
3
+ * Version: 0.54.0-dev-20250909(4e45ba0c5ff45fc61c0ccac61c0987369df04a6e)
4
4
  * Released under the MIT license
5
5
  * https://github.com/microsoft/vscode/blob/main/LICENSE.txt
6
6
  *-----------------------------------------------------------*/
@@ -4,6 +4,7 @@
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import { DisposableStore, toDisposable } from '../common/lifecycle.js';
6
6
  import { Schemas } from '../common/network.js';
7
+ import { reset } from './dom.js';
7
8
  import dompurify from './dompurify/dompurify.js';
8
9
  /**
9
10
  * List of safe, non-input html tags.
@@ -138,9 +139,6 @@ function hookDomPurifyHrefAndSrcSanitizer(allowedLinkProtocols, allowedMediaProt
138
139
  const defaultDomPurifyConfig = Object.freeze({
139
140
  ALLOWED_TAGS: [...basicMarkupHtmlTags],
140
141
  ALLOWED_ATTR: [...defaultAllowedAttrs],
141
- RETURN_DOM: false,
142
- RETURN_DOM_FRAGMENT: false,
143
- RETURN_TRUSTED_TYPE: true,
144
142
  // We sanitize the src/href attributes later if needed
145
143
  ALLOW_UNKNOWN_PROTOCOLS: true,
146
144
  });
@@ -153,6 +151,9 @@ const defaultDomPurifyConfig = Object.freeze({
153
151
  * @returns A sanitized string of html.
154
152
  */
155
153
  export function sanitizeHtml(untrusted, config) {
154
+ return doSanitizeHtml(untrusted, config, 'trusted');
155
+ }
156
+ function doSanitizeHtml(untrusted, config, outputType) {
156
157
  const store = new DisposableStore();
157
158
  try {
158
159
  const resolvedConfig = { ...defaultDomPurifyConfig };
@@ -217,10 +218,18 @@ export function sanitizeHtml(untrusted, config) {
217
218
  }
218
219
  }));
219
220
  }
220
- return dompurify.sanitize(untrusted, {
221
- ...resolvedConfig,
222
- RETURN_TRUSTED_TYPE: true
223
- });
221
+ if (outputType === 'dom') {
222
+ return dompurify.sanitize(untrusted, {
223
+ ...resolvedConfig,
224
+ RETURN_DOM_FRAGMENT: true
225
+ });
226
+ }
227
+ else {
228
+ return dompurify.sanitize(untrusted, {
229
+ ...resolvedConfig,
230
+ RETURN_TRUSTED_TYPE: true
231
+ });
232
+ }
224
233
  }
225
234
  finally {
226
235
  store.dispose();
@@ -276,6 +285,7 @@ export function convertTagToPlaintext(element) {
276
285
  * Sanitizes the given `value` and reset the given `node` with it.
277
286
  */
278
287
  export function safeSetInnerHtml(node, untrusted, config) {
279
- node.innerHTML = sanitizeHtml(untrusted, config);
288
+ const fragment = doSanitizeHtml(untrusted, config, 'dom');
289
+ reset(node, fragment);
280
290
  }
281
291
  //# sourceMappingURL=domSanitize.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["file:///mnt/vss/_work/1/s/dependencies/vscode/out-editor-src/vs/base/browser/domSanitize.ts","vs/base/browser/domSanitize.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,eAAe,EAAe,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,SAAS,MAAM,0BAA0B,CAAC;AAGjD;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC;IAChD,GAAG;IACH,MAAM;IACN,GAAG;IACH,KAAK;IACL,YAAY;IACZ,IAAI;IACJ,SAAS;IACT,MAAM;IACN,MAAM;IACN,KAAK;IACL,UAAU;IACV,IAAI;IACJ,KAAK;IACL,SAAS;IACT,KAAK;IACL,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,YAAY;IACZ,QAAQ;IACR,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,GAAG;IACH,KAAK;IACL,KAAK;IACL,KAAK;IACL,OAAO;IACP,IAAI;IACJ,MAAM;IACN,IAAI;IACJ,GAAG;IACH,KAAK;IACL,GAAG;IACH,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,QAAQ;IACR,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,KAAK;IACL,SAAS;IACT,KAAK;IACL,OAAO;IACP,OAAO;IACP,IAAI;I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,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,cAAc,GAAG,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACjG,IAAI,cAAc,EAAE,CAAC;QACpB,QAAQ,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAiB,EAAE,SAAiB,EAAE,MAA2B;IACjG,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC,SAAS,EAAE,MAAM,CAAQ,CAAC;AACzD,CAAC","file":"domSanitize.js","sourceRoot":"file:///mnt/vss/_work/1/s/dependencies/vscode/out-editor-src","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { DisposableStore, IDisposable, toDisposable } from '../common/lifecycle.js';\nimport { Schemas } from '../common/network.js';\nimport dompurify from './dompurify/dompurify.js';\n\n\n/**\n * List of safe, non-input html tags.\n */\nexport const basicMarkupHtmlTags = Object.freeze([\n\t'a',\n\t'abbr',\n\t'b',\n\t'bdo',\n\t'blockquote',\n\t'br',\n\t'caption',\n\t'cite',\n\t'code',\n\t'col',\n\t'colgroup',\n\t'dd',\n\t'del',\n\t'details',\n\t'dfn',\n\t'div',\n\t'dl',\n\t'dt',\n\t'em',\n\t'figcaption',\n\t'figure',\n\t'h1',\n\t'h2',\n\t'h3',\n\t'h4',\n\t'h5',\n\t'h6',\n\t'hr',\n\t'i',\n\t'img',\n\t'ins',\n\t'kbd',\n\t'label',\n\t'li',\n\t'mark',\n\t'ol',\n\t'p',\n\t'pre',\n\t'q',\n\t'rp',\n\t'rt',\n\t'ruby',\n\t'samp',\n\t'small',\n\t'small',\n\t'source',\n\t'span',\n\t'strike',\n\t'strong',\n\t'sub',\n\t'summary',\n\t'sup',\n\t'table',\n\t'tbody',\n\t'td',\n\t'tfoot',\n\t'th',\n\t'thead',\n\t'time',\n\t'tr',\n\t'tt',\n\t'u',\n\t'ul',\n\t'var',\n\t'video',\n\t'wbr',\n]);\n\nexport const defaultAllowedAttrs = Object.freeze([\n\t'href',\n\t'target',\n\t'src',\n\t'alt',\n\t'title',\n\t'for',\n\t'name',\n\t'role',\n\t'tabindex',\n\t'x-dispatch',\n\t'required',\n\t'checked',\n\t'placeholder',\n\t'type',\n\t'start',\n\t'width',\n\t'height',\n\t'align',\n]);\n\n\ntype UponSanitizeElementCb = (currentNode: Element, data: dompurify.SanitizeElementHookEvent, config: dompurify.Config) => void;\ntype UponSanitizeAttributeCb = (currentNode: Element, data: dompurify.SanitizeAttributeHookEvent, config: dompurify.Config) => void;\n\nfunction addDompurifyHook(hook: 'uponSanitizeElement', cb: UponSanitizeElementCb): IDisposable;\nfunction addDompurifyHook(hook: 'uponSanitizeAttribute', cb: UponSanitizeAttributeCb): IDisposable;\nfunction addDompurifyHook(hook: 'uponSanitizeElement' | 'uponSanitizeAttribute', cb: any): IDisposable {\n\tdompurify.addHook(hook, cb);\n\treturn toDisposable(() => dompurify.removeHook(hook));\n}\n\n/**\n * Hooks dompurify using `afterSanitizeAttributes` to check that all `href` and `src`\n * attributes are valid.\n */\nfunction hookDomPurifyHrefAndSrcSanitizer(allowedLinkProtocols: readonly string[] | '*', allowedMediaProtocols: readonly string[]): IDisposable {\n\t// https://github.com/cure53/DOMPurify/blob/main/demos/hooks-scheme-allowlist.html\n\t// build an anchor to map URLs to\n\tconst anchor = document.createElement('a');\n\n\tfunction validateLink(value: string, allowedProtocols: readonly string[] | '*'): boolean {\n\t\tif (allowedProtocols === '*') {\n\t\t\treturn true; // allow all protocols\n\t\t}\n\n\t\tanchor.href = value;\n\t\treturn allowedProtocols.includes(anchor.protocol.replace(/:$/, ''));\n\t}\n\n\tdompurify.addHook('afterSanitizeAttributes', (node) => {\n\t\t// check all href/src attributes for validity\n\t\tfor (const attr of ['href', 'src']) {\n\t\t\tif (node.hasAttribute(attr)) {\n\t\t\t\tconst attrValue = node.getAttribute(attr) as string;\n\t\t\t\tif (attr === 'href') {\n\n\t\t\t\t\tif (!attrValue.startsWith('#') && !validateLink(attrValue, allowedLinkProtocols)) {\n\t\t\t\t\t\tnode.removeAttribute(attr);\n\t\t\t\t\t}\n\n\t\t\t\t} else {// 'src'\n\t\t\t\t\tif (!validateLink(attrValue, allowedMediaProtocols)) {\n\t\t\t\t\t\tnode.removeAttribute(attr);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n\n\treturn toDisposable(() => dompurify.removeHook('afterSanitizeAttributes'));\n}\n\n/**\n * Predicate that checks if an attribute should be kept or removed.\n *\n * @returns A boolean indicating whether the attribute should be kept or a string with the sanitized value (which implicitly keeps the attribute)\n */\nexport type SanitizeAttributePredicate = (node: Element, data: { readonly attrName: string; readonly attrValue: string }) => boolean | string;\n\nexport interface SanitizeAttributeRule {\n\treadonly attributeName: string;\n\tshouldKeep: SanitizeAttributePredicate;\n}\n\nexport interface DomSanitizerConfig {\n\t/**\n\t * Configured the allowed html tags.\n\t */\n\treadonly allowedTags?: {\n\t\treadonly override?: readonly string[];\n\t\treadonly augment?: readonly string[];\n\t};\n\n\t/**\n\t * Configured the allowed html attributes.\n\t */\n\treadonly allowedAttributes?: {\n\t\treadonly override?: ReadonlyArray<string | SanitizeAttributeRule>;\n\t\treadonly augment?: ReadonlyArray<string | SanitizeAttributeRule>;\n\t};\n\n\t/**\n\t * List of allowed protocols for `href` attributes.\n\t */\n\treadonly allowedLinkProtocols?: {\n\t\treadonly override?: readonly string[] | '*';\n\t};\n\n\t/**\n\t * List of allowed protocols for `src` attributes.\n\t */\n\treadonly allowedMediaProtocols?: {\n\t\treadonly override?: readonly string[];\n\t};\n\n\t/**\n\t * If set, replaces unsupported tags with their plaintext representation instead of removing them.\n\t *\n\t * For example, <p><bad>\"text\"</bad></p> becomes <p>\"<bad>text</bad>\"</p>.\n\t */\n\treadonly replaceWithPlaintext?: boolean;\n}\n\nconst defaultDomPurifyConfig = Object.freeze({\n\tALLOWED_TAGS: [...basicMarkupHtmlTags],\n\tALLOWED_ATTR: [...defaultAllowedAttrs],\n\tRETURN_DOM: false,\n\tRETURN_DOM_FRAGMENT: false,\n\tRETURN_TRUSTED_TYPE: true,\n\t// We sanitize the src/href attributes later if needed\n\tALLOW_UNKNOWN_PROTOCOLS: true,\n} satisfies dompurify.Config);\n\n/**\n * Sanitizes an html string.\n *\n * @param untrusted The HTML string to sanitize.\n * @param config Optional configuration for sanitization. If not provided, defaults to a safe configuration.\n *\n * @returns A sanitized string of html.\n */\nexport function sanitizeHtml(untrusted: string, config?: DomSanitizerConfig): TrustedHTML {\n\tconst store = new DisposableStore();\n\ttry {\n\t\tconst resolvedConfig: dompurify.Config = { ...defaultDomPurifyConfig };\n\n\t\tif (config?.allowedTags) {\n\t\t\tif (config.allowedTags.override) {\n\t\t\t\tresolvedConfig.ALLOWED_TAGS = [...config.allowedTags.override];\n\t\t\t}\n\n\t\t\tif (config.allowedTags.augment) {\n\t\t\t\tresolvedConfig.ALLOWED_TAGS = [...(resolvedConfig.ALLOWED_TAGS ?? []), ...config.allowedTags.augment];\n\t\t\t}\n\t\t}\n\n\t\tlet resolvedAttributes: Array<string | SanitizeAttributeRule> = [...defaultAllowedAttrs];\n\t\tif (config?.allowedAttributes) {\n\t\t\tif (config.allowedAttributes.override) {\n\t\t\t\tresolvedAttributes = [...config.allowedAttributes.override];\n\t\t\t}\n\n\t\t\tif (config.allowedAttributes.augment) {\n\t\t\t\tresolvedAttributes = [...resolvedAttributes, ...config.allowedAttributes.augment];\n\t\t\t}\n\t\t}\n\n\t\t// All attr names are lower-case in the sanitizer hooks\n\t\tresolvedAttributes = resolvedAttributes.map((attr): string | SanitizeAttributeRule => {\n\t\t\tif (typeof attr === 'string') {\n\t\t\t\treturn attr.toLowerCase();\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tattributeName: attr.attributeName.toLowerCase(),\n\t\t\t\tshouldKeep: attr.shouldKeep,\n\t\t\t};\n\t\t});\n\n\t\tconst allowedAttrNames = new Set(resolvedAttributes.map(attr => typeof attr === 'string' ? attr : attr.attributeName));\n\t\tconst allowedAttrPredicates = new Map<string, SanitizeAttributeRule>();\n\t\tfor (const attr of resolvedAttributes) {\n\t\t\tif (typeof attr === 'string') {\n\t\t\t\t// New string attribute value clears previously set predicates\n\t\t\t\tallowedAttrPredicates.delete(attr);\n\t\t\t} else {\n\t\t\t\tallowedAttrPredicates.set(attr.attributeName, attr);\n\t\t\t}\n\t\t}\n\n\t\tresolvedConfig.ALLOWED_ATTR = Array.from(allowedAttrNames);\n\n\t\tstore.add(hookDomPurifyHrefAndSrcSanitizer(\n\t\t\tconfig?.allowedLinkProtocols?.override ?? [Schemas.http, Schemas.https],\n\t\t\tconfig?.allowedMediaProtocols?.override ?? [Schemas.http, Schemas.https]));\n\n\t\tif (config?.replaceWithPlaintext) {\n\t\t\tstore.add(addDompurifyHook('uponSanitizeElement', replaceWithPlainTextHook));\n\t\t}\n\n\t\tif (allowedAttrPredicates.size) {\n\t\t\tstore.add(addDompurifyHook('uponSanitizeAttribute', (node, e) => {\n\t\t\t\tconst predicate = allowedAttrPredicates.get(e.attrName);\n\t\t\t\tif (predicate) {\n\t\t\t\t\tconst result = predicate.shouldKeep(node, e);\n\t\t\t\t\tif (typeof result === 'string') {\n\t\t\t\t\t\te.keepAttr = true;\n\t\t\t\t\t\te.attrValue = result;\n\t\t\t\t\t} else {\n\t\t\t\t\t\te.keepAttr = result;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\te.keepAttr = allowedAttrNames.has(e.attrName);\n\t\t\t\t}\n\t\t\t}));\n\t\t}\n\n\t\treturn dompurify.sanitize(untrusted, {\n\t\t\t...resolvedConfig,\n\t\t\tRETURN_TRUSTED_TYPE: true\n\t\t});\n\t} finally {\n\t\tstore.dispose();\n\t}\n}\n\nconst selfClosingTags = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];\n\nfunction replaceWithPlainTextHook(element: Element, data: dompurify.SanitizeElementHookEvent, _config: dompurify.Config) {\n\tif (!data.allowedTags[data.tagName] && data.tagName !== 'body') {\n\t\tconst replacement = convertTagToPlaintext(element);\n\t\tif (element.nodeType === Node.COMMENT_NODE) {\n\t\t\t// Workaround for https://github.com/cure53/DOMPurify/issues/1005\n\t\t\t// The comment will be deleted in the next phase. However if we try to remove it now, it will cause\n\t\t\t// an exception. Instead we insert the text node before the comment.\n\t\t\telement.parentElement?.insertBefore(replacement, element);\n\t\t} else {\n\t\t\telement.parentElement?.replaceChild(replacement, element);\n\t\t}\n\t}\n}\n\nexport function convertTagToPlaintext(element: Element): DocumentFragment {\n\tlet startTagText: string;\n\tlet endTagText: string | undefined;\n\tif (element.nodeType === Node.COMMENT_NODE) {\n\t\tstartTagText = `<!--${element.textContent}-->`;\n\t} else {\n\t\tconst tagName = element.tagName.toLowerCase();\n\t\tconst isSelfClosing = selfClosingTags.includes(tagName);\n\t\tconst attrString = element.attributes.length ?\n\t\t\t' ' + Array.from(element.attributes)\n\t\t\t\t.map(attr => `${attr.name}=\"${attr.value}\"`)\n\t\t\t\t.join(' ')\n\t\t\t: '';\n\t\tstartTagText = `<${tagName}${attrString}>`;\n\t\tif (!isSelfClosing) {\n\t\t\tendTagText = `</${tagName}>`;\n\t\t}\n\t}\n\n\tconst fragment = document.createDocumentFragment();\n\tconst textNode = element.ownerDocument.createTextNode(startTagText);\n\tfragment.appendChild(textNode);\n\twhile (element.firstChild) {\n\t\tfragment.appendChild(element.firstChild);\n\t}\n\n\tconst endTagTextNode = endTagText ? element.ownerDocument.createTextNode(endTagText) : undefined;\n\tif (endTagTextNode) {\n\t\tfragment.appendChild(endTagTextNode);\n\t}\n\n\treturn fragment;\n}\n\n/**\n * Sanitizes the given `value` and reset the given `node` with it.\n */\nexport function safeSetInnerHtml(node: HTMLElement, untrusted: string, config?: DomSanitizerConfig): void {\n\tnode.innerHTML = sanitizeHtml(untrusted, config) as any;\n}\n","/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { DisposableStore, IDisposable, toDisposable } from '../common/lifecycle.js';\nimport { Schemas } from '../common/network.js';\nimport dompurify from './dompurify/dompurify.js';\n\n\n/**\n * List of safe, non-input html tags.\n */\nexport const basicMarkupHtmlTags = Object.freeze([\n\t'a',\n\t'abbr',\n\t'b',\n\t'bdo',\n\t'blockquote',\n\t'br',\n\t'caption',\n\t'cite',\n\t'code',\n\t'col',\n\t'colgroup',\n\t'dd',\n\t'del',\n\t'details',\n\t'dfn',\n\t'div',\n\t'dl',\n\t'dt',\n\t'em',\n\t'figcaption',\n\t'figure',\n\t'h1',\n\t'h2',\n\t'h3',\n\t'h4',\n\t'h5',\n\t'h6',\n\t'hr',\n\t'i',\n\t'img',\n\t'ins',\n\t'kbd',\n\t'label',\n\t'li',\n\t'mark',\n\t'ol',\n\t'p',\n\t'pre',\n\t'q',\n\t'rp',\n\t'rt',\n\t'ruby',\n\t'samp',\n\t'small',\n\t'small',\n\t'source',\n\t'span',\n\t'strike',\n\t'strong',\n\t'sub',\n\t'summary',\n\t'sup',\n\t'table',\n\t'tbody',\n\t'td',\n\t'tfoot',\n\t'th',\n\t'thead',\n\t'time',\n\t'tr',\n\t'tt',\n\t'u',\n\t'ul',\n\t'var',\n\t'video',\n\t'wbr',\n]);\n\nexport const defaultAllowedAttrs = Object.freeze([\n\t'href',\n\t'target',\n\t'src',\n\t'alt',\n\t'title',\n\t'for',\n\t'name',\n\t'role',\n\t'tabindex',\n\t'x-dispatch',\n\t'required',\n\t'checked',\n\t'placeholder',\n\t'type',\n\t'start',\n\t'width',\n\t'height',\n\t'align',\n]);\n\n\ntype UponSanitizeElementCb = (currentNode: Element, data: dompurify.SanitizeElementHookEvent, config: dompurify.Config) => void;\ntype UponSanitizeAttributeCb = (currentNode: Element, data: dompurify.SanitizeAttributeHookEvent, config: dompurify.Config) => void;\n\nfunction addDompurifyHook(hook: 'uponSanitizeElement', cb: UponSanitizeElementCb): IDisposable;\nfunction addDompurifyHook(hook: 'uponSanitizeAttribute', cb: UponSanitizeAttributeCb): IDisposable;\nfunction addDompurifyHook(hook: 'uponSanitizeElement' | 'uponSanitizeAttribute', cb: any): IDisposable {\n\tdompurify.addHook(hook, cb);\n\treturn toDisposable(() => dompurify.removeHook(hook));\n}\n\n/**\n * Hooks dompurify using `afterSanitizeAttributes` to check that all `href` and `src`\n * attributes are valid.\n */\nfunction hookDomPurifyHrefAndSrcSanitizer(allowedLinkProtocols: readonly string[] | '*', allowedMediaProtocols: readonly string[]): IDisposable {\n\t// https://github.com/cure53/DOMPurify/blob/main/demos/hooks-scheme-allowlist.html\n\t// build an anchor to map URLs to\n\tconst anchor = document.createElement('a');\n\n\tfunction validateLink(value: string, allowedProtocols: readonly string[] | '*'): boolean {\n\t\tif (allowedProtocols === '*') {\n\t\t\treturn true; // allow all protocols\n\t\t}\n\n\t\tanchor.href = value;\n\t\treturn allowedProtocols.includes(anchor.protocol.replace(/:$/, ''));\n\t}\n\n\tdompurify.addHook('afterSanitizeAttributes', (node) => {\n\t\t// check all href/src attributes for validity\n\t\tfor (const attr of ['href', 'src']) {\n\t\t\tif (node.hasAttribute(attr)) {\n\t\t\t\tconst attrValue = node.getAttribute(attr) as string;\n\t\t\t\tif (attr === 'href') {\n\n\t\t\t\t\tif (!attrValue.startsWith('#') && !validateLink(attrValue, allowedLinkProtocols)) {\n\t\t\t\t\t\tnode.removeAttribute(attr);\n\t\t\t\t\t}\n\n\t\t\t\t} else {// 'src'\n\t\t\t\t\tif (!validateLink(attrValue, allowedMediaProtocols)) {\n\t\t\t\t\t\tnode.removeAttribute(attr);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n\n\treturn toDisposable(() => dompurify.removeHook('afterSanitizeAttributes'));\n}\n\n/**\n * Predicate that checks if an attribute should be kept or removed.\n *\n * @returns A boolean indicating whether the attribute should be kept or a string with the sanitized value (which implicitly keeps the attribute)\n */\nexport type SanitizeAttributePredicate = (node: Element, data: { readonly attrName: string; readonly attrValue: string }) => boolean | string;\n\nexport interface SanitizeAttributeRule {\n\treadonly attributeName: string;\n\tshouldKeep: SanitizeAttributePredicate;\n}\n\nexport interface DomSanitizerConfig {\n\t/**\n\t * Configured the allowed html tags.\n\t */\n\treadonly allowedTags?: {\n\t\treadonly override?: readonly string[];\n\t\treadonly augment?: readonly string[];\n\t};\n\n\t/**\n\t * Configured the allowed html attributes.\n\t */\n\treadonly allowedAttributes?: {\n\t\treadonly override?: ReadonlyArray<string | SanitizeAttributeRule>;\n\t\treadonly augment?: ReadonlyArray<string | SanitizeAttributeRule>;\n\t};\n\n\t/**\n\t * List of allowed protocols for `href` attributes.\n\t */\n\treadonly allowedLinkProtocols?: {\n\t\treadonly override?: readonly string[] | '*';\n\t};\n\n\t/**\n\t * List of allowed protocols for `src` attributes.\n\t */\n\treadonly allowedMediaProtocols?: {\n\t\treadonly override?: readonly string[];\n\t};\n\n\t/**\n\t * If set, replaces unsupported tags with their plaintext representation instead of removing them.\n\t *\n\t * For example, <p><bad>\"text\"</bad></p> becomes <p>\"<bad>text</bad>\"</p>.\n\t */\n\treadonly replaceWithPlaintext?: boolean;\n}\n\nconst defaultDomPurifyConfig = Object.freeze({\n\tALLOWED_TAGS: [...basicMarkupHtmlTags],\n\tALLOWED_ATTR: [...defaultAllowedAttrs],\n\tRETURN_DOM: false,\n\tRETURN_DOM_FRAGMENT: false,\n\tRETURN_TRUSTED_TYPE: true,\n\t// We sanitize the src/href attributes later if needed\n\tALLOW_UNKNOWN_PROTOCOLS: true,\n} satisfies dompurify.Config);\n\n/**\n * Sanitizes an html string.\n *\n * @param untrusted The HTML string to sanitize.\n * @param config Optional configuration for sanitization. If not provided, defaults to a safe configuration.\n *\n * @returns A sanitized string of html.\n */\nexport function sanitizeHtml(untrusted: string, config?: DomSanitizerConfig): TrustedHTML {\n\tconst store = new DisposableStore();\n\ttry {\n\t\tconst resolvedConfig: dompurify.Config = { ...defaultDomPurifyConfig };\n\n\t\tif (config?.allowedTags) {\n\t\t\tif (config.allowedTags.override) {\n\t\t\t\tresolvedConfig.ALLOWED_TAGS = [...config.allowedTags.override];\n\t\t\t}\n\n\t\t\tif (config.allowedTags.augment) {\n\t\t\t\tresolvedConfig.ALLOWED_TAGS = [...(resolvedConfig.ALLOWED_TAGS ?? []), ...config.allowedTags.augment];\n\t\t\t}\n\t\t}\n\n\t\tlet resolvedAttributes: Array<string | SanitizeAttributeRule> = [...defaultAllowedAttrs];\n\t\tif (config?.allowedAttributes) {\n\t\t\tif (config.allowedAttributes.override) {\n\t\t\t\tresolvedAttributes = [...config.allowedAttributes.override];\n\t\t\t}\n\n\t\t\tif (config.allowedAttributes.augment) {\n\t\t\t\tresolvedAttributes = [...resolvedAttributes, ...config.allowedAttributes.augment];\n\t\t\t}\n\t\t}\n\n\t\t// All attr names are lower-case in the sanitizer hooks\n\t\tresolvedAttributes = resolvedAttributes.map((attr): string | SanitizeAttributeRule => {\n\t\t\tif (typeof attr === 'string') {\n\t\t\t\treturn attr.toLowerCase();\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tattributeName: attr.attributeName.toLowerCase(),\n\t\t\t\tshouldKeep: attr.shouldKeep,\n\t\t\t};\n\t\t});\n\n\t\tconst allowedAttrNames = new Set(resolvedAttributes.map(attr => typeof attr === 'string' ? attr : attr.attributeName));\n\t\tconst allowedAttrPredicates = new Map<string, SanitizeAttributeRule>();\n\t\tfor (const attr of resolvedAttributes) {\n\t\t\tif (typeof attr === 'string') {\n\t\t\t\t// New string attribute value clears previously set predicates\n\t\t\t\tallowedAttrPredicates.delete(attr);\n\t\t\t} else {\n\t\t\t\tallowedAttrPredicates.set(attr.attributeName, attr);\n\t\t\t}\n\t\t}\n\n\t\tresolvedConfig.ALLOWED_ATTR = Array.from(allowedAttrNames);\n\n\t\tstore.add(hookDomPurifyHrefAndSrcSanitizer(\n\t\t\tconfig?.allowedLinkProtocols?.override ?? [Schemas.http, Schemas.https],\n\t\t\tconfig?.allowedMediaProtocols?.override ?? [Schemas.http, Schemas.https]));\n\n\t\tif (config?.replaceWithPlaintext) {\n\t\t\tstore.add(addDompurifyHook('uponSanitizeElement', replaceWithPlainTextHook));\n\t\t}\n\n\t\tif (allowedAttrPredicates.size) {\n\t\t\tstore.add(addDompurifyHook('uponSanitizeAttribute', (node, e) => {\n\t\t\t\tconst predicate = allowedAttrPredicates.get(e.attrName);\n\t\t\t\tif (predicate) {\n\t\t\t\t\tconst result = predicate.shouldKeep(node, e);\n\t\t\t\t\tif (typeof result === 'string') {\n\t\t\t\t\t\te.keepAttr = true;\n\t\t\t\t\t\te.attrValue = result;\n\t\t\t\t\t} else {\n\t\t\t\t\t\te.keepAttr = result;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\te.keepAttr = allowedAttrNames.has(e.attrName);\n\t\t\t\t}\n\t\t\t}));\n\t\t}\n\n\t\treturn dompurify.sanitize(untrusted, {\n\t\t\t...resolvedConfig,\n\t\t\tRETURN_TRUSTED_TYPE: true\n\t\t});\n\t} finally {\n\t\tstore.dispose();\n\t}\n}\n\nconst selfClosingTags = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];\n\nfunction replaceWithPlainTextHook(element: Element, data: dompurify.SanitizeElementHookEvent, _config: dompurify.Config) {\n\tif (!data.allowedTags[data.tagName] && data.tagName !== 'body') {\n\t\tconst replacement = convertTagToPlaintext(element);\n\t\tif (element.nodeType === Node.COMMENT_NODE) {\n\t\t\t// Workaround for https://github.com/cure53/DOMPurify/issues/1005\n\t\t\t// The comment will be deleted in the next phase. However if we try to remove it now, it will cause\n\t\t\t// an exception. Instead we insert the text node before the comment.\n\t\t\telement.parentElement?.insertBefore(replacement, element);\n\t\t} else {\n\t\t\telement.parentElement?.replaceChild(replacement, element);\n\t\t}\n\t}\n}\n\nexport function convertTagToPlaintext(element: Element): DocumentFragment {\n\tlet startTagText: string;\n\tlet endTagText: string | undefined;\n\tif (element.nodeType === Node.COMMENT_NODE) {\n\t\tstartTagText = `<!--${element.textContent}-->`;\n\t} else {\n\t\tconst tagName = element.tagName.toLowerCase();\n\t\tconst isSelfClosing = selfClosingTags.includes(tagName);\n\t\tconst attrString = element.attributes.length ?\n\t\t\t' ' + Array.from(element.attributes)\n\t\t\t\t.map(attr => `${attr.name}=\"${attr.value}\"`)\n\t\t\t\t.join(' ')\n\t\t\t: '';\n\t\tstartTagText = `<${tagName}${attrString}>`;\n\t\tif (!isSelfClosing) {\n\t\t\tendTagText = `</${tagName}>`;\n\t\t}\n\t}\n\n\tconst fragment = document.createDocumentFragment();\n\tconst textNode = element.ownerDocument.createTextNode(startTagText);\n\tfragment.appendChild(textNode);\n\twhile (element.firstChild) {\n\t\tfragment.appendChild(element.firstChild);\n\t}\n\n\tconst endTagTextNode = endTagText ? element.ownerDocument.createTextNode(endTagText) : undefined;\n\tif (endTagTextNode) {\n\t\tfragment.appendChild(endTagTextNode);\n\t}\n\n\treturn fragment;\n}\n\n/**\n * Sanitizes the given `value` and reset the given `node` with it.\n */\nexport function safeSetInnerHtml(node: HTMLElement, untrusted: string, config?: DomSanitizerConfig): void {\n\tnode.innerHTML = sanitizeHtml(untrusted, config) as any;\n}\n"]}
1
+ {"version":3,"sources":["file:///mnt/vss/_work/1/s/dependencies/vscode/out-editor-src/vs/base/browser/domSanitize.ts","vs/base/browser/domSanitize.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,eAAe,EAAe,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,MAAM,s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c,EAAE,CAAC;QACpB,QAAQ,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAiB,EAAE,SAAiB,EAAE,MAA2B;IACjG,MAAM,QAAQ,GAAG,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC1D,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACvB,CAAC","file":"domSanitize.js","sourceRoot":"file:///mnt/vss/_work/1/s/dependencies/vscode/out-editor-src","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { DisposableStore, IDisposable, toDisposable } from '../common/lifecycle.js';\nimport { Schemas } from '../common/network.js';\nimport { reset } from './dom.js';\nimport dompurify from './dompurify/dompurify.js';\n\n\n/**\n * List of safe, non-input html tags.\n */\nexport const basicMarkupHtmlTags = Object.freeze([\n\t'a',\n\t'abbr',\n\t'b',\n\t'bdo',\n\t'blockquote',\n\t'br',\n\t'caption',\n\t'cite',\n\t'code',\n\t'col',\n\t'colgroup',\n\t'dd',\n\t'del',\n\t'details',\n\t'dfn',\n\t'div',\n\t'dl',\n\t'dt',\n\t'em',\n\t'figcaption',\n\t'figure',\n\t'h1',\n\t'h2',\n\t'h3',\n\t'h4',\n\t'h5',\n\t'h6',\n\t'hr',\n\t'i',\n\t'img',\n\t'ins',\n\t'kbd',\n\t'label',\n\t'li',\n\t'mark',\n\t'ol',\n\t'p',\n\t'pre',\n\t'q',\n\t'rp',\n\t'rt',\n\t'ruby',\n\t'samp',\n\t'small',\n\t'small',\n\t'source',\n\t'span',\n\t'strike',\n\t'strong',\n\t'sub',\n\t'summary',\n\t'sup',\n\t'table',\n\t'tbody',\n\t'td',\n\t'tfoot',\n\t'th',\n\t'thead',\n\t'time',\n\t'tr',\n\t'tt',\n\t'u',\n\t'ul',\n\t'var',\n\t'video',\n\t'wbr',\n]);\n\nexport const defaultAllowedAttrs = Object.freeze([\n\t'href',\n\t'target',\n\t'src',\n\t'alt',\n\t'title',\n\t'for',\n\t'name',\n\t'role',\n\t'tabindex',\n\t'x-dispatch',\n\t'required',\n\t'checked',\n\t'placeholder',\n\t'type',\n\t'start',\n\t'width',\n\t'height',\n\t'align',\n]);\n\n\ntype UponSanitizeElementCb = (currentNode: Element, data: dompurify.SanitizeElementHookEvent, config: dompurify.Config) => void;\ntype UponSanitizeAttributeCb = (currentNode: Element, data: dompurify.SanitizeAttributeHookEvent, config: dompurify.Config) => void;\n\nfunction addDompurifyHook(hook: 'uponSanitizeElement', cb: UponSanitizeElementCb): IDisposable;\nfunction addDompurifyHook(hook: 'uponSanitizeAttribute', cb: UponSanitizeAttributeCb): IDisposable;\nfunction addDompurifyHook(hook: 'uponSanitizeElement' | 'uponSanitizeAttribute', cb: any): IDisposable {\n\tdompurify.addHook(hook, cb);\n\treturn toDisposable(() => dompurify.removeHook(hook));\n}\n\n/**\n * Hooks dompurify using `afterSanitizeAttributes` to check that all `href` and `src`\n * attributes are valid.\n */\nfunction hookDomPurifyHrefAndSrcSanitizer(allowedLinkProtocols: readonly string[] | '*', allowedMediaProtocols: readonly string[]): IDisposable {\n\t// https://github.com/cure53/DOMPurify/blob/main/demos/hooks-scheme-allowlist.html\n\t// build an anchor to map URLs to\n\tconst anchor = document.createElement('a');\n\n\tfunction validateLink(value: string, allowedProtocols: readonly string[] | '*'): boolean {\n\t\tif (allowedProtocols === '*') {\n\t\t\treturn true; // allow all protocols\n\t\t}\n\n\t\tanchor.href = value;\n\t\treturn allowedProtocols.includes(anchor.protocol.replace(/:$/, ''));\n\t}\n\n\tdompurify.addHook('afterSanitizeAttributes', (node) => {\n\t\t// check all href/src attributes for validity\n\t\tfor (const attr of ['href', 'src']) {\n\t\t\tif (node.hasAttribute(attr)) {\n\t\t\t\tconst attrValue = node.getAttribute(attr) as string;\n\t\t\t\tif (attr === 'href') {\n\n\t\t\t\t\tif (!attrValue.startsWith('#') && !validateLink(attrValue, allowedLinkProtocols)) {\n\t\t\t\t\t\tnode.removeAttribute(attr);\n\t\t\t\t\t}\n\n\t\t\t\t} else {// 'src'\n\t\t\t\t\tif (!validateLink(attrValue, allowedMediaProtocols)) {\n\t\t\t\t\t\tnode.removeAttribute(attr);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n\n\treturn toDisposable(() => dompurify.removeHook('afterSanitizeAttributes'));\n}\n\n/**\n * Predicate that checks if an attribute should be kept or removed.\n *\n * @returns A boolean indicating whether the attribute should be kept or a string with the sanitized value (which implicitly keeps the attribute)\n */\nexport type SanitizeAttributePredicate = (node: Element, data: { readonly attrName: string; readonly attrValue: string }) => boolean | string;\n\nexport interface SanitizeAttributeRule {\n\treadonly attributeName: string;\n\tshouldKeep: SanitizeAttributePredicate;\n}\n\nexport interface DomSanitizerConfig {\n\t/**\n\t * Configured the allowed html tags.\n\t */\n\treadonly allowedTags?: {\n\t\treadonly override?: readonly string[];\n\t\treadonly augment?: readonly string[];\n\t};\n\n\t/**\n\t * Configured the allowed html attributes.\n\t */\n\treadonly allowedAttributes?: {\n\t\treadonly override?: ReadonlyArray<string | SanitizeAttributeRule>;\n\t\treadonly augment?: ReadonlyArray<string | SanitizeAttributeRule>;\n\t};\n\n\t/**\n\t * List of allowed protocols for `href` attributes.\n\t */\n\treadonly allowedLinkProtocols?: {\n\t\treadonly override?: readonly string[] | '*';\n\t};\n\n\t/**\n\t * List of allowed protocols for `src` attributes.\n\t */\n\treadonly allowedMediaProtocols?: {\n\t\treadonly override?: readonly string[];\n\t};\n\n\t/**\n\t * If set, replaces unsupported tags with their plaintext representation instead of removing them.\n\t *\n\t * For example, <p><bad>\"text\"</bad></p> becomes <p>\"<bad>text</bad>\"</p>.\n\t */\n\treadonly replaceWithPlaintext?: boolean;\n}\n\nconst defaultDomPurifyConfig = Object.freeze({\n\tALLOWED_TAGS: [...basicMarkupHtmlTags],\n\tALLOWED_ATTR: [...defaultAllowedAttrs],\n\t// We sanitize the src/href attributes later if needed\n\tALLOW_UNKNOWN_PROTOCOLS: true,\n} satisfies dompurify.Config);\n\n/**\n * Sanitizes an html string.\n *\n * @param untrusted The HTML string to sanitize.\n * @param config Optional configuration for sanitization. If not provided, defaults to a safe configuration.\n *\n * @returns A sanitized string of html.\n */\nexport function sanitizeHtml(untrusted: string, config?: DomSanitizerConfig): TrustedHTML {\n\treturn doSanitizeHtml(untrusted, config, 'trusted');\n}\n\nfunction doSanitizeHtml(untrusted: string, config: DomSanitizerConfig | undefined, outputType: 'dom'): DocumentFragment;\nfunction doSanitizeHtml(untrusted: string, config: DomSanitizerConfig | undefined, outputType: 'trusted'): TrustedHTML;\nfunction doSanitizeHtml(untrusted: string, config: DomSanitizerConfig | undefined, outputType: 'dom' | 'trusted'): TrustedHTML | DocumentFragment {\n\tconst store = new DisposableStore();\n\ttry {\n\t\tconst resolvedConfig: dompurify.Config = { ...defaultDomPurifyConfig };\n\n\t\tif (config?.allowedTags) {\n\t\t\tif (config.allowedTags.override) {\n\t\t\t\tresolvedConfig.ALLOWED_TAGS = [...config.allowedTags.override];\n\t\t\t}\n\n\t\t\tif (config.allowedTags.augment) {\n\t\t\t\tresolvedConfig.ALLOWED_TAGS = [...(resolvedConfig.ALLOWED_TAGS ?? []), ...config.allowedTags.augment];\n\t\t\t}\n\t\t}\n\n\t\tlet resolvedAttributes: Array<string | SanitizeAttributeRule> = [...defaultAllowedAttrs];\n\t\tif (config?.allowedAttributes) {\n\t\t\tif (config.allowedAttributes.override) {\n\t\t\t\tresolvedAttributes = [...config.allowedAttributes.override];\n\t\t\t}\n\n\t\t\tif (config.allowedAttributes.augment) {\n\t\t\t\tresolvedAttributes = [...resolvedAttributes, ...config.allowedAttributes.augment];\n\t\t\t}\n\t\t}\n\n\t\t// All attr names are lower-case in the sanitizer hooks\n\t\tresolvedAttributes = resolvedAttributes.map((attr): string | SanitizeAttributeRule => {\n\t\t\tif (typeof attr === 'string') {\n\t\t\t\treturn attr.toLowerCase();\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tattributeName: attr.attributeName.toLowerCase(),\n\t\t\t\tshouldKeep: attr.shouldKeep,\n\t\t\t};\n\t\t});\n\n\t\tconst allowedAttrNames = new Set(resolvedAttributes.map(attr => typeof attr === 'string' ? attr : attr.attributeName));\n\t\tconst allowedAttrPredicates = new Map<string, SanitizeAttributeRule>();\n\t\tfor (const attr of resolvedAttributes) {\n\t\t\tif (typeof attr === 'string') {\n\t\t\t\t// New string attribute value clears previously set predicates\n\t\t\t\tallowedAttrPredicates.delete(attr);\n\t\t\t} else {\n\t\t\t\tallowedAttrPredicates.set(attr.attributeName, attr);\n\t\t\t}\n\t\t}\n\n\t\tresolvedConfig.ALLOWED_ATTR = Array.from(allowedAttrNames);\n\n\t\tstore.add(hookDomPurifyHrefAndSrcSanitizer(\n\t\t\tconfig?.allowedLinkProtocols?.override ?? [Schemas.http, Schemas.https],\n\t\t\tconfig?.allowedMediaProtocols?.override ?? [Schemas.http, Schemas.https]));\n\n\t\tif (config?.replaceWithPlaintext) {\n\t\t\tstore.add(addDompurifyHook('uponSanitizeElement', replaceWithPlainTextHook));\n\t\t}\n\n\t\tif (allowedAttrPredicates.size) {\n\t\t\tstore.add(addDompurifyHook('uponSanitizeAttribute', (node, e) => {\n\t\t\t\tconst predicate = allowedAttrPredicates.get(e.attrName);\n\t\t\t\tif (predicate) {\n\t\t\t\t\tconst result = predicate.shouldKeep(node, e);\n\t\t\t\t\tif (typeof result === 'string') {\n\t\t\t\t\t\te.keepAttr = true;\n\t\t\t\t\t\te.attrValue = result;\n\t\t\t\t\t} else {\n\t\t\t\t\t\te.keepAttr = result;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\te.keepAttr = allowedAttrNames.has(e.attrName);\n\t\t\t\t}\n\t\t\t}));\n\t\t}\n\n\t\tif (outputType === 'dom') {\n\t\t\treturn dompurify.sanitize(untrusted, {\n\t\t\t\t...resolvedConfig,\n\t\t\t\tRETURN_DOM_FRAGMENT: true\n\t\t\t});\n\t\t} else {\n\t\t\treturn dompurify.sanitize(untrusted, {\n\t\t\t\t...resolvedConfig,\n\t\t\t\tRETURN_TRUSTED_TYPE: true\n\t\t\t});\n\t\t}\n\t} finally {\n\t\tstore.dispose();\n\t}\n}\n\nconst selfClosingTags = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];\n\nfunction replaceWithPlainTextHook(element: Element, data: dompurify.SanitizeElementHookEvent, _config: dompurify.Config) {\n\tif (!data.allowedTags[data.tagName] && data.tagName !== 'body') {\n\t\tconst replacement = convertTagToPlaintext(element);\n\t\tif (element.nodeType === Node.COMMENT_NODE) {\n\t\t\t// Workaround for https://github.com/cure53/DOMPurify/issues/1005\n\t\t\t// The comment will be deleted in the next phase. However if we try to remove it now, it will cause\n\t\t\t// an exception. Instead we insert the text node before the comment.\n\t\t\telement.parentElement?.insertBefore(replacement, element);\n\t\t} else {\n\t\t\telement.parentElement?.replaceChild(replacement, element);\n\t\t}\n\t}\n}\n\nexport function convertTagToPlaintext(element: Element): DocumentFragment {\n\tlet startTagText: string;\n\tlet endTagText: string | undefined;\n\tif (element.nodeType === Node.COMMENT_NODE) {\n\t\tstartTagText = `<!--${element.textContent}-->`;\n\t} else {\n\t\tconst tagName = element.tagName.toLowerCase();\n\t\tconst isSelfClosing = selfClosingTags.includes(tagName);\n\t\tconst attrString = element.attributes.length ?\n\t\t\t' ' + Array.from(element.attributes)\n\t\t\t\t.map(attr => `${attr.name}=\"${attr.value}\"`)\n\t\t\t\t.join(' ')\n\t\t\t: '';\n\t\tstartTagText = `<${tagName}${attrString}>`;\n\t\tif (!isSelfClosing) {\n\t\t\tendTagText = `</${tagName}>`;\n\t\t}\n\t}\n\n\tconst fragment = document.createDocumentFragment();\n\tconst textNode = element.ownerDocument.createTextNode(startTagText);\n\tfragment.appendChild(textNode);\n\twhile (element.firstChild) {\n\t\tfragment.appendChild(element.firstChild);\n\t}\n\n\tconst endTagTextNode = endTagText ? element.ownerDocument.createTextNode(endTagText) : undefined;\n\tif (endTagTextNode) {\n\t\tfragment.appendChild(endTagTextNode);\n\t}\n\n\treturn fragment;\n}\n\n/**\n * Sanitizes the given `value` and reset the given `node` with it.\n */\nexport function safeSetInnerHtml(node: HTMLElement, untrusted: string, config?: DomSanitizerConfig): void {\n\tconst fragment = doSanitizeHtml(untrusted, config, 'dom');\n\treset(node, fragment);\n}\n","/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { DisposableStore, IDisposable, toDisposable } from '../common/lifecycle.js';\nimport { Schemas } from '../common/network.js';\nimport { reset } from './dom.js';\nimport dompurify from './dompurify/dompurify.js';\n\n\n/**\n * List of safe, non-input html tags.\n */\nexport const basicMarkupHtmlTags = Object.freeze([\n\t'a',\n\t'abbr',\n\t'b',\n\t'bdo',\n\t'blockquote',\n\t'br',\n\t'caption',\n\t'cite',\n\t'code',\n\t'col',\n\t'colgroup',\n\t'dd',\n\t'del',\n\t'details',\n\t'dfn',\n\t'div',\n\t'dl',\n\t'dt',\n\t'em',\n\t'figcaption',\n\t'figure',\n\t'h1',\n\t'h2',\n\t'h3',\n\t'h4',\n\t'h5',\n\t'h6',\n\t'hr',\n\t'i',\n\t'img',\n\t'ins',\n\t'kbd',\n\t'label',\n\t'li',\n\t'mark',\n\t'ol',\n\t'p',\n\t'pre',\n\t'q',\n\t'rp',\n\t'rt',\n\t'ruby',\n\t'samp',\n\t'small',\n\t'small',\n\t'source',\n\t'span',\n\t'strike',\n\t'strong',\n\t'sub',\n\t'summary',\n\t'sup',\n\t'table',\n\t'tbody',\n\t'td',\n\t'tfoot',\n\t'th',\n\t'thead',\n\t'time',\n\t'tr',\n\t'tt',\n\t'u',\n\t'ul',\n\t'var',\n\t'video',\n\t'wbr',\n]);\n\nexport const defaultAllowedAttrs = Object.freeze([\n\t'href',\n\t'target',\n\t'src',\n\t'alt',\n\t'title',\n\t'for',\n\t'name',\n\t'role',\n\t'tabindex',\n\t'x-dispatch',\n\t'required',\n\t'checked',\n\t'placeholder',\n\t'type',\n\t'start',\n\t'width',\n\t'height',\n\t'align',\n]);\n\n\ntype UponSanitizeElementCb = (currentNode: Element, data: dompurify.SanitizeElementHookEvent, config: dompurify.Config) => void;\ntype UponSanitizeAttributeCb = (currentNode: Element, data: dompurify.SanitizeAttributeHookEvent, config: dompurify.Config) => void;\n\nfunction addDompurifyHook(hook: 'uponSanitizeElement', cb: UponSanitizeElementCb): IDisposable;\nfunction addDompurifyHook(hook: 'uponSanitizeAttribute', cb: UponSanitizeAttributeCb): IDisposable;\nfunction addDompurifyHook(hook: 'uponSanitizeElement' | 'uponSanitizeAttribute', cb: any): IDisposable {\n\tdompurify.addHook(hook, cb);\n\treturn toDisposable(() => dompurify.removeHook(hook));\n}\n\n/**\n * Hooks dompurify using `afterSanitizeAttributes` to check that all `href` and `src`\n * attributes are valid.\n */\nfunction hookDomPurifyHrefAndSrcSanitizer(allowedLinkProtocols: readonly string[] | '*', allowedMediaProtocols: readonly string[]): IDisposable {\n\t// https://github.com/cure53/DOMPurify/blob/main/demos/hooks-scheme-allowlist.html\n\t// build an anchor to map URLs to\n\tconst anchor = document.createElement('a');\n\n\tfunction validateLink(value: string, allowedProtocols: readonly string[] | '*'): boolean {\n\t\tif (allowedProtocols === '*') {\n\t\t\treturn true; // allow all protocols\n\t\t}\n\n\t\tanchor.href = value;\n\t\treturn allowedProtocols.includes(anchor.protocol.replace(/:$/, ''));\n\t}\n\n\tdompurify.addHook('afterSanitizeAttributes', (node) => {\n\t\t// check all href/src attributes for validity\n\t\tfor (const attr of ['href', 'src']) {\n\t\t\tif (node.hasAttribute(attr)) {\n\t\t\t\tconst attrValue = node.getAttribute(attr) as string;\n\t\t\t\tif (attr === 'href') {\n\n\t\t\t\t\tif (!attrValue.startsWith('#') && !validateLink(attrValue, allowedLinkProtocols)) {\n\t\t\t\t\t\tnode.removeAttribute(attr);\n\t\t\t\t\t}\n\n\t\t\t\t} else {// 'src'\n\t\t\t\t\tif (!validateLink(attrValue, allowedMediaProtocols)) {\n\t\t\t\t\t\tnode.removeAttribute(attr);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n\n\treturn toDisposable(() => dompurify.removeHook('afterSanitizeAttributes'));\n}\n\n/**\n * Predicate that checks if an attribute should be kept or removed.\n *\n * @returns A boolean indicating whether the attribute should be kept or a string with the sanitized value (which implicitly keeps the attribute)\n */\nexport type SanitizeAttributePredicate = (node: Element, data: { readonly attrName: string; readonly attrValue: string }) => boolean | string;\n\nexport interface SanitizeAttributeRule {\n\treadonly attributeName: string;\n\tshouldKeep: SanitizeAttributePredicate;\n}\n\nexport interface DomSanitizerConfig {\n\t/**\n\t * Configured the allowed html tags.\n\t */\n\treadonly allowedTags?: {\n\t\treadonly override?: readonly string[];\n\t\treadonly augment?: readonly string[];\n\t};\n\n\t/**\n\t * Configured the allowed html attributes.\n\t */\n\treadonly allowedAttributes?: {\n\t\treadonly override?: ReadonlyArray<string | SanitizeAttributeRule>;\n\t\treadonly augment?: ReadonlyArray<string | SanitizeAttributeRule>;\n\t};\n\n\t/**\n\t * List of allowed protocols for `href` attributes.\n\t */\n\treadonly allowedLinkProtocols?: {\n\t\treadonly override?: readonly string[] | '*';\n\t};\n\n\t/**\n\t * List of allowed protocols for `src` attributes.\n\t */\n\treadonly allowedMediaProtocols?: {\n\t\treadonly override?: readonly string[];\n\t};\n\n\t/**\n\t * If set, replaces unsupported tags with their plaintext representation instead of removing them.\n\t *\n\t * For example, <p><bad>\"text\"</bad></p> becomes <p>\"<bad>text</bad>\"</p>.\n\t */\n\treadonly replaceWithPlaintext?: boolean;\n}\n\nconst defaultDomPurifyConfig = Object.freeze({\n\tALLOWED_TAGS: [...basicMarkupHtmlTags],\n\tALLOWED_ATTR: [...defaultAllowedAttrs],\n\t// We sanitize the src/href attributes later if needed\n\tALLOW_UNKNOWN_PROTOCOLS: true,\n} satisfies dompurify.Config);\n\n/**\n * Sanitizes an html string.\n *\n * @param untrusted The HTML string to sanitize.\n * @param config Optional configuration for sanitization. If not provided, defaults to a safe configuration.\n *\n * @returns A sanitized string of html.\n */\nexport function sanitizeHtml(untrusted: string, config?: DomSanitizerConfig): TrustedHTML {\n\treturn doSanitizeHtml(untrusted, config, 'trusted');\n}\n\nfunction doSanitizeHtml(untrusted: string, config: DomSanitizerConfig | undefined, outputType: 'dom'): DocumentFragment;\nfunction doSanitizeHtml(untrusted: string, config: DomSanitizerConfig | undefined, outputType: 'trusted'): TrustedHTML;\nfunction doSanitizeHtml(untrusted: string, config: DomSanitizerConfig | undefined, outputType: 'dom' | 'trusted'): TrustedHTML | DocumentFragment {\n\tconst store = new DisposableStore();\n\ttry {\n\t\tconst resolvedConfig: dompurify.Config = { ...defaultDomPurifyConfig };\n\n\t\tif (config?.allowedTags) {\n\t\t\tif (config.allowedTags.override) {\n\t\t\t\tresolvedConfig.ALLOWED_TAGS = [...config.allowedTags.override];\n\t\t\t}\n\n\t\t\tif (config.allowedTags.augment) {\n\t\t\t\tresolvedConfig.ALLOWED_TAGS = [...(resolvedConfig.ALLOWED_TAGS ?? []), ...config.allowedTags.augment];\n\t\t\t}\n\t\t}\n\n\t\tlet resolvedAttributes: Array<string | SanitizeAttributeRule> = [...defaultAllowedAttrs];\n\t\tif (config?.allowedAttributes) {\n\t\t\tif (config.allowedAttributes.override) {\n\t\t\t\tresolvedAttributes = [...config.allowedAttributes.override];\n\t\t\t}\n\n\t\t\tif (config.allowedAttributes.augment) {\n\t\t\t\tresolvedAttributes = [...resolvedAttributes, ...config.allowedAttributes.augment];\n\t\t\t}\n\t\t}\n\n\t\t// All attr names are lower-case in the sanitizer hooks\n\t\tresolvedAttributes = resolvedAttributes.map((attr): string | SanitizeAttributeRule => {\n\t\t\tif (typeof attr === 'string') {\n\t\t\t\treturn attr.toLowerCase();\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tattributeName: attr.attributeName.toLowerCase(),\n\t\t\t\tshouldKeep: attr.shouldKeep,\n\t\t\t};\n\t\t});\n\n\t\tconst allowedAttrNames = new Set(resolvedAttributes.map(attr => typeof attr === 'string' ? attr : attr.attributeName));\n\t\tconst allowedAttrPredicates = new Map<string, SanitizeAttributeRule>();\n\t\tfor (const attr of resolvedAttributes) {\n\t\t\tif (typeof attr === 'string') {\n\t\t\t\t// New string attribute value clears previously set predicates\n\t\t\t\tallowedAttrPredicates.delete(attr);\n\t\t\t} else {\n\t\t\t\tallowedAttrPredicates.set(attr.attributeName, attr);\n\t\t\t}\n\t\t}\n\n\t\tresolvedConfig.ALLOWED_ATTR = Array.from(allowedAttrNames);\n\n\t\tstore.add(hookDomPurifyHrefAndSrcSanitizer(\n\t\t\tconfig?.allowedLinkProtocols?.override ?? [Schemas.http, Schemas.https],\n\t\t\tconfig?.allowedMediaProtocols?.override ?? [Schemas.http, Schemas.https]));\n\n\t\tif (config?.replaceWithPlaintext) {\n\t\t\tstore.add(addDompurifyHook('uponSanitizeElement', replaceWithPlainTextHook));\n\t\t}\n\n\t\tif (allowedAttrPredicates.size) {\n\t\t\tstore.add(addDompurifyHook('uponSanitizeAttribute', (node, e) => {\n\t\t\t\tconst predicate = allowedAttrPredicates.get(e.attrName);\n\t\t\t\tif (predicate) {\n\t\t\t\t\tconst result = predicate.shouldKeep(node, e);\n\t\t\t\t\tif (typeof result === 'string') {\n\t\t\t\t\t\te.keepAttr = true;\n\t\t\t\t\t\te.attrValue = result;\n\t\t\t\t\t} else {\n\t\t\t\t\t\te.keepAttr = result;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\te.keepAttr = allowedAttrNames.has(e.attrName);\n\t\t\t\t}\n\t\t\t}));\n\t\t}\n\n\t\tif (outputType === 'dom') {\n\t\t\treturn dompurify.sanitize(untrusted, {\n\t\t\t\t...resolvedConfig,\n\t\t\t\tRETURN_DOM_FRAGMENT: true\n\t\t\t});\n\t\t} else {\n\t\t\treturn dompurify.sanitize(untrusted, {\n\t\t\t\t...resolvedConfig,\n\t\t\t\tRETURN_TRUSTED_TYPE: true\n\t\t\t});\n\t\t}\n\t} finally {\n\t\tstore.dispose();\n\t}\n}\n\nconst selfClosingTags = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];\n\nfunction replaceWithPlainTextHook(element: Element, data: dompurify.SanitizeElementHookEvent, _config: dompurify.Config) {\n\tif (!data.allowedTags[data.tagName] && data.tagName !== 'body') {\n\t\tconst replacement = convertTagToPlaintext(element);\n\t\tif (element.nodeType === Node.COMMENT_NODE) {\n\t\t\t// Workaround for https://github.com/cure53/DOMPurify/issues/1005\n\t\t\t// The comment will be deleted in the next phase. However if we try to remove it now, it will cause\n\t\t\t// an exception. Instead we insert the text node before the comment.\n\t\t\telement.parentElement?.insertBefore(replacement, element);\n\t\t} else {\n\t\t\telement.parentElement?.replaceChild(replacement, element);\n\t\t}\n\t}\n}\n\nexport function convertTagToPlaintext(element: Element): DocumentFragment {\n\tlet startTagText: string;\n\tlet endTagText: string | undefined;\n\tif (element.nodeType === Node.COMMENT_NODE) {\n\t\tstartTagText = `<!--${element.textContent}-->`;\n\t} else {\n\t\tconst tagName = element.tagName.toLowerCase();\n\t\tconst isSelfClosing = selfClosingTags.includes(tagName);\n\t\tconst attrString = element.attributes.length ?\n\t\t\t' ' + Array.from(element.attributes)\n\t\t\t\t.map(attr => `${attr.name}=\"${attr.value}\"`)\n\t\t\t\t.join(' ')\n\t\t\t: '';\n\t\tstartTagText = `<${tagName}${attrString}>`;\n\t\tif (!isSelfClosing) {\n\t\t\tendTagText = `</${tagName}>`;\n\t\t}\n\t}\n\n\tconst fragment = document.createDocumentFragment();\n\tconst textNode = element.ownerDocument.createTextNode(startTagText);\n\tfragment.appendChild(textNode);\n\twhile (element.firstChild) {\n\t\tfragment.appendChild(element.firstChild);\n\t}\n\n\tconst endTagTextNode = endTagText ? element.ownerDocument.createTextNode(endTagText) : undefined;\n\tif (endTagTextNode) {\n\t\tfragment.appendChild(endTagTextNode);\n\t}\n\n\treturn fragment;\n}\n\n/**\n * Sanitizes the given `value` and reset the given `node` with it.\n */\nexport function safeSetInnerHtml(node: HTMLElement, untrusted: string, config?: DomSanitizerConfig): void {\n\tconst fragment = doSanitizeHtml(untrusted, config, 'dom');\n\treset(node, fragment);\n}\n"]}
@@ -51,6 +51,9 @@ export function createStyleSheet(container = mainWindow.document.head, beforeApp
51
51
  if (container === mainWindow.document.head) {
52
52
  const globalStylesheetClones = new Set();
53
53
  globalStylesheets.set(style, globalStylesheetClones);
54
+ if (disposableStore) {
55
+ disposableStore.add(toDisposable(() => globalStylesheets.delete(style)));
56
+ }
54
57
  for (const { window: targetWindow, disposables } of getWindows()) {
55
58
  if (targetWindow === mainWindow) {
56
59
  continue; // main window is already tracked
@@ -1 +1 @@
1
- {"version":3,"sources":["file:///mnt/vss/_work/1/s/dependencies/vscode/out-editor-src/vs/base/browser/domStylesheets.ts","vs/base/browser/domStylesheets.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,eAAe,EAAE,YAAY,EAAe,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,OAAO,EAAe,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAwH,CAAC;AAE1J;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAChC,OAAO,IAAI,mBAAmB,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,mBAAmB;IAAzB;QACS,qBAA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AAK,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC;IACzC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAC1B,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC,CAAC;IACJ,OAAO,KAAK,CAAC;AACd,CAAC","file":"domStylesheets.js","sourceRoot":"file:///mnt/vss/_work/1/s/dependencies/vscode/out-editor-src","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { DisposableStore, toDisposable, IDisposable } from '../common/lifecycle.js';\nimport { autorun, IObservable } from '../common/observable.js';\nimport { getWindows, sharedMutationObserver } from './dom.js';\nimport { mainWindow } from './window.js';\n\nconst globalStylesheets = new Map<HTMLStyleElement /* main stylesheet */, Set<HTMLStyleElement /* aux window clones that track the main stylesheet */>>();\n\n/**\n * A version of createStyleSheet which has a unified API to initialize/set the style content.\n */\nexport function createStyleSheet2(): WrappedStyleElement {\n\treturn new WrappedStyleElement();\n}\n\nclass WrappedStyleElement {\n\tprivate _currentCssStyle = '';\n\tprivate _styleSheet: HTMLStyleElement | undefined = undefined;\n\n\tpublic setStyle(cssStyle: string): void {\n\t\tif (cssStyle === this._currentCssStyle) {\n\t\t\treturn;\n\t\t}\n\t\tthis._currentCssStyle = cssStyle;\n\n\t\tif (!this._styleSheet) {\n\t\t\tthis._styleSheet = createStyleSheet(mainWindow.document.head, (s) => s.textContent = cssStyle);\n\t\t} else {\n\t\t\tthis._styleSheet.textContent = cssStyle;\n\t\t}\n\t}\n\n\tpublic dispose(): void {\n\t\tif (this._styleSheet) {\n\t\t\tthis._styleSheet.remove();\n\t\t\tthis._styleSheet = undefined;\n\t\t}\n\t}\n}\n\nexport function createStyleSheet(container: HTMLElement = mainWindow.document.head, beforeAppend?: (style: HTMLStyleElement) => void, disposableStore?: DisposableStore): HTMLStyleElement {\n\tconst style = document.createElement('style');\n\tstyle.type = 'text/css';\n\tstyle.media = 'screen';\n\tbeforeAppend?.(style);\n\tcontainer.appendChild(style);\n\n\tif (disposableStore) {\n\t\tdisposableStore.add(toDisposable(() => style.remove()));\n\t}\n\n\t// With <head> as container, the stylesheet becomes global and is tracked\n\t// to support auxiliary windows to clone the stylesheet.\n\tif (container === mainWindow.document.head) {\n\t\tconst globalStylesheetClones = new Set<HTMLStyleElement>();\n\t\tglobalStylesheets.set(style, globalStylesheetClones);\n\n\t\tfor (const { window: targetWindow, disposables } of getWindows()) {\n\t\t\tif (targetWindow === mainWindow) {\n\t\t\t\tcontinue; // main window is already tracked\n\t\t\t}\n\n\t\t\tconst cloneDisposable = disposables.add(cloneGlobalStyleSheet(style, globalStylesheetClones, targetWindow));\n\t\t\tdisposableStore?.add(cloneDisposable);\n\t\t}\n\t}\n\n\treturn style;\n}\n\nfunction cloneGlobalStyleSheet(globalStylesheet: HTMLStyleElement, globalStylesheetClones: Set<HTMLStyleElement>, targetWindow: Window): IDisposable {\n\tconst disposables = new DisposableStore();\n\n\tconst clone = globalStylesheet.cloneNode(true) as HTMLStyleElement;\n\ttargetWindow.document.head.appendChild(clone);\n\tdisposables.add(toDisposable(() => clone.remove()));\n\n\tfor (const rule of getDynamicStyleSheetRules(globalStylesheet)) {\n\t\tclone.sheet?.insertRule(rule.cssText, clone.sheet?.cssRules.length);\n\t}\n\n\tdisposables.add(sharedMutationObserver.observe(globalStylesheet, disposables, { childList: true })(() => {\n\t\tclone.textContent = globalStylesheet.textContent;\n\t}));\n\n\tglobalStylesheetClones.add(clone);\n\tdisposables.add(toDisposable(() => globalStylesheetClones.delete(clone)));\n\n\treturn disposables;\n}\n\nlet _sharedStyleSheet: HTMLStyleElement | null = null;\nfunction getSharedStyleSheet(): HTMLStyleElement {\n\tif (!_sharedStyleSheet) {\n\t\t_sharedStyleSheet = createStyleSheet();\n\t}\n\treturn _sharedStyleSheet;\n}\n\nfunction getDynamicStyleSheetRules(style: HTMLStyleElement) {\n\tif (style?.sheet?.rules) {\n\t\t// Chrome, IE\n\t\treturn style.sheet.rules;\n\t}\n\tif (style?.sheet?.cssRules) {\n\t\t// FF\n\t\treturn style.sheet.cssRules;\n\t}\n\treturn [];\n}\n\nexport function createCSSRule(selector: string, cssText: string, style = getSharedStyleSheet()): void {\n\tif (!style || !cssText) {\n\t\treturn;\n\t}\n\n\tstyle.sheet?.insertRule(`${selector} {${cssText}}`, 0);\n\n\t// Apply rule also to all cloned global stylesheets\n\tfor (const clonedGlobalStylesheet of globalStylesheets.get(style) ?? []) {\n\t\tcreateCSSRule(selector, cssText, clonedGlobalStylesheet);\n\t}\n}\n\nexport function removeCSSRulesContainingSelector(ruleName: string, style = getSharedStyleSheet()): void {\n\tif (!style) {\n\t\treturn;\n\t}\n\n\tconst rules = getDynamicStyleSheetRules(style);\n\tconst toDelete: number[] = [];\n\tfor (let i = 0; i < rules.length; i++) {\n\t\tconst rule = rules[i];\n\t\tif (isCSSStyleRule(rule) && rule.selectorText.indexOf(ruleName) !== -1) {\n\t\t\ttoDelete.push(i);\n\t\t}\n\t}\n\n\tfor (let i = toDelete.length - 1; i >= 0; i--) {\n\t\tstyle.sheet?.deleteRule(toDelete[i]);\n\t}\n\n\t// Remove rules also from all cloned global stylesheets\n\tfor (const clonedGlobalStylesheet of globalStylesheets.get(style) ?? []) {\n\t\tremoveCSSRulesContainingSelector(ruleName, clonedGlobalStylesheet);\n\t}\n}\n\nfunction isCSSStyleRule(rule: CSSRule): rule is CSSStyleRule {\n\treturn typeof (rule as CSSStyleRule).selectorText === 'string';\n}\n\nexport function createStyleSheetFromObservable(css: IObservable<string>): IDisposable {\n\tconst store = new DisposableStore();\n\tconst w = store.add(createStyleSheet2());\n\tstore.add(autorun(reader => {\n\t\tw.setStyle(css.read(reader));\n\t}));\n\treturn store;\n}\n","/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { DisposableStore, toDisposable, IDisposable } from '../common/lifecycle.js';\nimport { autorun, IObservable } from '../common/observable.js';\nimport { getWindows, sharedMutationObserver } from './dom.js';\nimport { mainWindow } from './window.js';\n\nconst globalStylesheets = new Map<HTMLStyleElement /* main stylesheet */, Set<HTMLStyleElement /* aux window clones that track the main stylesheet */>>();\n\n/**\n * A version of createStyleSheet which has a unified API to initialize/set the style content.\n */\nexport function createStyleSheet2(): WrappedStyleElement {\n\treturn new WrappedStyleElement();\n}\n\nclass WrappedStyleElement {\n\tprivate _currentCssStyle = '';\n\tprivate _styleSheet: HTMLStyleElement | undefined = undefined;\n\n\tpublic setStyle(cssStyle: string): void {\n\t\tif (cssStyle === this._currentCssStyle) {\n\t\t\treturn;\n\t\t}\n\t\tthis._currentCssStyle = cssStyle;\n\n\t\tif (!this._styleSheet) {\n\t\t\tthis._styleSheet = createStyleSheet(mainWindow.document.head, (s) => s.textContent = cssStyle);\n\t\t} else {\n\t\t\tthis._styleSheet.textContent = cssStyle;\n\t\t}\n\t}\n\n\tpublic dispose(): void {\n\t\tif (this._styleSheet) {\n\t\t\tthis._styleSheet.remove();\n\t\t\tthis._styleSheet = undefined;\n\t\t}\n\t}\n}\n\nexport function createStyleSheet(container: HTMLElement = mainWindow.document.head, beforeAppend?: (style: HTMLStyleElement) => void, disposableStore?: DisposableStore): HTMLStyleElement {\n\tconst style = document.createElement('style');\n\tstyle.type = 'text/css';\n\tstyle.media = 'screen';\n\tbeforeAppend?.(style);\n\tcontainer.appendChild(style);\n\n\tif (disposableStore) {\n\t\tdisposableStore.add(toDisposable(() => style.remove()));\n\t}\n\n\t// With <head> as container, the stylesheet becomes global and is tracked\n\t// to support auxiliary windows to clone the stylesheet.\n\tif (container === mainWindow.document.head) {\n\t\tconst globalStylesheetClones = new Set<HTMLStyleElement>();\n\t\tglobalStylesheets.set(style, globalStylesheetClones);\n\n\t\tfor (const { window: targetWindow, disposables } of getWindows()) {\n\t\t\tif (targetWindow === mainWindow) {\n\t\t\t\tcontinue; // main window is already tracked\n\t\t\t}\n\n\t\t\tconst cloneDisposable = disposables.add(cloneGlobalStyleSheet(style, globalStylesheetClones, targetWindow));\n\t\t\tdisposableStore?.add(cloneDisposable);\n\t\t}\n\t}\n\n\treturn style;\n}\n\nfunction cloneGlobalStyleSheet(globalStylesheet: HTMLStyleElement, globalStylesheetClones: Set<HTMLStyleElement>, targetWindow: Window): IDisposable {\n\tconst disposables = new DisposableStore();\n\n\tconst clone = globalStylesheet.cloneNode(true) as HTMLStyleElement;\n\ttargetWindow.document.head.appendChild(clone);\n\tdisposables.add(toDisposable(() => clone.remove()));\n\n\tfor (const rule of getDynamicStyleSheetRules(globalStylesheet)) {\n\t\tclone.sheet?.insertRule(rule.cssText, clone.sheet?.cssRules.length);\n\t}\n\n\tdisposables.add(sharedMutationObserver.observe(globalStylesheet, disposables, { childList: true })(() => {\n\t\tclone.textContent = globalStylesheet.textContent;\n\t}));\n\n\tglobalStylesheetClones.add(clone);\n\tdisposables.add(toDisposable(() => globalStylesheetClones.delete(clone)));\n\n\treturn disposables;\n}\n\nlet _sharedStyleSheet: HTMLStyleElement | null = null;\nfunction getSharedStyleSheet(): HTMLStyleElement {\n\tif (!_sharedStyleSheet) {\n\t\t_sharedStyleSheet = createStyleSheet();\n\t}\n\treturn _sharedStyleSheet;\n}\n\nfunction getDynamicStyleSheetRules(style: HTMLStyleElement) {\n\tif (style?.sheet?.rules) {\n\t\t// Chrome, IE\n\t\treturn style.sheet.rules;\n\t}\n\tif (style?.sheet?.cssRules) {\n\t\t// FF\n\t\treturn style.sheet.cssRules;\n\t}\n\treturn [];\n}\n\nexport function createCSSRule(selector: string, cssText: string, style = getSharedStyleSheet()): void {\n\tif (!style || !cssText) {\n\t\treturn;\n\t}\n\n\tstyle.sheet?.insertRule(`${selector} {${cssText}}`, 0);\n\n\t// Apply rule also to all cloned global stylesheets\n\tfor (const clonedGlobalStylesheet of globalStylesheets.get(style) ?? []) {\n\t\tcreateCSSRule(selector, cssText, clonedGlobalStylesheet);\n\t}\n}\n\nexport function removeCSSRulesContainingSelector(ruleName: string, style = getSharedStyleSheet()): void {\n\tif (!style) {\n\t\treturn;\n\t}\n\n\tconst rules = getDynamicStyleSheetRules(style);\n\tconst toDelete: number[] = [];\n\tfor (let i = 0; i < rules.length; i++) {\n\t\tconst rule = rules[i];\n\t\tif (isCSSStyleRule(rule) && rule.selectorText.indexOf(ruleName) !== -1) {\n\t\t\ttoDelete.push(i);\n\t\t}\n\t}\n\n\tfor (let i = toDelete.length - 1; i >= 0; i--) {\n\t\tstyle.sheet?.deleteRule(toDelete[i]);\n\t}\n\n\t// Remove rules also from all cloned global stylesheets\n\tfor (const clonedGlobalStylesheet of globalStylesheets.get(style) ?? []) {\n\t\tremoveCSSRulesContainingSelector(ruleName, clonedGlobalStylesheet);\n\t}\n}\n\nfunction isCSSStyleRule(rule: CSSRule): rule is CSSStyleRule {\n\treturn typeof (rule as CSSStyleRule).selectorText === 'string';\n}\n\nexport function createStyleSheetFromObservable(css: IObservable<string>): IDisposable {\n\tconst store = new DisposableStore();\n\tconst w = store.add(createStyleSheet2());\n\tstore.add(autorun(reader => {\n\t\tw.setStyle(css.read(reader));\n\t}));\n\treturn store;\n}\n"]}
1
+ {"version":3,"sources":["file:///mnt/vss/_work/1/s/dependencies/vscode/out-editor-src/vs/base/browser/domStylesheets.ts","vs/base/browser/domStylesheets.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,eAAe,EAAE,YAAY,EAAe,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,OAAO,EAAe,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,iBAAiB,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AAC,IAAI,EAAE,EAAE,CAAC;QACzE,gCAAgC,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;IACpE,CAAC;AACF,CAAC;AAED,SAAS,cAAc,CAAC,IAAa;IACpC,OAAO,OAAQ,IAAqB,CAAC,YAAY,KAAK,QAAQ,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,GAAwB;IACtE,MAAM,KAAK,GAAG,IAAI,eAAe,EAAE,CAAC;IACpC,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC;IACzC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAC1B,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC,CAAC;IACJ,OAAO,KAAK,CAAC;AACd,CAAC","file":"domStylesheets.js","sourceRoot":"file:///mnt/vss/_work/1/s/dependencies/vscode/out-editor-src","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { DisposableStore, toDisposable, IDisposable } from '../common/lifecycle.js';\nimport { autorun, IObservable } from '../common/observable.js';\nimport { getWindows, sharedMutationObserver } from './dom.js';\nimport { mainWindow } from './window.js';\n\nconst globalStylesheets = new Map<HTMLStyleElement /* main stylesheet */, Set<HTMLStyleElement /* aux window clones that track the main stylesheet */>>();\n\n/**\n * A version of createStyleSheet which has a unified API to initialize/set the style content.\n */\nexport function createStyleSheet2(): WrappedStyleElement {\n\treturn new WrappedStyleElement();\n}\n\nclass WrappedStyleElement {\n\tprivate _currentCssStyle = '';\n\tprivate _styleSheet: HTMLStyleElement | undefined = undefined;\n\n\tpublic setStyle(cssStyle: string): void {\n\t\tif (cssStyle === this._currentCssStyle) {\n\t\t\treturn;\n\t\t}\n\t\tthis._currentCssStyle = cssStyle;\n\n\t\tif (!this._styleSheet) {\n\t\t\tthis._styleSheet = createStyleSheet(mainWindow.document.head, (s) => s.textContent = cssStyle);\n\t\t} else {\n\t\t\tthis._styleSheet.textContent = cssStyle;\n\t\t}\n\t}\n\n\tpublic dispose(): void {\n\t\tif (this._styleSheet) {\n\t\t\tthis._styleSheet.remove();\n\t\t\tthis._styleSheet = undefined;\n\t\t}\n\t}\n}\n\nexport function createStyleSheet(container: HTMLElement = mainWindow.document.head, beforeAppend?: (style: HTMLStyleElement) => void, disposableStore?: DisposableStore): HTMLStyleElement {\n\tconst style = document.createElement('style');\n\tstyle.type = 'text/css';\n\tstyle.media = 'screen';\n\tbeforeAppend?.(style);\n\tcontainer.appendChild(style);\n\n\tif (disposableStore) {\n\t\tdisposableStore.add(toDisposable(() => style.remove()));\n\t}\n\n\t// With <head> as container, the stylesheet becomes global and is tracked\n\t// to support auxiliary windows to clone the stylesheet.\n\tif (container === mainWindow.document.head) {\n\t\tconst globalStylesheetClones = new Set<HTMLStyleElement>();\n\t\tglobalStylesheets.set(style, globalStylesheetClones);\n\t\tif (disposableStore) {\n\t\t\tdisposableStore.add(toDisposable(() => globalStylesheets.delete(style)));\n\t\t}\n\n\t\tfor (const { window: targetWindow, disposables } of getWindows()) {\n\t\t\tif (targetWindow === mainWindow) {\n\t\t\t\tcontinue; // main window is already tracked\n\t\t\t}\n\n\t\t\tconst cloneDisposable = disposables.add(cloneGlobalStyleSheet(style, globalStylesheetClones, targetWindow));\n\t\t\tdisposableStore?.add(cloneDisposable);\n\t\t}\n\t}\n\n\treturn style;\n}\n\nfunction cloneGlobalStyleSheet(globalStylesheet: HTMLStyleElement, globalStylesheetClones: Set<HTMLStyleElement>, targetWindow: Window): IDisposable {\n\tconst disposables = new DisposableStore();\n\n\tconst clone = globalStylesheet.cloneNode(true) as HTMLStyleElement;\n\ttargetWindow.document.head.appendChild(clone);\n\tdisposables.add(toDisposable(() => clone.remove()));\n\n\tfor (const rule of getDynamicStyleSheetRules(globalStylesheet)) {\n\t\tclone.sheet?.insertRule(rule.cssText, clone.sheet?.cssRules.length);\n\t}\n\n\tdisposables.add(sharedMutationObserver.observe(globalStylesheet, disposables, { childList: true })(() => {\n\t\tclone.textContent = globalStylesheet.textContent;\n\t}));\n\n\tglobalStylesheetClones.add(clone);\n\tdisposables.add(toDisposable(() => globalStylesheetClones.delete(clone)));\n\n\treturn disposables;\n}\n\nlet _sharedStyleSheet: HTMLStyleElement | null = null;\nfunction getSharedStyleSheet(): HTMLStyleElement {\n\tif (!_sharedStyleSheet) {\n\t\t_sharedStyleSheet = createStyleSheet();\n\t}\n\treturn _sharedStyleSheet;\n}\n\nfunction getDynamicStyleSheetRules(style: HTMLStyleElement) {\n\tif (style?.sheet?.rules) {\n\t\t// Chrome, IE\n\t\treturn style.sheet.rules;\n\t}\n\tif (style?.sheet?.cssRules) {\n\t\t// FF\n\t\treturn style.sheet.cssRules;\n\t}\n\treturn [];\n}\n\nexport function createCSSRule(selector: string, cssText: string, style = getSharedStyleSheet()): void {\n\tif (!style || !cssText) {\n\t\treturn;\n\t}\n\n\tstyle.sheet?.insertRule(`${selector} {${cssText}}`, 0);\n\n\t// Apply rule also to all cloned global stylesheets\n\tfor (const clonedGlobalStylesheet of globalStylesheets.get(style) ?? []) {\n\t\tcreateCSSRule(selector, cssText, clonedGlobalStylesheet);\n\t}\n}\n\nexport function removeCSSRulesContainingSelector(ruleName: string, style = getSharedStyleSheet()): void {\n\tif (!style) {\n\t\treturn;\n\t}\n\n\tconst rules = getDynamicStyleSheetRules(style);\n\tconst toDelete: number[] = [];\n\tfor (let i = 0; i < rules.length; i++) {\n\t\tconst rule = rules[i];\n\t\tif (isCSSStyleRule(rule) && rule.selectorText.indexOf(ruleName) !== -1) {\n\t\t\ttoDelete.push(i);\n\t\t}\n\t}\n\n\tfor (let i = toDelete.length - 1; i >= 0; i--) {\n\t\tstyle.sheet?.deleteRule(toDelete[i]);\n\t}\n\n\t// Remove rules also from all cloned global stylesheets\n\tfor (const clonedGlobalStylesheet of globalStylesheets.get(style) ?? []) {\n\t\tremoveCSSRulesContainingSelector(ruleName, clonedGlobalStylesheet);\n\t}\n}\n\nfunction isCSSStyleRule(rule: CSSRule): rule is CSSStyleRule {\n\treturn typeof (rule as CSSStyleRule).selectorText === 'string';\n}\n\nexport function createStyleSheetFromObservable(css: IObservable<string>): IDisposable {\n\tconst store = new DisposableStore();\n\tconst w = store.add(createStyleSheet2());\n\tstore.add(autorun(reader => {\n\t\tw.setStyle(css.read(reader));\n\t}));\n\treturn store;\n}\n","/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { DisposableStore, toDisposable, IDisposable } from '../common/lifecycle.js';\nimport { autorun, IObservable } from '../common/observable.js';\nimport { getWindows, sharedMutationObserver } from './dom.js';\nimport { mainWindow } from './window.js';\n\nconst globalStylesheets = new Map<HTMLStyleElement /* main stylesheet */, Set<HTMLStyleElement /* aux window clones that track the main stylesheet */>>();\n\n/**\n * A version of createStyleSheet which has a unified API to initialize/set the style content.\n */\nexport function createStyleSheet2(): WrappedStyleElement {\n\treturn new WrappedStyleElement();\n}\n\nclass WrappedStyleElement {\n\tprivate _currentCssStyle = '';\n\tprivate _styleSheet: HTMLStyleElement | undefined = undefined;\n\n\tpublic setStyle(cssStyle: string): void {\n\t\tif (cssStyle === this._currentCssStyle) {\n\t\t\treturn;\n\t\t}\n\t\tthis._currentCssStyle = cssStyle;\n\n\t\tif (!this._styleSheet) {\n\t\t\tthis._styleSheet = createStyleSheet(mainWindow.document.head, (s) => s.textContent = cssStyle);\n\t\t} else {\n\t\t\tthis._styleSheet.textContent = cssStyle;\n\t\t}\n\t}\n\n\tpublic dispose(): void {\n\t\tif (this._styleSheet) {\n\t\t\tthis._styleSheet.remove();\n\t\t\tthis._styleSheet = undefined;\n\t\t}\n\t}\n}\n\nexport function createStyleSheet(container: HTMLElement = mainWindow.document.head, beforeAppend?: (style: HTMLStyleElement) => void, disposableStore?: DisposableStore): HTMLStyleElement {\n\tconst style = document.createElement('style');\n\tstyle.type = 'text/css';\n\tstyle.media = 'screen';\n\tbeforeAppend?.(style);\n\tcontainer.appendChild(style);\n\n\tif (disposableStore) {\n\t\tdisposableStore.add(toDisposable(() => style.remove()));\n\t}\n\n\t// With <head> as container, the stylesheet becomes global and is tracked\n\t// to support auxiliary windows to clone the stylesheet.\n\tif (container === mainWindow.document.head) {\n\t\tconst globalStylesheetClones = new Set<HTMLStyleElement>();\n\t\tglobalStylesheets.set(style, globalStylesheetClones);\n\t\tif (disposableStore) {\n\t\t\tdisposableStore.add(toDisposable(() => globalStylesheets.delete(style)));\n\t\t}\n\n\t\tfor (const { window: targetWindow, disposables } of getWindows()) {\n\t\t\tif (targetWindow === mainWindow) {\n\t\t\t\tcontinue; // main window is already tracked\n\t\t\t}\n\n\t\t\tconst cloneDisposable = disposables.add(cloneGlobalStyleSheet(style, globalStylesheetClones, targetWindow));\n\t\t\tdisposableStore?.add(cloneDisposable);\n\t\t}\n\t}\n\n\treturn style;\n}\n\nfunction cloneGlobalStyleSheet(globalStylesheet: HTMLStyleElement, globalStylesheetClones: Set<HTMLStyleElement>, targetWindow: Window): IDisposable {\n\tconst disposables = new DisposableStore();\n\n\tconst clone = globalStylesheet.cloneNode(true) as HTMLStyleElement;\n\ttargetWindow.document.head.appendChild(clone);\n\tdisposables.add(toDisposable(() => clone.remove()));\n\n\tfor (const rule of getDynamicStyleSheetRules(globalStylesheet)) {\n\t\tclone.sheet?.insertRule(rule.cssText, clone.sheet?.cssRules.length);\n\t}\n\n\tdisposables.add(sharedMutationObserver.observe(globalStylesheet, disposables, { childList: true })(() => {\n\t\tclone.textContent = globalStylesheet.textContent;\n\t}));\n\n\tglobalStylesheetClones.add(clone);\n\tdisposables.add(toDisposable(() => globalStylesheetClones.delete(clone)));\n\n\treturn disposables;\n}\n\nlet _sharedStyleSheet: HTMLStyleElement | null = null;\nfunction getSharedStyleSheet(): HTMLStyleElement {\n\tif (!_sharedStyleSheet) {\n\t\t_sharedStyleSheet = createStyleSheet();\n\t}\n\treturn _sharedStyleSheet;\n}\n\nfunction getDynamicStyleSheetRules(style: HTMLStyleElement) {\n\tif (style?.sheet?.rules) {\n\t\t// Chrome, IE\n\t\treturn style.sheet.rules;\n\t}\n\tif (style?.sheet?.cssRules) {\n\t\t// FF\n\t\treturn style.sheet.cssRules;\n\t}\n\treturn [];\n}\n\nexport function createCSSRule(selector: string, cssText: string, style = getSharedStyleSheet()): void {\n\tif (!style || !cssText) {\n\t\treturn;\n\t}\n\n\tstyle.sheet?.insertRule(`${selector} {${cssText}}`, 0);\n\n\t// Apply rule also to all cloned global stylesheets\n\tfor (const clonedGlobalStylesheet of globalStylesheets.get(style) ?? []) {\n\t\tcreateCSSRule(selector, cssText, clonedGlobalStylesheet);\n\t}\n}\n\nexport function removeCSSRulesContainingSelector(ruleName: string, style = getSharedStyleSheet()): void {\n\tif (!style) {\n\t\treturn;\n\t}\n\n\tconst rules = getDynamicStyleSheetRules(style);\n\tconst toDelete: number[] = [];\n\tfor (let i = 0; i < rules.length; i++) {\n\t\tconst rule = rules[i];\n\t\tif (isCSSStyleRule(rule) && rule.selectorText.indexOf(ruleName) !== -1) {\n\t\t\ttoDelete.push(i);\n\t\t}\n\t}\n\n\tfor (let i = toDelete.length - 1; i >= 0; i--) {\n\t\tstyle.sheet?.deleteRule(toDelete[i]);\n\t}\n\n\t// Remove rules also from all cloned global stylesheets\n\tfor (const clonedGlobalStylesheet of globalStylesheets.get(style) ?? []) {\n\t\tremoveCSSRulesContainingSelector(ruleName, clonedGlobalStylesheet);\n\t}\n}\n\nfunction isCSSStyleRule(rule: CSSRule): rule is CSSStyleRule {\n\treturn typeof (rule as CSSStyleRule).selectorText === 'string';\n}\n\nexport function createStyleSheetFromObservable(css: IObservable<string>): IDisposable {\n\tconst store = new DisposableStore();\n\tconst w = store.add(createStyleSheet2());\n\tstore.add(autorun(reader => {\n\t\tw.setStyle(css.read(reader));\n\t}));\n\treturn store;\n}\n"]}
@@ -27,9 +27,8 @@ export class BaseDropdown extends ActionRunner {
27
27
  }
28
28
  for (const event of [EventType.MOUSE_DOWN, GestureEventType.Tap]) {
29
29
  this._register(addDisposableListener(this._label, event, e => {
30
- if (isMouseEvent(e) && (e.detail > 1 || e.button !== 0)) {
30
+ if (isMouseEvent(e) && e.button !== 0) {
31
31
  // prevent right click trigger to allow separate context menu (https://github.com/microsoft/vscode/issues/151064)
32
- // prevent multiple clicks to open multiple context menus (https://github.com/microsoft/vscode/issues/41363)
33
32
  return;
34
33
  }
35
34
  if (this.visible) {
@@ -1 +1 @@
1
- {"version":3,"sources":["file:///mnt/vss/_work/1/s/dependencies/vscode/out-editor-src/vs/base/browser/ui/dropdown/dropdown.ts","vs/base/browser/ui/dropdown/dropdown.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,EAAE,CAAC,EAAE,qBAAqB,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACtG,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGxE,OAAO,EAAE,YAAY,EAAW,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAGnD,OAAO,gBAAgB,CAAC;AAWxB,MAAM,OAAO,YAAa,SAAQ,YAAY;IAU7C,YAAY,SAAsB,EAAE,OAA6B;QAChE,KAAK,EAAE,CAAC;QAJD,2BAAsB,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,OAAO,EAAW,CAAC,CAAC;QAC/D,0BAAqB,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC;QAKlE,IAAI,CAAC,QAAQ,GAAG,MAA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AAC,WAAW,CAAC,eAAe,CAAC,CAAC,6BAAqB;YAC3F,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;YACtE,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,aAAa;SAC1C,CAAC,CAAC;IACJ,CAAC;IAEQ,IAAI;QACZ,KAAK,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAEO,MAAM;QACb,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;CACD","file":"dropdown.js","sourceRoot":"file:///mnt/vss/_work/1/s/dependencies/vscode/out-editor-src","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { IContextMenuProvider } from '../../contextmenu.js';\nimport { $, addDisposableListener, append, EventHelper, EventType, isMouseEvent } from '../../dom.js';\nimport { StandardKeyboardEvent } from '../../keyboardEvent.js';\nimport { EventType as GestureEventType, Gesture } from '../../touch.js';\nimport { AnchorAlignment } from '../contextview/contextview.js';\nimport { IMenuOptions } from '../menu/menu.js';\nimport { ActionRunner, IAction } from '../../../common/actions.js';\nimport { Emitter } from '../../../common/event.js';\nimport { KeyCode } from '../../../common/keyCodes.js';\nimport { IDisposable } from '../../../common/lifecycle.js';\nimport './dropdown.css';\n\nexport interface ILabelRenderer {\n\t(container: HTMLElement): IDisposable | null;\n}\n\nexport interface IBaseDropdownOptions {\n\tlabel?: string;\n\tlabelRenderer?: ILabelRenderer;\n}\n\nexport class BaseDropdown extends ActionRunner {\n\tprivate _element: HTMLElement;\n\tprivate boxContainer?: HTMLElement;\n\tprivate _label?: HTMLElement;\n\tprivate contents?: HTMLElement;\n\n\tprivate visible: boolean | undefined;\n\tprivate _onDidChangeVisibility = this._register(new Emitter<boolean>());\n\treadonly onDidChangeVisibility = this._onDidChangeVisibility.event;\n\n\tconstructor(container: HTMLElement, options: IBaseDropdownOptions) {\n\t\tsuper();\n\n\t\tthis._element = append(container, $('.monaco-dropdown'));\n\n\t\tthis._label = append(this._element, $('.dropdown-label'));\n\n\t\tlet labelRenderer = options.labelRenderer;\n\t\tif (!labelRenderer) {\n\t\t\tlabelRenderer = (container: HTMLElement): IDisposable | null => {\n\t\t\t\tcontainer.textContent = options.label || '';\n\n\t\t\t\treturn null;\n\t\t\t};\n\t\t}\n\n\t\tfor (const event of [EventType.CLICK, EventType.MOUSE_DOWN, GestureEventType.Tap]) {\n\t\t\tthis._register(addDisposableListener(this.element, event, e => EventHelper.stop(e, true))); // prevent default click behaviour to trigger\n\t\t}\n\n\t\tfor (const event of [EventType.MOUSE_DOWN, GestureEventType.Tap]) {\n\t\t\tthis._register(addDisposableListener(this._label, event, e => {\n\t\t\t\tif (isMouseEvent(e) && (e.detail > 1 || e.button !== 0)) {\n\t\t\t\t\t// prevent right click trigger to allow separate context menu (https://github.com/microsoft/vscode/issues/151064)\n\t\t\t\t\t// prevent multiple clicks to open multiple context menus (https://github.com/microsoft/vscode/issues/41363)\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (this.visible) {\n\t\t\t\t\tthis.hide();\n\t\t\t\t} else {\n\t\t\t\t\tthis.show();\n\t\t\t\t}\n\t\t\t}));\n\t\t}\n\n\t\tthis._register(addDisposableListener(this._label, EventType.KEY_DOWN, e => {\n\t\t\tconst event = new StandardKeyboardEvent(e);\n\t\t\tif (event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) {\n\t\t\t\tEventHelper.stop(e, true); // https://github.com/microsoft/vscode/issues/57997\n\n\t\t\t\tif (this.visible) {\n\t\t\t\t\tthis.hide();\n\t\t\t\t} else {\n\t\t\t\t\tthis.show();\n\t\t\t\t}\n\t\t\t}\n\t\t}));\n\n\t\tconst cleanupFn = labelRenderer(this._label);\n\t\tif (cleanupFn) {\n\t\t\tthis._register(cleanupFn);\n\t\t}\n\n\t\tthis._register(Gesture.addTarget(this._label));\n\t}\n\n\tget element(): HTMLElement {\n\t\treturn this._element;\n\t}\n\n\tshow(): void {\n\t\tif (!this.visible) {\n\t\t\tthis.visible = true;\n\t\t\tthis._onDidChangeVisibility.fire(true);\n\t\t}\n\t}\n\n\thide(): void {\n\t\tif (this.visible) {\n\t\t\tthis.visible = false;\n\t\t\tthis._onDidChangeVisibility.fire(false);\n\t\t}\n\t}\n\n\toverride dispose(): void {\n\t\tsuper.dispose();\n\t\tthis.hide();\n\n\t\tif (this.boxContainer) {\n\t\t\tthis.boxContainer.remove();\n\t\t\tthis.boxContainer = undefined;\n\t\t}\n\n\t\tif (this.contents) {\n\t\t\tthis.contents.remove();\n\t\t\tthis.contents = undefined;\n\t\t}\n\n\t\tif (this._label) {\n\t\t\tthis._label.remove();\n\t\t\tthis._label = undefined;\n\t\t}\n\t}\n}\n\nexport interface IActionProvider {\n\tgetActions(): readonly IAction[];\n}\n\nexport interface IDropdownMenuOptions extends IBaseDropdownOptions {\n\tcontextMenuProvider: IContextMenuProvider;\n\treadonly actions?: IAction[];\n\treadonly actionProvider?: IActionProvider;\n\tmenuClassName?: string;\n\tmenuAsChild?: boolean; // scope down for #99448\n\treadonly skipTelemetry?: boolean;\n}\n\nexport class DropdownMenu extends BaseDropdown {\n\tprivate _menuOptions: IMenuOptions | undefined;\n\tprivate _actions: readonly IAction[] = [];\n\n\tconstructor(container: HTMLElement, private readonly _options: IDropdownMenuOptions) {\n\t\tsuper(container, _options);\n\n\t\tthis.actions = _options.actions || [];\n\t}\n\n\tset menuOptions(options: IMenuOptions | undefined) {\n\t\tthis._menuOptions = options;\n\t}\n\n\tget menuOptions(): IMenuOptions | undefined {\n\t\treturn this._menuOptions;\n\t}\n\n\tprivate get actions(): readonly IAction[] {\n\t\tif (this._options.actionProvider) {\n\t\t\treturn this._options.actionProvider.getActions();\n\t\t}\n\n\t\treturn this._actions;\n\t}\n\n\tprivate set actions(actions: readonly IAction[]) {\n\t\tthis._actions = actions;\n\t}\n\n\toverride show(): void {\n\t\tsuper.show();\n\n\t\tthis.element.classList.add('active');\n\n\t\tthis._options.contextMenuProvider.showContextMenu({\n\t\t\tgetAnchor: () => this.element,\n\t\t\tgetActions: () => this.actions,\n\t\t\tgetActionsContext: () => this.menuOptions ? this.menuOptions.context : null,\n\t\t\tgetActionViewItem: (action, options) => this.menuOptions && this.menuOptions.actionViewItemProvider ? this.menuOptions.actionViewItemProvider(action, options) : undefined,\n\t\t\tgetKeyBinding: action => this.menuOptions && this.menuOptions.getKeyBinding ? this.menuOptions.getKeyBinding(action) : undefined,\n\t\t\tgetMenuClassName: () => this._options.menuClassName || '',\n\t\t\tonHide: () => this.onHide(),\n\t\t\tactionRunner: this.menuOptions ? this.menuOptions.actionRunner : undefined,\n\t\t\tanchorAlignment: this.menuOptions ? this.menuOptions.anchorAlignment : AnchorAlignment.LEFT,\n\t\t\tdomForShadowRoot: this._options.menuAsChild ? this.element : undefined,\n\t\t\tskipTelemetry: this._options.skipTelemetry\n\t\t});\n\t}\n\n\toverride hide(): void {\n\t\tsuper.hide();\n\t}\n\n\tprivate onHide(): void {\n\t\tthis.hide();\n\t\tthis.element.classList.remove('active');\n\t}\n}\n","/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { IContextMenuProvider } from '../../contextmenu.js';\nimport { $, addDisposableListener, append, EventHelper, EventType, isMouseEvent } from '../../dom.js';\nimport { StandardKeyboardEvent } from '../../keyboardEvent.js';\nimport { EventType as GestureEventType, Gesture } from '../../touch.js';\nimport { AnchorAlignment } from '../contextview/contextview.js';\nimport { IMenuOptions } from '../menu/menu.js';\nimport { ActionRunner, IAction } from '../../../common/actions.js';\nimport { Emitter } from '../../../common/event.js';\nimport { KeyCode } from '../../../common/keyCodes.js';\nimport { IDisposable } from '../../../common/lifecycle.js';\nimport './dropdown.css';\n\nexport interface ILabelRenderer {\n\t(container: HTMLElement): IDisposable | null;\n}\n\nexport interface IBaseDropdownOptions {\n\tlabel?: string;\n\tlabelRenderer?: ILabelRenderer;\n}\n\nexport class BaseDropdown extends ActionRunner {\n\tprivate _element: HTMLElement;\n\tprivate boxContainer?: HTMLElement;\n\tprivate _label?: HTMLElement;\n\tprivate contents?: HTMLElement;\n\n\tprivate visible: boolean | undefined;\n\tprivate _onDidChangeVisibility = this._register(new Emitter<boolean>());\n\treadonly onDidChangeVisibility = this._onDidChangeVisibility.event;\n\n\tconstructor(container: HTMLElement, options: IBaseDropdownOptions) {\n\t\tsuper();\n\n\t\tthis._element = append(container, $('.monaco-dropdown'));\n\n\t\tthis._label = append(this._element, $('.dropdown-label'));\n\n\t\tlet labelRenderer = options.labelRenderer;\n\t\tif (!labelRenderer) {\n\t\t\tlabelRenderer = (container: HTMLElement): IDisposable | null => {\n\t\t\t\tcontainer.textContent = options.label || '';\n\n\t\t\t\treturn null;\n\t\t\t};\n\t\t}\n\n\t\tfor (const event of [EventType.CLICK, EventType.MOUSE_DOWN, GestureEventType.Tap]) {\n\t\t\tthis._register(addDisposableListener(this.element, event, e => EventHelper.stop(e, true))); // prevent default click behaviour to trigger\n\t\t}\n\n\t\tfor (const event of [EventType.MOUSE_DOWN, GestureEventType.Tap]) {\n\t\t\tthis._register(addDisposableListener(this._label, event, e => {\n\t\t\t\tif (isMouseEvent(e) && (e.detail > 1 || e.button !== 0)) {\n\t\t\t\t\t// prevent right click trigger to allow separate context menu (https://github.com/microsoft/vscode/issues/151064)\n\t\t\t\t\t// prevent multiple clicks to open multiple context menus (https://github.com/microsoft/vscode/issues/41363)\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (this.visible) {\n\t\t\t\t\tthis.hide();\n\t\t\t\t} else {\n\t\t\t\t\tthis.show();\n\t\t\t\t}\n\t\t\t}));\n\t\t}\n\n\t\tthis._register(addDisposableListener(this._label, EventType.KEY_DOWN, e => {\n\t\t\tconst event = new StandardKeyboardEvent(e);\n\t\t\tif (event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) {\n\t\t\t\tEventHelper.stop(e, true); // https://github.com/microsoft/vscode/issues/57997\n\n\t\t\t\tif (this.visible) {\n\t\t\t\t\tthis.hide();\n\t\t\t\t} else {\n\t\t\t\t\tthis.show();\n\t\t\t\t}\n\t\t\t}\n\t\t}));\n\n\t\tconst cleanupFn = labelRenderer(this._label);\n\t\tif (cleanupFn) {\n\t\t\tthis._register(cleanupFn);\n\t\t}\n\n\t\tthis._register(Gesture.addTarget(this._label));\n\t}\n\n\tget element(): HTMLElement {\n\t\treturn this._element;\n\t}\n\n\tshow(): void {\n\t\tif (!this.visible) {\n\t\t\tthis.visible = true;\n\t\t\tthis._onDidChangeVisibility.fire(true);\n\t\t}\n\t}\n\n\thide(): void {\n\t\tif (this.visible) {\n\t\t\tthis.visible = false;\n\t\t\tthis._onDidChangeVisibility.fire(false);\n\t\t}\n\t}\n\n\toverride dispose(): void {\n\t\tsuper.dispose();\n\t\tthis.hide();\n\n\t\tif (this.boxContainer) {\n\t\t\tthis.boxContainer.remove();\n\t\t\tthis.boxContainer = undefined;\n\t\t}\n\n\t\tif (this.contents) {\n\t\t\tthis.contents.remove();\n\t\t\tthis.contents = undefined;\n\t\t}\n\n\t\tif (this._label) {\n\t\t\tthis._label.remove();\n\t\t\tthis._label = undefined;\n\t\t}\n\t}\n}\n\nexport interface IActionProvider {\n\tgetActions(): readonly IAction[];\n}\n\nexport interface IDropdownMenuOptions extends IBaseDropdownOptions {\n\tcontextMenuProvider: IContextMenuProvider;\n\treadonly actions?: IAction[];\n\treadonly actionProvider?: IActionProvider;\n\tmenuClassName?: string;\n\tmenuAsChild?: boolean; // scope down for #99448\n\treadonly skipTelemetry?: boolean;\n}\n\nexport class DropdownMenu extends BaseDropdown {\n\tprivate _menuOptions: IMenuOptions | undefined;\n\tprivate _actions: readonly IAction[] = [];\n\n\tconstructor(container: HTMLElement, private readonly _options: IDropdownMenuOptions) {\n\t\tsuper(container, _options);\n\n\t\tthis.actions = _options.actions || [];\n\t}\n\n\tset menuOptions(options: IMenuOptions | undefined) {\n\t\tthis._menuOptions = options;\n\t}\n\n\tget menuOptions(): IMenuOptions | undefined {\n\t\treturn this._menuOptions;\n\t}\n\n\tprivate get actions(): readonly IAction[] {\n\t\tif (this._options.actionProvider) {\n\t\t\treturn this._options.actionProvider.getActions();\n\t\t}\n\n\t\treturn this._actions;\n\t}\n\n\tprivate set actions(actions: readonly IAction[]) {\n\t\tthis._actions = actions;\n\t}\n\n\toverride show(): void {\n\t\tsuper.show();\n\n\t\tthis.element.classList.add('active');\n\n\t\tthis._options.contextMenuProvider.showContextMenu({\n\t\t\tgetAnchor: () => this.element,\n\t\t\tgetActions: () => this.actions,\n\t\t\tgetActionsContext: () => this.menuOptions ? this.menuOptions.context : null,\n\t\t\tgetActionViewItem: (action, options) => this.menuOptions && this.menuOptions.actionViewItemProvider ? this.menuOptions.actionViewItemProvider(action, options) : undefined,\n\t\t\tgetKeyBinding: action => this.menuOptions && this.menuOptions.getKeyBinding ? this.menuOptions.getKeyBinding(action) : undefined,\n\t\t\tgetMenuClassName: () => this._options.menuClassName || '',\n\t\t\tonHide: () => this.onHide(),\n\t\t\tactionRunner: this.menuOptions ? this.menuOptions.actionRunner : undefined,\n\t\t\tanchorAlignment: this.menuOptions ? this.menuOptions.anchorAlignment : AnchorAlignment.LEFT,\n\t\t\tdomForShadowRoot: this._options.menuAsChild ? this.element : undefined,\n\t\t\tskipTelemetry: this._options.skipTelemetry\n\t\t});\n\t}\n\n\toverride hide(): void {\n\t\tsuper.hide();\n\t}\n\n\tprivate onHide(): void {\n\t\tthis.hide();\n\t\tthis.element.classList.remove('active');\n\t}\n}\n"]}
1
+ {"version":3,"sources":["file:///mnt/vss/_work/1/s/dependencies/vscode/out-editor-src/vs/base/browser/ui/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WAAW,IAAI,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS;YAC1K,aAAa,EAAE,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;YAChI,gBAAgB,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,IAAI,EAAE;YACzD,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE;YAC3B,YAAY,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;YAC1E,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,6BAAqB;YAC3F,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;YACtE,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,aAAa;SAC1C,CAAC,CAAC;IACJ,CAAC;IAEQ,IAAI;QACZ,KAAK,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAEO,MAAM;QACb,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;CACD","file":"dropdown.js","sourceRoot":"file:///mnt/vss/_work/1/s/dependencies/vscode/out-editor-src","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { IContextMenuProvider } from '../../contextmenu.js';\nimport { $, addDisposableListener, append, EventHelper, EventType, isMouseEvent } from '../../dom.js';\nimport { StandardKeyboardEvent } from '../../keyboardEvent.js';\nimport { EventType as GestureEventType, Gesture } from '../../touch.js';\nimport { AnchorAlignment } from '../contextview/contextview.js';\nimport { IMenuOptions } from '../menu/menu.js';\nimport { ActionRunner, IAction } from '../../../common/actions.js';\nimport { Emitter } from '../../../common/event.js';\nimport { KeyCode } from '../../../common/keyCodes.js';\nimport { IDisposable } from '../../../common/lifecycle.js';\nimport './dropdown.css';\n\nexport interface ILabelRenderer {\n\t(container: HTMLElement): IDisposable | null;\n}\n\nexport interface IBaseDropdownOptions {\n\tlabel?: string;\n\tlabelRenderer?: ILabelRenderer;\n}\n\nexport class BaseDropdown extends ActionRunner {\n\tprivate _element: HTMLElement;\n\tprivate boxContainer?: HTMLElement;\n\tprivate _label?: HTMLElement;\n\tprivate contents?: HTMLElement;\n\n\tprivate visible: boolean | undefined;\n\tprivate _onDidChangeVisibility = this._register(new Emitter<boolean>());\n\treadonly onDidChangeVisibility = this._onDidChangeVisibility.event;\n\n\tconstructor(container: HTMLElement, options: IBaseDropdownOptions) {\n\t\tsuper();\n\n\t\tthis._element = append(container, $('.monaco-dropdown'));\n\n\t\tthis._label = append(this._element, $('.dropdown-label'));\n\n\t\tlet labelRenderer = options.labelRenderer;\n\t\tif (!labelRenderer) {\n\t\t\tlabelRenderer = (container: HTMLElement): IDisposable | null => {\n\t\t\t\tcontainer.textContent = options.label || '';\n\n\t\t\t\treturn null;\n\t\t\t};\n\t\t}\n\n\t\tfor (const event of [EventType.CLICK, EventType.MOUSE_DOWN, GestureEventType.Tap]) {\n\t\t\tthis._register(addDisposableListener(this.element, event, e => EventHelper.stop(e, true))); // prevent default click behaviour to trigger\n\t\t}\n\n\t\tfor (const event of [EventType.MOUSE_DOWN, GestureEventType.Tap]) {\n\t\t\tthis._register(addDisposableListener(this._label, event, e => {\n\t\t\t\tif (isMouseEvent(e) && e.button !== 0) {\n\t\t\t\t\t// prevent right click trigger to allow separate context menu (https://github.com/microsoft/vscode/issues/151064)\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (this.visible) {\n\t\t\t\t\tthis.hide();\n\t\t\t\t} else {\n\t\t\t\t\tthis.show();\n\t\t\t\t}\n\t\t\t}));\n\t\t}\n\n\t\tthis._register(addDisposableListener(this._label, EventType.KEY_DOWN, e => {\n\t\t\tconst event = new StandardKeyboardEvent(e);\n\t\t\tif (event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) {\n\t\t\t\tEventHelper.stop(e, true); // https://github.com/microsoft/vscode/issues/57997\n\n\t\t\t\tif (this.visible) {\n\t\t\t\t\tthis.hide();\n\t\t\t\t} else {\n\t\t\t\t\tthis.show();\n\t\t\t\t}\n\t\t\t}\n\t\t}));\n\n\t\tconst cleanupFn = labelRenderer(this._label);\n\t\tif (cleanupFn) {\n\t\t\tthis._register(cleanupFn);\n\t\t}\n\n\t\tthis._register(Gesture.addTarget(this._label));\n\t}\n\n\tget element(): HTMLElement {\n\t\treturn this._element;\n\t}\n\n\tshow(): void {\n\t\tif (!this.visible) {\n\t\t\tthis.visible = true;\n\t\t\tthis._onDidChangeVisibility.fire(true);\n\t\t}\n\t}\n\n\thide(): void {\n\t\tif (this.visible) {\n\t\t\tthis.visible = false;\n\t\t\tthis._onDidChangeVisibility.fire(false);\n\t\t}\n\t}\n\n\toverride dispose(): void {\n\t\tsuper.dispose();\n\t\tthis.hide();\n\n\t\tif (this.boxContainer) {\n\t\t\tthis.boxContainer.remove();\n\t\t\tthis.boxContainer = undefined;\n\t\t}\n\n\t\tif (this.contents) {\n\t\t\tthis.contents.remove();\n\t\t\tthis.contents = undefined;\n\t\t}\n\n\t\tif (this._label) {\n\t\t\tthis._label.remove();\n\t\t\tthis._label = undefined;\n\t\t}\n\t}\n}\n\nexport interface IActionProvider {\n\tgetActions(): readonly IAction[];\n}\n\nexport interface IDropdownMenuOptions extends IBaseDropdownOptions {\n\tcontextMenuProvider: IContextMenuProvider;\n\treadonly actions?: IAction[];\n\treadonly actionProvider?: IActionProvider;\n\tmenuClassName?: string;\n\tmenuAsChild?: boolean; // scope down for #99448\n\treadonly skipTelemetry?: boolean;\n}\n\nexport class DropdownMenu extends BaseDropdown {\n\tprivate _menuOptions: IMenuOptions | undefined;\n\tprivate _actions: readonly IAction[] = [];\n\n\tconstructor(container: HTMLElement, private readonly _options: IDropdownMenuOptions) {\n\t\tsuper(container, _options);\n\n\t\tthis.actions = _options.actions || [];\n\t}\n\n\tset menuOptions(options: IMenuOptions | undefined) {\n\t\tthis._menuOptions = options;\n\t}\n\n\tget menuOptions(): IMenuOptions | undefined {\n\t\treturn this._menuOptions;\n\t}\n\n\tprivate get actions(): readonly IAction[] {\n\t\tif (this._options.actionProvider) {\n\t\t\treturn this._options.actionProvider.getActions();\n\t\t}\n\n\t\treturn this._actions;\n\t}\n\n\tprivate set actions(actions: readonly IAction[]) {\n\t\tthis._actions = actions;\n\t}\n\n\toverride show(): void {\n\t\tsuper.show();\n\n\t\tthis.element.classList.add('active');\n\n\t\tthis._options.contextMenuProvider.showContextMenu({\n\t\t\tgetAnchor: () => this.element,\n\t\t\tgetActions: () => this.actions,\n\t\t\tgetActionsContext: () => this.menuOptions ? this.menuOptions.context : null,\n\t\t\tgetActionViewItem: (action, options) => this.menuOptions && this.menuOptions.actionViewItemProvider ? this.menuOptions.actionViewItemProvider(action, options) : undefined,\n\t\t\tgetKeyBinding: action => this.menuOptions && this.menuOptions.getKeyBinding ? this.menuOptions.getKeyBinding(action) : undefined,\n\t\t\tgetMenuClassName: () => this._options.menuClassName || '',\n\t\t\tonHide: () => this.onHide(),\n\t\t\tactionRunner: this.menuOptions ? this.menuOptions.actionRunner : undefined,\n\t\t\tanchorAlignment: this.menuOptions ? this.menuOptions.anchorAlignment : AnchorAlignment.LEFT,\n\t\t\tdomForShadowRoot: this._options.menuAsChild ? this.element : undefined,\n\t\t\tskipTelemetry: this._options.skipTelemetry\n\t\t});\n\t}\n\n\toverride hide(): void {\n\t\tsuper.hide();\n\t}\n\n\tprivate onHide(): void {\n\t\tthis.hide();\n\t\tthis.element.classList.remove('active');\n\t}\n}\n","/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n\nimport { IContextMenuProvider } from '../../contextmenu.js';\nimport { $, addDisposableListener, append, EventHelper, EventType, isMouseEvent } from '../../dom.js';\nimport { StandardKeyboardEvent } from '../../keyboardEvent.js';\nimport { EventType as GestureEventType, Gesture } from '../../touch.js';\nimport { AnchorAlignment } from '../contextview/contextview.js';\nimport { IMenuOptions } from '../menu/menu.js';\nimport { ActionRunner, IAction } from '../../../common/actions.js';\nimport { Emitter } from '../../../common/event.js';\nimport { KeyCode } from '../../../common/keyCodes.js';\nimport { IDisposable } from '../../../common/lifecycle.js';\nimport './dropdown.css';\n\nexport interface ILabelRenderer {\n\t(container: HTMLElement): IDisposable | null;\n}\n\nexport interface IBaseDropdownOptions {\n\tlabel?: string;\n\tlabelRenderer?: ILabelRenderer;\n}\n\nexport class BaseDropdown extends ActionRunner {\n\tprivate _element: HTMLElement;\n\tprivate boxContainer?: HTMLElement;\n\tprivate _label?: HTMLElement;\n\tprivate contents?: HTMLElement;\n\n\tprivate visible: boolean | undefined;\n\tprivate _onDidChangeVisibility = this._register(new Emitter<boolean>());\n\treadonly onDidChangeVisibility = this._onDidChangeVisibility.event;\n\n\tconstructor(container: HTMLElement, options: IBaseDropdownOptions) {\n\t\tsuper();\n\n\t\tthis._element = append(container, $('.monaco-dropdown'));\n\n\t\tthis._label = append(this._element, $('.dropdown-label'));\n\n\t\tlet labelRenderer = options.labelRenderer;\n\t\tif (!labelRenderer) {\n\t\t\tlabelRenderer = (container: HTMLElement): IDisposable | null => {\n\t\t\t\tcontainer.textContent = options.label || '';\n\n\t\t\t\treturn null;\n\t\t\t};\n\t\t}\n\n\t\tfor (const event of [EventType.CLICK, EventType.MOUSE_DOWN, GestureEventType.Tap]) {\n\t\t\tthis._register(addDisposableListener(this.element, event, e => EventHelper.stop(e, true))); // prevent default click behaviour to trigger\n\t\t}\n\n\t\tfor (const event of [EventType.MOUSE_DOWN, GestureEventType.Tap]) {\n\t\t\tthis._register(addDisposableListener(this._label, event, e => {\n\t\t\t\tif (isMouseEvent(e) && e.button !== 0) {\n\t\t\t\t\t// prevent right click trigger to allow separate context menu (https://github.com/microsoft/vscode/issues/151064)\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (this.visible) {\n\t\t\t\t\tthis.hide();\n\t\t\t\t} else {\n\t\t\t\t\tthis.show();\n\t\t\t\t}\n\t\t\t}));\n\t\t}\n\n\t\tthis._register(addDisposableListener(this._label, EventType.KEY_DOWN, e => {\n\t\t\tconst event = new StandardKeyboardEvent(e);\n\t\t\tif (event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) {\n\t\t\t\tEventHelper.stop(e, true); // https://github.com/microsoft/vscode/issues/57997\n\n\t\t\t\tif (this.visible) {\n\t\t\t\t\tthis.hide();\n\t\t\t\t} else {\n\t\t\t\t\tthis.show();\n\t\t\t\t}\n\t\t\t}\n\t\t}));\n\n\t\tconst cleanupFn = labelRenderer(this._label);\n\t\tif (cleanupFn) {\n\t\t\tthis._register(cleanupFn);\n\t\t}\n\n\t\tthis._register(Gesture.addTarget(this._label));\n\t}\n\n\tget element(): HTMLElement {\n\t\treturn this._element;\n\t}\n\n\tshow(): void {\n\t\tif (!this.visible) {\n\t\t\tthis.visible = true;\n\t\t\tthis._onDidChangeVisibility.fire(true);\n\t\t}\n\t}\n\n\thide(): void {\n\t\tif (this.visible) {\n\t\t\tthis.visible = false;\n\t\t\tthis._onDidChangeVisibility.fire(false);\n\t\t}\n\t}\n\n\toverride dispose(): void {\n\t\tsuper.dispose();\n\t\tthis.hide();\n\n\t\tif (this.boxContainer) {\n\t\t\tthis.boxContainer.remove();\n\t\t\tthis.boxContainer = undefined;\n\t\t}\n\n\t\tif (this.contents) {\n\t\t\tthis.contents.remove();\n\t\t\tthis.contents = undefined;\n\t\t}\n\n\t\tif (this._label) {\n\t\t\tthis._label.remove();\n\t\t\tthis._label = undefined;\n\t\t}\n\t}\n}\n\nexport interface IActionProvider {\n\tgetActions(): readonly IAction[];\n}\n\nexport interface IDropdownMenuOptions extends IBaseDropdownOptions {\n\tcontextMenuProvider: IContextMenuProvider;\n\treadonly actions?: IAction[];\n\treadonly actionProvider?: IActionProvider;\n\tmenuClassName?: string;\n\tmenuAsChild?: boolean; // scope down for #99448\n\treadonly skipTelemetry?: boolean;\n}\n\nexport class DropdownMenu extends BaseDropdown {\n\tprivate _menuOptions: IMenuOptions | undefined;\n\tprivate _actions: readonly IAction[] = [];\n\n\tconstructor(container: HTMLElement, private readonly _options: IDropdownMenuOptions) {\n\t\tsuper(container, _options);\n\n\t\tthis.actions = _options.actions || [];\n\t}\n\n\tset menuOptions(options: IMenuOptions | undefined) {\n\t\tthis._menuOptions = options;\n\t}\n\n\tget menuOptions(): IMenuOptions | undefined {\n\t\treturn this._menuOptions;\n\t}\n\n\tprivate get actions(): readonly IAction[] {\n\t\tif (this._options.actionProvider) {\n\t\t\treturn this._options.actionProvider.getActions();\n\t\t}\n\n\t\treturn this._actions;\n\t}\n\n\tprivate set actions(actions: readonly IAction[]) {\n\t\tthis._actions = actions;\n\t}\n\n\toverride show(): void {\n\t\tsuper.show();\n\n\t\tthis.element.classList.add('active');\n\n\t\tthis._options.contextMenuProvider.showContextMenu({\n\t\t\tgetAnchor: () => this.element,\n\t\t\tgetActions: () => this.actions,\n\t\t\tgetActionsContext: () => this.menuOptions ? this.menuOptions.context : null,\n\t\t\tgetActionViewItem: (action, options) => this.menuOptions && this.menuOptions.actionViewItemProvider ? this.menuOptions.actionViewItemProvider(action, options) : undefined,\n\t\t\tgetKeyBinding: action => this.menuOptions && this.menuOptions.getKeyBinding ? this.menuOptions.getKeyBinding(action) : undefined,\n\t\t\tgetMenuClassName: () => this._options.menuClassName || '',\n\t\t\tonHide: () => this.onHide(),\n\t\t\tactionRunner: this.menuOptions ? this.menuOptions.actionRunner : undefined,\n\t\t\tanchorAlignment: this.menuOptions ? this.menuOptions.anchorAlignment : AnchorAlignment.LEFT,\n\t\t\tdomForShadowRoot: this._options.menuAsChild ? this.element : undefined,\n\t\t\tskipTelemetry: this._options.skipTelemetry\n\t\t});\n\t}\n\n\toverride hide(): void {\n\t\tsuper.hide();\n\t}\n\n\tprivate onHide(): void {\n\t\tthis.hide();\n\t\tthis.element.classList.remove('active');\n\t}\n}\n"]}
@@ -663,6 +663,9 @@ export class DeferredPromise {
663
663
  });
664
664
  }
665
665
  complete(value) {
666
+ if (this.isSettled) {
667
+ return Promise.resolve();
668
+ }
666
669
  return new Promise(resolve => {
667
670
  this.completeCallback(value);
668
671
  this.outcome = { outcome: 0 /* DeferredOutcome.Resolved */, value };
@@ -670,6 +673,9 @@ export class DeferredPromise {
670
673
  });
671
674
  }
672
675
  error(err) {
676
+ if (this.isSettled) {
677
+ return Promise.resolve();
678
+ }
673
679
  return new Promise(resolve => {
674
680
  this.errorCallback(err);
675
681
  this.outcome = { outcome: 1 /* DeferredOutcome.Rejected */, value: err };