• Stars
    star
    108
  • Rank 321,259 (Top 7 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A utility-first CSS runtime for rapid UI development.

RunCSS

RunCSS is the runtime equivalent of TailwindCSS, featuring the same CSS utility class names, but with no build step required. It achieves this by generating CSS on the fly with JavaScript.

RunCSS comes with batteries included. By default all additional variants such as hover, active, visited, group-hover, sm, lg etc work with all class names. All packaged in a single 25kb (8kb after compression) JS file!

Usage

Add to <head>:

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/runcss/dist/runcss.min.css">
  <script src="https://cdn.jsdelivr.net/npm/runcss/dist/runcss.min.js" defer watch></script>

Done! RunCSS will parse the documents and generate the corresponding classes, with no further configuration required. RunCSS will also watch for new element insertions and parse them. Remove the watch attribute to disable this feature.

Check the examples/ directory for some examples.

Avoid element popup

You may add the runcss-cloak attribute to any element to hide it until RunCSS processes it.

For example:

<body runcss-cloak>
  <img class="w-3 h-3" src="mylargeimage.png">
</body>

Custom configuration

TODO - WORK IN PROGRESS Before loading runcss.js, add the following script:

<script>
window.runcssConfig = {
  colors: {
    'main': '#fff',
    'secondary': {
      100:  '#09132aa'
    },
  },
  screens: {
    sm: '480px',
    md: '768px',
    lg: '976px',
    xl: '1440px',
  },
  fontFamily: {
    sans: ['Graphik', 'sans-serif'],
    serif: ['Merriweather', 'serif'],
  },
}
</script>
<script></script>

You may use it to either extend or override default values. Currently, this is not yet implemented. colors, screens and fontFamily.

Advanced usage as module

<script type="module">
  import RunCSS, {extendRunCSS} from "https://cdn.jsdelivr.net/npm/runcss/dist/runcss.min.mjs"

  // Add things to the RunCSS templates
  extendRunCSS( ({defaultsTemplate, ruleTemplate, shortcuts, states}) => {
    states.modifiers['myclass'] = '.myclass'
    return {defaultsTemplate, ruleTemplate, shortcuts, states}
  })

  // Setup theme
  const { processClasses, startWatching, stopWatching, exportCSS } = RunCSS({
    colors: {
      'main': '#fff',
    },
    //.... same options as above
  })

  // Add classes
  processClasses('sm:text-red text-blue') // don't worry about duplicates

  // Iterate through document
  for(const element of document.querySelectorAll('*[class]')) {
    processClasses(element.getAttribute("class"))
  }

  // Start watching for changes
  startWatching(document.getElementById('hello')) // if not specified, fallback to document.body

  // Stop watching
  stopWatching()

  // Log generated CSS file
  console.log(exportCSS())

  // Remove runcss-cloak attribute
  const hiddenNodes = document.querySelectorAll('*[runcss-cloak]')
  for(let node of hiddenNodes){
    node.removeAttribute('runcss-cloak')
  }
</script>

Caveats and differences with TailwindCSS

Currently, this project is still under development, but it aims to cover the totality of TailwindCSS classes.

If you find something missing, feel free to open an issue.

By design, this parser is way less strict than Tailwind's one. This allows smaller builds and faster load times, but also means that wrong values may be turned into CSS rules regardless. This is intentional, because the browser will discard those rules anyway.

VSCode Intellisense

To enable Tailwind's autocompletion, install the official Tailwind extension, and create an empty file called tailwind.config.js in the same folder of your html files.

Build / contribute

Clone this repository and use bun to install dependencies:

git clone https://github.com/lucafabbian/runcss.git
cd runcss
bun i

Then, you may use:

bun run build    # Build for production
bun run dev      # Build, watch for changes + start server with live reload! 

Authors and License

Current author: Luca Fabbian [email protected]

Based on RunCSS of mudgen, follow him on twitter.

Distributed under MIT License.

More Repositories

1

awesome-diamonds

A curated list of awesome EIP2535 Diamonds resources, libraries, tools, articles and more
341
star
2

diamond

Information about three diamond reference implementations.
257
star
3

diamond-3

EIP-2535 Diamonds reference implementation.
Solidity
254
star
4

diamond-3-hardhat

EIP-2535 Diamond reference implementation using Hardhat and Solidity 0.8.*
Solidity
234
star
5

diamond-1-hardhat

EIP-2535 Diamond reference implementation using Hardhat and Solidity 0.8.*
Solidity
130
star
6

diamond-2-hardhat

Gas-optimized EIP-2535 Diamond reference implementation using Hardhat and Solidity 0.8.*
Solidity
92
star
7

webscript

Webscript is a Javascript library for creating DOM elements. Use it to create web applications. It is like HTML but it is Javascript. It is designed to work with existing libraries.
JavaScript
86
star
8

diamond-1

EIP-2535 Diamonds reference implementation.
Solidity
30
star
9

diamond-2

Gas-optimized EIP-2535 Diamonds reference implementation.
Solidity
27
star
10

quickswap

Decentralized trading protocol on Matic Network.
Solidity
19
star
11

transparent-contracts-erc1538

Reference implementation of ERC1538
JavaScript
17
star
12

diamond-foundry

A reference implementation of EIP2535 Diamonds using Foundry
Solidity
12
star
13

emoji-token

💎 Token
Solidity
10
star
14

governance-token-diamond

An ERC20 governance token diamond that can be used to govern a project as well as itself.
Solidity
10
star
15

diamond-util

Javascript library for deploying and upgrading diamonds.
JavaScript
8
star
16

contracts-starter

Template for starting smart contract repos
JavaScript
8
star
17

diamond-docs

Documentation for EIP2535 Diamonds
Python
6
star
18

mokens-bug-bounty

Bug Bounty Program for Mokens Contract
6
star
19

ethers-ledger

TypeScript
5
star
20

jobboard

Clojure
5
star
21

erc998.org

Website for ERC998
HTML
4
star
22

personal-diamonds

Personal diamond
4
star
23

Telecommute-Job-Board

Free Job Board for telecommute technology jobs.
Ruby
3
star
24

ethereum-to-matic

Bridging ERC20 tokens from Ethereum to Matic Network
Solidity
3
star
25

quickswap-contracts

Solidity
3
star
26

deno-postcss

Port of postcss to deno.
JavaScript
2
star
27

SimpleCache

A Simple PHP Caching System
PHP
2
star
28

viv

Library for creating web applications in the browser.
JavaScript
2
star
29

denotailcss

Port of Tailwind CSS to deno.
JavaScript
1
star
30

hardhat-fork-test

Testing hardhat forks
JavaScript
1
star
31

matic-uniswap

Uniswap on Matic Network
1
star
32

quickswap-snapshot

Solidity
1
star
33

ideas

Some ideas
1
star
34

personal-diamonds-client

JavaScript
1
star