ng-cw-v12 Component Library

website·Indexed 31 days ago

https://nc12.chenxiaopa.cn

A component library based on Angular 12 featuring a wide array of UI elements including animation backgrounds (PrismBackground, LightRaysBackground), text effects (Highlighter, AnimatedShinyText, TypingText), and specialized viewers (GltfViewer, PdfViewer, WordViewer). It also provides utility services such as NcCommonService, NcMouseTooltipService, and NcHtml2canvasService for enhanced development efficiency.

Tokens
23.2K
Snippets
179
Records
209
Agent score
50%

What's inside ng-cw-v12

  1. Install and import VideoEasy player module

    The VideoEasy player is a component based on easyplayer that supports HLS formats (H.264 and H.265). To use it in an Angular project, import the NcVideoEasyModule from the ng-cw-v12/video-easy package.
    import { NcVideoEasyModule } from 'ng-cw-v12/video-easy';
  2. Install and import the ImgEnlargement module

    To use the image enlargement preview component, import the NcImgEnlargementModule from the ng-cw-v12/img-enlargement package.
    import { NcImgEnlargementModule } from 'ng-cw-v12/img-enlargement';
  3. Apply UI Directives for common interactions

    Several directives are available to enhance element behavior:

    • ClickOutside: Triggers an action when a user clicks outside a specific element.
    • Ripple: Adds a ripple effect to elements (supports border-radius and container positioning).
    • Ribbon: Adds a ribbon decoration to elements.
    • HorizontalScroll: Enables mouse-based horizontal scrolling.
    • Spin: Provides a 'loading' state directive.
  4. Use 3D Model Viewers (GltfViewer and ObjViewer)

    The library provides components for 3D model visualization:

    • GltfViewer: Supports GLTF models with animation controls and a collapsible environment light panel.
    • ObjViewer: Supports OBJ models. Features include loading progress indicators, spherical background textures, automatic rotation (with configurable speed), and automatic texture path resolution (defaults to the same directory as the .obj file).
  5. Install and import FlipText module

    To use the FlipText character animation component, import the NcFlipTextModule from the ng-cw-v12/flip-text package.
    import { NcFlipTextModule } from 'ng-cw-v12/flip-text';
  6. Implement horizontal mouse wheel scrolling with ncHorizontalScroll

    The ncHorizontalScroll directive allows a host element to be scrolled horizontally using the mouse wheel. To use this directive, import the NcHorizontalScrollModule into your Angular module.
    import { NcHorizontalScrollModule } from 'ng-cw-v12/horizontal-scroll';

    <!-- Basic Usage --> <div class="demoDom" ncHorizontalScroll> <div class="demoDomItem" *ngFor="let i of itemsList">{{ i }}</div> </div>

    <style> .demoDom { display: flex; height: 67px; overflow-x: auto; /* Ensure overflow is handled */ } .demoDomItem { width: 100px; height: 50px; background-color: rgb(0, 204, 255); margin: 0 10px; flex-shrink: 0; color: white; line-height: 50px; text-align: center; } </style>

  7. Implement a base HTTP service for Angular with unified error handling

    Create a HttpService that wraps Angular's HttpClient to provide a centralized way to handle authentication tokens, set default headers, and process program-level errors. This service abstracts GET, POST, and Blob requests, ensuring that every request includes the necessary Authorization bearer token and that errors are displayed via a notification service (e.g., NzMessageService).
    import { Injectable } from '@angular/core';
    import { HttpHeaders, HttpErrorResponse, HttpClient } from '@angular/common/http';
    import { Observable, throwError } from 'rxjs';
    import { map, catchError } from 'rxjs/operators';
    import { NzMessageService } from 'ng-zorro-antd/message';
    
    @Injectable({
        providedIn: 'root'
    })
    export class HttpService {
        constructor(private http: HttpClient, private message: NzMessageService) { }
    
        get<T>(url: string): Observable<T> {
            const headers = this.createHeaders('application/json');
            return this.http.get<T>(url, { headers }).pipe(
                map(this.extractData),
                catchError(this.handleError)
            );
        }
    
        post<T>(url: string, body: any): Observable<T> {
            const headers = this.createHeaders('application/json');
            return this.http.post<T>(url, body, { headers }).pipe(
                map(this.extractData),
                catchError(this.handleError)
            );
        }
    
        postBlob<T>(url: string, body: any): Observable<T> {
            const headers = this.createHeaders('application/json');
            return this.http.post<T>(url, body, { headers , responseType: 'blob' as 'json' }).pipe(
                map(this.extractData),
                catchError(this.handleError)
            );
        }
    
        private createHeaders(contentType?: string): HttpHeaders {
            let headers: HttpHeaders = new HttpHeaders();
            if (contentType) {
                headers = headers.set('Content-Type', contentType);
            }
            if (this.token) {
                headers = headers.set('Authorization', `Bearer ${this.token}`);
            }
            return headers;
        }
    
        private extractData(res: any) {
            return res || {};
        }
    
        private handleError = (error: HttpErrorResponse) => {
            let errorMessage = '';
            if (error.error instanceof ErrorEvent) {
                errorMessage = `错误: ${error.error.message}`;
            } else {
                errorMessage = `服务器返回代码: ${error.status}, 错误信息: ${error.message}`;
            }
            this.message.error(errorMessage, { nzDuration: 5000 });
            return throwError(new Error(errorMessage));
        }
    }
  8. Install and import ImgZoom module

    To use the ImgZoom functionality, import the NcImgZoomModule from the ng-cw-v12/img-zoom package into your Angular module.
    import { NcImgZoomModule } from 'ng-cw-v12/img-zoom';
  9. Use Document Viewers for file previews

    The library provides a suite of viewer components for common file types:

    • PdfViewer: For PDF documents.
    • WordViewer: For Word documents.
    • ExcelViewer: For Excel spreadsheets.
    • TxtViewer: For plain text files.
  10. Import and use the AutoScrollText component

    The AutoScrollText component creates a scrolling text effect. To use it, import the NcAutoScrollTextModule from the ng-cw-v12/auto-scroll-text package.
    import { NcAutoScrollTextModule } from 'ng-cw-v12/auto-scroll-text';
  11. Install and import AnimatedGradientText

    To use the AnimatedGradientText component, import the NcAnimatedGradientTextModule from the ng-cw-v12/animated-gradient-text package. If you need to specify the animation direction using the provided type, import NcDirectionType.
    import { NcAnimatedGradientTextModule } from 'ng-cw-v12/animated-gradient-text';
    import { NcDirectionType } from 'ng-cw-v12/animated-gradient-text';
  12. Install and import WordViewer module

    To use the Word preview component, import the NcWordViewerModule from the ng-cw-v12/word-viewer package into your Angular module.
    import { NcWordViewerModule } from 'ng-cw-v12/word-viewer';