All Projects → oleggromov → sauron-style

oleggromov / sauron-style

Licence: MIT license
One library to observe them all (style changes) 👁

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to sauron-style

Layouts
Grab-and-go layouts for React
Stars: ✭ 202 (+445.95%)
Mutual labels:  styles
ColorRatingBar
change color of star in rating bar
Stars: ✭ 23 (-37.84%)
Mutual labels:  change
CustomWebRadioButton
An example of a make radio-button design on the web.
Stars: ✭ 15 (-59.46%)
Mutual labels:  styles
Ocean-blue-GDM3
Ocean Blue GDM3 theme for ubuntu
Stars: ✭ 27 (-27.03%)
Mutual labels:  change
react-trigger-change
Trigger React's synthetic change events on input, textarea and select elements
Stars: ✭ 63 (+70.27%)
Mutual labels:  change
sudohulk
try privilege escalation changing sudo command
Stars: ✭ 114 (+208.11%)
Mutual labels:  change
Preset
A simple CSS preset for 2020
Stars: ✭ 146 (+294.59%)
Mutual labels:  styles
react-native-use-styles
A classy approach to manage your react native styles.
Stars: ✭ 66 (+78.38%)
Mutual labels:  styles
gitbook-plugin-autotheme
GitBook自动换肤插件
Stars: ✭ 13 (-64.86%)
Mutual labels:  change
CDDN-Change-DNS-Dynamically-with-your-Network
This script allows you to have the best configuration of your DNS when switching from one Wi-Fi to another.
Stars: ✭ 22 (-40.54%)
Mutual labels:  change
diffido
Watch web pages for changes
Stars: ✭ 19 (-48.65%)
Mutual labels:  change
silly-android
Android plugins for Java, making core Android APIs easy to use
Stars: ✭ 40 (+8.11%)
Mutual labels:  change
LycricsTextView
No description or website provided.
Stars: ✭ 14 (-62.16%)
Mutual labels:  change
gochanges
**[ARCHIVED]** website changes tracker 🔍
Stars: ✭ 12 (-67.57%)
Mutual labels:  change
use-color-change
📈📉React hook for flashing a text when a value becomes higher or lower
Stars: ✭ 32 (-13.51%)
Mutual labels:  change
Dropcss
An exceptionally fast, thorough and tiny unused-CSS cleaner
Stars: ✭ 2,102 (+5581.08%)
Mutual labels:  styles
Converto
Installing Kali linux on Vps Server
Stars: ✭ 100 (+170.27%)
Mutual labels:  change
white-cursor
Provides a white I-bar cursor in the Atom editor for use with dark backgrounds
Stars: ✭ 13 (-64.86%)
Mutual labels:  styles
prop-styles
Utility to create flexible React components which accept props to enable/disable certain styles.
Stars: ✭ 31 (-16.22%)
Mutual labels:  styles
Android Skin Support
Android-skin-support is an easy dynamic skin framework to use for Android, Only one line of code to integrate it. Android 换肤框架, 极低的学习成本, 极好的用户体验. "一行"代码就可以实现换肤, 你值得拥有!!!
Stars: ✭ 5,706 (+15321.62%)
Mutual labels:  change

SauronStyle 👁

JavaScript library to observe style changes on any DOM element. For an observed element, on every computed style change returns a difference object.

Works on top of window.MutationObserver and window.getComputedStyle so if your target browsers do not support these global interfaces, unfortunately, it won't help you.

⚠️ Current implementation is SLOW! Don't try to use it on many elements. What is many exactly? Depends on your clients' performance, but likely it's something over 50-100 elements at once on a usual modern laptop.

Quick Browser Usage Guide

  1. Clone the repository
  2. Build the library: yarn build:prod
  3. Copy build/sauron-style.min.js to somewhere in your project
  4. Connect it with to your page: <script src="sauron-style.min.js"></script>

And observe an element you're interested in:

const sauronStyle = new SauronStyle(document.querySelector('#item'))
sauronStyle.subscribe(diff => {
  console.log(diff)
})

Assumptions and How It Works

SauronStyle watches element attribute changes, such as class and style. Apparently, any change of those might cause computed CSS changes as well. In the same way changes to parent elements can affect the styling of an observable element. Consider, for instance, class orange applied to a parent when a stylesheet has the following line:

.orange .watchedElement {
  height: 250px;
}

Without observing parent element class attribute changes we won't be able to spot such a change on .watchedElement.

Another way of affecting element representation is via external stylesheets. They could be added by inserting style or link elements into a document or removing any of them. This is also watched by SauronStyle.

Since getComputedStyle method is used, reported changes are always sent in resolved form. For example, setting transform: rotate(-2deg) for an element will cause the following difference to be reported:

{
  transform: {
    cur: "matrix(0.999391, -0.0348995, 0.0348995, 0.999391, 0, 0)",
    prev: "none"
  }
}

Another drawback of using computed style watching is that not only longhand CSS props are updated but also shorthand ones, and vice versa. For example, setting background: red will cause the following difference:

{
  background: {
    cur: "rgb(255, 255, 0) none repeat scroll 0% 0% / auto padding-box border-box",
    prev: "rgba(0, 0, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box"
  },
  backgroundColor: {
    cur: "rgb(255, 255, 0)",
    prev: "rgba(0, 0, 0, 0)"
  }
}

Written above means you should use the difference with care.

⚠️ Low Performance

Currently, performance is one of the strong considerations about project viability. Due to getComputedStyle usage, the library is inherently slow - on my MacBook 2013, it takes about 1-5ms to get a copy of computed styles for 1 element.

Be extremely careful when adding listeners to more than 50-100 elements!

If the library becomes used widely, I'll possibly think about implementing smarter style difference algorithms but the worst-case scenario performance will always gravitate towards asymptote, i.e. be slow.

ToDo

  • not covered cases:
    • handle transitions on parents with account for browser differences
    • pseudo-classes like :hover and :focus
  • split library into modules
  • lint
  • test it:
    • write unit tests
    • add integration tests
    • performance tests
  • set up build:
    • make it work for browsers
    • CommonJS
    • import
  • add CI (try travis?)
    • add deploy to some (free) CDN
  • promo
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].