Web Fonts preset
শুধুমাত্র font names প্রদান করে Google Fonts, FontShare থেকে web fonts ব্যবহার করুন।
সমস্ত সমর্থিত providers দেখুন।
ইনস্টলেশন
pnpm add -D @unocss/preset-web-fontsyarn add -D @unocss/preset-web-fontsnpm install -D @unocss/preset-web-fontsbun add -D @unocss/preset-web-fontsimport presetWebFonts from '@unocss/preset-web-fonts'
import presetWind3 from '@unocss/preset-wind3'
import { defineConfig } from 'unocss'
export default defineConfig({
presets: [
presetWind3(),
presetWebFonts({ /* options */ }),
],
})TIP
এই preset unocss প্যাকেজে অন্তর্ভুক্ত, আপনি সেখান থেকেও import করতে পারেন:
import { presetWebFonts } from 'unocss'Providers
বর্তমানে সমর্থিত Providers:
none- কিছু করবে না, font-কে system font হিসাবে treat করবেgoogle- Google Fontsbunny- Privacy-Friendly Google Fontsfontshare- Quality Font Service by ITF
INFO
আরও providers যোগ করতে PR স্বাগত। 🙌
Custom fetch function
Font source fetch করতে আপনার নিজের function ব্যবহার করুন।
import presetWebFonts from '@unocss/preset-web-fonts'
import presetWind3 from '@unocss/preset-wind3'
import axios from 'axios'
import ProxyAgent from 'proxy-agent'
import { defineConfig } from 'unocss'
export default defineConfig({
presets: [
presetWind3(),
presetWebFonts({
// use axios with an https proxy
customFetch: (url: string) => axios.get(url, { httpsAgent: new ProxyAgent('https://localhost:7890') }).then(it => it.data),
provider: 'google',
fonts: {
sans: 'Roboto',
mono: ['Fira Code', 'Fira Mono:400,700'],
},
}),
],
})অপশন
provider
- Type:
WebFontsProviders - Default:
google
Web fonts-এর provider service।
type WebFontsProviders = 'google' | 'bunny' | 'fontshare' | 'none'fonts
- Type:
Record<string, WebFontMeta | string | (WebFontMeta | string)[]>
Fonts। আরও বিস্তারিত জানার জন্য example দেখুন।
interface WebFontMeta {
name: string
weights?: (string | number)[]
italic?: boolean
/**
* Override the provider
* @default <matches root config>
*/
provider?: WebFontsProviders
}extendTheme
- Type:
boolean - Default:
true
Theme object extend করুন।
themeKey
- Type:
string - Default:
fontFamily
Theme object-এর জন্য key।
inlineImports
- Type:
boolean - Default:
true
CSS @import() inline করুন।
customFetch
- Type:
(url: string) => Promise<string> - Default:
undefined
Font source fetch করতে আপনার নিজের function ব্যবহার করুন। Custom fetch function দেখুন।
উদাহরণ
presetWebFonts({
provider: 'google', // default provider
fonts: {
// these will extend the default theme
sans: 'Roboto',
mono: ['Fira Code', 'Fira Mono:400,700'],
// custom ones
lobster: 'Lobster',
lato: [
{
name: 'Lato',
weights: ['400', '700'],
italic: true,
},
{
name: 'sans-serif',
provider: 'none',
},
],
},
})নিম্নলিখিত CSS স্বয়ংক্রিয়ভাবে generate হবে:
@import url('https://fonts.googleapis.com/css2?family=Roboto&family=Fira+Code&family=Fira+Mono:wght@400;700&family=Lobster&family=Lato:ital,wght@0,400;0,700;1,400;1,700&display=swap');
/* layer: default */
.font-lato {
font-family: "Lato", sans-serif;
}
.font-lobster {
font-family: "Lobster";
}
.font-mono {
font-family: "Fira Code", "Fira Mono", ui-monospace, SFMono-Regular, Menlo,
Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
.font-sans {
font-family: "Roboto", ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans",
sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
"Noto Color Emoji";
}Fonts স্থানীয়ভাবে সার্ভ করা
ডিফল্টভাবে preset fonts provider-এর CDN থেকে fetch করবে। আপনি যদি fonts স্থানীয়ভাবে সার্ভ করতে চান, আপনি fonts download করে @unocss/preset-web-fonts/local থেকে processor ব্যবহার করে আপনার নিজের server থেকে সার্ভ করতে পারেন।
import presetWebFonts from '@unocss/preset-web-fonts'
import { createLocalFontProcessor } from '@unocss/preset-web-fonts/local'
import { defineConfig } from 'unocss'
export default defineConfig({
presets: [
presetWebFonts({
provider: 'none',
fonts: {
sans: 'Roboto',
mono: 'Fira Code',
},
// This will download the fonts and serve them locally
processors: createLocalFontProcessor({
// Directory to cache the fonts
cacheDir: 'node_modules/.cache/unocss/fonts',
// Directory to save the fonts assets
fontAssetsDir: 'public/assets/fonts',
// Base URL to serve the fonts from the client
fontServeBaseUrl: '/assets/fonts'
})
}),
],
})এটি fonts assets public/assets/fonts-এ download করবে এবং client-এ /assets/fonts থেকে সার্ভ করবে। এটি করার সময়, অনুগ্রহ করে নিশ্চিত করুন যে fonts-এর license আপনাকে redistribute করার অনুমতি দেয়, tool কোনো legal issues-এর জন্য দায়ী নয়।
INFO
এই feature Node.js specific এবং browser-এ কাজ করবে না।