@svfig/vite 0.1.0
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/README.md +41 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# @svfig/vite
|
|
2
|
+
|
|
3
|
+
Vite plugin to import `.svfig` files as rendered SVG.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import svg, { document } from './diagram.svfig';
|
|
7
|
+
// svg: string (rendered SVG markup)
|
|
8
|
+
// document: parsed SVFIG document
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pnpm add -D @svfig/vite
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Vite
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// vite.config.ts
|
|
23
|
+
import { defineConfig } from 'vite';
|
|
24
|
+
import { svfig } from '@svfig/vite';
|
|
25
|
+
|
|
26
|
+
export default defineConfig({
|
|
27
|
+
plugins: [svfig()],
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Astro
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
// astro.config.mjs
|
|
35
|
+
import { defineConfig } from 'astro/config';
|
|
36
|
+
import { svfig } from '@svfig/vite';
|
|
37
|
+
|
|
38
|
+
export default defineConfig({
|
|
39
|
+
vite: { plugins: [svfig()] },
|
|
40
|
+
});
|
|
41
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,KAAK;;;eAGC;QAAE,YAAY,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,MAAM,MAAM;;;;CA0BpE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { renderSvg } from '@svfig/build';
|
|
4
|
+
import { imagePaths, imageWatchPath } from '@svfig/build/path';
|
|
5
|
+
import { parse } from '@svfig/core';
|
|
6
|
+
export const svfig = () => ({
|
|
7
|
+
name: '@svfig/vite:svfig',
|
|
8
|
+
enforce: 'pre',
|
|
9
|
+
async load(id) {
|
|
10
|
+
const filename = id.split('?')[0];
|
|
11
|
+
if (!filename.endsWith('.svfig'))
|
|
12
|
+
return null;
|
|
13
|
+
this.addWatchFile?.(filename);
|
|
14
|
+
const src = await readFile(filename, 'utf8');
|
|
15
|
+
const svfig = parse(src, filename);
|
|
16
|
+
const baseDir = dirname(filename);
|
|
17
|
+
for (const path of imagePaths(svfig.elements)) {
|
|
18
|
+
const watch = await imageWatchPath(path, { baseDir });
|
|
19
|
+
if (watch)
|
|
20
|
+
this.addWatchFile?.(watch);
|
|
21
|
+
}
|
|
22
|
+
const svg = await renderSvg(svfig, { baseDir });
|
|
23
|
+
return {
|
|
24
|
+
code: `const document = ${JSON.stringify(svfig)};\n` +
|
|
25
|
+
`const svg = ${JSON.stringify(svg)};\n` +
|
|
26
|
+
`export { document };\n` +
|
|
27
|
+
`export default svg;\n`,
|
|
28
|
+
map: null,
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@svfig/vite",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@svfig/build": "0.1.0",
|
|
19
|
+
"@svfig/core": "0.1.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^22.10.0"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"vite": ">=5.0.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.build.json",
|
|
29
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
30
|
+
}
|
|
31
|
+
}
|