1 define([ 'util/ensureCallback', 'features', 'sprites/renderers/DomContext', 'util/create', 'sprites/container' ], function (ensureCallback, features, DomContext, create, container) {
2 var CSSMatrix = features.CSSMatrix;
4 function RenderContext(sourceData, frameData) {
9 this.loadPromise = quickPromise();
10 DomContext.call(this, sourceData, frameData, this.loadPromise.resolve);
12 this.elements.forEach(function (frameElements) {
13 frameElements.forEach(function (element) {
14 element.style[features.transformOriginStyleProperty] = '0 0';
18 this.transformData = frameData.map(function (objectTransforms) {
19 return objectTransforms.map(function (t) {
20 var m = new CSSMatrix();
31 this.containerElement = container();
34 RenderContext.prototype = create(DomContext.prototype);
36 RenderContext.prototype.load = function load(callback) {
37 callback = ensureCallback(callback);
40 callback(new Error('Not supported'));
44 document.body.appendChild(this.containerElement);
46 this.loadPromise.then(function () {
51 RenderContext.prototype.unload = function unload() {
52 this.containerElement.parentNode.removeChild(this.containerElement);
53 DomContext.prototype.unload.call(this);
56 var transformStyleProperty = features.transformStyleProperty;
58 RenderContext.prototype.processElements = function processElements(elements, transforms) {
59 var count = transforms.length;
61 for (i = 0; i < count; ++i) {
62 var element = elements[i];
63 element.style[transformStyleProperty] = transforms[i];
66 // Elements not in the DOM need to be added
67 if (!element.parentNode) {
68 this.containerElement.appendChild(element);
73 return function (element, frameData) {
74 return new RenderContext(element, frameData);