stage-js 1.0.0 → 1.0.1

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.
package/dist/stage.d.ts CHANGED
@@ -552,6 +552,7 @@ export declare class Root extends Component {
552
552
  sleep: boolean;
553
553
  constructor();
554
554
  mount: (configs?: RootConfig) => void;
555
+ resizeCanvas(): void;
555
556
  /** @hidden */
556
557
  debugDrawAxis: number;
557
558
  private renderDebug;
package/dist/stage.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Stage.js v1.0.0
2
+ * Stage.js v1.0.1
3
3
  * @copyright Copyright Ali Shakiba
4
4
  * @license Licensed under the MIT (https://github.com/piqnt/stage.js/blob/main/LICENSE.md)
5
5
  */
@@ -3095,11 +3095,11 @@ var Root = (
3095
3095
  _this.canvas = null;
3096
3096
  _this.dom = null;
3097
3097
  _this.context = null;
3098
- _this.pixelWidth = -1;
3099
- _this.pixelHeight = -1;
3098
+ _this.clientWidth = -1;
3099
+ _this.clientHeight = -1;
3100
3100
  _this.pixelRatio = 1;
3101
- _this.drawingWidth = 0;
3102
- _this.drawingHeight = 0;
3101
+ _this.canvasWidth = 0;
3102
+ _this.canvasHeight = 0;
3103
3103
  _this.mounted = false;
3104
3104
  _this.paused = false;
3105
3105
  _this.sleep = false;
@@ -3168,24 +3168,7 @@ var Root = (
3168
3168
  return;
3169
3169
  }
3170
3170
  _this.requestFrame();
3171
- var newPixelWidth = _this.canvas.clientWidth;
3172
- var newPixelHeight = _this.canvas.clientHeight;
3173
- if (_this.pixelWidth !== newPixelWidth || _this.pixelHeight !== newPixelHeight) {
3174
- _this.pixelWidth = newPixelWidth;
3175
- _this.pixelHeight = newPixelHeight;
3176
- _this.drawingWidth = newPixelWidth * _this.pixelRatio;
3177
- _this.drawingHeight = newPixelHeight * _this.pixelRatio;
3178
- if (_this.canvas.width !== _this.drawingWidth || _this.canvas.height !== _this.drawingHeight) {
3179
- _this.canvas.width = _this.drawingWidth;
3180
- _this.canvas.height = _this.drawingHeight;
3181
- console.debug && console.debug("Resize: [" + _this.drawingWidth + ", " + _this.drawingHeight + "] = " + _this.pixelRatio + " x [" + _this.pixelWidth + ", " + _this.pixelHeight + "]");
3182
- _this.viewport({
3183
- width: _this.drawingWidth,
3184
- height: _this.drawingHeight,
3185
- ratio: _this.pixelRatio
3186
- });
3187
- }
3188
- }
3171
+ _this.resizeCanvas();
3189
3172
  var last = _this._lastFrameTime || now;
3190
3173
  var elapsed = now - last;
3191
3174
  if (!_this.mounted || _this.paused || _this.sleep) {
@@ -3197,9 +3180,9 @@ var Root = (
3197
3180
  if (_this._mo_touch != _this._ts_touch) {
3198
3181
  _this._mo_touch = _this._ts_touch;
3199
3182
  _this.sleep = false;
3200
- if (_this.drawingWidth > 0 && _this.drawingHeight > 0) {
3183
+ if (_this.canvasWidth > 0 && _this.canvasHeight > 0) {
3201
3184
  _this.context.setTransform(1, 0, 0, 1, 0, 0);
3202
- _this.context.clearRect(0, 0, _this.drawingWidth, _this.drawingHeight);
3185
+ _this.context.clearRect(0, 0, _this.canvasWidth, _this.canvasHeight);
3203
3186
  if (_this.debugDrawAxis > 0) {
3204
3187
  _this.renderDebug(_this.context);
3205
3188
  }
@@ -3216,6 +3199,35 @@ var Root = (
3216
3199
  _this.label("Root");
3217
3200
  return _this;
3218
3201
  }
3202
+ Root2.prototype.resizeCanvas = function() {
3203
+ var newClientWidth = this.canvas.clientWidth;
3204
+ var newClientHeight = this.canvas.clientHeight;
3205
+ if (this.clientWidth === newClientWidth && this.clientHeight === newClientHeight)
3206
+ return;
3207
+ this.clientWidth = newClientWidth;
3208
+ this.clientHeight = newClientHeight;
3209
+ var notStyled = this.canvas.clientWidth === this.canvas.width && this.canvas.clientHeight === this.canvas.height;
3210
+ var pixelRatio;
3211
+ if (notStyled) {
3212
+ pixelRatio = 1;
3213
+ this.canvasWidth = this.canvas.width;
3214
+ this.canvasHeight = this.canvas.height;
3215
+ } else {
3216
+ pixelRatio = this.pixelRatio;
3217
+ this.canvasWidth = this.clientWidth * pixelRatio;
3218
+ this.canvasHeight = this.clientHeight * pixelRatio;
3219
+ if (this.canvas.width !== this.canvasWidth || this.canvas.height !== this.canvasHeight) {
3220
+ this.canvas.width = this.canvasWidth;
3221
+ this.canvas.height = this.canvasHeight;
3222
+ }
3223
+ }
3224
+ console.debug && console.debug("Resize: [" + this.canvasWidth + ", " + this.canvasHeight + "] = " + pixelRatio + " x [" + this.clientWidth + ", " + this.clientHeight + "]");
3225
+ this.viewport({
3226
+ width: this.canvasWidth,
3227
+ height: this.canvasHeight,
3228
+ ratio: pixelRatio
3229
+ });
3230
+ };
3219
3231
  Root2.prototype.renderDebug = function(context) {
3220
3232
  var size = typeof this.debugDrawAxis === "number" ? this.debugDrawAxis : 10;
3221
3233
  var m = this.matrix();
@@ -3353,12 +3365,14 @@ var Root = (
3353
3365
  var cameraZoomY = (camera === null || camera === void 0 ? void 0 : camera.d) || 1;
3354
3366
  var cameraX = (camera === null || camera === void 0 ? void 0 : camera.e) || 0;
3355
3367
  var cameraY = (camera === null || camera === void 0 ? void 0 : camera.f) || 0;
3356
- var scaleX = this.pin("scaleX");
3357
- var scaleY = this.pin("scaleY");
3358
- this.pin("scaleX", scaleX * cameraZoomX);
3359
- this.pin("scaleY", scaleY * cameraZoomY);
3360
- this.pin("offsetX", cameraX - viewboxX * scaleX * cameraZoomX);
3361
- this.pin("offsetY", cameraY - viewboxY * scaleY * cameraZoomY);
3368
+ var pinScaleX = this.pin("scaleX");
3369
+ var pinScaleY = this.pin("scaleY");
3370
+ var scaleX = pinScaleX * cameraZoomX;
3371
+ var scaleY = pinScaleY * cameraZoomY;
3372
+ this.pin("scaleX", scaleX);
3373
+ this.pin("scaleY", scaleY);
3374
+ this.pin("offsetX", cameraX - viewboxX * scaleX);
3375
+ this.pin("offsetY", cameraY - viewboxY * scaleY);
3362
3376
  } else if (viewport) {
3363
3377
  this.pin({
3364
3378
  width: viewport.width,