Skip to content

Commit d867a22

Browse files
committed
feat!: nuxt and vue plugins
1 parent 998fd17 commit d867a22

22 files changed

+9798
-1142
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.vscode
2+
.nuxt
23
node_modules
34
dist
45
coverage

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
## Features
1313

14+
- ✅ Vue and Nuxt Plugin
1415
- ✅ Local or File Object
1516
- ✅ Support JSON
1617
- ✅ Exclude Wrong Data

package.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "nvton-monorepo",
2+
"name": "nvton",
33
"version": "0.0.0",
44
"repository": {
55
"type": "git",
@@ -16,8 +16,10 @@
1616
},
1717
"private": true,
1818
"scripts": {
19-
"build": "pnpm run build:core",
19+
"build": "pnpm -r --filter=\"./packages/**/*\" run build",
2020
"build:core": "pnpm -C packages/nvton run build",
21+
"build:vue": "pnpm -C packages/vue run build",
22+
"build:nuxt": "pnpm -C packages/nuxt run build",
2123
"format": "prettier . --write",
2224
"test": "vitest run --coverage",
2325
"test:dev": "vitest",
@@ -27,13 +29,6 @@
2729
"publish-ci": "tsx scripts/publish-ci.ts",
2830
"release": "tsx scripts/release.ts"
2931
},
30-
"dependencies": {
31-
"c12": "^3.3.1",
32-
"defu": "^6.1.4",
33-
"destr": "^2.0.5",
34-
"fs-extra": "^11.3.2",
35-
"pathe": "^2.0.3"
36-
},
3732
"devDependencies": {
3833
"@types/fs-extra": "^11.0.4",
3934
"@types/node": "^24.9.2",
@@ -42,10 +37,10 @@
4237
"generi": "^1.4.1",
4338
"prettier": "^3.6.2",
4439
"tinyglobby": "^0.2.15",
45-
"tsdown": "^0.15.11",
40+
"tsdown": "^0.15.12",
4641
"tsx": "^4.20.6",
4742
"typescript": "^5.9.3",
48-
"vitest": "^4.0.4",
43+
"vitest": "^4.0.5",
4944
"zx": "^8.8.5"
5045
}
5146
}

packages/nuxt/.nuxtrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
imports.autoImport=false
2+
typescript.includeWorkspace=true

packages/nuxt/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Nuxt4 NVTON Module
2+
3+
## Setup
4+
5+
```bash
6+
npm i nuxt-nvton
7+
```
8+
9+
```js
10+
// nuxt.config.ts
11+
modules: [
12+
'nuxt-nvton'
13+
]
14+
```
15+
16+
## Example
17+
18+
```ts
19+
<script setup>
20+
import { useNuxtApp } from '#app';
21+
22+
const { $nvton } = useNuxtApp()
23+
24+
$pdf.new({
25+
plugins: [
26+
{
27+
page: [
28+
// simple counter footer
29+
({ Text }, context, current, total) => {
30+
// render in every page
31+
Text(`${current}/${total}`, { fontSize: 20 }, {
32+
x: context.width / 2,
33+
y: context.height - context.margins.bottom
34+
})
35+
},
36+
// simple header
37+
({ Text }, context, current, total) => {
38+
// render in every page
39+
Text('A Simple Header', {}, {
40+
x: context.width / 2,
41+
y: context.margins.top - 20
42+
})
43+
}
44+
]
45+
}
46+
]
47+
})
48+
49+
$pdf.add([
50+
{ raw: 'Hello NUXT!', text: { fontSize: 22 }},
51+
])
52+
53+
$pdf.run().then(blob => {
54+
const iframe = document.querySelector('#pdf')
55+
56+
iframe.src = blob
57+
}).catch((err) => {
58+
console.error(err)
59+
})
60+
</script>
61+
```

packages/nuxt/package.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "nuxt-nvton",
3+
"sideEffects": false,
4+
"author": {
5+
"email": "novout@hotmail.com",
6+
"name": "Giovane Cardoso",
7+
"url": "https://github.com/Novout"
8+
},
9+
"version": "0.0.0",
10+
"repository": "https://github.com/Novout/nvton",
11+
"description": "A PDF document generator to your Nuxt application.",
12+
"engines": {
13+
"node": ">=14.16"
14+
},
15+
"bugs": {
16+
"url": "https://github.com/betterwrite/Novout/nvton"
17+
},
18+
"keywords": [
19+
"nvton",
20+
"nuxt4"
21+
],
22+
"license": "MIT",
23+
"type": "module",
24+
"exports": {
25+
".": {
26+
"import": "./dist/module.mjs",
27+
"require": "./dist/module.cjs"
28+
}
29+
},
30+
"main": "./dist/module.cjs",
31+
"types": "./dist/types.d.ts",
32+
"files": [
33+
"dist",
34+
"package.json"
35+
],
36+
"scripts": {
37+
"todo:build": "nuxi prepare && nuxt-module-build && nuxi prepare playground",
38+
"prepack": "nuxi prepare && nuxt-module-build && nuxi prepare playground"
39+
},
40+
"dependencies": {
41+
"@nuxt/kit": "^4.2.0",
42+
"defu": "catalog:",
43+
"nvton": "workspace:*"
44+
},
45+
"devDependencies": {
46+
"@nuxt/module-builder": "^1.0.2",
47+
"@nuxt/schema": "^4.2.0",
48+
"@nuxtjs/eslint-config-typescript": "^12.1.0",
49+
"eslint": "^8.42.0",
50+
"nuxt": "^4.2.0"
51+
}
52+
}

packages/nuxt/src/module.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { fileURLToPath } from 'url';
2+
import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit';
3+
import { type Nvton, type NvtonOptions, DEFAULT_CONFIG } from 'nvton';
4+
import { defu } from 'defu';
5+
6+
export default defineNuxtModule<NvtonOptions>({
7+
meta: {
8+
name: 'nuxt-nvton',
9+
configKey: 'nvton',
10+
compatibility: {
11+
nuxt: '>=4.0.0',
12+
},
13+
},
14+
defaults: DEFAULT_CONFIG,
15+
setup(options, nuxt) {
16+
const { resolve } = createResolver(import.meta.url);
17+
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url));
18+
19+
nuxt.options.build.transpile.push(runtimeDir);
20+
nuxt.options.runtimeConfig.public.nvton = defu(
21+
nuxt.options.runtimeConfig.public.nvton ?? DEFAULT_CONFIG,
22+
options
23+
);
24+
25+
addPlugin(resolve(runtimeDir, 'plugin'));
26+
},
27+
});
28+
29+
declare module '#app' {
30+
interface NuxtApp {
31+
$nvton: Nvton;
32+
}
33+
}
34+
35+
declare module 'vue' {
36+
interface ComponentCustomProperties {
37+
$nvton: Nvton;
38+
}
39+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineNuxtPlugin } from '#app';
2+
import { nvton } from 'nvton';
3+
4+
export default defineNuxtPlugin(({ provide }) => {
5+
provide('nvton', nvton(false));
6+
});

packages/nuxt/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./.nuxt/tsconfig.json"
3+
}

packages/nvton/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,12 @@
4444
"dev": "tsdown",
4545
"dev:watch": "tsdown --watch",
4646
"build": "tsdown --minify"
47+
},
48+
"dependencies": {
49+
"c12": "catalog:",
50+
"defu": "catalog:",
51+
"destr": "catalog:",
52+
"fs-extra": "catalog:",
53+
"pathe": "catalog:"
4754
}
4855
}

0 commit comments

Comments
 (0)