@pdfme/common 6.1.1-dev.5 → 6.1.1-dev.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,9 +2,11 @@ import { PDFME_VERSION } from './version.js';
2
2
  import { MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, BLANK_A4_PDF, CUSTOM_A4_PDF, ZOOM, DEFAULT_FONT_NAME } from './constants.js';
3
3
  import type { ChangeSchemaItem, ChangeSchemas, SchemaPageArray, PropPanel, PropPanelSchema, PropPanelWidgetProps, PDFRenderProps, Mode, UIRenderProps, Plugin, Lang, Dict, Size, Schema, SchemaForUI, Font, ColorType, BasePdf, BlankPdf, CustomPdf, Template, CommonOptions, GeneratorOptions, Plugins, PluginRegistry, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, DynamicLayoutArgs, DynamicLayoutCallbackResult, DynamicLayoutPatchArgs, DynamicLayoutResult, GetDynamicLayout } from './types.js';
4
4
  import type { PdfLinkAnnotationRect } from './helper.js';
5
+ import type { PageOrientation, PageSize, PageSizePreset } from './pageSize.js';
5
6
  import { cloneDeep, getFallbackFontName, getDefaultFont, getB64BasePdf, b64toUint8Array, checkFont, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, mm2pt, pt2mm, pt2px, px2mm, isHexValid, getInputFromTemplate, isBlankPdf, isUrlSafeToFetch, getInternalLinkTarget, normalizeInternalLinkHref, normalizeLinkHref, normalizeSafeLinkUri, registerInternalLinkAnchor, registerInternalLinkAnnotation, resetInternalLinkAnnotations, applyInternalLinkAnnotations } from './helper.js';
7
+ import { PAGE_SIZE_PRESETS, detectPaperSize, resolvePageSize } from './pageSize.js';
6
8
  import { getDynamicTemplate } from './dynamicTemplate.js';
7
9
  import { replacePlaceholders } from './expression.js';
8
10
  import { pluginRegistry } from './pluginRegistry.js';
9
- export { PDFME_VERSION, MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, BLANK_A4_PDF, CUSTOM_A4_PDF, ZOOM, DEFAULT_FONT_NAME, cloneDeep, getFallbackFontName, getDefaultFont, getB64BasePdf, b64toUint8Array, mm2pt, pt2mm, pt2px, px2mm, isHexValid, getInputFromTemplate, isBlankPdf, getDynamicTemplate, replacePlaceholders, checkFont, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, pluginRegistry, isUrlSafeToFetch, getInternalLinkTarget, normalizeInternalLinkHref, normalizeLinkHref, normalizeSafeLinkUri, registerInternalLinkAnchor, registerInternalLinkAnnotation, resetInternalLinkAnnotations, applyInternalLinkAnnotations, };
10
- export type { Lang, Dict, Size, Schema, SchemaForUI, Font, ColorType, BasePdf, BlankPdf, CustomPdf, Template, CommonOptions, GeneratorOptions, Plugin, Plugins, PluginRegistry, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, ChangeSchemaItem, ChangeSchemas, SchemaPageArray, PropPanel, PropPanelSchema, PropPanelWidgetProps, PDFRenderProps, UIRenderProps, Mode, DynamicLayoutArgs, DynamicLayoutCallbackResult, DynamicLayoutPatchArgs, DynamicLayoutResult, GetDynamicLayout, PdfLinkAnnotationRect, };
11
+ export { PDFME_VERSION, MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, BLANK_A4_PDF, CUSTOM_A4_PDF, ZOOM, DEFAULT_FONT_NAME, cloneDeep, getFallbackFontName, getDefaultFont, getB64BasePdf, b64toUint8Array, mm2pt, pt2mm, pt2px, px2mm, isHexValid, getInputFromTemplate, isBlankPdf, getDynamicTemplate, replacePlaceholders, checkFont, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, pluginRegistry, isUrlSafeToFetch, getInternalLinkTarget, normalizeInternalLinkHref, normalizeLinkHref, normalizeSafeLinkUri, registerInternalLinkAnchor, registerInternalLinkAnnotation, resetInternalLinkAnnotations, applyInternalLinkAnnotations, PAGE_SIZE_PRESETS, detectPaperSize, resolvePageSize, };
12
+ export type { Lang, Dict, Size, Schema, SchemaForUI, Font, ColorType, BasePdf, BlankPdf, CustomPdf, Template, CommonOptions, GeneratorOptions, Plugin, Plugins, PluginRegistry, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, ChangeSchemaItem, ChangeSchemas, SchemaPageArray, PropPanel, PropPanelSchema, PropPanelWidgetProps, PDFRenderProps, UIRenderProps, Mode, DynamicLayoutArgs, DynamicLayoutCallbackResult, DynamicLayoutPatchArgs, DynamicLayoutResult, GetDynamicLayout, PdfLinkAnnotationRect, PageOrientation, PageSize, PageSizePreset, };
package/dist/index.js CHANGED
@@ -5,6 +5,70 @@ import * as acorn from "acorn";
5
5
  //#region src/version.ts
6
6
  var PDFME_VERSION = "6.1.1";
7
7
  //#endregion
8
+ //#region src/pageSize.ts
9
+ var PAGE_SIZE_PRESETS = {
10
+ A3: {
11
+ width: 297,
12
+ height: 420
13
+ },
14
+ A4: {
15
+ width: 210,
16
+ height: 297
17
+ },
18
+ A5: {
19
+ width: 148,
20
+ height: 210
21
+ },
22
+ A6: {
23
+ width: 105,
24
+ height: 148
25
+ },
26
+ B4: {
27
+ width: 250,
28
+ height: 353
29
+ },
30
+ B5: {
31
+ width: 176,
32
+ height: 250
33
+ },
34
+ B6: {
35
+ width: 125,
36
+ height: 176
37
+ },
38
+ Letter: {
39
+ width: 215.9,
40
+ height: 279.4
41
+ },
42
+ Legal: {
43
+ width: 215.9,
44
+ height: 355.6
45
+ },
46
+ Tabloid: {
47
+ width: 279.4,
48
+ height: 431.8
49
+ }
50
+ };
51
+ var resolvePageSize = (size = "A4", orientation = "portrait") => {
52
+ const resolved = typeof size === "string" ? PAGE_SIZE_PRESETS[size] : {
53
+ width: size.width,
54
+ height: size.height
55
+ };
56
+ if (!resolved) throw new Error(`@pdfme/common: unknown page size preset "${String(size)}"`);
57
+ if (orientation === "landscape") return {
58
+ width: resolved.height,
59
+ height: resolved.width
60
+ };
61
+ return {
62
+ width: resolved.width,
63
+ height: resolved.height
64
+ };
65
+ };
66
+ var detectPaperSize = (width, height, tolerance = 2) => {
67
+ const entries = Object.entries(PAGE_SIZE_PRESETS);
68
+ for (const [name, size] of entries) if (Math.abs(width - size.width) <= tolerance && Math.abs(height - size.height) <= tolerance || Math.abs(width - size.height) <= tolerance && Math.abs(height - size.width) <= tolerance) return `${name} ${width < height ? "portrait" : "landscape"}`;
69
+ return null;
70
+ };
71
+ //#endregion
8
72
  //#region src/constants.ts
9
73
  var PT_TO_PX_RATIO = 1.333;
10
74
  var PT_TO_MM_RATIO = .3528;
@@ -14,8 +78,7 @@ var ZOOM = 3.7795275591;
14
78
  * Blank A4 PDF size.
15
79
  */
16
80
  var BLANK_A4_PDF = {
17
- width: 210,
18
- height: 297,
81
+ ...PAGE_SIZE_PRESETS.A4,
19
82
  padding: [
20
83
  10,
21
84
  10,
@@ -1110,6 +1173,6 @@ var pluginRegistry = (plugins) => {
1110
1173
  };
1111
1174
  };
1112
1175
  //#endregion
1113
- export { BLANK_A4_PDF, BLANK_PDF, CUSTOM_A4_PDF, DEFAULT_FONT_NAME, MM_TO_PT_RATIO, PDFME_VERSION, PT_TO_MM_RATIO, PT_TO_PX_RATIO, ZOOM, applyInternalLinkAnnotations, b64toUint8Array, checkDesignerProps, checkFont, checkGenerateProps, checkInputs, checkPreviewProps, checkTemplate, checkUIOptions, checkUIProps, cloneDeep, getB64BasePdf, getDefaultFont, getDynamicTemplate, getFallbackFontName, getInputFromTemplate, getInternalLinkTarget, isBlankPdf, isHexValid, isUrlSafeToFetch, mm2pt, normalizeInternalLinkHref, normalizeLinkHref, normalizeSafeLinkUri, pluginRegistry, pt2mm, pt2px, px2mm, registerInternalLinkAnchor, registerInternalLinkAnnotation, replacePlaceholders, resetInternalLinkAnnotations };
1176
+ export { BLANK_A4_PDF, BLANK_PDF, CUSTOM_A4_PDF, DEFAULT_FONT_NAME, MM_TO_PT_RATIO, PAGE_SIZE_PRESETS, PDFME_VERSION, PT_TO_MM_RATIO, PT_TO_PX_RATIO, ZOOM, applyInternalLinkAnnotations, b64toUint8Array, checkDesignerProps, checkFont, checkGenerateProps, checkInputs, checkPreviewProps, checkTemplate, checkUIOptions, checkUIProps, cloneDeep, detectPaperSize, getB64BasePdf, getDefaultFont, getDynamicTemplate, getFallbackFontName, getInputFromTemplate, getInternalLinkTarget, isBlankPdf, isHexValid, isUrlSafeToFetch, mm2pt, normalizeInternalLinkHref, normalizeLinkHref, normalizeSafeLinkUri, pluginRegistry, pt2mm, pt2px, px2mm, registerInternalLinkAnchor, registerInternalLinkAnnotation, replacePlaceholders, resetInternalLinkAnnotations, resolvePageSize };
1114
1177
 
1115
1178
  //# sourceMappingURL=index.js.map