UNPKG

@qier-player/danmaku

Version:

Powerful danmaku, support many features.

100 lines 3.83 kB
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 __()); }; })(); import Base from './base'; import { dispose, addDisposeListener } from '../utils/dispose'; import { removeEle } from '../utils/dom'; import { setBlurStyle, setHoverStyle } from '../helper'; import { EVENT } from '../constants'; var BaseRolling = /** @class */ (function (_super) { __extends(BaseRolling, _super); function BaseRolling(danmaku, el, config, options) { var _this = _super.call(this, config, options) || this; _this.danmaku = danmaku; _this.objToElm = new WeakMap(); _this.elmToObj = new WeakMap(); _this.staticDanmu = null; _this.el = el; var proxyEl = options.eventProxyElement; if (proxyEl) { addDisposeListener(_this, proxyEl, 'mouseover', _this.mouseOverEventHandler.bind(_this)); addDisposeListener(_this, proxyEl, 'mouseout', _this.mouseOutEventHandler.bind(_this)); addDisposeListener(_this, proxyEl, 'click', _this.mouseClickEventHandler.bind(_this)); } return _this; } BaseRolling.prototype.mouseOverEventHandler = function (e) { var target = e.target; if (!target) { return; } var newStaticDanmu = this.elmToObj.get(target); var oldStaticDanmu = this.staticDanmu; if (newStaticDanmu === oldStaticDanmu) { return; } this.staticDanmu = null; if (newStaticDanmu) { this.staticDanmu = newStaticDanmu; newStaticDanmu.static = true; setHoverStyle(target); this.danmaku.emit(EVENT.HOVER, newStaticDanmu, target); } }; BaseRolling.prototype.mouseOutEventHandler = function (e) { var target = e.target; if (!target) { return; } var staticDanmu = this.elmToObj.get(target); this.staticDanmu = null; if (staticDanmu) { staticDanmu.static = false; var oldStaticEle = this.objToElm.get(staticDanmu); oldStaticEle && setBlurStyle(oldStaticEle); this.danmaku.emit(EVENT.BLUR, staticDanmu, oldStaticEle); } }; BaseRolling.prototype.mouseClickEventHandler = function (e) { var target = e.target; var danmu = this.elmToObj.get(target); if (danmu) { this.danmaku.emit(EVENT.CLICK, danmu, target); } }; BaseRolling.prototype.removeElement = function (target) { this.el.removeChild(target); }; BaseRolling.prototype.reset = function () { var _this = this; this.each(function (track) { track.each(function (danmu) { var el = _this.objToElm.get(danmu); if (!el) { return; } _this.removeElement(el); }); track.reset(); }); }; BaseRolling.prototype.dispose = function () { removeEle(this.el); dispose(this); }; return BaseRolling; }(Base)); export default BaseRolling; //# sourceMappingURL=base-rolling.js.map