vue-pdfiy 0.0.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.
Files changed (89) hide show
  1. package/.cursorrules +0 -0
  2. package/.editorconfig +8 -0
  3. package/.gitattributes +1 -0
  4. package/.github/workflows/deploy.yml +66 -0
  5. package/.oxlintrc.json +10 -0
  6. package/.prettierrc.json +6 -0
  7. package/.vitepress/config.ts +63 -0
  8. package/.vitepress/theme/index.ts +42 -0
  9. package/.vitepress/theme/style.css +255 -0
  10. package/.vscode/extensions.json +10 -0
  11. package/README.md +294 -0
  12. package/api-examples.md +49 -0
  13. package/bun.lock +1165 -0
  14. package/docs/assets/logo.svg +9 -0
  15. package/docs/examples.md +507 -0
  16. package/docs/guide/introduction.md +14 -0
  17. package/docs/guide/quick-start.md +76 -0
  18. package/docs/index.md +35 -0
  19. package/docs/plugins/table-builder-api-refrences.md +430 -0
  20. package/docs/plugins/table-builder-hooks.md +294 -0
  21. package/docs/plugins/table-builder.md +278 -0
  22. package/docs/plugins/vfs.md +108 -0
  23. package/docs/public/assets/file-type-pdf-dark.svg +9 -0
  24. package/docs/public/assets/file-type-pdf-light.svg +9 -0
  25. package/docs/public/assets/file-type-pdf.svg +9 -0
  26. package/docs/public/assets/logo.svg +9 -0
  27. package/docs/public/assets/table-dark.svg +6 -0
  28. package/docs/public/assets/table-light.svg +6 -0
  29. package/docs/public/assets/table.svg +6 -0
  30. package/docs/public/assets/tools-dark.svg +9 -0
  31. package/docs/public/assets/tools-light.svg +9 -0
  32. package/docs/public/assets/tools.svg +9 -0
  33. package/docs/utils/array-buffer-to-base64.md +60 -0
  34. package/docs/utils/is-arabic-text.md +59 -0
  35. package/docs/utils/load-custom-font.md +105 -0
  36. package/docs/utils/text-splitter.md +182 -0
  37. package/env.d.ts +1 -0
  38. package/index.html +13 -0
  39. package/package.json +58 -0
  40. package/plan.md +279 -0
  41. package/public/Cairo-Regular.ttf +0 -0
  42. package/public/PlaywriteGBJGuides-Italic.ttf +0 -0
  43. package/public/PlaywriteGBJGuides-Regular.ttf +0 -0
  44. package/public/favicon.ico +0 -0
  45. package/public/logo.svg +1 -0
  46. package/src/App.vue +122 -0
  47. package/src/assets/base.css +0 -0
  48. package/src/assets/logo.svg +1 -0
  49. package/src/assets/main.css +61 -0
  50. package/src/components/PDFRender.vue +16 -0
  51. package/src/components/Pagination.vue +40 -0
  52. package/src/components/TheWelcome.vue +95 -0
  53. package/src/components/WelcomeItem.vue +87 -0
  54. package/src/components/__tests__/HelloWorld.spec.ts +7 -0
  55. package/src/components/icons/IconCommunity.vue +7 -0
  56. package/src/components/icons/IconDocumentation.vue +7 -0
  57. package/src/components/icons/IconEcosystem.vue +7 -0
  58. package/src/components/icons/IconSupport.vue +7 -0
  59. package/src/components/icons/IconTooling.vue +19 -0
  60. package/src/composables/index.ts +583 -0
  61. package/src/composables/useTableBuilder.ts +465 -0
  62. package/src/examples/CustomizationTable.vue +1095 -0
  63. package/src/examples/DynamicTable.vue +84 -0
  64. package/src/examples/InvoiceTable.vue +93 -0
  65. package/src/examples/MultiTablesWithHeaderFooter.vue +95 -0
  66. package/src/examples/ReusableTableBuilder.vue +84 -0
  67. package/src/examples/SimpleTable.vue +51 -0
  68. package/src/examples/TableFromObjects.vue +70 -0
  69. package/src/examples/tableBuilderExample.ts +405 -0
  70. package/src/main.ts +6 -0
  71. package/src/plugins/AutoTable.ts +67 -0
  72. package/src/plugins/Svg.ts +6 -0
  73. package/src/plugins/TextSplitter.ts +14 -0
  74. package/src/plugins/VFS.ts +14 -0
  75. package/src/plugins/table.ts +33 -0
  76. package/src/types/index.ts +149 -0
  77. package/src/types/table.ts +130 -0
  78. package/src/utils/ArrayBufferToBase64.ts +14 -0
  79. package/src/utils/IsArabicText.ts +9 -0
  80. package/src/utils/LoadCustomFont.ts +20 -0
  81. package/src/utils/PXToMM.ts +3 -0
  82. package/src/utils/SetTextPosition.ts +16 -0
  83. package/src/utils/tableHelpers.ts +133 -0
  84. package/tsconfig.app.json +12 -0
  85. package/tsconfig.json +14 -0
  86. package/tsconfig.node.json +19 -0
  87. package/tsconfig.vitest.json +11 -0
  88. package/vite.config.ts +15 -0
  89. package/vitest.config.ts +14 -0
package/README.md ADDED
@@ -0,0 +1,294 @@
1
+ # vue-pdfiy
2
+
3
+ A powerful Vue 3 composable for creating PDF documents with jsPDF and jsPDF-AutoTable. Build PDFs programmatically with a clean, fluent API.
4
+
5
+ ## Features
6
+
7
+ - 📄 **Simple PDF Creation** - Create PDFs with ease using Vue 3 composables
8
+ - 📊 **Table Builder** - Fluent API for dynamic table generation
9
+ - 🎨 **Rich Styling** - Comprehensive styling options for tables and content
10
+ - 🔧 **TypeScript Support** - Full TypeScript definitions included
11
+ - 🚀 **Performant** - Built on top of jsPDF and jsPDF-AutoTable
12
+ - 💪 **Flexible** - Both declarative and programmatic APIs available
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install vue-pdfiy
18
+ # or
19
+ yarn add vue-pdfiy
20
+ # or
21
+ bun add vue-pdfiy
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ### Basic PDF Creation
27
+
28
+ ```typescript
29
+ import { useJsPdf } from 'vue-pdfiy'
30
+
31
+ const { addText, setFontSize, savePdf } = useJsPdf({
32
+ orientation: 'p',
33
+ unit: 'mm',
34
+ format: 'a4'
35
+ })
36
+
37
+ setFontSize(20)
38
+ addText('Hello, PDF!', 20, 20)
39
+ savePdf('hello.pdf')
40
+ ```
41
+
42
+ ### Simple Table
43
+
44
+ ```typescript
45
+ import { useJsPdf } from 'vue-pdfiy'
46
+
47
+ const { createTable, savePdf } = useJsPdf({ orientation: 'p', unit: 'mm', format: 'a4' })
48
+
49
+ createTable({
50
+ header: [['Name', 'Age', 'City']],
51
+ body: [
52
+ ['John', 30, 'NYC'],
53
+ ['Jane', 25, 'LA']
54
+ ]
55
+ }, { theme: 'grid' })
56
+
57
+ savePdf('table.pdf')
58
+ ```
59
+
60
+ ## TableBuilder API
61
+
62
+ For dynamic, programmatic table creation, use the TableBuilder:
63
+
64
+ ### Basic Example
65
+
66
+ ```typescript
67
+ import { useJsPdf } from 'vue-pdfiy'
68
+
69
+ const { createTableBuilder, savePdf } = useJsPdf({ orientation: 'p', unit: 'mm', format: 'a4' })
70
+
71
+ createTableBuilder()
72
+ .addHeader(['Product', 'Price', 'Stock'])
73
+ .addRow(['Laptop', '$999', 50])
74
+ .addRow(['Mouse', '$29', 200])
75
+ .setTheme('striped')
76
+ .setHeaderStyles({ fillColor: '#4CAF50', textColor: '#fff' })
77
+ .build()
78
+
79
+ savePdf('products.pdf')
80
+ ```
81
+
82
+ ### Dynamic Generation
83
+
84
+ ```typescript
85
+ const builder = createTableBuilder()
86
+ .addHeader(['Name', 'Score'])
87
+
88
+ for (const student of students) {
89
+ builder.addRow([student.name, student.score])
90
+ }
91
+
92
+ builder
93
+ .setTheme('grid')
94
+ .setAlternateRowStyles({ fillColor: '#f5f5f5' })
95
+ .build()
96
+ ```
97
+
98
+ ### With Helper Utilities
99
+
100
+ ```typescript
101
+ import { useJsPdf, fromObjects, formatCurrency } from 'vue-pdfiy'
102
+
103
+ const { createTableBuilder, savePdf } = useJsPdf({ orientation: 'p', unit: 'mm', format: 'a4' })
104
+
105
+ const data = [
106
+ { product: 'Laptop', price: 999, quantity: 5 },
107
+ { product: 'Mouse', price: 29, quantity: 10 }
108
+ ]
109
+
110
+ const { header, body } = fromObjects(data)
111
+
112
+ createTableBuilder()
113
+ .setHeader(header)
114
+ .addRows(body)
115
+ .build()
116
+
117
+ savePdf('report.pdf')
118
+ ```
119
+
120
+ ## Documentation
121
+
122
+ - [TableBuilder API Documentation](./docs/TABLE_BUILDER.md) - Comprehensive API reference
123
+ - [Examples](./examples/tableBuilderExample.ts) - Real-world usage examples
124
+
125
+ ## API Overview
126
+
127
+ ### useJsPdf Composable
128
+
129
+ The main composable provides methods for PDF creation:
130
+
131
+ #### PDF Methods
132
+ - `pdf` - Access to the underlying jsPDF instance
133
+ - `fileId(id)` - Set PDF file ID
134
+ - `savePdf(filename)` - Save PDF to file
135
+
136
+ #### Text Methods
137
+ - `addText(text, x, y)` - Add text to PDF
138
+ - `setFont(name, style, weight)` - Set font
139
+ - `setFontSize(size)` - Set font size
140
+ - `textColor(r, g, b, alpha)` - Set text color
141
+ - `loadCustomFontFn(path, name, family, style)` - Load custom font
142
+
143
+ #### Page Methods
144
+ - `addPage(format, orientation)` - Add new page
145
+ - `setPage(pageNumber)` - Set active page
146
+ - `movePage(target, before)` - Move page
147
+ - `deletePage(pageNumber)` - Delete page
148
+
149
+ #### Drawing Methods
150
+ - `drawLine(x1, y1, x2, y2, style)` - Draw line
151
+ - `createCircle(x, y, r, style)` - Draw circle
152
+ - `lineCap(cap)` - Set line cap style
153
+ - `lineDashPattern(pattern, phase)` - Set dash pattern
154
+ - `lineWidth(width)` - Set line width
155
+ - `drawColor(r, g, b, alpha)` - Set draw color
156
+ - `fillColor(r, g, b, alpha)` - Set fill color
157
+
158
+ #### Table Methods
159
+ - `createTable(content, options)` - Create table (declarative)
160
+ - `createTableBuilder(config)` - Create table builder (programmatic)
161
+
162
+ ### Helper Utilities
163
+
164
+ - `fromObjects(data)` - Convert object array to table data
165
+ - `fromKeys(obj)` - Extract keys from object
166
+ - `formatCurrency(value, currency)` - Format number as currency
167
+ - `formatDate(date, format)` - Format date
168
+ - `createTotalRow(label, data, columnIndices)` - Create total row
169
+
170
+ ## TableBuilder Methods
171
+
172
+ ### Header
173
+ - `addHeader(row)` - Add header row
174
+ - `setHeader(rows)` - Set entire header
175
+ - `clearHeader()` - Clear header
176
+
177
+ ### Body
178
+ - `addRow(row)` - Add single row
179
+ - `addRows(rows)` - Add multiple rows
180
+ - `setBody(rows)` - Set entire body
181
+ - `clearBody()` - Clear body
182
+
183
+ ### Footer
184
+ - `addFooter(row)` - Add footer row
185
+ - `setFooter(rows)` - Set entire footer
186
+ - `clearFooter()` - Clear footer
187
+
188
+ ### Styling
189
+ - `setTheme(theme)` - Set table theme
190
+ - `setHeaderStyles(styles)` - Style header
191
+ - `setBodyStyles(styles)` - Style body
192
+ - `setFooterStyles(styles)` - Style footer
193
+ - `setAlternateRowStyles(styles)` - Style alternate rows
194
+ - `setColumnStyles(index, styles)` - Style specific column
195
+
196
+ ### Layout
197
+ - `setMargin(margin)` - Set table margins
198
+ - `setStartY(y)` - Set starting Y position
199
+ - `setTableWidth(width)` - Set table width
200
+
201
+ ### Build
202
+ - `build(pdf?)` - Build and render table
203
+ - `getContent()` - Get content configuration
204
+ - `getOptions()` - Get options configuration
205
+ - `reset()` - Reset builder
206
+ - `clone()` - Clone builder
207
+
208
+ ## When to Use What
209
+
210
+ ### Use `createTable` when:
211
+ - ✓ You have all data upfront
212
+ - ✓ Simple table structure
213
+ - ✓ One-time generation
214
+
215
+ ### Use `createTableBuilder` when:
216
+ - ✓ Building tables dynamically
217
+ - ✓ Conditional rows/styling
218
+ - ✓ Programmatic generation in loops
219
+ - ✓ Complex styling requirements
220
+
221
+ ## TypeScript Support
222
+
223
+ Full TypeScript definitions are included:
224
+
225
+ ```typescript
226
+ import type {
227
+ TableBuilder,
228
+ TableBuilderConfig,
229
+ TableHelpers,
230
+ AutoTableContent,
231
+ AutoTableOptions
232
+ } from 'vue-pdfiy'
233
+ ```
234
+
235
+ ## Examples
236
+
237
+ Check out the [examples directory](./examples) for comprehensive usage examples:
238
+ - Simple tables
239
+ - Styled tables
240
+ - Dynamic generation
241
+ - Multi-page reports
242
+ - Invoice generation
243
+ - And more...
244
+
245
+ ## Recommended IDE Setup
246
+
247
+ [VS Code](https://code.visualstudio.com/) + [Vue (Official)](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
248
+
249
+ ## Recommended Browser Setup
250
+
251
+ - Chromium-based browsers (Chrome, Edge, Brave, etc.):
252
+ - [Vue.js devtools](https://chromewebstore.google.com/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd)
253
+ - [Turn on Custom Object Formatter in Chrome DevTools](http://bit.ly/object-formatters)
254
+ - Firefox:
255
+ - [Vue.js devtools](https://addons.mozilla.org/en-US/firefox/addon/vue-js-devtools/)
256
+ - [Turn on Custom Object Formatter in Firefox DevTools](https://fxdx.dev/firefox-devtools-custom-object-formatters/)
257
+
258
+ ## Type Support for `.vue` Imports in TS
259
+
260
+ TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
261
+
262
+ ## Customize configuration
263
+
264
+ See [Vite Configuration Reference](https://vite.dev/config/).
265
+
266
+ ## Project Setup
267
+
268
+ ```sh
269
+ bun install
270
+ ```
271
+
272
+ ### Compile and Hot-Reload for Development
273
+
274
+ ```sh
275
+ bun dev
276
+ ```
277
+
278
+ ### Type-Check, Compile and Minify for Production
279
+
280
+ ```sh
281
+ bun run build
282
+ ```
283
+
284
+ ### Run Unit Tests with [Vitest](https://vitest.dev/)
285
+
286
+ ```sh
287
+ bun test:unit
288
+ ```
289
+
290
+ ### Lint with [ESLint](https://eslint.org/)
291
+
292
+ ```sh
293
+ bun lint
294
+ ```
@@ -0,0 +1,49 @@
1
+ ---
2
+ outline: deep
3
+ ---
4
+
5
+ # Runtime API Examples
6
+
7
+ This page demonstrates usage of some of the runtime APIs provided by VitePress.
8
+
9
+ The main `useData()` API can be used to access site, theme, and page data for the current page. It works in both `.md` and `.vue` files:
10
+
11
+ ```md
12
+ <script setup>
13
+ import { useData } from 'vitepress'
14
+
15
+ const { theme, page, frontmatter } = useData()
16
+ </script>
17
+
18
+ ## Results
19
+
20
+ ### Theme Data
21
+ <pre>{{ theme }}</pre>
22
+
23
+ ### Page Data
24
+ <pre>{{ page }}</pre>
25
+
26
+ ### Page Frontmatter
27
+ <pre>{{ frontmatter }}</pre>
28
+ ```
29
+
30
+ <script setup>
31
+ import { useData } from 'vitepress'
32
+
33
+ const { site, theme, page, frontmatter } = useData()
34
+ </script>
35
+
36
+ ## Results
37
+
38
+ ### Theme Data
39
+ <pre>{{ theme }}</pre>
40
+
41
+ ### Page Data
42
+ <pre>{{ page }}</pre>
43
+
44
+ ### Page Frontmatter
45
+ <pre>{{ frontmatter }}</pre>
46
+
47
+ ## More
48
+
49
+ Check out the documentation for the [full list of runtime APIs](https://vitepress.dev/reference/runtime-api#usedata).