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

domino.css

v0.1.6

Published

Extends CSS with rules that modify DOM structure.

Downloads

12

Readme

domino.css

DominoCSS is a lightweight JavaScript library that gives CSS the power to mutate the DOM by extending it with new rules. DominoCSS makes it possible for developers to write more semantic HTML by moving element nesting/ordering instructions (which do affect presentation) out of HTML and into CSS.

It's really easy to get started with DominoCSS:

styles.css:

.container {
    width: 800px;
    margin: 0 auto;
}

.title {
    color: red;
    -domino-order: 0;
    -domino-container: .container;
}

article {
    font-size: 11pt;
    -domino-order: 100;
    -domino-container: .container;
}

page.html:

<!DOCTYPE html>
<html>
    <head>
        <title>Using DominoCSS is Easy!</title>

        <!-- Reference the stylesheet like normal. -->
        <link rel="stylesheet" href="./styles.css">

        <script src="./node_modules/domino.css/dist/domino-css.min.js"></script>
    </head>
    <body>
        <!-- ==============CONTENT============== -->
        <article>
            <p>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus vitae justo quis mi
                efficitur viverra. Aenean nisi nisl, blandit quis nisi a, convallis consectetur tortor.
                Donec tincidunt mauris sit amet risus ultrices lobortis. Pellentesque ut massa porttitor,
                pharetra nunc bibendum, euismod tortor. Fusce eget ornare metus. Nullam sodales, turpis
                eu imperdiet condimentum, turpis lectus gravida massa, ac facilisis dui nulla at dui.
                Donec aliquam ex non nibh scelerisque, in viverra diam sollicitudin.
            </p>
        </article>

        <h1 class="title">Lorem Ipsum RULES.</h1>

        <!-- =============CONTAINERS============= -->
        <div class="contianer"></div>
        
        <!-- bootstrap domino -->
        <script>window.dominoCSS.bootstrap(document.documentElement);</script>
    </body>
</html>

Install

$> npm install domino.css --save

With a <script> Tag

<script src="./node_modules/domino.css/dist/domino-css.min.js"></script>
<script>window.dominoCSS.bootstrap(document.documentElement);</script>

With RequireJS (AMD)

define(['node_modules/domino.css/dist/domino-css.min.js'], function(dominoCSS) {
    dominoCSS.bootstrap(document.documentElement);
});

With Browserify (CommonJS)

var dominoCSS = require('domino.css');

dominoCSS.bootstrap(document.documentElement);

CSS Rules

Currently, DominoCSS extends CSS with two new rules.

  1. -domino-container: This rule specifies an element's (or multiple elements') container. The value should be a valid CSS selector. At runtime, DominoCSS will move all elements matching the main selector into the first element matching the valueof -domino-container.

    .content {
        /* Move all elements matching ".content" into the first element matching "div.main-container" */
        -domino-container: div.main-container;
    }
  2. -domino-order: This rule specifies an element's (or multiple elements') position(s) realitive to its/their siblings. The value can be any integer (positive or negative.) At runtime, DominoCSS will reorder sibling elements according to their -domino-order (with lower values at the top of the list.)

    .first {
        -domino-order: 0;
        -domino-container: main;
    }
    .second {
        -domino-order: 100;
        -domino-container: main;
    }
    .third {
        -domino-order: 200;
        -domino-order: main;
    }
    .irrelevant {
        -domino-order: 150;
        -domino-container: .some-other-element;
    }
    
    /*
    Because they are all siblings (as specified by -domino-contianer,) .first, .second and .third
    will be moved in the DOM to be in that order. Because .irrelevant has a different parent (and
    is therefore in a different ordering context,) it does not factor into the ordering of the
    other three elements.
    */

Media Queries

One of DominoCSS' most powerful features is its support for media queries. Using normal CSS media queries combined with -domino- rules it is easy to change element ordering/nesting based on screen/device dimensions/orientation/etc.

Use in Production

To improve performance in production, it makes sense to pre-compile CSS files into DominoCSS instructions.

  1. Install domino.css globally:

    $> npm install -g domino.css
  2. Use the domino-css CLI tool to pre-compile CSS:

    $> domino-css < ./path/to/styles.css > ./styles.css.domino.js
  3. Add the compiled JavaScript file after the CSS in your page:

    <link rel="stylesheet" href="./path/to/styles.css">
    <script src="./styles.css.domino.js"></script>
  4. Bootstrap DominoCSS with the runtime library:

    • With a <script> tag:

      <script src="./node_modules/domino.css/dist/domino-css--runtime.min.js"></script>
      <script>window.dominoCSS.bootstrap(document.documentElement);
    • With RequireJS (AMD)

      define(['./node_modules/domino.css/dist/domino-css--runtime.min.js'], function(dominoCSS) {
          dominoCSS.bootstrap(document.documentElement);
      });
    • With Browserify (CommonJS)

      var dominoCSS = require('domino.css/runtime');
      
      dominoCSS.bootstrap(document.documentElement);

API

The dominoCSS Object exposes the following Functions:

  • parse(String:stylesheet): Object: Accepts a String of CSS and returns an Object in DominoCSS rules format. That format looks like this:

    {
        "rules": {
            "container": [
                { "selector": ".content", "value": ".div.container" }
            ],
            "order": [
                { "selector": ".first", "value": 200 }
            ]
        },
        "mediaQueries": [
            {
                "directive": "only screen and (min-width: 768px)",
                "rules": {
                    "container": [
                        { "selector": ".content", "value": ".mobile-container" }
                    ],
                    "order": [
                        { "selector": ".first", "value": -1000 }
                    ]
                }
            }
        ]
    }

    NOTE: Parsing is not available in the DominoCSS runtime library. Attempting to call dominoCSS.parse() will throw an Error.

  • applyRules(Object:rules, Element:element): Accepts an Object in the DominoCSS rules format and applies those rules to the provided element.

  • bootstrap(Element:element): Function: Finds DominoCSS rules and applies them to the provided element. Returns a Function that, when called, will re-apply the found rules to the element. This Function also sets up a resize handler on the element's Window that re-applies styles so that media queries work as expected.

    This Function has different methods for getting the DominoCSS rules depending if the full or runtime library is being used.

    In the full library:

    1. The text of any <style> element and the text of any external <link>ed stylesheets (fetched via XHR) is retrieved.
    2. The text of each element is parsed into DominoCSS rules.
    3. The rules are combined (respecting the order of the <link>s/<style>s in the DOM.)
    4. The rules are applied to the element.

    In the runtime library:

    1. Rules are retrieved from a global __dominoCSSRules__ Array (created and added to by the compiled CSS rules scripts.)
    2. The rules are combined (respecting the order of the __dominoCSSRules__ Array, which will reflect the order of <script>s in the DOM.)
    3. The rules are applied to the element.

Developing

First, clone the repository:

$> git clone [email protected]:cinema6/domino.css.git

Then, install dependencies:

$> npm install

Run Unit Tests:

This runs unit tests a single time (using Karma and PhantomJS.)

$> npm test

Start an Example Server:

This starts a webserver on port 8000 that serves out of the "examples" directory. It uses livereload to automatically refresh the page whenever a file changes.

$> npm run examples

Start a Test-Driven-Development Runner

This starts a process that will automatically run unit tests whenever a file changes.

$> npm run tdd

Build The Library

This uses Browserify and UglifyJS2 to build a UMD of DominoCSS (both full and runtime, with minified counterparts) into the "dist" directory.