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

@lwc/style-compiler

v6.5.2

Published

Transform style sheet to be consumed by the LWC engine

Downloads

304,593

Readme

@lwc/style-compiler

Transform style sheet to be consumed by the LWC engine.

Features

  • Shadow DOM style scoping:
    • transform :host pseudo-class selectors
    • scope all the other selectors using CSS attribute selectors
  • Custom Properties: inline replacement of var() CSS function
  • Right-to-left: transform the :dir pseudo class selector to [dir] attribute selectors
  • CSS import: resolve imports via static ES module imports

Installation

yarn add --dev @lwc/style-compiler

Usage

const { transform } = require('@lwc/style-compiler');

const source = `
    :host {
        opacity: 0.4;
    }

    span {
        text-transform: uppercase;
    }
`;

const { code } = transform(source, 'example.css');

API

transform(source, id, options)

Options:

  • source (string, required) - the css source file to compiler
  • id (string, required) - the css source file path, used by the compiler to produce errors with the file name
  • options (object, optional)
    • customProperties (object, optional)
      • resolverModule (boolean, optional) - module name for the custom properties resolve
    • scoped (boolean, optional) - true if the styles are scoped (via Light DOM style scoping)
    • disableSyntheticShadowSupport (boolean, optional) - true if synthetic shadow DOM support is not needed, which can result in smaller output
    • apiVersion (number, optional) - API version to associate with the compiled stylesheet.

Return:

  • code - the generated code

Note: The LWC style compiler doesn't preserve the authored format, and always produce compressed code.

Selector scoping caveats

  • No support for ::slotted pseudo-element.
  • No support for >>> deep combinator (spec still under consideration: issue).
  • No support for :host-context pseudo-selector (browser vendors are not able to agree: webkit, gecko)
  • This transform duplicates the :host selector to able to use the generated style in both the synthetic and native shadow DOM. The duplication is necessary to support the functional form of :host(), :host(.foo, .bar) {} needs to get transformed into .foo[x-btn-host], .bar[x-btn-host] {} to work in the synthetic shadow DOM.
  • Scoped CSS has a non-negligeable performance impact:
    • Each selector chain is scoped and each compound expression passed to the :host() need to be spread into multiple selectors. This transformation greatly increases the overall size and complexity of the generated CSS, leading to more bits on the wire, longer parsing time and longer style recalculation.
    • In order to ensure CSS encapsulation, each element needs to add an extra attribute. This increases the actual rendering time.