Giter VIP home page Giter VIP logo

css-selector-tokenizer's Introduction

CSS Modules Logo

CSS Modules

A CSS Module is a CSS file where all class names and animation names are scoped locally by default. All URLs (url(...)) and @imports are in module request format (./xxx and ../xxx means relative, xxx and xxx/yyy means in modules folder, i.e. in node_modules).

CSS Modules compile to a low-level interchange format called ICSS (or Interoperable CSS) but are written like normal CSS files:

/* style.css */
.className {
  color: green;
}

When importing a CSS Module from a JavaScript Module, it exports an object with all mappings from local names to global names.

import styles from './style.css';

element.innerHTML = '<div class="' + styles.className + '">';

Table of Contents

Why CSS Modules?

  • Local Scope Prevents Clashes: CSS Modules use local scope to avoid style conflicts across different project parts, allowing component-scoped styling.
  • Clear Style Dependencies: Importing styles into their respective components clarifies which styles impact which areas, enhancing code readability and maintenance.
  • Solves Global Scope Problems: CSS Modules prevent the common issue of styles in one file affecting the entire project by localizing styles to specific components.
  • Boosts Reusability and Modularity: CSS Modules allow the same class names in different modules, promoting modular, reusable styling.

css-selector-tokenizer's People

Contributors

alexander-akait avatar avivahl avatar barak007 avatar cauldrath avatar evilebottnawi avatar geelen avatar pieter avatar sokra avatar warmans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

css-selector-tokenizer's Issues

Bundle size increases by more then 10x

Hi,
Just to note that latest patch release increased the bundle size by more then 10x.
The reason is that the new version of regexpu-core is now depended on regenerate-unicode-properties (380k)

Bundle Size

unescapeString doesn't properly unescape unicode characters

The following are valid unicode escaped strings:

  • '\a'
  • '\00000A'

Both of these aren't matched by unescapeString(), which wants to have at least 2 characters and a maximum of 5. In fact stringifyValues() can stringily to '\A', which then can't be parsed again by parseValues().

Symbolset font content incorrectly escaped

I use the symbolset ss-pika in several projects and when trying to use webpack with the css-loader the resulting CSS string breaks and I end up with two scrambled characters (��) instead of my search icon (🔎).

This happens when you have UTF-16 characters like 🔎 (escapes properly to \1F50E) which becomes a surrogate pair when trying to escape it in Javascript.

I've been attempting to fix this using the cssesc module:

var cssesc = require("cssesc");

function escape(str, stringType) {
    return cssesc(str, {
        quotes: stringType === "'" ? "single" : "double"
    });
}

The tests break though, cause assert.deepAssert creates a surrogate pair when comparing the parseValues result of the file test-cases-values.js.

However, if I rollback css-loader to 0.14.5 (webpack-contrib/css-loader@51e11f3) then this is no longer an issue as the CSS isn't escaped.

Not escaping the content might be a more sane option?

Related reading:
https://mathiasbynens.be/notes/javascript-encoding
https://mathiasbynens.be/notes/css-escapes

Missing support for selectors with CSS escapes

Let's say we have a selector used to select an element in HTML with the class name "10w"

.\31 0w

This is valid selector according to https://jigsaw.w3.org/css-validator/#validate_by_input (enter .\31 0w {})

But when we parse it we get the following result

  {
    "type": "selectors",
    "nodes": [
        {
            "type": "selector",
            "nodes": [
                {
                    "type": "element",
                    "name": "31"
                },
                {
                    "type": "spacing",
                    "value": " "
                },
                {
                    "type": "invalid",
                    "value": "0"
                },
                {
                    "type": "element",
                    "name": "w"
                }
            ]
        }
    ]
}

While expected result is

  {
    "type": "selectors",
    "nodes": [
        {
            "type": "selector",
            "nodes": [
                {
                    "type": "class",
                    "name": "10w"
                }
            ]
        }
    ]
}

Emoji support

The selector .🍰 is valid CSS, but this parses it to .\�\�

:matches() not parsed correctly

See :matches().

:not(.b) parses to:

{
  "type":"selectors",
  "nodes":[
    {
      "type":"selector",
      "nodes":[
        {
          "type":"nested-pseudo-class",
          "name":"not",
          "nodes":[
            {
              "type":"selector",
              "nodes":[
                {
                  "type":"class",
                  "name":"b"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

whereas :matches(.b) currently parses to:

{
  "type":"selectors",
  "nodes":[
    {
      "type":"selector",
      "nodes":[
        {
          "type":"pseudo-class",
          "name":"matches",
          "content":".b"
        }
      ]
    }
  ]
}

Attribute selectors not fully parsed

Currently, the parse tree doesn't include full details for attribute selectors. For example, [att*=val] is parsed into:

{"type":"selectors","nodes":[
  {
    "type":"selector",
    "nodes":[
      {
        "type":"attribute",
        "content":"att*=val"
      }
    ]
  }
]}

It would be better if the "content" was further parsed, so we could get something like:

{"type":"selectors","nodes":[
  {
    "type":"selector",
    "nodes":[
      {
        "type":"attribute",
        "name":"att",
        "operator":"*=",
        "content":"val"
      }
    ]
  }
]}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.