UNPKG

tav-media

Version:

Cross platform media editing framework

345 lines (344 loc) 12.3 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var Matrix_1; import { PAGModule } from '../pag-module'; import { destroyVerify, wasmAwaitRewind } from '../utils/decorators'; let Matrix = Matrix_1 = class Matrix { constructor(wasmIns) { this.isDestroyed = false; this.wasmIns = wasmIns; } /** * Sets Matrix to: * * | scaleX skewX transX | * | skewY scaleY transY | * | pers0 pers1 pers2 | * * @param scaleX horizontal scale factor * @param skewX horizontal skew factor * @param transX horizontal translation * @param skewY vertical skew factor * @param scaleY vertical scale factor * @param transY vertical translation * @param pers0 input x-axis perspective factor * @param pers1 input y-axis perspective factor * @param pers2 perspective scale factor * @return Matrix constructed from parameters */ static makeAll(scaleX, skewX, transX, skewY, scaleY, transY, pers0 = 0, pers1 = 0, pers2 = 1) { const wasmIns = PAGModule._Matrix._MakeAll(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2); if (!wasmIns) throw new Error('Matrix.makeAll fail, please check parameters valid!'); return new Matrix_1(wasmIns); } /** * Sets Matrix to scale by (sx, sy). Returned matrix is: * * | sx 0 0 | * | 0 sy 0 | * | 0 0 1 | * * @param scaleX horizontal scale factor * @param scaleY [optionals] vertical scale factor, default equal scaleX. * @return Matrix with scale */ static makeScale(scaleX, scaleY) { let wasmIns; if (scaleY !== undefined) { wasmIns = PAGModule._Matrix._MakeScale(scaleX, scaleY); } else { wasmIns = PAGModule._Matrix._MakeScale(scaleX); } if (!wasmIns) throw new Error('Matrix.makeScale fail, please check parameters valid!'); return new Matrix_1(wasmIns); } /** * Sets Matrix to translate by (dx, dy). Returned matrix is: * * | 1 0 dx | * | 0 1 dy | * | 0 0 1 | * * @param dx horizontal translation * @param dy vertical translation * @return Matrix with translation */ static makeTrans(dx, dy) { const wasmIns = PAGModule._Matrix._MakeTrans(dx, dy); if (!wasmIns) throw new Error('Matrix.makeTrans fail, please check parameters valid!'); return new Matrix_1(wasmIns); } /** * scaleX; horizontal scale factor to store */ get a() { return this.wasmIns ? this.wasmIns._get(0 /* MatrixIndex.a */) : 0; } set a(value) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._set(0 /* MatrixIndex.a */, value); } /** * skewY; vertical skew factor to store */ get b() { return this.wasmIns ? this.wasmIns._get(3 /* MatrixIndex.b */) : 0; } set b(value) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._set(3 /* MatrixIndex.b */, value); } /** * skewX; horizontal skew factor to store */ get c() { return this.wasmIns ? this.wasmIns._get(1 /* MatrixIndex.c */) : 0; } set c(value) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._set(1 /* MatrixIndex.c */, value); } /** * scaleY; vertical scale factor to store */ get d() { return this.wasmIns ? this.wasmIns._get(4 /* MatrixIndex.d */) : 0; } set d(value) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._set(4 /* MatrixIndex.d */, value); } /** * transX; horizontal translation to store */ get tx() { return this.wasmIns ? this.wasmIns._get(2 /* MatrixIndex.tx */) : 0; } set tx(value) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._set(2 /* MatrixIndex.tx */, value); } /** * transY; vertical translation to store */ get ty() { return this.wasmIns ? this.wasmIns._get(5 /* MatrixIndex.ty */) : 0; } set ty(value) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._set(5 /* MatrixIndex.ty */, value); } /** * Returns one matrix value. */ get(index) { return this.wasmIns ? this.wasmIns._get(index) : 0; } /** * Sets Matrix value. */ set(index, value) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._set(index, value); } /** * Sets all values from parameters. Sets matrix to: * * | scaleX skewX transX | * | skewY scaleY transY | * | persp0 persp1 persp2 | * * @param scaleX horizontal scale factor to store * @param skewX horizontal skew factor to store * @param transX horizontal translation to store * @param skewY vertical skew factor to store * @param scaleY vertical scale factor to store * @param transY vertical translation to store * @param persp0 input x-axis values perspective factor to store * @param persp1 input y-axis values perspective factor to store * @param persp2 perspective scale factor to store */ setAll(scaleX, skewX, transX, skewY, scaleY, transY, pers0 = 0, pers1 = 0, pers2 = 1) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._setAll(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2); } setAffine(a, b, c, d, tx, ty) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._setAffine(a, b, c, d, tx, ty); } /** * Sets Matrix to identity; which has no effect on mapped Point. Sets Matrix to: * * | 1 0 0 | * | 0 1 0 | * | 0 0 1 | * * Also called setIdentity(); use the one that provides better inline documentation. */ reset() { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._reset(); } /** * Sets Matrix to translate by (dx, dy). * @param dx horizontal translation * @param dy vertical translation */ setTranslate(dx, dy) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._setTranslate(dx, dy); } /** * Sets Matrix to scale by sx and sy, about a pivot point at (px, py). The pivot point is * unchanged when mapped with Matrix. * @param sx horizontal scale factor * @param sy vertical scale factor * @param px pivot on x-axis * @param py pivot on y-axis */ setScale(sx, sy, px = 0, py = 0) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._setScale(sx, sy, px, py); } /** * Sets Matrix to rotate by degrees about a pivot point at (px, py). The pivot point is * unchanged when mapped with Matrix. Positive degrees rotates clockwise. * @param degrees angle of axes relative to upright axes * @param px pivot on x-axis * @param py pivot on y-axis */ setRotate(degrees, px = 0, py = 0) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._setRotate(degrees, px, py); } /** * Sets Matrix to rotate by sinValue and cosValue, about a pivot point at (px, py). * The pivot point is unchanged when mapped with Matrix. * Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1). * Vector length specifies scale. */ setSinCos(sinV, cosV, px = 0, py = 0) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._setSinCos(sinV, cosV, px, py); } /** * Sets Matrix to skew by kx and ky, about a pivot point at (px, py). The pivot point is * unchanged when mapped with Matrix. * @param kx horizontal skew factor * @param ky vertical skew factor * @param px pivot on x-axis * @param py pivot on y-axis */ setSkew(kx, ky, px = 0, py = 0) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._setSkew(kx, ky, px, py); } /** * Sets Matrix to Matrix a multiplied by Matrix b. Either a or b may be this. * * Given: * * | A B C | | J K L | * a = | D E F |, b = | M N O | * | G H I | | P Q R | * * sets Matrix to: * * | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR | * a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR | * | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR | * * @param a Matrix on left side of multiply expression * @param b Matrix on right side of multiply expression */ setConcat(a, b) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._setConcat(a.wasmIns, b.wasmIns); } /** * Preconcats the matrix with the specified scale. M' = M * S(sx, sy) */ preTranslate(dx, dy) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._preTranslate(dx, dy); } /** * Postconcats the matrix with the specified scale. M' = S(sx, sy, px, py) * M */ preScale(sx, sy, px = 0, py = 0) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._preScale(sx, sy, px, py); } /** * Preconcats the matrix with the specified rotation. M' = M * R(degrees, px, py) */ preRotate(degrees, px = 0, py = 0) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._preRotate(degrees, px, py); } /** * Preconcats the matrix with the specified skew. M' = M * K(kx, ky, px, py) */ preSkew(kx, ky, px = 0, py = 0) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._preSkew(kx, ky, px, py); } /** * Preconcats the matrix with the specified matrix. M' = M * other */ preConcat(other) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._preConcat(other.wasmIns); } /** * Postconcats the matrix with the specified translation. M' = T(dx, dy) * M */ postTranslate(dx, dy) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._postTranslate(dx, dy); } /** * Postconcats the matrix with the specified scale. M' = S(sx, sy, px, py) * M */ postScale(sx, sy, px = 0, py = 0) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._postScale(sx, sy, px, py); } /** * Postconcats the matrix with the specified rotation. M' = R(degrees, px, py) * M */ postRotate(degrees, px = 0, py = 0) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._postRotate(degrees, px, py); } /** * Postconcats the matrix with the specified skew. M' = K(kx, ky, px, py) * M */ postSkew(kx, ky, px = 0, py = 0) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._postSkew(kx, ky, px, py); } /** * Postconcats the matrix with the specified matrix. M' = other * M */ postConcat(other) { var _a; (_a = this.wasmIns) === null || _a === void 0 ? void 0 : _a._postConcat(other.wasmIns); } destroy() { this.wasmIns.delete(); } }; Matrix = Matrix_1 = __decorate([ destroyVerify, wasmAwaitRewind ], Matrix); export { Matrix };