// Class: openfl._internal.renderer.dom.DOMRenderer

var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this

$global.Object.defineProperty(exports, "__esModule", {value: true});

var __map_reserved = {};

// Imports

var $hxClasses = require("./../../../../hxClasses_stub").default;
var $import = require("./../../../../import_stub").default;
var $extend = require("./../../../../extend_stub").default;
function openfl__$internal_renderer_AbstractRenderer() {return require("./../../../../openfl/_internal/renderer/AbstractRenderer");}
function openfl__$internal_renderer_RenderSession() {return require("./../../../../openfl/_internal/renderer/RenderSession");}
function openfl_display_DisplayObject() {return require("./../../../../openfl/display/DisplayObject");}
function Reflect() {return require("./../../../../Reflect");}
function openfl__$internal_renderer_canvas_CanvasRenderer() {return require("./../../../../openfl/_internal/renderer/canvas/CanvasRenderer");}
function openfl__$internal_renderer_dom_DOMMaskManager() {return require("./../../../../openfl/_internal/renderer/dom/DOMMaskManager");}
function openfl__$internal_renderer_dom_DOMBlendModeManager() {return require("./../../../../openfl/_internal/renderer/dom/DOMBlendModeManager");}
function lime_graphics_RendererType() {return require("./../../../../lime/graphics/RendererType");}

// Constructor

var DOMRenderer = function(stage,element) {
	(openfl__$internal_renderer_AbstractRenderer().default).call(this,stage);
	this.element = element;
	this.renderSession = new (openfl__$internal_renderer_RenderSession().default)();
	this.renderSession.clearRenderDirty = true;
	this.renderSession.element = element;
	(openfl_display_DisplayObject().default).__supportDOM = true;
	var config = stage.window.config;
	if(config != null && (Reflect().default).hasField(config,"allowHighDPI") && config.allowHighDPI) {
		(openfl__$internal_renderer_canvas_CanvasRenderer().default).scale = window.devicePixelRatio || 1;
	}
	var prefix = (function () {
		  var styles = window.getComputedStyle(document.documentElement, ''),
			pre = (Array.prototype.slice
			  .call(styles)
			  .join('') 
			  .match(/-(moz|webkit|ms)-/) || (styles.OLink === '' && ['', 'o'])
			)[1],
			dom = ('WebKit|Moz|MS|O').match(new RegExp('(' + pre + ')', 'i'))[1];
		  return {
			dom: dom,
			lowercase: pre,
			css: '-' + pre + '-',
			js: pre[0].toUpperCase() + pre.substr(1)
		  };
		})();
	this.renderSession.vendorPrefix = prefix.lowercase;
	this.renderSession.transformProperty = prefix.lowercase == "webkit" ? "-webkit-transform" : "transform";
	this.renderSession.transformOriginProperty = prefix.lowercase == "webkit" ? "-webkit-transform-origin" : "transform-origin";
	this.renderSession.maskManager = new (openfl__$internal_renderer_dom_DOMMaskManager().default)(this.renderSession);
	this.renderSession.blendModeManager = new (openfl__$internal_renderer_dom_DOMBlendModeManager().default)(this.renderSession);
	this.renderSession.renderer = this;
	this.renderSession.renderType = (lime_graphics_RendererType().default).DOM;
}

// Meta

DOMRenderer.__name__ = ["openfl","_internal","renderer","dom","DOMRenderer"];
DOMRenderer.__super__ = (openfl__$internal_renderer_AbstractRenderer().default);
DOMRenderer.prototype = $extend((openfl__$internal_renderer_AbstractRenderer().default).prototype, {
	render: function() {
		this.renderSession.allowSmoothing = this.stage.quality != "low";
		if(!this.stage.__transparent) {
			this.element.style.background = this.stage.__colorString;
		} else {
			this.element.style.background = "none";
		}
		this.renderSession.z = 1;
		this.stage.__renderDOM(this.renderSession);
	},
	renderStage3D: function() {
		var _g = 0;
		var _g1 = this.stage.stage3Ds;
		while(_g < _g1.get_length()) {
			var stage3D = _g1.get(_g);
			++_g;
			stage3D.__renderDOM(this.stage,this.renderSession);
		}
	}
});
DOMRenderer.prototype.__class__ = $hxClasses["openfl._internal.renderer.dom.DOMRenderer"] = DOMRenderer;

// Init



// Statics

DOMRenderer.applyStyle = function(displayObject,renderSession,setTransform,setAlpha,setClip) {
	var style = displayObject.__style;
	if(setTransform && displayObject.__renderTransformChanged) {
		style.setProperty(renderSession.transformProperty,displayObject.__renderTransform.to3DString(renderSession.roundPixels),null);
	}
	if(displayObject.__worldZ != ++renderSession.z) {
		displayObject.__worldZ = renderSession.z;
		style.setProperty("z-index",displayObject.__worldZ == null ? "null" : "" + displayObject.__worldZ,null);
	}
	if(setAlpha && displayObject.__worldAlphaChanged) {
		if(displayObject.__worldAlpha < 1) {
			style.setProperty("opacity",displayObject.__worldAlpha == null ? "null" : "" + displayObject.__worldAlpha,null);
		} else {
			style.removeProperty("opacity");
		}
	}
	if(setClip && displayObject.__worldClipChanged) {
		if(displayObject.__worldClip == null) {
			style.removeProperty("clip");
		} else {
			var clip = displayObject.__worldClip;
			style.setProperty("clip","rect(" + clip.y + "px, " + clip.get_right() + "px, " + clip.get_bottom() + "px, " + clip.x + "px)",null);
		}
	}
}
DOMRenderer.initializeElement = function(displayObject,element,renderSession) {
	var style = displayObject.__style = element.style;
	style.setProperty("position","absolute",null);
	style.setProperty("top","0",null);
	style.setProperty("left","0",null);
	style.setProperty(renderSession.transformOriginProperty,"0 0 0",null);
	renderSession.element.appendChild(element);
	displayObject.__worldAlphaChanged = true;
	displayObject.__renderTransformChanged = true;
	displayObject.__worldVisibleChanged = true;
	displayObject.__worldClipChanged = true;
	displayObject.__worldClip = null;
	displayObject.__worldZ = -1;
}
DOMRenderer.updateClip = function(displayObject,renderSession) {
	var maskManager = renderSession.maskManager;
	maskManager.updateClip(displayObject);
}


// Export

exports.default = DOMRenderer;