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

ng-svg-editor

v0.0.24

Published

[![NG SVG Editor](https://github.com/rajeshkumaravel/ng-svg-editor/actions/workflows/run-test-cc.yml/badge.svg)](https://github.com/rajeshkumaravel/ng-svg-editor/actions/workflows/run-test-cc.yml) ![Coveralls](https://img.shields.io/coveralls/github/rajes

Downloads

41

Readme

NgSvgEditor

NG SVG Editor Coveralls Coveralls branch GitHub

ng-svg-editor is a lightweight and very complete Angular library for editing SVG template inside any Angular project. It was built for modern browsers using TypeScript, HTML5 and Angular >=12.x.x.


Getting started

How to use svg editor in your projects

Using library locally

Run the below command and use npm link under dist/svg-editor folder in your application

npm run watch

License

This project is licensed under the MIT License. See LICENSE for more information.

Table of contents


Installation

$ npm install --save ng-svg-editor

Import in Angular

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { SvgEditorModule } from 'svg-editor';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    SvgEditorModule
  ],
  providers: [ ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }
<svg-editor [togglePreview]="togglePreview" [onEdit]="onEdit" (elementClicked)="elementClicked($event)" [svgContent]="svgStringSanitized"></svg-editor>

Options

svg-editor comes with some parameters / options in order to make it fit your needs. The following parameters / options have to be used like this:

Note: image upload accepts either URL / base64 string

<svg-editor [parameter-or-option-name]="value"></svg-editor>

| Option | Type | Required | Description | | --- | --- | --- | --- | | svgContent | @@Input String | Yes | SVG content | icon | @@Input String | Optional | SVG edit icon | onEdit | @Input Observable | Yes | Observable Subject to send edited element, type and updated value | elementClicked | @Output EventEmitter | Yes | Event emitter when a SVG element is clicked | togglePreview | @Input Observable | Optional | Observable Subject for preview and edit toggle

Handle events

<svg-editor [togglePreview]="togglePreview" [onEdit]="onEdit" (elementClicked)="elementClicked($event)" [svgContent]="svgStringSanitized"></svg-editor>

elementClicked

Handling Event emitted when a SVG element is clicked

@Component({
  // ...
})
export class AppComponent {
  onEdit: Subject<any> = new Subject();
  selectedElement: any;
  constructor() {
  }

  public elementClicked(e: any) {
    this.selectedElement = e;
    if (e.type == 'text') {
      // If element clicked is `text`; execute editText method
      this.editText(e);
    } else {
      // If element clicked is `image`; execute imageUpload method
      this.imageUpload();
    }
  }
}

onEdit

Observable Subject to send edited element, type and updated value

@Component({
  // ...
})
export class AppComponent {
  onEdit: Subject<any> = new Subject();
  selectedElement: any;
  constructor() {
  }

  public elementClicked(e: any) {
    this.selectedElement = e;
    if (e.type == 'text') {
      // If element clicked is `text`; execute editText method
      this.editText(e);
    } else {
      // If element clicked is `image`; execute imageUpload method
      this.imageUpload();
    }
  }

  public editText(e: any) {
    let inputText = prompt("Provide updated value", e.element.textContent);
    if (inputText) {
      this.onEdit.next({
        element: e.element,
        type: 'text',
        value: inputText
      });
    }
  }

  imageUpload() {
    let text = "Upload image with URL; select cancel to upload image from your computer";
    if (confirm(text) == true) {
      let inputText = prompt("Provide image URL value");
      if (inputText) {
        this.onEdit.next({
          element: this.selectedElement.element,
          type: 'image',
          value: inputText
        });
      }
    } else {
      this.onEdit.next({
        element: this.selectedElement.element,
        type: 'image',
        value: <BASE_64 STRING>
      });
    }
  }
}

togglePreview

Toggle preview and edit on SVG template

  <div class="d-inline-flex flex-column mx-2">
    <h4>Toggle Edit / Preview</h4>
    <button *ngIf="previewButton == 'show'" type="button" class="btn btn-primary" (click)="toggleSVGPreview()">Preview</button>
    <button *ngIf="previewButton == 'hide'" type="button" class="btn btn-primary" (click)="toggleSVGPreview()">Edit</button>
  </div>
@Component({
  // ...
})
export class AppComponent {
  togglePreview: Subject<any> = new Subject();
  previewButton: string;
  constructor() {
    this.previewButton = 'show';
  }

  public toggleSVGPreview() {
    this.previewButton = this.previewButton == 'show' ? 'hide' : 'show';
    this.togglePreview.next(this.previewButton);
  }
}