0.5.0 • Published 4 years ago

cssom v0.5.0

Weekly downloads
19,243,918
License
MIT
Repository
github
Last release
4 years ago

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/NV/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 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. 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

Who uses CSSOM.js

archetype-libraryreact-native-bluetooth2killi8n-react-native-fast-imageticket-jsdomspecify-importsbabel-specify-imports@icanpm/api-masterpaperbits-demojsdom-exreact-native-template-rfbaseairscanairscan-examplereact-native-esc-pos-sahaab@borisovart/atol-kkt-modulejuice-enhanceddeneme323112@ntt_app/react-native-custom-notificationreact-native-covid-sdkgql_din_modjsdom-fork@olivervorasai/sliderreact-native-printer-brothersisv-lynx-devwilscannerjsdom__no_corsstretch-rollup@mink-opn/build-tokensreact-native-slider-kfsvelte-slime@twbs/svg-spriteplginexpand-react-bridgesklif-ui-kitsklif-api@everything-registry/sub-chunk-1421p149-table@pmadhur/jsdomsklif-uitailwind-vector-effectsyncbackbasessvgkitweb-elements-iconsvz-parserwebchewoven-challenge-deploysuperset-plugin-chart-hello-world2supercluster-googlemaps-adapter-clonesstanikionespotify-ds-sestarbucks-jp-drinksticky-scroll-catchstp-cdktestapatestnpm_lmnsvelte-component-libsvg-cleanersvg-sprite-sachasvg-spritesvg-sprite-datasvg-sprite_lvision-camera-plugin-scan-facesvue-axios-rest@donapot/mylibtest@cryptocode99/token-lists@cubesoft/jsdom@cute-apocalypse/react-tree@corelmax/react-native-my2c2p-sdk@bung87/svg-sprite@rps-engine/core@rstacruz/pnpm@percent/percent-api-hooks@poscredit/plugin-chart-borisgenerator-bootstrap-boilerplate-templatejulien-easy-modaljsdomprojsdomsjs-snippet-librarykalacanvasjss-cssjnf-accesscontrol-rnttljparserjsbrowserjsdom-arc-extnjsdom-canvas-2jsdom-lambdajsdom-lightjsdom-littlejsdom-napi-rs-canvasjsdom-no-contextifyjsdom-no-cssjsdom-nocontextifiyjsdom-nogypjsdom-papandreoujsdom-rjsdom-denojsdom-extra-jsjsdom-fabricjsjsdom-wcjsdom_win32jsdom-se
0.5.0

4 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

8 years ago

0.3.1

9 years ago

0.3.0

11 years ago

0.2.5

13 years ago

0.2.4

13 years ago

0.2.3

13 years ago

0.2.2

13 years ago

0.2.1

13 years ago

0.2.0

14 years ago