<commit_before>import Core from "Bao/Core"

class View
{
	orientation: string;
	initialised: boolean;
	element: HTMLElement;
	nofocus: boolean;
	obtype = "view";

	constructor()
	{
		this.element = null;
		this.initialised = false;
		this.orientation = "none";
		this.$bind();
	}

	$createElement(type)
	{
		if (this.initialised === true) throw new Error("Already attached");
		this.element = document.createElement(type);
		if (this.element["stitched"]) throw new Error("DOM element already attached");
		this.$_stitch();
		this.$createContent();
		return (this.element as any);
	}

	$getElementById(id)
	{
		if (this.initialised === true) throw new Error("Already attached");
		this.element = document.getElementById(id);
		if (!this.element) throw new Error("Cannot find element with id " + id);
		if (this.element["stitched"]) throw new Error("DOM element already attached");
		this.$_stitch();
		this.$createContent();
		return (this.element as any);
	}

	$assignElement(obj)
	{
		if (this.initialised === true) throw new Error("Already attached");
		this.element = obj;
		if (!this.element) throw new Error("Object is null");
		if (this.element["stitched"]) throw new Error("DOM element already attached");
		this.$_stitch();
		this.$createContent();
		return (this.element as any);
	}

	$createContent()
	{
	}

	$appendChild(child)
	{
		this.element.appendChild(child);
	}

	$setId(id)
	{
		if (!this.initialised) throw new Error("Not initialised");
		this.element.setAttribute("id", id);
	}

	$position(x, y, w, h)
	{
		if (!this.initialised) throw new Error("Not initialised");
		this.$move(x, y);
		this.$resize(w, h);
	}

	$move(x, y)
	{
		if (!this.initialised) throw new Error("Not initialised");
		if (x !== false) this.element.style.left = x;
		if (y !== false) this.element.style.top = y;
	}

	$resize(w, h)
	{
		if (!this.initialised) throw new Error("Not initialised");
		if (w !== false) this.element.style.width = w;
		if (h !== false) this.element.style.height = h;
	}

	$focus()
	{
		var f = Core().Focus;
		var n:any = this.element.firstChild;
		while (n) {
			if (n["stitched"]) {
				if (n.$focus && n.$focus()) {
					f.$set(n);
					return true;
				}
			}
			n = n.nextSibling;
		}

		if (this.element.getAttribute("data-focus") !== "nofocus") {
			if (!this.$hasClass("focused")) {
				this.$addClass("focused");
				this.$signal("focus");
			}
			return true;
		}
		return false;
	}

	$blur()
	{
		if (this.$hasClass("focused")) {
			this.$removeClass("focused");
			this.$signal("blur");
		}
	}

	$addClass(cls)
	{
		if (!this.initialised) throw new Error("Not initialised");
		if (this.$hasClass(cls)) return;
		let clss = (this.element.getAttribute("class") || "").split(" ");
		clss.push(cls);
		this.element.setAttribute("class", clss.join(" "));
		return this;
	}

	$hasClass(cls)
	{
		if (!this.initialised) throw new Error("Not initialised");
		let clss = (this.element.getAttribute("class") || "").split(" ");
		return (clss.indexOf(cls) > -1);
	}

	$removeClass(cls)
	{
		if (!this.initialised) throw new Error("Not initialised");
		if (this.$hasClass(cls)) {
			let clss = (this.element.getAttribute("class") || "").split(" ");
			let n = [];
			for (let i = 0; i < clss.length; i++) {
				if (cls != clss[i]) n.push(clss[i]);
			}
			this.element.setAttribute("class", n.join(" "));
		}
	}

	$signal(type, data?)
	{
		if (!this.initialised) throw new Error("Not initialised");
		if (this.element) {
			let ev = document.createEvent("Event");
			if (ev) {
				ev.initEvent(type, true, true);
				ev["sender"] = this.element;
				ev["signalData"] = data;
				this.element.dispatchEvent(ev);
			}
		}
	}

	$bind()
	{
		for (let member in this) {
			if ("function" === typeof this[member]) {
				this[member] = (this[member] as any).bind(this);
			}
		}
	}

	$_stitch()
	{
		let exclude = this.$exclusions();
		for (let member in this) {
			if ("function" === typeof this[member]) {
				if (exclude.indexOf(member) > -1) continue;
				if (exclude.indexOf(member.substr(1)) > -1) continue;
				try {
					(this.element as any)[member] = this[member];
				} catch (e) {}
			}
		}
		/*
		for (let member in this.element) {
			if ("function" == typeof (this.element as any)[member]) {
				if (member.indexOf("$") === 0) continue;
				if (exclude.indexOf(member) > -1) continue;
				if ((this.element as any)["$"+member]) continue;
				(this.element as any)["$" + member] = (this.element as any)[member];
			}
		}
		*/

		this.element["stitched"] = true;<commit_msg>don't stitch functions starting with _ and remove some commented out code<commit_after>import Core from "Bao/Core"

class View
{
	orientation: string;
	initialised: boolean;
	element: HTMLElement;
	nofocus: boolean;
	obtype = "view";

	constructor()
	{
		this.element = null;
		this.initialised = false;
		this.orientation = "none";
		this.$bind();
	}

	$createElement(type)
	{
		if (this.initialised === true) throw new Error("Already attached");
		this.element = document.createElement(type);
		if (this.element["stitched"]) throw new Error("DOM element already attached");
		this.$_stitch();
		this.$createContent();
		return (this.element as any);
	}

	$getElementById(id)
	{
		if (this.initialised === true) throw new Error("Already attached");
		this.element = document.getElementById(id);
		if (!this.element) throw new Error("Cannot find element with id " + id);
		if (this.element["stitched"]) throw new Error("DOM element already attached");
		this.$_stitch();
		this.$createContent();
		return (this.element as any);
	}

	$assignElement(obj)
	{
		if (this.initialised === true) throw new Error("Already attached");
		this.element = obj;
		if (!this.element) throw new Error("Object is null");
		if (this.element["stitched"]) throw new Error("DOM element already attached");
		this.$_stitch();
		this.$createContent();
		return (this.element as any);
	}

	$createContent()
	{
	}

	$appendChild(child)
	{
		this.element.appendChild(child);
	}

	$setId(id)
	{
		if (!this.initialised) throw new Error("Not initialised");
		this.element.setAttribute("id", id);
	}

	$position(x, y, w, h)
	{
		if (!this.initialised) throw new Error("Not initialised");
		this.$move(x, y);
		this.$resize(w, h);
	}

	$move(x, y)
	{
		if (!this.initialised) throw new Error("Not initialised");
		if (x !== false) this.element.style.left = x;
		if (y !== false) this.element.style.top = y;
	}

	$resize(w, h)
	{
		if (!this.initialised) throw new Error("Not initialised");
		if (w !== false) this.element.style.width = w;
		if (h !== false) this.element.style.height = h;
	}

	$focus()
	{
		var f = Core().Focus;
		var n:any = this.element.firstChild;
		while (n) {
			if (n["stitched"]) {
				if (n.$focus && n.$focus()) {
					f.$set(n);
					return true;
				}
			}
			n = n.nextSibling;
		}

		if (this.element.getAttribute("data-focus") !== "nofocus") {
			if (!this.$hasClass("focused")) {
				this.$addClass("focused");
				this.$signal("focus");
			}
			return true;
		}
		return false;
	}

	$blur()
	{
		if (this.$hasClass("focused")) {
			this.$removeClass("focused");
			this.$signal("blur");
		}
	}

	$addClass(cls)
	{
		if (!this.initialised) throw new Error("Not initialised");
		if (this.$hasClass(cls)) return;
		let clss = (this.element.getAttribute("class") || "").split(" ");
		clss.push(cls);
		this.element.setAttribute("class", clss.join(" "));
		return this;
	}

	$hasClass(cls)
	{
		if (!this.initialised) throw new Error("Not initialised");
		let clss = (this.element.getAttribute("class") || "").split(" ");
		return (clss.indexOf(cls) > -1);
	}

	$removeClass(cls)
	{
		if (!this.initialised) throw new Error("Not initialised");
		if (this.$hasClass(cls)) {
			let clss = (this.element.getAttribute("class") || "").split(" ");
			let n = [];
			for (let i = 0; i < clss.length; i++) {
				if (cls != clss[i]) n.push(clss[i]);
			}
			this.element.setAttribute("class", n.join(" "));
		}
	}

	$signal(type, data?)
	{
		if (!this.initialised) throw new Error("Not initialised");
		if (this.element) {
			let ev = document.createEvent("Event");
			if (ev) {
				ev.initEvent(type, true, true);
				ev["sender"] = this.element;
				ev["signalData"] = data;
				this.element.dispatchEvent(ev);
			}
		}
	}

	$bind()
	{
		for (let member in this) {
			if ("function" === typeof this[member]) {
				this[member] = (this[member] as any).bind(this);
			}
		}
	}

	$_stitch()
	{
		let exclude = this.$exclusions();
		for (let member in this) {
			if ("function" === typeof this[member]) {
				if (exclude.indexOf(member) > -1) continue;
				if (exclude.indexOf(member.substr(1)) > -1) continue;
				if (member.indexOf("_") === 0) continue;
				try {
					(this.element as any)[member] = this[member];
				} catch (e) {}
			}
		}

		this.element["stitched"] = true;
{'fraction_non_alphanumeric': 0.18911828447587545, 'fraction_numerical': 0.0014828333523440173, 'mean_word_length': 3.58098223615465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, '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': '7336579', 'n_tokens_mistral': 3479, 'n_tokens_neox': 3081, 'n_words': 720}