Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function (global) {
- function clean(css) {
- return css
- .replace(/\/\*[\W\w]*?\*\//g, "") // remove comments
- .replace(/^\s+|\s+$/g, "") // remove trailing spaces
- .replace(/\s*([:;{}])\s*/g, "$1") // remove trailing separator spaces
- .replace(/\};+/g, "}") // remove unnecessary separators
- .replace(/([^:;{}])}/g, "$1;}") // add trailing separators
- }
- function refine(css, isBlock) {
- return /^@/.test(css) ? (css = css.split(" ")) && {
- "identifier": css.shift().substr(1).toLowerCase(),
- "parameters": css.join(" ")
- } : (isBlock ? /:$/ : /:/).test(css) ? (css = css.split(":")) && {
- "property": css.shift(),
- "value": css.join(":")
- } : css;
- }
- function parse(css, regExp, object) {
- for (var m; (m = regExp.exec(css)) != null;) {
- if (m[2] == "{") object.block.push(object = {
- "selector": refine(m[1], true),
- "block": [],
- "parent": object
- });
- else if (m[2] == "}") object = object.parent;
- else if (m[2] == ";") object.block.push(refine(m[1]));
- }
- }
- global.parseCSS = function (css) {
- return parse(clean(css), /([^{};]*)([;{}])/g, css = { block: [] }), css;
- };
- global.vendorCSS = function (css) {
- var newCSS = {}, block, i, e;
- if (css.selector) newCSS.selector = css.selector;
- if (css.property) newCSS.property = global.vendor.property[css.property] || css.property;
- if (css.value) {
- newCSS.value = css.value;
- for (i in global.vendor.value) {
- e = global.vendor.value[i];
- i = new RegExp(i, "g");
- if (newCSS.value.match(i)) newCSS.value = newCSS.value.replace(i, e);
- }
- }
- if (css.block) for (newCSS.block = [], i = 0; css.block[i]; ++i) newCSS.block[i] = global.vendorCSS(css.block[i]);
- return newCSS;
- };
- global.renderCSS = function (css) {
- var str = "", i;
- if (css.selector) str += css.selector + "{";
- if (css.property) str += css.property + ":" + css.value + ";";
- for (i = 0; css.block && css.block[i]; ++i) str += global.renderCSS(css.block[i]);
- if (css.selector) str += "}";
- return str;
- };
- global.vendor = function (vendorObject, vendorPrefixRe, camelToDashedRe, camelToDashedFn, style, linearGradient, e, m) {
- for (e in style) if (m = e.match(vendorPrefixRe)) {
- vendorObject.prefix = m[1].toLowerCase();
- break;
- }
- for (e in style) if (m = e.match(vendorPrefixRe)) vendorObject.property[e[m[1].length].toLowerCase() + e.slice(m[1].length + 1).replace(camelToDashedRe, camelToDashedFn)] = e.replace(camelToDashedRe, camelToDashedFn);
- style.backgroundImage = "-" + vendorObject.prefix + "-" + linearGradient + "(red, red)", vendorObject.value[linearGradient] = style.backgroundImage ? "-" + vendorObject.prefix + "-" + linearGradient : linearGradient;
- return vendorObject;
- }({
- property: {},
- value: {}
- }, /^(O|Moz|ms|webkit)[A-Z]/, /[A-Z]/g, function (e) {
- return "-" + e.toLowerCase()
- }, document.createElement("x-element").style, "linear-gradient");
- })(this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement