npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-annotate-text

v17.2.0

Published

An Angular component library for interactively highlighting / annotating parts of text.

Downloads

690

Readme

ngx-annotate-text

Edit ngx-annotate-text demo

An Angular component library for interactively highlighting / annotating parts of text.

Screenshot

Features

  • :point_up_2: Interactively mark entities such as cities, numbers, dates, etc.
  • :wastebasket: Interactively remove annotations / marked entities.
  • :tada: Purely based on CSS. No magic, no canvas, and no SVGs.

Demo

Edit ngx-annotate-text demo

View and edit the live demo Angular app on codesandbox.io or look through the code of the demo app in ngx-annotate-text/src/app/.

Screen recording:

Screen recording GIF

Usage

  1. Install the NPM package:

    npm install ngx-annotate-text
  2. Import the Angular module NgxAnnotateTextModule:

    import { BrowserModule } from "@angular/platform-browser";
    import { NgModule } from "@angular/core";
    
    import { AppComponent } from "./app.component";
    import { NgxAnnotateTextModule } from "ngx-annotate-text";
    
    @NgModule({
      declarations: [AppComponent],
      imports: [BrowserModule, NgxAnnotateTextModule],
      providers: [],
      bootstrap: [AppComponent],
    })
    export class AppModule {}
  3. Add the component ngx-annotate-text to your template:

    <ngx-annotate-text
      [(annotations)]="annotations"
      [removable]="true"
      [text]="text"
      annotationClass="my-annotation"
      #annotateText
    >
    </ngx-annotate-text>
  4. Create properties in your component class for the text to be annotated and an (empty) array of annotations:

    import { Component, ViewChild } from "@angular/core";
    import { Annotation, NgxAnnotateTextComponent } from "ngx-annotate-text";
    
    @Component({
      selector: "app-root",
      templateUrl: "./app.component.html",
      styleUrls: ["./app.component.css"],
    })
    export class AppComponent {
      text: string =
        "On August 1, we went on vacation to Barcelona, Spain. Our flight took off at 11:00 am.";
    
      annotations: Annotation[] = [
        new Annotation(3, 11, "Date", "#0069d9"),
        new Annotation(36, 45, "City", "#dc3545"),
        new Annotation(47, 52, "Country", "#28a745"),
        new Annotation(77, 85, "Time", "#5a6268"),
      ];
    }
  5. Having set annotationClass="my-annotation", a custom CSS styling can be applied by combining ::ng-deep with the class selector .my-annotation, e.g., to remove the border-radius:

    ::ng-deep .my-annotation .annotation-parent,
    ::ng-deep .my-annotation .annotation-content {
      border-radius: 0rem !important;
    }

API - NgxAnnotateText

Inputs

| Input | Description | Type | Default value | | :-------------- | ------------------------------------------------------------ | ------------------ | :------------ | | annotations | Represents the parts of the given text which shall be annotated. | Annotation[] | [] | | annotationClass | An optional CSS class applied to all elements which wrap the annotated parts of the given text. | string|undefined | undefined | | removable | Determines whether annotations shall have a small button in the top right corner so that the user can remove an annotation. | boolean | true | | text | The text which shall be displayed and annotated. | string | empty string |

Outputs

| Output | Description | Type | | ----------------- | ----------------------------------------------------------------------------------------------------------------------- | ---------------------------- | | annotationsChange | Emits the list of existing annotations after an element has been removed by the user. | EventEmitter<Annotation[]> | | clickAnnotation | Emits the selected annotation when the user clicks on an annotation's box, the label or text. | EventEmitter<Annotation> | | removeAnnotation | Emits the selected annotation when the user removes it by clicking the annotation's X button in the upper right corner. | EventEmitter<Annotation> |

Methods

| Method | Description | Return type | | ------------------------------------ | ------------------------------------------------------------ | ---------------------- | | getCurrentTextSelection | Returns the start index and end index of the currently selected text range. Returns undefined if no text is currently selected. | ISelection|undefined | | isOverlappingWithExistingAnnotations | Returns true if the given text selection is (partially) overlapping with an existing annotation. Returns false otherwise. | boolean |

Development

Recreate project from scratch

npm install -g @angular/cli@^16
ng new ngx-annotate-text-workspace
cd ngx-annotate-text-workspace/
ng generate library ngx-annotate-text
ng add @angular-eslint/schematics
npm install prettier

Build

Run ng build ngx-annotate-text to build the project. The build artifacts will be stored in the dist/ directory.

Running the demo app

Run ng serve --open to start the demo app in your browser.

Running linting tools

Run ng lint ngx-annotate-text to execute ESLint.

Running unit tests

Run ng test ngx-annotate-text --code-coverage to execute the unit tests via Karma. Don't forget to set the environment variable for where to find Chrome / Chromium like so: export CHROME_BIN=/snap/bin/chromium.

Publish library as an npm package

:warning: Don't manually publish to npmjs.org, there is a pipeline that runs automatically when a new release is created.

ng build ngx-annotate-text --configuration production
cd dist/ngx-annotate-text
npm publish

Development server

Build the library in watch mode:

ng build ngx-annotate-text --watch

Run the Angular dev server:

ng serve --open

Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.