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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ngx-kit/styler

v1.0.0-beta.15

Published

ngx-kit - styler

Downloads

57

Readme

Build Status npm version

Angular Styler

Keep CSS in TypeScript.

Currently in a deep beta!

Install

npm install @ngx-kit/styler --save

Usage

Provide module

import { StylerModule } from '@ngx-kit/styler';
...
@NgModule({
  imports: [
      ...
      StylerModule.forRoot(),
...

Use import with .forRoot() only once on the top level.

Add styles to component

...
@Component({
  ...
  viewProviders: [StylerComponent]
  ...
  constructor(private styler: StylerComponent) {
    this.styler.register({
      wrapper: {
        background: '#ffffff',
        color: 'red',
      },
      inside: {
        color: 'yellow',
        fontSize: '2rem',
      }
    });
    ...

Use styles in template

<div styler="wrapper">
  <div styler="inside">
  </div>
</div>

Cases

:host styling

Just define host element:

this.styler.register({
  host: {
    display: 'flex',
    flexDirection: 'column',
  },
});

Nested styles

this.styler.register({
  wrapper: {
    $nest: {
      '&:hover': {
        background: 'grey',
      },
      '& a': {
        textDecoration: 'none',
      },
    },
  },
});

Register media styles

this.styler.register({
  wrapper: {
    display: 'flex',
    flexDirection: 'row',
    $media: [
      [{maxWidth: 600}, {
        flexDirection: 'column',
      }],
    ],
  },
});

Element state styling

Define element states:

constructor(private def: StylerDefService)
...
this.styler.register({
  host: {
    ...
  },
  panel: (state) => {
    border: '1px solid green',
    // multi-state
    ...this.def.pick(state.size, {
      small: {
        padding: 2,
      },
      medium: {
        padding: 4,
      },
      large: {
        padding: 8,
      },
    }, 'medium'),
    // bool-state
    ...this.def.toggle(state.disabled, {
      color: '#666',
      background: '#999'
    }),
  },
  ...
});

Set state via service for host:

this.styler.host.applyState({size: 'small'});

Or set state with styler directive:

<div styler="panel" [stylerState]="{size: 'small'}"></div>

Move styles to a separate file

Provide styler view built-it module method:

@Component({
  ...
  viewProviders: [StylerModule.forComponent(ThisComponentStyle)],

Define style injectable:

import { Injectable } from '@angular/core';
import { ComponentStyle, StylerDefService, StyleDef } from '@ngx-kit/styler';

@Injectable()
export class ThisComponentStyle implements ComponentStyle {
  
  constructor(private def: StylerDefService) {
  }
  
  host(): StyleDef {
    return {
      display: 'block',
    };
  }
  
  wrapper(): StyleDef {
    return {
      background: '#ffffff',
      color: 'red',
    };
  }
  
  // state handling
  panel(state): StyleDef {
    return {
      border: '1px solid green',
      // multi-state
      ...this.def.pick(state.size, {
        small: {
          padding: 2,
        },
        medium: {
          padding: 4,
        },
        large: {
          padding: 8,
        },
      }, 'medium'),
      // bool-state
      ...this.def.toggle(state.disabled, {
        color: '#666',
        background: '#999'
      }),
    };
  };
  
}

Multi-register

Styles deep-merged from left to right.

this.styler.register([
  {
    host: {
      background: '#ffffff',
      color: 'yellow'
    },
  },
  {
    host: {
      color: 'red',
      fontSize: '1.1rem',
    },
  },
]);

Similar to:

this.styler.register([
  {
    host: {
      background: '#ffffff',
      color: 'red',
      fontSize: '1.1rem',
    },
  },
]);

Provide few separated styles to component:

viewProviders: [
  StylerModule.forComponent(LayoutStyle),
  StylerModule.forComponent(ThisComponentStyle),
],

Fallback styles

TBD

Smart styles

  • padding: [10, 20] => padding: '10px 20px'
  • padding: {top: 10, left: 30} => paddingTop: '10px', paddingLeft: '30px'
  • margin: [10, 20, 30] => padding: '10px 20px 30px'
  • border: [1, 'solid', 'blue'] => border: '1px solid blue'

Mixins

TBD

@keyframes

constructor(private styler: StylerComponent) {
  this.styler.register({
    host: {
      animationDuration: '1s',
      animationName: this.styler.keyframes({
        '0%': {
          transform: 'rotate(0deg)',
        },
        '100%': {
          transform: 'rotate(360deg)',
        },
      }),
      animationTimingFunction: 'linear',
      animationIterationCount: 'infinite',
    },
  });
}

Automatically add classes

Styler can add classes to elements. Class attribute based on component name (should be setted), element name and element state.

Provide BemClassGenStrategy:

providers: [
  {
    provide: ClassGenStategy,
    useClass: BemClassGenStrategy,
  },
],

Set component name:

constructor(private styler: StylerComponent) {
  this.styler.classPrefix = 'component-name';
}

Helpers

Styles definition

  • defPick(state: string, styles: StyleDef, default?: string) - returns styles[state|default]
  • defToggle(state: boolean, styles: StyleDef, falseStyles?: StyleDef) - returns styles if state is true
  • defMerge(styles: StyleDef[]) - js deepMerge, needed if states have $nest props

Colors

Helpers for color manipulating.

...
background: darken(0.2, someColorVar),
  • adjustHue
  • complement
  • darken
  • desaturate
  • grayscale
  • hsl
  • hsla
  • invert
  • lighten
  • mix
  • opacify
  • rgb
  • rgba
  • saturate
  • setHue
  • setLightness
  • setSaturation
  • shade
  • tint
  • toColorString
  • transparentize