Skip to content
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

Check this please~ #265

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,39 @@ function isKeyDownDebugMode(e: KeyboardEvent) {
return ok
}

// Ex:
//
// parseDurationMs("") // -> (error)
// parseDurationMs("0") // -> 0
// parseDurationMs("100") // -> 100
// parseDurationMs("100ms") // -> 100
// parseDurationMs("100s") // -> 100,000
// parseDurationMs("100m") // -> 6,000,000
//
function parseDurationMs(durStr : any){
let [numStr, unit] = durStr.trim().split(/(ms|s|m)$/);
if(!numStr){
throw new Error(`parseDurationMs: expected \`ms\`, \`s\`, or \`m\`; durStr=${durStr}`)
}

let n = +numStr;
switch (unit) {
case 'ms':
// No-op
break;
case 's':
n *= 1000;
break;
case 'm':
n *= 1000 * 60;
break;
default:
// No-op
break;
}
return n;
}

devjoylee marked this conversation as resolved.
Show resolved Hide resolved
class Duomo implements Runtime {
static localStorageKey = "duomo-theme-preference"

Expand Down Expand Up @@ -145,6 +178,8 @@ class Duomo implements Runtime {
return this.#darkMode
}
setDarkMode(mode: boolean) {
const durValue = getComputedStyle(document.documentElement).getPropertyValue('--default-theme-transition-duration');
devjoylee marked this conversation as resolved.
Show resolved Hide resolved

if(this.#shouldNoOpDarkMode){
Copy link
Owner

Choose a reason for hiding this comment

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

Make sure you’re using Prettier if you’re not already. I would expect this to be if (this.#shouldNoOpDarkMode) { (you have no spaces right now).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I installed the Prettier, but It's still same. Probably prettier setting problem on my vscode..

return
}
Expand Down Expand Up @@ -172,7 +207,7 @@ class Duomo implements Runtime {
setTimeout(() => {
this.#html!.removeAttribute("data-theme-effect")
this.#shouldNoOpDarkMode = false
}, 300)
}, parseDurationMs(durValue))
devjoylee marked this conversation as resolved.
Show resolved Hide resolved
}, 25)
}
}
Expand Down