-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): finishing touches for V0 (#31)
- Loading branch information
1 parent
0583939
commit b3bf383
Showing
253 changed files
with
3,129 additions
and
15,757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v3 | ||
|
||
- uses: oven-sh/setup-bun@v2 | ||
with: | ||
bun-version: latest | ||
|
||
- name: Install Dependencies | ||
run: bun install | ||
|
||
- name: Create Release PR or Publish to NPM | ||
id: changesets | ||
uses: changesets/action@v1 | ||
with: | ||
publish: bun run release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Run tests | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
build: | ||
name: "Build & test packages" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup bun | ||
uses: oven-sh/setup-bun@v2 | ||
with: | ||
bun-version: latest | ||
- name: Install dependencies | ||
run: bun install --frozen-lockfile | ||
- name: Build packages | ||
run: bun run build --filter='!www' | ||
- name: Running tests | ||
run: bun test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[test] | ||
preload = "./happydom.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
import type { Nullable } from "@/lib/types/nullable.js"; | ||
|
||
interface BatteryState { | ||
level: Nullable<number>; | ||
charging: Nullable<boolean>; | ||
chargingTime: Nullable<number>; | ||
dischargingTime: Nullable<number>; | ||
} | ||
|
||
interface BatteryManager extends Readonly<BatteryState>, EventTarget { | ||
onchargingchange: () => void; | ||
onchargingtimechange: () => void; | ||
ondischargingtimechange: () => void; | ||
onlevelchange: () => void; | ||
} | ||
|
||
interface NavigatorWithPossibleBattery extends Navigator { | ||
getBattery?: () => Promise<BatteryManager>; | ||
} | ||
|
||
type UseBatteryState = | ||
| { isSupported: false } // Battery API is not supported | ||
| { isSupported: true; loading: true } // battery API supported but not fetched yet | ||
| (BatteryState & { isSupported: true; loading: false }); // battery API supported and fetched | ||
|
||
const nav: NavigatorWithPossibleBattery | undefined = | ||
typeof navigator !== "undefined" ? navigator : undefined; | ||
|
||
const isBatteryApiSupported = nav && typeof nav.getBattery === "function"; | ||
|
||
/** | ||
* Returns the device's current battery state if available via the Navigator API. | ||
*/ | ||
function useBattery(): UseBatteryState { | ||
const [state, setState] = useState<UseBatteryState>({ | ||
isSupported: true, | ||
loading: true, | ||
}); | ||
|
||
useEffect(() => { | ||
if (!nav?.getBattery) { | ||
setState((s) => ({ ...s, isSupported: false, loading: false })); | ||
return; | ||
} | ||
|
||
let battery: BatteryManager | null = null; | ||
|
||
const handleChange = () => { | ||
if (!battery) return; | ||
|
||
const { level, charging, chargingTime, dischargingTime } = battery; | ||
|
||
setState({ | ||
isSupported: true, | ||
loading: false, | ||
level, | ||
charging, | ||
chargingTime, | ||
dischargingTime, | ||
}); | ||
}; | ||
|
||
nav.getBattery().then((b) => { | ||
battery = b; | ||
handleChange(); | ||
|
||
b.addEventListener("levelchange", handleChange); | ||
b.addEventListener("chargingchange", handleChange); | ||
b.addEventListener("chargingtimechange", handleChange); | ||
b.addEventListener("dischargingtimechange", handleChange); | ||
}); | ||
|
||
return () => { | ||
if (battery) { | ||
battery.removeEventListener("levelchange", handleChange); | ||
battery.removeEventListener("chargingchange", handleChange); | ||
battery.removeEventListener("chargingtimechange", handleChange); | ||
battery.removeEventListener("dischargingtimechange", handleChange); | ||
} | ||
}; | ||
}, []); | ||
|
||
return state; | ||
} | ||
|
||
const useBattery_ = isBatteryApiSupported | ||
? useBattery | ||
: (): UseBatteryState => ({ isSupported: false }); | ||
|
||
export { useBattery_ as useBattery }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Transforms a type into a nullable type. | ||
* | ||
* @example | ||
* type A = Nullable<string> // string | null | ||
*/ | ||
export type Nullable<T> = T | null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { GlobalRegistrator } from "@happy-dom/global-registrator"; | ||
|
||
GlobalRegistrator.register(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,15 @@ | |
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"release": "turbo run build && changesets publish", | ||
"build": "turbo run build", | ||
"dev": "turbo run dev", | ||
"clean": "rimraf -g packages/**/dist www/**/.vercel packages/**/.turbo www/**/.turbo www/**/.astro", | ||
"preview": "turbo run preview", | ||
"www": "pnpm --filter www run", | ||
"cli": "pnpm --filter cli run", | ||
"common": "pnpm --filter common run" | ||
"check": "turbo run check", | ||
"www": "bun --filter www run", | ||
"cli": "bun --filter cli run", | ||
"common": "bun --filter common run" | ||
}, | ||
"workspaces": [ | ||
"packages/*", | ||
|
@@ -26,7 +29,7 @@ | |
"turbo": "^2.1.1", | ||
"typescript": "^5.5.4" | ||
}, | ||
"packageManager": "[email protected]+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1", | ||
"packageManager": "[email protected]", | ||
"license": "MIT", | ||
"dependencies": { | ||
"eta": "^3.5.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.