@esotericsoftware/spine-webgl 4.0.10 → 4.0.14

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.
@@ -1,6 +1,9 @@
1
1
  var spine = (() => {
2
2
  var __defProp = Object.defineProperty;
3
3
  var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
4
+ var __require = typeof require !== "undefined" ? require : (x) => {
5
+ throw new Error('Dynamic require of "' + x + '" is not supported');
6
+ };
4
7
  var __export = (target, all) => {
5
8
  __markAsModule(target);
6
9
  for (var name in all)
@@ -26,6 +29,7 @@ var spine = (() => {
26
29
  BoneData: () => BoneData,
27
30
  BoundingBoxAttachment: () => BoundingBoxAttachment,
28
31
  CURRENT: () => CURRENT,
32
+ CameraController: () => CameraController,
29
33
  ClippingAttachment: () => ClippingAttachment,
30
34
  Color: () => Color,
31
35
  Color2Attribute: () => Color2Attribute,
@@ -4291,14 +4295,14 @@ var spine = (() => {
4291
4295
  return dataUri.substr(dataUri.indexOf(",") + 1);
4292
4296
  }
4293
4297
  }
4294
- base64ToArrayBuffer(base64) {
4298
+ base64ToUint8Array(base64) {
4295
4299
  var binary_string = window.atob(base64);
4296
4300
  var len = binary_string.length;
4297
4301
  var bytes = new Uint8Array(len);
4298
4302
  for (var i = 0; i < len; i++) {
4299
4303
  bytes[i] = binary_string.charCodeAt(i);
4300
4304
  }
4301
- return bytes.buffer;
4305
+ return bytes;
4302
4306
  }
4303
4307
  dataUriToUint8Array(dataUri) {
4304
4308
  if (!dataUri.startsWith("data:")) {
@@ -4308,7 +4312,7 @@ var spine = (() => {
4308
4312
  if (base64Idx == -1)
4309
4313
  throw new Error("Not a binary data URI.");
4310
4314
  base64Idx += "base64,".length;
4311
- return this.base64ToArrayBuffer(dataUri.substr(base64Idx));
4315
+ return this.base64ToUint8Array(dataUri.substr(base64Idx));
4312
4316
  }
4313
4317
  downloadText(url, success, error) {
4314
4318
  if (this.start(url, success, error))
@@ -9254,14 +9258,13 @@ var spine = (() => {
9254
9258
  // spine-webgl/src/Input.ts
9255
9259
  var Input = class {
9256
9260
  constructor(element) {
9257
- this.lastX = 0;
9258
- this.lastY = 0;
9261
+ this.mouseX = 0;
9262
+ this.mouseY = 0;
9259
9263
  this.buttonDown = false;
9260
- this.currTouch = null;
9264
+ this.touch0 = null;
9265
+ this.touch1 = null;
9266
+ this.initialPinchDistance = 0;
9261
9267
  this.listeners = new Array();
9262
- this.touchesPool = new Pool(() => {
9263
- return new Touch(0, 0, 0);
9264
- });
9265
9268
  this.element = element;
9266
9269
  this.setupCallbacks(element);
9267
9270
  }
@@ -9269,15 +9272,14 @@ var spine = (() => {
9269
9272
  let mouseDown = (ev) => {
9270
9273
  if (ev instanceof MouseEvent) {
9271
9274
  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;
9275
+ this.mouseX = ev.clientX - rect.left;
9276
+ ;
9277
+ this.mouseY = ev.clientY - rect.top;
9280
9278
  this.buttonDown = true;
9279
+ this.listeners.map((listener) => {
9280
+ if (listener.down)
9281
+ listener.down(this.mouseX, this.mouseY);
9282
+ });
9281
9283
  document.addEventListener("mousemove", mouseMove);
9282
9284
  document.addEventListener("mouseup", mouseUp);
9283
9285
  }
@@ -9285,138 +9287,154 @@ var spine = (() => {
9285
9287
  let mouseMove = (ev) => {
9286
9288
  if (ev instanceof MouseEvent) {
9287
9289
  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++) {
9290
+ this.mouseX = ev.clientX - rect.left;
9291
+ ;
9292
+ this.mouseY = ev.clientY - rect.top;
9293
+ this.listeners.map((listener) => {
9292
9294
  if (this.buttonDown) {
9293
- if (listeners[i].dragged)
9294
- listeners[i].dragged(x, y);
9295
+ if (listener.dragged)
9296
+ listener.dragged(this.mouseX, this.mouseY);
9295
9297
  } else {
9296
- if (listeners[i].moved)
9297
- listeners[i].moved(x, y);
9298
+ if (listener.moved)
9299
+ listener.moved(this.mouseX, this.mouseY);
9298
9300
  }
9299
- }
9300
- this.lastX = x;
9301
- this.lastY = y;
9301
+ });
9302
9302
  }
9303
9303
  };
9304
9304
  let mouseUp = (ev) => {
9305
9305
  if (ev instanceof MouseEvent) {
9306
9306
  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;
9307
+ this.mouseX = ev.clientX - rect.left;
9308
+ ;
9309
+ this.mouseY = ev.clientY - rect.top;
9315
9310
  this.buttonDown = false;
9311
+ this.listeners.map((listener) => {
9312
+ if (listener.up)
9313
+ listener.up(this.mouseX, this.mouseY);
9314
+ });
9316
9315
  document.removeEventListener("mousemove", mouseMove);
9317
9316
  document.removeEventListener("mouseup", mouseUp);
9318
9317
  }
9319
9318
  };
9319
+ let mouseWheel = (e) => {
9320
+ e.preventDefault();
9321
+ let deltaY = e.deltaY;
9322
+ if (e.deltaMode == WheelEvent.DOM_DELTA_LINE)
9323
+ deltaY *= 8;
9324
+ if (e.deltaMode == WheelEvent.DOM_DELTA_PAGE)
9325
+ deltaY *= 24;
9326
+ this.listeners.map((listener) => {
9327
+ if (listener.wheel)
9328
+ listener.wheel(e.deltaY);
9329
+ });
9330
+ };
9320
9331
  element.addEventListener("mousedown", mouseDown, true);
9321
9332
  element.addEventListener("mousemove", mouseMove, true);
9322
9333
  element.addEventListener("mouseup", mouseUp, true);
9334
+ element.addEventListener("wheel", mouseWheel, true);
9323
9335
  element.addEventListener("touchstart", (ev) => {
9324
- if (!this.currTouch) {
9336
+ if (!this.touch0 || !this.touch1) {
9325
9337
  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;
9338
+ let nativeTouch = touches.item(0);
9339
+ let rect = element.getBoundingClientRect();
9340
+ let x = nativeTouch.clientX - rect.left;
9341
+ let y = nativeTouch.clientY - rect.top;
9342
+ let touch = new Touch(nativeTouch.identifier, x, y);
9343
+ this.mouseX = x;
9344
+ this.mouseY = y;
9344
9345
  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
- }
9346
+ if (!this.touch0) {
9347
+ this.touch0 = touch;
9348
+ this.listeners.map((listener) => {
9349
+ if (listener.down)
9350
+ listener.down(touch.x, touch.y);
9351
+ });
9352
+ } else if (!this.touch1) {
9353
+ this.touch1 = touch;
9354
+ let dx = this.touch1.x - this.touch0.x;
9355
+ let dy = this.touch1.x - this.touch0.x;
9356
+ this.initialPinchDistance = Math.sqrt(dx * dx + dy * dy);
9357
+ this.listeners.map((listener) => {
9358
+ if (listener.zoom)
9359
+ listener.zoom(this.initialPinchDistance, this.initialPinchDistance);
9360
+ });
9369
9361
  }
9370
9362
  }
9371
9363
  ev.preventDefault();
9372
9364
  }, false);
9373
- element.addEventListener("touchcancel", (ev) => {
9374
- if (this.currTouch) {
9365
+ element.addEventListener("touchmove", (ev) => {
9366
+ if (this.touch0) {
9375
9367
  var touches = ev.changedTouches;
9368
+ let rect = element.getBoundingClientRect();
9376
9369
  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;
9370
+ var nativeTouch = touches[i];
9371
+ let x = nativeTouch.clientX - rect.left;
9372
+ let y = nativeTouch.clientY - rect.top;
9373
+ if (this.touch0.identifier === nativeTouch.identifier) {
9374
+ this.touch0.x = this.mouseX = x;
9375
+ this.touch0.y = this.mouseY = y;
9376
+ this.listeners.map((listener) => {
9377
+ if (listener.dragged)
9378
+ listener.dragged(x, y);
9379
+ });
9380
+ }
9381
+ if (this.touch1 && this.touch1.identifier === nativeTouch.identifier) {
9382
+ this.touch1.x = this.mouseX = x;
9383
+ this.touch1.y = this.mouseY = y;
9393
9384
  }
9394
9385
  }
9386
+ if (this.touch0 && this.touch1) {
9387
+ let dx = this.touch1.x - this.touch0.x;
9388
+ let dy = this.touch1.x - this.touch0.x;
9389
+ let distance = Math.sqrt(dx * dx + dy * dy);
9390
+ this.listeners.map((listener) => {
9391
+ if (listener.zoom)
9392
+ listener.zoom(this.initialPinchDistance, distance);
9393
+ });
9394
+ }
9395
9395
  }
9396
9396
  ev.preventDefault();
9397
9397
  }, false);
9398
- element.addEventListener("touchmove", (ev) => {
9399
- if (this.currTouch) {
9398
+ let touchEnd = (ev) => {
9399
+ if (this.touch0) {
9400
9400
  var touches = ev.changedTouches;
9401
+ let rect = element.getBoundingClientRect();
9401
9402
  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);
9403
+ var nativeTouch = touches[i];
9404
+ let x = nativeTouch.clientX - rect.left;
9405
+ let y = nativeTouch.clientY - rect.top;
9406
+ if (this.touch0.identifier === nativeTouch.identifier) {
9407
+ this.touch0 = null;
9408
+ this.mouseX = x;
9409
+ this.mouseY = y;
9410
+ this.listeners.map((listener) => {
9411
+ if (listener.up)
9412
+ listener.up(x, y);
9413
+ });
9414
+ if (!this.touch1) {
9415
+ this.buttonDown = false;
9416
+ break;
9417
+ } else {
9418
+ this.touch0 = this.touch1;
9419
+ this.touch1 = null;
9420
+ this.mouseX = this.touch0.x;
9421
+ this.mouseX = this.touch0.x;
9422
+ this.buttonDown = true;
9423
+ this.listeners.map((listener) => {
9424
+ if (listener.down)
9425
+ listener.down(this.touch0.x, this.touch0.y);
9426
+ });
9411
9427
  }
9412
- this.lastX = this.currTouch.x = x;
9413
- this.lastY = this.currTouch.y = y;
9414
- break;
9428
+ }
9429
+ if (this.touch1 && this.touch1.identifier) {
9430
+ this.touch1 = null;
9415
9431
  }
9416
9432
  }
9417
9433
  }
9418
9434
  ev.preventDefault();
9419
- }, false);
9435
+ };
9436
+ element.addEventListener("touchend", touchEnd, false);
9437
+ element.addEventListener("touchcancel", touchEnd);
9420
9438
  }
9421
9439
  addListener(listener) {
9422
9440
  this.listeners.push(listener);
@@ -9436,6 +9454,72 @@ var spine = (() => {
9436
9454
  }
9437
9455
  };
9438
9456
 
9457
+ // spine-webgl/src/CameraController.ts
9458
+ var CameraController = class {
9459
+ constructor(canvas, camera) {
9460
+ this.canvas = canvas;
9461
+ this.camera = camera;
9462
+ let cameraX = 0, cameraY = 0, cameraZoom = 0;
9463
+ let mouseX = 0, mouseY = 0;
9464
+ let lastX = 0, lastY = 0;
9465
+ let initialZoom = 0;
9466
+ new Input(canvas).addListener({
9467
+ down: (x, y) => {
9468
+ cameraX = camera.position.x;
9469
+ cameraY = camera.position.y;
9470
+ mouseX = lastX = x;
9471
+ mouseY = lastY = y;
9472
+ initialZoom = camera.zoom;
9473
+ },
9474
+ dragged: (x, y) => {
9475
+ let deltaX = x - mouseX;
9476
+ let deltaY = y - mouseY;
9477
+ let originWorld = camera.screenToWorld(new Vector3(0, 0), canvas.clientWidth, canvas.clientHeight);
9478
+ let deltaWorld = camera.screenToWorld(new Vector3(deltaX, deltaY), canvas.clientWidth, canvas.clientHeight).sub(originWorld);
9479
+ camera.position.set(cameraX - deltaWorld.x, cameraY - deltaWorld.y, 0);
9480
+ camera.update();
9481
+ lastX = x;
9482
+ lastY = y;
9483
+ },
9484
+ wheel: (delta) => {
9485
+ let zoomAmount = delta / 200 * camera.zoom;
9486
+ let newZoom = camera.zoom + zoomAmount;
9487
+ if (newZoom > 0) {
9488
+ let x = 0, y = 0;
9489
+ if (delta < 0) {
9490
+ x = lastX;
9491
+ y = lastY;
9492
+ } else {
9493
+ let viewCenter = new Vector3(canvas.clientWidth / 2 + 15, canvas.clientHeight / 2);
9494
+ let mouseToCenterX = lastX - viewCenter.x;
9495
+ let mouseToCenterY = canvas.clientHeight - 1 - lastY - viewCenter.y;
9496
+ x = viewCenter.x - mouseToCenterX;
9497
+ y = canvas.clientHeight - 1 - viewCenter.y + mouseToCenterY;
9498
+ }
9499
+ let oldDistance = camera.screenToWorld(new Vector3(x, y), canvas.clientWidth, canvas.clientHeight);
9500
+ camera.zoom = newZoom;
9501
+ camera.update();
9502
+ let newDistance = camera.screenToWorld(new Vector3(x, y), canvas.clientWidth, canvas.clientHeight);
9503
+ camera.position.add(oldDistance.sub(newDistance));
9504
+ camera.update();
9505
+ }
9506
+ },
9507
+ zoom: (initialDistance, distance) => {
9508
+ let newZoom = initialDistance / distance;
9509
+ camera.zoom = initialZoom * newZoom;
9510
+ },
9511
+ up: (x, y) => {
9512
+ lastX = x;
9513
+ lastY = y;
9514
+ },
9515
+ moved: (x, y) => {
9516
+ lastX = x;
9517
+ lastY = y;
9518
+ }
9519
+ });
9520
+ }
9521
+ };
9522
+
9439
9523
  // spine-webgl/src/Shader.ts
9440
9524
  var _Shader = class {
9441
9525
  constructor(context, vertexShader, fragmentShader) {