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

angular-collision

v1.0.2

Published

### Angular 10 library for elements collision detection

Downloads

4

Readme

NgCollision

Angular 10 library for elements collision detection

Auto-generated documentation

Example

  • Install
npm i angular-collision
  • Module (add AngularCollisionModule to imports, forRoot is optional to pass config - in this case disable interval collision checking)
import { AngularCollisionModule, NgcConfig } from 'angular-collision';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    AngularCollisionModule.forRoot(new NgcConfig(true)),
    CommonModule,
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}
  • Template (add ngcAngularCollision directive to any element)
  <div
    *ngFor="let rectangle of rectangles"
    class="rect"
    ngcAngularCollision
    #directiveRef="ngcAngularCollision"
    (rectangleChange)="handleRectChange($event, rectangle.name)"
    (collisionActiveChange)="handleCollisionActiveChange($event)"
  >
    <span>Example element ({{ directiveRef.collision$ | async }})</span>
      <div *ngIf="rectangle.position">
        <div>X: {{ position.x | number: '1.0-0' }}px</div>
        <div>Y: {{ position.y | number: '1.0-0' }}px</div>
        <div>W: {{ position.width | number: '1.0-0' }}px</div>
        <div>H: {{ position.height | number: '1.0-0' }}px</div>
      </div>
  </div>
  • SCSS (class collision is applied by directive to host element)
.collision {
  border-color: red;
}

.rect {
  width: 150px;
  height: 150px;
  border: 2px solid transparent;
  position: relative;


  &__one {
    top: 100px;
    left: 100px;
  }

  &__two {
    top: 50px;
    left: 150px;
  }

   &__three {
    top: 250px;
    left: 300px;
   }
}
  • Component (register elements to collision checking with AngularCollisionService)
import {
  AngularCollisionService,
  AngularCollisionDirective,
  NgcCollisionChange,
  NgcElementChange,
} from 'angular-collision';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent implements AfterViewInit {
  @ViewChildren(AngularCollisionDirective) elements: QueryList<
    AngularCollisionDirective
  >;

  public collisions: Map<number, NgcCollisionChange> = new Map();

  public rectangles: Array<{ name: string, position: DOMRect }> = [
    {
      name: 'one,
      position: null,
    },
    {
      name: 'two',
      position: null,
    },
    {
      name: 'three',
      position: null,
    },
  ];

  constructor(public service: AngularCollisionService) {}

  public ngAfterViewInit(): void {
    // Register elements for collision detection
    this.service.register(this.elements);

    setTimeout(() => {
      this.stopTrackingFirstElement();
    }, 10000);
  }

  public stopTrackingFirstElement(): void {
    // Remove first element from tracking
    this.service.remove(this.elements.first);
  }

  public handleRectChange(
    position: NgcElementChange,
    rectangleName: RectanglesEnum
  ): void {
    // Handle position changes
    this.rectangles.find(
      (rectangle) => rectangle.name === rectangleName
    ).position = position.domRect;
  }

  public handleCollisionActiveChange(change: NgcCollisionChange): void {
    // Handle collisions
    this.collisions.set(change.id, change);
  }
}

Running demo app

ng serve demo-app

Drag & drop made with angular/cdk. Not a part of library.

Generate docs

Documentation is auto-generated every commit.

You can also generate docs manually by: npm run compodoc

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory. Use the --prod flag for a production build.

Running unit tests

Run ng test to execute the unit tests via Karma.

Running end-to-end tests

Run ng e2e to execute the end-to-end tests via Protractor.