feat(core): Enhance document generation capabilities with improved modular structure and extended translation support.

This commit is contained in:
Philipp Kunz 2024-12-01 23:04:28 +01:00
parent ab2c1e21f2
commit 4c9b2671a9
23 changed files with 104 additions and 78 deletions

View File

@ -1,5 +1,14 @@
# Changelog # Changelog
## 2024-12-01 - 1.2.0 - feat(core)
Enhance document generation capabilities with improved modular structure and extended translation support.
- Enhanced document generation framework with a more modular structure.
- Integrated support for translations using JSON-based language maps.
- Optimized PDF generation process for dynamic document content.
- Added properties in 'IDocumentSettings' for language code management.
- Updated README documentation with more comprehensive examples and guidance.
## 2024-11-30 - 1.1.0 - feat(core) ## 2024-11-30 - 1.1.0 - feat(core)
Enhanced document generation features and added translation capabilities Enhanced document generation features and added translation capabilities

View File

@ -5,29 +5,26 @@
"githost": "code.foss.global", "githost": "code.foss.global",
"gitscope": "designestate/private", "gitscope": "designestate/private",
"gitrepo": "dedocument-catalog", "gitrepo": "dedocument-catalog",
"description": "A versatile tool for dynamically generating and rendering business documents, such as invoices, using modern web technologies and elements.", "description": "A comprehensive tool for dynamically generating and rendering business documents like invoices using modern web technologies.",
"npmPackagename": "@designestate_private/dedocument-catalog", "npmPackagename": "@designestate_private/dedocument-catalog",
"license": "MIT", "license": "MIT",
"projectDomain": "design.estate", "projectDomain": "design.estate",
"shortDescription": "undefined variable", "shortDescription": "undefined variable",
"keywords": [ "keywords": [
"document generation", "document generation",
"invoices", "invoice automation",
"PDF creation",
"TypeScript",
"web components",
"templating",
"dynamic rendering",
"responsive design",
"business documentation", "business documentation",
"automated workflows", "dynamic rendering",
"modular architecture", "PDF creation",
"smart contracts", "web components",
"javascript", "Node.js",
"TypeScript",
"templating",
"modern web technologies",
"responsive design",
"QR code", "QR code",
"custom elements", "modular architecture",
"nodejs", "automated workflows"
"data-driven"
] ]
} }
}, },

View File

@ -2,7 +2,7 @@
"name": "@design.estate/dees-document", "name": "@design.estate/dees-document",
"version": "1.1.0", "version": "1.1.0",
"private": false, "private": false,
"description": "A versatile tool for dynamically generating and rendering business documents, such as invoices, using modern web technologies and elements.", "description": "A comprehensive tool for dynamically generating and rendering business documents like invoices using modern web technologies.",
"main": "dist_ts_web/index.js", "main": "dist_ts_web/index.js",
"typings": "dist_ts_web/index.d.ts", "typings": "dist_ts_web/index.d.ts",
"exports": { "exports": {
@ -28,6 +28,7 @@
"@push.rocks/smartpdf": "^3.1.8", "@push.rocks/smartpdf": "^3.1.8",
"@push.rocks/smarttime": "^4.0.8", "@push.rocks/smarttime": "^4.0.8",
"@tsclass/tsclass": "^4.1.2", "@tsclass/tsclass": "^4.1.2",
"@types/node": "^22.10.1",
"@types/qrcode": "^1.5.5", "@types/qrcode": "^1.5.5",
"qrcode": "^1.5.4" "qrcode": "^1.5.4"
}, },
@ -65,21 +66,18 @@
"homepage": "https://gitlab.com/designestate/private/dedocument-catalog#readme", "homepage": "https://gitlab.com/designestate/private/dedocument-catalog#readme",
"keywords": [ "keywords": [
"document generation", "document generation",
"invoices", "invoice automation",
"PDF creation",
"TypeScript",
"web components",
"templating",
"dynamic rendering",
"responsive design",
"business documentation", "business documentation",
"automated workflows", "dynamic rendering",
"modular architecture", "PDF creation",
"smart contracts", "web components",
"javascript", "Node.js",
"TypeScript",
"templating",
"modern web technologies",
"responsive design",
"QR code", "QR code",
"custom elements", "modular architecture",
"nodejs", "automated workflows"
"data-driven"
] ]
} }

3
pnpm-lock.yaml generated
View File

@ -38,6 +38,9 @@ importers:
'@tsclass/tsclass': '@tsclass/tsclass':
specifier: ^4.1.2 specifier: ^4.1.2
version: 4.1.2 version: 4.1.2
'@types/node':
specifier: ^22.10.1
version: 22.10.1
'@types/qrcode': '@types/qrcode':
specifier: ^1.5.5 specifier: ^1.5.5
version: 1.5.5 version: 1.5.5

View File

@ -1,31 +1,32 @@
```markdown
# @design.estate/dees-document # @design.estate/dees-document
A comprehensive solution for generating documents like invoices, integrating elements, templates, and services to streamline document creation. A versatile tool for dynamically generating and rendering business documents, such as invoices, using modern web technologies and elements.
## Install ## Install
To add `@design.estate/dees-document` to your project, run the following command in your terminal: To incorporate `@design.estate/dees-document` into your project, execute the following command in your terminal:
```shell ```shell
npm install @design.estate/dees-document --save npm install @design.estate/dees-document --save
``` ```
This will install the package and add it to your project's dependencies, ensuring all required modules are available in your `node_modules` directory. This command will install the package and add it to your project's dependencies, thus making all the necessary modules available within your `node_modules` directory.
## Usage ## Usage
The `@design.estate/dees-document` package provides a robust framework for creating documents including invoices, contracts, and various other business-related documents. It is built on modern web technologies including TypeScript and ES modules to ensure a type-safe and easy-to-integrate experience. Below, we will guide you through the comprehensive usage of this package, from setting up your environment to generating PDF documents. The `@design.estate/dees-document` package serves as a robust framework to facilitate the generation of business documents, such as invoices and contracts. Leveraging modern web technologies, this package integrates seamlessly with TypeScript and ES modules, offering a type-safe environment conducive to efficient, dynamic document creation. Presented here is a comprehensive guide to utilizing this package, ranging from initializing your environment to generating complete PDF documents.
### Getting Started ### Getting Started
Before creating documents, initialize the document service which is central to this package. This is typically done at the beginning of your application. To embark on a document creation journey, initiate the document service. This service constitutes the core of this package and is typically started at the application's outset.
```typescript ```typescript
import { PdfService, IPdfServiceConstructorOptions } from '@design.estate/dees-document'; import { PdfService, IPdfServiceConstructorOptions } from '@design.estate/dees-document';
async function setupPdfService() { async function setupPdfService() {
const options: IPdfServiceConstructorOptions = { const options: IPdfServiceConstructorOptions = {
// Add necessary configuration here // configure your options here
}; };
const pdfService = await PdfService.createAndStart(options); const pdfService = await PdfService.createAndStart(options);
@ -34,15 +35,15 @@ async function setupPdfService() {
} }
``` ```
This script initializes `PdfService`. Modify the options to tailor the service to your needs. The above code initializes the `PdfService`. Tailor the configuration options to suit your specific requirements.
### Creating Documents ### Creating Documents
With the PDF service ready, you can proceed to generate documents. The following section provides a detailed example of creating an invoice. This example is applicable to various document types with necessary adjustments. With the PDF service initialized, you can now proceed to generate your documents. In the following section, you will find a detailed walkthrough for creating an invoice. This method can be adapted to other document types with necessary modifications.
#### Step-by-Step: Create an Invoice #### Step-by-Step: Create an Invoice
1. **Define the Data Structure**: Describe the invoice details. This includes sender and recipient information, the items being invoiced, and more. 1. **Define the Data Structure**: Construct the details of the invoice, including the sender, recipient information, and the details of the items being invoiced.
```typescript ```typescript
import { ILetter } from '@design.estate/dees-document'; import { ILetter } from '@design.estate/dees-document';
@ -95,22 +96,22 @@ With the PDF service ready, you can proceed to generate documents. The following
}; };
``` ```
Here, `ILetter` interface details all components of an invoice including sender (`from`) and recipient (`to`) information, as well as the invoiced items. The `ILetter` interface captures all the components of an invoice, including both the sender (`from`) and recipient (`to`) information, alongside the details of the invoiced items.
2. **Generate the PDF**: Transform the invoice details into a PDF. 2. **Generate the PDF**: Convert the invoice details into a PDF file.
```typescript ```typescript
async function generateInvoice(pdfService: PdfService, invoiceData: ILetter) { async function generateInvoice(pdfService: PdfService, invoiceData: ILetter) {
const pdfBuffer = await pdfService.createPdfFromLetterObject(invoiceData); const pdfBuffer = await pdfService.createPdfFromLetterObject(invoiceData);
console.log('Invoice PDF generated successfully.'); console.log('Invoice PDF generated successfully.');
// Save the PDF, send it via email, etc. // Here you could save the PDF to your filesystem, send it via email, etc.
} }
``` ```
The function `createPdfFromLetterObject` returns a `Buffer` containing the generated PDF. From here, you can save this PDF to a file, send it to clients, or archive it. The `createPdfFromLetterObject` function returns a `Buffer` that contains the generated PDF, enabling you to save it to a file, send it to clients, or store it for record-keeping.
3. **Integrate It All**: Here's how everything ties together into a complete script for generating an invoice: 3. **Integrate It All**: The following script ties together the PDF service and generates the invoice with the described data.
```typescript ```typescript
async function main() { async function main() {
@ -121,15 +122,15 @@ With the PDF service ready, you can proceed to generate documents. The following
main().then(() => console.log('Invoice generation process completed.')); main().then(() => console.log('Invoice generation process completed.'));
``` ```
This script initiates the PDF service and generates the invoice PDF with the provided information. This example initiates the PDF service and utilizes it to generate a PDF invoice with specified parameters.
### Advanced Document Features ### Advanced Document Features
The package is designed to create not only invoices but a wide range of document types. Leverage its modular architecture to build and customize documents to fit specific needs. The package is designed to create a broad range of documents, far beyond simple invoices. Utilize the modular architecture to customize documents to your specific business requirements.
#### Advanced Scenarios #### Advanced Scenarios
1. **Custom Styling**: Customize the appearance of elements within your documents, such as headers, footers, and more. 1. **Custom Styling**: Alter the visual styles of various elements within your documents, like headers, footers, and more through CSS or inline styles.
```typescript ```typescript
import { DeDocumentViewer } from '@design.estate/dees-element'; import { DeDocumentViewer } from '@design.estate/dees-element';
@ -139,31 +140,33 @@ The package is designed to create not only invoices but a wide range of document
document.body.appendChild(customStyledViewer); document.body.appendChild(customStyledViewer);
``` ```
Customize via CSS or dynamically through TypeScript where necessary. Adjust styles either with standard CSS or via dynamic TypeScript changes.
2. **Interactive Document Elements**: Incorporate UI components like buttons, input fields, or visualizations tailored for your document needs. 2. **Interactive Document Elements**: Integrate interactive UI components, like buttons or input fields, fitting seamlessly into your documents.
3. **Multi-page Document Generation**: Handle overflow of content and automatic page generation while maintaining headers and footers. 3. **Multi-page Document Generation**: Handle content overflow elegantly through automatic page creation, keeping headers and footers intact.
```typescript ```typescript
pdfService.adjustDePageScaling(); pdfService.adjustDePageScaling();
``` ```
Toggle between print and digital formats and handle scaling. Adapt between print and digital formats, managing scaling effectively.
4. **Embedding Images and Logos**: Add company logos, graphics, or auxiliary content to enhance document presentation. 4. **Embedding Images and Logos**: Enhance your document's appearance with company logos, graphics, and other auxiliary content.
### Additional Capabilities ### Additional Capabilities
Beyond these examples, delve deeper into advanced functionalities such as: Beyond basic functionality, this package offers a range of advanced features:
- **Document Management**: Manage multiple document templates, manage versions, and add annotations or notes. - **Document Management**: Manage multiple document templates, maintain version control, and append annotations or notes.
- **Dynamic Rendering**: Use templating for dynamic content rendering based on variable inputs. - **Dynamic Rendering**: Utilize templating engines to render dynamic content based on input variables.
- **Responsive Design for Digital Documents**: Ensure documents are displayed correctly across devices. - **Responsive Design for Digital Documents**: Ensure your documents are consistently displayed across various devices.
### Concluding Remarks ### Concluding Remarks
The `@design.estate/dees-document` package is an essential tool in the modern document generation ecosystem. Its expansive capabilities, from basic invoices to complex document templates, make it a versatile solution for businesses of all scales. Implementing this service broadly simplifies document management workflows and enhances document presentation precision and quality. For further depth, consult the package's documentation or explore the examples included in the module. The `@design.estate/dees-document` package presents a powerful solution within the modern document generation realm. From basic invoices to intricate templates, this package provides the essential tools for businesses to streamline their document workflows and enhance their presentation quality and accuracy. Explore further depth by consulting the packages detailed documentation or by reviewing the examples included within the module.
```
## License and Legal Information ## License and Legal Information

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@design.estate/dees-document', name: '@design.estate/dees-document',
version: '1.1.0', version: '1.2.0',
description: 'A versatile tool for dynamically generating and rendering business documents, such as invoices, using modern web technologies and elements.' description: 'A comprehensive tool for dynamically generating and rendering business documents like invoices using modern web technologies.'
} }

View File

@ -1,5 +1,8 @@
import * as shared from '../shared/index.js';
export interface IDocumentSettings { export interface IDocumentSettings {
enableTopDraftText?: boolean; enableTopDraftText?: boolean;
enableDefaultHeader?: boolean; enableDefaultHeader?: boolean;
enableDefaultFooter?: boolean; enableDefaultFooter?: boolean;
languageCode?: shared.translation.TLanguageCode;
} }

View File

@ -1,4 +1,6 @@
import * as tsclass from '@tsclass/tsclass'; import * as tsclass from '@tsclass/tsclass';
import * as interfaces from '../interfaces/index.js';
const fromContact: tsclass.business.IContact = { const fromContact: tsclass.business.IContact = {
name: 'Awesome From Company', name: 'Awesome From Company',
type: 'company', type: 'company',
@ -207,4 +209,11 @@ export const demoLetter: tsclass.business.ILetter = {
logoUrl: null, logoUrl: null,
pdfAttachments: null, pdfAttachments: null,
subject: 'Invoice: LL-INV-48765', subject: 'Invoice: LL-INV-48765',
} }
export const demoDocumentSettings: interfaces.IDocumentSettings = {
enableTopDraftText: true,
enableDefaultHeader: true,
enableDefaultFooter: true,
languageCode: 'DE',
};

View File

@ -6,4 +6,4 @@ export const leftMargin = 90;
import * as translation from './translation.js'; import * as translation from './translation.js';
export { translation }; export { translation };
export * from './demoletter.js'; export * from './demoletter.js';

View File

@ -1,4 +1,4 @@
import * as interfaces from '../../../ts/interfaces/index.js'; import * as interfaces from '../interfaces/index.js';
type TTranslationImplementation = { type TTranslationImplementation = {
[key in keyof interfaces.IDeDocumentTranslations]: string; [key in keyof interfaces.IDeDocumentTranslations]: string;

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@design.estate/dees-document', name: '@design.estate/dees-document',
version: '1.1.0', version: '1.2.0',
description: 'A versatile tool for dynamically generating and rendering business documents, such as invoices, using modern web technologies and elements.' description: 'A comprehensive tool for dynamically generating and rendering business documents like invoices using modern web technologies.'
} }

View File

@ -15,7 +15,7 @@ import {
domtools, domtools,
} from '@design.estate/dees-element'; } from '@design.estate/dees-element';
import * as plugins from '../plugins.js'; import * as plugins from '../plugins.js';
import * as shared from './shared/index.js'; import * as shared from '../../ts/shared/index.js';

View File

@ -1,4 +1,4 @@
import * as shared from './shared/index.js'; import * as shared from '../../ts/shared/index.js';
import { html } from '@design.estate/dees-element'; import { html } from '@design.estate/dees-element';
export const demoFunc = () => html` export const demoFunc = () => html`

View File

@ -24,7 +24,7 @@ export const defaultDocumentSettings: interfaces.IDocumentSettings = {
import { DePage } from './page.js'; import { DePage } from './page.js';
import { DeContentInvoice } from './contentinvoice.js'; import { DeContentInvoice } from './contentinvoice.js';
import * as shared from './shared/index.js'; import * as shared from '../../ts/shared/index.js';
import { demoFunc } from './document.demo.js'; import { demoFunc } from './document.demo.js';
declare global { declare global {

View File

@ -8,4 +8,4 @@ export * from './pagefooter.js';
export * from './pageheader.js'; export * from './pageheader.js';
export * from './viewer.js'; export * from './viewer.js';
export * from './shared/index.js'; export * from '../../ts/shared/index.js';

View File

@ -10,7 +10,7 @@ import {
} from '@design.estate/dees-element'; } from '@design.estate/dees-element';
import * as domtools from '@design.estate/dees-domtools'; import * as domtools from '@design.estate/dees-domtools';
import * as shared from './shared/index.js'; import * as shared from '../../ts/shared/index.js';
import * as tsclass from '@tsclass/tsclass'; import * as tsclass from '@tsclass/tsclass';
declare global { declare global {

View File

@ -15,7 +15,7 @@ import * as interfaces from '../../ts/interfaces/index.js';
import { defaultDocumentSettings } from './document.js'; import { defaultDocumentSettings } from './document.js';
import * as shared from './shared/index.js'; import * as shared from '../../ts/shared/index.js';
declare global { declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {

View File

@ -10,7 +10,7 @@ import {
} from '@design.estate/dees-element'; } from '@design.estate/dees-element';
import * as domtools from '@design.estate/dees-domtools'; import * as domtools from '@design.estate/dees-domtools';
import * as shared from './shared/index.js'; import * as shared from '../../ts/shared/index.js';
declare global { declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {

View File

@ -10,7 +10,7 @@ import {
} from '@design.estate/dees-element'; } from '@design.estate/dees-element';
import * as domtools from '@design.estate/dees-domtools'; import * as domtools from '@design.estate/dees-domtools';
import * as shared from './shared/index.js'; import * as shared from '../../ts/shared/index.js';
import * as tsclass from '@tsclass/tsclass'; import * as tsclass from '@tsclass/tsclass';
declare global { declare global {

View File

@ -10,7 +10,7 @@ import {
} from '@design.estate/dees-element'; } from '@design.estate/dees-element';
import * as domtools from '@design.estate/dees-domtools'; import * as domtools from '@design.estate/dees-domtools';
import * as shared from './shared/index.js'; import * as shared from '../../ts/shared/index.js';
import * as tsclass from '@tsclass/tsclass'; import * as tsclass from '@tsclass/tsclass';
declare global { declare global {

View File

@ -10,7 +10,7 @@ import {
} from '@design.estate/dees-element'; } from '@design.estate/dees-element';
import * as domtools from '@design.estate/dees-domtools'; import * as domtools from '@design.estate/dees-domtools';
import * as shared from './shared/index.js'; import * as shared from '../../ts/shared/index.js';
import * as tsclass from '@tsclass/tsclass'; import * as tsclass from '@tsclass/tsclass';
declare global { declare global {

View File

@ -1,6 +1,6 @@
import { html } from '@design.estate/dees-element'; import { html } from '@design.estate/dees-element';
import * as shared from './shared/index.js'; import * as shared from '../../ts/shared/index.js';
export const demoFunc = () => html` export const demoFunc = () => html`
<dedocument-viewer .letterData=${shared.demoLetter}></dedocument-viewer> <dedocument-viewer .letterData=${shared.demoLetter} .documentSettings=${shared.demoDocumentSettings}></dedocument-viewer>
`; `;

View File

@ -1,7 +1,9 @@
import * as plugins from '../plugins.js'; import * as plugins from '../plugins.js';
import * as interfaces from '../../ts/interfaces/index.js';
import { DeesElement, css, cssManager, customElement, html } from '@design.estate/dees-element'; import { DeesElement, css, cssManager, customElement, html } from '@design.estate/dees-element';
import { demoFunc } from './viewer.demo.js'; import { demoFunc } from './viewer.demo.js';
import { defaultDocumentSettings } from './document.js';
declare global { declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {
@ -17,6 +19,8 @@ export class DeDocumentViewer extends DeesElement {
// INSTANCE // INSTANCE
public letterData: plugins.tsclass.business.ILetter = null; public letterData: plugins.tsclass.business.ILetter = null;
public documentSettings: interfaces.IDocumentSettings = defaultDocumentSettings;
public static styles = [ public static styles = [
cssManager.defaultStyles, cssManager.defaultStyles,
css` css`
@ -67,7 +71,7 @@ export class DeDocumentViewer extends DeesElement {
<div class="maincontainer"> <div class="maincontainer">
<div class="viewport"> <div class="viewport">
${this.letterData ${this.letterData
? html` <dedocument-dedocument .letterData=${this.letterData}></dedocument-dedocument> ` ? html` <dedocument-dedocument .letterData=${this.letterData} .documentSettings=${this.documentSettings}></dedocument-dedocument> `
: html``} : html``}
</div> </div>
<div class="controls"></div> <div class="controls"></div>