@@ -2041,7 +2041,7 @@ b.AnimCache[o.url]=g,o.spine=g,o.spineAtlas=d,o.spineAtlasLoader=n,a.loadingCoun
20412041 document.querySelector(selector).removeAttribute(attributeName);
20422042 var clonedWindow = container.contentWindow;
20432043 var node = clonedWindow.document.querySelector(selector);
2044- node.style.opacity === "0" && node.tagName === "HTML-GL " ? node.style.opacity = 1 : null;
2044+ node.style.opacity === "0" && node.getAttribute('renderer') === "webgl " ? node.style.opacity = 1 : null;
20452045 var oncloneHandler = (typeof(options.onclone) === "function") ? Promise.resolve(options.onclone(clonedWindow.document)) : Promise.resolve(true);
20462046 return oncloneHandler.then(function() {
20472047 return renderWindow(node, container, options, windowWidth, windowHeight);
@@ -3460,6 +3460,17 @@ b.AnimCache[o.url]=g,o.spine=g,o.spineAtlas=d,o.spineAtlasLoader=n,a.loadingCoun
34603460 blh = borderRadius[3][0],
34613461 blv = borderRadius[3][1];
34623462
3463+ var halfHeight = Math.floor(height / 2);
3464+
3465+ tlh = tlh > halfHeight ? halfHeight : tlh;
3466+ tlv = tlv > halfHeight ? halfHeight : tlv;
3467+ trh = trh > halfHeight ? halfHeight : trh;
3468+ trv = trv > halfHeight ? halfHeight : trv;
3469+ brh = brh > halfHeight ? halfHeight : brh;
3470+ brv = brv > halfHeight ? halfHeight : brv;
3471+ blh = blh > halfHeight ? halfHeight : blh;
3472+ blv = blv > halfHeight ? halfHeight : blv;
3473+
34633474 var topWidth = width - trh,
34643475 rightHeight = height - brv,
34653476 bottomWidth = width - brh,
@@ -3892,10 +3903,10 @@ b.AnimCache[o.url]=g,o.spine=g,o.spineAtlas=d,o.spineAtlasLoader=n,a.loadingCoun
38923903 imageContainer,
38933904 0,
38943905 0,
3895- imageContainer.image.width || width,
3896- imageContainer.image.height || height,
3897- bounds.left + paddingLeft + borders[3].width,
3898- bounds.top + paddingTop + borders[0].width,
3906+ Math.round( imageContainer.image.width || width) ,
3907+ Math.round( imageContainer.image.height || height) ,
3908+ Math.round( bounds.left + paddingLeft + borders[3].width) ,
3909+ Math.round( bounds.top + paddingTop + borders[0].width) ,
38993910 width,
39003911 height
39013912 );
@@ -8513,11 +8524,12 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
85138524 * */
85148525
85158526(function (w) {
8516-
85178527 //Defining global namespace with respect if exists
85188528 HTMLGL = w.HTMLGL = w.HTMLGL || {};
85198529
85208530 //Defining it`s properties
8531+ HTMLGL.JQ_PLUGIN_NAME = 'htmlgl';
8532+ HTMLGL.CUSTOM_ELEMENT_TAG_NAME = 'html-gl';
85218533 HTMLGL.context = undefined;
85228534 HTMLGL.stage = undefined;
85238535 HTMLGL.renderer = undefined;
@@ -8721,20 +8733,21 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
87218733* */
87228734
87238735(function (w) {
8724- var style = document.createElement('style');
8725- style.innerHTML = 'html-gl { display: inline-block; transform: translateZ(0);}';
8726- document.getElementsByTagName('head')[0].appendChild(style);
8736+ var p = Object.create(HTMLElement.prototype),
8737+ style = document.createElement('style');
87278738
8728- var CUSTOM_ELEMENT_TAG_NAME = 'html-gl',
8729- p = Object.create(HTMLElement.prototype);
8739+ //Default styling for html-gl elements
8740+ style.innerHTML = HTMLGL.CUSTOM_ELEMENT_TAG_NAME + ' { display: inline-block; transform: translateZ(0);}';
8741+ document.head.appendChild(style);
87308742
87318743 p.createdCallback = function () {
87328744 //Checking is node created inside of html2canvas virtual window or not. We do not need WebGL there
87338745 var isInsideHtml2Canvas = this.baseURI.length === 0;
87348746
87358747 if (!isInsideHtml2Canvas) {
8736- w.HTMLGL.elements.push(this);
8737- //Needed to determine is element WebGL rendered or not
8748+ HTMLGL.elements.push(this);
8749+ //Needed to determine is element WebGL rendered or not relying on tag name
8750+ this.setAttribute('renderer', 'webgl');
87388751 this.renderer = 'webgl';
87398752 this.transformObject = {};
87408753 this.boundingRect = {};
@@ -8787,7 +8800,7 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
87878800 this.updatePivot();
87888801 this.updateSpriteTransform();
87898802
8790- w. HTMLGL.context.markStageAsChanged();
8803+ HTMLGL.context.markStageAsChanged();
87918804 }
87928805
87938806 //Just updates WebGL representation coordinates and transformation
@@ -8808,7 +8821,7 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
88088821 this.sprite.rotation = rotate;
88098822 }
88108823
8811- w. HTMLGL.context.markStageAsChanged();
8824+ HTMLGL.context.markStageAsChanged();
88128825 }
88138826
88148827 //Getting bounding rect with respect to current scroll position
@@ -8821,8 +8834,9 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
88218834 width: this.getBoundingClientRect().width,
88228835 height: this.getBoundingClientRect().height,
88238836 };
8824- this.boundingRect.left = w.HTMLGL.scrollX + parseFloat(this.boundingRect.left);
8825- this.boundingRect.top = w.HTMLGL.scrollY + parseFloat(this.boundingRect.top);
8837+
8838+ this.boundingRect.left = HTMLGL.scrollX + parseFloat(this.boundingRect.left);
8839+ this.boundingRect.top = HTMLGL.scrollY + parseFloat(this.boundingRect.top);
88268840 }
88278841
88288842 //Correct pivot needed to rotate element around it`s center
@@ -8837,7 +8851,7 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
88378851 var self = this;
88388852 //this.sprite = new PIXI.Sprite(texture);
88398853 this.sprite.setTexture(texture);
8840- w. HTMLGL.document.addChild(this.sprite);
8854+ HTMLGL.document.addChild(this.sprite);
88418855 setTimeout(function () {
88428856 self.hideDOM();
88438857 }, 0);
@@ -8870,7 +8884,7 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
88708884 var self = this;
88718885 self.styleGL = {};
88728886
8873- w. HTMLGL.util.getterSetter(this.styleGL, this.transformProperty, function () {
8887+ HTMLGL.util.getterSetter(this.styleGL, this.transformProperty, function () {
88748888 var result = '';
88758889
88768890 for (var transformPropertyName in self.transformObject) {
@@ -8909,7 +8923,35 @@ will produce an inaccurate conversion value. The same issue exists with the cx/c
89098923 return this.sprite.stage;
89108924 }
89118925
8912- w. HTMLGL.GLElement = document.registerElement(CUSTOM_ELEMENT_TAG_NAME, {
8926+ HTMLGL.GLElement = document.registerElement(HTMLGL. CUSTOM_ELEMENT_TAG_NAME, {
89138927 prototype: p
8914- });
8928+ })
8929+
8930+ HTMLGL.GLElement.createFromNode = function (node) {
8931+ //Extending node with GLElement methods
8932+ for (var i in p) {
8933+ if (p.hasOwnProperty(i)) {
8934+ node[i] = p[i];
8935+ }
8936+ }
8937+
8938+ p.createdCallback.apply(node);
8939+ return node;
8940+ }
8941+
8942+ //Wrap to jQuery plugin
8943+ if (w.$ !== undefined) {
8944+ $[HTMLGL.JQ_PLUGIN_NAME] = {};
8945+ $[HTMLGL.JQ_PLUGIN_NAME].elements = [];
8946+
8947+ $.fn[HTMLGL.JQ_PLUGIN_NAME] = function () {
8948+ return this.each(function () {
8949+ if (!$.data(this, 'plugin_' + HTMLGL.JQ_PLUGIN_NAME)) {
8950+ var propellerObj = HTMLGL.GLElement.createFromNode(this);
8951+ $.data(this, 'plugin_' + HTMLGL.JQ_PLUGIN_NAME, propellerObj);
8952+ $[HTMLGL.JQ_PLUGIN_NAME].elements.push(propellerObj);
8953+ }
8954+ });
8955+ };
8956+ }
89158957})(window);
0 commit comments