UNPKG

@daign/2d-pipeline

Version:
98 lines (97 loc) 3.61 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.NativeScaleTransform = void 0; var math_1 = require("@daign/math"); var transform_1 = require("./transform"); /** * A scaling transformation that supports native SVG transform usage. */ var NativeScaleTransform = /** @class */ (function (_super) { __extends(NativeScaleTransform, _super); /** * Constructor. */ function NativeScaleTransform() { var _this = _super.call(this) || this; /** * The scaling vector. */ _this._scaling = new math_1.Vector2(); // Notify observers when scaling vector changes. var callback = function () { _this.notifyObservers(); }; _this._scaling.subscribeToChanges(callback); return _this; } Object.defineProperty(NativeScaleTransform.prototype, "scaling", { /** * Getter for the scaling vector. * @returns The scaling vector. */ get: function () { return this._scaling; }, enumerable: false, configurable: true }); Object.defineProperty(NativeScaleTransform.prototype, "matrix", { /** * Getter for the transformation matrix. * @returns The transformation matrix. */ get: function () { // Calculate the matrix from scaling vector. var matrix = new math_1.Matrix3().setScaling(this._scaling); return matrix; }, enumerable: false, configurable: true }); Object.defineProperty(NativeScaleTransform.prototype, "matrixNonNative", { /** * Getter for the transformation matrix, not including native transforms. * @returns The transformation matrix. */ get: function () { // Since this is a native transform only an identity transformation is returned here. var matrix = new math_1.Matrix3().setIdentity(); return matrix; }, enumerable: false, configurable: true }); Object.defineProperty(NativeScaleTransform.prototype, "nativeSvgTransform", { /** * Getter for the native SVG transform attribute string. * @returns The transform command string or null. */ get: function () { var command = null; // Only return the scaling if it's different than (1/1). if (this._scaling.x !== 1 || this._scaling.y !== 1) { command = "scale(".concat(this._scaling.x, ", ").concat(this._scaling.y, ")"); } return command; }, enumerable: false, configurable: true }); return NativeScaleTransform; }(transform_1.Transform)); exports.NativeScaleTransform = NativeScaleTransform;