-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSS Panel #6
Comments
That is absolutely possible. All we need to do is to write a CSS emitter. It's a script that runs on the page and fetches information about the CSS styles. Then construct an object (state) and send it to Kuker via It's in this CodePen https://codepen.io/krasimir/pen/paErGV?editors=0010 The tricky parts in such emitter are:
Here is some code: function sendMessage(css) {
window.postMessage({
kuker: true,
type: 'CSS_UPDATE',
time: (new Date()).getTime(),
state: css
}, '*');
}
function extractCSS() {
var css = {};
for (let i = 0; i < document.styleSheets.length; i++) {
var sheet = document.styleSheets[i];
var rules = ('cssRules' in sheet) ? sheet.cssRules : sheet.rules;
for (let j = 0; j<rules.length; j++) {
let rule = rules[j];
css[rule.selectorText] = Object.keys(rule.style).reduce((result, prop) => {
if (rule.style[prop] !== '' && prop.toString().length >= 3) {
result[prop] = rule.style[prop];
}
return result;
}, {});
}
}
return css;
}
const cssPlaceholder = document.querySelector('#js-driven-styles');
document.querySelector('button').addEventListener('click', function () {
cssPlaceholder.innerHTML = `button { background: ${ getRandomColor() }; font-family: ${ getRandomFont() } }`;
sendMessage(extractCSS());
});
sendMessage(extractCSS()); |
Nice! And its super simple to do with this
|
BTW, absurd.js site is down http://absurdjs.com/pages/installation/ |
I'm not quite sold on this idea. That is because Kuker is made to display events + state mutations. Should be agnostic what data those events hold and what the state tree represents.
That's true. That is why the emitter should implement some kind of throttling logic like React emitter does. Kuker itself works in
You'll get a new event on the left side panel and still the same state on the right side. Kuker tho gives you a hint which of the events are mutating the state.
That is nice but do those libraries has a hook where you may plug the
Yep, it is possible and Kuker uses the same code (in a little bit hacky way) in the React emitter. Fetching the React component tree in real time requires lots of knowledge for how React works. I myself tried to do that alone and I failed. That's why Kuker uses code from React's devtools.
Yep, I decided to stop paying the domain and hosting and moved the site here http://absurdjs.krasimirtsonev.com/ Looking at the GA stats it had like ~10 hits per month so not really worth the money. |
@krasimir Would you consider adding a panel that shows CSS devtools, more specifically CSS-in-JS devtools, I would be happy to write an adapter for
freestyler
.The text was updated successfully, but these errors were encountered: