<commit_before>#set up global object
root = exports ? this
		
obscura = (img,target=null) ->

	###
	internal variables
	###
	fileRegExp = /\.((jp(e)?g)|(png)|(gif))$/i
	@onLoad = =>
		return true
		
	###
	Set up local variables with image data from source
	###
	@setUpImageData = =>
		@dimensions = 
				w:@image.width
				h:@image.height
		@imageDimensions = @dimensions
		@canvas.width = @canvas.height = if @dimensions.w>@dimensions.h then @dimensions.w*2 else @dimensions.h*2
		
		#initial load of image
		@load(0,0,@image.width,@image.height,@image.width,@image.height,@image);
		
	###
	load image
	###
	@load =(x=0,y=0,w=@image.width,h=@image.height,cw,ch,image)=>
		@context.globalCompositeOperation = "copy";
		image = image ? @canvas
		@context.drawImage(image,0,0,@imageDimensions.w,@imageDimensions.h,x,y,w,h)
		@imageDimensions = {w,h}
		@render()
		return @
	
	###
	render edited image to target
	###
	@render = =>
		@target.width = @dimensions.w
		@target.height = @dimensions.h
		@target.getContext('2d').drawImage(@canvas,0,0)
		return @
	
	###
	Convert image to base64 encoded string for saving to server
	###
	@save = => 
		return @target.toDataURL()
		
	###
	resizes an image
	###	
	@resize = (scale,keepProportions=true,crop=false) =>
		@context.save()
		#check type of scale and convert it to an object if not already
		if Object.prototype.toString.call(scale) is '[object Array]'
			scale = 
				w: scale[0]
				h:scale[1]
		else if typeof scale isnt 'object'
			scale = 
				w:scale
				h:scale
				
		#convert percentages to actual values
		scale.w = if typeof scale.w is 'string' and scale.w.match(/%/) then @dimensions.w * (parseFloat(scale.w)/100) else parseFloat(scale.w) 
		scale.h = if typeof scale.h is 'string' and scale.h.match(/%/) then @dimensions.h * (parseFloat(scale.h)/100) else parseFloat(scale.h)
		
		currentDimensions = @dimensions
		@dimensions = scale
		
		newScale = scale
		#if keepProportions force stop image distorting
		if keepProportions
			if scale.w > scale.h or (scale.w is scale.h and currentDimensions.w > currentDimensions.h)
				newScale.w = scale.w
				newScale.h = (scale.w/currentDimensions.w)*currentDimensions.h
			else if scale.h>scale.w or (scale.h is scale.w and currentDimensions.h > currentDimensions.w)
				newScale.w = (scale.h/currentDimensions.h)*currentDimensions.w
				newScale.h = scale.h
				
			@dimensions = newScale unless crop
				
		
		
		@load(0,0,newScale.w,newScale.h)
		@context.restore()
		return @
	
	###
	Crops an image
	###
	@crop = (x,y,w,h) =>
		@context.save()
		size = @dimensions
		@dimensions = {w,h}
		@context.drawImage(@canvas,x,y,w,h,0,0,w,h)
		@imageDimensions = {w,h}
		@render()
		@context.restore()
		return @
		
	###
	Resizes an image to fit completely into a given space
	###
	@fit = (w,h) =>
		return @ if w>@canvas.width and h>@canvas.height<commit_msg>Remove whitespace<commit_after>#set up global object
root = exports ? this
		
obscura = (img,target=null) ->

	###
	internal variables
	###
	fileRegExp = /\.((jp(e)?g)|(png)|(gif))$/i
	@onLoad = =>
		return true
		
	###
	Set up local variables with image data from source
	###
	@setUpImageData = =>
		@dimensions = 
				w:@image.width
				h:@image.height
		@imageDimensions = @dimensions
		@canvas.width = @canvas.height = if @dimensions.w>@dimensions.h then @dimensions.w*2 else @dimensions.h*2
		
		#initial load of image
		@load(0,0,@image.width,@image.height,@image.width,@image.height,@image);
		
	###
	load image
	###
	@load =(x=0,y=0,w=@image.width,h=@image.height,cw,ch,image)=>
		@context.globalCompositeOperation = "copy";
		image = image ? @canvas
		@context.drawImage(image,0,0,@imageDimensions.w,@imageDimensions.h,x,y,w,h)
		@imageDimensions = {w,h}
		@render()
		return @
	
	###
	render edited image to target
	###
	@render = =>
		@target.width = @dimensions.w
		@target.height = @dimensions.h
		@target.getContext('2d').drawImage(@canvas,0,0)
		return @
	
	###
	Convert image to base64 encoded string for saving to server
	###
	@save = => 
		return @target.toDataURL()
		
	###
	resizes an image
	###	
	@resize = (scale,keepProportions=true,crop=false) =>
		@context.save()
		#check type of scale and convert it to an object if not already
		if Object.prototype.toString.call(scale) is '[object Array]'
			scale = 
				w: scale[0]
				h:scale[1]
		else if typeof scale isnt 'object'
			scale = 
				w:scale
				h:scale
				
		#convert percentages to actual values
		scale.w = if typeof scale.w is 'string' and scale.w.match(/%/) then @dimensions.w * (parseFloat(scale.w)/100) else parseFloat(scale.w) 
		scale.h = if typeof scale.h is 'string' and scale.h.match(/%/) then @dimensions.h * (parseFloat(scale.h)/100) else parseFloat(scale.h)
		
		currentDimensions = @dimensions
		@dimensions = scale
		
		newScale = scale
		#if keepProportions force stop image distorting
		if keepProportions
			if scale.w > scale.h or (scale.w is scale.h and currentDimensions.w > currentDimensions.h)
				newScale.w = scale.w
				newScale.h = (scale.w/currentDimensions.w)*currentDimensions.h
			else if scale.h>scale.w or (scale.h is scale.w and currentDimensions.h > currentDimensions.w)
				newScale.w = (scale.h/currentDimensions.h)*currentDimensions.w
				newScale.h = scale.h
				
			@dimensions = newScale unless crop
						
		@load(0,0,newScale.w,newScale.h)
		@context.restore()
		return @
	
	###
	Crops an image
	###
	@crop = (x,y,w,h) =>
		@context.save()
		size = @dimensions
		@dimensions = {w,h}
		@context.drawImage(@canvas,x,y,w,h,0,0,w,h)
		@imageDimensions = {w,h}
		@render()
		@context.restore()
		return @
		
	###
	Resizes an image to fit completely into a given space
	###
	@fit = (w,h) =>
		return @ if w>@canvas.width and h>@canvas.height
{'fraction_non_alphanumeric': 0.15204473960153791, 'fraction_numerical': 0.008738203425375743, 'mean_word_length': 3.6377633711507293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '2612327', 'n_tokens_mistral': 2357, 'n_tokens_neox': 2091, 'n_words': 466}