CSSJSON playground

paste css into CSS editor, run, get JSON ourput

by sophtwhere

HTML

<body>
  <pre id="src">
     blah
   </pre>
</body>

CSS

/* NEWTON'S BALLS */

.centered {
  position: absolute;
  top: 50%;
  left: 50%;
  /* bring your own prefixes */
  transform: translate(-50%, -50%);
}

.scaled {
  zoom: 3;
  -moz-transform: scale(3);
}

@-webkit-keyframes newtonBallFirst {
  0% {
    -webkit-transform: rotate(70deg);
  }
  50% {
    -webkit-transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(0deg);
  }
}

@-webkit-keyframes newtonBallMiddle {
  0% {
    -webkit-transform: rotate(0deg);
  }
  50% {
    -webkit-transform: rotate(0deg);
  }
  51% {
    -webkit-transform: rotate(-0.5deg);
  }
  52% {
    -webkit-transform: rotate(0.5deg);
  }
  53% {
    -webkit-transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(0deg);
  }
}

@-webkit-keyframes newtonBallLast {
  0% {
    -webkit-transform: rotate(0deg);
  }
  50% {
    -webkit-transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(-70deg);
  }
}

@keyframes newtonBallFirst {
  0% {
    transform: rotate(70deg);
  }
  50% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(0deg);
  }
}

@keyframes newtonBallMiddle {
  0% {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(0deg);
  }
  51% {
    transform: rotate(-0.5deg);
  }
  52% {
    transform: rotate(0.5deg);
  }
  53% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(0deg);
  }
}

@keyframes newtonBallLast {
  0% {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(-70deg);
  }
}

.spinner.newton .ball {
  position: relative;
  display: inline-block;
  width: 1em;
  height: 6em;
  -webkit-transform-origin: 50% 0%;
  transform-origin: 50% 0%;
}

.spinner.newton .ball::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1em;
  height: 1em;
  border-radius: 100%;
  background: radial-gradient(circle at 40% 40%, rgb(79, 77, 77) 39%, rgb(55, 55, 55) 42%);
}

.spinner.newton .ball::before {
  content: '';
  position: absolute;
 ...

JavaScript

/**
 * CSS-JSON Converter for JavaScript
 * Converts CSS to JSON and back.
 * Version 2.1
 *
 * Released under the MIT license.
 *
 * Copyright (c) 2013 Aram Kocharyan, http://aramk.com/

 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 to permit persons to whom the Software is furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all copies or substantial portions
 of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 */

var CSSJSON = new function() {

  var base = this;

  base.init = function() {
    // String functions
    String.prototype.trim = function() {
      return this.replace(/^\s+|\s+$/g, '');
    };

    String.prototype.repeat = function(n) {
      return new Array(1 + n).join(this);
    };
  };
  base.init();

  var selX = /([^\s\;\{\}][^\;\{\}]*)\{/g;
  var endX = /\}/g;
  var lineX = /([^\;\{\}]*)\;/g;
  var commentX = /\/\*[\s\S]*?\*\//g;
  var lineAttrX = /([^\:]+):([^\;]*);/;

  // This is used, a concatenation of all above. We use alternation to
  // capture.
  var altX = /(\/\*[\s\S]*?\*\/)|([^\s\;\{\}][^\;\{\}]*(?=\{))|(\})|([^\;\{\}]+\;(?!\s*\*\/))/gmi;

  // Capture groups
  var capComment = 1;
  var capSelector = 2;
  var capEnd = 3;
  var capAttr =...