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

@tokens-studio/configurator

v0.2.0

Published

Online IDE for configuring Style-Dictionary

Downloads

25

Readme

Style Dictionary Configurator

This repository contains the style-dictionary configurator.

See projects for more info on status.

This project was started from a Style Dictionary Playground fork

Usage

Part of the application is a reusable Web Component that can be consumed in other contexts.

For Monaco to work properly, we have to render it to LightDOM, as the consumer you are responsible for slotting in the monaco container divs with 100% height, we'll do the rest!

// Custom Element definition, optionally you can also do: 
// import { ConfiguratorElement } from '@tokens-studio/configurator';
// to register it under a different custom element tag name.
import '@tokens-studio/configurator';
<configurator-element>
  <div
    style="height: 100%"
    slot="monaco-config"
  ></div>
  <div
    style="height: 100%"
    slot="monaco-output"
  ></div>
</configurator-element>

You'll also need to ensure that WASM bindings are supported in whatever dev server you use. For Vite for example, you will need:

optimizeDeps: {
  exclude: ['@rollup/browser'],
}

Attributes

<configurator-element prevent-init></configurator-element>

Allow prevent-init attribute to not initialize the configurator-element. Users can call configuratorEl.init() themselves e.g. after initializing the source files with the replaceSource utility, since this utility requires the configurator-element definition to at least be loaded.

Icons

This element uses Microsoft Codicons.

For them to render properly, ensure the codicon font definition is loaded in your app.

Utils

We also export some utilities to make it easier to work with this:

import { replaceSource, resizeMonacoLayout, SD_FUNCTIONS_PATH, SD_CONFIG_PATH } from '@tokens-studio/configurator/utils';

window.addEventListener('resize', resizeMonacoLayout);

replaceSource({
  [SD_CONFIG_PATH]: '{}',
  [SD_FUNCTIONS_PATH]: `import StyleDictionary from 'style-dictionary';
import { register } from '@tokens-studio/sd-transforms';

register(StyleDictionary);`,
  'studio.tokens.json': '{}'
}, {
  run: true,
  clear: 'all'
});

The second param of replaceSource is an options object with props:

  • run -> true or false, default value: true. Whether or not to run Style-Dictionary after replacing the files.
  • clear -> true, false or "all", default value: true. "all" means all files are cleared first, including the Style-Dictionary config and functions files.

Note that your token files cannot match "config.json", "sd.config.json", "config.js", "sd.config.js", "config.mjs", "sd.config.mjs" or "registerSDFunctions.js". These are reserved filenames for the SD Config / Functions files.

Events

There are a couple of events you can listen to on window:

  • When the Functions tab content gets saved - FUNCTIONS_SAVED_EVENT -> ev.detail is the saved content
  • When the Config tab content gets saved - CONFIG_SAVED_EVENT -> ev.detail is the saved content
  • When the tokens (input/output) content gets saved - TOKENS_SAVED_EVENT -> ev.detail is the saved content
  • When the input files are created initially or when using replaceSource() utility - INPUT_FILES_CREATED_EVENT

There's also an event on sdState you can listen to, which gives you the updated Style-Dictionary object:

import { sdState, SD_CHANGED_EVENT } from '@tokens-studio/configurator/utils';

sdState.addEventListener(SD_CHANGED_EVENT, (ev) => {
  console.log(ev.detail); // Style-Dictionary object
})