stage-js 1.0.0 → 1.0.2

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,8 +1,8 @@
1
1
  (function(global, factory) {
2
2
  typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.Stage = {}));
3
- })(this, function(exports2) {
3
+ })(this, (function(exports2) {
4
4
  "use strict";/**
5
- * Stage.js v1.0.0
5
+ * Stage.js v1.0.2
6
6
  * @copyright Copyright Ali Shakiba
7
7
  * @license Licensed under the MIT (https://github.com/piqnt/stage.js/blob/main/LICENSE.md)
8
8
  */
@@ -56,7 +56,7 @@
56
56
  math.limit = clamp;
57
57
  var Matrix = (
58
58
  /** @class */
59
- function() {
59
+ (function() {
60
60
  function Matrix2(a, b, c, d, e, f) {
61
61
  this.a = 1;
62
62
  this.b = 0;
@@ -220,7 +220,7 @@
220
220
  return this.b * x + this.d * y + this.f;
221
221
  };
222
222
  return Matrix2;
223
- }()
223
+ })()
224
224
  );
225
225
  /*! *****************************************************************************
226
226
  Copyright (c) Microsoft Corporation.
@@ -377,7 +377,7 @@
377
377
  };
378
378
  var Texture = (
379
379
  /** @class */
380
- function() {
380
+ (function() {
381
381
  function Texture2() {
382
382
  this.uid = "texture:" + uid();
383
383
  this.sx = 0;
@@ -435,11 +435,11 @@
435
435
  this.drawWithNormalizedArgs(context, sx, sy, sw, sh, dx, dy, dw, dh);
436
436
  };
437
437
  return Texture2;
438
- }()
438
+ })()
439
439
  );
440
440
  var ImageTexture = (
441
441
  /** @class */
442
- function(_super) {
442
+ (function(_super) {
443
443
  __extends(ImageTexture2, _super);
444
444
  function ImageTexture2(source, pixelRatio) {
445
445
  var _this = _super.call(this) || this;
@@ -496,11 +496,11 @@
496
496
  }
497
497
  };
498
498
  return ImageTexture2;
499
- }(Texture)
499
+ })(Texture)
500
500
  );
501
501
  var PipeTexture = (
502
502
  /** @class */
503
- function(_super) {
503
+ (function(_super) {
504
504
  __extends(PipeTexture2, _super);
505
505
  function PipeTexture2(source) {
506
506
  var _this = _super.call(this) || this;
@@ -529,11 +529,11 @@
529
529
  texture2.draw(context, sx, sy, sw, sh, dx, dy, dw, dh);
530
530
  };
531
531
  return PipeTexture2;
532
- }(Texture)
532
+ })(Texture)
533
533
  );
534
534
  var Atlas = (
535
535
  /** @class */
536
- function(_super) {
536
+ (function(_super) {
537
537
  __extends(Atlas2, _super);
538
538
  function Atlas2(def) {
539
539
  if (def === void 0) {
@@ -648,7 +648,7 @@
648
648
  });
649
649
  };
650
650
  return Atlas2;
651
- }(ImageTexture)
651
+ })(ImageTexture)
652
652
  );
653
653
  function asyncLoadImage(src) {
654
654
  console.debug && console.debug("Loading image: " + src);
@@ -688,7 +688,7 @@
688
688
  }
689
689
  var TextureSelection = (
690
690
  /** @class */
691
- function() {
691
+ (function() {
692
692
  function TextureSelection2(selection, atlas2) {
693
693
  this.selection = selection;
694
694
  this.atlas = atlas2;
@@ -731,10 +731,10 @@
731
731
  return array;
732
732
  };
733
733
  return TextureSelection2;
734
- }()
734
+ })()
735
735
  );
736
736
  var NO_TEXTURE = new /** @class */
737
- (function(_super) {
737
+ ((function(_super) {
738
738
  __extends(class_1, _super);
739
739
  function class_1() {
740
740
  var _this = _super.call(this) || this;
@@ -763,7 +763,7 @@
763
763
  class_1.prototype.draw = function() {
764
764
  };
765
765
  return class_1;
766
- }(Texture))();
766
+ })(Texture))();
767
767
  var NO_SELECTION = new TextureSelection(NO_TEXTURE);
768
768
  var ATLAS_MEMO_BY_NAME = {};
769
769
  var ATLAS_ARRAY = [];
@@ -843,7 +843,7 @@
843
843
  }
844
844
  var ResizableTexture = (
845
845
  /** @class */
846
- function(_super) {
846
+ (function(_super) {
847
847
  __extends(ResizableTexture2, _super);
848
848
  function ResizableTexture2(source, mode) {
849
849
  var _this = _super.call(this) || this;
@@ -940,7 +940,7 @@
940
940
  }
941
941
  };
942
942
  return ResizableTexture2;
943
- }(Texture)
943
+ })(Texture)
944
944
  );
945
945
  function getDevicePixelRatio() {
946
946
  return typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
@@ -949,9 +949,12 @@
949
949
  return value && (value === "cover" || value === "contain" || value === "fill" || value === "in" || value === "in-pad" || value === "out" || value === "out-crop");
950
950
  }
951
951
  var iid$1 = 0;
952
+ function getIID() {
953
+ return iid$1++;
954
+ }
952
955
  var Pin = (
953
956
  /** @class */
954
- function() {
957
+ (function() {
955
958
  function Pin2(owner) {
956
959
  this.uid = "pin:" + uid();
957
960
  this._directionX = 1;
@@ -1016,6 +1019,7 @@
1016
1019
  var abs = this._absoluteMatrix;
1017
1020
  abs.reset(this.relativeMatrix());
1018
1021
  this._parent && abs.concat(this._parent._absoluteMatrix);
1022
+ this._owner._xf && abs.concat(this._owner._xf);
1019
1023
  this._ts_matrix = ++iid$1;
1020
1024
  return abs;
1021
1025
  };
@@ -1139,8 +1143,39 @@
1139
1143
  }
1140
1144
  };
1141
1145
  return Pin2;
1142
- }()
1146
+ })()
1143
1147
  );
1148
+ function fit(inWidth, inHeight, outWidth, outHeight, mode) {
1149
+ if (mode === "contain")
1150
+ mode = "in-pad";
1151
+ if (mode === "cover")
1152
+ mode = "out-crop";
1153
+ var scaleX;
1154
+ var scaleY;
1155
+ var width;
1156
+ var height;
1157
+ if (typeof outWidth === "number") {
1158
+ scaleX = outWidth / inWidth;
1159
+ width = inWidth;
1160
+ }
1161
+ if (typeof outHeight === "number") {
1162
+ scaleY = outHeight / inHeight;
1163
+ height = inHeight;
1164
+ }
1165
+ if (typeof outWidth === "number" && typeof outHeight === "number" && typeof mode === "string") {
1166
+ if (mode === "fill") ;
1167
+ else if (mode === "out" || mode === "out-crop") {
1168
+ scaleX = scaleY = Math.max(scaleX, scaleY);
1169
+ } else if (mode === "in" || mode === "in-pad") {
1170
+ scaleX = scaleY = Math.min(scaleX, scaleY);
1171
+ }
1172
+ if (mode === "out-crop" || mode === "in-pad") {
1173
+ width = outWidth / scaleX;
1174
+ height = outHeight / scaleY;
1175
+ }
1176
+ }
1177
+ return { scaleX, scaleY, width, height };
1178
+ }
1144
1179
  var getters = {
1145
1180
  alpha: function(pin) {
1146
1181
  return pin._alpha;
@@ -1368,7 +1403,7 @@
1368
1403
  };
1369
1404
  var Easing = (
1370
1405
  /** @class */
1371
- function() {
1406
+ (function() {
1372
1407
  function Easing2() {
1373
1408
  }
1374
1409
  Easing2.init = function(query, params) {
@@ -1390,7 +1425,7 @@
1390
1425
  return easing;
1391
1426
  };
1392
1427
  return Easing2;
1393
- }()
1428
+ })()
1394
1429
  );
1395
1430
  var initEasing = function(query, params) {
1396
1431
  var easing;
@@ -1450,6 +1485,9 @@
1450
1485
  return t < 1 / 2.75 ? 7.5625 * t * t : t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + 0.75 : t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + 0.9375 : 7.5625 * (t -= 2.625 / 2.75) * t + 0.984375;
1451
1486
  };
1452
1487
  var poly = function(e) {
1488
+ if (e === void 0) {
1489
+ e = 3;
1490
+ }
1453
1491
  return function(t) {
1454
1492
  return Math.pow(t, e);
1455
1493
  };
@@ -1573,7 +1611,7 @@
1573
1611
  };
1574
1612
  var Transition = (
1575
1613
  /** @class */
1576
- function() {
1614
+ (function() {
1577
1615
  function Transition2(owner, options) {
1578
1616
  if (options === void 0) {
1579
1617
  options = {};
@@ -1743,7 +1781,7 @@
1743
1781
  return this;
1744
1782
  };
1745
1783
  return Transition2;
1746
- }()
1784
+ })()
1747
1785
  );
1748
1786
  function pinning(component2, map, key, value) {
1749
1787
  if (typeof component2._pin.get(key) === "number") {
@@ -1753,6 +1791,37 @@
1753
1791
  map[key + "Y"] = value;
1754
1792
  }
1755
1793
  }
1794
+ function renderAxis(ctx, size) {
1795
+ ctx.strokeStyle = "rgba(93, 173, 226)";
1796
+ ctx.beginPath();
1797
+ ctx.moveTo(0, 0);
1798
+ ctx.lineTo(0, 0.8 * size);
1799
+ ctx.lineTo(-0.2 * size, 0.8 * size);
1800
+ ctx.lineTo(0, size);
1801
+ ctx.lineTo(0.2 * size, 0.8 * size);
1802
+ ctx.lineTo(0, 0.8 * size);
1803
+ ctx.stroke();
1804
+ ctx.strokeStyle = "rgba(236, 112, 99)";
1805
+ ctx.beginPath();
1806
+ ctx.moveTo(0, 0);
1807
+ ctx.lineTo(0.8 * size, 0);
1808
+ ctx.lineTo(0.8 * size, -0.2 * size);
1809
+ ctx.lineTo(size, 0);
1810
+ ctx.lineTo(0.8 * size, 0.2 * size);
1811
+ ctx.lineTo(0.8 * size, 0);
1812
+ ctx.stroke();
1813
+ }
1814
+ function renderPoint(ctx, px, py) {
1815
+ ctx.beginPath();
1816
+ ctx.beginPath();
1817
+ ctx.moveTo(px - 0.2, py - 0.2);
1818
+ ctx.lineTo(px + 0.2, py + 0.2);
1819
+ ctx.stroke();
1820
+ ctx.beginPath();
1821
+ ctx.moveTo(px - 0.2, py + 0.2);
1822
+ ctx.lineTo(px + 0.2, py - 0.2);
1823
+ ctx.stroke();
1824
+ }
1756
1825
  var iid = 0;
1757
1826
  stats.create = 0;
1758
1827
  function assertType(obj) {
@@ -1790,7 +1859,7 @@
1790
1859
  }
1791
1860
  var Component = (
1792
1861
  /** @class */
1793
- function() {
1862
+ (function() {
1794
1863
  function Component2() {
1795
1864
  var _this = this;
1796
1865
  this.uid = "component:" + uid();
@@ -1852,15 +1921,14 @@
1852
1921
  return this._pin.absoluteMatrix();
1853
1922
  };
1854
1923
  Component2.prototype.getPixelRatio = function() {
1855
- var _a;
1856
- var m = (_a = this._parent) === null || _a === void 0 ? void 0 : _a.matrix();
1857
- var pixelRatio = !m ? 1 : Math.max(Math.abs(m.a), Math.abs(m.b)) / getDevicePixelRatio();
1858
- return pixelRatio;
1924
+ return this.getLogicalPixelRatio();
1859
1925
  };
1860
1926
  Component2.prototype.getDevicePixelRatio = function() {
1861
1927
  var _a;
1862
1928
  var parentMatrix = (_a = this._parent) === null || _a === void 0 ? void 0 : _a.matrix();
1863
- var pixelRatio = !parentMatrix ? 1 : Math.max(Math.abs(parentMatrix.a), Math.abs(parentMatrix.b));
1929
+ if (!parentMatrix)
1930
+ return 1;
1931
+ var pixelRatio = Math.max(Math.abs(parentMatrix.a), Math.abs(parentMatrix.b));
1864
1932
  return pixelRatio;
1865
1933
  };
1866
1934
  Component2.prototype.getLogicalPixelRatio = function() {
@@ -2232,6 +2300,7 @@
2232
2300
  }
2233
2301
  stats.component++;
2234
2302
  var m = this.matrix();
2303
+ this.renderDebug(context, m);
2235
2304
  context.setTransform(m.a, m.b, m.c, m.d, m.e, m.f);
2236
2305
  this._alpha = this._pin._alpha * (this._parent ? this._parent._alpha : 1);
2237
2306
  var alpha = this._pin._textureAlpha * this._alpha;
@@ -2622,8 +2691,30 @@
2622
2691
  this._spacing = space;
2623
2692
  return this;
2624
2693
  };
2694
+ Component2.prototype.renderDebug = function(ctx, xf) {
2695
+ if (!this._debug)
2696
+ return;
2697
+ var ppu = this.getLogicalPixelRatio();
2698
+ ctx.lineWidth = 1 / ppu;
2699
+ ctx.lineCap = "round";
2700
+ ctx.lineJoin = "round";
2701
+ renderAxis(ctx, 1);
2702
+ var pin = this._pin;
2703
+ if (pin._pivoted) {
2704
+ ctx.strokeStyle = "orange";
2705
+ renderPoint(ctx, pin._pivotX * pin._width, pin._pivotY * pin._height);
2706
+ }
2707
+ if (pin._aligned) {
2708
+ ctx.strokeStyle = "green";
2709
+ renderPoint(ctx, pin._alignX * pin._width, pin._alignY * pin._height);
2710
+ }
2711
+ if (pin._handled) {
2712
+ ctx.strokeStyle = "yellow";
2713
+ renderPoint(ctx, pin._handleX * pin._width, pin._handleY * pin._height);
2714
+ }
2715
+ };
2625
2716
  return Component2;
2626
- }()
2717
+ })()
2627
2718
  );
2628
2719
  function sprite(frame) {
2629
2720
  var sprite2 = new Sprite();
@@ -2632,7 +2723,7 @@
2632
2723
  }
2633
2724
  var Sprite = (
2634
2725
  /** @class */
2635
- function(_super) {
2726
+ (function(_super) {
2636
2727
  __extends(Sprite2, _super);
2637
2728
  function Sprite2() {
2638
2729
  var _this = _super.call(this) || this;
@@ -2700,11 +2791,11 @@
2700
2791
  this._texture.draw(context);
2701
2792
  };
2702
2793
  return Sprite2;
2703
- }(Component)
2794
+ })(Component)
2704
2795
  );
2705
2796
  var CanvasTexture = (
2706
2797
  /** @class */
2707
- function(_super) {
2798
+ (function(_super) {
2708
2799
  __extends(CanvasTexture2, _super);
2709
2800
  function CanvasTexture2() {
2710
2801
  var _this = _super.call(this, document.createElement("canvas")) || this;
@@ -2777,7 +2868,7 @@
2777
2868
  return this;
2778
2869
  };
2779
2870
  return CanvasTexture2;
2780
- }(ImageTexture)
2871
+ })(ImageTexture)
2781
2872
  );
2782
2873
  function canvas(type, attributes, legacyTextureDrawer) {
2783
2874
  if (typeof type === "function") {
@@ -2829,7 +2920,7 @@
2829
2920
  var POINTER_END = "touchend mouseup";
2830
2921
  var EventPoint = (
2831
2922
  /** @class */
2832
- function() {
2923
+ (function() {
2833
2924
  function EventPoint2() {
2834
2925
  }
2835
2926
  EventPoint2.prototype.clone = function(obj) {
@@ -2848,11 +2939,11 @@
2848
2939
  return (this.x | 0) + "x" + (this.y | 0);
2849
2940
  };
2850
2941
  return EventPoint2;
2851
- }()
2942
+ })()
2852
2943
  );
2853
2944
  var PointerSyntheticEvent = (
2854
2945
  /** @class */
2855
- function() {
2946
+ (function() {
2856
2947
  function PointerSyntheticEvent2() {
2857
2948
  this.abs = new EventPoint();
2858
2949
  }
@@ -2872,11 +2963,11 @@
2872
2963
  return this.type + ": " + (this.x | 0) + "x" + (this.y | 0);
2873
2964
  };
2874
2965
  return PointerSyntheticEvent2;
2875
- }()
2966
+ })()
2876
2967
  );
2877
2968
  var VisitPayload = (
2878
2969
  /** @class */
2879
- function() {
2970
+ (function() {
2880
2971
  function VisitPayload2() {
2881
2972
  this.type = "";
2882
2973
  this.x = 0;
@@ -2890,13 +2981,13 @@
2890
2981
  return this.type + ": " + (this.x | 0) + "x" + (this.y | 0);
2891
2982
  };
2892
2983
  return VisitPayload2;
2893
- }()
2984
+ })()
2894
2985
  );
2895
2986
  var syntheticEvent = new PointerSyntheticEvent();
2896
2987
  var PAYLOAD = new VisitPayload();
2897
2988
  var Pointer = (
2898
2989
  /** @class */
2899
- function() {
2990
+ (function() {
2900
2991
  function Pointer2() {
2901
2992
  var _this = this;
2902
2993
  this.ratio = 1;
@@ -3060,7 +3151,7 @@
3060
3151
  };
3061
3152
  Pointer2.DEBUG = false;
3062
3153
  return Pointer2;
3063
- }()
3154
+ })()
3064
3155
  );
3065
3156
  var Mouse = {
3066
3157
  CLICK: "click",
@@ -3092,18 +3183,18 @@
3092
3183
  var DEFAULT_CANVAS_MOUNTED = false;
3093
3184
  var Root = (
3094
3185
  /** @class */
3095
- function(_super) {
3186
+ (function(_super) {
3096
3187
  __extends(Root2, _super);
3097
3188
  function Root2() {
3098
3189
  var _this = _super.call(this) || this;
3099
3190
  _this.canvas = null;
3100
3191
  _this.dom = null;
3101
3192
  _this.context = null;
3102
- _this.pixelWidth = -1;
3103
- _this.pixelHeight = -1;
3193
+ _this.clientWidth = -1;
3194
+ _this.clientHeight = -1;
3104
3195
  _this.pixelRatio = 1;
3105
- _this.drawingWidth = 0;
3106
- _this.drawingHeight = 0;
3196
+ _this.canvasWidth = 0;
3197
+ _this.canvasHeight = 0;
3107
3198
  _this.mounted = false;
3108
3199
  _this.paused = false;
3109
3200
  _this.sleep = false;
@@ -3172,24 +3263,7 @@
3172
3263
  return;
3173
3264
  }
3174
3265
  _this.requestFrame();
3175
- var newPixelWidth = _this.canvas.clientWidth;
3176
- var newPixelHeight = _this.canvas.clientHeight;
3177
- if (_this.pixelWidth !== newPixelWidth || _this.pixelHeight !== newPixelHeight) {
3178
- _this.pixelWidth = newPixelWidth;
3179
- _this.pixelHeight = newPixelHeight;
3180
- _this.drawingWidth = newPixelWidth * _this.pixelRatio;
3181
- _this.drawingHeight = newPixelHeight * _this.pixelRatio;
3182
- if (_this.canvas.width !== _this.drawingWidth || _this.canvas.height !== _this.drawingHeight) {
3183
- _this.canvas.width = _this.drawingWidth;
3184
- _this.canvas.height = _this.drawingHeight;
3185
- console.debug && console.debug("Resize: [" + _this.drawingWidth + ", " + _this.drawingHeight + "] = " + _this.pixelRatio + " x [" + _this.pixelWidth + ", " + _this.pixelHeight + "]");
3186
- _this.viewport({
3187
- width: _this.drawingWidth,
3188
- height: _this.drawingHeight,
3189
- ratio: _this.pixelRatio
3190
- });
3191
- }
3192
- }
3266
+ _this.resizeCanvas();
3193
3267
  var last = _this._lastFrameTime || now;
3194
3268
  var elapsed = now - last;
3195
3269
  if (!_this.mounted || _this.paused || _this.sleep) {
@@ -3201,12 +3275,9 @@
3201
3275
  if (_this._mo_touch != _this._ts_touch) {
3202
3276
  _this._mo_touch = _this._ts_touch;
3203
3277
  _this.sleep = false;
3204
- if (_this.drawingWidth > 0 && _this.drawingHeight > 0) {
3278
+ if (_this.canvasWidth > 0 && _this.canvasHeight > 0) {
3205
3279
  _this.context.setTransform(1, 0, 0, 1, 0, 0);
3206
- _this.context.clearRect(0, 0, _this.drawingWidth, _this.drawingHeight);
3207
- if (_this.debugDrawAxis > 0) {
3208
- _this.renderDebug(_this.context);
3209
- }
3280
+ _this.context.clearRect(0, 0, _this.canvasWidth, _this.canvasHeight);
3210
3281
  _this.render(_this.context);
3211
3282
  }
3212
3283
  } else if (tickRequest) {
@@ -3216,39 +3287,44 @@
3216
3287
  }
3217
3288
  stats.fps = elapsed ? 1e3 / elapsed : 0;
3218
3289
  };
3219
- _this.debugDrawAxis = 0;
3220
3290
  _this.label("Root");
3221
3291
  return _this;
3222
3292
  }
3223
- Root2.prototype.renderDebug = function(context) {
3224
- var size = typeof this.debugDrawAxis === "number" ? this.debugDrawAxis : 10;
3225
- var m = this.matrix();
3226
- context.setTransform(m.a, m.b, m.c, m.d, m.e, m.f);
3227
- var lineWidth = 3 / m.a;
3228
- context.beginPath();
3229
- context.moveTo(0, 0);
3230
- context.lineTo(0, 0.8 * size);
3231
- context.lineTo(-0.2 * size, 0.8 * size);
3232
- context.lineTo(0, size);
3233
- context.lineTo(0.2 * size, 0.8 * size);
3234
- context.lineTo(0, 0.8 * size);
3235
- context.strokeStyle = "rgba(93, 173, 226)";
3236
- context.lineJoin = "round";
3237
- context.lineCap = "round";
3238
- context.lineWidth = lineWidth;
3239
- context.stroke();
3240
- context.beginPath();
3241
- context.moveTo(0, 0);
3242
- context.lineTo(0.8 * size, 0);
3243
- context.lineTo(0.8 * size, -0.2 * size);
3244
- context.lineTo(size, 0);
3245
- context.lineTo(0.8 * size, 0.2 * size);
3246
- context.lineTo(0.8 * size, 0);
3247
- context.strokeStyle = "rgba(236, 112, 99)";
3248
- context.lineJoin = "round";
3249
- context.lineCap = "round";
3250
- context.lineWidth = lineWidth;
3251
- context.stroke();
3293
+ Root2.prototype.resizeCanvas = function() {
3294
+ var newClientWidth = this.canvas.clientWidth;
3295
+ var newClientHeight = this.canvas.clientHeight;
3296
+ if (this.clientWidth === newClientWidth && this.clientHeight === newClientHeight)
3297
+ return;
3298
+ this.clientWidth = newClientWidth;
3299
+ this.clientHeight = newClientHeight;
3300
+ var notStyled = this.canvas.clientWidth === this.canvas.width && this.canvas.clientHeight === this.canvas.height;
3301
+ var pixelRatio;
3302
+ if (notStyled) {
3303
+ pixelRatio = 1;
3304
+ this.canvasWidth = this.canvas.width;
3305
+ this.canvasHeight = this.canvas.height;
3306
+ } else {
3307
+ pixelRatio = this.pixelRatio;
3308
+ this.canvasWidth = this.clientWidth * pixelRatio;
3309
+ this.canvasHeight = this.clientHeight * pixelRatio;
3310
+ if (this.canvas.width !== this.canvasWidth || this.canvas.height !== this.canvasHeight) {
3311
+ this.canvas.width = this.canvasWidth;
3312
+ this.canvas.height = this.canvasHeight;
3313
+ }
3314
+ }
3315
+ console.debug && console.debug("Resize: [" + this.canvasWidth + ", " + this.canvasHeight + "] = " + pixelRatio + " x [" + this.clientWidth + ", " + this.clientHeight + "]");
3316
+ this.viewport({
3317
+ width: this.canvasWidth,
3318
+ height: this.canvasHeight,
3319
+ ratio: pixelRatio
3320
+ });
3321
+ };
3322
+ Root2.prototype.renderDebug = function(ctx, m) {
3323
+ if (!this._debug)
3324
+ return;
3325
+ ctx.setTransform(m.a, m.b, m.c, m.d, m.e, m.f);
3326
+ ctx.lineWidth = 3 / m.a;
3327
+ renderAxis(ctx, 10);
3252
3328
  };
3253
3329
  Root2.prototype.resume = function() {
3254
3330
  if (this.sleep || this.paused) {
@@ -3305,7 +3381,7 @@
3305
3381
  height,
3306
3382
  ratio: typeof ratio === "number" ? ratio : 1
3307
3383
  };
3308
- this.viewbox();
3384
+ this.rescale();
3309
3385
  var data_1 = Object.assign({}, this._viewport);
3310
3386
  this.visit({
3311
3387
  start: function(component2) {
@@ -3332,37 +3408,25 @@
3332
3408
  return this;
3333
3409
  };
3334
3410
  Root2.prototype.camera = function(matrix) {
3335
- this._camera = matrix;
3336
- this.rescale();
3411
+ this._xf = matrix.clone();
3412
+ this._pin._ts_transform = getIID();
3413
+ this.touch();
3337
3414
  return this;
3338
3415
  };
3339
3416
  Root2.prototype.rescale = function() {
3340
3417
  var viewbox = this._viewbox;
3341
3418
  var viewport = this._viewport;
3342
- var camera = this._camera;
3343
3419
  if (viewport && viewbox) {
3344
- var viewportWidth = viewport.width;
3345
- var viewportHeight = viewport.height;
3346
3420
  var viewboxMode = isValidFitMode(viewbox.mode) ? viewbox.mode : "in-pad";
3347
- var viewboxWidth = viewbox.width;
3348
- var viewboxHeight = viewbox.height;
3421
+ var fitted = fit(viewbox.width, viewbox.height, viewport.width, viewport.height, viewboxMode);
3349
3422
  this.pin({
3350
- width: viewboxWidth,
3351
- height: viewboxHeight
3423
+ width: fitted.width,
3424
+ height: fitted.height,
3425
+ scaleX: fitted.scaleX,
3426
+ scaleY: fitted.scaleY,
3427
+ offsetX: -(viewbox.x || 0) * fitted.scaleX,
3428
+ offsetY: -(viewbox.y || 0) * fitted.scaleY
3352
3429
  });
3353
- this.fit(viewportWidth, viewportHeight, viewboxMode);
3354
- var viewboxX = viewbox.x || 0;
3355
- var viewboxY = viewbox.y || 0;
3356
- var cameraZoomX = (camera === null || camera === void 0 ? void 0 : camera.a) || 1;
3357
- var cameraZoomY = (camera === null || camera === void 0 ? void 0 : camera.d) || 1;
3358
- var cameraX = (camera === null || camera === void 0 ? void 0 : camera.e) || 0;
3359
- var cameraY = (camera === null || camera === void 0 ? void 0 : camera.f) || 0;
3360
- var scaleX = this.pin("scaleX");
3361
- var scaleY = this.pin("scaleY");
3362
- this.pin("scaleX", scaleX * cameraZoomX);
3363
- this.pin("scaleY", scaleY * cameraZoomY);
3364
- this.pin("offsetX", cameraX - viewboxX * scaleX * cameraZoomX);
3365
- this.pin("offsetY", cameraY - viewboxY * scaleY * cameraZoomY);
3366
3430
  } else if (viewport) {
3367
3431
  this.pin({
3368
3432
  width: viewport.width,
@@ -3380,7 +3444,7 @@
3380
3444
  return this;
3381
3445
  };
3382
3446
  return Root2;
3383
- }(Component)
3447
+ })(Component)
3384
3448
  );
3385
3449
  function anim(frames, fps) {
3386
3450
  var anim2 = new Anim();
@@ -3391,7 +3455,7 @@
3391
3455
  var FPS = 15;
3392
3456
  var Anim = (
3393
3457
  /** @class */
3394
- function(_super) {
3458
+ (function(_super) {
3395
3459
  __extends(Anim2, _super);
3396
3460
  function Anim2() {
3397
3461
  var _this = _super.call(this) || this;
@@ -3496,14 +3560,14 @@
3496
3560
  return this;
3497
3561
  };
3498
3562
  return Anim2;
3499
- }(Component)
3563
+ })(Component)
3500
3564
  );
3501
3565
  function monotype(chars) {
3502
3566
  return new Monotype().frames(chars);
3503
3567
  }
3504
3568
  var Monotype = (
3505
3569
  /** @class */
3506
- function(_super) {
3570
+ (function(_super) {
3507
3571
  __extends(Monotype2, _super);
3508
3572
  function Monotype2() {
3509
3573
  var _this = _super.call(this) || this;
@@ -3570,7 +3634,7 @@
3570
3634
  return this;
3571
3635
  };
3572
3636
  return Monotype2;
3573
- }(Component)
3637
+ })(Component)
3574
3638
  );
3575
3639
  const Stage = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3576
3640
  __proto__: null,
@@ -3610,6 +3674,8 @@
3610
3674
  column,
3611
3675
  component,
3612
3676
  create,
3677
+ fit,
3678
+ getIID,
3613
3679
  image: sprite,
3614
3680
  isValidFitMode,
3615
3681
  layer,
@@ -3668,6 +3734,8 @@
3668
3734
  exports2.component = component;
3669
3735
  exports2.create = create;
3670
3736
  exports2.default = Stage;
3737
+ exports2.fit = fit;
3738
+ exports2.getIID = getIID;
3671
3739
  exports2.image = sprite;
3672
3740
  exports2.isValidFitMode = isValidFitMode;
3673
3741
  exports2.layer = layer;
@@ -3689,5 +3757,5 @@
3689
3757
  exports2.texture = texture;
3690
3758
  exports2.wrap = wrap;
3691
3759
  Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3692
- });
3760
+ }));
3693
3761
  //# sourceMappingURL=stage.umd.cjs.map