-
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.
#1 `virtual:astro-svgs` 模块支持
- Loading branch information
Showing
1 changed file
with
18 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { InjectedType } from "astro"; | ||
import { type SVGsOptions, name } from "."; | ||
import { compose } from "./core"; | ||
|
||
export async function virtual(opts: SVGsOptions): Promise<InjectedType> { | ||
let filename = "types.d.ts"; | ||
|
||
const { symbolIds } = await compose(opts); | ||
const SymbolId = | ||
symbolIds.length > 0 | ||
? symbolIds.map((id) => `\t| '${id}'`).join("\n\t") | ||
: "\t| null"; // Fallback for empty symbolIds | ||
|
||
const content = | ||
`declare module 'virtual:${name}' {\n\texport type SymbolId =\n\t${SymbolId};\n\texport const file: string;\n}`.trim(); | ||
|
||
return { filename, content }; | ||
} |