<commit_before>/**
 changed methods from mootools
 - styleNumber: never return rounded value
 - getOffsets: never return rounded value
 
 license: MIT-style license.

 credits:
  - Element positioning based on the [qooxdoo](http://qooxdoo.org/) code and smart browser fixes, [LGPL License](http://www.gnu.org/licenses/lgpl.html).
  - Viewport dimensions based on [YUI](http://developer.yahoo.com/yui/) code, [BSD License](http://developer.yahoo.com/yui/license.html).
 */

KM.define(function(K, require){

// ---------- mootools.dimensions start ----------

var 

DOC = document,
HTML = DOC.documentElement,
WIN = K.__HOST,

COMPACT_ELEMENT = !DOC.compatMode || DOC.compatMode == 'CSS1Compat' ? HTML : DOC.body,

FIXED = 'fixed', STATIC = 'static', SCROLL = 'scroll',

brokenOffsetParent = function(){
	var element = document.createElement('div'),
		child = document.createElement('div'),
		ret;
	element.style.height = '0';
	element.appendChild(child);
	ret = child.offsetParent === element;
	element = child = null;
	
	return ret;
}(),

styleString = Element.getComputedStyle;


function styleNumber(element, style){
	return parseFloat( styleString(element, style) ) || 0;
};

function borderBox(element){
	return styleString(element, '-moz-box-sizing') == 'border-box';
};

function topBorder(element){
	return styleNumber(element, 'border-top-width');
};

function leftBorder(element){
	return styleNumber(element, 'border-left-width');
};

function isBody(element){
	return (/^(?:body|html)$/i).test(element.tagName);
};

function isContainer(element){
	return element === WIN || element === DOC || (/^(?:body|html)$/i).test(element.tagName);
};

function isOffset(el){
	return styleString(el, 'position') != 'static' || isBody(el);
};

function isOffsetStatic(el){
	return isOffset(el) || (/^(?:table|td|th)$/i).test(el.tagName);
};

/**
 *
 * ---------------------------------------------------------- */
 
function createMethod(filter, meta){
	var method = function(element){
		return filter(element) ? method.doc(element) : method.normal(element);
	};
	
	method.doc    = meta.doc;    delete meta.doc;
	method.normal = meta.normal; delete meta.normal;
	
	return method;
};


var getSize = createMethod(isContainer, {
	doc: function(){
		var wrap = COMPACT_ELEMENT;
		return {
			width	: wrap.clientWidth, 
			height	: wrap.clientHeight
		}
	},
	
	normal: function(element){
		return {
			width	: element.offsetWidth, 
			height	: element.offsetHeight
		};
	}
}),

getScrollSize = createMethod(isContainer, {
	doc: function(element){
		var wrap 	= COMPACT_ELEMENT,
			min  	= getSize.doc(element),
			body 	= DOC.body;

		return {
			width	: Math.max(wrap.scrollWidth,  body.scrollWidth,  min.width  ), 
			height	: Math.max(wrap.scrollHeight, body.scrollHeight, min.height )
		};
	},
	
	normal: function(element){
		return {
			width	: element.scrollWidth, 
			height	: element.scrollHeight
		};
	}
}),

getPosition = createMethod(isContainer, {
	doc: function(){
		return {
			left: 0, 
			top: 0
		};
	},
	
	normal: function(element, relative){
		var offset = getOffsets(element),
			scroll = getScrolls(element);
			position = {
				left	: offset.left - scroll.left,
				top		: offset.top  - scroll.top
			};
		
		if (relative && (relative = document.id(relative))){
			var rel_pos = getPosition(relative);
			
			position.left -= rel_pos.left - leftBorder(relative); 
			position.top  -= rel_pos.top  - topBorder(relative);
		}
		
		return position;
	}
}),

getScroll = createMethod(isContainer, {
	doc: function(){
		var win  = WIN, 
			wrap = COMPACT_ELEMENT;
		return {
			left	: win.pageXOffset || wrap.scrollLeft, 
			top		: win.pageYOffset || wrap.scrollTop
		};
	},
	
	normal: function(element){
		return {
			left	: element.scrollLeft, 
			top		: element.scrollTop
		};
	}
});


function getScrolls(element){
	var left = 0,
		top = 0;
		
	while( (element = element.parentNode) && !isBody(element) ){
		left += element.scrollLeft;
		top  += element.scrollTop;
	}
	
	return {
		left	: left,
		top		: top
	}
};


function getOffsets(element){
	var position = {left: 0, top: 0},
		is_firefox = K.UA.firefox,
		walk = element,
		parent;

	if (element.getBoundingClientRect && !K.UA.ios){
		var bound = element.getBoundingClientRect(),
			html = HTML,
			htmlScroll = styleString(element, 'position') === FIXED ? {left:0, top:0} : getScroll(html),
			elemScrolls = getScrolls(element);

		return {
			left	: bound.left + elemScrolls.left + htmlScroll.left - html.clientLeft,
			top		: bound.top  + elemScrolls.top  + htmlScroll.top  - html.clientTop
		};
	}
	
	if (!isBody(element)){
		do {
			parent = walk.parentNode;
		
			position.left += walk.offsetLeft;
			position.top  += walk.offsetTop;
	
			if (is_firefox){
				if (!borderBox(walk)){
					position.left += leftBorder(walk);
					position.top  += topBorder(walk);
				}
				
				if (parent && styleString(parent, 'overflow') != 'visible'){
					position.left += leftBorder(parent);
					position.top  += topBorder(parent);
				}
			} else if (walk !== element && K.UA.safari){
				position.left += leftBorder(walk);
				position.top  += topBorder(walk);
			}
			
		} while( (walk = parent) && !isBody(walk) );
		
		if (is_firefox && !borderBox(element)){
			position.left -= leftBorder(element);
			position.top  -= topBorder(element);
		}
	}
	
	return position;
};


// ---------- / mootools.dimensions end ----------


return {
	// no setter
	offset: getPosition,
	 
	size: function(element, type){
		return type === SCROLL ? getScrollSize(element) : getSize(element);
	},
	
	scroll: getScroll,
	
	offsetParent: brokenOffsetParent ? 
		function(element){
			var position = styleString(element, 'position'),
				parent = HTML,
				offsetCheck;
		
			if (!isBody(element) && position !== FIXED){
				offsetCheck = position === STATIC ? isOffsetStatic : isOffset;
				
				while ((element = element.parentNode)){
					if (offsetCheck(element)){
						parent = element;
						break;
					}
				}
			}
			
			return parent;
		} 
	:	
		function(element){
			var parent = HTML;
			
			if (!isBody(element) && styleString(element, 'position') !== FIXED){
				try {
					parent = element.offsetParent;
				} catch(e) {}
			}
			
			return parent;
		}	
};

});
<commit_msg>dom/dimension: migrate to Neuron<commit_after>/**
 changed methods from mootools
 - styleNumber: never return rounded value
 - getOffsets: never return rounded value
 
 license: MIT-style license.

 credits:
  - Element positioning based on the [qooxdoo](http://qooxdoo.org/) code and smart browser fixes, [LGPL License](http://www.gnu.org/licenses/lgpl.html).
  - Viewport dimensions based on [YUI](http://developer.yahoo.com/yui/) code, [BSD License](http://developer.yahoo.com/yui/license.html).
 */

KM.define(function(K, require){

// ---------- mootools.dimensions start ----------

var 

DOC = document,
HTML = DOC.documentElement,
WIN = K.__HOST,

COMPACT_ELEMENT = !DOC.compatMode || DOC.compatMode == 'CSS1Compat' ? HTML : DOC.body,

FIXED = 'fixed', STATIC = 'static', SCROLL = 'scroll',

brokenOffsetParent = function(){
	var element = document.createElement('div'),
		child = document.createElement('div'),
		ret;
	element.style.height = '0';
	element.appendChild(child);
	ret = child.offsetParent === element;
	element = child = null;
	
	return ret;
}(),

styleString = K.DOM.feature.curCSS;


function styleNumber(element, style){
	return parseFloat( styleString(element, style) ) || 0;
};

function borderBox(element){
	return styleString(element, '-moz-box-sizing') == 'border-box';
};

function topBorder(element){
	return styleNumber(element, 'border-top-width');
};

function leftBorder(element){
	return styleNumber(element, 'border-left-width');
};

function isBody(element){
	return (/^(?:body|html)$/i).test(element.tagName);
};

function isContainer(element){
	return element === WIN || element === DOC || (/^(?:body|html)$/i).test(element.tagName);
};

function isOffset(el){
	return styleString(el, 'position') != 'static' || isBody(el);
};

function isOffsetStatic(el){
	return isOffset(el) || (/^(?:table|td|th)$/i).test(el.tagName);
};

/**
 *
 * ---------------------------------------------------------- */
 
function createMethod(filter, meta){
	var method = function(element){
		return filter(element) ? method.doc(element) : method.normal(element);
	};
	
	method.doc    = meta.doc;    delete meta.doc;
	method.normal = meta.normal; delete meta.normal;
	
	return method;
};


var getSize = createMethod(isContainer, {
	doc: function(){
		var wrap = COMPACT_ELEMENT;
		return {
			width	: wrap.clientWidth, 
			height	: wrap.clientHeight
		}
	},
	
	normal: function(element){
		return {
			width	: element.offsetWidth, 
			height	: element.offsetHeight
		};
	}
}),

getScrollSize = createMethod(isContainer, {
	doc: function(element){
		var wrap 	= COMPACT_ELEMENT,
			min  	= getSize.doc(element),
			body 	= DOC.body;

		return {
			width	: Math.max(wrap.scrollWidth,  body.scrollWidth,  min.width  ), 
			height	: Math.max(wrap.scrollHeight, body.scrollHeight, min.height )
		};
	},
	
	normal: function(element){
		return {
			width	: element.scrollWidth, 
			height	: element.scrollHeight
		};
	}
}),

getPosition = createMethod(isContainer, {
	doc: function(){
		return {
			left: 0, 
			top: 0
		};
	},
	
	normal: function(element, relative){
		var offset = getOffsets(element),
			scroll = getScrolls(element);
			position = {
				left	: offset.left - scroll.left,
				top		: offset.top  - scroll.top
			};
		
		if (relative && (relative = document.id(relative))){
			var rel_pos = getPosition(relative);
			
			position.left -= rel_pos.left - leftBorder(relative); 
			position.top  -= rel_pos.top  - topBorder(relative);
		}
		
		return position;
	}
}),

getScroll = createMethod(isContainer, {
	doc: function(){
		var win  = WIN, 
			wrap = COMPACT_ELEMENT;
		return {
			left	: win.pageXOffset || wrap.scrollLeft, 
			top		: win.pageYOffset || wrap.scrollTop
		};
	},
	
	normal: function(element){
		return {
			left	: element.scrollLeft, 
			top		: element.scrollTop
		};
	}
});


function getScrolls(element){
	var left = 0,
		top = 0;
		
	while( (element = element.parentNode) && !isBody(element) ){
		left += element.scrollLeft;
		top  += element.scrollTop;
	}
	
	return {
		left	: left,
		top		: top
	}
};


function getOffsets(element){
	var position = {left: 0, top: 0},
		is_firefox = K.UA.firefox,
		walk = element,
		parent;

	if (element.getBoundingClientRect && !K.UA.ios){
		var bound = element.getBoundingClientRect(),
			html = HTML,
			htmlScroll = styleString(element, 'position') === FIXED ? {left:0, top:0} : getScroll(html),
			elemScrolls = getScrolls(element);

		return {
			left	: bound.left + elemScrolls.left + htmlScroll.left - html.clientLeft,
			top		: bound.top  + elemScrolls.top  + htmlScroll.top  - html.clientTop
		};
	}
	
	if (!isBody(element)){
		do {
			parent = walk.parentNode;
		
			position.left += walk.offsetLeft;
			position.top  += walk.offsetTop;
	
			if (is_firefox){
				if (!borderBox(walk)){
					position.left += leftBorder(walk);
					position.top  += topBorder(walk);
				}
				
				if (parent && styleString(parent, 'overflow') != 'visible'){
					position.left += leftBorder(parent);
					position.top  += topBorder(parent);
				}
			} else if (walk !== element && K.UA.safari){
				position.left += leftBorder(walk);
				position.top  += topBorder(walk);
			}
			
		} while( (walk = parent) && !isBody(walk) );
		
		if (is_firefox && !borderBox(element)){
			position.left -= leftBorder(element);
			position.top  -= topBorder(element);
		}
	}
	
	return position;
};


// ---------- / mootools.dimensions end ----------


return {
	// no setter
	offset: getPosition,
	 
	size: function(element, type){
		return type === SCROLL ? getScrollSize(element) : getSize(element);
	},
	
	scroll: getScroll,
	
	offsetParent: brokenOffsetParent ? 
		function(element){
			var position = styleString(element, 'position'),
				parent = HTML,
				offsetCheck;
		
			if (!isBody(element) && position !== FIXED){
				offsetCheck = position === STATIC ? isOffsetStatic : isOffset;
				
				while ((element = element.parentNode)){
					if (offsetCheck(element)){
						parent = element;
						break;
					}
				}
			}
			
			return parent;
		} 
	:	
		function(element){
			var parent = HTML;
			
			if (!isBody(element) && styleString(element, 'position') !== FIXED){
				try {
					parent = element.offsetParent;
				} catch(e) {}
			}
			
			return parent;
		}	
};

});

{'fraction_non_alphanumeric': 0.16521251901064596, 'fraction_numerical': 0.0017609861522452574, 'mean_word_length': 3.2223724231159174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '194669', 'n_tokens_mistral': 4733, 'n_tokens_neox': 4097, 'n_words': 865}