UNPKG

ng-cw-v12

Version:

Angular UI component library

209 lines (200 loc) 9.52 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) : typeof define === 'function' && define.amd ? define('ng-cw-v12/typing-text', ['exports', '@angular/core'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global["ng-cw-v12"] = global["ng-cw-v12"] || {}, global["ng-cw-v12"]["typing-text"] = {}), global.ng.core)); })(this, (function (exports, i0) { 'use strict'; function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n["default"] = e; return Object.freeze(n); } var i0__namespace = /*#__PURE__*/_interopNamespace(i0); var TypingTextComponent = /** @class */ (function () { function TypingTextComponent(elementRef) { this.elementRef = elementRef; /** 展示的文本内容 */ this._text = ''; /** 每个字符之间的延迟 */ this.ncDelayMultiple = 100; /** 每个字符之间的间距 */ this.ncGap = 0; /** 延迟 */ this.ncDelay = 0; /** 是否在视图可见时才开始动画 */ this._startOnView = false; /** 是否只执行一次动画 */ this._once = false; this.displayedText = ''; this.observer = null; this.typingInterval = null; this.timeout = null; } Object.defineProperty(TypingTextComponent.prototype, "ncText", { get: function () { return this._text; }, set: function (value) { var _this = this; this._text = value; setTimeout(function () { _this.start(); }); }, enumerable: false, configurable: true }); Object.defineProperty(TypingTextComponent.prototype, "ncStartOnView", { get: function () { return this._startOnView; }, set: function (val) { this._startOnView = val !== null && val !== undefined && val !== false && val !== 'false'; }, enumerable: false, configurable: true }); Object.defineProperty(TypingTextComponent.prototype, "ncOnce", { get: function () { return this._once; }, set: function (val) { this._once = val !== null && val !== undefined && val !== false && val !== 'false'; }, enumerable: false, configurable: true }); TypingTextComponent.prototype.ngOnInit = function () { }; TypingTextComponent.prototype.ngOnDestroy = function () { this.clear(); }; TypingTextComponent.prototype.start = function () { var _this = this; this.clear(); if (!this.ncStartOnView) { this.timeout = setTimeout(function () { _this.startTyping(); }, this.ncDelay); } else { this.setupIntersectionObserver(); } }; TypingTextComponent.prototype.clear = function () { if (this.observer) { this.observer.disconnect(); } if (this.typingInterval) { clearInterval(this.typingInterval); } if (this.timeout) { clearTimeout(this.timeout); } }; TypingTextComponent.prototype.setupIntersectionObserver = function () { var _this = this; this.observer = new IntersectionObserver(function (entries) { if (entries[0].isIntersecting) { _this.timeout = setTimeout(function () { _this.startTyping(); }, _this.ncDelay); if (_this.ncOnce) { if (_this.observer) { _this.observer.disconnect(); } } } else if (!_this.ncOnce) { _this.endTyping(); } }, { threshold: 0.1 }); this.observer.observe(this.elementRef.nativeElement); }; TypingTextComponent.prototype.startTyping = function () { var _this = this; var i = 0; this.typingInterval = setInterval(function () { if (i < _this.ncText.length) { _this.displayedText = _this.ncText.substring(0, i + 1); i++; } else { clearInterval(_this.typingInterval); } }, this.ncDelayMultiple); }; TypingTextComponent.prototype.endTyping = function () { //若执行动画(startTyping)内部正在执行,则清除动画 if (this.typingInterval) { clearInterval(this.typingInterval); } //若存在ncDelay,离开视图后,进入动画(startTyping)可能还未执行,则需要清除timeout if (this.timeout) { clearTimeout(this.timeout); } //隐藏显示的文本 this.displayedText = ''; }; return TypingTextComponent; }()); TypingTextComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0__namespace, type: TypingTextComponent, deps: [{ token: i0__namespace.ElementRef }], target: i0__namespace.ɵɵFactoryTarget.Component }); TypingTextComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.5", type: TypingTextComponent, selector: "nc-typing-text", inputs: { ncText: "ncText", ncDelayMultiple: "ncDelayMultiple", ncGap: "ncGap", ncDelay: "ncDelay", ncStartOnView: "ncStartOnView", ncOnce: "ncOnce" }, ngImport: i0__namespace, template: "<div class=\"typing-text-container\" style=\"--gap: {{ncGap}}px;\">\r\n {{ displayedText }}\r\n</div>", styles: [".typing-text-container{width:-moz-fit-content;width:fit-content;letter-spacing:var(--gap)}\n"] }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0__namespace, type: TypingTextComponent, decorators: [{ type: i0.Component, args: [{ selector: 'nc-typing-text', templateUrl: './typing-text.component.html', styleUrls: ['./typing-text.component.less'] }] }], ctorParameters: function () { return [{ type: i0__namespace.ElementRef }]; }, propDecorators: { ncText: [{ type: i0.Input }], ncDelayMultiple: [{ type: i0.Input }], ncGap: [{ type: i0.Input }], ncDelay: [{ type: i0.Input }], ncStartOnView: [{ type: i0.Input }], ncOnce: [{ type: i0.Input }] } }); var NcTypingTextModule = /** @class */ (function () { function NcTypingTextModule() { } return NcTypingTextModule; }()); NcTypingTextModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0__namespace, type: NcTypingTextModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule }); NcTypingTextModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0__namespace, type: NcTypingTextModule, declarations: [TypingTextComponent], exports: [TypingTextComponent] }); NcTypingTextModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0__namespace, type: NcTypingTextModule, imports: [[]] }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.5", ngImport: i0__namespace, type: NcTypingTextModule, decorators: [{ type: i0.NgModule, args: [{ declarations: [ TypingTextComponent ], imports: [], exports: [ TypingTextComponent ] }] }] }); /** * Generated bundle index. Do not edit. */ exports.NcTypingTextModule = NcTypingTextModule; exports.TypingTextComponent = TypingTextComponent; Object.defineProperty(exports, '__esModule', { value: true }); })); //# sourceMappingURL=ng-cw-v12-typing-text.umd.js.map