Initial commit
This commit is contained in:
37
node_modules/astro/dist/assets/fonts/providers/index.d.ts
generated
vendored
Normal file
37
node_modules/astro/dist/assets/fonts/providers/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import { type AdobeProviderOptions, type GoogleFamilyOptions, type GoogleiconsFamilyOptions } from 'unifont';
|
||||
import type { FontProvider } from '../types.js';
|
||||
import { type LocalFamilyOptions } from './local.js';
|
||||
/** [Adobe](https://fonts.adobe.com/) */
|
||||
declare function adobe(config: AdobeProviderOptions): FontProvider;
|
||||
/** [Bunny](https://fonts.bunny.net/) */
|
||||
declare function bunny(): FontProvider;
|
||||
/** [Fontshare](https://www.fontshare.com/) */
|
||||
declare function fontshare(): FontProvider;
|
||||
/** [Fontsource](https://fontsource.org/) */
|
||||
declare function fontsource(): FontProvider;
|
||||
/** [Google](https://fonts.google.com/) */
|
||||
declare function google(): FontProvider<GoogleFamilyOptions | undefined>;
|
||||
/** [Google Icons](https://fonts.google.com/icons) */
|
||||
declare function googleicons(): FontProvider<GoogleiconsFamilyOptions | undefined>;
|
||||
/** A provider that handles local files. */
|
||||
declare function local(): FontProvider<LocalFamilyOptions>;
|
||||
/**
|
||||
* Astro exports a few built-in providers:
|
||||
* - [Adobe](https://fonts.adobe.com/)
|
||||
* - [Bunny](https://fonts.bunny.net/)
|
||||
* - [Fontshare](https://www.fontshare.com/)
|
||||
* - [Fontsource](https://fontsource.org/)
|
||||
* - [Google](https://fonts.google.com/)
|
||||
* - [Google Icons](https://fonts.google.com/icons)
|
||||
* - Local
|
||||
*/
|
||||
export declare const fontProviders: {
|
||||
adobe: typeof adobe;
|
||||
bunny: typeof bunny;
|
||||
fontshare: typeof fontshare;
|
||||
fontsource: typeof fontsource;
|
||||
google: typeof google;
|
||||
googleicons: typeof googleicons;
|
||||
local: typeof local;
|
||||
};
|
||||
export {};
|
||||
119
node_modules/astro/dist/assets/fonts/providers/index.js
generated
vendored
Normal file
119
node_modules/astro/dist/assets/fonts/providers/index.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
import {
|
||||
providers
|
||||
} from "unifont";
|
||||
import { FontaceFontFileReader } from "../infra/fontace-font-file-reader.js";
|
||||
import { LocalFontProvider } from "./local.js";
|
||||
function adobe(config) {
|
||||
const provider = providers.adobe(config);
|
||||
let initializedProvider;
|
||||
return {
|
||||
name: provider._name,
|
||||
config,
|
||||
async init(context) {
|
||||
initializedProvider = await provider(context);
|
||||
},
|
||||
async resolveFont({ familyName, ...rest }) {
|
||||
return await initializedProvider?.resolveFont(familyName, rest);
|
||||
},
|
||||
async listFonts() {
|
||||
return await initializedProvider?.listFonts?.();
|
||||
}
|
||||
};
|
||||
}
|
||||
function bunny() {
|
||||
const provider = providers.bunny();
|
||||
let initializedProvider;
|
||||
return {
|
||||
name: provider._name,
|
||||
async init(context) {
|
||||
initializedProvider = await provider(context);
|
||||
},
|
||||
async resolveFont({ familyName, ...rest }) {
|
||||
return await initializedProvider?.resolveFont(familyName, rest);
|
||||
},
|
||||
async listFonts() {
|
||||
return await initializedProvider?.listFonts?.();
|
||||
}
|
||||
};
|
||||
}
|
||||
function fontshare() {
|
||||
const provider = providers.fontshare();
|
||||
let initializedProvider;
|
||||
return {
|
||||
name: provider._name,
|
||||
async init(context) {
|
||||
initializedProvider = await provider(context);
|
||||
},
|
||||
async resolveFont({ familyName, ...rest }) {
|
||||
return await initializedProvider?.resolveFont(familyName, rest);
|
||||
},
|
||||
async listFonts() {
|
||||
return await initializedProvider?.listFonts?.();
|
||||
}
|
||||
};
|
||||
}
|
||||
function fontsource() {
|
||||
const provider = providers.fontsource();
|
||||
let initializedProvider;
|
||||
return {
|
||||
name: provider._name,
|
||||
async init(context) {
|
||||
initializedProvider = await provider(context);
|
||||
},
|
||||
async resolveFont({ familyName, ...rest }) {
|
||||
return await initializedProvider?.resolveFont(familyName, rest);
|
||||
},
|
||||
async listFonts() {
|
||||
return await initializedProvider?.listFonts?.();
|
||||
}
|
||||
};
|
||||
}
|
||||
function google() {
|
||||
const provider = providers.google();
|
||||
let initializedProvider;
|
||||
return {
|
||||
name: provider._name,
|
||||
async init(context) {
|
||||
initializedProvider = await provider(context);
|
||||
},
|
||||
async resolveFont({ familyName, ...rest }) {
|
||||
return await initializedProvider?.resolveFont(familyName, rest);
|
||||
},
|
||||
async listFonts() {
|
||||
return await initializedProvider?.listFonts?.();
|
||||
}
|
||||
};
|
||||
}
|
||||
function googleicons() {
|
||||
const provider = providers.googleicons();
|
||||
let initializedProvider;
|
||||
return {
|
||||
name: provider._name,
|
||||
async init(context) {
|
||||
initializedProvider = await provider(context);
|
||||
},
|
||||
async resolveFont({ familyName, ...rest }) {
|
||||
return await initializedProvider?.resolveFont(familyName, rest);
|
||||
},
|
||||
async listFonts() {
|
||||
return await initializedProvider?.listFonts?.();
|
||||
}
|
||||
};
|
||||
}
|
||||
function local() {
|
||||
return new LocalFontProvider({
|
||||
fontFileReader: new FontaceFontFileReader()
|
||||
});
|
||||
}
|
||||
const fontProviders = {
|
||||
adobe,
|
||||
bunny,
|
||||
fontshare,
|
||||
fontsource,
|
||||
google,
|
||||
googleicons,
|
||||
local
|
||||
};
|
||||
export {
|
||||
fontProviders
|
||||
};
|
||||
44
node_modules/astro/dist/assets/fonts/providers/local.d.ts
generated
vendored
Normal file
44
node_modules/astro/dist/assets/fonts/providers/local.d.ts
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import type * as unifont from 'unifont';
|
||||
import type { FontFileReader } from '../definitions.js';
|
||||
import type { FamilyProperties, FontProvider, FontProviderInitContext, ResolveFontOptions, Style, Weight } from '../types.js';
|
||||
type RawSource = string | URL | {
|
||||
url: string | URL;
|
||||
tech?: string | undefined;
|
||||
};
|
||||
interface Variant extends FamilyProperties {
|
||||
/**
|
||||
* Font [sources](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src). It can be a path relative to the root, a package import or a URL. URLs are particularly useful if you inject local fonts through an integration.
|
||||
*/
|
||||
src: [RawSource, ...Array<RawSource>];
|
||||
/**
|
||||
* A [font weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight). If the associated font is a [variable font](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_fonts/Variable_fonts_guide), you can specify a range of weights:
|
||||
*
|
||||
* ```js
|
||||
* weight: "100 900"
|
||||
* ```
|
||||
*/
|
||||
weight?: Weight | undefined;
|
||||
/**
|
||||
* A [font style](https://developer.mozilla.org/en-US/docs/Web/CSS/font-style).
|
||||
*/
|
||||
style?: Style | undefined;
|
||||
}
|
||||
export interface LocalFamilyOptions {
|
||||
/**
|
||||
* Each variant represents a [`@font-face` declaration](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/).
|
||||
*/
|
||||
variants: [Variant, ...Array<Variant>];
|
||||
}
|
||||
export declare class LocalFontProvider implements FontProvider<LocalFamilyOptions> {
|
||||
#private;
|
||||
name: string;
|
||||
config?: Record<string, any> | undefined;
|
||||
constructor({ fontFileReader, }: {
|
||||
fontFileReader: FontFileReader;
|
||||
});
|
||||
init(context: Pick<FontProviderInitContext, 'root'>): void;
|
||||
resolveFont(options: ResolveFontOptions<LocalFamilyOptions>): {
|
||||
fonts: Array<unifont.FontFaceData>;
|
||||
};
|
||||
}
|
||||
export {};
|
||||
69
node_modules/astro/dist/assets/fonts/providers/local.js
generated
vendored
Normal file
69
node_modules/astro/dist/assets/fonts/providers/local.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
import { createRequire } from "node:module";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
class LocalFontProvider {
|
||||
name = "local";
|
||||
config;
|
||||
#fontFileReader;
|
||||
#root;
|
||||
constructor({
|
||||
fontFileReader
|
||||
}) {
|
||||
this.config = void 0;
|
||||
this.#fontFileReader = fontFileReader;
|
||||
this.#root = void 0;
|
||||
}
|
||||
init(context) {
|
||||
this.#root = context.root;
|
||||
}
|
||||
#resolveEntrypoint(root, entrypoint) {
|
||||
const require2 = createRequire(root);
|
||||
try {
|
||||
return pathToFileURL(require2.resolve(entrypoint));
|
||||
} catch {
|
||||
return new URL(entrypoint, root);
|
||||
}
|
||||
}
|
||||
#normalizeSource(value) {
|
||||
const isValue = typeof value === "string" || value instanceof URL;
|
||||
const url = (isValue ? value : value.url).toString();
|
||||
const tech = isValue ? void 0 : value.tech;
|
||||
return {
|
||||
url: fileURLToPath(this.#resolveEntrypoint(this.#root ?? new URL(import.meta.url), url)),
|
||||
tech
|
||||
};
|
||||
}
|
||||
resolveFont(options) {
|
||||
return {
|
||||
fonts: options.options?.variants.map((variant) => {
|
||||
const shouldInfer = variant.weight === void 0 || variant.style === void 0;
|
||||
const data = {
|
||||
// If it should be inferred, we don't want to set the value
|
||||
weight: variant.weight,
|
||||
style: variant.style,
|
||||
src: [],
|
||||
unicodeRange: variant.unicodeRange,
|
||||
display: variant.display,
|
||||
stretch: variant.stretch,
|
||||
featureSettings: variant.featureSettings,
|
||||
variationSettings: variant.variationSettings
|
||||
};
|
||||
data.src = variant.src.map((rawSource, index) => {
|
||||
const source = this.#normalizeSource(rawSource);
|
||||
if (shouldInfer && index === 0) {
|
||||
const result = this.#fontFileReader.extract({
|
||||
family: options.familyName,
|
||||
url: source.url
|
||||
});
|
||||
if (variant.weight === void 0) data.weight = result.weight;
|
||||
if (variant.style === void 0) data.style = result.style;
|
||||
}
|
||||
return source;
|
||||
});
|
||||
return data;
|
||||
}) ?? []
|
||||
};
|
||||
}
|
||||
}
|
||||
export {
|
||||
LocalFontProvider
|
||||
};
|
||||
Reference in New Issue
Block a user