@esotericsoftware/spine-webgl 4.0.11 → 4.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/AssetManager.d.ts +33 -33
  2. package/dist/AssetManager.js +37 -37
  3. package/dist/Camera.d.ts +49 -49
  4. package/dist/Camera.js +80 -80
  5. package/dist/CameraController.d.ts +34 -0
  6. package/dist/CameraController.js +96 -0
  7. package/dist/GLTexture.d.ts +46 -46
  8. package/dist/GLTexture.js +102 -102
  9. package/dist/Input.d.ts +56 -54
  10. package/dist/Input.js +211 -214
  11. package/dist/LoadingScreen.d.ts +43 -43
  12. package/dist/LoadingScreen.js +114 -114
  13. package/dist/Matrix4.d.ts +68 -68
  14. package/dist/Matrix4.js +321 -321
  15. package/dist/Mesh.d.ts +88 -88
  16. package/dist/Mesh.js +193 -193
  17. package/dist/PolygonBatcher.d.ts +53 -53
  18. package/dist/PolygonBatcher.js +121 -119
  19. package/dist/SceneRenderer.d.ts +73 -73
  20. package/dist/SceneRenderer.js +476 -476
  21. package/dist/Shader.d.ts +75 -75
  22. package/dist/Shader.js +262 -262
  23. package/dist/ShapeRenderer.d.ts +69 -69
  24. package/dist/ShapeRenderer.js +338 -338
  25. package/dist/SkeletonDebugRenderer.d.ts +60 -60
  26. package/dist/SkeletonDebugRenderer.js +222 -222
  27. package/dist/SkeletonRenderer.d.ts +49 -49
  28. package/dist/SkeletonRenderer.js +295 -295
  29. package/dist/SpineCanvas.d.ts +73 -73
  30. package/dist/SpineCanvas.js +82 -82
  31. package/dist/Vector3.d.ts +47 -47
  32. package/dist/Vector3.js +103 -103
  33. package/dist/WebGL.d.ts +44 -43
  34. package/dist/WebGL.js +96 -96
  35. package/dist/iife/spine-webgl.js +195 -112
  36. package/dist/iife/spine-webgl.js.map +3 -3
  37. package/dist/iife/spine-webgl.min.js +26 -26
  38. package/dist/index.d.ts +18 -17
  39. package/dist/index.js +19 -18
  40. package/package.json +34 -34
@@ -26,6 +26,7 @@ var spine = (() => {
26
26
  BoneData: () => BoneData,
27
27
  BoundingBoxAttachment: () => BoundingBoxAttachment,
28
28
  CURRENT: () => CURRENT,
29
+ CameraController: () => CameraController,
29
30
  ClippingAttachment: () => ClippingAttachment,
30
31
  Color: () => Color,
31
32
  Color2Attribute: () => Color2Attribute,
@@ -4291,14 +4292,14 @@ var spine = (() => {
4291
4292
  return dataUri.substr(dataUri.indexOf(",") + 1);
4292
4293
  }
4293
4294
  }
4294
- base64ToArrayBuffer(base64) {
4295
+ base64ToUint8Array(base64) {
4295
4296
  var binary_string = window.atob(base64);
4296
4297
  var len = binary_string.length;
4297
4298
  var bytes = new Uint8Array(len);
4298
4299
  for (var i = 0; i < len; i++) {
4299
4300
  bytes[i] = binary_string.charCodeAt(i);
4300
4301
  }
4301
- return bytes.buffer;
4302
+ return bytes;
4302
4303
  }
4303
4304
  dataUriToUint8Array(dataUri) {
4304
4305
  if (!dataUri.startsWith("data:")) {
@@ -4308,7 +4309,7 @@ var spine = (() => {
4308
4309
  if (base64Idx == -1)
4309
4310
  throw new Error("Not a binary data URI.");
4310
4311
  base64Idx += "base64,".length;
4311
- return this.base64ToArrayBuffer(dataUri.substr(base64Idx));
4312
+ return this.base64ToUint8Array(dataUri.substr(base64Idx));
4312
4313
  }
4313
4314
  downloadText(url, success, error) {
4314
4315
  if (this.start(url, success, error))
@@ -9254,14 +9255,13 @@ var spine = (() => {
9254
9255
  // spine-webgl/src/Input.ts
9255
9256
  var Input = class {
9256
9257
  constructor(element) {
9257
- this.lastX = 0;
9258
- this.lastY = 0;
9258
+ this.mouseX = 0;
9259
+ this.mouseY = 0;
9259
9260
  this.buttonDown = false;
9260
- this.currTouch = null;
9261
+ this.touch0 = null;
9262
+ this.touch1 = null;
9263
+ this.initialPinchDistance = 0;
9261
9264
  this.listeners = new Array();
9262
- this.touchesPool = new Pool(() => {
9263
- return new Touch(0, 0, 0);
9264
- });
9265
9265
  this.element = element;
9266
9266
  this.setupCallbacks(element);
9267
9267
  }
@@ -9269,15 +9269,14 @@ var spine = (() => {
9269
9269
  let mouseDown = (ev) => {
9270
9270
  if (ev instanceof MouseEvent) {
9271
9271
  let rect = element.getBoundingClientRect();
9272
- let x = ev.clientX - rect.left;
9273
- let y = ev.clientY - rect.top;
9274
- let listeners = this.listeners;
9275
- for (let i = 0; i < listeners.length; i++)
9276
- if (listeners[i].down)
9277
- listeners[i].down(x, y);
9278
- this.lastX = x;
9279
- this.lastY = y;
9272
+ this.mouseX = ev.clientX - rect.left;
9273
+ ;
9274
+ this.mouseY = ev.clientY - rect.top;
9280
9275
  this.buttonDown = true;
9276
+ this.listeners.map((listener) => {
9277
+ if (listener.down)
9278
+ listener.down(this.mouseX, this.mouseY);
9279
+ });
9281
9280
  document.addEventListener("mousemove", mouseMove);
9282
9281
  document.addEventListener("mouseup", mouseUp);
9283
9282
  }
@@ -9285,138 +9284,154 @@ var spine = (() => {
9285
9284
  let mouseMove = (ev) => {
9286
9285
  if (ev instanceof MouseEvent) {
9287
9286
  let rect = element.getBoundingClientRect();
9288
- let x = ev.clientX - rect.left;
9289
- let y = ev.clientY - rect.top;
9290
- let listeners = this.listeners;
9291
- for (let i = 0; i < listeners.length; i++) {
9287
+ this.mouseX = ev.clientX - rect.left;
9288
+ ;
9289
+ this.mouseY = ev.clientY - rect.top;
9290
+ this.listeners.map((listener) => {
9292
9291
  if (this.buttonDown) {
9293
- if (listeners[i].dragged)
9294
- listeners[i].dragged(x, y);
9292
+ if (listener.dragged)
9293
+ listener.dragged(this.mouseX, this.mouseY);
9295
9294
  } else {
9296
- if (listeners[i].moved)
9297
- listeners[i].moved(x, y);
9295
+ if (listener.moved)
9296
+ listener.moved(this.mouseX, this.mouseY);
9298
9297
  }
9299
- }
9300
- this.lastX = x;
9301
- this.lastY = y;
9298
+ });
9302
9299
  }
9303
9300
  };
9304
9301
  let mouseUp = (ev) => {
9305
9302
  if (ev instanceof MouseEvent) {
9306
9303
  let rect = element.getBoundingClientRect();
9307
- let x = ev.clientX - rect.left;
9308
- let y = ev.clientY - rect.top;
9309
- let listeners = this.listeners;
9310
- for (let i = 0; i < listeners.length; i++)
9311
- if (listeners[i].up)
9312
- listeners[i].up(x, y);
9313
- this.lastX = x;
9314
- this.lastY = y;
9304
+ this.mouseX = ev.clientX - rect.left;
9305
+ ;
9306
+ this.mouseY = ev.clientY - rect.top;
9315
9307
  this.buttonDown = false;
9308
+ this.listeners.map((listener) => {
9309
+ if (listener.up)
9310
+ listener.up(this.mouseX, this.mouseY);
9311
+ });
9316
9312
  document.removeEventListener("mousemove", mouseMove);
9317
9313
  document.removeEventListener("mouseup", mouseUp);
9318
9314
  }
9319
9315
  };
9316
+ let mouseWheel = (e) => {
9317
+ e.preventDefault();
9318
+ let deltaY = e.deltaY;
9319
+ if (e.deltaMode == WheelEvent.DOM_DELTA_LINE)
9320
+ deltaY *= 8;
9321
+ if (e.deltaMode == WheelEvent.DOM_DELTA_PAGE)
9322
+ deltaY *= 24;
9323
+ this.listeners.map((listener) => {
9324
+ if (listener.wheel)
9325
+ listener.wheel(e.deltaY);
9326
+ });
9327
+ };
9320
9328
  element.addEventListener("mousedown", mouseDown, true);
9321
9329
  element.addEventListener("mousemove", mouseMove, true);
9322
9330
  element.addEventListener("mouseup", mouseUp, true);
9331
+ element.addEventListener("wheel", mouseWheel, true);
9323
9332
  element.addEventListener("touchstart", (ev) => {
9324
- if (!this.currTouch) {
9333
+ if (!this.touch0 || !this.touch1) {
9325
9334
  var touches = ev.changedTouches;
9326
- for (var i = 0; i < touches.length; i++) {
9327
- var touch = touches[i];
9328
- let rect = element.getBoundingClientRect();
9329
- let x = touch.clientX - rect.left;
9330
- let y = touch.clientY - rect.top;
9331
- this.currTouch = this.touchesPool.obtain();
9332
- this.currTouch.identifier = touch.identifier;
9333
- this.currTouch.x = x;
9334
- this.currTouch.y = y;
9335
- break;
9336
- }
9337
- let listeners = this.listeners;
9338
- for (let i2 = 0; i2 < listeners.length; i2++) {
9339
- if (listeners[i2].down)
9340
- listeners[i2].down(this.currTouch.x, this.currTouch.y);
9341
- }
9342
- this.lastX = this.currTouch.x;
9343
- this.lastY = this.currTouch.y;
9335
+ let nativeTouch = touches.item(0);
9336
+ let rect = element.getBoundingClientRect();
9337
+ let x = nativeTouch.clientX - rect.left;
9338
+ let y = nativeTouch.clientY - rect.top;
9339
+ let touch = new Touch(nativeTouch.identifier, x, y);
9340
+ this.mouseX = x;
9341
+ this.mouseY = y;
9344
9342
  this.buttonDown = true;
9345
- }
9346
- ev.preventDefault();
9347
- }, false);
9348
- element.addEventListener("touchend", (ev) => {
9349
- if (this.currTouch) {
9350
- var touches = ev.changedTouches;
9351
- for (var i = 0; i < touches.length; i++) {
9352
- var touch = touches[i];
9353
- if (this.currTouch.identifier === touch.identifier) {
9354
- let rect = element.getBoundingClientRect();
9355
- let x = this.currTouch.x = touch.clientX - rect.left;
9356
- let y = this.currTouch.y = touch.clientY - rect.top;
9357
- this.touchesPool.free(this.currTouch);
9358
- let listeners = this.listeners;
9359
- for (let i2 = 0; i2 < listeners.length; i2++) {
9360
- if (listeners[i2].up)
9361
- listeners[i2].up(x, y);
9362
- }
9363
- this.lastX = x;
9364
- this.lastY = y;
9365
- this.buttonDown = false;
9366
- this.currTouch = null;
9367
- break;
9368
- }
9343
+ if (!this.touch0) {
9344
+ this.touch0 = touch;
9345
+ this.listeners.map((listener) => {
9346
+ if (listener.down)
9347
+ listener.down(touch.x, touch.y);
9348
+ });
9349
+ } else if (!this.touch1) {
9350
+ this.touch1 = touch;
9351
+ let dx = this.touch1.x - this.touch0.x;
9352
+ let dy = this.touch1.x - this.touch0.x;
9353
+ this.initialPinchDistance = Math.sqrt(dx * dx + dy * dy);
9354
+ this.listeners.map((listener) => {
9355
+ if (listener.zoom)
9356
+ listener.zoom(this.initialPinchDistance, this.initialPinchDistance);
9357
+ });
9369
9358
  }
9370
9359
  }
9371
9360
  ev.preventDefault();
9372
9361
  }, false);
9373
- element.addEventListener("touchcancel", (ev) => {
9374
- if (this.currTouch) {
9362
+ element.addEventListener("touchmove", (ev) => {
9363
+ if (this.touch0) {
9375
9364
  var touches = ev.changedTouches;
9365
+ let rect = element.getBoundingClientRect();
9376
9366
  for (var i = 0; i < touches.length; i++) {
9377
- var touch = touches[i];
9378
- if (this.currTouch.identifier === touch.identifier) {
9379
- let rect = element.getBoundingClientRect();
9380
- let x = this.currTouch.x = touch.clientX - rect.left;
9381
- let y = this.currTouch.y = touch.clientY - rect.top;
9382
- this.touchesPool.free(this.currTouch);
9383
- let listeners = this.listeners;
9384
- for (let i2 = 0; i2 < listeners.length; i2++) {
9385
- if (listeners[i2].up)
9386
- listeners[i2].up(x, y);
9387
- }
9388
- this.lastX = x;
9389
- this.lastY = y;
9390
- this.buttonDown = false;
9391
- this.currTouch = null;
9392
- break;
9367
+ var nativeTouch = touches[i];
9368
+ let x = nativeTouch.clientX - rect.left;
9369
+ let y = nativeTouch.clientY - rect.top;
9370
+ if (this.touch0.identifier === nativeTouch.identifier) {
9371
+ this.touch0.x = this.mouseX = x;
9372
+ this.touch0.y = this.mouseY = y;
9373
+ this.listeners.map((listener) => {
9374
+ if (listener.dragged)
9375
+ listener.dragged(x, y);
9376
+ });
9377
+ }
9378
+ if (this.touch1 && this.touch1.identifier === nativeTouch.identifier) {
9379
+ this.touch1.x = this.mouseX = x;
9380
+ this.touch1.y = this.mouseY = y;
9393
9381
  }
9394
9382
  }
9383
+ if (this.touch0 && this.touch1) {
9384
+ let dx = this.touch1.x - this.touch0.x;
9385
+ let dy = this.touch1.x - this.touch0.x;
9386
+ let distance = Math.sqrt(dx * dx + dy * dy);
9387
+ this.listeners.map((listener) => {
9388
+ if (listener.zoom)
9389
+ listener.zoom(this.initialPinchDistance, distance);
9390
+ });
9391
+ }
9395
9392
  }
9396
9393
  ev.preventDefault();
9397
9394
  }, false);
9398
- element.addEventListener("touchmove", (ev) => {
9399
- if (this.currTouch) {
9395
+ let touchEnd = (ev) => {
9396
+ if (this.touch0) {
9400
9397
  var touches = ev.changedTouches;
9398
+ let rect = element.getBoundingClientRect();
9401
9399
  for (var i = 0; i < touches.length; i++) {
9402
- var touch = touches[i];
9403
- if (this.currTouch.identifier === touch.identifier) {
9404
- let rect = element.getBoundingClientRect();
9405
- let x = touch.clientX - rect.left;
9406
- let y = touch.clientY - rect.top;
9407
- let listeners = this.listeners;
9408
- for (let i2 = 0; i2 < listeners.length; i2++) {
9409
- if (listeners[i2].dragged)
9410
- listeners[i2].dragged(x, y);
9400
+ var nativeTouch = touches[i];
9401
+ let x = nativeTouch.clientX - rect.left;
9402
+ let y = nativeTouch.clientY - rect.top;
9403
+ if (this.touch0.identifier === nativeTouch.identifier) {
9404
+ this.touch0 = null;
9405
+ this.mouseX = x;
9406
+ this.mouseY = y;
9407
+ this.listeners.map((listener) => {
9408
+ if (listener.up)
9409
+ listener.up(x, y);
9410
+ });
9411
+ if (!this.touch1) {
9412
+ this.buttonDown = false;
9413
+ break;
9414
+ } else {
9415
+ this.touch0 = this.touch1;
9416
+ this.touch1 = null;
9417
+ this.mouseX = this.touch0.x;
9418
+ this.mouseX = this.touch0.x;
9419
+ this.buttonDown = true;
9420
+ this.listeners.map((listener) => {
9421
+ if (listener.down)
9422
+ listener.down(this.touch0.x, this.touch0.y);
9423
+ });
9411
9424
  }
9412
- this.lastX = this.currTouch.x = x;
9413
- this.lastY = this.currTouch.y = y;
9414
- break;
9425
+ }
9426
+ if (this.touch1 && this.touch1.identifier) {
9427
+ this.touch1 = null;
9415
9428
  }
9416
9429
  }
9417
9430
  }
9418
9431
  ev.preventDefault();
9419
- }, false);
9432
+ };
9433
+ element.addEventListener("touchend", touchEnd, false);
9434
+ element.addEventListener("touchcancel", touchEnd);
9420
9435
  }
9421
9436
  addListener(listener) {
9422
9437
  this.listeners.push(listener);
@@ -9436,6 +9451,72 @@ var spine = (() => {
9436
9451
  }
9437
9452
  };
9438
9453
 
9454
+ // spine-webgl/src/CameraController.ts
9455
+ var CameraController = class {
9456
+ constructor(canvas, camera) {
9457
+ this.canvas = canvas;
9458
+ this.camera = camera;
9459
+ let cameraX = 0, cameraY = 0, cameraZoom = 0;
9460
+ let mouseX = 0, mouseY = 0;
9461
+ let lastX = 0, lastY = 0;
9462
+ let initialZoom = 0;
9463
+ new Input(canvas).addListener({
9464
+ down: (x, y) => {
9465
+ cameraX = camera.position.x;
9466
+ cameraY = camera.position.y;
9467
+ mouseX = lastX = x;
9468
+ mouseY = lastY = y;
9469
+ initialZoom = camera.zoom;
9470
+ },
9471
+ dragged: (x, y) => {
9472
+ let deltaX = x - mouseX;
9473
+ let deltaY = y - mouseY;
9474
+ let originWorld = camera.screenToWorld(new Vector3(0, 0), canvas.clientWidth, canvas.clientHeight);
9475
+ let deltaWorld = camera.screenToWorld(new Vector3(deltaX, deltaY), canvas.clientWidth, canvas.clientHeight).sub(originWorld);
9476
+ camera.position.set(cameraX - deltaWorld.x, cameraY - deltaWorld.y, 0);
9477
+ camera.update();
9478
+ lastX = x;
9479
+ lastY = y;
9480
+ },
9481
+ wheel: (delta) => {
9482
+ let zoomAmount = delta / 200 * camera.zoom;
9483
+ let newZoom = camera.zoom + zoomAmount;
9484
+ if (newZoom > 0) {
9485
+ let x = 0, y = 0;
9486
+ if (delta < 0) {
9487
+ x = lastX;
9488
+ y = lastY;
9489
+ } else {
9490
+ let viewCenter = new Vector3(canvas.clientWidth / 2 + 15, canvas.clientHeight / 2);
9491
+ let mouseToCenterX = lastX - viewCenter.x;
9492
+ let mouseToCenterY = canvas.clientHeight - 1 - lastY - viewCenter.y;
9493
+ x = viewCenter.x - mouseToCenterX;
9494
+ y = canvas.clientHeight - 1 - viewCenter.y + mouseToCenterY;
9495
+ }
9496
+ let oldDistance = camera.screenToWorld(new Vector3(x, y), canvas.clientWidth, canvas.clientHeight);
9497
+ camera.zoom = newZoom;
9498
+ camera.update();
9499
+ let newDistance = camera.screenToWorld(new Vector3(x, y), canvas.clientWidth, canvas.clientHeight);
9500
+ camera.position.add(oldDistance.sub(newDistance));
9501
+ camera.update();
9502
+ }
9503
+ },
9504
+ zoom: (initialDistance, distance) => {
9505
+ let newZoom = initialDistance / distance;
9506
+ camera.zoom = initialZoom * newZoom;
9507
+ },
9508
+ up: (x, y) => {
9509
+ lastX = x;
9510
+ lastY = y;
9511
+ },
9512
+ moved: (x, y) => {
9513
+ lastX = x;
9514
+ lastY = y;
9515
+ }
9516
+ });
9517
+ }
9518
+ };
9519
+
9439
9520
  // spine-webgl/src/Shader.ts
9440
9521
  var _Shader = class {
9441
9522
  constructor(context, vertexShader, fragmentShader) {
@@ -9888,6 +9969,8 @@ var spine = (() => {
9888
9969
  gl.blendFuncSeparate(this.srcColorBlend, this.dstBlend, this.srcAlphaBlend, this.dstBlend);
9889
9970
  }
9890
9971
  setBlendMode(srcColorBlend, srcAlphaBlend, dstBlend) {
9972
+ if (this.srcColorBlend == srcColorBlend && this.srcAlphaBlend == srcAlphaBlend && this.dstBlend == dstBlend)
9973
+ return;
9891
9974
  this.srcColorBlend = srcColorBlend;
9892
9975
  this.srcAlphaBlend = srcAlphaBlend;
9893
9976
  this.dstBlend = dstBlend;