New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dynamicss

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynamicss - npm Package Compare versions

Comparing version 0.0.14 to 0.1.0

src/helpers/dss.ceil.js

2

bower.json
{
"name": "dss",
"version": "0.0.14",
"version": "0.1.0",
"homepage": "https://github.com/guisouza/dss",

@@ -5,0 +5,0 @@ "description": "DSS - Dynamic Style Sheets",

@@ -602,3 +602,5 @@ // http://www.w3.org/TR/CSS21/grammar.html

myRules : {},
refreshValues : {}
refreshValues : {},
nonDynamicRules : {},
events : {}
}

@@ -696,2 +698,3 @@ };

dss.core.refreshDss();
dss.trigger('init');
}

@@ -714,5 +717,15 @@ }

var pseudo = false;
var selectors = rules.selectors.join(',');
var explicitDssProperty = false;
var isDynamic = false;
var declarations = rules.declarations.filter(function(rule){
return rule.value.indexOf('||') !== -1;
isDynamic = rule.value.indexOf('||') !== -1 || rule.parent.selectors.join('').indexOf(':dss') !== -1 || rule.property.indexOf('dss-') !== -1;
if (!isDynamic){
if (!dss.core.nonDynamicRules[selectors])
dss.core.nonDynamicRules[selectors] = {};
dss.core.nonDynamicRules[selectors][rule.property] = rule.value;
}
return isDynamic;
}).map(function(prop){

@@ -725,15 +738,24 @@ var obj = {};

if (declarations.length > 0){
dss.core.refreshValues[rules.selectors.join(',')] = declarations;
pseudo = selectors.indexOf(':dss') !== -1;
if (pseudo)
selectors = selectors.replace(/:dss/gmi,'');
var newObj = {};
dss.core.refreshValues[rules.selectors.join(',')].map(function(property){
if (!dss.core.refreshValues[selectors]){
dss.core.refreshValues[selectors] = {};
}
declarations.map(function(property){
Object.keys(property).map(function(prop){
newObj[prop] = property[prop];
var propName = prop.replace('dss-','');
explicitDssProperty = false;
explicitDssProperty = prop.indexOf('dss-') !== -1;
if (pseudo || explicitDssProperty){
dss.core.refreshValues[selectors][propName] = '||'+property[prop]+'||';
}else{
dss.core.refreshValues[selectors][propName] = property[prop];
}
});
});
dss.core.refreshValues[rules.selectors.join(',')] = newObj;
}

@@ -805,3 +827,2 @@ };

return Object.keys(rules).map(function(rule){

@@ -814,5 +835,4 @@

return rule+'{'+Object.keys(rules[rule]).reduce(function(acc,a,i,fullArr){
return '\n'+rule+'\n{'+Object.keys(rules[rule]).reduce(function(acc,a,i,fullArr){
if (i === 1){

@@ -874,3 +894,2 @@ if(typeof rules[rule][acc] === 'string'){

dss.core.refreshDss();
console.log(dss.rawStyleSheet);

@@ -929,2 +948,3 @@

}
dss.trigger('render');
};

@@ -984,2 +1004,14 @@ })(this.dss);

})(this.dss);
//File : src/interface/dss.on.js
(function(dss){
'use strict';
dss.core.defineMethod('on',function(label,event){
if (!dss.core.events[label])
dss.core.events[label] = [];
dss.core.events[label].push(event);
});
})(this.dss);
//File : src/interface/dss.setProperty.js

@@ -1005,2 +1037,15 @@

})(this.dss);
//File : src/interface/dss.trigger.js
(function(dss){
'use strict';
dss.core.defineMethod('trigger',function(label){
if (dss.core.events[label])
dss.core.events[label].map(function(event){
event();
});
});
})(this.dss);
//File : src/helpers/dss.bounds.js

@@ -1080,2 +1125,16 @@

})(this.dss);
//File : src/helpers/dss.reference.js
(function(dss){
'use strict';
dss.core.defineMethod('reference',function(selector,property,relation){
if (dss.core.refreshValues[selector])
if(dss.core.refreshValues[selector][property])
return dss.core.refreshValues[selector][property].value;
return dss.core.nonDynamicRules[selector][property];
});
})(this.dss);
//File : src/defaultProperties/dss.defaultProperties.mouse.js

@@ -1082,0 +1141,0 @@

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

var commentre=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,css=function(a,b){b=b||{};var c=1,d=1;function e(a){var b=a.match(/\n/g);b&&(c+=b.length);var e=a.lastIndexOf("\n");d=~e?a.length-e:d+a.length}function f(){return function(a){return n(),a}}var g=[];function h(a){console.log(a)}function i(){var a=l();return{type:"stylesheet",stylesheet:{rules:a,parsingErrors:g}}}function j(){return m(/^{\s*/)}function k(){return m(/^}/)}function l(){var b,c=[];n(),o(c);while(a.length&&"}"!=a.charAt(0)&&(b=G()||H()))b!==!1&&(c.push(b),o(c));return c}function m(b){var c=b.exec(a);if(c){var d=c[0];return e(d),a=a.slice(d.length),c}}function n(){m(/^\s*/)}function o(a){var b;a=a||[];while(b=p())b!==!1&&a.push(b);return a}function p(){var b=f();if("/"==a.charAt(0)&&"*"==a.charAt(1)){var c=2;while(""!=a.charAt(c)&&("*"!=a.charAt(c)||"/"!=a.charAt(c+1)))++c;if(c+=2,""===a.charAt(c-1))return h("End of comment missing");var g=a.slice(2,c-2);return d+=2,e(g),a=a.slice(c),d+=2,b({type:"comment",comment:g})}}function q(){var a=m(/^([^{]+)/);if(a)return trim(a[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g,"").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g,function(a){return a.replace(/,/g,"\u200c")}).split(/\s*(?![^(]*\)),\s*/).map(function(a){return a.replace(/\u200C/g,",")})}function r(){var a=f(),b=m(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);if(b){if(b=trim(b[0]),!m(/^:\s*/))return h("property missing ':'");var c=m(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/),d=a({type:"declaration",property:b.replace(commentre,""),value:c?trim(c[0]).replace(commentre,""):""});return m(/^[;\s]*/),d}}function s(){var a=[];if(!j())return h("missing '{'");o(a);var b;while(b=r())b!==!1&&(a.push(b),o(a));return k()?a:h("missing '}'")}function t(){var a,b=[],c=f();while(a=m(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/))b.push(a[1]),m(/^,\s*/);return b.length?c({type:"keyframe",values:b,declarations:s()}):void 0}function u(){var a=f(),b=m(/^@([-\w]+)?keyframes\s*/);if(b){var c=b[1],b=m(/^([-\w]+)\s*/);if(!b)return h("@keyframes missing name");var d=b[1];if(!j())return h("@keyframes missing '{'");var e,g=o();while(e=t())g.push(e),g=g.concat(o());return k()?a({type:"keyframes",name:d,vendor:c,keyframes:g}):h("@keyframes missing '}'")}}function v(){var a=f(),b=m(/^@supports *([^{]+)/);if(b){var c=trim(b[1]);if(!j())return h("@supports missing '{'");var d=o().concat(l());return k()?a({type:"supports",supports:c,rules:d}):h("@supports missing '}'")}}function w(){var a=f(),b=m(/^@host\s*/);if(b){if(!j())return h("@host missing '{'");var c=o().concat(l());return k()?a({type:"host",rules:c}):h("@host missing '}'")}}function x(){var a=f(),b=m(/^@media *([^{]+)/);if(b){var c=trim(b[1]);if(!j())return h("@media missing '{'");var d=o().concat(l());return k()?a({type:"media",media:c,rules:d}):h("@media missing '}'")}}function y(){var a=f(),b=m(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);return b?a({type:"custom-media",name:trim(b[1]),media:trim(b[2])}):void 0}function z(){var a=f(),b=m(/^@page */);if(b){var c=q()||[];if(!j())return h("@page missing '{'");var d=o(),e;while(e=r())d.push(e),d=d.concat(o());return k()?a({type:"page",selectors:c,declarations:d}):h("@page missing '}'")}}function A(){var a=f(),b=m(/^@([-\w]+)?document *([^{]+)/);if(b){var c=trim(b[1]),d=trim(b[2]);if(!j())return h("@document missing '{'");var e=o().concat(l());return k()?a({type:"document",document:d,vendor:c,rules:e}):h("@document missing '}'")}}function B(){var a=f(),b=m(/^@font-face\s*/);if(b){if(!j())return h("@font-face missing '{'");var c=o(),d;while(d=r())c.push(d),c=c.concat(o());return k()?a({type:"font-face",declarations:c}):h("@font-face missing '}'")}}var C=F("import"),D=F("charset"),E=F("namespace");function F(a){var b=new RegExp("^@"+a+"\\s*([^;]+);");return function(){var c=f(),d=m(b);if(d){var e={type:a};return e[a]=d[1].trim(),c(e)}}}function G(){return"@"==a[0]?u()||x()||y()||v()||C()||D()||E()||A()||z()||w()||B():void 0}function H(){var a=f(),b=q();return b?(o(),a({type:"rule",selectors:b,declarations:s()})):h("selector missing")}return addParent(i())};function trim(a){return a?a.replace(/^\s+|\s+$/g,""):""}function addParent(a,b){var c=a&&"string"==typeof a.type,d=c?a:b;for(var e in a){var f=a[e];Array.isArray(f)?f.forEach(function(a){addParent(a,d)}):f&&"object"==typeof f&&addParent(f,d)}return c&&Object.defineProperty(a,"parent",{configurable:!0,writable:!0,enumerable:!1,value:b||null}),a}!function(a){"use strict";a.dss=function(){return{core:{myRules:{},refreshValues:{}}}}()}(this),function(a){"use strict";a.core.ajax=function(a){var b=a.callback||function(){return!1},c=a.url,d=a.method||"GET",e=a.data||!1,f;if("undefined"!=typeof XMLHttpRequest)f=new XMLHttpRequest;else for(var g=["MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp.2.0","Microsoft.XmlHttp"],h=0,i=g.length;i>h;h++)try{f=new ActiveXObject(g[h]);break}catch(j){}f.onreadystatechange=k;function k(){f.readyState<4||(200===f.status||0===f.status)&&4===f.readyState&&b(f.response)}f.open(d,c,!0),"POST"==d.toUpperCase()?(f.setRequestHeader("Content-type","application/x-www-form-urlencoded"),e=x.core.serialize(e),f.send(e)):f.send("")}}(this.dss),function(a){"use strict";a.core.defineMethod=function(b,c){if(a[b])throw"Method "+b+"() already exists";a[b]=c}}(this.dss),function(a){"use strict";a.core.fetchStyleSheets=function(){var b=document.querySelectorAll('link[rel="dynamic-stylesheet"]'),c=b.length,d=0;return 0===c&&(a.core.IS_INITIALIZED=!0),[].forEach.call(b,function(b){return b.attributes.href?a.core.loadStyleSheets(b.attributes.href.value,function e(){d++,c===d&&(a.core.IS_INITIALIZED=!0,a.core.refreshDss())}):void c--})}}(this.dss),function(a){"use strict";a.core.findDynamics=function(b){var c=b.declarations.filter(function(a){return-1!==a.value.indexOf("||")}).map(function(a){var b={};return b[a.property]=a.value,b});if(c.length>0){a.core.refreshValues[b.selectors.join(",")]=c;var d={};a.core.refreshValues[b.selectors.join(",")].map(function(a){Object.keys(a).map(function(b){d[b]=a[b]})}),a.core.refreshValues[b.selectors.join(",")]=d}}}(this.dss),function(dss){"use strict";function _parse(value){var newValue=value;for(var property in dss.core.dynamics)"number"==typeof dss.core.dynamics[property]&&(newValue=newValue.replace(new RegExp(property,"gmi"),dss.core.dynamics[property])),"string"==typeof dss.core.dynamics[property]&&(newValue=newValue.replace(new RegExp(property,"gmi"),"'"+dss.core.dynamics[property]+"'"));try{return eval(newValue)}catch(err){return newValue}}function _parseFields(a){var b=a.replace(/(\|\|[^\|]*\|\|)/gim,function(a){var b=a.replace(/\|/gim,"").split(":");if(dss.core.dynamics&&dss.core.dynamics[b[0]])return dss.core.dynamics[b[0]];var c=_parse(b[0]);return c!==!1&&b[0]!==c?_parse(b[0]):b[1]||!1});return b}dss.core.findMatch=function(a){return _parseFields(a)}}(this.dss),function(a){"use strict";a.core.generateCss=function(a){return Object.keys(a).map(function(b){if(1===Object.keys(a[b]).length){var c=Object.keys(a[b]);return b+"{"+c+":"+a[b][c].value+"}"}return b+"{"+Object.keys(a[b]).reduce(function(c,d,e,f){return 1===e?(c="string"==typeof a[b][c]?c+":"+a[b][c]+";":c+":"+a[b][c].value+";","string"==typeof a[b][d]?c+d+":"+a[b][d]+";":c+d+":"+a[b][d].value+";"):"string"==typeof a[b][d]?c+d+":"+a[b][d]+";":c+d+":"+a[b][d].value+";"})+"}"}).join("")}}(this.dss),function(a){"use strict";a.core.loadStyleSheets=function(b,c){a.core.ajax({url:b,callback:function d(e){a.core.parseStyleSheets(e,b),c()}})}}(this.dss),function(a){"use strict";a.core.parseStyleSheets=function(b,c){var d=document.createElement("link");d.setAttribute("rel","stylesheet"),d.setAttribute("href",c),d.setAttribute("type","text/css"),document.head.appendChild(d),css(b).stylesheet.rules.forEach(a.core.findDynamics),a.rawStyleSheet=a.core.generateCss(a.core.refreshValues),a.core.refreshDss(),console.log(a.rawStyleSheet)}}(this.dss),function(a){"use strict";a.core.refreshDss=function(b){Object.keys(a.core.refreshValues).map(function(c){Object.keys(a.core.refreshValues[c]).map(function(d){"string"==typeof a.core.refreshValues[c][d]?a.core.refreshValues[c][d]={originalValue:a.core.refreshValues[c][d],value:a.core.findMatch(a.core.refreshValues[c][d])}:(-1!==a.core.refreshValues[c][d].originalValue.indexOf(b)||void 0===b)&&(a.core.refreshValues[c][d].value=a.core.findMatch(a.core.refreshValues[c][d].originalValue))})}),a.core.render()}}(this.dss),function(a){"use strict";a.core.render=function(){var b=document.querySelectorAll('[rel="dss-generated-stylesheet"]');if(b[0]){var c=a.core.generateCss(a.core.refreshValues);a.lastDSSSheet!==c&&(a.lastDSSSheet=c,b[0].innerHTML=c)}else{var d=document.createElement("style");d.setAttribute("rel","dss-generated-stylesheet"),a.lastDSSSheet=a.core.generateCss(a.core.refreshValues),d.appendChild(document.createTextNode(a.lastDSSSheet)),document.head.appendChild(d)}}}(this.dss),function(a){"use strict";function b(a){return a.charAt(0).toUpperCase()+a.slice(1)}a.core.defineMethod("addDefaultProperty",function(c,d){if(d=d(),d["default"]){var e=d["default"]();for(var f in e)a.setProperty(c+b(f),e[f])}d.context.addEventListener(d.event,function g(){var e=d.getter.apply(d,arguments);for(var f in e)a.setProperty(c+b(f),e[f])})}),a.core.defineMethod("setDynamicProperty",function(c,d){d=d(),d.context.addEventListener(d.event,function e(){var e=d.getter.apply(d,arguments);for(var f in e)a.setProperty(c+b(f),e[f])})})}(this.dss),function(a){"use strict";a.core.defineMethod("init",a.core.fetchStyleSheets),document.addEventListener("DOMContentLoaded",a.init,!1)}(this.dss),function(a){"use strict";a.core.defineMethod("setProperty",function(b,c){var d=!1;a.core.dynamics||(a.core.dynamics={}),a.core.dynamics[b]!==c&&(a.core.dynamics[b]=c,d=!0),a.core.IS_INITIALIZED&&d&&a.core.refreshDss(b)})}(this.dss),function(a){"use strict";a.core.defineMethod("bounds",function(a,b){return function(c){return a>c?a:c>b?b:c}})}(this.dss),function(a){"use strict";a.core.defineMethod("if",function(a){return function(b){return function(c){return a?b:c}}})}(this.dss),function(a){"use strict";a.core.defineMethod("limitDown",function(a){return function(b){return a>b?a:b}})}(this.dss),function(a){"use strict";a.core.defineMethod("limitUp",function(a){return function(b){return b>a?a:b}})}(this.dss),function(a){"use strict";a.core.defineMethod("pon",function(a){return Math.max(0,a)})}(this.dss),function(a){"use strict";a.addDefaultProperty("mouse",function(){return{context:document,event:"mousemove",getter:function(a){return{x:a.pageX,y:a.pageY}}}})}(this.dss),function(a){"use strict";a.addDefaultProperty("scroll",function(){return{context:document,event:"scroll",getter:function(a){return{x:window.scrollX,y:window.scrollY}}}})}(this.dss),function(a){"use strict";a.addDefaultProperty("window",function(){return{context:window,event:"resize",getter:function(a){return{width:window.innerWidth,height:window.innerHeight}},"default":function(){return{width:window.innerWidth,height:window.innerHeight}}}})}(this.dss);
var commentre=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,css=function(a,b){b=b||{};var c=1,d=1;function e(a){var b=a.match(/\n/g);b&&(c+=b.length);var e=a.lastIndexOf("\n");d=~e?a.length-e:d+a.length}function f(){return function(a){return n(),a}}var g=[];function h(a){console.log(a)}function i(){var a=l();return{type:"stylesheet",stylesheet:{rules:a,parsingErrors:g}}}function j(){return m(/^{\s*/)}function k(){return m(/^}/)}function l(){var b,c=[];n(),o(c);while(a.length&&"}"!=a.charAt(0)&&(b=G()||H()))b!==!1&&(c.push(b),o(c));return c}function m(b){var c=b.exec(a);if(c){var d=c[0];return e(d),a=a.slice(d.length),c}}function n(){m(/^\s*/)}function o(a){var b;a=a||[];while(b=p())b!==!1&&a.push(b);return a}function p(){var b=f();if("/"==a.charAt(0)&&"*"==a.charAt(1)){var c=2;while(""!=a.charAt(c)&&("*"!=a.charAt(c)||"/"!=a.charAt(c+1)))++c;if(c+=2,""===a.charAt(c-1))return h("End of comment missing");var g=a.slice(2,c-2);return d+=2,e(g),a=a.slice(c),d+=2,b({type:"comment",comment:g})}}function q(){var a=m(/^([^{]+)/);if(a)return trim(a[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g,"").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g,function(a){return a.replace(/,/g,"\u200c")}).split(/\s*(?![^(]*\)),\s*/).map(function(a){return a.replace(/\u200C/g,",")})}function r(){var a=f(),b=m(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);if(b){if(b=trim(b[0]),!m(/^:\s*/))return h("property missing ':'");var c=m(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/),d=a({type:"declaration",property:b.replace(commentre,""),value:c?trim(c[0]).replace(commentre,""):""});return m(/^[;\s]*/),d}}function s(){var a=[];if(!j())return h("missing '{'");o(a);var b;while(b=r())b!==!1&&(a.push(b),o(a));return k()?a:h("missing '}'")}function t(){var a,b=[],c=f();while(a=m(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/))b.push(a[1]),m(/^,\s*/);return b.length?c({type:"keyframe",values:b,declarations:s()}):void 0}function u(){var a=f(),b=m(/^@([-\w]+)?keyframes\s*/);if(b){var c=b[1],b=m(/^([-\w]+)\s*/);if(!b)return h("@keyframes missing name");var d=b[1];if(!j())return h("@keyframes missing '{'");var e,g=o();while(e=t())g.push(e),g=g.concat(o());return k()?a({type:"keyframes",name:d,vendor:c,keyframes:g}):h("@keyframes missing '}'")}}function v(){var a=f(),b=m(/^@supports *([^{]+)/);if(b){var c=trim(b[1]);if(!j())return h("@supports missing '{'");var d=o().concat(l());return k()?a({type:"supports",supports:c,rules:d}):h("@supports missing '}'")}}function w(){var a=f(),b=m(/^@host\s*/);if(b){if(!j())return h("@host missing '{'");var c=o().concat(l());return k()?a({type:"host",rules:c}):h("@host missing '}'")}}function x(){var a=f(),b=m(/^@media *([^{]+)/);if(b){var c=trim(b[1]);if(!j())return h("@media missing '{'");var d=o().concat(l());return k()?a({type:"media",media:c,rules:d}):h("@media missing '}'")}}function y(){var a=f(),b=m(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);return b?a({type:"custom-media",name:trim(b[1]),media:trim(b[2])}):void 0}function z(){var a=f(),b=m(/^@page */);if(b){var c=q()||[];if(!j())return h("@page missing '{'");var d=o(),e;while(e=r())d.push(e),d=d.concat(o());return k()?a({type:"page",selectors:c,declarations:d}):h("@page missing '}'")}}function A(){var a=f(),b=m(/^@([-\w]+)?document *([^{]+)/);if(b){var c=trim(b[1]),d=trim(b[2]);if(!j())return h("@document missing '{'");var e=o().concat(l());return k()?a({type:"document",document:d,vendor:c,rules:e}):h("@document missing '}'")}}function B(){var a=f(),b=m(/^@font-face\s*/);if(b){if(!j())return h("@font-face missing '{'");var c=o(),d;while(d=r())c.push(d),c=c.concat(o());return k()?a({type:"font-face",declarations:c}):h("@font-face missing '}'")}}var C=F("import"),D=F("charset"),E=F("namespace");function F(a){var b=new RegExp("^@"+a+"\\s*([^;]+);");return function(){var c=f(),d=m(b);if(d){var e={type:a};return e[a]=d[1].trim(),c(e)}}}function G(){return"@"==a[0]?u()||x()||y()||v()||C()||D()||E()||A()||z()||w()||B():void 0}function H(){var a=f(),b=q();return b?(o(),a({type:"rule",selectors:b,declarations:s()})):h("selector missing")}return addParent(i())};function trim(a){return a?a.replace(/^\s+|\s+$/g,""):""}function addParent(a,b){var c=a&&"string"==typeof a.type,d=c?a:b;for(var e in a){var f=a[e];Array.isArray(f)?f.forEach(function(a){addParent(a,d)}):f&&"object"==typeof f&&addParent(f,d)}return c&&Object.defineProperty(a,"parent",{configurable:!0,writable:!0,enumerable:!1,value:b||null}),a}!function(a){"use strict";a.dss=function(){return{core:{myRules:{},refreshValues:{},nonDynamicRules:{},events:{}}}}()}(this),function(a){"use strict";a.core.ajax=function(a){var b=a.callback||function(){return!1},c=a.url,d=a.method||"GET",e=a.data||!1,f;if("undefined"!=typeof XMLHttpRequest)f=new XMLHttpRequest;else for(var g=["MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp.2.0","Microsoft.XmlHttp"],h=0,i=g.length;i>h;h++)try{f=new ActiveXObject(g[h]);break}catch(j){}f.onreadystatechange=k;function k(){f.readyState<4||(200===f.status||0===f.status)&&4===f.readyState&&b(f.response)}f.open(d,c,!0),"POST"==d.toUpperCase()?(f.setRequestHeader("Content-type","application/x-www-form-urlencoded"),e=x.core.serialize(e),f.send(e)):f.send("")}}(this.dss),function(a){"use strict";a.core.defineMethod=function(b,c){if(a[b])throw"Method "+b+"() already exists";a[b]=c}}(this.dss),function(a){"use strict";a.core.fetchStyleSheets=function(){var b=document.querySelectorAll('link[rel="dynamic-stylesheet"]'),c=b.length,d=0;return 0===c&&(a.core.IS_INITIALIZED=!0),[].forEach.call(b,function(b){return b.attributes.href?a.core.loadStyleSheets(b.attributes.href.value,function e(){d++,c===d&&(a.core.IS_INITIALIZED=!0,a.core.refreshDss(),a.trigger("init"))}):void c--})}}(this.dss),function(a){"use strict";a.core.findDynamics=function(b){var c=!1,d=b.selectors.join(","),e=!1,f=!1,g=b.declarations.filter(function(b){return f=-1!==b.value.indexOf("||")||-1!==b.parent.selectors.join("").indexOf(":dss")||-1!==b.property.indexOf("dss-"),f||(a.core.nonDynamicRules[d]||(a.core.nonDynamicRules[d]={}),a.core.nonDynamicRules[d][b.property]=b.value),f}).map(function(a){var b={};return b[a.property]=a.value,b});g.length>0&&(c=-1!==d.indexOf(":dss"),c&&(d=d.replace(/:dss/gim,"")),a.core.refreshValues[d]||(a.core.refreshValues[d]={}),g.map(function(b){Object.keys(b).map(function(f){var g=f.replace("dss-","");e=!1,e=-1!==f.indexOf("dss-"),c||e?a.core.refreshValues[d][g]="||"+b[f]+"||":a.core.refreshValues[d][g]=b[f]})}))}}(this.dss),function(dss){"use strict";function _parse(value){var newValue=value;for(var property in dss.core.dynamics)"number"==typeof dss.core.dynamics[property]&&(newValue=newValue.replace(new RegExp(property,"gmi"),dss.core.dynamics[property])),"string"==typeof dss.core.dynamics[property]&&(newValue=newValue.replace(new RegExp(property,"gmi"),"'"+dss.core.dynamics[property]+"'"));try{return eval(newValue)}catch(err){return newValue}}function _parseFields(a){var b=a.replace(/(\|\|[^\|]*\|\|)/gim,function(a){var b=a.replace(/\|/gim,"").split(":");if(dss.core.dynamics&&dss.core.dynamics[b[0]])return dss.core.dynamics[b[0]];var c=_parse(b[0]);return c!==!1&&b[0]!==c?_parse(b[0]):b[1]||!1});return b}dss.core.findMatch=function(a){return _parseFields(a)}}(this.dss),function(a){"use strict";a.core.generateCss=function(a){return Object.keys(a).map(function(b){if(1===Object.keys(a[b]).length){var c=Object.keys(a[b]);return b+"{"+c+":"+a[b][c].value+"}"}return"\n"+b+"\n{"+Object.keys(a[b]).reduce(function(c,d,e,f){return 1===e?(c="string"==typeof a[b][c]?c+":"+a[b][c]+";":c+":"+a[b][c].value+";","string"==typeof a[b][d]?c+d+":"+a[b][d]+";":c+d+":"+a[b][d].value+";"):"string"==typeof a[b][d]?c+d+":"+a[b][d]+";":c+d+":"+a[b][d].value+";"})+"}"}).join("")}}(this.dss),function(a){"use strict";a.core.loadStyleSheets=function(b,c){a.core.ajax({url:b,callback:function d(e){a.core.parseStyleSheets(e,b),c()}})}}(this.dss),function(a){"use strict";a.core.parseStyleSheets=function(b,c){var d=document.createElement("link");d.setAttribute("rel","stylesheet"),d.setAttribute("href",c),d.setAttribute("type","text/css"),document.head.appendChild(d),css(b).stylesheet.rules.forEach(a.core.findDynamics),a.rawStyleSheet=a.core.generateCss(a.core.refreshValues),a.core.refreshDss()}}(this.dss),function(a){"use strict";a.core.refreshDss=function(b){Object.keys(a.core.refreshValues).map(function(c){Object.keys(a.core.refreshValues[c]).map(function(d){"string"==typeof a.core.refreshValues[c][d]?a.core.refreshValues[c][d]={originalValue:a.core.refreshValues[c][d],value:a.core.findMatch(a.core.refreshValues[c][d])}:(-1!==a.core.refreshValues[c][d].originalValue.indexOf(b)||void 0===b)&&(a.core.refreshValues[c][d].value=a.core.findMatch(a.core.refreshValues[c][d].originalValue))})}),a.core.render()}}(this.dss),function(a){"use strict";a.core.render=function(){var b=document.querySelectorAll('[rel="dss-generated-stylesheet"]');if(b[0]){var c=a.core.generateCss(a.core.refreshValues);a.lastDSSSheet!==c&&(a.lastDSSSheet=c,b[0].innerHTML=c)}else{var d=document.createElement("style");d.setAttribute("rel","dss-generated-stylesheet"),a.lastDSSSheet=a.core.generateCss(a.core.refreshValues),d.appendChild(document.createTextNode(a.lastDSSSheet)),document.head.appendChild(d)}a.trigger("render")}}(this.dss),function(a){"use strict";function b(a){return a.charAt(0).toUpperCase()+a.slice(1)}a.core.defineMethod("addDefaultProperty",function(c,d){if(d=d(),d["default"]){var e=d["default"]();for(var f in e)a.setProperty(c+b(f),e[f])}d.context.addEventListener(d.event,function g(){var e=d.getter.apply(d,arguments);for(var f in e)a.setProperty(c+b(f),e[f])})}),a.core.defineMethod("setDynamicProperty",function(c,d){d=d(),d.context.addEventListener(d.event,function e(){var e=d.getter.apply(d,arguments);for(var f in e)a.setProperty(c+b(f),e[f])})})}(this.dss),function(a){"use strict";a.core.defineMethod("init",a.core.fetchStyleSheets),document.addEventListener("DOMContentLoaded",a.init,!1)}(this.dss),function(a){"use strict";a.core.defineMethod("on",function(b,c){a.core.events[b]||(a.core.events[b]=[]),a.core.events[b].push(c)})}(this.dss),function(a){"use strict";a.core.defineMethod("setProperty",function(b,c){var d=!1;a.core.dynamics||(a.core.dynamics={}),a.core.dynamics[b]!==c&&(a.core.dynamics[b]=c,d=!0),a.core.IS_INITIALIZED&&d&&a.core.refreshDss(b)})}(this.dss),function(a){"use strict";a.core.defineMethod("trigger",function(b){a.core.events[b]&&a.core.events[b].map(function(a){a()})})}(this.dss),function(a){"use strict";a.core.defineMethod("bounds",function(a,b){return function(c){return a>c?a:c>b?b:c}})}(this.dss),function(a){"use strict";a.core.defineMethod("if",function(a){return function(b){return function(c){return a?b:c}}})}(this.dss),function(a){"use strict";a.core.defineMethod("limitDown",function(a){return function(b){return a>b?a:b}})}(this.dss),function(a){"use strict";a.core.defineMethod("limitUp",function(a){return function(b){return b>a?a:b}})}(this.dss),function(a){"use strict";a.core.defineMethod("pon",function(a){return Math.max(0,a)})}(this.dss),function(a){"use strict";a.core.defineMethod("reference",function(b,c,d){return a.core.refreshValues[b]&&a.core.refreshValues[b][c]?a.core.refreshValues[b][c].value:a.core.nonDynamicRules[b][c]})}(this.dss),function(a){"use strict";a.addDefaultProperty("mouse",function(){return{context:document,event:"mousemove",getter:function(a){return{x:a.pageX,y:a.pageY}}}})}(this.dss),function(a){"use strict";a.addDefaultProperty("scroll",function(){return{context:document,event:"scroll",getter:function(a){return{x:window.scrollX,y:window.scrollY}}}})}(this.dss),function(a){"use strict";a.addDefaultProperty("window",function(){return{context:window,event:"resize",getter:function(a){return{width:window.innerWidth,height:window.innerHeight}},"default":function(){return{width:window.innerWidth,height:window.innerHeight}}}})}(this.dss);
//# sourceMappingURL=dss.min.map
{
"name": "dynamicss",
"version": "0.0.14",
"version": "0.1.0",
"description": "Dynamic Style Sheets",

@@ -5,0 +5,0 @@ "author": "Guilherme (Coder) de Souza",

@@ -27,10 +27,7 @@ # DSS (NOT SAFE FOR PRODUCTION)

Dynamic Style Sheets gives you the ability to dynamically set values to your css properties on the go.
No more inline binding.
An DSS example
***First things first ...***
First things first ...
```bash
bower install dss;
bower install dss;
```

@@ -43,3 +40,5 @@

```
then ...
***then ...***
```html

@@ -52,2 +51,45 @@ <!--

```
***DSS loaded!***
***Now you can put DSS declarations in your sheet in three different flavours:***
##### - Double pipe
```css
.box{
width: 50px;
height: 50px;
background: ||companyColor:red||;
position: absolute;
top: ||mouseY-25||px;
left: ||mouseX-25||px;
}
```
##### - Pseudo dss selector
```css
.box:dss{
width: 50px;
height: 50px;
background: companyColor:red;
position: absolute;
top: mouseY-25;
left: mouseX-25;
}
```
##### - "dss-" preffix property
```css
.box{
width: 50px;
height: 50px;
background-dss: companyColor:red;
position: absolute;
dss-top: mouseY-25;
dss-left: mouseX-25;
}
```
The **mouseY** and **mouseX** identifiers will automatically receive the mouse position on the screen, every time it changes.

@@ -61,6 +103,27 @@

# Default Auto-Binded Properties
##### **mouseX**
Automatically receives the x position of the cursor.
##### **mouseY**
Automatically receives the y position of the cursor.
##### **scrollX**
Automatically receives the x position of the window scroll.
##### **scrollY**
Automatically receives the y position of the window scroll.
##### **windowWidth**
Automatically receives the window width.
##### **windowHeight**
Automatically receives the window height.
# DSS Helpers
**dss.limitDown**
**dss.floor**
```css

@@ -73,3 +136,3 @@ /*margin-top will aways be 200 or more*/

**dss.limitUp**
**dss.ceil**
```css

@@ -109,2 +172,4 @@ /*margin-top will aways be 200 or less*/

## Managing properties
**dss.setProperty**

@@ -134,24 +199,20 @@ ```js

# Default Auto-Binded Properties
## Events
##### **mouseX**
Automatically receives the x position of the cursor.
**init**
```javascript
dss.on('init',function(){
console.log('DSS initialized with its first render Cycle =D ')
})
```
##### **mouseY**
Automatically receives the y position of the cursor.
**render**
```javascript
dss.on('render',function(){
console.log('there is a render cycle =D')
})
```
##### **scrollX**
Automatically receives the x position of the window scroll.
##### **scrollY**
Automatically receives the y position of the window scroll.
##### **windowWidth**
Automatically receives the window width.
##### **windowHeight**
Automatically receives the window height.
# Version
0.0.14 **Alpha**
0.1.0 **Beta**

@@ -158,0 +219,0 @@ # Building

@@ -21,2 +21,3 @@ //File : src/core/dss.core.fetchStyleSheets.js

dss.core.refreshDss();
dss.trigger('init');
}

@@ -23,0 +24,0 @@ }

@@ -8,5 +8,15 @@ //File : src/core/dss.core.findDynamics.js

var pseudo = false;
var selectors = rules.selectors.join(',');
var explicitDssProperty = false;
var isDynamic = false;
var declarations = rules.declarations.filter(function(rule){
return rule.value.indexOf('||') !== -1;
isDynamic = rule.value.indexOf('||') !== -1 || rule.parent.selectors.join('').indexOf(':dss') !== -1 || rule.property.indexOf('dss-') !== -1;
if (!isDynamic){
if (!dss.core.nonDynamicRules[selectors])
dss.core.nonDynamicRules[selectors] = {};
dss.core.nonDynamicRules[selectors][rule.property] = rule.value;
}
return isDynamic;
}).map(function(prop){

@@ -19,15 +29,24 @@ var obj = {};

if (declarations.length > 0){
dss.core.refreshValues[rules.selectors.join(',')] = declarations;
pseudo = selectors.indexOf(':dss') !== -1;
if (pseudo)
selectors = selectors.replace(/:dss/gmi,'');
var newObj = {};
dss.core.refreshValues[rules.selectors.join(',')].map(function(property){
if (!dss.core.refreshValues[selectors]){
dss.core.refreshValues[selectors] = {};
}
declarations.map(function(property){
Object.keys(property).map(function(prop){
newObj[prop] = property[prop];
var propName = prop.replace('dss-','');
explicitDssProperty = false;
explicitDssProperty = prop.indexOf('dss-') !== -1;
if (pseudo || explicitDssProperty){
dss.core.refreshValues[selectors][propName] = '||'+property[prop]+'||';
}else{
dss.core.refreshValues[selectors][propName] = property[prop];
}
});
});
dss.core.refreshValues[rules.selectors.join(',')] = newObj;
}

@@ -34,0 +53,0 @@ };

@@ -7,3 +7,2 @@ //File : src/core/dss.core.generateCss.js

return Object.keys(rules).map(function(rule){

@@ -16,5 +15,4 @@

return rule+'{'+Object.keys(rules[rule]).reduce(function(acc,a,i,fullArr){
return '\n'+rule+'\n{'+Object.keys(rules[rule]).reduce(function(acc,a,i,fullArr){
if (i === 1){

@@ -21,0 +19,0 @@ if(typeof rules[rule][acc] === 'string'){

@@ -22,2 +22,3 @@ //File : src/core/dss.core.render.js

}
dss.trigger('render');
};

@@ -24,0 +25,0 @@ })(this.dss);

@@ -16,3 +16,5 @@ //File : src/dss.js

myRules : {},
refreshValues : {}
refreshValues : {},
nonDynamicRules : {},
events : {}
}

@@ -19,0 +21,0 @@ };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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