UNPKG

agora-edu-core

Version:

Core APIs for building an online classroom

257 lines (256 loc) 11.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Track = void 0; var _decorator = require("agora-rte-sdk/lib/core/decorator"); var _mobx = require("mobx"); var _helper = require("./helper"); var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class, _class2, _descriptor, _descriptor2, _descriptor3; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _initializerDefineProperty(e, i, r, l) { r && Object.defineProperty(e, i, { enumerable: r.enumerable, configurable: r.configurable, writable: r.writable, value: r.initializer ? r.initializer.call(l) : void 0 }); } function _applyDecoratedDescriptor(i, e, r, n, l) { var a = {}; return Object.keys(n).forEach(function (i) { a[i] = n[i]; }), a.enumerable = !!a.enumerable, a.configurable = !!a.configurable, ("value" in a || a.initializer) && (a.writable = !0), a = r.slice().reverse().reduce(function (r, n) { return n(i, e, r) || r; }, a), l && void 0 !== a.initializer && (a.value = a.initializer ? a.initializer.call(l) : void 0, a.initializer = void 0), void 0 === a.initializer ? (Object.defineProperty(i, e, a), null) : a; } function _initializerWarningHelper(r, e) { throw Error("Decorating class property failed. Please ensure that transform-class-properties is enabled and runs after the decorators transform."); } let Track = exports.Track = (_dec = _decorator.Log.attach({ proxyMethods: false }), _dec2 = _mobx.action.bound, _dec3 = _mobx.action.bound, _dec4 = _mobx.action.bound, _dec5 = _mobx.action.bound, _dec6 = _mobx.action.bound, _dec7 = _mobx.action.bound, _dec8 = _mobx.action.bound, _dec(_class = (_class2 = class Track { constructor(context, _posOnly) { this._posOnly = _posOnly; _initializerDefineProperty(this, "_localVal", _descriptor, this); _initializerDefineProperty(this, "_ratioVal", _descriptor2, this); _initializerDefineProperty(this, "_visible", _descriptor3, this); this._context = void 0; this._needTransition = false; this._context = context; } get realVal() { return this._localVal; } get ratioVal() { return this._ratioVal; } get isCovered() { return this._ratioVal.ratioDimensions.height === 1 && this._ratioVal.ratioDimensions.width === 1; } get visible() { return this._visible; } get needTransition() { return this._needTransition; } get trackContext() { return this._context; } setReal(position, dimensions, needTransition) { const { width, height } = this._context.outerSize; const medX = width - dimensions.width; const medY = height - dimensions.height; this._ratioVal = (0, _helper.convertLocalToRatio)(this.fixPos(position, true), dimensions, medX, medY, this._context.outerSize); this._localVal = { position: { x: position.x, y: position.y }, dimensions: { width: dimensions.width, height: dimensions.height } }; this._needTransition = !!needTransition; } setRealPos(position, needTransition) { const { width, height } = this._context.outerSize; const medX = width - this._localVal.dimensions.width; const medY = height - this._localVal.dimensions.height; const { ratioPosition } = (0, _helper.convertLocalPositionToRatio)(this.fixPos(position, true), medX, medY); this._ratioVal = { ratioPosition, ratioDimensions: this._ratioVal.ratioDimensions }; this._localVal = { position: { x: position.x, y: position.y }, dimensions: this._localVal.dimensions }; this._needTransition = !!needTransition; } setRealDimensions(dimensions, needTransition) { const { ratioDimensions } = (0, _helper.convertLocalDimensionsToRatio)(dimensions, this._context.outerSize); this._ratioVal = { ratioDimensions, ratioPosition: this._ratioVal.ratioPosition }; this._localVal = { dimensions: { width: dimensions.width, height: dimensions.height }, position: this._localVal.position }; this._needTransition = !!needTransition; } setRatio(position, dimensions, needTransition) { if (this._posOnly) { this._localVal = (0, _helper.convertRatioToLocalWithFixedDimensions)({ ratioX: position.x, ratioY: position.y }, dimensions, this._context.outerSize, this._context.resizeBounds); } else { this._localVal = (0, _helper.convertRatioToLocal)({ ratioX: position.x, ratioY: position.y }, { ratioWidth: dimensions.width, ratioHeight: dimensions.height }, this._context.outerSize, this._context.resizeBounds); } this._localVal.position = this.fixPos(this._localVal.position, false); this._ratioVal = { ratioPosition: { x: position.x, y: position.y }, ratioDimensions: { width: dimensions.width, height: dimensions.height } }; this._needTransition = !!needTransition; } setRatioPos(ratioPos, needTransition) { if (this._posOnly) { const { position } = (0, _helper.convertRatioToLocalPositionWithFixedDimensions)({ ratioX: ratioPos.x, ratioY: ratioPos.y }, this._localVal.dimensions, this._context.outerSize, this._context.resizeBounds); this._localVal = { position, dimensions: this._localVal.dimensions }; } else { const { position } = (0, _helper.convertRatioToLocalPosition)({ ratioX: ratioPos.x, ratioY: ratioPos.y }, { ratioWidth: this._ratioVal.ratioDimensions.width, ratioHeight: this._ratioVal.ratioDimensions.height }, this._context.outerSize, this._context.resizeBounds); this._localVal = { position, dimensions: this._localVal.dimensions }; } this._localVal.position = this.fixPos(this._localVal.position, false); this._ratioVal = { ratioPosition: { x: ratioPos.x, y: ratioPos.y }, ratioDimensions: this._ratioVal.ratioDimensions }; this._needTransition = !!needTransition; } setRatioDimensions(ratioDimensions, needTransition) { const { dimensions } = (0, _helper.convertRatioToLocalDimensions)({ ratioWidth: ratioDimensions.width, ratioHeight: ratioDimensions.height }, this._context.outerSize, this._context.resizeBounds); this._localVal = { dimensions, position: this._localVal.position }; this._ratioVal = { ratioDimensions: { width: ratioDimensions.width, height: ratioDimensions.height }, ratioPosition: this._ratioVal.ratioPosition }; this._needTransition = !!needTransition; } fixPos(pos, local) { const { left, top } = this._context.offset; return { x: local ? pos.x - left : pos.x + left, y: local ? pos.y - top : pos.y + top }; } updateContext(context) { this._context = _objectSpread(_objectSpread({}, this._context), context); } setVisibility(visible) { this._visible = visible; } reposition() { let needTransition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; if (this._posOnly) { this.setRatioPos(this._ratioVal.ratioPosition, needTransition); } else { this.setRatio(this._ratioVal.ratioPosition, this._ratioVal.ratioDimensions, needTransition); } } }, _descriptor = _applyDecoratedDescriptor(_class2.prototype, "_localVal", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return { position: { x: 0, y: 0 }, dimensions: { width: 0, height: 0 } }; } }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "_ratioVal", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return { ratioPosition: { x: 0, y: 0 }, ratioDimensions: { width: 0, height: 0 } }; } }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "_visible", [_mobx.observable], { configurable: true, enumerable: true, writable: true, initializer: function () { return true; } }), _applyDecoratedDescriptor(_class2.prototype, "realVal", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "realVal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "ratioVal", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "ratioVal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "isCovered", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "isCovered"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "visible", [_mobx.computed], Object.getOwnPropertyDescriptor(_class2.prototype, "visible"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setReal", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "setReal"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setRealPos", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "setRealPos"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setRealDimensions", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "setRealDimensions"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setRatio", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "setRatio"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setRatioPos", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "setRatioPos"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setRatioDimensions", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "setRatioDimensions"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "updateContext", [_decorator.bound], Object.getOwnPropertyDescriptor(_class2.prototype, "updateContext"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "setVisibility", [_dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "setVisibility"), _class2.prototype), _class2)) || _class);