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

@salesforce-ux/design-system-parser

v1.1.1

Published

Parse CSS comments into a data structure

Downloads

92

Readme

Design System Parser

Parses CSS comments into a tree data structure using assertion selectors.

Installation

npm install @salesforce-ux/design-system-parser

Api

  • comments :: () -> [Comment]
  • components :: () -> [Component]
  • component :: Id -> FullComponent
  • moduleComponents :: () -> [ModuleComponent]
  • moduleComponent :: Id -> FullModule
  • findVariant :: (Id, FullComponent) -> FullComponent
  • findModifier :: (Id, FullComponent) -> FullComponent

Things to know

  • Comment is a parsed annotation
  • Component is a Comment w/ an id One of Base | Variant | Modifier
  • FullComponent is a Component with restrictees
  • Repo is our "database" of comments. We put finds there.
  • Comment is our model for Comp/Variant/Modifier

How it works

  • The entry point is index.js
  • We parse sass comments and match on @ symbols
  • The post-parsed comments are given to Repo.
  • Repo initializes by partitioning and normalizing comments. utils are comments with a restrict of * so we can't use them for hierarchy building.

fancy comments are ones with with any special characters in their restriction. It separates any css selector syntax from plain classnames and element names (e.g. td[class=~"Im fancy"] vs td.plain > name). This is because we need to actually interpret fancy selectors, but the rest can be statically indexed. Speaking of which, it then sets up an INDEX of {restrict: [comment]} where any classname mentioned in the restrict is now a key in this INDEX pointing to the comment. This is so we can rapidly look up the comments via a selector later.

Setting Restrictees

Components / Modules

We start by finding the first concrete variant. This is because there is no selector/restrict on an abstract component. Then we call recurse with a cache and the first variant.

recurse will first get the selector from the comment, then exit if it's missing or if we've already populated the restrictees for that comment in the cache. We then find all comments who's restrict rule matches our selector and recursively populate each of their restrictees before finally setting them to the restrictees attribute of our comment. The workhorse here is Repo.findAllByRestrict

Repo.findAllByRestrict starts by searching the INDEX, which is keyed by selector names mentioned in restrict rules. Then, it does a second pass on (the much smaller set) fancy. For fancy, we first make sure we're not comparing the comment to itself, then we find the restrict. With restrict in hand, we actually generate html according to the selector and apply the restrict to see if there's a match using cheerio. This is much like how validation works in ds-markup.

Utilities

Utilities work top-down looking for selectors, not restricts. The reason is restrict should always be * (or .myscope > *) for a utility. We use the same matching technique we used with fancy, but this time we use utils and also flip the html generation around: the candidates generate html and the abstract utility's selector is used to match.

Licenses

Source code is licensed under BSD 3-Clause