@kiiimatz/fontrum 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +49 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var c={woff2:"woff2",woff:"woff",ttf:"truetype",otf:"opentype",eot:"embedded-opentype",svg:"svg",svgz:"svg"};function y(o){let n=o.split("?")[0].split(".").pop()?.toLowerCase()??"";return c[n]??n}function g(o){return o.map(n=>`url('${n}') format('${y(n)}')`).join(`,
|
|
2
|
+
`)}function u(o){return `<style>${o.map(t=>{let s=t.class,r=Array.isArray(t.font)?t.font:[t.font],e=t.weight??"normal",i=t.style??"normal",a=t.display??"swap",l=t.fallback??"sans-serif",f=["@font-face{",`font-family:'${s}';`,`src:${g(r)};`,`font-weight:${e};`,`font-style:${i};`,`font-display:${a};`,"}"].join(""),p=`.${s}{font-family:'${s}',${l};}`;return `${f}${p}`}).join("")}</style>`}var $=u;exports.default=$;exports.fontrum=u;//# sourceMappingURL=index.cjs.map
|
|
3
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["FORMAT_MAP","getFormat","path","ext","buildSrc","fonts","f","fontrum","cfg","family","sources","weight","style","display","fallback","face","cls","index_default"],"mappings":"sEAyBA,IAAMA,CAAAA,CAAqC,CACzC,KAAA,CAAO,OAAA,CACP,IAAA,CAAM,MAAA,CACN,GAAA,CAAK,UAAA,CACL,GAAA,CAAK,UAAA,CACL,GAAA,CAAK,mBAAA,CACL,GAAA,CAAK,KAAA,CACL,IAAA,CAAM,KACR,CAAA,CAEA,SAASC,CAAAA,CAA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AAA,EAAKK,CAAQ,CAAA,EAAA,CAAA,CAE1D,OAAO,GAAGC,CAAI,CAAA,EAAGC,CAAG,CAAA,CACtB,CAAC,EAEsB,IAAA,CAAK,EAAE,CAAC,CAAA,QAAA,CACjC,KAEOC,CAAAA,CAAQV","file":"index.cjs","sourcesContent":["export type FontDisplay = \"auto\" | \"block\" | \"swap\" | \"fallback\" | \"optional\";\n\nexport interface FontConfig {\n /** CSS class name to apply this font (e.g. \"inter\") */\n class: string;\n /**\n * Path(s) to the font file(s). Supports ttf, otf, woff, woff2, eot, svg.\n * Paths are relative to your public directory (e.g. \"/fonts/inter.woff2\").\n * Pass an array to provide multiple sources for the same font.\n */\n font: string | string[];\n /** Font weight. Defaults to \"normal\". */\n weight?: string | number;\n /** Font style. Defaults to \"normal\". */\n style?: string;\n /**\n * Controls how the font is displayed while loading.\n * \"swap\" (default) shows fallback font immediately then swaps — best for\n * most use cases and avoids invisible text during load.\n */\n display?: FontDisplay;\n /** Fallback font families appended after the custom font. Defaults to \"sans-serif\". */\n fallback?: string;\n}\n\nconst FORMAT_MAP: Record<string, string> = {\n woff2: \"woff2\",\n woff: \"woff\",\n ttf: \"truetype\",\n otf: \"opentype\",\n eot: \"embedded-opentype\",\n svg: \"svg\",\n svgz: \"svg\",\n};\n\nfunction getFormat(path: string): string {\n const ext = path.split(\"?\")[0].split(\".\").pop()?.toLowerCase() ?? \"\";\n return FORMAT_MAP[ext] ?? ext;\n}\n\nfunction buildSrc(fonts: string[]): string {\n return fonts\n .map((f) => `url('${f}') format('${getFormat(f)}')`)\n .join(\",\\n \");\n}\n\n/**\n * Generate CSS for the given font configurations.\n *\n * Returns a `<style>` tag string ready to be injected via `{@html}` in a\n * `<svelte:head>` block. Works on both server (SSR/SSG) and client.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import fontrum from \"@kiiimatz/fontrum\";\n * const styles = fontrum([\n * { class: \"inter\", font: \"/fonts/inter.woff2\" },\n * { class: \"mono\", font: [\"/fonts/mono.woff2\", \"/fonts/mono.ttf\"] },\n * ]);\n * </script>\n *\n * <svelte:head>\n * {@html styles}\n * </svelte:head>\n * ```\n */\nexport function fontrum(fonts: FontConfig[]): string {\n const rules = fonts.map((cfg) => {\n const family = cfg.class;\n const sources = Array.isArray(cfg.font) ? cfg.font : [cfg.font];\n const weight = cfg.weight ?? \"normal\";\n const style = cfg.style ?? \"normal\";\n const display = cfg.display ?? \"swap\";\n const fallback = cfg.fallback ?? \"sans-serif\";\n\n const face = [\n `@font-face{`,\n `font-family:'${family}';`,\n `src:${buildSrc(sources)};`,\n `font-weight:${weight};`,\n `font-style:${style};`,\n `font-display:${display};`,\n `}`,\n ].join(\"\");\n\n const cls = `.${family}{font-family:'${family}',${fallback};}`;\n\n return `${face}${cls}`;\n });\n\n return `<style>${rules.join(\"\")}</style>`;\n}\n\nexport default fontrum;\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
type FontDisplay = "auto" | "block" | "swap" | "fallback" | "optional";
|
|
2
|
+
interface FontConfig {
|
|
3
|
+
/** CSS class name to apply this font (e.g. "inter") */
|
|
4
|
+
class: string;
|
|
5
|
+
/**
|
|
6
|
+
* Path(s) to the font file(s). Supports ttf, otf, woff, woff2, eot, svg.
|
|
7
|
+
* Paths are relative to your public directory (e.g. "/fonts/inter.woff2").
|
|
8
|
+
* Pass an array to provide multiple sources for the same font.
|
|
9
|
+
*/
|
|
10
|
+
font: string | string[];
|
|
11
|
+
/** Font weight. Defaults to "normal". */
|
|
12
|
+
weight?: string | number;
|
|
13
|
+
/** Font style. Defaults to "normal". */
|
|
14
|
+
style?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Controls how the font is displayed while loading.
|
|
17
|
+
* "swap" (default) shows fallback font immediately then swaps — best for
|
|
18
|
+
* most use cases and avoids invisible text during load.
|
|
19
|
+
*/
|
|
20
|
+
display?: FontDisplay;
|
|
21
|
+
/** Fallback font families appended after the custom font. Defaults to "sans-serif". */
|
|
22
|
+
fallback?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Generate CSS for the given font configurations.
|
|
26
|
+
*
|
|
27
|
+
* Returns a `<style>` tag string ready to be injected via `{@html}` in a
|
|
28
|
+
* `<svelte:head>` block. Works on both server (SSR/SSG) and client.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```svelte
|
|
32
|
+
* <script lang="ts">
|
|
33
|
+
* import fontrum from "@kiiimatz/fontrum";
|
|
34
|
+
* const styles = fontrum([
|
|
35
|
+
* { class: "inter", font: "/fonts/inter.woff2" },
|
|
36
|
+
* { class: "mono", font: ["/fonts/mono.woff2", "/fonts/mono.ttf"] },
|
|
37
|
+
* ]);
|
|
38
|
+
* </script>
|
|
39
|
+
*
|
|
40
|
+
* <svelte:head>
|
|
41
|
+
* {@html styles}
|
|
42
|
+
* </svelte:head>
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare function fontrum(fonts: FontConfig[]): string;
|
|
46
|
+
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
export = fontrum;
|
|
49
|
+
export { type FontConfig, type FontDisplay, fontrum };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
type FontDisplay = "auto" | "block" | "swap" | "fallback" | "optional";
|
|
2
|
+
interface FontConfig {
|
|
3
|
+
/** CSS class name to apply this font (e.g. "inter") */
|
|
4
|
+
class: string;
|
|
5
|
+
/**
|
|
6
|
+
* Path(s) to the font file(s). Supports ttf, otf, woff, woff2, eot, svg.
|
|
7
|
+
* Paths are relative to your public directory (e.g. "/fonts/inter.woff2").
|
|
8
|
+
* Pass an array to provide multiple sources for the same font.
|
|
9
|
+
*/
|
|
10
|
+
font: string | string[];
|
|
11
|
+
/** Font weight. Defaults to "normal". */
|
|
12
|
+
weight?: string | number;
|
|
13
|
+
/** Font style. Defaults to "normal". */
|
|
14
|
+
style?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Controls how the font is displayed while loading.
|
|
17
|
+
* "swap" (default) shows fallback font immediately then swaps — best for
|
|
18
|
+
* most use cases and avoids invisible text during load.
|
|
19
|
+
*/
|
|
20
|
+
display?: FontDisplay;
|
|
21
|
+
/** Fallback font families appended after the custom font. Defaults to "sans-serif". */
|
|
22
|
+
fallback?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Generate CSS for the given font configurations.
|
|
26
|
+
*
|
|
27
|
+
* Returns a `<style>` tag string ready to be injected via `{@html}` in a
|
|
28
|
+
* `<svelte:head>` block. Works on both server (SSR/SSG) and client.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```svelte
|
|
32
|
+
* <script lang="ts">
|
|
33
|
+
* import fontrum from "@kiiimatz/fontrum";
|
|
34
|
+
* const styles = fontrum([
|
|
35
|
+
* { class: "inter", font: "/fonts/inter.woff2" },
|
|
36
|
+
* { class: "mono", font: ["/fonts/mono.woff2", "/fonts/mono.ttf"] },
|
|
37
|
+
* ]);
|
|
38
|
+
* </script>
|
|
39
|
+
*
|
|
40
|
+
* <svelte:head>
|
|
41
|
+
* {@html styles}
|
|
42
|
+
* </svelte:head>
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare function fontrum(fonts: FontConfig[]): string;
|
|
46
|
+
|
|
47
|
+
export { type FontConfig, type FontDisplay, fontrum as default, fontrum };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var c={woff2:"woff2",woff:"woff",ttf:"truetype",otf:"opentype",eot:"embedded-opentype",svg:"svg",svgz:"svg"};function y(o){let n=o.split("?")[0].split(".").pop()?.toLowerCase()??"";return c[n]??n}function g(o){return o.map(n=>`url('${n}') format('${y(n)}')`).join(`,
|
|
2
|
+
`)}function u(o){return `<style>${o.map(t=>{let s=t.class,r=Array.isArray(t.font)?t.font:[t.font],e=t.weight??"normal",i=t.style??"normal",a=t.display??"swap",l=t.fallback??"sans-serif",f=["@font-face{",`font-family:'${s}';`,`src:${g(r)};`,`font-weight:${e};`,`font-style:${i};`,`font-display:${a};`,"}"].join(""),p=`.${s}{font-family:'${s}',${l};}`;return `${f}${p}`}).join("")}</style>`}var $=u;export{$ as default,u as fontrum};//# sourceMappingURL=index.js.map
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["FORMAT_MAP","getFormat","path","ext","buildSrc","fonts","f","fontrum","cfg","family","sources","weight","style","display","fallback","face","cls","index_default"],"mappings":"AAyBA,IAAMA,CAAAA,CAAqC,CACzC,KAAA,CAAO,OAAA,CACP,IAAA,CAAM,MAAA,CACN,GAAA,CAAK,UAAA,CACL,GAAA,CAAK,UAAA,CACL,GAAA,CAAK,mBAAA,CACL,GAAA,CAAK,KAAA,CACL,IAAA,CAAM,KACR,CAAA,CAEA,SAASC,CAAAA,CAAUC,CAAAA,CAAsB,CACvC,IAAMC,CAAAA,CAAMD,CAAAA,CAAK,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,CAAE,KAAA,CAAM,GAAG,CAAA,CAAE,GAAA,EAAI,EAAG,WAAA,EAAY,EAAK,EAAA,CAClE,OAAOF,CAAAA,CAAWG,CAAG,CAAA,EAAKA,CAC5B,CAEA,SAASC,CAAAA,CAASC,CAAAA,CAAyB,CACzC,OAAOA,CAAAA,CACJ,GAAA,CAAKC,CAAAA,EAAM,CAAA,KAAA,EAAQA,CAAC,CAAA,WAAA,EAAcL,CAAAA,CAAUK,CAAC,CAAC,CAAA,EAAA,CAAI,CAAA,CAClD,IAAA,CAAK,CAAA;AAAA,OAAA,CAAY,CACtB,CAuBO,SAASC,EAAQF,CAAAA,CAA6B,CAwBnD,OAAO,CAAA,OAAA,EAvBOA,CAAAA,CAAM,IAAKG,CAAAA,EAAQ,CAC/B,IAAMC,CAAAA,CAASD,CAAAA,CAAI,MACbE,CAAAA,CAAU,KAAA,CAAM,QAAQF,CAAAA,CAAI,IAAI,EAAIA,CAAAA,CAAI,IAAA,CAAO,CAACA,CAAAA,CAAI,IAAI,EACxDG,CAAAA,CAASH,CAAAA,CAAI,QAAU,QAAA,CACvBI,CAAAA,CAAQJ,EAAI,KAAA,EAAS,QAAA,CACrBK,EAAUL,CAAAA,CAAI,OAAA,EAAW,OACzBM,CAAAA,CAAWN,CAAAA,CAAI,UAAY,YAAA,CAE3BO,CAAAA,CAAO,CACX,aAAA,CACA,CAAA,aAAA,EAAgBN,CAAM,CAAA,EAAA,CAAA,CACtB,CAAA,IAAA,EAAOL,EAASM,CAAO,CAAC,IACxB,CAAA,YAAA,EAAeC,CAAM,IACrB,CAAA,WAAA,EAAcC,CAAK,IACnB,CAAA,aAAA,EAAgBC,CAAO,IACvB,GACF,CAAA,CAAE,KAAK,EAAE,CAAA,CAEHG,EAAM,CAAA,CAAA,EAAIP,CAAM,iBAAiBA,CAAM,CAAA,EAAA,EAAKK,CAAQ,CAAA,EAAA,CAAA,CAE1D,OAAO,GAAGC,CAAI,CAAA,EAAGC,CAAG,CAAA,CACtB,CAAC,EAEsB,IAAA,CAAK,EAAE,CAAC,CAAA,QAAA,CACjC,KAEOC,CAAAA,CAAQV","file":"index.js","sourcesContent":["export type FontDisplay = \"auto\" | \"block\" | \"swap\" | \"fallback\" | \"optional\";\n\nexport interface FontConfig {\n /** CSS class name to apply this font (e.g. \"inter\") */\n class: string;\n /**\n * Path(s) to the font file(s). Supports ttf, otf, woff, woff2, eot, svg.\n * Paths are relative to your public directory (e.g. \"/fonts/inter.woff2\").\n * Pass an array to provide multiple sources for the same font.\n */\n font: string | string[];\n /** Font weight. Defaults to \"normal\". */\n weight?: string | number;\n /** Font style. Defaults to \"normal\". */\n style?: string;\n /**\n * Controls how the font is displayed while loading.\n * \"swap\" (default) shows fallback font immediately then swaps — best for\n * most use cases and avoids invisible text during load.\n */\n display?: FontDisplay;\n /** Fallback font families appended after the custom font. Defaults to \"sans-serif\". */\n fallback?: string;\n}\n\nconst FORMAT_MAP: Record<string, string> = {\n woff2: \"woff2\",\n woff: \"woff\",\n ttf: \"truetype\",\n otf: \"opentype\",\n eot: \"embedded-opentype\",\n svg: \"svg\",\n svgz: \"svg\",\n};\n\nfunction getFormat(path: string): string {\n const ext = path.split(\"?\")[0].split(\".\").pop()?.toLowerCase() ?? \"\";\n return FORMAT_MAP[ext] ?? ext;\n}\n\nfunction buildSrc(fonts: string[]): string {\n return fonts\n .map((f) => `url('${f}') format('${getFormat(f)}')`)\n .join(\",\\n \");\n}\n\n/**\n * Generate CSS for the given font configurations.\n *\n * Returns a `<style>` tag string ready to be injected via `{@html}` in a\n * `<svelte:head>` block. Works on both server (SSR/SSG) and client.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import fontrum from \"@kiiimatz/fontrum\";\n * const styles = fontrum([\n * { class: \"inter\", font: \"/fonts/inter.woff2\" },\n * { class: \"mono\", font: [\"/fonts/mono.woff2\", \"/fonts/mono.ttf\"] },\n * ]);\n * </script>\n *\n * <svelte:head>\n * {@html styles}\n * </svelte:head>\n * ```\n */\nexport function fontrum(fonts: FontConfig[]): string {\n const rules = fonts.map((cfg) => {\n const family = cfg.class;\n const sources = Array.isArray(cfg.font) ? cfg.font : [cfg.font];\n const weight = cfg.weight ?? \"normal\";\n const style = cfg.style ?? \"normal\";\n const display = cfg.display ?? \"swap\";\n const fallback = cfg.fallback ?? \"sans-serif\";\n\n const face = [\n `@font-face{`,\n `font-family:'${family}';`,\n `src:${buildSrc(sources)};`,\n `font-weight:${weight};`,\n `font-style:${style};`,\n `font-display:${display};`,\n `}`,\n ].join(\"\");\n\n const cls = `.${family}{font-family:'${family}',${fallback};}`;\n\n return `${face}${cls}`;\n });\n\n return `<style>${rules.join(\"\")}</style>`;\n}\n\nexport default fontrum;\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kiiimatz/fontrum",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Lightweight font management library for SvelteKit and beyond",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"dev": "tsup --watch",
|
|
27
|
+
"prepublishOnly": "npm run build"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"svelte",
|
|
31
|
+
"sveltekit",
|
|
32
|
+
"font",
|
|
33
|
+
"typography",
|
|
34
|
+
"css",
|
|
35
|
+
"ssr",
|
|
36
|
+
"ssg"
|
|
37
|
+
],
|
|
38
|
+
"author": "kiiimatz",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"tsup": "^8.3.5",
|
|
42
|
+
"typescript": "^5.7.3"
|
|
43
|
+
}
|
|
44
|
+
}
|