├── .babelrc
├── .editorconfig
├── .gitignore
├── .npmrc
├── .nvmrc
├── .prettierignore
├── .prettierrc
├── .stylelintignore
├── .stylelintrc
├── .travis.yml
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── package.json
├── src
├── images
│ └── favicon.ico
├── markup
│ └── index.html.ejs
├── scripts
│ ├── charts
│ │ └── index.js
│ ├── fontLoader.js
│ └── main.js
└── styles
│ ├── _animations.css
│ ├── _charts.css
│ ├── _content-block.css
│ ├── _elements.css
│ ├── _form.css
│ ├── _header.css
│ ├── _variables.css
│ ├── _wrapper.css
│ ├── main.css
│ └── vendor
│ └── _normalize.css
├── webpack.config.js
└── yarn.lock
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["@babel/preset-env"]
3 | }
4 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | .vscode/
3 |
4 | dist/
5 | node_modules/
6 |
7 | .DS_Store
8 | package-lock.json
9 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | engine-strict=true
2 |
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | 10
2 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | .vscode/
3 |
4 | package-lock.json
5 |
6 | build/
7 | dist/
8 | node_modules/
9 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/prettierrc",
3 | "printWidth": 100,
4 | "tabWidth": 2,
5 | "useTabs": false,
6 | "semi": false,
7 | "singleQuote": true,
8 | "trailingComma": "all"
9 | }
10 |
--------------------------------------------------------------------------------
/.stylelintignore:
--------------------------------------------------------------------------------
1 | src/styles/vendor
2 |
--------------------------------------------------------------------------------
/.stylelintrc:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "stylelint-order"
4 | ],
5 | "extends": "stylelint-config-standard",
6 | "rules": {
7 | "at-rule-no-unknown": [
8 | true,
9 | {
10 | ignoreAtRules: [
11 | "mixin",
12 | "include"
13 | ]
14 | }
15 | ],
16 | "number-leading-zero": "never",
17 | "order/properties-alphabetical-order": true
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - 10
4 | cache:
5 | directories:
6 | - node_modules
7 | before_install:
8 | - curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.9.4
9 | - export PATH="$HOME/.yarn/bin:$PATH"
10 | script:
11 | - yarn build
12 | deploy:
13 | provider: pages
14 | skip_cleanup: true
15 | github_token: $github_token
16 | local_dir: dist
17 | on:
18 | branch: master
19 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others’ private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at francesco.schwarz@posteo.de. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project’s leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [https://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: https://contributor-covenant.org
46 | [version]: https://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Pull requests go into the `master` branch. The `gh-pages` branch is a presentation of the `master` branch at the last given push.
4 |
5 | ## Prerequisites
6 |
7 | - You must have [**Node.js**](https://nodejs.org/) and [**Yarn**](https://yarnpkg.com/lang/en/) installed to run the *Specificity Visualizer* locally.
8 | - Clone the repository with
9 | `git clone https://github.com/isellsoap/specificity-visualizer.git`
10 | - Go into the folder with
11 | `cd specificity-visualizer`
12 |
13 | ## Developing
14 |
15 | - **`yarn start`** starts the application in development mode and continuously watches all files.
16 |
17 | ## Building
18 |
19 | - **`yarn build`** builds the application in production mode.
20 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017 Francesco Schwarz
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 📈 Specificity Visualizer
2 |
3 | [](https://travis-ci.org/isellsoap/specificity-visualizer)
4 |
5 | A visual way to analyze the specificity of selectors in CSS.
6 |
7 | - [Website](https://isellsoap.github.io/specificity-visualizer/)
8 | - [Introductory blog post](https://francescoschwarz.com/articles/introducing-the-specificity-visualizer/)
9 | - [Features](#features)
10 | - [Contributing](#contributing)
11 | - [Download](#download)
12 |
13 | ---
14 |
15 | The _Specificity Visualizer_ enables you to identify patterns, trends and inconsistencies across a CSS file in bird’s-eye view. It’s especially useful for analyzing big and complex stylesheets. The underlying concept of the [specificity graph](https://csswizardry.com/2014/10/the-specificity-graph/) has been coined by Harry Roberts.
16 |
17 | ## Features
18 |
19 | - 😍 It’s a pretty fun and nice visual experience and potentially changes the way how you look into and think about (your) stylesheets.
20 | - 🔍 Hover over single data points to see the exact selector or zoom into areas of interest, e.g. you can look at only the selectors of the first half of the file or you can zoom into all selectors with the specificity of `0,2,1` across the entire file.
21 | - 📊 To better distinguish different specificity categories the data points are using proper colors and forms. You can also click on a legend item to toggle its visibility, e.g. if you only want to see all ID selectors.
22 | - 📸️ Taking screenshots of the chart is great to track progress, e.g. you could save a snapshot of your stylesheet before and after a major refactoring to visualize the difference. Also, you could use it for presentations to effectively communicate to other developers and/or stakeholders.
23 | - 📏 Specificities are treated as proper categories on the `y` axis and aren’t simply “added up” (after all, no amount of class selectors can overrule an ID selector). Also, selectors inside of `@media`, `@supports` and `@document` blocks are counted, selectors inside of `@keyframes` blocks aren’t.
24 |
25 | ## Contributing
26 |
27 | Pull requests go into the `master` branch. The `gh-pages` branch is a presentation of the `master` branch at the last given push.
28 |
29 | ### Prerequisites
30 |
31 | - You must have [**Node.js**](https://nodejs.org/) and [**Yarn**](https://yarnpkg.com/lang/en/) installed to run the _Specificity Visualizer_ locally.
32 | - Clone the repository with
33 | `git clone https://github.com/isellsoap/specificity-visualizer.git`
34 | - Go into the folder with
35 | `cd specificity-visualizer`
36 |
37 | ### Developing
38 |
39 | - **`yarn start`** starts the application in development mode and continuously watches all files.
40 |
41 | ### Building
42 |
43 | - **`yarn build`** builds the application in production mode.
44 |
45 | ## Download
46 |
47 | You can simply [download the latest version of the website as a ZIP file](https://github.com/isellsoap/specificity-visualizer/archive/gh-pages.zip).
48 |
49 | ## License
50 |
51 | This repository is published under the [MIT license](https://github.com/isellsoap/specificity-visualizer/LICENSE.md).
52 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "specificity-visualizer",
3 | "repository": "isellsoap/specificity-visualizer",
4 | "author": "Francesco Schwarz",
5 | "description": "A visual way to analyze the specificity of selectors in CSS.",
6 | "homepage": "https://isellsoap.github.io/specificity-visualizer/",
7 | "bugs": {
8 | "url": "https://github.com/isellsoap/specificity-visualizer/issues"
9 | },
10 | "license": "MIT",
11 | "engines": {
12 | "node": "10",
13 | "yarn": ">= 1.9.4"
14 | },
15 | "browserslist": [
16 | "IE >= 10"
17 | ],
18 | "scripts": {
19 | "build": "yarn && cross-env NODE_ENV=production webpack",
20 | "start": "yarn && cross-env NODE_ENV=development webpack-dev-server"
21 | },
22 | "dependencies": {
23 | "highcharts": "6.1.2",
24 | "javascript-natural-sort": "0.7.1",
25 | "lodash": "4.17.10",
26 | "normalize.css": "8.0.0",
27 | "parsel-js": "^1.0.1",
28 | "webfontloader": "1.6.28"
29 | },
30 | "devDependencies": {
31 | "@babel/core": "7.0.0",
32 | "@babel/preset-env": "7.0.0",
33 | "@types/webpack": "4.4.11",
34 | "autoprefixer": "9.1.5",
35 | "babel-loader": "8.0.2",
36 | "clean-webpack-plugin": "0.1.19",
37 | "cross-env": "^5.2.0",
38 | "css-loader": "1.0.0",
39 | "html-webpack-plugin": "3.2.0",
40 | "mini-css-extract-plugin": "0.4.2",
41 | "postcss": "^8.2.8",
42 | "postcss-custom-media": "^8.0.0",
43 | "postcss-custom-properties": "^11.0.0",
44 | "postcss-hexrgba": "^2.0.1",
45 | "postcss-import": "^14.0.0",
46 | "postcss-loader": "4.x",
47 | "postcss-mixins": "^7.0.3",
48 | "prettier": "^2.2.1",
49 | "style-loader": "0.23.0",
50 | "stylelint": "9.5.0",
51 | "stylelint-config-standard": "18.2.0",
52 | "stylelint-order": "1.0.0",
53 | "stylelint-webpack-plugin": "0.10.5",
54 | "terser-webpack-plugin": "^4.x",
55 | "ts-node": "7.0.1",
56 | "typescript": "3.0.3",
57 | "webpack": "4.17.2",
58 | "webpack-cli": "3.1.0",
59 | "webpack-dev-server": "3.1.8"
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/images/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/isellsoap/specificity-visualizer/470c5b8c806b03df932c3d0f93aee335b242eb35/src/images/favicon.ico
--------------------------------------------------------------------------------
/src/markup/index.html.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
115 | 🤩 It’s a pretty fun and nice visual experience and potentially changes the way how
116 | you look into and think about your stylesheets.
117 |
118 |
119 | 🔍 Hover over single data points to see the exact selector or zoom into areas of
120 | interest, e.g. you can look at only the selectors of the first half of the file or you
121 | can zoom into all selectors with the specificity of 0,2,1 across the
122 | entire file.
123 |
124 |
125 | 📊 To better distinguish different specificity categories the data points are using
126 | proper colors and forms. You can also click on a legend item to toggle its visibility,
127 | e.g. if you want to only see ID selectors.
128 |
129 |
130 | 📸️ Taking screenshots of the chart is great to track progress, e.g. you could save a
131 | snapshot of your stylesheet before and after a major refactoring to visualize the
132 | difference. Also, you could use it for presentations to effectively communicate to
133 | other developers and/or stakeholders.
134 |
135 |
136 | 📏 Specificities aren’t simply “added up” but rather treated as proper categories.
137 | After all, no amount of class selectors can overrule an ID selector.
138 | Also, selectors inside of @media, @supports and
139 | @document blocks are counted, selectors inside of
140 | @keyframes blocks aren’t.
141 |
142 |
143 |
How to read the chart
144 |
145 |
146 | The x-axis shows the physical location of selectors as they are written in the
147 | CSS. On the left side is the first one, on the right side the last one.
148 |
149 |
150 | The y-axis shows the specificity of selectors, beginning with the least specific one
151 | at the bottom and ending with the most specific one at the top.
152 |
153 |
154 |
What is considered a “good” or “bad” graph?
155 |
156 |
157 | First off, think of the chart more as a rough conceptual model and not as an exact
158 | tool.
159 |
160 |
161 | A spiky graph with an overall high specificity and high amount of noise can be
162 | considered as potentially “bad”.
163 |
164 |
165 | An upward-trending graph with overall low specificity and low amount of noise can be
166 | considered potentially “good”.
167 |
180 | Check out these resources if you want to dig deeper into how specificity graphs can help
181 | you getting an overview of big stylesheets and what the reasoning behind it is:
182 |
288 | Did you spot an error? Do you miss a feature? Please be sure to check out
289 | the list of existing issues
292 | before creating
293 | one of your own. Any feedback and help is appreciated.
296 |