<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
"use strict";

function styleBody(e) {
  e && (e.classList.remove("vscode-light", "vscode-dark", "vscode-high-contrast"), e.classList.add(initData.activeTheme))
}

function getTarget() {
  return document.getElementById("_target")
}
var initData = {};
const ipcRenderer = require("electron").ipcRenderer;
document.addEventListener("DOMContentLoaded", function (e) {
  ipcRenderer.on("baseUrl", function (e, t) {
    initData.baseUrl = t
  }), ipcRenderer.on("styles", function (e, t, n) {
    initData.styles = t, initData.activeTheme = n;
    var o = document.getElementById("_defaultStyles");
    o.innerHTML = initData.styles;
    var a = getTarget().contentDocument.getElementsByTagName("body");
    styleBody(a[0]), o = getTarget().contentDocument.getElementById("_defaultStyles"), o && (o.innerHTML = initData.styles)
  }), ipcRenderer.on("focus", function () {
    getTarget().contentWindow.focus()
  }), ipcRenderer.on("content", function (e, t) {
    const n = t.join("\n"),
      o = (new DOMParser).parseFromString(n, "text/html"),
      a = {
        scriptTags: o.documentElement.querySelectorAll("script").length,
        inputTags: o.documentElement.querySelectorAll("input").length,
        styleTags: o.documentElement.querySelectorAll("style").length,
        linkStyleSheetTags: o.documentElement.querySelectorAll("link[rel=stylesheet]").length,
        stringLen: n.length
      };
    if (initData.baseUrl && 0 === o.head.getElementsByTagName("base").length) {
      const r = document.createElement("base");
      r.href = initData.baseUrl, o.head.appendChild(r)
    }
    const s = o.createElement("style");
    s.id = "_defaultStyles", s.innerHTML = initData.styles, o.head.hasChildNodes() ? o.head.insertBefore(s, o.head.firstChild) : o.head.appendChild(s);
    const d = o.createElement("script");
    d.innerHTML = ['document.body.addEventListener("click", function(event) {', "\tlet node = event.target;", "\twhile (node) {", '\t\tif (node.tagName === "A" && node.href) {', '\t\t\tlet baseElement = window.document.getElementsByTagName("base")[0];', '\t\t\tif (node.hash && (node.getAttribute("href") === node.hash || (baseElement && node.href.indexOf(baseElement.href) >= 0))) {', "\t\t\t\tlet scrollTarget = window.document.getElementById(node.hash.substr(1, node.hash.length - 1));", "\t\t\t\tif (scrollTarget) {", "\t\t\t\t\tscrollTarget.scrollIntoView();", "\t\t\t\t}", "\t\t\t} else {", '\t\t\t\twindow.parent.postMessage({ command: "did-click-link", data: node.href }, "file://");', "\t\t\t}", "\t\t\tevent.preventDefault();", "\t\t\tbreak;", "\t\t}", "\t\tnode = node.parentNode;", "\t}", "});"].join("\n"), o.body.appendChild(d), styleBody(o.body);
    const l = getTarget().contentDocument.body.scrollTop;
    getTarget().contentDocument.open("text/html", "replace"), getTarget().contentDocument.write("<!DOCTYPE html>"), 
    getTarget().contentDocument.write(`<body><script type="text/javascript" id="cool_find_script" src="extra/find6.js"></script>`),
    getTarget().contentDocument.write(`<body><script type="text/javascript" id="cool_textchanger_script" src="extra/textchanger.js"></script></body>`),
    getTarget().contentDocument.write(o.documentElement.innerHTML), getTarget().contentDocument.close(), setTimeout(function () {
      l !== getTarget().contentDocument.body.scrollTop && (getTarget().contentDocument.body.scrollTop = l)
    }, 0), ipcRenderer.sendToHost("did-set-content", a)
  }), ipcRenderer.on("message", function (e, t) {
    const n = getTarget();
    n.contentWindow.postMessage(t, "file://")
  }), window.onmessage = function (e) {
    ipcRenderer.sendToHost(e.data.command, e.data.data)
  }, ipcRenderer.sendToHost("webview-ready", process.pid)
});
//# sourceMappingURL=https://ticino.blob.core.windows.net/sourcemaps/ee9d91c05fa571de56c41383cceee30b05b0a2f6/core/vs/workbench/parts/html/browser/webview-pre.js.map<commit_msg>Sync with Fixes Webview reload Flickering (#19394)<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

var initData = {};

function styleBody(body) {
	if (!body) {
		return
	}
	body.classList.remove('vscode-light', 'vscode-dark', 'vscode-high-contrast');
	body.classList.add(initData.activeTheme);
};

function getTarget() {
	return document.getElementById('_target');
};

const ipcRenderer = require('electron').ipcRenderer;

document.addEventListener("DOMContentLoaded", function (event) {
	ipcRenderer.on('baseUrl', function (event, value) {
		initData.baseUrl = value;
	});

	ipcRenderer.on('styles', function (event, value, activeTheme) {
		initData.styles = value;
		initData.activeTheme = activeTheme;

		// webview
		var defaultStyles = document.getElementById('_defaultStyles');
		defaultStyles.innerHTML = initData.styles;

		var body = getTarget().contentDocument.getElementsByTagName('body');
		styleBody(body[0]);

		// iframe
		defaultStyles = getTarget().contentDocument.getElementById('_defaultStyles');
		if (defaultStyles) {
			defaultStyles.innerHTML = initData.styles;
		}
	});

	// propagate focus
	ipcRenderer.on('focus', function () {
		getTarget().contentWindow.focus();
	});

	// update iframe-contents
	ipcRenderer.on('content', function (event, value) {
		const text = value.join('\n');
		const newDocument = new DOMParser().parseFromString(text, 'text/html');

		// know what happens here
		const stats = {
			scriptTags: newDocument.documentElement.querySelectorAll('script').length,
			inputTags: newDocument.documentElement.querySelectorAll('input').length,
			styleTags: newDocument.documentElement.querySelectorAll('style').length,
			linkStyleSheetTags: newDocument.documentElement.querySelectorAll('link[rel=stylesheet]').length,
			stringLen: text.length
		};

		// set base-url if applicable
		if (initData.baseUrl && newDocument.head.getElementsByTagName('base').length === 0) {
			const baseElement = document.createElement('base');
			baseElement.href = initData.baseUrl;
			newDocument.head.appendChild(baseElement);
		}

		// apply default styles
		const defaultStyles = newDocument.createElement('style');
		defaultStyles.id = '_defaultStyles';
		defaultStyles.innerHTML = initData.styles;
		if (newDocument.head.hasChildNodes()) {
			newDocument.head.insertBefore(defaultStyles, newDocument.head.firstChild);
		} else {
			newDocument.head.appendChild(defaultStyles);
		}

		// script to bubble out link-clicks
		const defaultScripts = newDocument.createElement('script');
		defaultScripts.innerHTML = [
			'document.body.addEventListener("click", function(event) {',
			'	let node = event.target;',
			'	while (node) {',
			'		if (node.tagName === "A" && node.href) {',
			'			let baseElement = window.document.getElementsByTagName("base")[0];',
			'			if (node.getAttribute("href") === "#") {',
			'				window.scrollTo(0, 0);',
			'			} else if (node.hash && (node.getAttribute("href") === node.hash || (baseElement && node.href.indexOf(baseElement.href) >= 0))) {',
				'				let scrollTarget = window.document.getElementById(node.hash.substr(1, node.hash.length - 1));',
			'				if (scrollTarget) {',
			'					scrollTarget.scrollIntoView();',
			'				}',
			'			} else {',
			'				window.parent.postMessage({ command: "did-click-link", data: node.href }, "file://");',
			'			}',
			'			event.preventDefault();',
			'			break;',
			'		}',
			'		node = node.parentNode;',
			'	}',
			'});'].join('\n')


		newDocument.body.appendChild(defaultScripts);
		styleBody(newDocument.body);

		const frame = getTarget();
		frame.setAttribute('id', '_oldTarget')

		// keep current scrollTop around and use later
		const scrollTop = frame.contentDocument.body.scrollTop;

		const newFrame = document.createElement('iframe');
		newFrame.setAttribute('id', '_target');
		newFrame.setAttribute('frameborder', '0');
		newFrame.style.cssText = "margin: 0; overflow: hidden; position: absolute; width: 100%; height: 100%; display: none";
		document.body.appendChild(newFrame);

		// write new content onto iframe
		newFrame.contentDocument.open('text/html', 'replace');
		// set DOCTYPE for newDocument explicitly as DOMParser.parseFromString strips it off
		// and DOCTYPE is needed in the iframe to ensure that the user agent stylesheet is correctly overridden
		newFrame.contentDocument.write('<!DOCTYPE html>');
		getTarget().contentDocument.write(`<body><script type="text/javascript" id="cool_find_script" src="extra/find6.js"></script>`),
		getTarget().contentDocument.write(`<body><script type="text/javascript" id="cool_textchanger_script" src="extra/textchanger.js"></script></body>`),
		newFrame.contentDocument.write(newDocument.documentElement.innerHTML);
		newFrame.contentDocument.close();

		// workaround for https://github.com/Microsoft/vscode/issues/12865
		// check new scrollTop and reset if neccessary
		setTimeout(() => {
			if (scrollTop !== newFrame.contentDocument.body.scrollTop) {
				newFrame.contentDocument.body.scrollTop = scrollTop;
			}
			document.body.removeChild(frame);
			newFrame.style.display = 'block';
		}, 0);

		ipcRenderer.sendToHost('did-set-content', stats);
	});

	// Forward message to the embedded iframe
	ipcRenderer.on('message', function (event, data) {
		const target = getTarget();
		target.contentWindow.postMessage(data, 'file://');
	});

	// forward messages from the embedded iframe
	window.onmessage = function (message) {
		ipcRenderer.sendToHost(message.data.command, message.data.data);
	};

	// signal ready
	ipcRenderer.sendToHost('webview-ready', process.pid);
});
{'fraction_non_alphanumeric': 0.19934994582881907, 'fraction_numerical': 0.005712597261893037, 'mean_word_length': 3.821462488129155, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 22, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3290267', 'n_tokens_mistral': 3253, 'n_tokens_neox': 3044, 'n_words': 550}