Comparing version 0.1.21 to 0.2.0
@@ -1,2 +0,2 @@ | ||
/* version: 0.1.21 */ | ||
/* version: 0.2.0 */ | ||
var Absurd = (function(w) { | ||
@@ -88,3 +88,5 @@ var lib = { | ||
return lib.helpers.Extend; | ||
} else { | ||
} else if(v == '../helpers/Clone') { | ||
return lib.helpers.Clone; | ||
} else { | ||
return function() {} | ||
@@ -148,3 +150,3 @@ } | ||
CSS = { raw: css, element: style }; | ||
} else { | ||
} else if(CSS.raw !== css) { | ||
CSS.raw = css; | ||
@@ -167,4 +169,4 @@ CSS.element.innerHTML = css; | ||
} | ||
HTMLSource = {'': HTMLElement.outerHTML.replace(/</g, '<').replace(/>/g, '>') }; | ||
} | ||
HTMLSource = {'': HTMLElement.outerHTML.replace(/</g, '<').replace(/>/g, '>') }; | ||
next(); | ||
@@ -189,6 +191,6 @@ } else if(typeof this.html === 'object') { | ||
var handleHTML = function(next) { | ||
if(HTMLSource) { | ||
if(HTMLSource) { | ||
absurd.flush().morph("html").add(HTMLSource).compile(function(err, html) { | ||
(function merge(e1, e2) { | ||
if(typeof e1 === 'undefined' || typeof e2 === 'undefined') return; | ||
if(typeof e1 === 'undefined' || typeof e2 === 'undefined' || e1.isEqualNode(e2)) return; | ||
// replace the whole node | ||
@@ -228,2 +230,3 @@ if(e1.nodeName !== e2.nodeName) { | ||
for(var i=0; i<e1.childNodes.length; i++) { | ||
if(!e2.childNodes[i]) { e2.appendChild(document.createTextNode("")); } | ||
merge(e1.childNodes[i], e2.childNodes[i]); | ||
@@ -279,3 +282,3 @@ } | ||
} | ||
return { | ||
var component = { | ||
populate: function(options) { | ||
@@ -303,2 +306,3 @@ queue([ | ||
} | ||
return component; | ||
} | ||
@@ -309,3 +313,3 @@ var components = function(absurd) { | ||
api.register = function(name, cls) { | ||
return comps[name] = extend({}, Observer(), Component(name, absurd), cls); | ||
return comps[name] = extend({}, Observer(), Component(name, absurd), cls); | ||
} | ||
@@ -461,3 +465,5 @@ api.get = function(name) { | ||
var extend = require("../helpers/Extend"); | ||
var checkAndExecutePlugin = function(selector, prop, value, stylesheet) { | ||
var clone = require("../helpers/Clone"); | ||
var toRegister = []; | ||
var checkAndExecutePlugin = function(selector, prop, value, stylesheet, parentSelector) { | ||
var plugin = API.getPlugins()[prop]; | ||
@@ -467,3 +473,3 @@ if(typeof plugin !== 'undefined') { | ||
if(pluginResponse) { | ||
addRule(selector, pluginResponse, stylesheet); | ||
addRule(selector, pluginResponse, stylesheet, parentSelector); | ||
} | ||
@@ -475,59 +481,19 @@ return true; | ||
} | ||
var clearing = function(props) { | ||
// plugins | ||
var plugins = API.getPlugins(); | ||
for(var prop in props) { | ||
if(typeof plugins[prop] !== 'undefined') { | ||
props[prop] = false; | ||
var addRule = function(selector, props, stylesheet, parentSelector) { | ||
// console.log("\n---------- addRule ---------", selector, ".........", parentSelector, "\n", props); | ||
stylesheet = stylesheet || "mainstream"; | ||
if(/, ?/g.test(selector)) { | ||
var parts = selector.replace(/, /g, ',').split(','); | ||
for(var i=0; i<parts.length, p=parts[i]; i++) { | ||
addRule(p, props, stylesheet, parentSelector); | ||
} | ||
return; | ||
} | ||
// pseudo classes | ||
for(var prop in props) { | ||
if(prop.charAt(0) === ":") { | ||
props[prop] = false; | ||
} | ||
} | ||
// ampersand | ||
for(var prop in props) { | ||
if(/&/g.test(prop)) { | ||
props[prop] = false; | ||
} | ||
} | ||
} | ||
var checkForNesting = function(selector, props, stylesheet) { | ||
for(var prop in props) { | ||
if(typeof props[prop] === 'object') { | ||
// check for pseudo classes | ||
if(prop.charAt(0) === ":") { | ||
addRule(selector + prop, props[prop], stylesheet); | ||
// check for ampersand operator | ||
} else if(/&/g.test(prop)) { | ||
addRule(prop.replace(/&/g, selector), props[prop], stylesheet); | ||
// check for media query | ||
} else if(prop.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { | ||
addRule(selector, props[prop], prop); | ||
// check for media query | ||
} else if(selector.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { | ||
addRule(prop, props[prop], selector); | ||
// check for plugins | ||
} else if(checkAndExecutePlugin(selector, prop, props[prop], stylesheet) === false) { | ||
addRule(selector + " " + prop, props[prop], stylesheet); | ||
} | ||
props[prop] = false; | ||
} else if(typeof props[prop] === 'function') { | ||
props[prop] = props[prop](); | ||
checkForNesting(selector, props, stylesheet); | ||
} else { | ||
if(checkAndExecutePlugin(selector, prop, props[prop], stylesheet)) { | ||
props[prop] = false; | ||
} | ||
} | ||
} | ||
} | ||
var addRule = function(selector, props, stylesheet) { | ||
// if array is passed as props | ||
if(typeof props.length !== 'undefined' && typeof props === "object") { | ||
for(var i=0; prop=props[i]; i++) { | ||
addRule(selector, prop, stylesheet); | ||
for(var i=0; i<props.length, prop=props[i]; i++) { | ||
addRule(selector, prop, stylesheet, parentSelector); | ||
} | ||
@@ -538,61 +504,88 @@ return; | ||
// check for plugin | ||
if(checkAndExecutePlugin(null, selector, props, stylesheet)) { | ||
if(checkAndExecutePlugin(null, selector, props, stylesheet, parentSelector)) { | ||
return; | ||
} | ||
// if the selector is already there | ||
if(typeof API.getRules(stylesheet || "mainstream")[selector] == 'object') { | ||
var current = API.getRules(stylesheet || "mainstream")[selector]; | ||
for(var propNew in props) { | ||
// overwrite already added value | ||
if(typeof props[propNew] != 'object') { | ||
current[propNew] = props[propNew]; | ||
var _props = {}, | ||
_selector = selector, | ||
_objects = {}, | ||
_functions = {}; | ||
// processing props | ||
for(var prop in props) { | ||
var type = typeof props[prop]; | ||
if(type !== 'object' && type !== 'function') { | ||
if(checkAndExecutePlugin(selector, prop, props[prop], stylesheet, parentSelector) === false) { | ||
_selector = typeof parentSelector !== "undefined" ? parentSelector + " " + selector : selector; | ||
_props[prop] = props[prop]; | ||
} | ||
} else if(type === 'object') { | ||
_objects[prop] = props[prop]; | ||
} else if(type === 'function') { | ||
_functions[prop] = props[prop]; | ||
} | ||
// no, the selector is still not added | ||
} else { | ||
API.getRules(stylesheet || "mainstream")[selector] = props; | ||
} | ||
checkForNesting(selector, props, stylesheet || "mainstream"); | ||
clearing(props); | ||
} | ||
var prepareRules = function(obj) { | ||
if(obj instanceof Array) { | ||
for(var i=0; i<obj.length; i++) { | ||
prepareRules(obj[i]); | ||
toRegister.push({ | ||
selector: _selector, | ||
props: _props, | ||
stylesheet: stylesheet | ||
}); | ||
for(var prop in _objects) { | ||
// check for pseudo classes | ||
if(prop.charAt(0) === ":") { | ||
addRule(selector + prop, _objects[prop], stylesheet, parentSelector); | ||
// check for ampersand operator | ||
} else if(/&/g.test(prop)) { | ||
addRule(prop.replace(/&/g, selector), _objects[prop], stylesheet, parentSelector); | ||
// check for media query | ||
} else if(prop.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { | ||
addRule(selector, _objects[prop], prop, parentSelector); | ||
// check for media query | ||
} else if(selector.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { | ||
addRule(prop, _objects[prop], selector, parentSelector); | ||
// check for plugins | ||
} else if(checkAndExecutePlugin(selector, prop, _objects[prop], stylesheet, parentSelector) === false) { | ||
addRule(prop, _objects[prop], stylesheet, (parentSelector ? parentSelector + " " : "") + selector); | ||
} | ||
return; | ||
} | ||
for(var prop in obj) { | ||
var value = obj[prop]; | ||
if(typeof value == 'object') { | ||
prepareRules(value); | ||
} | ||
if(/, ?/g.test(prop)) { | ||
var parts = prop.replace(/, /g, ',').split(','); | ||
for(var i=0; i<parts.length, p=parts[i]; i++) { | ||
if(obj[p]) { | ||
obj[p] = extend({}, obj[p], value); | ||
} else { | ||
obj[p] = extend({}, value); | ||
} | ||
} | ||
delete obj[prop]; | ||
} | ||
for(var prop in _functions) { | ||
var o = {}; | ||
o[prop] = _functions[prop](); | ||
addRule(selector, o, stylesheet, parentSelector); | ||
} | ||
} | ||
var add = function(rules, stylesheet) { | ||
toRegister = []; | ||
API.numOfAddedRules += 1; | ||
prepareRules(rules); | ||
for(var selector in rules) { | ||
if(rules[selector] instanceof Array) { | ||
for(var i=0; i<rules[selector].length, r=rules[selector][i]; i++) { | ||
addRule(selector, r, stylesheet || "mainstream"); | ||
addRule(selector, rules[selector], stylesheet || "mainstream"); | ||
} | ||
// if the selector is already there | ||
for(var i=0; i<toRegister.length; i++) { | ||
var stylesheet = toRegister[i].stylesheet, | ||
selector = toRegister[i].selector, | ||
props = toRegister[i].props, | ||
allRules = API.getRules(stylesheet); | ||
// console.log(selector, props); | ||
if(typeof allRules[selector] == 'object') { | ||
var current = allRules[selector]; | ||
for(var propNew in props) { | ||
// overwrite already added value | ||
if(typeof props[propNew] != 'object') { | ||
current[propNew] = props[propNew]; | ||
} | ||
} | ||
// no, the selector is still not added | ||
} else { | ||
addRule(selector, rules[selector], stylesheet || "mainstream"); | ||
allRules[selector] = props; | ||
} | ||
} | ||
return API; | ||
@@ -799,2 +792,54 @@ } | ||
} | ||
/* http://davidwalsh.name/javascript-clone */ | ||
lib.helpers.Clone = function clone(src) { | ||
function mixin(dest, source, copyFunc) { | ||
var name, s, i, empty = {}; | ||
for(name in source){ | ||
// the (!(name in empty) || empty[name] !== s) condition avoids copying properties in "source" | ||
// inherited from Object.prototype. For example, if dest has a custom toString() method, | ||
// don't overwrite it with the toString() method that source inherited from Object.prototype | ||
s = source[name]; | ||
if(!(name in dest) || (dest[name] !== s && (!(name in empty) || empty[name] !== s))){ | ||
dest[name] = copyFunc ? copyFunc(s) : s; | ||
} | ||
} | ||
return dest; | ||
} | ||
if(!src || typeof src != "object" || Object.prototype.toString.call(src) === "[object Function]"){ | ||
// null, undefined, any non-object, or function | ||
return src; // anything | ||
} | ||
if(src.nodeType && "cloneNode" in src){ | ||
// DOM Node | ||
return src.cloneNode(true); // Node | ||
} | ||
if(src instanceof Date){ | ||
// Date | ||
return new Date(src.getTime()); // Date | ||
} | ||
if(src instanceof RegExp){ | ||
// RegExp | ||
return new RegExp(src); // RegExp | ||
} | ||
var r, i, l; | ||
if(src instanceof Array){ | ||
// array | ||
r = []; | ||
for(i = 0, l = src.length; i < l; ++i){ | ||
if(i in src){ | ||
r.push(clone(src[i])); | ||
} | ||
} | ||
// we don't clone functions for performance reasons | ||
// }else if(d.isFunction(src)){ | ||
// // function | ||
// r = function(){ return src.apply(this, arguments); }; | ||
}else{ | ||
// generic objects | ||
r = src.constructor ? new src.constructor() : {}; | ||
} | ||
return mixin(r, src, clone); | ||
} | ||
// credits: http://www.sitepoint.com/javascript-generate-lighter-darker-color/ | ||
@@ -801,0 +846,0 @@ lib.helpers.ColorLuminance = function (hex, lum) { |
@@ -1,1 +0,1 @@ | ||
var Absurd=function(){var a={api:{},helpers:{},plugins:{},processors:{css:{plugins:{}},html:{plugins:{},helpers:{}},component:{plugins:{}}},ki:{}},b=function(a,b){!function c(){a.length>0&&a.shift().apply(b||{},[c].concat(Array.prototype.slice.call(arguments,0)))}()},d=function(a,b){var c;try{c=(b||document).querySelectorAll(a)}catch(d){c=document.querySelectorAll(a)}return c},e=function(a){var b=document.createElement("div");return b.innerHTML=a,b.childNodes[0]},f=function(a,b,c){return a.addEventListener?(a.addEventListener(b,c,!1),!0):a.attachEvent?a.attachEvent("on"+b,c):void 0},g=function(a){for(var b,c=a.childNodes,d=c.length,e=0,f=/^\s*$/;d>e;e++)b=c[e],3==b.nodeType?f.test(b.nodeValue)&&(a.removeChild(b),e--,d--):1==b.nodeType&&g(b);return a},h=function(b){return b.indexOf("css/CSS.js")>0?a.processors.css.CSS:b.indexOf("html/HTML.js")>0?a.processors.html.HTML:b.indexOf("component/Component.js")>0?a.processors.component.Component:"js-beautify"==b?{html:function(a){return a}}:"./helpers/PropAnalyzer"==b?a.processors.html.helpers.PropAnalyzer:"../../helpers/TransformUppercase"==b?a.helpers.TransformUppercase:"./helpers/TemplateEngine"==b?a.processors.html.helpers.TemplateEngine:"../helpers/Extend"==b?a.helpers.Extend:function(){}},i="",j=function(){var a=[];return{on:function(b,c){return a[b]||(a[b]=[]),a[b].push(c),this},off:function(b,c){return a[b]?(c||(a[b]=[]),this):this},dispatch:function(b,c){if(a[b])for(var d=0;d<a[b].length;d++){var e=a[b][d];e(c)}return this[b]&&"function"==typeof this[b]&&this[b](c),this}}},k=function(c,h){var i=!1,j=!1,k=!1,l=a.helpers.Extend,m={},n=!1,o={events:{}},p=function(a){this.css?h.flush().add(this.css).compile(function(b,e){if(i)i.raw=e,i.element.innerHTML=e;else{var f=document.createElement("style");f.setAttribute("id",c+"-css"),f.setAttribute("type","text/css"),f.innerHTML=e,(d("head")||d("body"))[0].appendChild(f),i={raw:e,element:f}}a()}):a()},q=function(a){if(this.html)if("string"==typeof this.html){if(k===!1){var b=d(this.html);b.length>0&&(k=b[0])}j={"":k.outerHTML.replace(/</g,"<").replace(/>/g,">")},a()}else"object"==typeof this.html?(j=l({},this.html),k===!1?h.flush().morph("html").add(j).compile(function(b,c){k=e(c),a()},this):a()):a();else a()},r=function(a){j?h.flush().morph("html").add(j).compile(function(b,c){!function d(b,c){if("undefined"!=typeof b&&"undefined"!=typeof c){if(b.nodeName!==c.nodeName)return b.parentNode&&b.parentNode.replaceChild(c,b),a(),void 0;if(b.nodeValue!==c.nodeValue&&(b.nodeValue=c.nodeValue),b.attributes){for(var e,f,g=b.attributes,h=c.attributes,i={},j=0;j<g.length,e=g[j];j++){for(var k=0;k<h.length,f=h[k];k++)e.name===f.name&&(b.setAttribute(e.name,f.value),i[e.name]=!0);i[e.name]||b.removeAttribute(e.name)}for(var j=0;j<h.length,f=h[j];j++)i[f.name]||b.setAttribute(f.name,f.value)}if(b.childNodes.length>=c.childNodes.length)for(var j=0;j<b.childNodes.length;j++)d(b.childNodes[j],c.childNodes[j]);else for(var j=0;j<c.childNodes.length;j++)b.appendChild(document.createTextNode("")),d(b.childNodes[j],c.childNodes[j])}}(g(k),g(e(c))),a()},this):a()},s=function(a){!n&&k&&this.get("parent")&&(n=!0,this.get("parent").appendChild(k)),a()},t=function(a){if(k){var b=this,c=function(a){var c=a.getAttribute("data-absurd-event");c=c.split(":"),c.length>=2&&(!o.events[c[0]]||o.events[c[0]].indexOf(a)<0)&&(o.events[c[0]]||(o.events[c[0]]=[]),o.events[c[0]].push(a),f(a,c[0],function(a){"function"==typeof b[c[1]]&&b[c[1]](a)}))};k.hasAttribute("data-absurd-event")&&c(k);for(var d=k.querySelectorAll?k.querySelectorAll("[data-absurd-event]"):[],e=0;e<d.length;e++)c(d[e])}a()};return{populate:function(a){b([p,q,r,s,t,function(){var b={css:i,html:{element:k}};this.dispatch("populated",b),a&&"function"==typeof a.callback&&a.callback(b)}],this)},set:function(a,b){return m[a]=b,this},get:function(a){return m[a]}}},l=function(b){var c={},d={},e=a.helpers.Extend;return c.register=function(a,c){return d[a]=e({},j(),k(a,b),c)},c.get=function(a){if(d[a])return d[a];throw new Error("There is no component with name '"+a+"'.")},c.remove=function(a){return d[a]?(delete d[a],!0):!1},c.list=function(){var a=[];for(var b in d)a.push(b);return a},c.flush=function(){return d={},c},c.broadcast=function(a){for(var b in d)d[b].dispatch(a);return c},c},m=function(){return function(b){var d=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},e={defaultProcessor:a.processors.css.CSS()},f={},g={},h={},i={};e.getRules=function(a){return"undefined"==typeof a?f:("undefined"==typeof f[a]&&(f[a]=[]),f[a])},e.getPlugins=function(){return h},e.getStorage=function(){return g},e.flush=function(){return f={},g=[],i={},e.defaultProcessor=a.processors.css.CSS(),e},e.import=function(){return e.callHooks("import",arguments)?e:e},e.addHook=function(a,b){i[a]||(i[a]=[]);for(var d=!1,e=0;c=i[a][e];e++)c===b&&(d=!0);d===!1?i[a].push(b):null},e.callHooks=function(a,b){if(i[a])for(var d=0;c=i[a][d];d++)if(c.apply(e,b)===!0)return!0;return!1},e.numOfAddedRules=0,e.components=l(e),e.compile=function(a,b){if(e.callHooks("compile",arguments))return e;var c={combineSelectors:!0,minify:!1,processor:e.defaultProcessor,keepCamelCase:!1,api:e};b=d(c,b||{}),b.processor(e.getRules(),a||function(){},b),e.flush()};for(var j in a.api)"compile"!==j&&(e[j]=a.api[j](e),e[j]=function(b){return function(){var c=a.api[b](e);return e.callHooks(b,arguments)?e:c.apply(e,arguments)}}(j));for(var k in a.plugins)e.plugin(k,a.plugins[k]());return"function"==typeof b&&b(e),e}};a.api.add=function(a){var b=h("../helpers/Extend"),c=function(b,c,d,e){var g=a.getPlugins()[c];if("undefined"!=typeof g){var h=g(a,d);return h&&f(b,h,e),!0}return!1},d=function(b){var c=a.getPlugins();for(var d in b)"undefined"!=typeof c[d]&&(b[d]=!1);for(var d in b)":"===d.charAt(0)&&(b[d]=!1);for(var d in b)/&/g.test(d)&&(b[d]=!1)},e=function(a,b,d){for(var g in b)"object"==typeof b[g]?(":"===g.charAt(0)?f(a+g,b[g],d):/&/g.test(g)?f(g.replace(/&/g,a),b[g],d):0===g.indexOf("@media")||0===g.indexOf("@supports")?f(a,b[g],g):0===a.indexOf("@media")||0===g.indexOf("@supports")?f(g,b[g],a):c(a,g,b[g],d)===!1&&f(a+" "+g,b[g],d),b[g]=!1):"function"==typeof b[g]?(b[g]=b[g](),e(a,b,d)):c(a,g,b[g],d)&&(b[g]=!1)},f=function(b,g,h){if("undefined"==typeof g.length||"object"!=typeof g){if(!c(null,b,g,h)){if("object"==typeof a.getRules(h||"mainstream")[b]){var i=a.getRules(h||"mainstream")[b];for(var j in g)"object"!=typeof g[j]&&(i[j]=g[j])}else a.getRules(h||"mainstream")[b]=g;e(b,g,h||"mainstream"),d(g)}}else for(var k=0;prop=g[k];k++)f(b,prop,h)},g=function(a){if(a instanceof Array)for(var c=0;c<a.length;c++)g(a[c]);else for(var d in a){var e=a[d];if("object"==typeof e&&g(e),/, ?/g.test(d)){for(var f=d.replace(/, /g,",").split(","),c=0;c<f.length,p=f[c];c++)a[p]=a[p]?b({},a[p],e):b({},e);delete a[d]}}},i=function(b,c){a.numOfAddedRules+=1,g(b);for(var d in b)if(b[d]instanceof Array)for(var e=0;e<b[d].length,r=b[d][e];e++)f(d,r,c||"mainstream");else f(d,b[d],c||"mainstream");return a};return i};var n=h("../helpers/Extend");a.api.compile=function(a){return function(){for(var b=null,c=null,d=null,e=0;e<arguments.length;e++)switch(typeof arguments[e]){case"function":c=arguments[e];break;case"string":b=arguments[e];break;case"object":d=arguments[e]}var f={combineSelectors:!0,minify:!1,keepCamelCase:!1,processor:a.defaultProcessor,api:a};d=n(f,d||{}),d.processor(a.getRules(),function(d,e){if(null!=b)try{t.writeFile(b,e,function(a){c(a,e)})}catch(d){c.apply({},arguments)}else c.apply({},arguments);a.flush()},d)}},a.api.compileFile=function(a){return a.compile};var q=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e};a.api.darken=function(){return function(a,b){return q(a,-(b/100))}},a.api.hook=function(a){return function(b,c){return a.addHook(b,c),a}};var q=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e};a.api.lighten=function(){return function(a,b){return q(a,b/100)}};var s={html:function(a){a.defaultProcessor=h(i+"/../processors/html/HTML.js")(),a.hook("add",function(b,c){return a.getRules(c||"mainstream").push(b),!0})},component:function(a){a.defaultProcessor=h(i+"/../processors/component/Component.js")(),a.hook("add",function(b){b instanceof Array||(b=[b]);for(var d=0;d<b.length,c=b[d];d++)a.getRules("mainstream").push(c);return!0})}};a.api.morph=function(a){return function(b){return s[b]&&(a.flush(),s[b](a)),a}},a.api.plugin=function(a){var b=function(b,c){return a.getPlugins()[b]=c,a};return b},a.api.raw=function(a){return function(b){var c={},d={},e="____raw_"+a.numOfAddedRules;return d[e]=b,c[e]=d,a.add(c),a}};{var t=h("fs");h("path")}a.api.rawImport=function(a){var b=function(b){var c=t.readFileSync(b,{encoding:"utf8"});a.raw(c)};return function(c){var d,e,f;if("string"==typeof c)b(c);else for(e=0,f=c.length;f>e;e++)d=c[e],b(d);return a}},a.api.register=function(a){return function(b,c){return a[b]=c,a}},a.api.storage=function(a){var b=a.getStorage(),c=function(d,e){if("undefined"!=typeof e)b[d]=e;else{if("object"!=typeof d){if(b[d])return b[d];throw new Error("There is no data in the storage associated with '"+d+"'")}for(var f in d)Object.prototype.hasOwnProperty.call(d,f)&&c(f,d[f])}return a};return c},a.helpers.ColorLuminance=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e},a.helpers.Extend=function(){for(var a=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},b=arguments[0],c=1;c<arguments.length;c++)b=a(b,arguments[c]);return b},a.helpers.RequireUncached=function(a){return delete h.cache[h.resolve(a)],h(a)},a.helpers.TransformUppercase=function(a,b){for(var d="",e=0;c=a.charAt(e);e++)d+=b&&b.keepCamelCase===!0?c:c===c.toUpperCase()&&c.toLowerCase()!==c.toUpperCase()?"-"+c.toLowerCase():c;return d};var u=function(a,b,d){var e="",f="",g=[],j=d.api;cssPreprocessor=h(i+"/../css/CSS.js")(),htmlPreprocessor=h(i+"/../html/HTML.js")();for(var k=function(a){for(var b=0;b<g.length,component=g[b];b++)"function"==typeof component&&(component=component()),j.add(component.css?component.css:{});cssPreprocessor(j.getRules(),function(b,c){e+=c,a(b)},d)},l=function(b){var c=0,e=null,g=function(){if(c>a.length-1)return b(e),void 0;var h=a[c];"function"==typeof h&&(h=h()),j.morph("html").add(h.html?h.html:{}),htmlPreprocessor(j.getRules(),function(a,b){f+=b,c+=1,e=a,g()},d)};g()},m=function(a){for(var b in a)if("_include"===b)if(a[b]instanceof Array)for(var d=0;d<a[b].length,c=a[b][d];d++)"function"==typeof c&&(c=c()),g.push(c),m(c);else"function"==typeof a[b]&&(a[b]=a[b]()),g.push(a[b]),m(a[b]);else"object"==typeof a[b]&&m(a[b])},n=0;n<a.length,c=a[n];n++)"function"==typeof c&&(c=c()),g.push(c),m(c);j.flush(),k(function(a){j.morph("html"),l(function(c){b(a||c?{error:{css:a,html:c}}:null,e,f)})})};a.processors.component.Component=function(){var a=function(a,b,c){u(a.mainstream,b,c)};return a.type="component",a};var w="\n",x={combineSelectors:!0,minify:!1,keepCamelCase:!1},y=h("../../helpers/TransformUppercase"),z=function(a,b){var c="";for(var d in a)if(0===d.indexOf("____raw"))c+=a[d][d]+w;else{var e=d+" {"+w;for(var f in a[d]){var g=a[d][f];""===g&&(g='""'),e+=" "+y(f,b)+": "+g+";"+w}e+="}"+w,c+=e}return c},A=function(a){var b={};for(var c in a){var d=!1,e={};for(var f in a[c]){var g=a[c][f];g!==!1&&"object"!=typeof g&&(d=!0,e[f]=g)}d&&(b[c]=e)}return b},B=function(a){var b={},c={};for(var d in a){var e=a[d];for(var f in e){var g=e[f];b[f]||(b[f]={}),b[f][g]||(b[f][g]=[]),b[f][g].push(d)}}for(var f in b){var h=b[f];for(var g in h){var i=h[g];c[i.join(", ")]||(c[i.join(", ")]={});var d=c[i.join(", ")];d[f]=g}}return c},C=function(a){return a=a.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\/|[\r\n\t]+/g,""),a=a.replace(/ {2,}/g," "),a=a.replace(/ ([{:}]) /g,"$1"),a=a.replace(/([;,]) /g,"$1"),a=a.replace(/ !/g,"!")};a.processors.css.CSS=function(){var a=function(a,b,c){c=c||x;var d="";for(var e in a){var f=A(a[e]);f=c.combineSelectors?B(f):f,d+="mainstream"===e?z(f,c):e+" {"+w+z(f,c)+"}"+w}return c.minify?(d=C(d),b&&b(null,d)):b&&b(null,d),d};return a.type="css",a},a.processors.css.plugins.charset=function(){return function(a,b){"string"==typeof b?a.raw('@charset: "'+b+'";'):"object"==typeof b&&(b=b.charset.replace(/:/g,"").replace(/'/g,"").replace(/"/g,"").replace(/ /g,""),a.raw('@charset: "'+b+'";'))}},a.processors.css.plugins.document=function(){return function(a,b){if("object"==typeof b){var c="";if(c+="@"+b.vendor+"document",c+=" "+b.document,b.rules&&b.rules.length)for(var d=0;rule=b.rules[d];d++)a.handlecssrule(rule,c);else"undefined"!=typeof b.styles&&a.add(b.styles,c)}}},a.processors.css.plugins.keyframes=function(){return function(a,b){var c=h(i+"/../CSS.js")();if("object"==typeof b)if("undefined"!=typeof b.frames){var d="@keyframes "+b.name+" {\n";d+=c({mainstream:b.frames}),d+="}",a.raw(d+"\n"+d.replace("@keyframes","@-webkit-keyframes"))}else if("undefined"!=typeof b.keyframes){for(var d="@keyframes "+b.name+" {\n",e={},f=0;rule=b.keyframes[f];f++)if("keyframe"===rule.type)for(var g=e[rule.values]={},j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value);d+=c({mainstream:e}),d+="}",a.raw(d+"\n"+d.replace("@keyframes","@-webkit-keyframes"))}}},a.processors.css.plugins.media=function(){return function(a,b){var c=h(i+"/../CSS.js")();if("object"==typeof b){for(var d="@media "+b.media+" {\n",e={},f=0;rule=b.rules[f];f++){var g=e[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value)}d+=c({mainstream:e}),d+="}",a.raw(d)}}},a.processors.css.plugins.namespace=function(){return function(a,b){"string"==typeof b?a.raw('@namespace: "'+b+'";'):"object"==typeof b&&(b=b.namespace.replace(/: /g,"").replace(/'/g,"").replace(/"/g,"").replace(/ /g,"").replace(/:h/g,"h"),a.raw('@namespace: "'+b+'";'))}},a.processors.css.plugins.page=function(){return function(a,b){if("object"==typeof b){var c="";c+=b.selectors.length>0?"@page "+b.selectors.join(", ")+" {\n":"@page {\n";for(var d=0;declaration=b.declarations[d];d++)"declaration"==declaration.type&&(c+=" "+declaration.property+": "+declaration.value+";\n");c+="}",a.raw(c)}}},a.processors.css.plugins.supports=function(){return function(a,b){var c=h(i+"/../CSS.js")();if("object"==typeof b){for(var d="@supports "+b.supports+" {\n",e={},f=0;rule=b.rules[f];f++){var g=e[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value)}d+=c({mainstream:e}),d+="}",a.raw(d)}}};var D=null,w="\n",x={},E=h("js-beautify").html,y=h("../../helpers/TransformUppercase"),F={},G=function(a){var b="";for(var c in D)if(c==a)for(var d=D[c].length,e=0;d>e;e++)b+=H("",D[c][e]);return b},H=function(a,b){var c="",d="",e="",f=h("./helpers/PropAnalyzer")(a);if(a=f.tag,""!=f.attrs&&(d+=" "+f.attrs),"string"==typeof b)return I(a,d,b);var g=function(a){""!=e&&(e+=w),e+=a};for(var i in b){var j=b[i];switch(i){case"_attrs":for(var k in j)d+="function"==typeof j[k]?" "+y(k,F)+'="'+j[k]()+'"':" "+y(k,F)+'="'+j[k]+'"';b[i]=!1;break;case"_":g(j),b[i]=!1;break;case"_tpl":if("string"==typeof j)g(G(j));else if(j instanceof Array){for(var l="",m=0;tpl=j[m];m++)l+=G(tpl),m<j.length-1&&(l+=w);g(l)}b[i]=!1;break;case"_include":var l="",n=function(a){"function"==typeof a&&(a=a()),a.css&&a.html&&(a=a.html),l+=H("",a)};if(j instanceof Array)for(var m=0;m<j.length,o=j[m];m++)n(o);else"object"==typeof j&&n(j);g(l),b[i]=!1}}for(var p in b){var j=b[p];if(j!==!1){var q=p;switch(typeof j){case"string":g(H(q,j));break;case"object":if(j.length&&j.length>0){for(var l="",m=0;v=j[m];m++)l+=H("","function"==typeof v?v():v),m<j.length-1&&(l+=w);g(H(q,l))}else g(H(q,j));break;case"function":g(H(q,j()))}}}return c+=""!=a?I(a,d,e):e},I=function(a,b,c){var d="";return""==a&&""==b&&""!=c?c:(a=""==a?"div":a,d+=""!==c?"<"+y(a,F)+b+">"+w+c+w+"</"+y(a,F)+">":"<"+y(a,F)+b+"/>")},J=function(a){return a=h("./helpers/TemplateEngine")(a.replace(/[\r\t\n]/g,""),F),F.minify?a:E(a,{indent_size:F.indentSize||4})};return a.processors.html.HTML=function(){var a=function(a,b,c){D=a,b=b||function(){},c=F=c||x;var d=J(G("mainstream"));return b(null,d),d};return a.type="html",a},a.processors.html.helpers.PropAnalyzer=function(a){for(var b={tag:"",attrs:""},d=(a.length,""),e=!1,f=[],g="",h=!1,i="",j=!1,k=0;c=a[k];k++)"["!==c||j?j?"]"!=c?i+=c:(j=!1,k-=1):"."!==c||e?e?"."!=c&&"#"!=c&&"["!=c&&"]"!=c?d+=c:(f.push(d),e=!1,d="",k-=1):"#"!==c||h?h?"."!=c&&"#"!=c&&"["!=c&&"]"!=c?g+=c:(h=!1,k-=1):"."!=c&&"#"!=c&&"["!=c&&"]"!=c&&(b.tag+=c):h=!0:e=!0:j=!0;""!=d&&f.push(d);for(var l="",k=0;cls=f[k];k++)l+=""===l?cls:" "+cls;return b.attrs+=""!=l?'class="'+l+'"':"",""!=g&&(b.attrs+=(""!=b.attrs?" ":"")+'id="'+g+'"'),""===b.tag&&""!=b.attrs&&(b.tag="div"),""!=i&&(b.attrs+=(""!=b.attrs?" ":"")+i),b},a.processors.html.helpers.TemplateEngine=function(a,b){for(var c=/<%(.+?)%>/g,d=/(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g,e="var r=[];\n",f=0,g=function(a,b){return e+=b?a.match(d)?a+"\n":"r.push("+a+");\n":""!=a?'r.push("'+a.replace(/"/g,'\\"')+'");\n':"",g};match=c.exec(a);)g(a.slice(f,match.index))(match[1],!0),f=match.index+match[0].length;return g(a.substr(f,a.length-f)),e+='return r.join("");',new Function(e.replace(/[\r\t\n]/g,"")).apply(b)},m()}(window); | ||
var Absurd=function(){var a={api:{},helpers:{},plugins:{},processors:{css:{plugins:{}},html:{plugins:{},helpers:{}},component:{plugins:{}}},ki:{}},b=function(a,b){!function c(){a.length>0&&a.shift().apply(b||{},[c].concat(Array.prototype.slice.call(arguments,0)))}()},d=function(a,b){var c;try{c=(b||document).querySelectorAll(a)}catch(d){c=document.querySelectorAll(a)}return c},e=function(a){var b=document.createElement("div");return b.innerHTML=a,b.childNodes[0]},f=function(a,b,c){return a.addEventListener?(a.addEventListener(b,c,!1),!0):a.attachEvent?a.attachEvent("on"+b,c):void 0},g=function(a){for(var b,c=a.childNodes,d=c.length,e=0,f=/^\s*$/;d>e;e++)b=c[e],3==b.nodeType?f.test(b.nodeValue)&&(a.removeChild(b),e--,d--):1==b.nodeType&&g(b);return a},h=function(b){return b.indexOf("css/CSS.js")>0?a.processors.css.CSS:b.indexOf("html/HTML.js")>0?a.processors.html.HTML:b.indexOf("component/Component.js")>0?a.processors.component.Component:"js-beautify"==b?{html:function(a){return a}}:"./helpers/PropAnalyzer"==b?a.processors.html.helpers.PropAnalyzer:"../../helpers/TransformUppercase"==b?a.helpers.TransformUppercase:"./helpers/TemplateEngine"==b?a.processors.html.helpers.TemplateEngine:"../helpers/Extend"==b?a.helpers.Extend:"../helpers/Clone"==b?a.helpers.Clone:function(){}},i="",j=function(){var a=[];return{on:function(b,c){return a[b]||(a[b]=[]),a[b].push(c),this},off:function(b,c){return a[b]?(c||(a[b]=[]),this):this},dispatch:function(b,c){if(a[b])for(var d=0;d<a[b].length;d++){var e=a[b][d];e(c)}return this[b]&&"function"==typeof this[b]&&this[b](c),this}}},k=function(c,h){var i=!1,j=!1,k=!1,l=a.helpers.Extend,m={},n=!1,o={events:{}},p=function(a){this.css?h.flush().add(this.css).compile(function(b,e){if(i)i.raw!==e&&(i.raw=e,i.element.innerHTML=e);else{var f=document.createElement("style");f.setAttribute("id",c+"-css"),f.setAttribute("type","text/css"),f.innerHTML=e,(d("head")||d("body"))[0].appendChild(f),i={raw:e,element:f}}a()}):a()},q=function(a){if(this.html)if("string"==typeof this.html){if(k===!1){var b=d(this.html);b.length>0&&(k=b[0]),j={"":k.outerHTML.replace(/</g,"<").replace(/>/g,">")}}a()}else"object"==typeof this.html?(j=l({},this.html),k===!1?h.flush().morph("html").add(j).compile(function(b,c){k=e(c),a()},this):a()):a();else a()},r=function(a){j?h.flush().morph("html").add(j).compile(function(b,c){!function d(b,c){if("undefined"!=typeof b&&"undefined"!=typeof c&&!b.isEqualNode(c)){if(b.nodeName!==c.nodeName)return b.parentNode&&b.parentNode.replaceChild(c,b),a(),void 0;if(b.nodeValue!==c.nodeValue&&(b.nodeValue=c.nodeValue),b.attributes){for(var e,f,g=b.attributes,h=c.attributes,i={},j=0;j<g.length,e=g[j];j++){for(var k=0;k<h.length,f=h[k];k++)e.name===f.name&&(b.setAttribute(e.name,f.value),i[e.name]=!0);i[e.name]||b.removeAttribute(e.name)}for(var j=0;j<h.length,f=h[j];j++)i[f.name]||b.setAttribute(f.name,f.value)}if(b.childNodes.length>=c.childNodes.length)for(var j=0;j<b.childNodes.length;j++)c.childNodes[j]||c.appendChild(document.createTextNode("")),d(b.childNodes[j],c.childNodes[j]);else for(var j=0;j<c.childNodes.length;j++)b.appendChild(document.createTextNode("")),d(b.childNodes[j],c.childNodes[j])}}(g(k),g(e(c))),a()},this):a()},s=function(a){!n&&k&&this.get("parent")&&(n=!0,this.get("parent").appendChild(k)),a()},t=function(a){if(k){var b=this,c=function(a){var c=a.getAttribute("data-absurd-event");c=c.split(":"),c.length>=2&&(!o.events[c[0]]||o.events[c[0]].indexOf(a)<0)&&(o.events[c[0]]||(o.events[c[0]]=[]),o.events[c[0]].push(a),f(a,c[0],function(a){"function"==typeof b[c[1]]&&b[c[1]](a)}))};k.hasAttribute("data-absurd-event")&&c(k);for(var d=k.querySelectorAll?k.querySelectorAll("[data-absurd-event]"):[],e=0;e<d.length;e++)c(d[e])}a()},u={populate:function(a){b([p,q,r,s,t,function(){var b={css:i,html:{element:k}};this.dispatch("populated",b),a&&"function"==typeof a.callback&&a.callback(b)}],this)},set:function(a,b){return m[a]=b,this},get:function(a){return m[a]}};return u},l=function(b){var c={},d={},e=a.helpers.Extend;return c.register=function(a,c){return d[a]=e({},j(),k(a,b),c)},c.get=function(a){if(d[a])return d[a];throw new Error("There is no component with name '"+a+"'.")},c.remove=function(a){return d[a]?(delete d[a],!0):!1},c.list=function(){var a=[];for(var b in d)a.push(b);return a},c.flush=function(){return d={},c},c.broadcast=function(a){for(var b in d)d[b].dispatch(a);return c},c},m=function(){return function(b){var d=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},e={defaultProcessor:a.processors.css.CSS()},f={},g={},h={},i={};e.getRules=function(a){return"undefined"==typeof a?f:("undefined"==typeof f[a]&&(f[a]=[]),f[a])},e.getPlugins=function(){return h},e.getStorage=function(){return g},e.flush=function(){return f={},g=[],i={},e.defaultProcessor=a.processors.css.CSS(),e},e.import=function(){return e.callHooks("import",arguments)?e:e},e.addHook=function(a,b){i[a]||(i[a]=[]);for(var d=!1,e=0;c=i[a][e];e++)c===b&&(d=!0);d===!1?i[a].push(b):null},e.callHooks=function(a,b){if(i[a])for(var d=0;c=i[a][d];d++)if(c.apply(e,b)===!0)return!0;return!1},e.numOfAddedRules=0,e.components=l(e),e.compile=function(a,b){if(e.callHooks("compile",arguments))return e;var c={combineSelectors:!0,minify:!1,processor:e.defaultProcessor,keepCamelCase:!1,api:e};b=d(c,b||{}),b.processor(e.getRules(),a||function(){},b),e.flush()};for(var j in a.api)"compile"!==j&&(e[j]=a.api[j](e),e[j]=function(b){return function(){var c=a.api[b](e);return e.callHooks(b,arguments)?e:c.apply(e,arguments)}}(j));for(var k in a.plugins)e.plugin(k,a.plugins[k]());return"function"==typeof b&&b(e),e}};a.api.add=function(a){var b=(h("../helpers/Extend"),h("../helpers/Clone"),[]),c=function(b,c,e,f,g){var h=a.getPlugins()[c];if("undefined"!=typeof h){var i=h(a,e);return i&&d(b,i,f,g),!0}return!1},d=function(a,e,f,g){if(f=f||"mainstream",/, ?/g.test(a))for(var h=a.replace(/, /g,",").split(","),i=0;i<h.length,p=h[i];i++)d(p,e,f,g);else if("undefined"==typeof e.length||"object"!=typeof e){if(!c(null,a,e,f,g)){var j={},k=a,l={},m={};for(var n in e){var o=typeof e[n];"object"!==o&&"function"!==o?c(a,n,e[n],f,g)===!1&&(k="undefined"!=typeof g?g+" "+a:a,j[n]=e[n]):"object"===o?l[n]=e[n]:"function"===o&&(m[n]=e[n])}b.push({selector:k,props:j,stylesheet:f});for(var n in l)":"===n.charAt(0)?d(a+n,l[n],f,g):/&/g.test(n)?d(n.replace(/&/g,a),l[n],f,g):0===n.indexOf("@media")||0===n.indexOf("@supports")?d(a,l[n],n,g):0===a.indexOf("@media")||0===n.indexOf("@supports")?d(n,l[n],a,g):c(a,n,l[n],f,g)===!1&&d(n,l[n],f,(g?g+" ":"")+a);for(var n in m){var q={};q[n]=m[n](),d(a,q,f,g)}}}else for(var i=0;i<e.length,n=e[i];i++)d(a,n,f,g)},e=function(c,e){b=[],a.numOfAddedRules+=1;for(var f in c)d(f,c[f],e||"mainstream");for(var g=0;g<b.length;g++){var e=b[g].stylesheet,f=b[g].selector,h=b[g].props,i=a.getRules(e);if("object"==typeof i[f]){var j=i[f];for(var k in h)"object"!=typeof h[k]&&(j[k]=h[k])}else i[f]=h}return a};return e};var n=h("../helpers/Extend");a.api.compile=function(a){return function(){for(var b=null,c=null,d=null,e=0;e<arguments.length;e++)switch(typeof arguments[e]){case"function":c=arguments[e];break;case"string":b=arguments[e];break;case"object":d=arguments[e]}var f={combineSelectors:!0,minify:!1,keepCamelCase:!1,processor:a.defaultProcessor,api:a};d=n(f,d||{}),d.processor(a.getRules(),function(d,e){if(null!=b)try{s.writeFile(b,e,function(a){c(a,e)})}catch(d){c.apply({},arguments)}else c.apply({},arguments);a.flush()},d)}},a.api.compileFile=function(a){return a.compile};var q=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e};a.api.darken=function(){return function(a,b){return q(a,-(b/100))}},a.api.hook=function(a){return function(b,c){return a.addHook(b,c),a}};var q=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e};a.api.lighten=function(){return function(a,b){return q(a,b/100)}};var r={html:function(a){a.defaultProcessor=h(i+"/../processors/html/HTML.js")(),a.hook("add",function(b,c){return a.getRules(c||"mainstream").push(b),!0})},component:function(a){a.defaultProcessor=h(i+"/../processors/component/Component.js")(),a.hook("add",function(b){b instanceof Array||(b=[b]);for(var d=0;d<b.length,c=b[d];d++)a.getRules("mainstream").push(c);return!0})}};a.api.morph=function(a){return function(b){return r[b]&&(a.flush(),r[b](a)),a}},a.api.plugin=function(a){var b=function(b,c){return a.getPlugins()[b]=c,a};return b},a.api.raw=function(a){return function(b){var c={},d={},e="____raw_"+a.numOfAddedRules;return d[e]=b,c[e]=d,a.add(c),a}};{var s=h("fs");h("path")}a.api.rawImport=function(a){var b=function(b){var c=s.readFileSync(b,{encoding:"utf8"});a.raw(c)};return function(c){var d,e,f;if("string"==typeof c)b(c);else for(e=0,f=c.length;f>e;e++)d=c[e],b(d);return a}},a.api.register=function(a){return function(b,c){return a[b]=c,a}},a.api.storage=function(a){var b=a.getStorage(),c=function(d,e){if("undefined"!=typeof e)b[d]=e;else{if("object"!=typeof d){if(b[d])return b[d];throw new Error("There is no data in the storage associated with '"+d+"'")}for(var f in d)Object.prototype.hasOwnProperty.call(d,f)&&c(f,d[f])}return a};return c},a.helpers.Clone=function J(a){function b(a,b,c){var d,e,f={};for(d in b)e=b[d],d in a&&(a[d]===e||d in f&&f[d]===e)||(a[d]=c?c(e):e);return a}if(!a||"object"!=typeof a||"[object Function]"===Object.prototype.toString.call(a))return a;if(a.nodeType&&"cloneNode"in a)return a.cloneNode(!0);if(a instanceof Date)return new Date(a.getTime());if(a instanceof RegExp)return new RegExp(a);var c,d,e;if(a instanceof Array)for(c=[],d=0,e=a.length;e>d;++d)d in a&&c.push(J(a[d]));else c=a.constructor?new a.constructor:{};return b(c,a,J)},a.helpers.ColorLuminance=function(a,b){a=String(a).replace(/[^0-9a-f]/gi,""),a.length<6&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),b=b||0;var c,d,e="#";for(d=0;3>d;d++)c=parseInt(a.substr(2*d,2),16),c=Math.round(Math.min(Math.max(0,c+c*b),255)).toString(16),e+=("00"+c).substr(c.length);return e},a.helpers.Extend=function(){for(var a=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},b=arguments[0],c=1;c<arguments.length;c++)b=a(b,arguments[c]);return b},a.helpers.RequireUncached=function(a){return delete h.cache[h.resolve(a)],h(a)},a.helpers.TransformUppercase=function(a,b){for(var d="",e=0;c=a.charAt(e);e++)d+=b&&b.keepCamelCase===!0?c:c===c.toUpperCase()&&c.toLowerCase()!==c.toUpperCase()?"-"+c.toLowerCase():c;return d};var t=function(a,b,d){var e="",f="",g=[],j=d.api;cssPreprocessor=h(i+"/../css/CSS.js")(),htmlPreprocessor=h(i+"/../html/HTML.js")();for(var k=function(a){for(var b=0;b<g.length,component=g[b];b++)"function"==typeof component&&(component=component()),j.add(component.css?component.css:{});cssPreprocessor(j.getRules(),function(b,c){e+=c,a(b)},d)},l=function(b){var c=0,e=null,g=function(){if(c>a.length-1)return b(e),void 0;var h=a[c];"function"==typeof h&&(h=h()),j.morph("html").add(h.html?h.html:{}),htmlPreprocessor(j.getRules(),function(a,b){f+=b,c+=1,e=a,g()},d)};g()},m=function(a){for(var b in a)if("_include"===b)if(a[b]instanceof Array)for(var d=0;d<a[b].length,c=a[b][d];d++)"function"==typeof c&&(c=c()),g.push(c),m(c);else"function"==typeof a[b]&&(a[b]=a[b]()),g.push(a[b]),m(a[b]);else"object"==typeof a[b]&&m(a[b])},n=0;n<a.length,c=a[n];n++)"function"==typeof c&&(c=c()),g.push(c),m(c);j.flush(),k(function(a){j.morph("html"),l(function(c){b(a||c?{error:{css:a,html:c}}:null,e,f)})})};a.processors.component.Component=function(){var a=function(a,b,c){t(a.mainstream,b,c)};return a.type="component",a};var u="\n",w={combineSelectors:!0,minify:!1,keepCamelCase:!1},x=h("../../helpers/TransformUppercase"),y=function(a,b){var c="";for(var d in a)if(0===d.indexOf("____raw"))c+=a[d][d]+u;else{var e=d+" {"+u;for(var f in a[d]){var g=a[d][f];""===g&&(g='""'),e+=" "+x(f,b)+": "+g+";"+u}e+="}"+u,c+=e}return c},z=function(a){var b={};for(var c in a){var d=!1,e={};for(var f in a[c]){var g=a[c][f];g!==!1&&"object"!=typeof g&&(d=!0,e[f]=g)}d&&(b[c]=e)}return b},A=function(a){var b={},c={};for(var d in a){var e=a[d];for(var f in e){var g=e[f];b[f]||(b[f]={}),b[f][g]||(b[f][g]=[]),b[f][g].push(d)}}for(var f in b){var h=b[f];for(var g in h){var i=h[g];c[i.join(", ")]||(c[i.join(", ")]={});var d=c[i.join(", ")];d[f]=g}}return c},B=function(a){return a=a.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\/|[\r\n\t]+/g,""),a=a.replace(/ {2,}/g," "),a=a.replace(/ ([{:}]) /g,"$1"),a=a.replace(/([;,]) /g,"$1"),a=a.replace(/ !/g,"!")};a.processors.css.CSS=function(){var a=function(a,b,c){c=c||w;var d="";for(var e in a){var f=z(a[e]);f=c.combineSelectors?A(f):f,d+="mainstream"===e?y(f,c):e+" {"+u+y(f,c)+"}"+u}return c.minify?(d=B(d),b&&b(null,d)):b&&b(null,d),d};return a.type="css",a},a.processors.css.plugins.charset=function(){return function(a,b){"string"==typeof b?a.raw('@charset: "'+b+'";'):"object"==typeof b&&(b=b.charset.replace(/:/g,"").replace(/'/g,"").replace(/"/g,"").replace(/ /g,""),a.raw('@charset: "'+b+'";'))}},a.processors.css.plugins.document=function(){return function(a,b){if("object"==typeof b){var c="";if(c+="@"+b.vendor+"document",c+=" "+b.document,b.rules&&b.rules.length)for(var d=0;rule=b.rules[d];d++)a.handlecssrule(rule,c);else"undefined"!=typeof b.styles&&a.add(b.styles,c)}}},a.processors.css.plugins.keyframes=function(){return function(a,b){var c=h(i+"/../CSS.js")();if("object"==typeof b)if("undefined"!=typeof b.frames){var d="@keyframes "+b.name+" {\n";d+=c({mainstream:b.frames}),d+="}",a.raw(d+"\n"+d.replace("@keyframes","@-webkit-keyframes"))}else if("undefined"!=typeof b.keyframes){for(var d="@keyframes "+b.name+" {\n",e={},f=0;rule=b.keyframes[f];f++)if("keyframe"===rule.type)for(var g=e[rule.values]={},j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value);d+=c({mainstream:e}),d+="}",a.raw(d+"\n"+d.replace("@keyframes","@-webkit-keyframes"))}}},a.processors.css.plugins.media=function(){return function(a,b){var c=h(i+"/../CSS.js")();if("object"==typeof b){for(var d="@media "+b.media+" {\n",e={},f=0;rule=b.rules[f];f++){var g=e[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value)}d+=c({mainstream:e}),d+="}",a.raw(d)}}},a.processors.css.plugins.namespace=function(){return function(a,b){"string"==typeof b?a.raw('@namespace: "'+b+'";'):"object"==typeof b&&(b=b.namespace.replace(/: /g,"").replace(/'/g,"").replace(/"/g,"").replace(/ /g,"").replace(/:h/g,"h"),a.raw('@namespace: "'+b+'";'))}},a.processors.css.plugins.page=function(){return function(a,b){if("object"==typeof b){var c="";c+=b.selectors.length>0?"@page "+b.selectors.join(", ")+" {\n":"@page {\n";for(var d=0;declaration=b.declarations[d];d++)"declaration"==declaration.type&&(c+=" "+declaration.property+": "+declaration.value+";\n");c+="}",a.raw(c)}}},a.processors.css.plugins.supports=function(){return function(a,b){var c=h(i+"/../CSS.js")();if("object"==typeof b){for(var d="@supports "+b.supports+" {\n",e={},f=0;rule=b.rules[f];f++){var g=e[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(g[declaration.property]=declaration.value)}d+=c({mainstream:e}),d+="}",a.raw(d)}}};var C=null,u="\n",w={},D=h("js-beautify").html,x=h("../../helpers/TransformUppercase"),E={},F=function(a){var b="";for(var c in C)if(c==a)for(var d=C[c].length,e=0;d>e;e++)b+=G("",C[c][e]);return b},G=function(a,b){var c="",d="",e="",f=h("./helpers/PropAnalyzer")(a);if(a=f.tag,""!=f.attrs&&(d+=" "+f.attrs),"string"==typeof b)return H(a,d,b);var g=function(a){""!=e&&(e+=u),e+=a};for(var i in b){var j=b[i];switch(i){case"_attrs":for(var k in j)d+="function"==typeof j[k]?" "+x(k,E)+'="'+j[k]()+'"':" "+x(k,E)+'="'+j[k]+'"';b[i]=!1;break;case"_":g(j),b[i]=!1;break;case"_tpl":if("string"==typeof j)g(F(j));else if(j instanceof Array){for(var l="",m=0;tpl=j[m];m++)l+=F(tpl),m<j.length-1&&(l+=u);g(l)}b[i]=!1;break;case"_include":var l="",n=function(a){"function"==typeof a&&(a=a()),a.css&&a.html&&(a=a.html),l+=G("",a)};if(j instanceof Array)for(var m=0;m<j.length,o=j[m];m++)n(o);else"object"==typeof j&&n(j);g(l),b[i]=!1}}for(var p in b){var j=b[p];if(j!==!1){var q=p;switch(typeof j){case"string":g(G(q,j));break;case"object":if(j.length&&j.length>0){for(var l="",m=0;v=j[m];m++)l+=G("","function"==typeof v?v():v),m<j.length-1&&(l+=u);g(G(q,l))}else g(G(q,j));break;case"function":g(G(q,j()))}}}return c+=""!=a?H(a,d,e):e},H=function(a,b,c){var d="";return""==a&&""==b&&""!=c?c:(a=""==a?"div":a,d+=""!==c?"<"+x(a,E)+b+">"+u+c+u+"</"+x(a,E)+">":"<"+x(a,E)+b+"/>")},I=function(a){return a=h("./helpers/TemplateEngine")(a.replace(/[\r\t\n]/g,""),E),E.minify?a:D(a,{indent_size:E.indentSize||4})};return a.processors.html.HTML=function(){var a=function(a,b,c){C=a,b=b||function(){},c=E=c||w;var d=I(F("mainstream"));return b(null,d),d};return a.type="html",a},a.processors.html.helpers.PropAnalyzer=function(a){for(var b={tag:"",attrs:""},d=(a.length,""),e=!1,f=[],g="",h=!1,i="",j=!1,k=0;c=a[k];k++)"["!==c||j?j?"]"!=c?i+=c:(j=!1,k-=1):"."!==c||e?e?"."!=c&&"#"!=c&&"["!=c&&"]"!=c?d+=c:(f.push(d),e=!1,d="",k-=1):"#"!==c||h?h?"."!=c&&"#"!=c&&"["!=c&&"]"!=c?g+=c:(h=!1,k-=1):"."!=c&&"#"!=c&&"["!=c&&"]"!=c&&(b.tag+=c):h=!0:e=!0:j=!0;""!=d&&f.push(d);for(var l="",k=0;cls=f[k];k++)l+=""===l?cls:" "+cls;return b.attrs+=""!=l?'class="'+l+'"':"",""!=g&&(b.attrs+=(""!=b.attrs?" ":"")+'id="'+g+'"'),""===b.tag&&""!=b.attrs&&(b.tag="div"),""!=i&&(b.attrs+=(""!=b.attrs?" ":"")+i),b},a.processors.html.helpers.TemplateEngine=function(a,b){for(var c=/<%(.+?)%>/g,d=/(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g,e="var r=[];\n",f=0,g=function(a,b){return e+=b?a.match(d)?a+"\n":"r.push("+a+");\n":""!=a?'r.push("'+a.replace(/"/g,'\\"')+'");\n':"",g};match=c.exec(a);)g(a.slice(f,match.index))(match[1],!0),f=match.index+match[0].length;return g(a.substr(f,a.length-f)),e+='return r.join("");',new Function(e.replace(/[\r\t\n]/g,"")).apply(b)},m()}(window); |
@@ -23,3 +23,5 @@ var require = function(v) { | ||
return lib.helpers.Extend; | ||
} else { | ||
} else if(v == '../helpers/Clone') { | ||
return lib.helpers.Clone; | ||
} else { | ||
return function() {} | ||
@@ -26,0 +28,0 @@ } |
@@ -19,3 +19,3 @@ var Component = function(name, absurd) { | ||
CSS = { raw: css, element: style }; | ||
} else { | ||
} else if(CSS.raw !== css) { | ||
CSS.raw = css; | ||
@@ -38,4 +38,4 @@ CSS.element.innerHTML = css; | ||
} | ||
HTMLSource = {'': HTMLElement.outerHTML.replace(/</g, '<').replace(/>/g, '>') }; | ||
} | ||
HTMLSource = {'': HTMLElement.outerHTML.replace(/</g, '<').replace(/>/g, '>') }; | ||
next(); | ||
@@ -60,6 +60,6 @@ } else if(typeof this.html === 'object') { | ||
var handleHTML = function(next) { | ||
if(HTMLSource) { | ||
if(HTMLSource) { | ||
absurd.flush().morph("html").add(HTMLSource).compile(function(err, html) { | ||
(function merge(e1, e2) { | ||
if(typeof e1 === 'undefined' || typeof e2 === 'undefined') return; | ||
if(typeof e1 === 'undefined' || typeof e2 === 'undefined' || e1.isEqualNode(e2)) return; | ||
// replace the whole node | ||
@@ -99,2 +99,3 @@ if(e1.nodeName !== e2.nodeName) { | ||
for(var i=0; i<e1.childNodes.length; i++) { | ||
if(!e2.childNodes[i]) { e2.appendChild(document.createTextNode("")); } | ||
merge(e1.childNodes[i], e2.childNodes[i]); | ||
@@ -150,3 +151,3 @@ } | ||
} | ||
return { | ||
var component = { | ||
populate: function(options) { | ||
@@ -174,2 +175,3 @@ queue([ | ||
} | ||
return component; | ||
} |
@@ -5,3 +5,3 @@ var components = function(absurd) { | ||
api.register = function(name, cls) { | ||
return comps[name] = extend({}, Observer(), Component(name, absurd), cls); | ||
return comps[name] = extend({}, Observer(), Component(name, absurd), cls); | ||
} | ||
@@ -8,0 +8,0 @@ api.get = function(name) { |
@@ -205,5 +205,5 @@ describe("Adding raw data", function() { | ||
expect(css).toBeDefined(); | ||
expect(css).toContain("body {\n line-height: 20px;\n}\nbody p {\n margin: 10px;\n padding: 4px;\n}\n@media all (max-width: 950px) {\nbody {\n line-height: 40px;\n color: #BADA55;\n}\nbody p {\n color: #9fA;\n padding: 12px;\n}\n}\n@media all (min-width: 550px) {\nbody {\n line-height: 32px;\n}\n}\n"); | ||
expect(css).toBe('body{line-height: 20px;}body p{margin: 10px;padding: 4px;}@media all (max-width: 950px) {body{line-height: 40px;color: #BADA55;}body p{color: #9fA;padding: 12px;}}@media all (min-width: 550px) {body{line-height: 32px;}}'); | ||
done(); | ||
}); | ||
}, {minify: true}); | ||
}); | ||
@@ -295,3 +295,6 @@ | ||
a: { | ||
'text-decoration': 'none' | ||
'text-decoration': 'none', | ||
span: { | ||
fontSize: '10px' | ||
} | ||
} | ||
@@ -305,6 +308,5 @@ } | ||
expect(css).toBeDefined(); | ||
expect(css).toContain('.content p'); | ||
expect(css).toContain('.content p a'); | ||
expect(css).toContain('.content p{font-size: 16px;text-shadow: 2px 2px #00F;}.content p a{text-decoration: none;}.content p a span{font-size: 10px;}'); | ||
done(); | ||
}); | ||
}, {minify: true}); | ||
}); | ||
@@ -601,3 +603,3 @@ | ||
expect(css).toBeDefined(); | ||
expect(css).toBe("a{color: red;}a:hover{color: blue;}a.fancy{color: green;}.ie6 a.fancy{color: yellow;}.ie7 a.fancy{color: black;}.ie6 a:hover,.ie7 a:hover{color: orange;}"); | ||
expect(css).toBe('a{color: red;}a:hover{color: blue;}a.fancy{color: green;}.ie6 a:hover,.ie7 a:hover{color: orange;}.ie6 a.fancy{color: yellow;}.ie7 a.fancy{color: black;}'); | ||
done(); | ||
@@ -911,3 +913,3 @@ }, { minify: true }) | ||
expect(css).toBeDefined(); | ||
expect(css).toBe("body{background: blue;}html{background: pink;}body,html{color: red;}"); | ||
expect(css).toBe("html,body{color: red;}html{background: pink;}body{background: blue;}"); | ||
done(); | ||
@@ -918,2 +920,27 @@ }, { minify: true }); | ||
}); | ||
describe("Should not modify the original object", function() { | ||
var api = require('../../index.js')(); | ||
it("should compile properly", function(done) { | ||
var styles = { | ||
body: { | ||
p: { | ||
fontSize: '20px', | ||
span: { | ||
display: 'block' | ||
} | ||
} | ||
} | ||
} | ||
api.add(styles).compile(function(err, css) { | ||
expect(err).toBe(null); | ||
expect(css).toBeDefined(); | ||
expect(css).toBe("body p{font-size: 20px;}body p span{display: block;}"); | ||
expect(styles.body.p).not.toBe(false); | ||
done(); | ||
}, { minify: true }); | ||
}); | ||
}); | ||
describe("Support comma separated selectors", function() { | ||
@@ -920,0 +947,0 @@ |
lib.api.add = function(API) { | ||
var extend = require("../helpers/Extend"); | ||
var checkAndExecutePlugin = function(selector, prop, value, stylesheet) { | ||
var clone = require("../helpers/Clone"); | ||
var toRegister = []; | ||
var checkAndExecutePlugin = function(selector, prop, value, stylesheet, parentSelector) { | ||
var plugin = API.getPlugins()[prop]; | ||
@@ -8,3 +10,3 @@ if(typeof plugin !== 'undefined') { | ||
if(pluginResponse) { | ||
addRule(selector, pluginResponse, stylesheet); | ||
addRule(selector, pluginResponse, stylesheet, parentSelector); | ||
} | ||
@@ -16,59 +18,19 @@ return true; | ||
} | ||
var clearing = function(props) { | ||
// plugins | ||
var plugins = API.getPlugins(); | ||
for(var prop in props) { | ||
if(typeof plugins[prop] !== 'undefined') { | ||
props[prop] = false; | ||
var addRule = function(selector, props, stylesheet, parentSelector) { | ||
// console.log("\n---------- addRule ---------", selector, ".........", parentSelector, "\n", props); | ||
stylesheet = stylesheet || "mainstream"; | ||
if(/, ?/g.test(selector)) { | ||
var parts = selector.replace(/, /g, ',').split(','); | ||
for(var i=0; i<parts.length, p=parts[i]; i++) { | ||
addRule(p, props, stylesheet, parentSelector); | ||
} | ||
return; | ||
} | ||
// pseudo classes | ||
for(var prop in props) { | ||
if(prop.charAt(0) === ":") { | ||
props[prop] = false; | ||
} | ||
} | ||
// ampersand | ||
for(var prop in props) { | ||
if(/&/g.test(prop)) { | ||
props[prop] = false; | ||
} | ||
} | ||
} | ||
var checkForNesting = function(selector, props, stylesheet) { | ||
for(var prop in props) { | ||
if(typeof props[prop] === 'object') { | ||
// check for pseudo classes | ||
if(prop.charAt(0) === ":") { | ||
addRule(selector + prop, props[prop], stylesheet); | ||
// check for ampersand operator | ||
} else if(/&/g.test(prop)) { | ||
addRule(prop.replace(/&/g, selector), props[prop], stylesheet); | ||
// check for media query | ||
} else if(prop.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { | ||
addRule(selector, props[prop], prop); | ||
// check for media query | ||
} else if(selector.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { | ||
addRule(prop, props[prop], selector); | ||
// check for plugins | ||
} else if(checkAndExecutePlugin(selector, prop, props[prop], stylesheet) === false) { | ||
addRule(selector + " " + prop, props[prop], stylesheet); | ||
} | ||
props[prop] = false; | ||
} else if(typeof props[prop] === 'function') { | ||
props[prop] = props[prop](); | ||
checkForNesting(selector, props, stylesheet); | ||
} else { | ||
if(checkAndExecutePlugin(selector, prop, props[prop], stylesheet)) { | ||
props[prop] = false; | ||
} | ||
} | ||
} | ||
} | ||
var addRule = function(selector, props, stylesheet) { | ||
// if array is passed as props | ||
if(typeof props.length !== 'undefined' && typeof props === "object") { | ||
for(var i=0; prop=props[i]; i++) { | ||
addRule(selector, prop, stylesheet); | ||
for(var i=0; i<props.length, prop=props[i]; i++) { | ||
addRule(selector, prop, stylesheet, parentSelector); | ||
} | ||
@@ -79,61 +41,88 @@ return; | ||
// check for plugin | ||
if(checkAndExecutePlugin(null, selector, props, stylesheet)) { | ||
if(checkAndExecutePlugin(null, selector, props, stylesheet, parentSelector)) { | ||
return; | ||
} | ||
// if the selector is already there | ||
if(typeof API.getRules(stylesheet || "mainstream")[selector] == 'object') { | ||
var current = API.getRules(stylesheet || "mainstream")[selector]; | ||
for(var propNew in props) { | ||
// overwrite already added value | ||
if(typeof props[propNew] != 'object') { | ||
current[propNew] = props[propNew]; | ||
var _props = {}, | ||
_selector = selector, | ||
_objects = {}, | ||
_functions = {}; | ||
// processing props | ||
for(var prop in props) { | ||
var type = typeof props[prop]; | ||
if(type !== 'object' && type !== 'function') { | ||
if(checkAndExecutePlugin(selector, prop, props[prop], stylesheet, parentSelector) === false) { | ||
_selector = typeof parentSelector !== "undefined" ? parentSelector + " " + selector : selector; | ||
_props[prop] = props[prop]; | ||
} | ||
} else if(type === 'object') { | ||
_objects[prop] = props[prop]; | ||
} else if(type === 'function') { | ||
_functions[prop] = props[prop]; | ||
} | ||
// no, the selector is still not added | ||
} else { | ||
API.getRules(stylesheet || "mainstream")[selector] = props; | ||
} | ||
checkForNesting(selector, props, stylesheet || "mainstream"); | ||
clearing(props); | ||
} | ||
var prepareRules = function(obj) { | ||
if(obj instanceof Array) { | ||
for(var i=0; i<obj.length; i++) { | ||
prepareRules(obj[i]); | ||
toRegister.push({ | ||
selector: _selector, | ||
props: _props, | ||
stylesheet: stylesheet | ||
}); | ||
for(var prop in _objects) { | ||
// check for pseudo classes | ||
if(prop.charAt(0) === ":") { | ||
addRule(selector + prop, _objects[prop], stylesheet, parentSelector); | ||
// check for ampersand operator | ||
} else if(/&/g.test(prop)) { | ||
addRule(prop.replace(/&/g, selector), _objects[prop], stylesheet, parentSelector); | ||
// check for media query | ||
} else if(prop.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { | ||
addRule(selector, _objects[prop], prop, parentSelector); | ||
// check for media query | ||
} else if(selector.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { | ||
addRule(prop, _objects[prop], selector, parentSelector); | ||
// check for plugins | ||
} else if(checkAndExecutePlugin(selector, prop, _objects[prop], stylesheet, parentSelector) === false) { | ||
addRule(prop, _objects[prop], stylesheet, (parentSelector ? parentSelector + " " : "") + selector); | ||
} | ||
return; | ||
} | ||
for(var prop in obj) { | ||
var value = obj[prop]; | ||
if(typeof value == 'object') { | ||
prepareRules(value); | ||
} | ||
if(/, ?/g.test(prop)) { | ||
var parts = prop.replace(/, /g, ',').split(','); | ||
for(var i=0; i<parts.length, p=parts[i]; i++) { | ||
if(obj[p]) { | ||
obj[p] = extend({}, obj[p], value); | ||
} else { | ||
obj[p] = extend({}, value); | ||
} | ||
} | ||
delete obj[prop]; | ||
} | ||
for(var prop in _functions) { | ||
var o = {}; | ||
o[prop] = _functions[prop](); | ||
addRule(selector, o, stylesheet, parentSelector); | ||
} | ||
} | ||
var add = function(rules, stylesheet) { | ||
toRegister = []; | ||
API.numOfAddedRules += 1; | ||
prepareRules(rules); | ||
for(var selector in rules) { | ||
if(rules[selector] instanceof Array) { | ||
for(var i=0; i<rules[selector].length, r=rules[selector][i]; i++) { | ||
addRule(selector, r, stylesheet || "mainstream"); | ||
addRule(selector, rules[selector], stylesheet || "mainstream"); | ||
} | ||
// if the selector is already there | ||
for(var i=0; i<toRegister.length; i++) { | ||
var stylesheet = toRegister[i].stylesheet, | ||
selector = toRegister[i].selector, | ||
props = toRegister[i].props, | ||
allRules = API.getRules(stylesheet); | ||
// console.log(selector, props); | ||
if(typeof allRules[selector] == 'object') { | ||
var current = allRules[selector]; | ||
for(var propNew in props) { | ||
// overwrite already added value | ||
if(typeof props[propNew] != 'object') { | ||
current[propNew] = props[propNew]; | ||
} | ||
} | ||
// no, the selector is still not added | ||
} else { | ||
addRule(selector, rules[selector], stylesheet || "mainstream"); | ||
allRules[selector] = props; | ||
} | ||
} | ||
return API; | ||
@@ -340,2 +329,54 @@ } | ||
} | ||
/* http://davidwalsh.name/javascript-clone */ | ||
lib.helpers.Clone = function clone(src) { | ||
function mixin(dest, source, copyFunc) { | ||
var name, s, i, empty = {}; | ||
for(name in source){ | ||
// the (!(name in empty) || empty[name] !== s) condition avoids copying properties in "source" | ||
// inherited from Object.prototype. For example, if dest has a custom toString() method, | ||
// don't overwrite it with the toString() method that source inherited from Object.prototype | ||
s = source[name]; | ||
if(!(name in dest) || (dest[name] !== s && (!(name in empty) || empty[name] !== s))){ | ||
dest[name] = copyFunc ? copyFunc(s) : s; | ||
} | ||
} | ||
return dest; | ||
} | ||
if(!src || typeof src != "object" || Object.prototype.toString.call(src) === "[object Function]"){ | ||
// null, undefined, any non-object, or function | ||
return src; // anything | ||
} | ||
if(src.nodeType && "cloneNode" in src){ | ||
// DOM Node | ||
return src.cloneNode(true); // Node | ||
} | ||
if(src instanceof Date){ | ||
// Date | ||
return new Date(src.getTime()); // Date | ||
} | ||
if(src instanceof RegExp){ | ||
// RegExp | ||
return new RegExp(src); // RegExp | ||
} | ||
var r, i, l; | ||
if(src instanceof Array){ | ||
// array | ||
r = []; | ||
for(i = 0, l = src.length; i < l; ++i){ | ||
if(i in src){ | ||
r.push(clone(src[i])); | ||
} | ||
} | ||
// we don't clone functions for performance reasons | ||
// }else if(d.isFunction(src)){ | ||
// // function | ||
// r = function(){ return src.apply(this, arguments); }; | ||
}else{ | ||
// generic objects | ||
r = src.constructor ? new src.constructor() : {}; | ||
} | ||
return mixin(r, src, clone); | ||
} | ||
// credits: http://www.sitepoint.com/javascript-generate-lighter-darker-color/ | ||
@@ -342,0 +383,0 @@ lib.helpers.ColorLuminance = function (hex, lum) { |
module.exports = function(API) { | ||
var extend = require("../helpers/Extend"); | ||
var checkAndExecutePlugin = function(selector, prop, value, stylesheet) { | ||
var clone = require("../helpers/Clone"); | ||
var toRegister = []; | ||
var checkAndExecutePlugin = function(selector, prop, value, stylesheet, parentSelector) { | ||
var plugin = API.getPlugins()[prop]; | ||
@@ -8,3 +10,3 @@ if(typeof plugin !== 'undefined') { | ||
if(pluginResponse) { | ||
addRule(selector, pluginResponse, stylesheet); | ||
addRule(selector, pluginResponse, stylesheet, parentSelector); | ||
} | ||
@@ -16,59 +18,19 @@ return true; | ||
} | ||
var clearing = function(props) { | ||
// plugins | ||
var plugins = API.getPlugins(); | ||
for(var prop in props) { | ||
if(typeof plugins[prop] !== 'undefined') { | ||
props[prop] = false; | ||
var addRule = function(selector, props, stylesheet, parentSelector) { | ||
// console.log("\n---------- addRule ---------", selector, ".........", parentSelector, "\n", props); | ||
stylesheet = stylesheet || "mainstream"; | ||
if(/, ?/g.test(selector)) { | ||
var parts = selector.replace(/, /g, ',').split(','); | ||
for(var i=0; i<parts.length, p=parts[i]; i++) { | ||
addRule(p, props, stylesheet, parentSelector); | ||
} | ||
return; | ||
} | ||
// pseudo classes | ||
for(var prop in props) { | ||
if(prop.charAt(0) === ":") { | ||
props[prop] = false; | ||
} | ||
} | ||
// ampersand | ||
for(var prop in props) { | ||
if(/&/g.test(prop)) { | ||
props[prop] = false; | ||
} | ||
} | ||
} | ||
var checkForNesting = function(selector, props, stylesheet) { | ||
for(var prop in props) { | ||
if(typeof props[prop] === 'object') { | ||
// check for pseudo classes | ||
if(prop.charAt(0) === ":") { | ||
addRule(selector + prop, props[prop], stylesheet); | ||
// check for ampersand operator | ||
} else if(/&/g.test(prop)) { | ||
addRule(prop.replace(/&/g, selector), props[prop], stylesheet); | ||
// check for media query | ||
} else if(prop.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { | ||
addRule(selector, props[prop], prop); | ||
// check for media query | ||
} else if(selector.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { | ||
addRule(prop, props[prop], selector); | ||
// check for plugins | ||
} else if(checkAndExecutePlugin(selector, prop, props[prop], stylesheet) === false) { | ||
addRule(selector + " " + prop, props[prop], stylesheet); | ||
} | ||
props[prop] = false; | ||
} else if(typeof props[prop] === 'function') { | ||
props[prop] = props[prop](); | ||
checkForNesting(selector, props, stylesheet); | ||
} else { | ||
if(checkAndExecutePlugin(selector, prop, props[prop], stylesheet)) { | ||
props[prop] = false; | ||
} | ||
} | ||
} | ||
} | ||
var addRule = function(selector, props, stylesheet) { | ||
// if array is passed as props | ||
if(typeof props.length !== 'undefined' && typeof props === "object") { | ||
for(var i=0; prop=props[i]; i++) { | ||
addRule(selector, prop, stylesheet); | ||
for(var i=0; i<props.length, prop=props[i]; i++) { | ||
addRule(selector, prop, stylesheet, parentSelector); | ||
} | ||
@@ -79,61 +41,88 @@ return; | ||
// check for plugin | ||
if(checkAndExecutePlugin(null, selector, props, stylesheet)) { | ||
if(checkAndExecutePlugin(null, selector, props, stylesheet, parentSelector)) { | ||
return; | ||
} | ||
// if the selector is already there | ||
if(typeof API.getRules(stylesheet || "mainstream")[selector] == 'object') { | ||
var current = API.getRules(stylesheet || "mainstream")[selector]; | ||
for(var propNew in props) { | ||
// overwrite already added value | ||
if(typeof props[propNew] != 'object') { | ||
current[propNew] = props[propNew]; | ||
var _props = {}, | ||
_selector = selector, | ||
_objects = {}, | ||
_functions = {}; | ||
// processing props | ||
for(var prop in props) { | ||
var type = typeof props[prop]; | ||
if(type !== 'object' && type !== 'function') { | ||
if(checkAndExecutePlugin(selector, prop, props[prop], stylesheet, parentSelector) === false) { | ||
_selector = typeof parentSelector !== "undefined" ? parentSelector + " " + selector : selector; | ||
_props[prop] = props[prop]; | ||
} | ||
} else if(type === 'object') { | ||
_objects[prop] = props[prop]; | ||
} else if(type === 'function') { | ||
_functions[prop] = props[prop]; | ||
} | ||
// no, the selector is still not added | ||
} else { | ||
API.getRules(stylesheet || "mainstream")[selector] = props; | ||
} | ||
checkForNesting(selector, props, stylesheet || "mainstream"); | ||
clearing(props); | ||
} | ||
var prepareRules = function(obj) { | ||
if(obj instanceof Array) { | ||
for(var i=0; i<obj.length; i++) { | ||
prepareRules(obj[i]); | ||
toRegister.push({ | ||
selector: _selector, | ||
props: _props, | ||
stylesheet: stylesheet | ||
}); | ||
for(var prop in _objects) { | ||
// check for pseudo classes | ||
if(prop.charAt(0) === ":") { | ||
addRule(selector + prop, _objects[prop], stylesheet, parentSelector); | ||
// check for ampersand operator | ||
} else if(/&/g.test(prop)) { | ||
addRule(prop.replace(/&/g, selector), _objects[prop], stylesheet, parentSelector); | ||
// check for media query | ||
} else if(prop.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { | ||
addRule(selector, _objects[prop], prop, parentSelector); | ||
// check for media query | ||
} else if(selector.indexOf("@media") === 0 || prop.indexOf("@supports") === 0) { | ||
addRule(prop, _objects[prop], selector, parentSelector); | ||
// check for plugins | ||
} else if(checkAndExecutePlugin(selector, prop, _objects[prop], stylesheet, parentSelector) === false) { | ||
addRule(prop, _objects[prop], stylesheet, (parentSelector ? parentSelector + " " : "") + selector); | ||
} | ||
return; | ||
} | ||
for(var prop in obj) { | ||
var value = obj[prop]; | ||
if(typeof value == 'object') { | ||
prepareRules(value); | ||
} | ||
if(/, ?/g.test(prop)) { | ||
var parts = prop.replace(/, /g, ',').split(','); | ||
for(var i=0; i<parts.length, p=parts[i]; i++) { | ||
if(obj[p]) { | ||
obj[p] = extend({}, obj[p], value); | ||
} else { | ||
obj[p] = extend({}, value); | ||
} | ||
} | ||
delete obj[prop]; | ||
} | ||
for(var prop in _functions) { | ||
var o = {}; | ||
o[prop] = _functions[prop](); | ||
addRule(selector, o, stylesheet, parentSelector); | ||
} | ||
} | ||
var add = function(rules, stylesheet) { | ||
toRegister = []; | ||
API.numOfAddedRules += 1; | ||
prepareRules(rules); | ||
for(var selector in rules) { | ||
if(rules[selector] instanceof Array) { | ||
for(var i=0; i<rules[selector].length, r=rules[selector][i]; i++) { | ||
addRule(selector, r, stylesheet || "mainstream"); | ||
addRule(selector, rules[selector], stylesheet || "mainstream"); | ||
} | ||
// if the selector is already there | ||
for(var i=0; i<toRegister.length; i++) { | ||
var stylesheet = toRegister[i].stylesheet, | ||
selector = toRegister[i].selector, | ||
props = toRegister[i].props, | ||
allRules = API.getRules(stylesheet); | ||
// console.log(selector, props); | ||
if(typeof allRules[selector] == 'object') { | ||
var current = allRules[selector]; | ||
for(var propNew in props) { | ||
// overwrite already added value | ||
if(typeof props[propNew] != 'object') { | ||
current[propNew] = props[propNew]; | ||
} | ||
} | ||
// no, the selector is still not added | ||
} else { | ||
addRule(selector, rules[selector], stylesheet || "mainstream"); | ||
allRules[selector] = props; | ||
} | ||
} | ||
return API; | ||
@@ -140,0 +129,0 @@ } |
{ | ||
"name": "absurd", | ||
"version": "0.1.21", | ||
"version": "0.2.0", | ||
"homepage": "http://krasimir.github.io/absurd", | ||
@@ -5,0 +5,0 @@ "description": "CSS/HTML preprocessor. Check out krasimirtsonev.com/blog/article/AbsurdJS-fundamentals", |
@@ -13,3 +13,3 @@ describe("Multiple selectors per rule overwrite all individual selectors", function() { | ||
expect(css).toBeDefined(); | ||
expect(css).toBe("body{background: blue;}html{background: pink;}body,html{color: red;}"); | ||
expect(css).toBe("html,body{color: red;}html{background: pink;}body{background: blue;}"); | ||
done(); | ||
@@ -16,0 +16,0 @@ }, { minify: true }); |
@@ -9,3 +9,3 @@ describe("Test case (charset)", function() { | ||
expect(css).toBeDefined(); | ||
expect(css).toBe('body {\n width: 100%;\n}\n@charset: "UTF-8";\n'); | ||
expect(css).toBe('@charset: "UTF-8";\nbody {\n width: 100%;\n}\n'); | ||
done(); | ||
@@ -19,3 +19,3 @@ }); | ||
expect(css).toBeDefined(); | ||
expect(css).toBe('body {\n width: 100%;\n}\np {\n margin-top: 20px;\n}\n@charset: "UTF-8";\n'); | ||
expect(css).toBe('@charset: "UTF-8";\nbody {\n width: 100%;\n}\np {\n margin-top: 20px;\n}\n'); | ||
done(); | ||
@@ -52,3 +52,3 @@ }); | ||
expect(css).toBeDefined(); | ||
expect(css).toBe('body {\n border-radius: 2px;\n}\nbody a {\n font-size: 2em;\n}\n@charset: "UTF-8";\np {\n margin: 2px;\n}\n@charset: "BLA-BLA";\n'); | ||
expect(css).toBe('@charset: "UTF-8";\n@charset: "BLA-BLA";\nbody {\n border-radius: 2px;\n}\nbody a {\n font-size: 2em;\n}\np {\n margin: 2px;\n}\n'); | ||
done(); | ||
@@ -55,0 +55,0 @@ }); |
@@ -9,3 +9,3 @@ describe("Test case (page)", function() { | ||
expect(css).toBeDefined(); | ||
expect(css).toBe('@page {\n font-size: 12px;\n}\n@page toc, index:blank {\n color: #000;\n}\n'); | ||
expect(css).toBe('@page toc, index:blank {\n color: #000;\n}\n@page {\n font-size: 12px;\n}\n'); | ||
done(); | ||
@@ -19,3 +19,3 @@ }); | ||
expect(css).toBeDefined(); | ||
expect(css).toBe('@page {\n font-size: 12px;\n}\n@page toc, index:blank {\n color: #000;\n}\n'); | ||
expect(css).toBe('@page toc, index:blank {\n color: #000;\n}\n@page {\n font-size: 12px;\n}\n'); | ||
done(); | ||
@@ -22,0 +22,0 @@ }); |
describe("Absurd acting in code:", function() { | ||
var Absurd, absurd; | ||
Absurd = require("../../index.js"); | ||
it("shoud create an instance of absurd", function(done) { | ||
Absurd = require("../../index.js"); | ||
xit("shoud create an instance of absurd", function(done) { | ||
expect(Absurd).toBeDefined(); | ||
@@ -11,3 +11,3 @@ done(); | ||
it("should initialize absurd", function(done) { | ||
xit("should initialize absurd", function(done) { | ||
absurd = Absurd(__dirname + "/../data/css/index.js"); | ||
@@ -18,3 +18,3 @@ expect(typeof absurd).toBe("object"); | ||
it("should work with no path passed", function(done) { | ||
xit("should work with no path passed", function(done) { | ||
absurd = Absurd(); | ||
@@ -30,3 +30,3 @@ absurd.add({a: {color: "#123"}}); | ||
it("should compile an inline function", function(done) { | ||
xit("should compile an inline function", function(done) { | ||
Absurd(function(api) { | ||
@@ -47,3 +47,3 @@ api.add({ | ||
it("should compile a file", function(done) { | ||
xit("should compile a file", function(done) { | ||
absurd = Absurd(__dirname + "/../data/css/index.js"); | ||
@@ -50,0 +50,0 @@ absurd.compile(function(err, css) { |
@@ -33,7 +33,7 @@ describe("Media queries", function() { | ||
expect(css).toBeDefined(); | ||
expect(css).toContain("body {\n line-height: 20px;\n}\nbody p {\n margin: 10px;\n padding: 4px;\n}\n@media all (max-width: 950px) {\nbody {\n line-height: 40px;\n color: #BADA55;\n}\nbody p {\n color: #9fA;\n padding: 12px;\n}\n}\n@media all (min-width: 550px) {\nbody {\n line-height: 32px;\n}\n}\n"); | ||
expect(css).toBe('body{line-height: 20px;}body p{margin: 10px;padding: 4px;}@media all (max-width: 950px) {body{line-height: 40px;color: #BADA55;}body p{color: #9fA;padding: 12px;}}@media all (min-width: 550px) {body{line-height: 32px;}}'); | ||
done(); | ||
}); | ||
}, {minify: true}); | ||
}); | ||
}); |
@@ -13,3 +13,6 @@ describe("Nested selectors", function() { | ||
a: { | ||
'text-decoration': 'none' | ||
'text-decoration': 'none', | ||
span: { | ||
fontSize: '10px' | ||
} | ||
} | ||
@@ -23,8 +26,7 @@ } | ||
expect(css).toBeDefined(); | ||
expect(css).toContain('.content p'); | ||
expect(css).toContain('.content p a'); | ||
expect(css).toContain('.content p{font-size: 16px;text-shadow: 2px 2px #00F;}.content p a{text-decoration: none;}.content p a span{font-size: 10px;}'); | ||
done(); | ||
}); | ||
}, {minify: true}); | ||
}); | ||
}); |
@@ -33,3 +33,3 @@ describe("Use ampersand operator", function() { | ||
expect(css).toBeDefined(); | ||
expect(css).toBe("a{color: red;}a:hover{color: blue;}a.fancy{color: green;}.ie6 a.fancy{color: yellow;}.ie7 a.fancy{color: black;}.ie6 a:hover,.ie7 a:hover{color: orange;}"); | ||
expect(css).toBe('a{color: red;}a:hover{color: blue;}a.fancy{color: green;}.ie6 a:hover,.ie7 a:hover{color: orange;}.ie6 a.fancy{color: yellow;}.ie7 a.fancy{color: black;}'); | ||
done(); | ||
@@ -36,0 +36,0 @@ }, { minify: true }) |
@@ -39,3 +39,3 @@ describe("Import CSS", function() { | ||
expect(css).toBeDefined(); | ||
expect(css).toBe("body {\n margin-top: 10px;\n font-size: 12px;\n}\nh1, h2, h3 {\n margin: 0;\n padding: 0;\n}\n"); | ||
expect(css).toBe("body {\n font-size: 12px;\n margin-top: 10px;\n}\nh1, h2, h3 {\n margin: 0;\n padding: 0;\n}\n"); | ||
done(); | ||
@@ -42,0 +42,0 @@ }); |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
382044
174
11707
43