Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d564b9562 | ||
|
|
ac78e6c74d | ||
|
|
bed5243fd5 | ||
|
|
3a1734c477 | ||
|
|
7279b93e4c | ||
|
|
1d940892d7 | ||
|
|
612ed7b631 | ||
|
|
fcd74152bb | ||
|
|
3451c86b36 | ||
|
|
fc49c91024 | ||
|
|
c3c4027511 | ||
|
|
a0fffb6cf7 | ||
|
|
f9c1045557 | ||
|
|
b759c032a8 | ||
|
|
851bc738e5 | ||
|
|
049c77a004 | ||
|
|
b16967c351 | ||
|
|
986d50a5eb | ||
|
|
a246f899f4 | ||
|
|
b5c6b5510e | ||
|
|
1e61719838 | ||
|
|
227188b012 | ||
|
|
790c043c70 | ||
|
|
02bba5fef0 | ||
|
|
c3a1b4566a | ||
|
|
7e90096586 | ||
|
|
158653e726 | ||
|
|
f0106cfd53 | ||
|
|
91d8af2079 | ||
|
|
a7229712ad |
@@ -4,77 +4,11 @@ variables:
|
|||||||
|
|
||||||
include:
|
include:
|
||||||
- project: '$CI_PROJECT_ROOT_NAMESPACE/ci-tools/pipeline/ci-tools-pipeline-release'
|
- project: '$CI_PROJECT_ROOT_NAMESPACE/ci-tools/pipeline/ci-tools-pipeline-release'
|
||||||
ref: 1.0.0
|
ref: 2.0.0
|
||||||
file: '/release-common.yml'
|
file: '/release-common.yml'
|
||||||
- project: '$CI_PROJECT_ROOT_NAMESPACE/ci-tools/pipeline/ci-tools-pipeline-release-node'
|
- project: '$CI_PROJECT_ROOT_NAMESPACE/ci-tools/pipeline/ci-tools-pipeline-release-node'
|
||||||
ref: 1.0.1
|
ref: 1.0.2
|
||||||
file: '/release-node.yml'
|
file: '/release-node.yml'
|
||||||
- project: '$CI_PROJECT_ROOT_NAMESPACE/ci-tools/pipeline/ci-tools-pipeline-project-foundry-module'
|
- project: '$CI_PROJECT_ROOT_NAMESPACE/ci-tools/pipeline/ci-tools-pipeline-project-foundry-module'
|
||||||
ref: 0.2.2
|
ref: 1.1.0
|
||||||
file: '/pipeline-foundry-module.yml'
|
file: '/pipeline-foundry-module.yml'
|
||||||
|
|
||||||
#image: node:14.15.5-stretch-slim
|
|
||||||
#
|
|
||||||
#variables:
|
|
||||||
# GIT_DEPTH: 0
|
|
||||||
# GIT_STRATEGY: fetch
|
|
||||||
#
|
|
||||||
#stages:
|
|
||||||
# - build
|
|
||||||
# - release
|
|
||||||
#
|
|
||||||
#build:
|
|
||||||
# stage: build
|
|
||||||
# image: $CI_REGISTRY/$CI_PROJECT_ROOT_NAMESPACE/ci-tools/docker/ci-tools-docker-node-14:1.0.0
|
|
||||||
# variables:
|
|
||||||
# MODULE_DIRS: lang styles
|
|
||||||
# MODULE_ZIP_DIRS: elements lang styles
|
|
||||||
# extends: .build
|
|
||||||
#
|
|
||||||
#.build:
|
|
||||||
# stage: build
|
|
||||||
# image: $CI_REGISTRY/$CI_PROJECT_ROOT_NAMESPACE/ci-tools/docker/ci-tools-docker-node-14:1.0.0
|
|
||||||
# before_script:
|
|
||||||
# - npm ci
|
|
||||||
# - npm run build
|
|
||||||
# script:
|
|
||||||
# - cp -r $MODULE_DIRS dist/
|
|
||||||
# - cp module.json dist
|
|
||||||
# - cd dist
|
|
||||||
# - zip $CI_PROJECT_NAME.zip -r *.* $MODULE_ZIP_DIRS -x ".*"
|
|
||||||
# - echo ARTIFACT_LOC="${CI_JOB_URL}/artifacts/raw" > $CI_PROJECT_DIR/variables.env
|
|
||||||
# artifacts:
|
|
||||||
# name: $CI_COMMIT_REF_NAME
|
|
||||||
# when: on_success
|
|
||||||
# reports:
|
|
||||||
# dotenv: variables.env
|
|
||||||
# paths:
|
|
||||||
# - dist/$CI_PROJECT_NAME.zip
|
|
||||||
# - dist/module.json
|
|
||||||
# expire_in: never
|
|
||||||
# only:
|
|
||||||
# - tags
|
|
||||||
# - master
|
|
||||||
# - main
|
|
||||||
#
|
|
||||||
#release:
|
|
||||||
# stage: release
|
|
||||||
# image: registry.gitlab.com/gitlab-org/release-cli:latest
|
|
||||||
# script:
|
|
||||||
# - echo 'Running the release job.'
|
|
||||||
# release:
|
|
||||||
# tag_name: $CI_COMMIT_TAG
|
|
||||||
# name: 'Release $CI_COMMIT_TAG'
|
|
||||||
# description: './CHANGELOG.md'
|
|
||||||
# assets:
|
|
||||||
# links:
|
|
||||||
# - name: 'module'
|
|
||||||
# url: '$ARTIFACT_LOC/dist/$CI_PROJECT_NAME.zip'
|
|
||||||
# filepath: '/dist/$CI_PROJECT_NAME.zip'
|
|
||||||
# link_type: package
|
|
||||||
# - name: 'manifest'
|
|
||||||
# url: '$ARTIFACT_LOC/dist/module.json'
|
|
||||||
# filepath: '/dist/module.json'
|
|
||||||
# link_type: package
|
|
||||||
# only:
|
|
||||||
# - tags
|
|
||||||
|
|||||||
11
CHANGELOG.md
11
CHANGELOG.md
@@ -1,5 +1,16 @@
|
|||||||
## In development
|
## In development
|
||||||
|
|
||||||
|
## 1.2.0
|
||||||
|
|
||||||
|
### New features
|
||||||
|
|
||||||
|
- HTML Responsive Export Characters sheet
|
||||||
|
- Add contextual menu to actor to HTML responsive Export Characters sheet
|
||||||
|
|
||||||
|
## 1.1.0
|
||||||
|
|
||||||
|
- Add contextual menu to actor to PDF Export Characters sheet
|
||||||
|
|
||||||
## 1.0.0
|
## 1.0.0
|
||||||
|
|
||||||
### New features
|
### New features
|
||||||
|
|||||||
14
README.md
14
README.md
@@ -1,6 +1,6 @@
|
|||||||
# WFRP 4 Actor Sheet Print
|
# WFRP 4 Actor Sheet Print
|
||||||
|
|
||||||
This module allow to export characters sheet on a friendly print pdf.
|
This module allow to export characters sheet on a friendly print pdf or a responsive html.
|
||||||
|
|
||||||
# Authors
|
# Authors
|
||||||
|
|
||||||
@@ -28,12 +28,8 @@ A print buton is added on top of sheet to export as pdf
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
A Contextual menu is added on Actor menu, one for pdf, an other for html
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Comming soon
|
## Comming soon
|
||||||
|
|
||||||
## Module link
|
|
||||||
|
|
||||||
https://raw.githubusercontent.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/dist/module.json
|
|
||||||
|
|
||||||
## Module Beta link
|
|
||||||
|
|
||||||
https://raw.githubusercontent.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/dist-beta/module-beta.json
|
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
{}
|
{
|
||||||
|
"WFRP4SHEETPRINT.export.pdf": "Export to PDF",
|
||||||
|
"WFRP4SHEETPRINT.export.html": "Export to Html"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
{}
|
{
|
||||||
|
"WFRP4SHEETPRINT.export.pdf": "Exporter en PDF",
|
||||||
|
"WFRP4SHEETPRINT.export.html": "Exporter en Html"
|
||||||
|
}
|
||||||
|
|||||||
6
local-deploy.sh
Normal file
6
local-deploy.sh
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cp -r ./dist/* $LOCAL_FOUNDRY
|
||||||
|
|
||||||
|
|
||||||
BIN
media/actor-sheet-print-actor-button.png
Executable file
BIN
media/actor-sheet-print-actor-button.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 83 KiB |
49
module.json
49
module.json
@@ -1,30 +1,51 @@
|
|||||||
{
|
{
|
||||||
"name": "wfrp4e-actor-sheet-print",
|
"id": "wfrp4e-actor-sheet-print",
|
||||||
"title": "[WFRP4] Actor Sheet Print",
|
"title": "[WFRP4] Actor Sheet Print",
|
||||||
"description": "Functions to print actor sheet",
|
"description": "Functions to print actor sheet",
|
||||||
"version": "1.0.2",
|
"version": "${MODULE_VERSION}",
|
||||||
"minimumCoreVersion": "0.8.0",
|
"compatibility": {
|
||||||
"compatibleCoreVersion": "0.8.9",
|
"minimum": "11",
|
||||||
"author": "Skeroujvapluvit",
|
"verified": "11.315",
|
||||||
"systems": ["wfrp4e"],
|
"maximum": "11"
|
||||||
"dependencies": [],
|
},
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Skeroujvapluvit",
|
||||||
|
"flags": {}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"relationships": {
|
||||||
|
"systems": [
|
||||||
|
{
|
||||||
|
"id": "wfrp4e",
|
||||||
|
"type": "system",
|
||||||
|
"compatibility": {
|
||||||
|
"minimum": "7.1.6",
|
||||||
|
"verified": "7.1.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"requires": []
|
||||||
|
},
|
||||||
"esmodules": ["main.js"],
|
"esmodules": ["main.js"],
|
||||||
"languages": [
|
"languages": [
|
||||||
{
|
{
|
||||||
"lang": "en",
|
"lang": "en",
|
||||||
"name": "English",
|
"name": "English",
|
||||||
"path": "lang/en.json"
|
"path": "lang/en.json",
|
||||||
|
"flags": {}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"lang": "fr",
|
"lang": "fr",
|
||||||
"name": "Français",
|
"name": "Français",
|
||||||
"path": "lang/fr.json"
|
"path": "lang/fr.json",
|
||||||
|
"flags": {}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"styles": ["./styles/main.css"],
|
"styles": ["./styles/main.css"],
|
||||||
"url": "https://github.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print",
|
"url": "https://gitlab.com/greenskin-foundryvtt/wfrp4-actor-sheet-print",
|
||||||
"download": "https://github.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/blob/dist/dist/wfrp4e-actor-sheet-print.zip?raw=true",
|
"download": "https://gitlab.com/greenskin-foundryvtt/wfrp4-actor-sheet-print/-/releases/${MODULE_VERSION}/downloads/dist/wfrp4-actor-sheet-print.zip",
|
||||||
"manifest": "https://raw.githubusercontent.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/dist/module.json",
|
"manifest": "https://gitlab.com/greenskin-foundryvtt/wfrp4-actor-sheet-print/-/releases/${MODULE_VERSION}/downloads/dist/module.json",
|
||||||
"readme": "https://raw.githubusercontent.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/dist/README.md",
|
"readme": "https://gitlab.com/greenskin-foundryvtt/wfrp4-actor-sheet-print/-/raw/${MODULE_VERSION}/README.md",
|
||||||
"changelog": "https://raw.githubusercontent.com/mcailleaux/WFRP4-FoundryVTT-wfrp4e-actor-sheet-print/dist/CHANGELOG.md"
|
"changelog": "https://gitlab.com/greenskin-foundryvtt/wfrp4-actor-sheet-print/-/raw/${MODULE_VERSION}/CHANGELOG.md"
|
||||||
}
|
}
|
||||||
|
|||||||
3435
package-lock.json
generated
3435
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@@ -2,18 +2,20 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"old-build": "tsc -p tsconfig.json && cp -r ./src ./dist",
|
"old-build": "tsc -p tsconfig.json && cp -r ./src ./dist",
|
||||||
"package": "sh ./package.sh",
|
"package": "sh ./package.sh",
|
||||||
"build": "webpack"
|
"build": "webpack",
|
||||||
|
"local-deploy": "npm run package && sh ./local-deploy.sh"
|
||||||
},
|
},
|
||||||
"version": "1.0.3",
|
"version": "3.1.1",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@league-of-foundry-developers/foundry-vtt-types": "0.8.8-8",
|
"@league-of-foundry-developers/foundry-vtt-types": "0.8.9-9",
|
||||||
"husky": "4.3.7",
|
"husky": "4.3.7",
|
||||||
"prettier": "2.2.1",
|
"prettier": "2.2.1",
|
||||||
"pretty-quick": "3.1.0",
|
"pretty-quick": "3.1.0",
|
||||||
"typescript": "4.3.5",
|
"typescript": "4.5.4",
|
||||||
"ts-loader": "9.2.6",
|
"ts-loader": "9.2.6",
|
||||||
"webpack": "5.58.2",
|
"webpack": "5.65.0",
|
||||||
"webpack-cli": "4.9.0"
|
"webpack-cli": "4.9.1",
|
||||||
|
"@types/file-saver": "2.0.5"
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
@@ -21,6 +23,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"jspdf": "2.4.0"
|
"jspdf": "2.4.0",
|
||||||
|
"file-saver": "2.0.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
package.sh
12
package.sh
@@ -1,6 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
rm -fr dist
|
||||||
npm run build
|
npm run build
|
||||||
mkdir -p ./dist/lang
|
cp -r $MODULE_DIRS dist/
|
||||||
mkdir -p ./dist/styles
|
export MODULE_VERSION=$(jq ".version" package.json | sed -r 's/["]+//g')
|
||||||
cp ./lang/* ./dist/lang/
|
envsubst '${MODULE_VERSION}' < ./module.json > ./dist/module.json
|
||||||
cp ./styles/* ./dist/styles/
|
|
||||||
cp module.json ./dist/module.json
|
|
||||||
|
|||||||
14
src/abstract-builder.ts
Normal file
14
src/abstract-builder.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { AbstractElement } from './elements/abstract-element';
|
||||||
|
import { GenerateTypeEnum } from './elements/generate-type.enum';
|
||||||
|
|
||||||
|
export abstract class AbstractBuilder {
|
||||||
|
public abstract build(elements: AbstractElement[]);
|
||||||
|
|
||||||
|
public abstract getLabelledRowHeight(): number;
|
||||||
|
|
||||||
|
public abstract save(name: string);
|
||||||
|
|
||||||
|
public abstract getImageScale(): number;
|
||||||
|
|
||||||
|
public abstract getGenerateType(): GenerateTypeEnum;
|
||||||
|
}
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
export const i18n = () => (<any>game).i18n;
|
export const i18n = () => (<any>game).i18n;
|
||||||
export const i18nLocalize = (id: string) => i18n().localize(id);
|
export const i18nLocalize = (id: string) => i18n().localize(id);
|
||||||
export const i18nFormat = (id: string, data?: any) => i18n().format(id, data);
|
export const i18nFormat = (id: string, data?: any) => i18n().format(id, data);
|
||||||
|
export const user = () => (<any>game).user;
|
||||||
|
export const isGM = () => user()?.isGM ?? false;
|
||||||
|
|
||||||
export const TEXT_SIZE = 8;
|
export const TEXT_SIZE = 8;
|
||||||
export const LABEL_SIZE = 6;
|
export const LABEL_SIZE = 6;
|
||||||
|
export const HTML_TEXT_SIZE = 1;
|
||||||
|
export const HTML_LABEL_SIZE = 0.75;
|
||||||
export const MARGINS = { top: 10, left: 10, bottom: 10, right: 10 };
|
export const MARGINS = { top: 10, left: 10, bottom: 10, right: 10 };
|
||||||
|
|||||||
38
src/elements/abstract-container-element.ts
Normal file
38
src/elements/abstract-container-element.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { AbstractElement } from './abstract-element';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
|
export abstract class AbstractContainerElement extends AbstractElement {
|
||||||
|
public pdfElements: AbstractElement[] = [];
|
||||||
|
public htmlElements: AbstractElement[] = [];
|
||||||
|
public contextElements: AbstractElement[] = [];
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
globalType: GenerateTypeEnum,
|
||||||
|
x: number,
|
||||||
|
y: number,
|
||||||
|
maxWidth: number | undefined,
|
||||||
|
elements: AbstractElement[] = [],
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
|
) {
|
||||||
|
super(globalType, x, y, maxWidth, context);
|
||||||
|
this.htmlElements = this.context.isHtml
|
||||||
|
? elements.filter((el) => el.context.isHtml)
|
||||||
|
: [];
|
||||||
|
this.pdfElements = this.context.isPdf
|
||||||
|
? elements.filter((el) => el.context.isPdf)
|
||||||
|
: [];
|
||||||
|
this.contextElements =
|
||||||
|
this.globalType === GenerateTypeEnum.HTML
|
||||||
|
? this.htmlElements
|
||||||
|
: this.pdfElements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getElements(): AbstractElement[] {
|
||||||
|
const elements: AbstractElement[] = [];
|
||||||
|
for (const element of this.contextElements) {
|
||||||
|
elements.push(...element.getElements());
|
||||||
|
}
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,36 @@
|
|||||||
import jsPDF from 'jspdf';
|
import jsPDF from 'jspdf';
|
||||||
import { MARGINS } from '../constants';
|
import { MARGINS } from '../constants';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
export abstract class AbstractElement {
|
export abstract class AbstractElement {
|
||||||
|
public static readonly DEFAULT_CONTEXT: IContext = {
|
||||||
|
isHtml: true,
|
||||||
|
isPdf: true,
|
||||||
|
name: 'element',
|
||||||
|
};
|
||||||
|
|
||||||
|
public globalType: GenerateTypeEnum;
|
||||||
public x: number;
|
public x: number;
|
||||||
public y: number;
|
public y: number;
|
||||||
public maxWidth?: number;
|
public maxWidth?: number;
|
||||||
|
public context: IContext = AbstractElement.DEFAULT_CONTEXT;
|
||||||
|
|
||||||
constructor(x: number, y: number, maxWidth?: number | undefined) {
|
constructor(
|
||||||
|
globalType: GenerateTypeEnum,
|
||||||
|
x: number,
|
||||||
|
y: number,
|
||||||
|
maxWidth?: number | undefined,
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
|
) {
|
||||||
|
this.globalType = globalType;
|
||||||
this.x = x >= MARGINS.left ? x : MARGINS.left;
|
this.x = x >= MARGINS.left ? x : MARGINS.left;
|
||||||
this.y = y >= MARGINS.top ? y : MARGINS.top;
|
this.y = y >= MARGINS.top ? y : MARGINS.top;
|
||||||
this.maxWidth = maxWidth;
|
this.maxWidth = maxWidth;
|
||||||
|
this.context = {
|
||||||
|
...this.context,
|
||||||
|
...context,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public getHeightFromPx(doc: jsPDF, size: number) {
|
public getHeightFromPx(doc: jsPDF, size: number) {
|
||||||
@@ -28,6 +49,13 @@ export abstract class AbstractElement {
|
|||||||
|
|
||||||
public abstract render(doc: jsPDF, maxWidth?: number): jsPDF;
|
public abstract render(doc: jsPDF, maxWidth?: number): jsPDF;
|
||||||
|
|
||||||
|
public abstract renderHtml(
|
||||||
|
doc: Document,
|
||||||
|
parent: HTMLElement,
|
||||||
|
cssRules: string[],
|
||||||
|
sheet: HTMLStyleElement
|
||||||
|
): Document;
|
||||||
|
|
||||||
public abstract getHeight(doc?: jsPDF): number;
|
public abstract getHeight(doc?: jsPDF): number;
|
||||||
|
|
||||||
public abstract getCheckNewPageHeight(doc?: jsPDF): number;
|
public abstract getCheckNewPageHeight(doc?: jsPDF): number;
|
||||||
|
|||||||
@@ -1,14 +1,23 @@
|
|||||||
import { AbstractElement } from './abstract-element';
|
import { AbstractElement } from './abstract-element';
|
||||||
import jsPDF from 'jspdf';
|
import jsPDF from 'jspdf';
|
||||||
import { Box } from './box';
|
import { Box } from './box';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
export class Blank extends Box {
|
export class Blank extends Box {
|
||||||
constructor(x: number, y: number, w: number, h: number) {
|
constructor(
|
||||||
super(x, y, w, h);
|
globalType: GenerateTypeEnum,
|
||||||
|
x: number,
|
||||||
|
y: number,
|
||||||
|
w: number,
|
||||||
|
h: number,
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
|
) {
|
||||||
|
super(globalType, x, y, w, h, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static heightBlank(h: number) {
|
public static heightBlank(globalType: GenerateTypeEnum, h: number) {
|
||||||
return new Blank(0, 0, 0, h);
|
return new Blank(globalType, 0, 0, 0, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCheckNewPageHeight(doc?: jsPDF): number {
|
public getCheckNewPageHeight(doc?: jsPDF): number {
|
||||||
|
|||||||
@@ -1,12 +1,21 @@
|
|||||||
import { AbstractElement } from './abstract-element';
|
import { AbstractElement } from './abstract-element';
|
||||||
import jsPDF from 'jspdf';
|
import jsPDF from 'jspdf';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
export class Box extends AbstractElement {
|
export class Box extends AbstractElement {
|
||||||
public w: number;
|
public w: number;
|
||||||
public h: number;
|
public h: number;
|
||||||
|
|
||||||
constructor(x: number, y: number, w: number, h: number) {
|
constructor(
|
||||||
super(x, y, w);
|
globalType: GenerateTypeEnum,
|
||||||
|
x: number,
|
||||||
|
y: number,
|
||||||
|
w: number,
|
||||||
|
h: number,
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
|
) {
|
||||||
|
super(globalType, x, y, w, context);
|
||||||
this.w = w;
|
this.w = w;
|
||||||
this.h = h;
|
this.h = h;
|
||||||
}
|
}
|
||||||
@@ -20,6 +29,34 @@ export class Box extends AbstractElement {
|
|||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public renderHtml(
|
||||||
|
doc: Document,
|
||||||
|
parent: HTMLElement,
|
||||||
|
cssRules: string[],
|
||||||
|
sheet: HTMLStyleElement
|
||||||
|
): Document {
|
||||||
|
const div = doc.createElement('div');
|
||||||
|
const css = `box-${this.w ?? 0}-${this.h ?? 0}`;
|
||||||
|
div.classList.add(`box`);
|
||||||
|
div.classList.add(css);
|
||||||
|
div.classList.add(this.context.name);
|
||||||
|
if (!cssRules.includes(css)) {
|
||||||
|
cssRules.push(css);
|
||||||
|
let rule = 'width: 100%;';
|
||||||
|
if (this.w > 0) {
|
||||||
|
rule += `max-width: ${this.w}px;`;
|
||||||
|
rule += `min-width: ${this.w}px;`;
|
||||||
|
}
|
||||||
|
if (this.h > 0) {
|
||||||
|
rule += `max-height: ${this.h}px;`;
|
||||||
|
rule += `min-height: ${this.h}px;`;
|
||||||
|
}
|
||||||
|
sheet.innerHTML += ` .${css} { ${rule} }`;
|
||||||
|
}
|
||||||
|
parent.append(div);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
public getHeight(_doc): number {
|
public getHeight(_doc): number {
|
||||||
return this.h;
|
return this.h;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
import { AbstractElement } from './abstract-element';
|
import { AbstractElement } from './abstract-element';
|
||||||
import jsPDF from 'jspdf';
|
import jsPDF from 'jspdf';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { AbstractContainerElement } from './abstract-container-element';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
export class Column extends AbstractElement {
|
export class Column extends AbstractContainerElement {
|
||||||
public elements: AbstractElement[] = [];
|
constructor(
|
||||||
|
globalType: GenerateTypeEnum,
|
||||||
constructor(x: number, y: number, elements: AbstractElement[]) {
|
x: number,
|
||||||
super(x, y);
|
y: number,
|
||||||
this.elements = elements;
|
elements: AbstractElement[],
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
|
) {
|
||||||
|
super(globalType, x, y, undefined, elements, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public prepareRender(doc: jsPDF, _maxWidth?: number): jsPDF {
|
public prepareRender(doc: jsPDF, _maxWidth?: number): jsPDF {
|
||||||
const elements = this.elements ?? [];
|
const elements = this.pdfElements ?? [];
|
||||||
|
|
||||||
let currentY = this.y;
|
let currentY = this.y;
|
||||||
for (let i = 0; i < elements.length; i++) {
|
for (let i = 0; i < elements.length; i++) {
|
||||||
@@ -29,9 +35,27 @@ export class Column extends AbstractElement {
|
|||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public renderHtml(
|
||||||
|
doc: Document,
|
||||||
|
parent: HTMLElement,
|
||||||
|
cssRules: string[],
|
||||||
|
sheet: HTMLStyleElement
|
||||||
|
): Document {
|
||||||
|
const div = doc.createElement('div');
|
||||||
|
div.classList.add(`column`);
|
||||||
|
div.classList.add(this.context.name);
|
||||||
|
const elements = this.htmlElements ?? [];
|
||||||
|
for (let i = 0; i < elements.length; i++) {
|
||||||
|
const element = elements[i];
|
||||||
|
element.renderHtml(doc, div, cssRules, sheet);
|
||||||
|
}
|
||||||
|
parent.append(div);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
public getHeight(doc): number {
|
public getHeight(doc): number {
|
||||||
return this.elements.length > 0
|
return this.pdfElements.length > 0
|
||||||
? this.elements
|
? this.pdfElements
|
||||||
.map((e) => e.getHeight(doc))
|
.map((e) => e.getHeight(doc))
|
||||||
.reduce((p, c, i) => {
|
.reduce((p, c, i) => {
|
||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
@@ -43,20 +67,8 @@ export class Column extends AbstractElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getCheckNewPageHeight(doc?: jsPDF): number {
|
public getCheckNewPageHeight(doc?: jsPDF): number {
|
||||||
return this.elements.length > 0
|
return this.pdfElements.length > 0
|
||||||
? this.elements[0].getCheckNewPageHeight(doc)
|
? this.pdfElements[0].getCheckNewPageHeight(doc)
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getElements(): AbstractElement[] {
|
|
||||||
const elements: AbstractElement[] = [];
|
|
||||||
for (const element of this.elements) {
|
|
||||||
elements.push(...element.getElements());
|
|
||||||
}
|
|
||||||
return elements;
|
|
||||||
}
|
|
||||||
|
|
||||||
public isEmpty(): boolean {
|
|
||||||
return this.elements.length === 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
5
src/elements/context.ts
Normal file
5
src/elements/context.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export interface IContext {
|
||||||
|
name: string;
|
||||||
|
isHtml: boolean;
|
||||||
|
isPdf: boolean;
|
||||||
|
}
|
||||||
4
src/elements/generate-type.enum.ts
Normal file
4
src/elements/generate-type.enum.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export enum GenerateTypeEnum {
|
||||||
|
PDF = 'PDF',
|
||||||
|
HTML = 'HTML',
|
||||||
|
}
|
||||||
@@ -1,12 +1,22 @@
|
|||||||
import { Box } from './box';
|
import { Box } from './box';
|
||||||
import jsPDF from 'jspdf';
|
import jsPDF from 'jspdf';
|
||||||
import { AbstractElement } from './abstract-element';
|
import { AbstractElement } from './abstract-element';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
export class Image extends Box {
|
export class Image extends Box {
|
||||||
public imageData: string;
|
public imageData: string;
|
||||||
|
|
||||||
constructor(x: number, y: number, w: number, h: number, imageData: string) {
|
constructor(
|
||||||
super(x, y, w, h);
|
globalType: GenerateTypeEnum,
|
||||||
|
x: number,
|
||||||
|
y: number,
|
||||||
|
w: number,
|
||||||
|
h: number,
|
||||||
|
imageData: string,
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
|
) {
|
||||||
|
super(globalType, x, y, w, h, context);
|
||||||
this.imageData = imageData;
|
this.imageData = imageData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,6 +31,32 @@ export class Image extends Box {
|
|||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public renderHtml(
|
||||||
|
doc: Document,
|
||||||
|
parent: HTMLElement,
|
||||||
|
cssRules: string[],
|
||||||
|
sheet: HTMLStyleElement
|
||||||
|
): Document {
|
||||||
|
const img = doc.createElement('img');
|
||||||
|
img.src = this.imageData;
|
||||||
|
const css = `img-${this.w ?? 0}`;
|
||||||
|
img.classList.add(`img`);
|
||||||
|
img.classList.add(css);
|
||||||
|
img.classList.add(this.context.name);
|
||||||
|
if (!cssRules.includes(css)) {
|
||||||
|
cssRules.push(css);
|
||||||
|
let rule = '';
|
||||||
|
if (this.w > 0) {
|
||||||
|
rule += `width: ${this.w}px;`;
|
||||||
|
}
|
||||||
|
if (rule.length > 0) {
|
||||||
|
sheet.innerHTML += ` .${css} { ${rule} }`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parent.append(img);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
public getElements(): AbstractElement[] {
|
public getElements(): AbstractElement[] {
|
||||||
return [this];
|
return [this];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,31 @@
|
|||||||
import jsPDF, { TextOptionsLight } from 'jspdf';
|
import jsPDF, { TextOptionsLight } from 'jspdf';
|
||||||
import { Text } from './text';
|
import { Text } from './text';
|
||||||
import { i18nLocalize, LABEL_SIZE, TEXT_SIZE } from '../constants';
|
import {
|
||||||
|
HTML_LABEL_SIZE,
|
||||||
|
HTML_TEXT_SIZE,
|
||||||
|
i18nLocalize,
|
||||||
|
LABEL_SIZE,
|
||||||
|
TEXT_SIZE,
|
||||||
|
} from '../constants';
|
||||||
import { AbstractElement } from './abstract-element';
|
import { AbstractElement } from './abstract-element';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
export class LabelledText extends Text {
|
export class LabelledText extends Text {
|
||||||
public label: string;
|
public label: string;
|
||||||
public labelOptions?: TextOptionsLight;
|
public labelOptions?: TextOptionsLight;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
globalType: GenerateTypeEnum,
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
label: string,
|
label: string,
|
||||||
text: string,
|
text: string,
|
||||||
textOptions?: TextOptionsLight,
|
textOptions?: TextOptionsLight,
|
||||||
labelOptions?: TextOptionsLight
|
labelOptions?: TextOptionsLight,
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
) {
|
) {
|
||||||
super(x, y, text, textOptions);
|
super(globalType, x, y, text, textOptions, context);
|
||||||
this.label = label;
|
this.label = label;
|
||||||
this.labelOptions = labelOptions;
|
this.labelOptions = labelOptions;
|
||||||
const textMaxWidth = this.textOptions?.maxWidth ?? 0;
|
const textMaxWidth = this.textOptions?.maxWidth ?? 0;
|
||||||
@@ -40,6 +50,40 @@ export class LabelledText extends Text {
|
|||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public renderHtml(
|
||||||
|
doc: Document,
|
||||||
|
parent: HTMLElement,
|
||||||
|
cssRules: string[],
|
||||||
|
sheet: HTMLStyleElement
|
||||||
|
): Document {
|
||||||
|
const div = doc.createElement('div');
|
||||||
|
div.classList.add(`column`);
|
||||||
|
div.classList.add(`labelled-text`);
|
||||||
|
div.classList.add(this.context.name);
|
||||||
|
const label = doc.createElement('p');
|
||||||
|
const text = doc.createElement('p');
|
||||||
|
const labelCss = `label-${LABEL_SIZE}`;
|
||||||
|
const textCss = `text-${TEXT_SIZE}`;
|
||||||
|
label.classList.add(labelCss);
|
||||||
|
text.classList.add(textCss);
|
||||||
|
if (!cssRules.includes(labelCss)) {
|
||||||
|
cssRules.push(labelCss);
|
||||||
|
sheet.innerHTML += ` .${labelCss} { font-size: ${HTML_LABEL_SIZE}rem; margin: 0; }`;
|
||||||
|
}
|
||||||
|
if (!cssRules.includes(textCss)) {
|
||||||
|
cssRules.push(textCss);
|
||||||
|
sheet.innerHTML += ` .${textCss} { font-size: ${HTML_TEXT_SIZE}rem; margin-top: 0.5rem; margin-bottom: 0.5rem; }`;
|
||||||
|
sheet.innerHTML += ` .labelled-text { margin-top: 0.5rem; margin-bottom: 0.5rem; }`;
|
||||||
|
sheet.innerHTML += ` .labelled-text > .${textCss} { font-size: ${HTML_TEXT_SIZE}rem; margin: 0; }`;
|
||||||
|
}
|
||||||
|
label.innerHTML = i18nLocalize(this.label);
|
||||||
|
text.innerHTML = i18nLocalize(this.text);
|
||||||
|
div.append(label);
|
||||||
|
div.append(text);
|
||||||
|
parent.append(div);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
protected updateMaxWidth(maxWidth?: number) {
|
protected updateMaxWidth(maxWidth?: number) {
|
||||||
if (maxWidth != null && maxWidth > 0) {
|
if (maxWidth != null && maxWidth > 0) {
|
||||||
this.maxWidth = maxWidth;
|
this.maxWidth = maxWidth;
|
||||||
|
|||||||
@@ -1,32 +1,52 @@
|
|||||||
import { Row } from './row';
|
import { Row } from './row';
|
||||||
import { Text } from './text';
|
import { Text } from './text';
|
||||||
import { MultilineText } from './multiline-text';
|
import { MultilineText } from './multiline-text';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { AbstractElement } from './abstract-element';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
export class LabelledValue extends Row {
|
export class LabelledValue extends Row {
|
||||||
public label: string;
|
public label: string;
|
||||||
public value: number;
|
public value: number;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
globalType: GenerateTypeEnum,
|
||||||
label: string,
|
label: string,
|
||||||
value: number,
|
value: number,
|
||||||
widthPercents?: number[],
|
widthPercents?: number[],
|
||||||
multiline = false,
|
multiline = false,
|
||||||
maxWidth?: number
|
maxWidth?: number,
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
|
globalType,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
[
|
[
|
||||||
multiline ? new MultilineText(0, 0, label) : new Text(0, 0, label),
|
multiline
|
||||||
new Text(0, 0, value.toString(), {
|
? new MultilineText(globalType, 0, 0, label)
|
||||||
|
: new Text(globalType, 0, 0, label),
|
||||||
|
new Text(globalType, 0, 0, value.toString(), {
|
||||||
align: 'right',
|
align: 'right',
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
maxWidth,
|
maxWidth,
|
||||||
widthPercents,
|
widthPercents,
|
||||||
[]
|
[],
|
||||||
|
context
|
||||||
);
|
);
|
||||||
this.label = label;
|
this.label = label;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public renderHtml(
|
||||||
|
doc: Document,
|
||||||
|
parent: HTMLElement,
|
||||||
|
cssRules: string[],
|
||||||
|
sheet: HTMLStyleElement
|
||||||
|
): Document {
|
||||||
|
const resultDoc = super.renderHtml(doc, parent, cssRules, sheet);
|
||||||
|
parent.lastElementChild?.classList?.add('labelled-value');
|
||||||
|
return resultDoc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,24 @@ import { Column } from './column';
|
|||||||
import { LabelledValue } from './labelled-value';
|
import { LabelledValue } from './labelled-value';
|
||||||
import jsPDF from 'jspdf';
|
import jsPDF from 'jspdf';
|
||||||
import { MARGINS } from '../constants';
|
import { MARGINS } from '../constants';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { AbstractElement } from './abstract-element';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
export class LabelledValues extends Row {
|
export class LabelledValues extends Row {
|
||||||
public labelledValues: { label: string; value: number }[];
|
public labelledValues: { label: string; value: number }[];
|
||||||
public nbrOfCol: number;
|
public nbrOfCol: number;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
globalType: GenerateTypeEnum,
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
labelledValues: { label: string; value: number }[],
|
labelledValues: { label: string; value: number }[],
|
||||||
nbrOfCol?: number,
|
nbrOfCol?: number,
|
||||||
multiline = false
|
multiline = false,
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
) {
|
) {
|
||||||
super(x, y, []);
|
super(globalType, x, y, [], undefined, undefined, undefined, context);
|
||||||
this.labelledValues = labelledValues;
|
this.labelledValues = labelledValues;
|
||||||
this.nbrOfCol = nbrOfCol ?? 3;
|
this.nbrOfCol = nbrOfCol ?? 3;
|
||||||
if (this.nbrOfCol > 3) {
|
if (this.nbrOfCol > 3) {
|
||||||
@@ -35,7 +40,9 @@ export class LabelledValues extends Row {
|
|||||||
rest > 2 ? nbrPerCol + 1 : nbrPerCol,
|
rest > 2 ? nbrPerCol + 1 : nbrPerCol,
|
||||||
];
|
];
|
||||||
for (let i = 0; i < this.nbrOfCol; i++) {
|
for (let i = 0; i < this.nbrOfCol; i++) {
|
||||||
this.elements[i] = new Column(0, 0, []);
|
this.contextElements[i] = new Column(globalType, 0, 0, [], {
|
||||||
|
name: `${this.context.name}-column`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
for (let i = 0; i < labelledValues.length; i++) {
|
for (let i = 0; i < labelledValues.length; i++) {
|
||||||
if (i < nbrPerCols[0]) {
|
if (i < nbrPerCols[0]) {
|
||||||
@@ -45,8 +52,9 @@ export class LabelledValues extends Row {
|
|||||||
} else {
|
} else {
|
||||||
currentIndex = 2;
|
currentIndex = 2;
|
||||||
}
|
}
|
||||||
(<Column>this.elements[currentIndex]).elements.push(
|
(<Column>this.contextElements[currentIndex]).contextElements.push(
|
||||||
new LabelledValue(
|
new LabelledValue(
|
||||||
|
globalType,
|
||||||
labelledValues[i].label,
|
labelledValues[i].label,
|
||||||
labelledValues[i].value,
|
labelledValues[i].value,
|
||||||
widthPercent,
|
widthPercent,
|
||||||
@@ -55,19 +63,24 @@ export class LabelledValues extends Row {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.elements.push(
|
this.contextElements.push(
|
||||||
new Column(
|
new Column(
|
||||||
|
globalType,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
labelledValues.map(
|
labelledValues.map(
|
||||||
(libelledValue) =>
|
(libelledValue) =>
|
||||||
new LabelledValue(
|
new LabelledValue(
|
||||||
|
globalType,
|
||||||
libelledValue.label,
|
libelledValue.label,
|
||||||
libelledValue.value,
|
libelledValue.value,
|
||||||
widthPercent,
|
widthPercent,
|
||||||
multiline
|
multiline
|
||||||
)
|
)
|
||||||
)
|
),
|
||||||
|
{
|
||||||
|
name: `${this.context.name}-column`,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -77,8 +90,8 @@ export class LabelledValues extends Row {
|
|||||||
public prepareRender(doc: jsPDF, maxWidth?: number): jsPDF {
|
public prepareRender(doc: jsPDF, maxWidth?: number): jsPDF {
|
||||||
const pageWidth = doc.internal.pageSize.width;
|
const pageWidth = doc.internal.pageSize.width;
|
||||||
const rowWidth = pageWidth - this.x - MARGINS.right;
|
const rowWidth = pageWidth - this.x - MARGINS.right;
|
||||||
for (const column of this.elements) {
|
for (const column of this.pdfElements) {
|
||||||
for (const labelledValue of (<Column>column).elements) {
|
for (const labelledValue of (<Column>column).pdfElements) {
|
||||||
labelledValue.maxWidth = rowWidth / this.nbrOfCol;
|
labelledValue.maxWidth = rowWidth / this.nbrOfCol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
import { AbstractElement } from './abstract-element';
|
import { AbstractElement } from './abstract-element';
|
||||||
import jsPDF, { TextOptionsLight } from 'jspdf';
|
import jsPDF, { TextOptionsLight } from 'jspdf';
|
||||||
import { i18nLocalize, TEXT_SIZE } from '../constants';
|
import { HTML_TEXT_SIZE, i18nLocalize, TEXT_SIZE } from '../constants';
|
||||||
import { Text } from './text';
|
import { Text } from './text';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
export class MultilineText extends Text {
|
export class MultilineText extends Text {
|
||||||
private nbrLine = 1;
|
private nbrLine = 1;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
globalType: GenerateTypeEnum,
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
text: string,
|
text: string,
|
||||||
textOptions?: TextOptionsLight
|
textOptions?: TextOptionsLight,
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
) {
|
) {
|
||||||
super(x, y, text, textOptions);
|
super(globalType, x, y, text, textOptions, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public prepareRender(doc: jsPDF, maxWidth?: number): jsPDF {
|
public prepareRender(doc: jsPDF, maxWidth?: number): jsPDF {
|
||||||
@@ -32,6 +36,27 @@ export class MultilineText extends Text {
|
|||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public renderHtml(
|
||||||
|
doc: Document,
|
||||||
|
parent: HTMLElement,
|
||||||
|
cssRules: string[],
|
||||||
|
sheet: HTMLStyleElement
|
||||||
|
): Document {
|
||||||
|
const text = doc.createElement('p');
|
||||||
|
const css = `text-${TEXT_SIZE}`;
|
||||||
|
text.classList.add(`multiline-text`);
|
||||||
|
text.classList.add(css);
|
||||||
|
text.classList.add(this.context.name);
|
||||||
|
if (!cssRules.includes(css)) {
|
||||||
|
cssRules.push(css);
|
||||||
|
sheet.innerHTML += ` .${css} { font-size: ${HTML_TEXT_SIZE}rem }`;
|
||||||
|
sheet.innerHTML += ` .labelled-text > .${css} { font-size: ${HTML_TEXT_SIZE}rem; margin: 0; }`;
|
||||||
|
}
|
||||||
|
text.innerHTML = i18nLocalize(this.text);
|
||||||
|
parent.append(text);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
public getHeight(doc): number {
|
public getHeight(doc): number {
|
||||||
return this.getHeightFromPx(doc, TEXT_SIZE) * this.nbrLine;
|
return this.getHeightFromPx(doc, TEXT_SIZE) * this.nbrLine;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,31 @@
|
|||||||
import { AbstractElement } from './abstract-element';
|
import { AbstractElement } from './abstract-element';
|
||||||
import jsPDF from 'jspdf';
|
import jsPDF from 'jspdf';
|
||||||
import { MARGINS } from '../constants';
|
import { MARGINS } from '../constants';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { AbstractContainerElement } from './abstract-container-element';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
export class Row extends AbstractElement {
|
export class Row extends AbstractContainerElement {
|
||||||
public elements: AbstractElement[] = [];
|
|
||||||
public widthPercents?: number[];
|
public widthPercents?: number[];
|
||||||
public maxWidths?: number[];
|
public maxWidths?: number[];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
globalType: GenerateTypeEnum,
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
elements: AbstractElement[],
|
elements: AbstractElement[],
|
||||||
maxWidth?: number | undefined,
|
maxWidth?: number | undefined,
|
||||||
widthPercents?: number[],
|
widthPercents?: number[],
|
||||||
maxWidths?: number[]
|
maxWidths?: number[],
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
) {
|
) {
|
||||||
super(x, y, maxWidth);
|
super(globalType, x, y, maxWidth, elements, context);
|
||||||
this.elements = elements ?? [];
|
|
||||||
this.widthPercents = widthPercents ?? [];
|
this.widthPercents = widthPercents ?? [];
|
||||||
this.maxWidths = maxWidths ?? [];
|
this.maxWidths = maxWidths ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public prepareRender(doc: jsPDF, maxWidth?: number): jsPDF {
|
public prepareRender(doc: jsPDF, maxWidth?: number): jsPDF {
|
||||||
const elements = this.elements ?? [];
|
const elements = this.pdfElements ?? [];
|
||||||
let maxWidths = this.maxWidths ?? [];
|
let maxWidths = this.maxWidths ?? [];
|
||||||
let widthPercents = this.widthPercents ?? [];
|
let widthPercents = this.widthPercents ?? [];
|
||||||
|
|
||||||
@@ -60,9 +63,27 @@ export class Row extends AbstractElement {
|
|||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public renderHtml(
|
||||||
|
doc: Document,
|
||||||
|
parent: HTMLElement,
|
||||||
|
cssRules: string[],
|
||||||
|
sheet: HTMLStyleElement
|
||||||
|
): Document {
|
||||||
|
const div = doc.createElement('div');
|
||||||
|
div.classList.add(`row`);
|
||||||
|
div.classList.add(this.context.name);
|
||||||
|
const elements = this.htmlElements ?? [];
|
||||||
|
for (let i = 0; i < elements.length; i++) {
|
||||||
|
const element = elements[i];
|
||||||
|
element.renderHtml(doc, div, cssRules, sheet);
|
||||||
|
}
|
||||||
|
parent.append(div);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
public getHeight(doc?: jsPDF): number {
|
public getHeight(doc?: jsPDF): number {
|
||||||
let maxHeight = 0;
|
let maxHeight = 0;
|
||||||
for (const element of this.elements) {
|
for (const element of this.pdfElements) {
|
||||||
maxHeight = Math.max(maxHeight, element.getHeight(doc));
|
maxHeight = Math.max(maxHeight, element.getHeight(doc));
|
||||||
}
|
}
|
||||||
return maxHeight;
|
return maxHeight;
|
||||||
@@ -70,21 +91,9 @@ export class Row extends AbstractElement {
|
|||||||
|
|
||||||
public getCheckNewPageHeight(doc?: jsPDF): number {
|
public getCheckNewPageHeight(doc?: jsPDF): number {
|
||||||
let maxHeight = 0;
|
let maxHeight = 0;
|
||||||
for (const element of this.elements) {
|
for (const element of this.pdfElements) {
|
||||||
maxHeight = Math.max(maxHeight, element.getCheckNewPageHeight(doc));
|
maxHeight = Math.max(maxHeight, element.getCheckNewPageHeight(doc));
|
||||||
}
|
}
|
||||||
return maxHeight;
|
return maxHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getElements(): AbstractElement[] {
|
|
||||||
const elements: AbstractElement[] = [];
|
|
||||||
for (const element of this.elements) {
|
|
||||||
elements.push(...element.getElements());
|
|
||||||
}
|
|
||||||
return elements;
|
|
||||||
}
|
|
||||||
|
|
||||||
public isEmpty(): boolean {
|
|
||||||
return this.elements.length === 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
import { AbstractElement } from './abstract-element';
|
import { AbstractElement } from './abstract-element';
|
||||||
import jsPDF from 'jspdf';
|
import jsPDF from 'jspdf';
|
||||||
import { MARGINS } from '../constants';
|
import { MARGINS } from '../constants';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
export class Separator extends AbstractElement {
|
export class Separator extends AbstractElement {
|
||||||
constructor(x: number, y: number, maxWidth?: number | undefined) {
|
constructor(
|
||||||
super(x, y, maxWidth);
|
globalType: GenerateTypeEnum,
|
||||||
|
x: number,
|
||||||
|
y: number,
|
||||||
|
maxWidth?: number | undefined,
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
|
) {
|
||||||
|
super(globalType, x, y, maxWidth, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getHeight(_doc?: jsPDF): number {
|
public getHeight(_doc?: jsPDF): number {
|
||||||
@@ -33,6 +41,19 @@ export class Separator extends AbstractElement {
|
|||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public renderHtml(
|
||||||
|
doc: Document,
|
||||||
|
parent: HTMLElement,
|
||||||
|
_cssRules: string[],
|
||||||
|
_sheet: HTMLStyleElement
|
||||||
|
): Document {
|
||||||
|
const div = doc.createElement('div');
|
||||||
|
div.classList.add(`separator`);
|
||||||
|
div.classList.add(this.context.name);
|
||||||
|
parent.append(div);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
public getElements(): AbstractElement[] {
|
public getElements(): AbstractElement[] {
|
||||||
return [this];
|
return [this];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
import { AbstractElement } from './abstract-element';
|
import { AbstractElement } from './abstract-element';
|
||||||
import jsPDF, { TextOptionsLight } from 'jspdf';
|
import jsPDF, { TextOptionsLight } from 'jspdf';
|
||||||
import { i18nLocalize, TEXT_SIZE } from '../constants';
|
import { HTML_TEXT_SIZE, i18nLocalize, TEXT_SIZE } from '../constants';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
export class Text extends AbstractElement {
|
export class Text extends AbstractElement {
|
||||||
public text: string;
|
public text: string;
|
||||||
public textOptions?: TextOptionsLight;
|
public textOptions?: TextOptionsLight;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
globalType: GenerateTypeEnum,
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
text: string,
|
text: string,
|
||||||
textOptions?: TextOptionsLight
|
textOptions?: TextOptionsLight,
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
) {
|
) {
|
||||||
super(x, y, textOptions?.maxWidth);
|
super(globalType, x, y, textOptions?.maxWidth, context);
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.textOptions = textOptions;
|
this.textOptions = textOptions;
|
||||||
}
|
}
|
||||||
@@ -36,6 +40,27 @@ export class Text extends AbstractElement {
|
|||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public renderHtml(
|
||||||
|
doc: Document,
|
||||||
|
parent: HTMLElement,
|
||||||
|
cssRules: string[],
|
||||||
|
sheet: HTMLStyleElement
|
||||||
|
): Document {
|
||||||
|
const text = doc.createElement('p');
|
||||||
|
const css = `text-${TEXT_SIZE}`;
|
||||||
|
text.classList.add(`ellipsis`);
|
||||||
|
text.classList.add(css);
|
||||||
|
text.classList.add(this.context.name);
|
||||||
|
text.innerHTML = i18nLocalize(i18nLocalize(this.text));
|
||||||
|
if (!cssRules.includes(css)) {
|
||||||
|
cssRules.push(css);
|
||||||
|
sheet.innerHTML += ` .${css} { font-size: ${HTML_TEXT_SIZE}rem }`;
|
||||||
|
sheet.innerHTML += ` .labelled-text > .${css} { font-size: ${HTML_TEXT_SIZE}rem; margin: 0; }`;
|
||||||
|
}
|
||||||
|
parent.append(text);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
protected updateMaxWidth(maxWidth?: number) {
|
protected updateMaxWidth(maxWidth?: number) {
|
||||||
if (maxWidth != null && maxWidth > 0) {
|
if (maxWidth != null && maxWidth > 0) {
|
||||||
this.maxWidth = maxWidth;
|
this.maxWidth = maxWidth;
|
||||||
|
|||||||
@@ -4,19 +4,24 @@ import jsPDF from 'jspdf';
|
|||||||
import { MARGINS } from '../constants';
|
import { MARGINS } from '../constants';
|
||||||
import { Text } from './text';
|
import { Text } from './text';
|
||||||
import { MultilineText } from './multiline-text';
|
import { MultilineText } from './multiline-text';
|
||||||
|
import { IContext } from './context';
|
||||||
|
import { AbstractElement } from './abstract-element';
|
||||||
|
import { GenerateTypeEnum } from './generate-type.enum';
|
||||||
|
|
||||||
export class Texts extends Row {
|
export class Texts extends Row {
|
||||||
public texts: string[];
|
public texts: string[];
|
||||||
public nbrOfCol: number;
|
public nbrOfCol: number;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
globalType: GenerateTypeEnum,
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
texts: string[],
|
texts: string[],
|
||||||
nbrOfCol?: number,
|
nbrOfCol?: number,
|
||||||
multiline = false
|
multiline = false,
|
||||||
|
context: Partial<IContext> = AbstractElement.DEFAULT_CONTEXT
|
||||||
) {
|
) {
|
||||||
super(x, y, []);
|
super(globalType, x, y, [], undefined, undefined, undefined, context);
|
||||||
this.texts = texts;
|
this.texts = texts;
|
||||||
this.nbrOfCol = nbrOfCol ?? 4;
|
this.nbrOfCol = nbrOfCol ?? 4;
|
||||||
if (this.nbrOfCol > 4) {
|
if (this.nbrOfCol > 4) {
|
||||||
@@ -34,7 +39,7 @@ export class Texts extends Row {
|
|||||||
rest > 3 ? nbrPerCol + 1 : nbrPerCol,
|
rest > 3 ? nbrPerCol + 1 : nbrPerCol,
|
||||||
];
|
];
|
||||||
for (let i = 0; i < this.nbrOfCol; i++) {
|
for (let i = 0; i < this.nbrOfCol; i++) {
|
||||||
this.elements[i] = new Column(0, 0, []);
|
this.contextElements[i] = new Column(this.globalType, 0, 0, []);
|
||||||
}
|
}
|
||||||
for (let i = 0; i < texts.length; i++) {
|
for (let i = 0; i < texts.length; i++) {
|
||||||
if (i < nbrPerCols[0]) {
|
if (i < nbrPerCols[0]) {
|
||||||
@@ -46,25 +51,26 @@ export class Texts extends Row {
|
|||||||
} else {
|
} else {
|
||||||
currentIndex = 3;
|
currentIndex = 3;
|
||||||
}
|
}
|
||||||
(<Column>this.elements[currentIndex]).elements.push(
|
(<Column>this.contextElements[currentIndex]).contextElements.push(
|
||||||
new Row(0, 0, [
|
new Row(this.globalType, 0, 0, [
|
||||||
multiline
|
multiline
|
||||||
? new MultilineText(0, 0, texts[i])
|
? new MultilineText(this.globalType, 0, 0, texts[i])
|
||||||
: new Text(0, 0, texts[i]),
|
: new Text(this.globalType, 0, 0, texts[i]),
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.elements.push(
|
this.contextElements.push(
|
||||||
new Column(
|
new Column(
|
||||||
|
this.globalType,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
texts.map(
|
texts.map(
|
||||||
(text) =>
|
(text) =>
|
||||||
new Row(0, 0, [
|
new Row(this.globalType, 0, 0, [
|
||||||
multiline
|
multiline
|
||||||
? new MultilineText(0, 0, text)
|
? new MultilineText(this.globalType, 0, 0, text)
|
||||||
: new Text(0, 0, text),
|
: new Text(this.globalType, 0, 0, text),
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -76,8 +82,8 @@ export class Texts extends Row {
|
|||||||
public prepareRender(doc: jsPDF, maxWidth?: number): jsPDF {
|
public prepareRender(doc: jsPDF, maxWidth?: number): jsPDF {
|
||||||
const pageWidth = doc.internal.pageSize.width;
|
const pageWidth = doc.internal.pageSize.width;
|
||||||
const rowWidth = pageWidth - this.x - MARGINS.right;
|
const rowWidth = pageWidth - this.x - MARGINS.right;
|
||||||
for (const column of this.elements) {
|
for (const column of this.pdfElements) {
|
||||||
for (const labelledValue of (<Column>column).elements) {
|
for (const labelledValue of (<Column>column).pdfElements) {
|
||||||
labelledValue.maxWidth = rowWidth / this.nbrOfCol;
|
labelledValue.maxWidth = rowWidth / this.nbrOfCol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
94
src/html-builder.ts
Normal file
94
src/html-builder.ts
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import { AbstractElement } from './elements/abstract-element';
|
||||||
|
import { AbstractBuilder } from './abstract-builder';
|
||||||
|
import { saveAs } from 'file-saver';
|
||||||
|
import {
|
||||||
|
HTML_LABEL_SIZE,
|
||||||
|
HTML_TEXT_SIZE,
|
||||||
|
i18n,
|
||||||
|
LABEL_SIZE,
|
||||||
|
TEXT_SIZE,
|
||||||
|
} from './constants';
|
||||||
|
import { GenerateTypeEnum } from './elements/generate-type.enum';
|
||||||
|
|
||||||
|
export class HtmlBuilder extends AbstractBuilder {
|
||||||
|
public doc: Document;
|
||||||
|
public styleSheet: HTMLStyleElement;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.doc = document.implementation.createHTMLDocument();
|
||||||
|
const style = document.createElement('style');
|
||||||
|
style.innerHTML = '.column { display: flex; flex-direction: column; }';
|
||||||
|
style.innerHTML += ' .main-column { align-items: center; }';
|
||||||
|
style.innerHTML += ' .row { display: flex; flex-direction: row }';
|
||||||
|
style.innerHTML += ' .row:not(.labelled-value) { gap: 5em; }';
|
||||||
|
style.innerHTML +=
|
||||||
|
' .row.labelled-value { gap: 10px; justify-content: space-between; }';
|
||||||
|
style.innerHTML +=
|
||||||
|
' .separator { border: 1px solid; width: 100%; height: 0px }';
|
||||||
|
style.appendChild(document.createTextNode(''));
|
||||||
|
this.doc.head.appendChild(style);
|
||||||
|
this.styleSheet = style;
|
||||||
|
const meta1 = document.createElement('meta');
|
||||||
|
meta1.setAttribute('charset', 'UTF-8');
|
||||||
|
this.doc.head.appendChild(meta1);
|
||||||
|
const meta2 = document.createElement('meta');
|
||||||
|
meta2.setAttribute('name', 'viewport');
|
||||||
|
meta2.setAttribute(
|
||||||
|
'content',
|
||||||
|
'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=yes'
|
||||||
|
);
|
||||||
|
this.doc.head.appendChild(meta2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getLabelledRowHeight(): number {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public save(name: string) {
|
||||||
|
this.doc.title = name;
|
||||||
|
const blob = new Blob(
|
||||||
|
[
|
||||||
|
`<html lang="${i18n().lang}">
|
||||||
|
${this.doc.documentElement.innerHTML}
|
||||||
|
</html>`,
|
||||||
|
],
|
||||||
|
{ type: 'text/html;charset=utf-8' }
|
||||||
|
);
|
||||||
|
saveAs(blob, `${name}.html`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public build(elements: AbstractElement[]) {
|
||||||
|
const cssList: string[] = [];
|
||||||
|
for (const element of elements.filter((el) => el.context.isHtml)) {
|
||||||
|
element.renderHtml(this.doc, this.doc.body, cssList, this.styleSheet);
|
||||||
|
}
|
||||||
|
// Mobile start
|
||||||
|
this.styleSheet.innerHTML += ' @media screen and (max-width: 959px) {';
|
||||||
|
this.styleSheet.innerHTML += ` .text-${TEXT_SIZE} { font-size: ${
|
||||||
|
2 * HTML_TEXT_SIZE
|
||||||
|
}rem; }`;
|
||||||
|
this.styleSheet.innerHTML += ` .labelled-text > .text-${TEXT_SIZE} { font-size: ${
|
||||||
|
2 * HTML_TEXT_SIZE
|
||||||
|
}rem; margin: 0; }`;
|
||||||
|
this.styleSheet.innerHTML += ` .label-${LABEL_SIZE} { font-size: ${
|
||||||
|
2 * HTML_LABEL_SIZE
|
||||||
|
}rem; }`;
|
||||||
|
this.styleSheet.innerHTML +=
|
||||||
|
' .main-column { align-items: stretch; overflow-x: hidden; }';
|
||||||
|
this.styleSheet.innerHTML +=
|
||||||
|
' .row:not(.labelled-value) { flex-wrap: wrap; gap: 0 5em; }';
|
||||||
|
this.styleSheet.innerHTML += ' .skills { width: 100%; }';
|
||||||
|
this.styleSheet.innerHTML += ' .skills-column { width: 100%; }';
|
||||||
|
this.styleSheet.innerHTML += ' }';
|
||||||
|
// Mobile end
|
||||||
|
}
|
||||||
|
|
||||||
|
public getImageScale(): number {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getGenerateType(): GenerateTypeEnum {
|
||||||
|
return GenerateTypeEnum.HTML;
|
||||||
|
}
|
||||||
|
}
|
||||||
1621
src/main.ts
1621
src/main.ts
File diff suppressed because it is too large
Load Diff
@@ -1,17 +1,29 @@
|
|||||||
import jsPDF, { jsPDFOptions } from 'jspdf';
|
import jsPDF, { jsPDFOptions } from 'jspdf';
|
||||||
import { AbstractElement } from './elements/abstract-element';
|
import { AbstractElement } from './elements/abstract-element';
|
||||||
import { MARGINS } from './constants';
|
import { LABEL_SIZE, MARGINS, TEXT_SIZE } from './constants';
|
||||||
|
import { AbstractBuilder } from './abstract-builder';
|
||||||
|
import { Util } from './util';
|
||||||
|
import { GenerateTypeEnum } from './elements/generate-type.enum';
|
||||||
|
|
||||||
export class PdfBuilder {
|
export class PdfBuilder extends AbstractBuilder {
|
||||||
public doc: jsPDF;
|
public doc: jsPDF;
|
||||||
|
|
||||||
constructor(options: jsPDFOptions) {
|
constructor(options: jsPDFOptions) {
|
||||||
|
super();
|
||||||
this.doc = new jsPDF(options);
|
this.doc = new jsPDF(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getLabelledRowHeight(): number {
|
||||||
|
return Util.getHeightFromPx(this.doc, TEXT_SIZE + LABEL_SIZE) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public save(name: string) {
|
||||||
|
this.doc.save(`${name}.pdf`);
|
||||||
|
}
|
||||||
|
|
||||||
public build(elements: AbstractElement[]) {
|
public build(elements: AbstractElement[]) {
|
||||||
const finalElements: AbstractElement[] = [];
|
const finalElements: AbstractElement[] = [];
|
||||||
for (const element of elements) {
|
for (const element of elements.filter((el) => el.context.isPdf)) {
|
||||||
element.prepareRender(this.doc);
|
element.prepareRender(this.doc);
|
||||||
finalElements.push(...element.getElements());
|
finalElements.push(...element.getElements());
|
||||||
}
|
}
|
||||||
@@ -58,4 +70,12 @@ export class PdfBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getImageScale(): number {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getGenerateType(): GenerateTypeEnum {
|
||||||
|
return GenerateTypeEnum.PDF;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ export class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static getActorItems(actor: Actor & any, key: string): (Item & any)[] {
|
public static getActorItems(actor: Actor & any, key: string): (Item & any)[] {
|
||||||
if (actor.itemCategories[key] == null) {
|
if (actor.itemTypes[key] == null) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return actor.itemCategories[key].filter((it) => {
|
return actor.itemTypes[key].filter((it) => {
|
||||||
const location = it.location.value;
|
const location = it.location.value;
|
||||||
if (location != null && location !== 0) {
|
if (location != null && location !== 0 && location !== '') {
|
||||||
return actor.getEmbeddedDocument('Item', location) != null;
|
return actor.getEmbeddedDocument('Item', location) != null;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user