snaha / diete.design

https://diete.design
MIT License
0 stars 0 forks source link

feat: colors page #250

Closed agazso closed 5 months ago

agazso commented 5 months ago

Adds a simple page which checks the CSS colors periodically and prints them in a code block, so that it can be copied in the CSS file.

vercel[bot] commented 5 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
diete-design ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2024 10:17am
agazso commented 5 months ago

Have you considered using MutationObserver?

Yes, but it looks to me that using that for computed styles can be quite complicated: https://stackoverflow.com/questions/20364687/mutationobserver-and-current-computed-css-styles

Should this page be linked from the menu?

I planned to link to here from the build page (#230) but we can add it to the menu as well. @david-gauquelin wdyt?

agazso commented 5 months ago

I think you may be right. Feel free to merge.

Just for the sake of how this could look like (thanks ChatGPT):

   onMount(() => {
        if (browser) {
            const observer = new MutationObserver((mutations) => {
                mutations.forEach((mutation) => {
                    if (mutation.type === 'attributes' && mutation.attributeName && mutation.target === document.documentElement) {
                        getColors()
                    }
                })
            })

            observer.observe(document.documentElement, {
                attributes: true,
                attributeFilter: [
                    'style'
                ]
            })

            // Initialize colors on mount
            getColors()

            onDestroy(() => {
                observer.disconnect()
            })
        }
    })

Based on this I managed to write the code with MutationObserver