<commit_before>'use strict';

window.altspaceutil = window.altspaceutil || {};
altspaceutil.behaviors = altspaceutil.behaviors || {};

// Native Event Helpers
altspaceutil.addNativeEventListener = function(name, callback) {
	return (altspace.inClient && altspace._internal && altspace._internal.couiEngine) ? altspace._internal.couiEngine.on(name, callback) : null;
}

altspaceutil.removeNativeEventListener = function(name, callback) {
	if(altspace.inClient && altspace._internal && altspace._internal.couiEngine) altspace._internal.couiEngine.off(name, callback);
}

altspaceutil.removeAllNativeEventListeners = function(name) {
	if(altspace.inClient && altspace._internal && altspace._internal.couiEngine && altspace._internal.couiEngine.events[name]) delete altspace._internal.couiEngine.events[name];
}

altspaceutil.getObject3DById = function(meshId) {
	return (altspace.inClient && altspace._internal) ? altspace._internal.getObject3DById(meshId) : null;
}

altspaceutil.getThreeJSScene = function() {
	return (altspace.inClient && altspace._internal) ? altspace._internal.getThreeJSScene() : null;
}

/**
* Expands the Altspace client's serialization buffer to improve loading performance.
* @function expandSerializationBuffer
* @param {Number} [size] The size to expand the serialization buffer by, in bytes.
* @memberof module:altspaceutil
*/
altspaceutil.expandSerializationBuffer = function(size) {
	if(altspace.inClient && altspace._internal && altspace._internal.ScratchThriftBuffer && size > 0) {
		altspace._internal.ScratchThriftBuffer.grow(size);
	}
}

/**
* Enables or disables the profiler for the Altspace client's serialization buffer to determine whether the buffer needs to be expanded.  Profiler messages will be displayed in the console when enabled.
* @function profileSerializationBuffer
* @param {Boolean} [enabled] Specifies whether the serialization buffer is to be enabled.
* @memberof module:altspaceutil
*/
altspaceutil.profileSerializationBuffer = function(enabled) {
	if(altspace.inClient && altspace._internal && altspace._internal.ScratchThriftBuffer) {
		altspace._internal.ScratchThriftBuffer.profile = (enabled === undefined) ? true : enabled;
	}
}

/**
* Indicates whether the app is being loaded on a mobile version of the Altspace client.  This is typically determined by the user agent exposed to the app.
* @function isMobileApp
* @returns {Boolean} Whether the app is running on a mobile client.  Returns true for mobile clients, false otherwise.
* @memberof module:altspaceutil
*/
altspaceutil.isMobileApp = function(url) {
	return /mobile/i.test(navigator.userAgent);
}

/**
* Gets the fullspace enclosure for the app.
* @function getFullspaceEnclosure
* @returns {Promise} A promise that resolves to a fullspace Enclosure.
* @memberof module:altspaceutil
*/
altspaceutil.getFullspaceEnclosure = function() {
	let getEnclosure = altspace.inClient ? altspace.getEnclosure : () => {
		// Emulate fullspace enclosure in browser
		if(!altspaceutil._BrowserEnclosure) {
			altspaceutil._BrowserEnclosure = new class extends THREE.EventDispatcher {
				constructor() {
					super();
					this.innerWidth = 1280;
					this.innerHeight = 720;
					this.innerDepth = 1280;
					this.pixelsPerMeter = 1;
					this.hasFocus = document.hasFocus();
					this.fullspace = true;

					window.addEventListener('focus', () => this.hasFocus = document.hasFocus());
					window.addEventListener('blur', () => this.hasFocus = document.hasFocus());
				}

				requestFullspace() {
					if(!this.fullspace) {
						this.fullspace = true;
						this.dispatchEvent({ type: 'fullspacechange' });
					}
					return Promise.resolve();
				}

				exitFullspace() {
					if(this.fullspace) {
						this.fullspace = false;
						this.dispatchEvent({ type: 'fullspacechange' });
					}
					return Promise.resolve();
				}
			};
		}

		return Promise.resolve(altspaceutil._BrowserEnclosure);
	};

	return new Promise((resolve, reject) => {
		getEnclosure().then(enclosure => enclosure.requestFullspace().then(() => {
			enclosure.addEventListener('fullspacechange', () => {
				if(!enclosure.fullspace) enclosure.requestFullspace().catch(() => reject('enclosure.requestFullspace() after fullspacechange event failed'));
			});
			resolve(enclosure);
		})).catch(() => reject('Failed to get fullspace enclosure.'));
	});
}

altspaceutil.getFullspaceAppManifest = function() {
	if(altspaceutil._fullspaceAppManifest) return Promise.resolve(altspaceutil._fullspaceAppManifest);

	let query = new URLSearchParams(window.location.search);
	let applyManifestUrlParams = manifest => {
		for(let q of query.entries()) {
			if(/altvr\.enclosure\.(.*)/i.test(q[0])) {
				let propertyname = q[0].match(/altvr\.enclosure\.(.*)/i)[1];

				let anchormanifest = manifest.enclosure = Object.assign({}, manifest.enclosure);
				anchormanifest.position = Object.assign({ x: 0, y: 0, z: 0 }, anchormanifest.position);
				anchormanifest.rotation = Object.assign({ x: 0, y: 0, z: 0 }, anchormanifest.rotation);
				anchormanifest.scale = (anchormanifest.hasOwnProperty('scale') && typeof anchormanifest.scale == 'number') ? { x: anchormanifest.scale || 1, y: anchormanifeste.scale || 1, z: anchormanifest.scale || 1 } : Object.assign({ x: 1, y: 1, z: 1 }, anchormanifest.scale);

				switch(propertyname) {
					case 'position':
					case 'rotation': {
						let property = q[1].split(',');
						if(property.length >= 1) anchormanifest[propertyname].x = parseFloat(property[0]) || 0;
						if(property.length >= 2) anchormanifest[propertyname].y = parseFloat(property[1]) || 0;
						if(property.length >= 3) anchormanifest[propertyname].z = parseFloat(property[2]) || 0;
						break;
					}

					case 'scale': {
						let property = q[1].split(',');
						if(property.length === 1) {
							anchormanifest[propertyname].x = anchormanifest[propertyname].y = anchormanifest[propertyname].z = parseFloat(property[0]) || 1;
						} else {
							if(property.length >= 1) anchormanifest[propertyname].x = parseFloat(property[0]) || 1;
							if(property.length >= 2) anchormanifest[propertyname].y = parseFloat(property[1]) || 1;
							if(property.length >= 3) anchormanifest[propertyname].z = parseFloat(property[2]) || 1;
						}
						break;
					}
				}
			} else if(/altvr\.anchors\.(.*)\.(.*)/i.test(q[0])) {
				let [, anchorname, propertyname] = q[0].match(/altvr\.anchors\.(.*)\.(.*)/i);

				let anchormanifestindex = manifest.anchors.findIndex(a => { return (a.name === anchorname); });
				if(anchormanifestindex < 0) anchormanifestindex = manifest.anchors.push({ name: anchorname }) - 1;

				anchormanifest = manifest.anchors[anchormanifestindex] = Object.assign({ name: anchorname }, manifest.anchors[anchormanifestindex]);
				anchormanifest.position = Object.assign({ x: 0, y: 0, z: 0 }, anchormanifest.position);
				anchormanifest.rotation = Object.assign({ x: 0, y: 0, z: 0 }, anchormanifest.rotation);
				anchormanifest.scale = (anchormanifest.hasOwnProperty('scale') && typeof anchormanifest.scale == 'number') ? { x: anchormanifest.scale || 1, y: anchormanifeste.scale || 1, z: anchormanifest.scale || 1 } : Object.assign({ x: 1, y: 1, z: 1 }, anchormanifest.scale);<commit_msg>Corrected issue with parsing non-uniform scale property for anchor points.<commit_after>'use strict';

window.altspaceutil = window.altspaceutil || {};
altspaceutil.behaviors = altspaceutil.behaviors || {};

// Native Event Helpers
altspaceutil.addNativeEventListener = function(name, callback) {
	return (altspace.inClient && altspace._internal && altspace._internal.couiEngine) ? altspace._internal.couiEngine.on(name, callback) : null;
}

altspaceutil.removeNativeEventListener = function(name, callback) {
	if(altspace.inClient && altspace._internal && altspace._internal.couiEngine) altspace._internal.couiEngine.off(name, callback);
}

altspaceutil.removeAllNativeEventListeners = function(name) {
	if(altspace.inClient && altspace._internal && altspace._internal.couiEngine && altspace._internal.couiEngine.events[name]) delete altspace._internal.couiEngine.events[name];
}

altspaceutil.getObject3DById = function(meshId) {
	return (altspace.inClient && altspace._internal) ? altspace._internal.getObject3DById(meshId) : null;
}

altspaceutil.getThreeJSScene = function() {
	return (altspace.inClient && altspace._internal) ? altspace._internal.getThreeJSScene() : null;
}

/**
* Expands the Altspace client's serialization buffer to improve loading performance.
* @function expandSerializationBuffer
* @param {Number} [size] The size to expand the serialization buffer by, in bytes.
* @memberof module:altspaceutil
*/
altspaceutil.expandSerializationBuffer = function(size) {
	if(altspace.inClient && altspace._internal && altspace._internal.ScratchThriftBuffer && size > 0) {
		altspace._internal.ScratchThriftBuffer.grow(size);
	}
}

/**
* Enables or disables the profiler for the Altspace client's serialization buffer to determine whether the buffer needs to be expanded.  Profiler messages will be displayed in the console when enabled.
* @function profileSerializationBuffer
* @param {Boolean} [enabled] Specifies whether the serialization buffer is to be enabled.
* @memberof module:altspaceutil
*/
altspaceutil.profileSerializationBuffer = function(enabled) {
	if(altspace.inClient && altspace._internal && altspace._internal.ScratchThriftBuffer) {
		altspace._internal.ScratchThriftBuffer.profile = (enabled === undefined) ? true : enabled;
	}
}

/**
* Indicates whether the app is being loaded on a mobile version of the Altspace client.  This is typically determined by the user agent exposed to the app.
* @function isMobileApp
* @returns {Boolean} Whether the app is running on a mobile client.  Returns true for mobile clients, false otherwise.
* @memberof module:altspaceutil
*/
altspaceutil.isMobileApp = function(url) {
	return /mobile/i.test(navigator.userAgent);
}

/**
* Gets the fullspace enclosure for the app.
* @function getFullspaceEnclosure
* @returns {Promise} A promise that resolves to a fullspace Enclosure.
* @memberof module:altspaceutil
*/
altspaceutil.getFullspaceEnclosure = function() {
	let getEnclosure = altspace.inClient ? altspace.getEnclosure : () => {
		// Emulate fullspace enclosure in browser
		if(!altspaceutil._BrowserEnclosure) {
			altspaceutil._BrowserEnclosure = new class extends THREE.EventDispatcher {
				constructor() {
					super();
					this.innerWidth = 1280;
					this.innerHeight = 720;
					this.innerDepth = 1280;
					this.pixelsPerMeter = 1;
					this.hasFocus = document.hasFocus();
					this.fullspace = true;

					window.addEventListener('focus', () => this.hasFocus = document.hasFocus());
					window.addEventListener('blur', () => this.hasFocus = document.hasFocus());
				}

				requestFullspace() {
					if(!this.fullspace) {
						this.fullspace = true;
						this.dispatchEvent({ type: 'fullspacechange' });
					}
					return Promise.resolve();
				}

				exitFullspace() {
					if(this.fullspace) {
						this.fullspace = false;
						this.dispatchEvent({ type: 'fullspacechange' });
					}
					return Promise.resolve();
				}
			};
		}

		return Promise.resolve(altspaceutil._BrowserEnclosure);
	};

	return new Promise((resolve, reject) => {
		getEnclosure().then(enclosure => enclosure.requestFullspace().then(() => {
			enclosure.addEventListener('fullspacechange', () => {
				if(!enclosure.fullspace) enclosure.requestFullspace().catch(() => reject('enclosure.requestFullspace() after fullspacechange event failed'));
			});
			resolve(enclosure);
		})).catch(() => reject('Failed to get fullspace enclosure.'));
	});
}

altspaceutil.getFullspaceAppManifest = function() {
	if(altspaceutil._fullspaceAppManifest) return Promise.resolve(altspaceutil._fullspaceAppManifest);

	let query = new URLSearchParams(window.location.search);
	let applyManifestUrlParams = manifest => {
		for(let q of query.entries()) {
			if(/altvr\.enclosure\.(.*)/i.test(q[0])) {
				let propertyname = q[0].match(/altvr\.enclosure\.(.*)/i)[1];

				let anchormanifest = manifest.enclosure = Object.assign({}, manifest.enclosure);
				anchormanifest.position = Object.assign({ x: 0, y: 0, z: 0 }, anchormanifest.position);
				anchormanifest.rotation = Object.assign({ x: 0, y: 0, z: 0 }, anchormanifest.rotation);
				anchormanifest.scale = (anchormanifest.hasOwnProperty('scale') && typeof anchormanifest.scale == 'number') ? { x: anchormanifest.scale || 1, y: anchormanifest.scale || 1, z: anchormanifest.scale || 1 } : Object.assign({ x: 1, y: 1, z: 1 }, anchormanifest.scale);

				switch(propertyname) {
					case 'position':
					case 'rotation': {
						let property = q[1].split(',');
						if(property.length >= 1) anchormanifest[propertyname].x = parseFloat(property[0]) || 0;
						if(property.length >= 2) anchormanifest[propertyname].y = parseFloat(property[1]) || 0;
						if(property.length >= 3) anchormanifest[propertyname].z = parseFloat(property[2]) || 0;
						break;
					}

					case 'scale': {
						let property = q[1].split(',');
						if(property.length === 1) {
							anchormanifest[propertyname].x = anchormanifest[propertyname].y = anchormanifest[propertyname].z = parseFloat(property[0]) || 1;
						} else {
							if(property.length >= 1) anchormanifest[propertyname].x = parseFloat(property[0]) || 1;
							if(property.length >= 2) anchormanifest[propertyname].y = parseFloat(property[1]) || 1;
							if(property.length >= 3) anchormanifest[propertyname].z = parseFloat(property[2]) || 1;
						}
						break;
					}
				}
			} else if(/altvr\.anchors\.(.*)\.(.*)/i.test(q[0])) {
				let [, anchorname, propertyname] = q[0].match(/altvr\.anchors\.(.*)\.(.*)/i);

				let anchormanifestindex = manifest.anchors.findIndex(a => { return (a.name === anchorname); });
				if(anchormanifestindex < 0) anchormanifestindex = manifest.anchors.push({ name: anchorname }) - 1;

				anchormanifest = manifest.anchors[anchormanifestindex] = Object.assign({ name: anchorname }, manifest.anchors[anchormanifestindex]);
				anchormanifest.position = Object.assign({ x: 0, y: 0, z: 0 }, anchormanifest.position);
				anchormanifest.rotation = Object.assign({ x: 0, y: 0, z: 0 }, anchormanifest.rotation);
				anchormanifest.scale = (anchormanifest.hasOwnProperty('scale') && typeof anchormanifest.scale == 'number') ? { x: anchormanifest.scale || 1, y: anchormanifest.scale || 1, z: anchormanifest.scale || 1 } : Object.assign({ x: 1, y: 1, z: 1 }, anchormanifest.scale);
{'fraction_non_alphanumeric': 0.1399239543726236, 'fraction_numerical': 0.009540269616315244, 'mean_word_length': 4.504566210045662, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '5578334', 'n_tokens_mistral': 5047, 'n_tokens_neox': 4316, 'n_words': 958}