包详细信息

@acemir/cssom

acemir136MIT0.9.19

CSS Object Model implementation and CSS parser

CSS, CSSOM, parser, styleSheet

自述文件

CSSOM

CSSOM.js is a CSS parser written in pure JavaScript. It is also a partial implementation of CSS Object Model.

CSSOM.parse("body {color: black}")
-> {
  cssRules: [
    {
      selectorText: "body",
      style: {
        0: "color",
        color: "black",
        length: 1
      }
    }
  ]
}

Parser demo

Works well in Google Chrome 6+, Safari 5+, Firefox 3.6+, Opera 10.63+. Doesn't work in IE < 9 because of unsupported getters/setters.

To use CSSOM.js in the browser you might want to build a one-file version that exposes a single CSSOM global variable:

➤ git clone https://github.com/acemir/CSSOM.git
➤ cd CSSOM
➤ node build.js
build/CSSOM.js is done

To use it with Node.js or any other CommonJS loader:

➤ npm install @acemir/cssom

Don’t use it if...

You parse CSS to mungle, minify or reformat code like this:

div {
  background: gray;
  background: linear-gradient(to bottom, white 0%, black 100%);
}

This pattern is often used to give browsers that don’t understand linear gradients a fallback solution (e.g. gray color in the example). In CSSOM, background: gray gets overwritten%3B%0A%7D). It does NOT get preserved.

If you do CSS mungling, minification, or image inlining, considere using one of the following:

Tests

To run tests locally:

➤ git submodule init
➤ git submodule update

更新日志

@acemir/cssom

0.9.19

Patch Changes

0.9.18

Patch Changes

  • #43 374d9a5 Thanks @acemir! - feat: improve parse options
    • add opts to CSSOM.parse
    • improve insertRule and deleteRule edge cases
    • adjust @font-face cannot be nested
    • throw correct error on insertRule invalid index
    • adjust @import canonical text and layer validation
    • adjust selectorText values formatting

0.9.17

Patch Changes

  • #41 a48b41f Thanks @acemir! - feat: sync common rules interfaces

    • CSSRule parentRule and parentStyleSheet, are now prototype getters to be readonly according to the CSSRule interface.
    • CSSStyleRule selectorText and style are now prototype getter and setter according to the CSSStyleRule interface.
    • Added a try catch to override local CSSStyleDeclaration with the one from cssstyle when needed
    • Implemented methods and indexed getters for CSSKeyframesRule
    • Implementd errorUtils for a more organized way to handle errors

0.9.16

Patch Changes

0.9.15

Patch Changes

0.9.14

Patch Changes

0.9.13

Patch Changes

0.9.12

Patch Changes

0.9.11

Patch Changes

0.9.10

Patch Changes

0.9.9

Patch Changes

0.9.8

Patch Changes

0.9.7

Patch Changes

0.9.6

Patch Changes

0.9.5

Patch Changes

0.9.4

Patch Changes

0.9.3

Patch Changes

  • d2a81ae Thanks @acemir! - feat: support attribute selector case-insensitive flag

0.9.2

Patch Changes

  • #8 5ea9d4f Thanks @acemir! - feat: parser improvements on selectors, declaration values and error handling

0.9.1

Patch Changes

  • #7 6d14f90 Thanks @acemir! - feat: add layer() and supports() to @import rule

  • #6 a6526ad Thanks @acemir! - feat: support CSSLayerStatementRule, adjust CSSLayerBlockRule and improves at-rule validation

  • #4 46a61ee Thanks @anntseng! - fix: check the priority value of the existing property

  • #3 243e8cd Thanks @DiogoDoreto! - index parameter of CSSStyleSheet.insertRule is now optional

0.9.0

Changes

  • #2 64e49ef - feat: support for nested selectors, nested declarations and at-rule validations

0.8.0

Minor Changes

0.7.1

Patch Changes

0.7.0

Minor Changes