Skip to content

chore: move setInitialMode to own module and import with raw#125

Open
paoloricciuti wants to merge 2 commits intosvecosystem:mainfrom
paoloricciuti:fix/set-initial-mode
Open

chore: move setInitialMode to own module and import with raw#125
paoloricciuti wants to merge 2 commits intosvecosystem:mainfrom
paoloricciuti:fix/set-initial-mode

Conversation

@paoloricciuti
Copy link

This is the change we talked about @huntabyte ...dunno if you actually like it (and i didn't check it actually works more than running the tests but maybe we should test it out there for completeness).

@changeset-bot
Copy link

changeset-bot bot commented Apr 18, 2025

🦋 Changeset detected

Latest commit: 947727b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mode-watcher Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Apr 18, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
mode-watcher ✅ Ready (View Log) Visit Preview 947727b

@huntabyte
Copy link
Member

Thanks man! Will give this a check!

@@ -0,0 +1 @@
function setInitialMode(a){const{defaultMode:b="system",themeColors:c,darkClassNames:d=["dark"],lightClassNames:e=[],defaultTheme:f="",modeStorageKey:g="mode-watcher-mode",themeStorageKey:h="mode-watcher-theme"}=a||{};const k=document.documentElement,l=localStorage.getItem(g)??b,m=localStorage.getItem(h)??f,n=l=="light"||(l=="system"&&matchMedia("(prefers-color-scheme: light)").matches),p=(q,r)=>q.length&&k.classList[r](...q);if(n){p(d,"remove");p(e,"add")}else{p(e,"remove");p(d,"add")}k.style.colorScheme=n?"light":"dark";let s;if(c&&(s=document.querySelector('meta[name="theme-color"]')))s.setAttribute("content",n?c.light:c.dark);if(m){k.setAttribute("data-theme",m);localStorage.setItem(h,m)}localStorage.setItem(g,l)} No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this hard to debug. Would it be better to keep the source code and run it through a minifier.

pnpm esbuild src/lib/set-initial-mode.ts --minify --format=esm --outfile=src/lib/set-initial-mode.min.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants