{"id":16982050,"url":"https://github.com/tenphi/jcss","last_synced_at":"2025-04-12T02:21:07.229Z","repository":{"id":2436303,"uuid":"3406076","full_name":"tenphi/jcss","owner":"tenphi","description":"Handy CSS Generation uses Javascript","archived":false,"fork":false,"pushed_at":"2015-03-29T09:49:16.000Z","size":250,"stargazers_count":15,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T07:58:55.288Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://tenphi.github.com/jcss","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tenphi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-10T09:52:29.000Z","updated_at":"2023-02-27T02:51:36.000Z","dependencies_parsed_at":"2022-08-31T00:02:01.764Z","dependency_job_id":null,"html_url":"https://github.com/tenphi/jcss","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenphi%2Fjcss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenphi%2Fjcss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenphi%2Fjcss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenphi%2Fjcss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tenphi","download_url":"https://codeload.github.com/tenphi/jcss/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248244891,"owners_count":21071355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T02:07:11.843Z","updated_at":"2025-04-12T02:21:07.207Z","avatar_url":"https://github.com/tenphi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"JCSS [![Build Status](https://travis-ci.org/tenphi/jcss.png)](https://travis-ci.org/tenphi/jcss)\n===\n\nHandy CSS Generator\n\nNow you can use Javascript for CSS declaration, and all its power at your fingertips!\n\nYou have no need to remember a lot of rules. JCSS uses the simple hierarchical declaration as the most of popular CSS-preprocessors (like LESS, Stylus, Sass), but using of advanced features like mixins will be as easier as you know Javascript. And I hope you know it well.\n\nKnowledge of the CoffeeScript can rise the usability of this library up to the new level! Because it's much more simple language for declarations, you know. In spite of this, all documentation wrote by Javascript.\n\n## Warning\n\nI should warn you that using of this library is not necessary in most of the cases. I recommend you to use any other modern css-framework (that based on CSS instead of JS).\nProbably you could find some situations (as I did) where JCSS shows itself. Anyway, use it with caution.\n\n## Getting started\nInstall via NPM...\n\n```\n$ npm install jcss\n```\n\n... or add script to your web page.\n\n```html\n\u003cscript type=\"text/javascript\" src=\"/path/to/jcss.js\"\u003e\u003c/script\u003e\n```\n\n... or install script via bower and add via requirejs.\n\n```bash\nbower install git://github.com/tenphi/jcss.git\n```\n\n```javascript\nrequire(['./components/jcss/jcss'], function(jcss) {\n  jcss.inject(/* name */, /* object of styles */);\n});\n```\n\n## Simple rules, great opportunities\nLet's try to learn more about JCSS. We can start with simplest example:\n\n```javascript\njcss.render({\n    '.class': {\n        color: 'black'\n    }\n});\n```\n\n```css\n.class {\n    color: black;\n}\n```\n\nYou could think that there are no benefits of using JCSS. But hold on, its just a beginning! Magic awaits us!\n\n```javascript\n// left join\njcss.render({\n    '.class1': {\n        color: 'red',\n        '.class2': { // '\u0026 .class' works as well if you like it\n            color: 'black'\n        }\n    }\n});\n\n// right join\njcss.render({\n    '.class1': {\n        color: 'red',\n        '.class2 \u0026': {\n            color: 'black'\n        }\n    }\n});\n```\n\n```css\n/* left join */\n.class1 {\n    color: red;\n}\n\n.class1 .class2 {\n    color: black;\n}\n\n/* right join */\n.class1 {\n    color: red;\n}\n\n.class2 .class1 {\n    color: black;\n}\n```\n\nIt's simple rules for joining selectors for flexible declaration.\nBut what should we do if we want to create a several values for single style. We can use arrays! Here is an another simple example:\n\n```javascript\njcss.render({\n    '.class1': {\n        background: [\n            'url(bg1.png), url(bg2.png)', // if browser supports multiple backgrounds\n            'url(bg.png)' // single background for other browsers\n        ]\n    }\n});\n```\n\n```css\n.class1 {\n    background: url(bg1.png), url(bg2.png);\n    background: url(bg.png);\n}\n```\n\nNow, Let's try to broke up the library with some complex example. Also, we will see how separation of selectors works.\n\n```javascript\njcss.render({\n    '.class1, .class2': {\n        '.class3, .class4': { // Also, as for clarity, we can use this notation - ' .class3| .class4'\n            color: 'black',\n            background: 'transparent'\n        }\n    },\n    '.class2 .class3': {\n        background: 'blue'\n    }\n});\n```\n\n```css\n.class1 .class3 {\n    color: black;\n    background: transparent;\n}\n\n.class1 .class4 {\n    color: black;\n    background: transparent;\n}\n\n.class2 .class3 {\n    color: black;\n    background: blue;\n}\n\n.class2 .class4 {\n    color: black;\n    background: transparent;\n}\n```\n\nWell, it's not what we except. It's because JCSS not an optimizer yet. For optimization I recommend libraries like CSSO. JCSS just makes fast code, not small, because redefinitions of styles work in generation step, not in product. It makes your CSS really fast! And you have no need of thinking about are there too much overrides or not.\n\n## Mixins\n\nAs many CSS-preprocessors JCSS have mixins as well. But JCSS's mixins are Javascript functions. And it's really cool. Why? Take a look:\n\n```javascript\njcss.mixins['borderRadius'] = function(val) {\n    return {\n        WebkitBorderRadius: val,\n        MozBorderRadius: val,\n        borderRadius: val\n    };\n};\njcss.render({\n    '.class': {\n        borderRadius: '5px'\n    }\n});\n```\n\n```css\n.class {\n    -webkit-border-radius: 5px;\n    -moz-border-radius: 5px;\n    border-radius: 5px;\n}\n```\n\nWow! Mixins are great, aren't they?\n\n## Variables \u0026 More\n\nJavascript provides you many opportunities of generating CSS which are limited only by your imagination. DO WHAT YOU WANT!\n\n```javascript\nvar width = '100px';\njcss.render(function() {\n    var out = {};\n    for (var i = 1; i \u003c 10; i++) {\n        out['.class' + i] = {\n            width: width\n        };\n    }\n    return out;\n}());\n```\n\nYou already know what output should be here :)\n\n## Extras\n\nDon't forget about @-rules. You can use it too, but more flexible. Here is some examples:\n\n### @media and @supports\n\n```javascript\njcss.render({\n    '@media (max-width=980)': {\n        '.class1': {\n            style1: 'red',\n            '\u0026 .class2': {\n                style2: 'blue'\n            }\n        }\n    },\n    '.class1': {\n        '@media (max-width=980)': {\n            style1: 'blue',\n            '\u0026 .class2': {\n                style2: 'red'\n            }\n        }\n    }\n});\n```\n\n```css\n@media (max-width=980) {\n\n    .class1 {\n        style1: blue;\n    }\n\n    .class1 .class2{\n        style2: red;\n    }\n\n}\n```\n\nIsn't this cool? JCSS overrided the rules.\n\n### @font-face and @page\n\n```javascript\njcss.render({\n    '@font-face': {\n        fontFamily: 'FontName',\n        src: 'url(\"fontname.otf\")'\n    },\n    '@page :first': {\n        margin: '1cm'\n    }\n});\n```\n\n```css\n@font-face {\n  font-family: FontName;\n  src: url(\"fontname.otf\");\n}\n\n@page :first {\n  margin: 1cm;\n}\n```\n\n### @import and @charset\n\n```javascript\njcss.render({\n    '@charset': '\"windows-1251\"',\n    '@import': '\"another.css\" all'\n});\n```\n\n```css\n@charset \"windows-1251\";\n\n@import \"another.css\" all;\n```\n\nYep! Not so cool. But we can live with that because it is very rare use case.\n\n## Custom Objects as style value\n\nFor example, if you have a super color library you may want to use it with JCSS. No problem!\n\n```javascript\nvar color = new Color('red').lighten(20); // a lighter shade of red\njcss.render({\n    '.class': {\n        color: color // \u003c- it's our Object! it will transform into string!\n    }\n});\n```\n\nIf Color prototype have `toString()` method it would use for getting value of style.\n\n## That's all, folks! :)\n\n## License\n\n(The MIT License)\n\nCopyright (c) 20011-2013 Andrey Yamanov \u003ctenphi@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenphi%2Fjcss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftenphi%2Fjcss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenphi%2Fjcss/lists"}