Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

absurd

Package Overview
Dependencies
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

absurd - npm Package Compare versions

Comparing version 0.0.39 to 0.0.40

lib/api/darken.js

151

client-side/build/absurd.js

@@ -1,2 +0,2 @@

/* version: 0.0.39 */
/* version: 0.0.40 */
var Absurd = (function(w) {

@@ -12,2 +12,3 @@ var lib = {

};
var __dirname = "";
var client = function() {

@@ -31,2 +32,3 @@ return function(arg) {

_plugins = {},
_hooks = {},
_defaultOptions = {

@@ -58,3 +60,27 @@ combineSelectors: true,

}
_api.import = function() {
if(_api.callHooks("import", arguments)) return _api;
return _api;
}
// hooks
_api.addHook = function(method, callback) {
if(!_hooks[method]) _hooks[method] = [];
var isAlreadyAdded = false;
for(var i=0; c=_hooks[method][i]; i++) {
if(c === callback) {
isAlreadyAdded = true;
}
}
isAlreadyAdded === false ? _hooks[method].push(callback) : null;
}
_api.callHooks = function(method, args) {
if(_hooks[method]) {
for(var i=0; c=_hooks[method][i]; i++) {
if(c.apply(_api, args) === true) return true;
}
}
return false;
}
// internal variables

@@ -67,2 +93,3 @@ _api.numOfAddedRules = 0;

_api.compile = function(callback, options) {
if(_api.callHooks("compile", arguments)) return _api;
options = extend(_defaultOptions, options || {});

@@ -75,5 +102,2 @@ options.processor(

}
_api.getPath = function() {
return {};
}

@@ -84,2 +108,9 @@ // registering api methods

_api[method] = lib.api[method](_api);
_api[method] = (function(method) {
return function() {
var f = lib.api[method](_api);
if(_api.callHooks(method, arguments)) return _api;
return f.apply(_api, arguments);
}
})(method);
}

@@ -200,38 +231,2 @@ }

}
// credits: http://www.sitepoint.com/javascript-generate-lighter-darker-color/
function ColorLuminance(hex, lum) {
// validate hex string
hex = String(hex).replace(/[^0-9a-f]/gi, '');
if (hex.length < 6) {
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
}
lum = lum || 0;
// convert to decimal and change luminosity
var rgb = "#", c, i;
for (i = 0; i < 3; i++) {
c = parseInt(hex.substr(i*2,2), 16);
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
rgb += ("00"+c).substr(c.length);
}
return rgb;
}
lib.api.colors = function(api) {
var darken = api.darken = function(color, percents) {
return ColorLuminance(color, -(percents/100));
}
var lighten = api.lighten = function(color, percents) {
return ColorLuminance(color, percents/100);
}
return {
darken: darken,
lighten: lighten
}
}
var extend = function(destination, source) {

@@ -246,4 +241,2 @@ for (var key in source) {

lib.api.compile = function(api) {

@@ -277,2 +270,56 @@ return function(callback, options) {

}
var ColorLuminance = function (hex, lum) {
// validate hex string
hex = String(hex).replace(/[^0-9a-f]/gi, '');
if (hex.length < 6) {
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
}
lum = lum || 0;
// convert to decimal and change luminosity
var rgb = "#", c, i;
for (i = 0; i < 3; i++) {
c = parseInt(hex.substr(i*2,2), 16);
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
rgb += ("00"+c).substr(c.length);
}
return rgb;
};
lib.api.darken = function(api) {
return function(color, percents) {
return ColorLuminance(color, -(percents/100));
}
}
lib.api.hook = function(api) {
return function(method, callback) {
api.addHook(method, callback);
return api;
}
}
var ColorLuminance = function (hex, lum) {
// validate hex string
hex = String(hex).replace(/[^0-9a-f]/gi, '');
if (hex.length < 6) {
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
}
lum = lum || 0;
// convert to decimal and change luminosity
var rgb = "#", c, i;
for (i = 0; i < 3; i++) {
c = parseInt(hex.substr(i*2,2), 16);
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
rgb += ("00"+c).substr(c.length);
}
return rgb;
};
lib.api.lighten = function(api) {
return function(color, percents) {
return ColorLuminance(color, percents/100);
}
}
lib.api.plugin = function(api) {

@@ -311,2 +358,22 @@ var plugin = function(name, func) {

}
// credits: http://www.sitepoint.com/javascript-generate-lighter-darker-color/
lib.helpers.ColorLuminance = function (hex, lum) {
// validate hex string
hex = String(hex).replace(/[^0-9a-f]/gi, '');
if (hex.length < 6) {
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
}
lum = lum || 0;
// convert to decimal and change luminosity
var rgb = "#", c, i;
for (i = 0; i < 3; i++) {
c = parseInt(hex.substr(i*2,2), 16);
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
rgb += ("00"+c).substr(c.length);
}
return rgb;
}
lib.helpers.RequireUncached = function(module) {

@@ -313,0 +380,0 @@ delete require.cache[require.resolve(module)]

@@ -1,1 +0,1 @@

var Absurd=function(){function a(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}var b={api:{},helpers:{},plugins:{},processors:{}},d=function(){return function(){}},e=function(){return function(a){var c=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a},d={},e={},f={},g={},h={combineSelectors:!0,minify:!1,processor:b.processors.CSS()};d.getRules=function(a){return"undefined"==typeof a?e:("undefined"==typeof e[a]&&(e[a]=[]),e[a])},d.getPlugins=function(){return g},d.getStorage=function(){return f},d.flush=function(){e={},f=[]},d.numOfAddedRules=0,d.compile=function(a,b){b=c(h,b||{}),b.processor(d.getRules(),a||function(){},{combineSelectors:!0})},d.getPath=function(){return{}};for(var i in b.api)"compile"!==i&&(d[i]=b.api[i](d));for(var j in b.plugins)d.plugin(j,b.plugins[j]());return"function"==typeof a&&a(d),d}};b.api.add=function(a){var b=function(b,c,d,f){var g=a.getPlugins()[c];if("undefined"!=typeof g){var h=g(a,d);return h&&e(b,h,f),!0}return!1},c=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)},d=function(a,c,d){for(var f in c)"object"==typeof c[f]?(":"===f.charAt(0)?e(a+f,c[f],d):0===f.indexOf("@media")||0===f.indexOf("@supports")?e(a,c[f],f):b(a,f,c[f],d)===!1&&e(a+" "+f,c[f],d),c[f]=!1):b(a,f,c[f],d)&&(c[f]=!1)},e=function(f,g,h){if("undefined"==typeof g.length||"object"!=typeof g){if(!b(null,f,g,h)){if("object"==typeof a.getRules(h||"mainstream")[f]){var i=a.getRules(h||"mainstream")[f];for(var j in g)i[j]=g[j]}else a.getRules(h||"mainstream")[f]=g;d(f,g,h||"mainstream"),c(g)}}else for(var k=0;prop=g[k];k++)e(f,prop,h)},f=function(b,c){a.numOfAddedRules+=1;for(var d in b)if("undefined"!=typeof b[d].length&&"object"==typeof b[d])for(var f=0;r=b[d][f];f++)e(d,r,c||"mainstream");else e(d,b[d],c||"mainstream");return a};return f},b.api.colors=function(b){var c=b.darken=function(b,c){return a(b,-(c/100))},d=b.lighten=function(b,c){return a(b,c/100)};return{darken:c,lighten:d}};var f=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a};b.api.compile=function(a){return function(b,c){var e={combineSelectors:!0,minify:!1,processor:d("../processors/CSS.js")()};c=f(e,c||{}),c.processor(a.getRules(),b||function(){},c)}},b.api.compileFile=function(a){return function(b,c,d){a.compile(function(a,d){try{fs.writeFile(b,d,function(a){c(a,d)})}catch(a){c(a)}},d)}},b.api.plugin=function(a){var b=function(b,c){return a.getPlugins()[b]=c,a};return b},b.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}},b.api.storage=function(a){var b=a.getStorage(),c=function(c,d){if("undefined"==typeof d){if(b[c])return b[c];throw new Error("There is no data in the storage associated with '"+c+"'")}return b[c]=d,a};return c},b.helpers.RequireUncached=function(a){return delete d.cache[d.resolve(a)],d(a)},b.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+'";'))}},b.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)}}},b.plugins.keyframes=function(){return function(a,b){var c=d(__dirname+"/../processors/CSS")();if("object"==typeof b)if("undefined"!=typeof b.frames){var e="@keyframes "+b.name+" {\n";e+=c({mainstream:b.frames}),e+="}",a.raw(e+"\n"+e.replace("@keyframes","@-webkit-keyframes"))}else if("undefined"!=typeof b.keyframes){for(var e="@keyframes "+b.name+" {\n",f={},g=0;rule=b.keyframes[g];g++)if("keyframe"===rule.type)for(var h=f[rule.values]={},i=0;declaration=rule.declarations[i];i++)"declaration"===declaration.type&&(h[declaration.property]=declaration.value);e+=c({mainstream:f}),e+="}",a.raw(e+"\n"+e.replace("@keyframes","@-webkit-keyframes"))}}},b.plugins.media=function(){return function(a,b){var c=d(__dirname+"/../processors/CSS")();if("object"==typeof b){for(var e="@media "+b.media+" {\n",f={},g=0;rule=b.rules[g];g++){var h=f[rule.selectors.toString()]={};if("rule"===rule.type)for(var i=0;declaration=rule.declarations[i];i++)"declaration"===declaration.type&&(h[declaration.property]=declaration.value)}e+=c({mainstream:f}),e+="}",a.raw(e)}}},b.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+'";'))}},b.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)}}},b.plugins.supports=function(){return function(a,b){var c=d(__dirname+"/../processors/CSS")();if("object"==typeof b){for(var e="@supports "+b.supports+" {\n",f={},g=0;rule=b.rules[g];g++){var h=f[rule.selectors.toString()]={};if("rule"===rule.type)for(var i=0;declaration=rule.declarations[i];i++)"declaration"===declaration.type&&(h[declaration.property]=declaration.value)}e+=c({mainstream:f}),e+="}",a.raw(e)}}};var g=d("clean-css"),h="\n",i={combineSelectors:!0,minify:!1},j=function(a){var b="";for(var c in a)if(0===c.indexOf("____raw"))b+=a[c][c]+h;else{var d=c+" {"+h;for(var e in a[c])a[c][e],d+=" "+m(e)+": "+a[c][e]+";"+h;d+="}"+h,b+=d}return b},k=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&&(d=!0,e[f]=g)}d&&(b[c]=e)}return b},l=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},m=function(a){for(var b="",d=0;c=a.charAt(d);d++)b+=c===c.toUpperCase()&&c.toLowerCase()!==c.toUpperCase()?"-"+c.toLowerCase():c;return b};return b.processors.CSS=function(){return function(a,b,c){c=c||i;var d="";for(var e in a){var f=k(a[e]);f=c.combineSelectors?l(f):f,d+="mainstream"===e?j(f):e+" {"+h+j(f)+"}"+h}return c.minify?(d=g.process(d),b&&b(null,d)):b&&b(null,d),d}},e()}(window);
var Absurd=function(){var a={api:{},helpers:{},plugins:{},processors:{}},b=function(){return function(){}},d="",e=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={},f={},g={},h={},i={},j={combineSelectors:!0,minify:!1,processor:a.processors.CSS()};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(){f={},g=[]},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.compile=function(a,b){return e.callHooks("compile",arguments)?e:(b=d(j,b||{}),b.processor(e.getRules(),a||function(){},{combineSelectors:!0}),void 0)};for(var k in a.api)"compile"!==k&&(e[k]=a.api[k](e),e[k]=function(b){return function(){var c=a.api[b](e);return e.callHooks(b,arguments)?e:c.apply(e,arguments)}}(k));for(var l in a.plugins)e.plugin(l,a.plugins[l]());return"function"==typeof b&&b(e),e}};a.api.add=function(a){var b=function(b,c,d,f){var g=a.getPlugins()[c];if("undefined"!=typeof g){var h=g(a,d);return h&&e(b,h,f),!0}return!1},c=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)},d=function(a,c,d){for(var f in c)"object"==typeof c[f]?(":"===f.charAt(0)?e(a+f,c[f],d):0===f.indexOf("@media")||0===f.indexOf("@supports")?e(a,c[f],f):b(a,f,c[f],d)===!1&&e(a+" "+f,c[f],d),c[f]=!1):b(a,f,c[f],d)&&(c[f]=!1)},e=function(f,g,h){if("undefined"==typeof g.length||"object"!=typeof g){if(!b(null,f,g,h)){if("object"==typeof a.getRules(h||"mainstream")[f]){var i=a.getRules(h||"mainstream")[f];for(var j in g)i[j]=g[j]}else a.getRules(h||"mainstream")[f]=g;d(f,g,h||"mainstream"),c(g)}}else for(var k=0;prop=g[k];k++)e(f,prop,h)},f=function(b,c){a.numOfAddedRules+=1;for(var d in b)if("undefined"!=typeof b[d].length&&"object"==typeof b[d])for(var f=0;r=b[d][f];f++)e(d,r,c||"mainstream");else e(d,b[d],c||"mainstream");return a};return f};var f=function(a,b){for(var c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a};a.api.compile=function(a){return function(c,d){var e={combineSelectors:!0,minify:!1,processor:b("../processors/CSS.js")()};d=f(e,d||{}),d.processor(a.getRules(),c||function(){},d)}},a.api.compileFile=function(a){return function(b,c,d){a.compile(function(a,d){try{fs.writeFile(b,d,function(a){c(a,d)})}catch(a){c(a)}},d)}};var g=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 g(a,-(b/100))}},a.api.hook=function(a){return function(b,c){return a.addHook(b,c),a}};var g=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 g(a,b/100)}},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}},a.api.storage=function(a){var b=a.getStorage(),c=function(c,d){if("undefined"==typeof d){if(b[c])return b[c];throw new Error("There is no data in the storage associated with '"+c+"'")}return b[c]=d,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.RequireUncached=function(a){return delete b.cache[b.resolve(a)],b(a)},a.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.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.plugins.keyframes=function(){return function(a,c){var e=b(d+"/../processors/CSS")();if("object"==typeof c)if("undefined"!=typeof c.frames){var f="@keyframes "+c.name+" {\n";f+=e({mainstream:c.frames}),f+="}",a.raw(f+"\n"+f.replace("@keyframes","@-webkit-keyframes"))}else if("undefined"!=typeof c.keyframes){for(var f="@keyframes "+c.name+" {\n",g={},h=0;rule=c.keyframes[h];h++)if("keyframe"===rule.type)for(var i=g[rule.values]={},j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(i[declaration.property]=declaration.value);f+=e({mainstream:g}),f+="}",a.raw(f+"\n"+f.replace("@keyframes","@-webkit-keyframes"))}}},a.plugins.media=function(){return function(a,c){var e=b(d+"/../processors/CSS")();if("object"==typeof c){for(var f="@media "+c.media+" {\n",g={},h=0;rule=c.rules[h];h++){var i=g[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(i[declaration.property]=declaration.value)}f+=e({mainstream:g}),f+="}",a.raw(f)}}},a.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.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.plugins.supports=function(){return function(a,c){var e=b(d+"/../processors/CSS")();if("object"==typeof c){for(var f="@supports "+c.supports+" {\n",g={},h=0;rule=c.rules[h];h++){var i=g[rule.selectors.toString()]={};if("rule"===rule.type)for(var j=0;declaration=rule.declarations[j];j++)"declaration"===declaration.type&&(i[declaration.property]=declaration.value)}f+=e({mainstream:g}),f+="}",a.raw(f)}}};var h=b("clean-css"),i="\n",j={combineSelectors:!0,minify:!1},k=function(a){var b="";for(var c in a)if(0===c.indexOf("____raw"))b+=a[c][c]+i;else{var d=c+" {"+i;for(var e in a[c])a[c][e],d+=" "+n(e)+": "+a[c][e]+";"+i;d+="}"+i,b+=d}return b},l=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&&(d=!0,e[f]=g)}d&&(b[c]=e)}return b},m=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},n=function(a){for(var b="",d=0;c=a.charAt(d);d++)b+=c===c.toUpperCase()&&c.toLowerCase()!==c.toUpperCase()?"-"+c.toLowerCase():c;return b};return a.processors.CSS=function(){return function(a,b,c){c=c||j;var d="";for(var e in a){var f=l(a[e]);f=c.combineSelectors?m(f):f,d+="mainstream"===e?k(f):e+" {"+i+k(f)+"}"+i}return c.minify?(d=h.process(d),b&&b(null,d)):b&&b(null,d),d}},e()}(window);
var require = function() {
return function() {}
};
};
var __dirname = "";

@@ -19,2 +19,3 @@ var client = function() {

_plugins = {},
_hooks = {},
_defaultOptions = {

@@ -46,3 +47,27 @@ combineSelectors: true,

}
_api.import = function() {
if(_api.callHooks("import", arguments)) return _api;
return _api;
}
// hooks
_api.addHook = function(method, callback) {
if(!_hooks[method]) _hooks[method] = [];
var isAlreadyAdded = false;
for(var i=0; c=_hooks[method][i]; i++) {
if(c === callback) {
isAlreadyAdded = true;
}
}
isAlreadyAdded === false ? _hooks[method].push(callback) : null;
}
_api.callHooks = function(method, args) {
if(_hooks[method]) {
for(var i=0; c=_hooks[method][i]; i++) {
if(c.apply(_api, args) === true) return true;
}
}
return false;
}
// internal variables

@@ -55,2 +80,3 @@ _api.numOfAddedRules = 0;

_api.compile = function(callback, options) {
if(_api.callHooks("compile", arguments)) return _api;
options = extend(_defaultOptions, options || {});

@@ -63,5 +89,2 @@ options.processor(

}
_api.getPath = function() {
return {};
}

@@ -72,2 +95,9 @@ // registering api methods

_api[method] = lib.api[method](_api);
_api[method] = (function(method) {
return function() {
var f = lib.api[method](_api);
if(_api.callHooks(method, arguments)) return _api;
return f.apply(_api, arguments);
}
})(method);
}

@@ -74,0 +104,0 @@ }

@@ -172,2 +172,78 @@ describe("Adding raw data", function() {

});
describe("Hooks", function() {
var Absurd = require('../../index.js');
it("Adding hook (add method)", function(done) {
Absurd(function(api) {
api.hook("add", function(rules, stylesheet) {
expect(rules).toBeDefined();
expect(stylesheet).not.toBeDefined();
expect(rules.body).toBeDefined();
expect(rules.body.fontSize).toBeDefined();
expect(rules.body.fontSize).toBe("20px");
}).add({
body: {
fontSize: "20px"
}
}).compile(function(err, css) {
expect(css).toBe("body {\n font-size: 20px;\n}\n");
done();
})
});
});
it("Prevent default", function(done) {
Absurd(function(api) {
api.hook("add", function(rules, stylesheet) {
return true;
}).add({
body: {
fontSize: "20px"
}
}).compile(function(err, css) {
expect(css).toBe("");
done();
})
});
});
it("Adding hook (import method)", function(done) {
Absurd(function(api) {
api.hook("import", function(file) {
if(file === "body-styles.bla") {
api.add({
body: {
fontSize: "11.5px"
}
});
}
}).add({
body: {
fontSize: "20px"
}
}).import("body-styles.bla").compile(function(err, css) {
expect(css).toBe("body {\n font-size: 11.5px;\n}\n");
done();
})
});
});
it("Adding hook (compile method)", function(done) {
Absurd(function(api) {
api.hook("compile", function(callback, options) {
callback(null, "AbsurdJS is awesome!")
return true;
}).add({
body: {
fontSize: "20px"
}
}).import("body-styles.bla").compile(function(err, css) {
expect(css).toBe("AbsurdJS is awesome!");
done();
})
});
});
});
describe("Media queries", function() {

@@ -174,0 +250,0 @@

@@ -99,38 +99,2 @@ lib.api.add = function(API) {

}
// credits: http://www.sitepoint.com/javascript-generate-lighter-darker-color/
function ColorLuminance(hex, lum) {
// validate hex string
hex = String(hex).replace(/[^0-9a-f]/gi, '');
if (hex.length < 6) {
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
}
lum = lum || 0;
// convert to decimal and change luminosity
var rgb = "#", c, i;
for (i = 0; i < 3; i++) {
c = parseInt(hex.substr(i*2,2), 16);
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
rgb += ("00"+c).substr(c.length);
}
return rgb;
}
lib.api.colors = function(api) {
var darken = api.darken = function(color, percents) {
return ColorLuminance(color, -(percents/100));
}
var lighten = api.lighten = function(color, percents) {
return ColorLuminance(color, percents/100);
}
return {
darken: darken,
lighten: lighten
}
}
var extend = function(destination, source) {

@@ -145,4 +109,2 @@ for (var key in source) {

lib.api.compile = function(api) {

@@ -176,2 +138,56 @@ return function(callback, options) {

}
var ColorLuminance = function (hex, lum) {
// validate hex string
hex = String(hex).replace(/[^0-9a-f]/gi, '');
if (hex.length < 6) {
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
}
lum = lum || 0;
// convert to decimal and change luminosity
var rgb = "#", c, i;
for (i = 0; i < 3; i++) {
c = parseInt(hex.substr(i*2,2), 16);
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
rgb += ("00"+c).substr(c.length);
}
return rgb;
};
lib.api.darken = function(api) {
return function(color, percents) {
return ColorLuminance(color, -(percents/100));
}
}
lib.api.hook = function(api) {
return function(method, callback) {
api.addHook(method, callback);
return api;
}
}
var ColorLuminance = function (hex, lum) {
// validate hex string
hex = String(hex).replace(/[^0-9a-f]/gi, '');
if (hex.length < 6) {
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
}
lum = lum || 0;
// convert to decimal and change luminosity
var rgb = "#", c, i;
for (i = 0; i < 3; i++) {
c = parseInt(hex.substr(i*2,2), 16);
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
rgb += ("00"+c).substr(c.length);
}
return rgb;
};
lib.api.lighten = function(api) {
return function(color, percents) {
return ColorLuminance(color, percents/100);
}
}
lib.api.plugin = function(api) {

@@ -210,2 +226,22 @@ var plugin = function(name, func) {

}
// credits: http://www.sitepoint.com/javascript-generate-lighter-darker-color/
lib.helpers.ColorLuminance = function (hex, lum) {
// validate hex string
hex = String(hex).replace(/[^0-9a-f]/gi, '');
if (hex.length < 6) {
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
}
lum = lum || 0;
// convert to decimal and change luminosity
var rgb = "#", c, i;
for (i = 0; i < 3; i++) {
c = parseInt(hex.substr(i*2,2), 16);
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
rgb += ("00"+c).substr(c.length);
}
return rgb;
}
lib.helpers.RequireUncached = function(module) {

@@ -212,0 +248,0 @@ delete require.cache[require.resolve(module)]

@@ -9,3 +9,4 @@ var fs = require('fs');

_storage = {},
_plugins = {};
_plugins = {},
_hooks = {};

@@ -74,2 +75,22 @@ _api.getRules = function(stylesheet) {

// hooks
_api.addHook = function(method, callback) {
if(!_hooks[method]) _hooks[method] = [];
var isAlreadyAdded = false;
for(var i=0; c=_hooks[method][i]; i++) {
if(c === callback) {
isAlreadyAdded = true;
}
}
isAlreadyAdded === false ? _hooks[method].push(callback) : null;
}
_api.callHooks = function(method, args) {
if(_hooks[method]) {
for(var i=0; c=_hooks[method][i]; i++) {
if(c.apply(_api, args) === true) return true;
}
}
return false;
}
// internal variables

@@ -83,3 +104,9 @@ _api.numOfAddedRules = 0;

var file = methods[i];
_api[file.replace(".js", "")] = require(__dirname + "/api/" + file)(_api);
_api[file.replace(".js", "")] = (function(file) {
return function() {
var f = require(__dirname + "/api/" + file)(_api);
if(_api.callHooks(file.replace(".js", ""), arguments)) return _api;
return f.apply(api, arguments);
}
})(file);
}

@@ -86,0 +113,0 @@ }

@@ -10,4 +10,2 @@ var extend = function(destination, source) {

module.exports = function(api) {

@@ -14,0 +12,0 @@ return function(callback, options) {

{
"name": "absurd",
"version": "0.0.39",
"version": "0.0.40",
"homepage": "https://github.com/krasimir/absurd",

@@ -5,0 +5,0 @@ "description": "CSS preprocessor",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc