@@ -3572,15 +3572,35 @@ var spine;
35723572 path = this.pathPrefix + path;
35733573 if (!this.queueAsset(clientId, textureLoader, path))
35743574 return;
3575- var img = new Image();
3576- img.crossOrigin = "anonymous";
3577- img.onload = function (ev) {
3578- _this.rawAssets[path] = img;
3579- };
3580- img.onerror = function (ev) {
3581- _this.errors[path] = "Couldn't load image " + path;
3582- };
3583- img.src = path;
3575+ var isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document);
3576+ var isWebWorker = !isBrowser && typeof importScripts !== 'undefined';
3577+ if (isWebWorker) {
3578+ var options = { mode: "cors" };
3579+ fetch(path, options).then(function (response) {
3580+ if (!response.ok) {
3581+ _this.errors[path] = "Couldn't load image " + path;
3582+ }
3583+ return response.blob();
3584+ }).then(function (blob) {
3585+ return createImageBitmap(blob, {
3586+ premultiplyAlpha: 'none',
3587+ colorSpaceConversion: 'none'
3588+ });
3589+ }).then(function (bitmap) {
3590+ _this.rawAssets[path] = bitmap;
3591+ });
3592+ }
3593+ else {
3594+ var img_1 = new Image();
3595+ img_1.crossOrigin = "anonymous";
3596+ img_1.onload = function (ev) {
3597+ _this.rawAssets[path] = img_1;
3598+ };
3599+ img_1.onerror = function (ev) {
3600+ _this.errors[path] = "Couldn't load image " + path;
3601+ };
3602+ img_1.src = path;
3603+ }
35843604 };
35853605 SharedAssetManager.prototype.get = function (clientId, path) {
35863606 path = this.pathPrefix + path;
@@ -3590,18 +3610,30 @@ var spine;
35903610 return clientAssets.assets[path];
35913611 };
35923612 SharedAssetManager.prototype.updateClientAssets = function (clientAssets) {
3613+ var isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document);
3614+ var isWebWorker = !isBrowser && typeof importScripts !== 'undefined';
35933615 for (var i = 0; i < clientAssets.toLoad.length; i++) {
35943616 var path = clientAssets.toLoad[i];
35953617 var asset = clientAssets.assets[path];
35963618 if (asset === null || asset === undefined) {
35973619 var rawAsset = this.rawAssets[path];
35983620 if (rawAsset === null || rawAsset === undefined)
35993621 continue;
3600- if (rawAsset instanceof HTMLImageElement) {
3601- clientAssets.assets[path] = clientAssets.textureLoader(rawAsset);
3622+ if (isWebWorker) {
3623+ if (rawAsset instanceof ImageBitmap) {
3624+ clientAssets.assets[path] = clientAssets.textureLoader(rawAsset);
3625+ }
3626+ else {
3627+ clientAssets.assets[path] = rawAsset;
3628+ }
36023629 }
36033630 else {
3604- clientAssets.assets[path] = rawAsset;
3631+ if (rawAsset instanceof HTMLImageElement) {
3632+ clientAssets.assets[path] = clientAssets.textureLoader(rawAsset);
3633+ }
3634+ else {
3635+ clientAssets.assets[path] = rawAsset;
3636+ }
36053637 }
36063638 }
36073639 }
@@ -7749,7 +7781,7 @@ var spine;
77497781 return _this;
77507782 }
77517783 BoundingBoxAttachment.prototype.copy = function () {
7752- var copy = new BoundingBoxAttachment(name);
7784+ var copy = new BoundingBoxAttachment(this. name);
77537785 this.copyTo(copy);
77547786 copy.color.setFromColor(this.color);
77557787 return copy;
@@ -7768,7 +7800,7 @@ var spine;
77687800 return _this;
77697801 }
77707802 ClippingAttachment.prototype.copy = function () {
7771- var copy = new ClippingAttachment(name);
7803+ var copy = new ClippingAttachment(this. name);
77727804 this.copyTo(copy);
77737805 copy.endSlot = this.endSlot;
77747806 copy.color.setFromColor(this.color);
@@ -7912,7 +7944,7 @@ var spine;
79127944 return _this;
79137945 }
79147946 PathAttachment.prototype.copy = function () {
7915- var copy = new PathAttachment(name);
7947+ var copy = new PathAttachment(this. name);
79167948 this.copyTo(copy);
79177949 copy.lengths = new Array(this.lengths.length);
79187950 spine.Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length);
@@ -7946,7 +7978,7 @@ var spine;
79467978 return Math.atan2(y, x) * spine.MathUtils.radDeg;
79477979 };
79487980 PointAttachment.prototype.copy = function () {
7949- var copy = new PointAttachment(name);
7981+ var copy = new PointAttachment(this. name);
79507982 copy.x = this.x;
79517983 copy.y = this.y;
79527984 copy.rotation = this.rotation;
@@ -10706,30 +10738,32 @@ var spine;
1070610738 (function (webgl) {
1070710739 var ManagedWebGLRenderingContext = (function () {
1070810740 function ManagedWebGLRenderingContext(canvasOrContext, contextConfig) {
10709- var _this = this;
1071010741 if (contextConfig === void 0) { contextConfig = { alpha: "true" }; }
1071110742 this.restorables = new Array();
10712- if (canvasOrContext instanceof HTMLCanvasElement) {
10713- var canvas_1 = canvasOrContext;
10714- this.gl = (canvas_1.getContext("webgl2", contextConfig) || canvas_1.getContext("webgl", contextConfig));
10715- this.canvas = canvas_1;
10716- canvas_1.addEventListener("webglcontextlost", function (e) {
10717- var event = e;
10718- if (e) {
10719- e.preventDefault();
10720- }
10721- });
10722- canvas_1.addEventListener("webglcontextrestored", function (e) {
10723- for (var i = 0, n = _this.restorables.length; i < n; i++) {
10724- _this.restorables[i].restore();
10725- }
10726- });
10743+ if (canvasOrContext instanceof HTMLCanvasElement || canvasOrContext instanceof EventTarget) {
10744+ this.setupCanvas(canvasOrContext, contextConfig);
1072710745 }
1072810746 else {
1072910747 this.gl = canvasOrContext;
1073010748 this.canvas = this.gl.canvas;
1073110749 }
1073210750 }
10751+ ManagedWebGLRenderingContext.prototype.setupCanvas = function (canvas, contextConfig) {
10752+ var _this = this;
10753+ this.gl = (canvas.getContext("webgl2", contextConfig) || canvas.getContext("webgl", contextConfig));
10754+ this.canvas = canvas;
10755+ canvas.addEventListener("webglcontextlost", function (e) {
10756+ var event = e;
10757+ if (e) {
10758+ e.preventDefault();
10759+ }
10760+ });
10761+ canvas.addEventListener("webglcontextrestored", function (e) {
10762+ for (var i = 0, n = _this.restorables.length; i < n; i++) {
10763+ _this.restorables[i].restore();
10764+ }
10765+ });
10766+ };
1073310767 ManagedWebGLRenderingContext.prototype.addRestorable = function (restorable) {
1073410768 this.restorables.push(restorable);
1073510769 };
0 commit comments