This commit is contained in:
2023-05-26 08:39:21 +08:00
parent 8e3c329fce
commit 0f40bc7c43
10 changed files with 172 additions and 2 deletions

View File

@@ -0,0 +1,23 @@
import { Component, ComponentChild, createContext } from "preact";
export const GlobalCtx = createContext<State | null>(null);
type State = {
stylesheets: Set<string>;
};
type Props = { children: ComponentChild };
export default class GlobalContext extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { stylesheets: new Set() };
}
render() {
return (
<GlobalCtx.Provider value={this.state}>
{this.props.children}
</GlobalCtx.Provider>
);
}
}

36
components/Menu.tsx Normal file
View File

@@ -0,0 +1,36 @@
import { Head } from "$fresh/runtime.ts";
import { Component } from "preact";
import { ContextType } from "preact";
import TopAppBar from "preact-material-components/TopAppBar";
import StyleSheet from "./StyleSheet.tsx";
import { GlobalCtx } from "./GlobalContext.tsx";
export default class Menu extends Component {
static contextType = GlobalCtx;
declare context: ContextType<typeof GlobalCtx>;
render() {
return (
<div>
<Head>
<GlobalCtx.Provider value={this.context}>
<StyleSheet href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<StyleSheet href="preact-material-components/TopAppBar/style.css" />
</GlobalCtx.Provider>
</Head>
<TopAppBar onNav={() => {}}>
<TopAppBar.Row>
<TopAppBar.Section align-start>
<TopAppBar.Icon navigation>menu</TopAppBar.Icon>
<TopAppBar.Title>
EH Downloader
</TopAppBar.Title>
</TopAppBar.Section>
<TopAppBar.Section align-end>
<TopAppBar.Icon>more_vert</TopAppBar.Icon>
</TopAppBar.Section>
</TopAppBar.Row>
</TopAppBar>
</div>
);
}
}

21
components/StyleSheet.tsx Normal file
View File

@@ -0,0 +1,21 @@
import { asset } from "$fresh/runtime.ts";
import { Component, ContextType, RenderableProps } from "preact";
import { GlobalCtx } from "./GlobalContext.tsx";
export type StyleSheetType = {
href: string;
};
export default class StyleSheet extends Component<StyleSheetType, unknown> {
static contextType = GlobalCtx;
declare context: ContextType<typeof GlobalCtx>;
render() {
const href = this.props.href;
if (this.context) {
const sheets = this.context.stylesheets;
if (sheets.has(href)) return null;
sheets.add(href);
}
return <link rel="stylesheet" href={asset(this.props.href)} />;
}
}

View File

@@ -5,7 +5,8 @@
"test": "deno test --allow-read=./ --allow-net --allow-write=./ --allow-run=tasklist.exe --unstable",
"run": "deno run --allow-read=./ --allow-write=./ --allow-run=tasklist.exe --allow-env=DENO_DEPLOYMENT_ID --allow-net --unstable",
"compile": "deno compile --allow-read=./ --allow-write=./ --allow-run=tasklist.exe --allow-env=DENO_DEPLOYMENT_ID --allow-net --unstable",
"compile_full": "deno compile --allow-read --allow-write --allow-run=tasklist.exe --allow-env=DENO_DEPLOYMENT_ID --allow-net --unstable"
"compile_full": "deno compile --allow-read --allow-write --allow-run=tasklist.exe --allow-env=DENO_DEPLOYMENT_ID --allow-net --unstable",
"fetch": "deno run --allow-read=./ --allow-write=./ --allow-net fetch_static_files.ts"
},
"fmt": {
"indentWidth": 4,

27
deno.lock generated
View File

@@ -194,18 +194,45 @@
"https://deno.land/x/[email protected]/lib/z-worker-inline.js": "df83d91413a2e79f76924f39f26f59e6efbe8f5487d3a91b7e92b6d64236927c",
"https://deno.land/x/[email protected]/lib/zip-fs.js": "a733360302f5fbec9cc01543cb9fcfe7bae3f35a50d0006626ce42fe8183b63f",
"https://esm.sh/*[email protected]": "88ec8d8706b6a3f1e0fdad3862a2690dcd9b350d87bdc8e7bd0e27fbc0f7d29e",
"https://esm.sh/[email protected]/TopAppBar": "e418485020aecb866d9cc44216cd52c5ac1ff120bd1ad422b318428c274b3474",
"https://esm.sh/[email protected]": "ae382301328ab874e2c42bee76e261bb8d094673fe76ca7eb71917636d43d8ad",
"https://esm.sh/[email protected]/hooks": "1813f80c6d648f8137a62569e35972b0716f92539f192d6db66d45b7aafea43a",
"https://esm.sh/[email protected]/jsx-runtime": "0caf2b2eade93af59e89abc31816b6cb2829a9b8a82b958c0ebc1d8bec241e2a",
"https://esm.sh/stable/[email protected]/deno/hooks.js": "f25445c4f9fa6742119c41db4a85a2f75ee6ea941c506ae8ad3b1568c7692c61",
"https://esm.sh/stable/[email protected]/deno/jsx-runtime.js": "7c8e1b8f272996846cbac0837dcb71f6f8cfc82611b3f7819501d07c37383dc0",
"https://esm.sh/stable/[email protected]/deno/preact.mjs": "9b73545225d0ed274c89f39aee524a2857c81a73060e80c2c4bdc2a6de7bec26",
"https://esm.sh/stable/[email protected]/deno/preact.mjs": "f51b1a99f29fa9879d70dc283bb8f42ce9beef99aa93dd6ca969f297e101e964",
"https://esm.sh/[email protected]": "e6db0352eb940ca8cdbf129fe4520809916d002b8ccc2e2fc7f8551138f7a161",
"https://esm.sh/[email protected]/sheets": "3472c3c28394aa25c026ff81a393361e71aca014b3b8db5d6c67396e60f87cc9",
"https://esm.sh/v118/[email protected]/hooks/src/index.d.ts": "5c29febb624fc25d71cb0e125848c9b711e233337a08f7eacfade38fd4c14cc3",
"https://esm.sh/v118/[email protected]/jsx-runtime/src/index.d.ts": "e153460ed2b3fe2ad8b93696ecd48fbf73cd628b0b0ea6692b71804a3af69dfd",
"https://esm.sh/v118/[email protected]/src/index.d.ts": "65398710de6aa0a07412da79784e05e6e96763f51c7c91b77344d2d0af06385c",
"https://esm.sh/v118/[email protected]/src/jsx.d.ts": "fde41cfb4944bcc5005e653c989ef8f85deb1cbb5364a1726654993937cd08d0",
"https://esm.sh/v118/[email protected]/src/index.d.ts": "65398710de6aa0a07412da79784e05e6e96763f51c7c91b77344d2d0af06385c",
"https://esm.sh/v118/[email protected]/src/jsx.d.ts": "de467cd980f79a13bf3026146afed7173a3634e7d6415d349184663c67174c0c",
"https://esm.sh/v122/@babel/[email protected]/deno/helpers/classCallCheck.js": "678d4a1fc837f06947628e73a957e1f017fe30c77e8500008ec9a5977563c4f9",
"https://esm.sh/v122/@babel/[email protected]/deno/helpers/createClass.js": "4205e44f1238343af0a0e0ebc92cfb043382600f54c3e53aa4e6801c9bec7a44",
"https://esm.sh/v122/@babel/[email protected]/deno/helpers/get.js": "2021a8fa9d0d4880ece83c1d93266ac1d7414430f4f4671691a336ef3aa25dbe",
"https://esm.sh/v122/@babel/[email protected]/deno/helpers/getPrototypeOf.js": "41e694838de6926a04a013646f2b3915afa24a57a9301f3e226eadc78fa32e76",
"https://esm.sh/v122/@babel/[email protected]/deno/helpers/inherits.js": "09429b866edd8b9dd67dab992f9ad8865c19e15ffecde5ff632e4929755e2807",
"https://esm.sh/v122/@babel/[email protected]/deno/helpers/interopRequireDefault.js": "273ebefd452416883e9e517a620b46197b732a9ee384dfcb2ef33f731b7293d4",
"https://esm.sh/v122/@babel/[email protected]/deno/helpers/possibleConstructorReturn.js": "c48587b6a4194dac1f823e4706c67a286187cec9f29d35aac06df940443baa51",
"https://esm.sh/v122/@babel/[email protected]/deno/helpers/typeof.js": "ea8e5723c88f83ac7cfbb5728d38e20449f7387093b2825e6c8c81fdc50a7f32",
"https://esm.sh/v122/@material/[email protected]/deno/component.js": "031f373ae497c52e9b7050165e31dc6e708aebe2b2df027b25c897ce4b7cd43a",
"https://esm.sh/v122/@material/[email protected]/deno/foundation.js": "4edd0737b3601305ffe599556e98e4861542210744da83af19194c8c4f50c0e0",
"https://esm.sh/v122/@material/[email protected]/deno/adapter.js": "29b56c7005653c22ce0d167db65b802e14903e2ba67164824d0be6364309117f",
"https://esm.sh/v122/@material/[email protected]/deno/constants.js": "f8a80510d9c102aacc87c0fdcdd665118685d53f18948f7eabe275b2c85512a8",
"https://esm.sh/v122/@material/[email protected]/deno/foundation.js": "691312af51a78412d5bea70fee6d85cd3c2e6beb6e39a5ad878496d874b9633a",
"https://esm.sh/v122/@material/[email protected]/deno/index.js": "379c671f75219f71074e9d5fc1d790325d4ef469e0268d509147afaab67c6e8a",
"https://esm.sh/v122/@material/[email protected]/deno/ripple.mjs": "a915efddd4cf20bc2bbb187fc44655b1d9919d563be67053fa9b71b78cd05df5",
"https://esm.sh/v122/@material/[email protected]/deno/util.js": "4df787664fc517d4545bb7d502f85de3b34cfa613e34edd6b4630ea21e673cf2",
"https://esm.sh/v122/@material/[email protected]/deno/top-app-bar.mjs": "e7de012030af2ce0baac3cff6c96adc206f763cea07924a8c714fd4a83b6a18f",
"https://esm.sh/v122/[email protected]/deno/bind-decorator.mjs": "21a126bdebaca6e38120139d903c3485c4f57e15487646666e79c1b5c15d0e44",
"https://esm.sh/v122/[email protected]/Base/MaterialComponent.d.ts": "af619a28f2d2f76113e29e952308a2ce46577438f7ed40531458b880ff9a141f",
"https://esm.sh/v122/[email protected]/Base/types.d.ts": "4ec93636595145b9c5cdd628111f28e66148821c23c8ef6273f84bb84a6b8eb8",
"https://esm.sh/v122/[email protected]/TopAppBar/index.d.ts": "d921bd9336541339b0fff19e0769cea149b798bc172d261a7b7a1595f6b90266",
"https://esm.sh/v122/[email protected]/deno/Base/MaterialComponent.js": "7dca052dee2ab5010232055eac4a3159c8455e9b2857870525f7002cb50160bd",
"https://esm.sh/v122/[email protected]/deno/TopAppBar.js": "ab7ec4fa168d7867961b9fd818e10d138ffb075c20ea4b11f6d231318d897145",
"https://esm.sh/v124/[email protected]/index.d.ts": "4c68749a564a6facdf675416d75789ee5a557afda8960e0803cf6711fa569288",
"https://esm.sh/v124/[email protected]/X-ZS8q/deno/preact-render-to-string.mjs": "672116885c5e5072207c527a0ec663f5bc52774a0868ec487985109520382a55",
"https://esm.sh/v124/[email protected]/X-ZS8q/src/index.d.ts": "b1d73703252c8570fdf2952475805f5808ba3511fefbd93a3e7bd8406de7dcd0",

41
fetch_static_files.ts Normal file
View File

@@ -0,0 +1,41 @@
import { dirname, join } from "std/path/mod.ts";
import { sure_dir } from "./utils.ts";
const map = JSON.parse(await Deno.readTextFile("./import_map.json")).imports;
const LIST: string[] = ["preact-material-components/TopAppBar/style.css"];
function get_url(i: string) {
for (const v of Object.getOwnPropertyNames(map)) {
if (v.endsWith("/") && i.startsWith(v)) {
return i.replace(v, map[v]);
}
}
for (const v of Object.getOwnPropertyNames(map)) {
if (i.startsWith(v)) {
return i.replace(v, map[v]);
}
}
return i;
}
async function fetch_file(u: string | URL, p: string) {
await sure_dir(dirname(p));
const f = await Deno.open(p, { create: true, write: true, truncate: true });
try {
const r = await fetch(u);
if (!r.body) throw Error("No body.");
await r.body.pipeTo(f.writable);
} finally {
try {
f.close();
} catch (_) {
null;
}
}
}
for (const i of LIST) {
const u = get_url(i);
const p = join("./static", i);
await fetch_file(u, p);
}

View File

@@ -4,10 +4,12 @@
import config from "./deno.json" assert { type: "json" };
import * as $0 from "./routes/api/task/list.ts";
import * as $1 from "./routes/index.tsx";
const manifest = {
routes: {
"./routes/api/task/list.ts": $0,
"./routes/index.tsx": $1,
},
islands: {},
baseUrl: import.meta.url,

View File

@@ -12,6 +12,7 @@
"@preact/signals-core": "https://esm.sh/*@preact/[email protected]",
"twind": "https://esm.sh/[email protected]",
"twind/": "https://esm.sh/[email protected]/",
"$std/": "https://deno.land/[email protected]/"
"$std/": "https://deno.land/[email protected]/",
"preact-material-components/": "https://esm.sh/[email protected]/"
}
}

17
routes/index.tsx Normal file
View File

@@ -0,0 +1,17 @@
import { Head } from "$fresh/runtime.ts";
import GlobalContext from "../components/GlobalContext.tsx";
import Menu from "../components/Menu.tsx";
import StyleSheet from "../components/StyleSheet.tsx";
export default function Index() {
return (
<body>
<GlobalContext>
<Head>
<title>EH Downloader</title>
</Head>
<Menu></Menu>
</GlobalContext>
</body>
);
}

1
static/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
preact-material-components/