Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@babylonjs/gui

Package Overview
Dependencies
Maintainers
1
Versions
544
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babylonjs/gui - npm Package Compare versions

Comparing version 4.1.0-alpha.19 to 4.1.0-alpha.20

13

2D/controls/image.d.ts

@@ -36,2 +36,6 @@ import { Nullable } from "@babylonjs/core/types";

/**
* Observable notified when _sourceLeft, _sourceTop, _sourceWidth and _sourceHeight are computed
*/
onSVGAttributesComputedObservable: Observable<Image>;
/**
* Gets a boolean indicating that the content is loaded

@@ -99,2 +103,11 @@ */

/**
* Checks for svg document with icon id present
*/
private _svgCheck;
/**
* Sets sourceLeft, sourceTop, sourceWidth, sourceHeight automatically
* given external svg file and icon id
*/
private _getSVGAttribs;
/**
* Gets or sets the cell width to use when animation sheet is enabled

@@ -101,0 +114,0 @@ * @see http://doc.babylonjs.com/how_to/gui#image

@@ -34,2 +34,6 @@ import * as tslib_1 from "tslib";

_this.onImageLoadedObservable = new Observable();
/**
* Observable notified when _sourceLeft, _sourceTop, _sourceWidth and _sourceHeight are computed
*/
_this.onSVGAttributesComputedObservable = new Observable();
_this.source = url;

@@ -343,2 +347,5 @@ return _this;

this._source = value;
if (value) {
this._svgCheck(value);
}
this._domImage = document.createElement("img");

@@ -356,2 +363,78 @@ this._domImage.onload = function () {

});
/**
* Checks for svg document with icon id present
*/
Image.prototype._svgCheck = function (value) {
var _this = this;
if ((value.search(/.svg#/gi) !== -1) && (value.indexOf("#") === value.lastIndexOf("#"))) {
var svgsrc = value.split('#')[0];
var elemid = value.split('#')[1];
// check if object alr exist in document
var svgExist = document.body.querySelector('object[data="' + svgsrc + '"]');
if (svgExist) {
if (svgExist.contentDocument) {
// svg object alr exists
this._getSVGAttribs(svgExist, elemid);
}
else {
// wait for object to load
svgExist.addEventListener("load", function () {
_this._getSVGAttribs(svgExist, elemid);
});
}
}
else {
// create document object
var svgImage = document.createElement("object");
svgImage.data = svgsrc;
svgImage.type = "image/svg+xml";
svgImage.width = "0%";
svgImage.height = "0%";
document.body.appendChild(svgImage);
// when the object has loaded, get the element attribs
svgImage.onload = function () {
var svgobj = document.body.querySelector('object[data="' + svgsrc + '"]');
if (svgobj) {
_this._getSVGAttribs(svgobj, elemid);
}
};
}
}
};
/**
* Sets sourceLeft, sourceTop, sourceWidth, sourceHeight automatically
* given external svg file and icon id
*/
Image.prototype._getSVGAttribs = function (svgsrc, elemid) {
var svgDoc = svgsrc.contentDocument;
// get viewbox width and height, get svg document width and height in px
if (svgDoc && svgDoc.documentElement) {
var vb = svgDoc.documentElement.getAttribute("viewBox");
var docwidth = Number(svgDoc.documentElement.getAttribute("width"));
var docheight = Number(svgDoc.documentElement.getAttribute("height"));
// get element bbox and matrix transform
var elem = svgDoc.getElementById(elemid);
if (elem instanceof SVGElement && vb && docwidth && docheight) {
var vb_width = Number(vb.split(" ")[2]);
var vb_height = Number(vb.split(" ")[3]);
var elem_bbox = elem.getBBox();
var elem_matrix_a = 1;
var elem_matrix_d = 1;
var elem_matrix_e = 0;
var elem_matrix_f = 0;
if (elem.transform && elem.transform.baseVal.consolidate()) {
elem_matrix_a = elem.transform.baseVal.consolidate().matrix.a;
elem_matrix_d = elem.transform.baseVal.consolidate().matrix.d;
elem_matrix_e = elem.transform.baseVal.consolidate().matrix.e;
elem_matrix_f = elem.transform.baseVal.consolidate().matrix.f;
}
// compute source coordinates and dimensions
this.sourceLeft = ((elem_matrix_a * elem_bbox.x + elem_matrix_e) * docwidth) / vb_width;
this.sourceTop = ((elem_matrix_d * elem_bbox.y + elem_matrix_f) * docheight) / vb_height;
this.sourceWidth = (elem_bbox.width * elem_matrix_a) * (docwidth / vb_width);
this.sourceHeight = (elem_bbox.height * elem_matrix_d) * (docheight / vb_height);
this.onSVGAttributesComputedObservable.notifyObservers(this);
}
}
};
Object.defineProperty(Image.prototype, "cellWidth", {

@@ -584,2 +667,3 @@ /**

this.onImageLoadedObservable.clear();
this.onSVGAttributesComputedObservable.clear();
};

@@ -586,0 +670,0 @@ Image._WorkingCanvas = null;

4

package.json

@@ -7,3 +7,3 @@ {

"description": "The Babylon.js GUI library is an extension you can use to generate interactive user interface. It is build on top of the DynamicTexture.",
"version": "4.1.0-alpha.19",
"version": "4.1.0-alpha.20",
"repository": {

@@ -198,3 +198,3 @@ "type": "git",

"dependencies": {
"@babylonjs/core": "4.1.0-alpha.19",
"@babylonjs/core": "4.1.0-alpha.20",
"tslib": "^1.9.3"

@@ -201,0 +201,0 @@ },

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc