astro-font-loader 0.0.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/.editorconfig +45 -0
- package/LICENSE +21 -0
- package/README.md +19 -0
- package/dist/astroBuild.d.ts +14 -0
- package/dist/astroBuild.d.ts.map +1 -0
- package/dist/astroBuild.js +34 -0
- package/dist/astroBuild.js.map +1 -0
- package/dist/astroConfig.d.ts +28 -0
- package/dist/astroConfig.d.ts.map +1 -0
- package/dist/astroConfig.js +48 -0
- package/dist/astroConfig.js.map +1 -0
- package/dist/css/filter.d.ts +12 -0
- package/dist/css/filter.d.ts.map +1 -0
- package/dist/css/filter.js +28 -0
- package/dist/css/filter.js.map +1 -0
- package/dist/css/get.d.ts +22 -0
- package/dist/css/get.d.ts.map +1 -0
- package/dist/css/get.js +24 -0
- package/dist/css/get.js.map +1 -0
- package/dist/css/index.d.ts +3 -0
- package/dist/css/index.d.ts.map +1 -0
- package/dist/css/index.js +3 -0
- package/dist/css/index.js.map +1 -0
- package/dist/css/transform.d.ts +12 -0
- package/dist/css/transform.d.ts.map +1 -0
- package/dist/css/transform.js +21 -0
- package/dist/css/transform.js.map +1 -0
- package/dist/fonts/available.d.ts +4 -0
- package/dist/fonts/available.d.ts.map +1 -0
- package/dist/fonts/available.js +42 -0
- package/dist/fonts/available.js.map +1 -0
- package/dist/fonts/index.d.ts +5 -0
- package/dist/fonts/index.d.ts.map +1 -0
- package/dist/fonts/index.js +3 -0
- package/dist/fonts/index.js.map +1 -0
- package/dist/fonts/package.d.ts +13 -0
- package/dist/fonts/package.d.ts.map +1 -0
- package/dist/fonts/package.js +36 -0
- package/dist/fonts/package.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/integration.d.ts +12 -0
- package/dist/integration.d.ts.map +1 -0
- package/dist/integration.js +31 -0
- package/dist/integration.js.map +1 -0
- package/package.json +43 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# EditorConfig helps developers define and maintain consistent
|
|
2
|
+
# coding styles between different editors and IDEs
|
|
3
|
+
# editorconfig.org
|
|
4
|
+
|
|
5
|
+
root = true
|
|
6
|
+
|
|
7
|
+
[*]
|
|
8
|
+
charset = utf-8
|
|
9
|
+
end_of_line = lf
|
|
10
|
+
trim_trailing_whitespace = true
|
|
11
|
+
insert_final_newline = true
|
|
12
|
+
indent_style = tab
|
|
13
|
+
indent_size = 4
|
|
14
|
+
|
|
15
|
+
[*.{diff}]
|
|
16
|
+
trim_trailing_whitespace = false
|
|
17
|
+
|
|
18
|
+
[Makefile]
|
|
19
|
+
indent_size = 2
|
|
20
|
+
indent_style = tab
|
|
21
|
+
|
|
22
|
+
[*.yml]
|
|
23
|
+
indent_size = 2
|
|
24
|
+
indent_style = space
|
|
25
|
+
|
|
26
|
+
[*.{py}]
|
|
27
|
+
indent_size = 4
|
|
28
|
+
indent_style = space
|
|
29
|
+
|
|
30
|
+
[*.{tf,tfvars}]
|
|
31
|
+
indent_size = 2
|
|
32
|
+
indent_style = space
|
|
33
|
+
|
|
34
|
+
[*.{md,Rmd,rst}]
|
|
35
|
+
indent_size = 2
|
|
36
|
+
indent_style = space
|
|
37
|
+
trim_trailing_whitespace = false
|
|
38
|
+
|
|
39
|
+
[*.txt]
|
|
40
|
+
insert_final_newline = false
|
|
41
|
+
|
|
42
|
+
[*.{yml,yaml,tpl,tpl}]
|
|
43
|
+
indent_size = 4
|
|
44
|
+
indent_style = space
|
|
45
|
+
trim_trailing_whitespace = false
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Michael Sleevi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Astro Font Loader
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
`astro-font-loader` hooks into the astro build process to copy selected fonts from installed font packages into the local build artifacts.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
# Using npm
|
|
12
|
+
npm i astro-font-loader
|
|
13
|
+
|
|
14
|
+
# Using yarn
|
|
15
|
+
yarn add astro-font-loader
|
|
16
|
+
|
|
17
|
+
# Using pnpm
|
|
18
|
+
pnpm add astro-font-loader
|
|
19
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AstroIntegrationLogger } from "astro";
|
|
2
|
+
import type { FontInfo } from "./fonts/fontInfo";
|
|
3
|
+
/**
|
|
4
|
+
* Handles the build completion phase for font loading.
|
|
5
|
+
*
|
|
6
|
+
* Copies all available font files to the output directory.
|
|
7
|
+
*
|
|
8
|
+
* @param {URL} dir - The build output directory URL.
|
|
9
|
+
* @param {AstroIntegrationLogger} logger - The Astro integration logger for outputting messages.
|
|
10
|
+
* @param {string} outputDir - The output directory name for font files.
|
|
11
|
+
* @param {FontInfo[]} availableFonts - Array of font files to copy.
|
|
12
|
+
*/
|
|
13
|
+
export declare function astroBuildDone(dir: URL, logger: AstroIntegrationLogger, outputDir: string, availableFonts: FontInfo[]): void;
|
|
14
|
+
//# sourceMappingURL=astroBuild.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astroBuild.d.ts","sourceRoot":"","sources":["../src/astroBuild.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC7B,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,sBAAsB,EAC9B,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,QAAQ,EAAE,GACxB,IAAI,CAuBN"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { copyFileSync, existsSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
/**
|
|
5
|
+
* Handles the build completion phase for font loading.
|
|
6
|
+
*
|
|
7
|
+
* Copies all available font files to the output directory.
|
|
8
|
+
*
|
|
9
|
+
* @param {URL} dir - The build output directory URL.
|
|
10
|
+
* @param {AstroIntegrationLogger} logger - The Astro integration logger for outputting messages.
|
|
11
|
+
* @param {string} outputDir - The output directory name for font files.
|
|
12
|
+
* @param {FontInfo[]} availableFonts - Array of font files to copy.
|
|
13
|
+
*/
|
|
14
|
+
export function astroBuildDone(dir, logger, outputDir, availableFonts) {
|
|
15
|
+
if (availableFonts.length === 0) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const outputPath = fileURLToPath(new URL(outputDir, dir));
|
|
19
|
+
if (!existsSync(outputPath)) {
|
|
20
|
+
mkdirSync(outputPath, { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
for (const font of availableFonts) {
|
|
23
|
+
const destPath = join(outputPath, font.filename);
|
|
24
|
+
try {
|
|
25
|
+
copyFileSync(font.sourcePath, destPath);
|
|
26
|
+
logger.info(`Copied ${font.filename}`);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
logger.error(`Failed to copy ${font.filename}: ${error}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
logger.info(`Copied ${availableFonts.length} font file(s) to ${outputDir}/`);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=astroBuild.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astroBuild.js","sourceRoot":"","sources":["../src/astroBuild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAMpC;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC7B,GAAQ,EACR,MAA8B,EAC9B,SAAiB,EACjB,cAA0B;IAE1B,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO;IACR,CAAC;IAED,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC;IAC1D,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjD,IAAI,CAAC;YACJ,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,CAAC,KAAK,CAAC,kBAAkB,IAAI,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC,CAAC;QAC3D,CAAC;IACF,CAAC;IAED,MAAM,CAAC,IAAI,CACV,UAAU,cAAc,CAAC,MAAM,oBAAoB,SAAS,GAAG,CAC/D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AstroIntegrationLogger } from "astro";
|
|
2
|
+
import type { FontInfo, FontsPackageInfo } from "./fonts/fontInfo";
|
|
3
|
+
/**
|
|
4
|
+
* Result of the configuration setup for font loading.
|
|
5
|
+
*
|
|
6
|
+
* @property {Array<FontsPackageInfo>} fontsInfoList - List of font package information objects.
|
|
7
|
+
* @property {FontInfo[]} availableFonts - Array of available font files from all packages.
|
|
8
|
+
* @property {string} transformedCss - The combined and transformed CSS from all packages.
|
|
9
|
+
*/
|
|
10
|
+
export type ConfigSetupResult = {
|
|
11
|
+
fontsInfoList: FontsPackageInfo[];
|
|
12
|
+
availableFonts: FontInfo[];
|
|
13
|
+
transformedCss: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Sets up font configuration for the Astro integration.
|
|
17
|
+
*
|
|
18
|
+
* Resolves font packages, collects available fonts, applies optional filtering, and transforms CSS.
|
|
19
|
+
*
|
|
20
|
+
* @param {AstroIntegrationLogger} logger - The Astro integration logger for outputting messages.
|
|
21
|
+
* @param {string[]} packages - Array of font package names to load.
|
|
22
|
+
* @param {string} outputDir - The output directory for font files.
|
|
23
|
+
* @param {(filename: string) => boolean} [filter] - Optional filter function to select font files.
|
|
24
|
+
* @param {URL} [root] - Optional root directory to resolve packages from.
|
|
25
|
+
* @returns {ConfigSetupResult} The result containing font info, available fonts, and transformed CSS.
|
|
26
|
+
*/
|
|
27
|
+
export declare function astroConfigSetup(logger: AstroIntegrationLogger, packages: string[], outputDir: string, filter?: (filename: string) => boolean, root?: URL): ConfigSetupResult;
|
|
28
|
+
//# sourceMappingURL=astroConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astroConfig.d.ts","sourceRoot":"","sources":["../src/astroConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AAMpD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B,aAAa,EAAE,gBAAgB,EAAE,CAAC;IAClC,cAAc,EAAE,QAAQ,EAAE,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,sBAAsB,EAC9B,QAAQ,EAAE,MAAM,EAAE,EAClB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,EACtC,IAAI,CAAC,EAAE,GAAG,GACR,iBAAiB,CAsCnB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { filterCssFontFaces } from "./css/filter";
|
|
3
|
+
import { transformCss } from "./css/transform";
|
|
4
|
+
import { getFontsPackageInfo } from "./fonts";
|
|
5
|
+
import { getAvailableFonts } from "./fonts/available";
|
|
6
|
+
/**
|
|
7
|
+
* Sets up font configuration for the Astro integration.
|
|
8
|
+
*
|
|
9
|
+
* Resolves font packages, collects available fonts, applies optional filtering, and transforms CSS.
|
|
10
|
+
*
|
|
11
|
+
* @param {AstroIntegrationLogger} logger - The Astro integration logger for outputting messages.
|
|
12
|
+
* @param {string[]} packages - Array of font package names to load.
|
|
13
|
+
* @param {string} outputDir - The output directory for font files.
|
|
14
|
+
* @param {(filename: string) => boolean} [filter] - Optional filter function to select font files.
|
|
15
|
+
* @param {URL} [root] - Optional root directory to resolve packages from.
|
|
16
|
+
* @returns {ConfigSetupResult} The result containing font info, available fonts, and transformed CSS.
|
|
17
|
+
*/
|
|
18
|
+
export function astroConfigSetup(logger, packages, outputDir, filter, root) {
|
|
19
|
+
const fontsInfoList = [];
|
|
20
|
+
let availableFonts = [];
|
|
21
|
+
let transformedCss = "";
|
|
22
|
+
if (!packages || packages.length === 0) {
|
|
23
|
+
logger.warn("No font packages specified. Fonts will not be copied.");
|
|
24
|
+
return { fontsInfoList: [], availableFonts, transformedCss };
|
|
25
|
+
}
|
|
26
|
+
for (const packageName of packages) {
|
|
27
|
+
const fontsInfo = getFontsPackageInfo(packageName, root);
|
|
28
|
+
if (!fontsInfo) {
|
|
29
|
+
logger.warn(`${packageName} package not found. Skipping.`);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
fontsInfoList.push(fontsInfo);
|
|
33
|
+
let packageFonts = getAvailableFonts(fontsInfo.fontsDir);
|
|
34
|
+
if (filter) {
|
|
35
|
+
packageFonts = packageFonts.filter((font) => filter(font.filename));
|
|
36
|
+
}
|
|
37
|
+
availableFonts = availableFonts.concat(packageFonts);
|
|
38
|
+
if (existsSync(fontsInfo.cssPath)) {
|
|
39
|
+
let rawCss = readFileSync(fontsInfo.cssPath, "utf-8");
|
|
40
|
+
rawCss = filterCssFontFaces(rawCss, filter);
|
|
41
|
+
transformedCss += transformCss(rawCss, outputDir, filter);
|
|
42
|
+
}
|
|
43
|
+
logger.info(`Loaded ${packageFonts.length} font file(s) from ${packageName}`);
|
|
44
|
+
}
|
|
45
|
+
logger.info(`Found ${availableFonts.length} total font file(s) to copy`);
|
|
46
|
+
return { fontsInfoList, availableFonts, transformedCss };
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=astroConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astroConfig.js","sourceRoot":"","sources":["../src/astroConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAInD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAgBtD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC/B,MAA8B,EAC9B,QAAkB,EAClB,SAAiB,EACjB,MAAsC,EACtC,IAAU;IAEV,MAAM,aAAa,GAAuB,EAAE,CAAC;IAC7C,IAAI,cAAc,GAAe,EAAE,CAAC;IACpC,IAAI,cAAc,GAAG,EAAE,CAAC;IAExB,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxC,MAAM,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;QACrE,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;IAC9D,CAAC;IAED,KAAK,MAAM,WAAW,IAAI,QAAQ,EAAE,CAAC;QACpC,MAAM,SAAS,GAAG,mBAAmB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QACzD,IAAI,CAAC,SAAS,EAAE,CAAC;YAChB,MAAM,CAAC,IAAI,CAAC,GAAG,WAAW,+BAA+B,CAAC,CAAC;YAC3D,SAAS;QACV,CAAC;QAED,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC9B,IAAI,YAAY,GAAG,iBAAiB,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACzD,IAAI,MAAM,EAAE,CAAC;YACZ,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QACrE,CAAC;QAED,cAAc,GAAG,cAAc,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACrD,IAAI,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YACnC,IAAI,MAAM,GAAG,YAAY,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACtD,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC5C,cAAc,IAAI,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAC3D,CAAC;QAED,MAAM,CAAC,IAAI,CACV,UAAU,YAAY,CAAC,MAAM,sBAAsB,WAAW,EAAE,CAChE,CAAC;IACH,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,SAAS,cAAc,CAAC,MAAM,6BAA6B,CAAC,CAAC;IAEzE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters @font-face rules in a CSS string based on a filename filter function.
|
|
3
|
+
*
|
|
4
|
+
* Iterates over all @font-face blocks and removes those for which the filter function returns false
|
|
5
|
+
* for any font file referenced in the block. If no filter is provided, returns the original CSS.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} css - The CSS string containing @font-face rules.
|
|
8
|
+
* @param {(filename: string) => boolean} [filter] - Optional filter function that receives a font filename and returns true to keep the rule, false to remove it.
|
|
9
|
+
* @returns {string} The filtered CSS string with only the allowed @font-face rules.
|
|
10
|
+
*/
|
|
11
|
+
export declare function filterCssFontFaces(css: string, filter?: (filename: string) => boolean): string;
|
|
12
|
+
//# sourceMappingURL=filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/css/filter.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,GACpC,MAAM,CAgBR"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* Filters @font-face rules in a CSS string based on a filename filter function.
|
|
4
|
+
*
|
|
5
|
+
* Iterates over all @font-face blocks and removes those for which the filter function returns false
|
|
6
|
+
* for any font file referenced in the block. If no filter is provided, returns the original CSS.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} css - The CSS string containing @font-face rules.
|
|
9
|
+
* @param {(filename: string) => boolean} [filter] - Optional filter function that receives a font filename and returns true to keep the rule, false to remove it.
|
|
10
|
+
* @returns {string} The filtered CSS string with only the allowed @font-face rules.
|
|
11
|
+
*/
|
|
12
|
+
export function filterCssFontFaces(css, filter) {
|
|
13
|
+
if (!filter) {
|
|
14
|
+
return css;
|
|
15
|
+
}
|
|
16
|
+
return css.replace(/@font-face\s*\{[^}]*\}/g, (match) => {
|
|
17
|
+
const urlMatches = match.matchAll(/url\(["']?\.\/([^"')]+)["']?\)/g);
|
|
18
|
+
for (const urlMatch of urlMatches) {
|
|
19
|
+
const relativePath = urlMatch[1];
|
|
20
|
+
const filename = basename(relativePath);
|
|
21
|
+
if (filter(filename)) {
|
|
22
|
+
return match;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return "";
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/css/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CACjC,GAAW,EACX,MAAsC;IAEtC,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,GAAG,CAAC;IACZ,CAAC;IAED,OAAO,GAAG,CAAC,OAAO,CAAC,yBAAyB,EAAE,CAAC,KAAK,EAAE,EAAE;QACvD,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,iCAAiC,CAAC,CAAC;QACrE,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,YAAY,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;YACjC,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;YACxC,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACtB,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,EAAE,CAAC;IACX,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FontsPackageInfo } from "../fonts";
|
|
2
|
+
/**
|
|
3
|
+
* Options for getting fonts CSS.
|
|
4
|
+
*/
|
|
5
|
+
export type GetFontsCssOptions = {
|
|
6
|
+
/** Optional filter function to select font files by filename. */
|
|
7
|
+
filter?: (filename: string) => boolean;
|
|
8
|
+
/** Optional output directory name. Defaults to "fonts". */
|
|
9
|
+
outputDir?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Loads, filters, and transforms the CSS for font-face rules from a font package.
|
|
13
|
+
*
|
|
14
|
+
* Reads the CSS file specified in the font package information, applies an optional filter to @font-face rules,
|
|
15
|
+
* and transforms the CSS for output. Returns an empty string if no font package information is provided or the CSS file does not exist.
|
|
16
|
+
*
|
|
17
|
+
* @param {GetFontsCssOptions} [options={}] - Options including filter and output directory.
|
|
18
|
+
* @param {FontsPackageInfo | null} fontPackageInformation - Information about the font package, including the CSS file path.
|
|
19
|
+
* @returns {string} The processed CSS string, or an empty string if the CSS file is missing or no package info is provided.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getFontsCss(options: GetFontsCssOptions | undefined, fontPackageInformation: FontsPackageInfo | null): string;
|
|
22
|
+
//# sourceMappingURL=get.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../src/css/get.ts"],"names":[],"mappings":"AAEA,OAAQ,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAIlD;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAChC,iEAAiE;IACjE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IACvC,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAC1B,OAAO,EAAE,kBAAkB,YAAK,EAChC,sBAAsB,EAAE,gBAAgB,GAAG,IAAI,GAC7C,MAAM,CAYR"}
|
package/dist/css/get.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { filterCssFontFaces } from "./filter";
|
|
3
|
+
import { transformCss } from "./transform";
|
|
4
|
+
/**
|
|
5
|
+
* Loads, filters, and transforms the CSS for font-face rules from a font package.
|
|
6
|
+
*
|
|
7
|
+
* Reads the CSS file specified in the font package information, applies an optional filter to @font-face rules,
|
|
8
|
+
* and transforms the CSS for output. Returns an empty string if no font package information is provided or the CSS file does not exist.
|
|
9
|
+
*
|
|
10
|
+
* @param {GetFontsCssOptions} [options={}] - Options including filter and output directory.
|
|
11
|
+
* @param {FontsPackageInfo | null} fontPackageInformation - Information about the font package, including the CSS file path.
|
|
12
|
+
* @returns {string} The processed CSS string, or an empty string if the CSS file is missing or no package info is provided.
|
|
13
|
+
*/
|
|
14
|
+
export function getFontsCss(options = {}, fontPackageInformation) {
|
|
15
|
+
const { filter, outputDir = "fonts" } = options;
|
|
16
|
+
if (!fontPackageInformation ||
|
|
17
|
+
!existsSync(fontPackageInformation.cssPath)) {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
let rawCss = readFileSync(fontPackageInformation.cssPath, "utf-8");
|
|
21
|
+
rawCss = filterCssFontFaces(rawCss, filter);
|
|
22
|
+
return transformCss(rawCss, outputDir, filter);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=get.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/css/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAY3C;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAC1B,UAA8B,EAAE,EAChC,sBAA+C;IAE/C,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC;IAChD,IACC,CAAC,sBAAsB;QACvB,CAAC,UAAU,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAC1C,CAAC;QACF,OAAO,EAAE,CAAC;IACX,CAAC;IAED,IAAI,MAAM,GAAG,YAAY,CAAC,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACnE,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,OAAO,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/css/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/css/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transforms font-face URLs in a CSS string to point to a specified output directory.
|
|
3
|
+
*
|
|
4
|
+
* Replaces relative font URLs with absolute URLs based on the output directory. Optionally filters font files by filename.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} rawCss - The raw CSS string containing font-face rules.
|
|
7
|
+
* @param {string} outputDir - The output directory to use in the transformed URLs.
|
|
8
|
+
* @param {(filename: string) => boolean} [filter] - Optional filter function to determine which font files to transform.
|
|
9
|
+
* @returns {string} The CSS string with transformed font-face URLs.
|
|
10
|
+
*/
|
|
11
|
+
export declare function transformCss(rawCss: string, outputDir: string, filter?: (filename: string) => boolean): string;
|
|
12
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/css/transform.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,GACpC,MAAM,CAWR"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* Transforms font-face URLs in a CSS string to point to a specified output directory.
|
|
4
|
+
*
|
|
5
|
+
* Replaces relative font URLs with absolute URLs based on the output directory. Optionally filters font files by filename.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} rawCss - The raw CSS string containing font-face rules.
|
|
8
|
+
* @param {string} outputDir - The output directory to use in the transformed URLs.
|
|
9
|
+
* @param {(filename: string) => boolean} [filter] - Optional filter function to determine which font files to transform.
|
|
10
|
+
* @returns {string} The CSS string with transformed font-face URLs.
|
|
11
|
+
*/
|
|
12
|
+
export function transformCss(rawCss, outputDir, filter) {
|
|
13
|
+
return rawCss.replace(/url\(["']?\.\/([^"')]+)["']?\)/g, (match, relativePath) => {
|
|
14
|
+
const filename = basename(relativePath);
|
|
15
|
+
if (filter && !filter(filename)) {
|
|
16
|
+
return match;
|
|
17
|
+
}
|
|
18
|
+
return `url("/${outputDir}/${filename}")`;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/css/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAC3B,MAAc,EACd,SAAiB,EACjB,MAAsC;IAEtC,OAAO,MAAM,CAAC,OAAO,CACpB,iCAAiC,EACjC,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE;QACvB,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;QACxC,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC;QACd,CAAC;QACD,OAAO,SAAS,SAAS,IAAI,QAAQ,IAAI,CAAC;IAC3C,CAAC,CACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"available.d.ts","sourceRoot":"","sources":["../../src/fonts/available.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE,CA+B9D;AAED,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAOhD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { getFontsPackageInfo } from "./package";
|
|
4
|
+
export function getAvailableFonts(fontsDir) {
|
|
5
|
+
const srcDir = join(fontsDir, "src");
|
|
6
|
+
if (!existsSync(srcDir)) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
const fonts = [];
|
|
10
|
+
const entries = readdirSync(srcDir, { withFileTypes: true });
|
|
11
|
+
for (const entry of entries) {
|
|
12
|
+
if (entry.isDirectory()) {
|
|
13
|
+
const subDirPath = join(srcDir, entry.name);
|
|
14
|
+
const subFiles = readdirSync(subDirPath);
|
|
15
|
+
for (const file of subFiles) {
|
|
16
|
+
if (/\.(woff2?|ttf|otf|eot)$/i.test(file)) {
|
|
17
|
+
fonts.push({
|
|
18
|
+
filename: file,
|
|
19
|
+
sourcePath: join(subDirPath, file),
|
|
20
|
+
relativePath: `${entry.name}/${file}`,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else if (/\.(woff2?|ttf|otf|eot)$/i.test(entry.name)) {
|
|
26
|
+
fonts.push({
|
|
27
|
+
filename: entry.name,
|
|
28
|
+
sourcePath: join(srcDir, entry.name),
|
|
29
|
+
relativePath: entry.name,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return fonts;
|
|
34
|
+
}
|
|
35
|
+
export function getAvailableFontNames() {
|
|
36
|
+
const fontsInfo = getFontsPackageInfo("@iveelsm/fonts");
|
|
37
|
+
if (!fontsInfo) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
return getAvailableFonts(fontsInfo.fontsDir).map((f) => f.filename);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=available.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"available.js","sourceRoot":"","sources":["../../src/fonts/available.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACrC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACX,CAAC;IAED,MAAM,KAAK,GAAe,EAAE,CAAC;IAC7B,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YACzB,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YAC5C,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;YACzC,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC7B,IAAI,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC3C,KAAK,CAAC,IAAI,CAAC;wBACV,QAAQ,EAAE,IAAI;wBACd,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC;wBAClC,YAAY,EAAE,GAAG,KAAK,CAAC,IAAI,IAAI,IAAI,EAAE;qBACrC,CAAC,CAAC;gBACJ,CAAC;YACF,CAAC;QACF,CAAC;aAAM,IAAI,0BAA0B,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACxD,KAAK,CAAC,IAAI,CAAC;gBACV,QAAQ,EAAE,KAAK,CAAC,IAAI;gBACpB,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC;gBACpC,YAAY,EAAE,KAAK,CAAC,IAAI;aACxB,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,qBAAqB;IACpC,MAAM,SAAS,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IACxD,IAAI,CAAC,SAAS,EAAE,CAAC;QAChB,OAAO,EAAE,CAAC;IACX,CAAC;IAED,OAAO,iBAAiB,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fonts/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fonts/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAIhD,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FontsPackageInfo } from "./fontInfo";
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves font package information for a given package name.
|
|
4
|
+
*
|
|
5
|
+
* Resolves the path to the package.json of the specified font package, then constructs the directory and CSS file path.
|
|
6
|
+
* Returns null if the package cannot be resolved.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} fontsPackage - The name of the font package to resolve.
|
|
9
|
+
* @param {URL | string} [root] - Optional root directory to resolve packages from. Can be a URL or file path.
|
|
10
|
+
* @returns {FontsPackageInfo | null} An object containing the fonts directory and CSS file path, or null if not found.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getFontsPackageInfo(fontsPackage: string, root?: URL | string): FontsPackageInfo | null;
|
|
13
|
+
//# sourceMappingURL=package.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../src/fonts/package.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAClC,YAAY,EAAE,MAAM,EACpB,IAAI,CAAC,EAAE,GAAG,GAAG,MAAM,GACjB,gBAAgB,GAAG,IAAI,CAsBzB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves font package information for a given package name.
|
|
6
|
+
*
|
|
7
|
+
* Resolves the path to the package.json of the specified font package, then constructs the directory and CSS file path.
|
|
8
|
+
* Returns null if the package cannot be resolved.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} fontsPackage - The name of the font package to resolve.
|
|
11
|
+
* @param {URL | string} [root] - Optional root directory to resolve packages from. Can be a URL or file path.
|
|
12
|
+
* @returns {FontsPackageInfo | null} An object containing the fonts directory and CSS file path, or null if not found.
|
|
13
|
+
*/
|
|
14
|
+
export function getFontsPackageInfo(fontsPackage, root) {
|
|
15
|
+
try {
|
|
16
|
+
// Create require relative to the root if provided, otherwise use import.meta.url
|
|
17
|
+
let requireBase;
|
|
18
|
+
if (root) {
|
|
19
|
+
// Handle both URL objects and string paths
|
|
20
|
+
const rootPath = root instanceof URL ? fileURLToPath(root) : root;
|
|
21
|
+
requireBase = join(rootPath, "package.json");
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
requireBase = import.meta.url;
|
|
25
|
+
}
|
|
26
|
+
const require = createRequire(requireBase);
|
|
27
|
+
const fontsPackagePath = require.resolve(`${fontsPackage}/package.json`);
|
|
28
|
+
const fontsDir = dirname(fontsPackagePath);
|
|
29
|
+
const cssPath = join(fontsDir, "src", "index.css");
|
|
30
|
+
return { fontsDir, cssPath };
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=package.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.js","sourceRoot":"","sources":["../../src/fonts/package.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAClC,YAAoB,EACpB,IAAmB;IAEnB,IAAI,CAAC;QACJ,iFAAiF;QACjF,IAAI,WAAmB,CAAC;QACxB,IAAI,IAAI,EAAE,CAAC;YACV,2CAA2C;YAC3C,MAAM,QAAQ,GAAG,IAAI,YAAY,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAClE,WAAW,GAAG,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACP,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;QAC/B,CAAC;QAED,MAAM,OAAO,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;QAC3C,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CACvC,GAAG,YAAY,eAAe,CAC9B,CAAC;QACF,MAAM,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;QACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AstroIntegration } from "astro";
|
|
2
|
+
import type { FontsIntegrationOptions } from "./integrationOptions";
|
|
3
|
+
/**
|
|
4
|
+
* Creates an Astro integration for font loading and transformation.
|
|
5
|
+
*
|
|
6
|
+
* Sets up hooks for Astro's config and build phases to process font files and CSS, using provided options for filtering and output directory.
|
|
7
|
+
*
|
|
8
|
+
* @param {FontsIntegrationOptions} [options={}] - Options for filtering font files and specifying the output directory.
|
|
9
|
+
* @returns {AstroIntegration} The Astro integration object for font loading.
|
|
10
|
+
*/
|
|
11
|
+
export declare function fontsIntegration(options: FontsIntegrationOptions): AstroIntegration;
|
|
12
|
+
//# sourceMappingURL=integration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAK9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAEpE;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,uBAAuB,GAC9B,gBAAgB,CA2BlB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { astroBuildDone } from "./astroBuild";
|
|
2
|
+
import { astroConfigSetup } from "./astroConfig";
|
|
3
|
+
/**
|
|
4
|
+
* Creates an Astro integration for font loading and transformation.
|
|
5
|
+
*
|
|
6
|
+
* Sets up hooks for Astro's config and build phases to process font files and CSS, using provided options for filtering and output directory.
|
|
7
|
+
*
|
|
8
|
+
* @param {FontsIntegrationOptions} [options={}] - Options for filtering font files and specifying the output directory.
|
|
9
|
+
* @returns {AstroIntegration} The Astro integration object for font loading.
|
|
10
|
+
*/
|
|
11
|
+
export function fontsIntegration(options) {
|
|
12
|
+
const { packages, filter, outputDir = "fonts" } = options;
|
|
13
|
+
let fontsInfoList = [];
|
|
14
|
+
let availableFonts = [];
|
|
15
|
+
let transformedCss = "";
|
|
16
|
+
return {
|
|
17
|
+
name: "astro-font-loader",
|
|
18
|
+
hooks: {
|
|
19
|
+
"astro:config:setup": ({ config, logger }) => {
|
|
20
|
+
const result = astroConfigSetup(logger, packages, outputDir, filter, config.root);
|
|
21
|
+
fontsInfoList = result.fontsInfoList;
|
|
22
|
+
availableFonts = result.availableFonts;
|
|
23
|
+
transformedCss = result.transformedCss;
|
|
24
|
+
},
|
|
25
|
+
"astro:build:done": ({ dir, logger }) => {
|
|
26
|
+
astroBuildDone(dir, logger, outputDir, availableFonts);
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=integration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.js","sourceRoot":"","sources":["../src/integration.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAIjD;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC/B,OAAgC;IAEhC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC;IAE1D,IAAI,aAAa,GAA4C,EAAE,CAAC;IAChE,IAAI,cAAc,GAAe,EAAE,CAAC;IACpC,IAAI,cAAc,GAAW,EAAE,CAAC;IAEhC,OAAO;QACN,IAAI,EAAE,mBAAmB;QACzB,KAAK,EAAE;YACN,oBAAoB,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC5C,MAAM,MAAM,GAAG,gBAAgB,CAC9B,MAAM,EACN,QAAQ,EACR,SAAS,EACT,MAAM,EACN,MAAM,CAAC,IAAI,CACX,CAAC;gBACF,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;gBACrC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;gBACvC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;YACxC,CAAC;YACD,kBAAkB,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE;gBACvC,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;YACxD,CAAC;SACD;KACD,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "astro-font-loader",
|
|
3
|
+
"description": "Loads fonts into astro build artifacts from custom fonts packages",
|
|
4
|
+
"author": "Mikey Sleevi <development@frogman.simplelogin.com>",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"version": "0.0.1",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"astro-component",
|
|
11
|
+
"astro-loader",
|
|
12
|
+
"astro",
|
|
13
|
+
"fonts",
|
|
14
|
+
"plugin"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/iveelsm/astro-font-loader#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/iveelsm/astro-font-loader/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/iveelsm/astro-font-loader.git"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"test": "node --import tsx --test tests/**/*.test.ts",
|
|
27
|
+
"lint": "prettier --check . && eslint .",
|
|
28
|
+
"lint:fix": "prettier --write . && eslint . --fix"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@tsconfig/recommended": "^1.0.13",
|
|
32
|
+
"@types/node": "^25.2.0",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
34
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
35
|
+
"astro": "^5.17.1",
|
|
36
|
+
"eslint": "^9.39.2",
|
|
37
|
+
"eslint-plugin-perfectionist": "^5.4.0",
|
|
38
|
+
"prettier": "^3.8.1",
|
|
39
|
+
"tsx": "^4.21.0",
|
|
40
|
+
"typescript": "^5.9.3",
|
|
41
|
+
"typescript-eslint": "^8.54.0"
|
|
42
|
+
}
|
|
43
|
+
}
|