@muni-sanfer/types-gestor-documental 0.0.1-beta.91 → 0.0.1-beta.92
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/contracts/document.contract.d.ts +2 -1
- package/dist/entities/document/folio.d.ts +54 -4
- package/dist/entities/document/folio.js +67 -7
- package/dist/entities/document/richStyle.d.ts +6 -0
- package/dist/entities/document/richStyle.js +2 -2
- package/package.json +1 -1
- package/src/contracts/document.contract.ts +2 -0
- package/src/entities/document/folio.ts +99 -9
- package/src/entities/document/richStyle.ts +6 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DocumentAccessAction, type DocumentAccessLevel, type DocumentAttachmentEntity, type DocumentDeliveryEntity, type DocumentEntity, type DocumentInstruction, type DocumentParticipantEntity, type DocumentStatus } from '../base/entities';
|
|
2
|
-
import { type StampBox, type DocumentFolioFormat, type DocumentFolioResponseEntity, type DocumentAnnulResponseEntity, type DocumentCloseDeliveryResponseEntity, type DocumentCreateResponseEntity, type DocumentAddRecipientsResponseEntity, type DocumentDeriveResponseEntity, type DocumentDiscardResponseEntity, type DocumentEmailCopyIssuedEntity, type DocumentEmailCopyViewEntity, type DocumentReminderEntity, type DocumentSlaReminderEntity, type DocumentGetAllResponseEntity, type DocumentGetByIdResponseEntity, type DocumentGetSummaryResponseEntity, type DocumentReviewAreaEntity, type DocumentInboxItemEntity, type DocumentPublicFileResponseEntity, type DocumentReassignResponseEntity, type DocumentReviewResponseEntity, type DocumentSignManyResponseEntity, type DocumentAgendaResponseEntity, type DocumentComposeResponseEntity, type DocumentComposition, type DocumentTrailExportEntity, type DocumentUpdateResponseEntity, type DocumentVerifyResponseEntity, type DocumentCommentResponseEntity, type DocumentCommentsResponseEntity, type DocumentVersionResponseEntity, type DocumentDraftCorrectionResponseEntity, type DocumentStampPlacements, type DocumentDraftReviewResponseEntity } from '../entities';
|
|
2
|
+
import { type StampBox, type DocumentFolioFormat, type FolioLayout, type DocumentFolioResponseEntity, type DocumentAnnulResponseEntity, type DocumentCloseDeliveryResponseEntity, type DocumentCreateResponseEntity, type DocumentAddRecipientsResponseEntity, type DocumentDeriveResponseEntity, type DocumentDiscardResponseEntity, type DocumentEmailCopyIssuedEntity, type DocumentEmailCopyViewEntity, type DocumentReminderEntity, type DocumentSlaReminderEntity, type DocumentGetAllResponseEntity, type DocumentGetByIdResponseEntity, type DocumentGetSummaryResponseEntity, type DocumentReviewAreaEntity, type DocumentInboxItemEntity, type DocumentPublicFileResponseEntity, type DocumentReassignResponseEntity, type DocumentReviewResponseEntity, type DocumentSignManyResponseEntity, type DocumentAgendaResponseEntity, type DocumentComposeResponseEntity, type DocumentComposition, type DocumentTrailExportEntity, type DocumentUpdateResponseEntity, type DocumentVerifyResponseEntity, type DocumentCommentResponseEntity, type DocumentCommentsResponseEntity, type DocumentVersionResponseEntity, type DocumentDraftCorrectionResponseEntity, type DocumentStampPlacements, type DocumentDraftReviewResponseEntity } from '../entities';
|
|
3
3
|
import { type RpcPage } from './contract';
|
|
4
4
|
/** Patrones NATS de `document`: `<servicio>.<recurso>.<acción>`. */
|
|
5
5
|
export declare const DocumentPatterns: {
|
|
@@ -281,6 +281,7 @@ export interface DocumentContract {
|
|
|
281
281
|
partsOffice?: boolean;
|
|
282
282
|
box?: StampBox;
|
|
283
283
|
format?: DocumentFolioFormat;
|
|
284
|
+
layout?: FolioLayout;
|
|
284
285
|
actor: DocumentActor;
|
|
285
286
|
};
|
|
286
287
|
response: DocumentFolioResponseEntity;
|
|
@@ -14,18 +14,66 @@ export interface DocumentFolioFormat {
|
|
|
14
14
|
label: FolioLabel;
|
|
15
15
|
number: FolioNumberStyle;
|
|
16
16
|
date: FolioDateStyle;
|
|
17
|
-
/** Un texto fijo
|
|
17
|
+
/** Un texto fijo, aparte (por ejemplo, «Oficina de Partes»). */
|
|
18
18
|
text?: string | null;
|
|
19
|
-
|
|
19
|
+
/** Ya no se usa: cada pieza se alinea en el bloque (`FolioLayout`). Se conserva en lo guardado antes. */
|
|
20
|
+
align?: 'left' | 'center' | 'right';
|
|
20
21
|
}
|
|
21
|
-
/** La de siempre: el nombre del tipo con su número, y la fecha larga
|
|
22
|
+
/** La de siempre: el nombre del tipo con su número, y la fecha larga. */
|
|
22
23
|
export declare const DEFAULT_FOLIO_FORMAT: DocumentFolioFormat;
|
|
24
|
+
/** Las piezas de la estampa del folio: el número (con el tipo o su sigla), la fecha y el texto fijo. */
|
|
25
|
+
export type FolioItemKey = 'number' | 'date' | 'text';
|
|
26
|
+
export declare const FOLIO_ITEM_KEYS: FolioItemKey[];
|
|
27
|
+
export type FolioAlign = 'left' | 'center' | 'right';
|
|
28
|
+
/**
|
|
29
|
+
* Dónde va una pieza dentro del bloque de la estampa, en puntos desde su esquina superior izquierda: `y` es el borde de
|
|
30
|
+
* arriba de su línea y `x` su ancla, que según `align` es su borde izquierdo, su centro o su borde derecho.
|
|
31
|
+
*/
|
|
32
|
+
export interface FolioItemPlacement {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
align: FolioAlign;
|
|
36
|
+
}
|
|
37
|
+
/** Cómo van las piezas dentro del bloque; la que falta se ubica sola. */
|
|
38
|
+
export type FolioLayout = Partial<Record<FolioItemKey, FolioItemPlacement>>;
|
|
39
|
+
/** Tamaño de letra de cada pieza, en puntos (el número en negrita). */
|
|
40
|
+
export declare const FOLIO_FONT_SIZE: Record<FolioItemKey, number>;
|
|
41
|
+
/** Alto de una línea, por punto de letra. */
|
|
42
|
+
export declare const FOLIO_LINE_HEIGHT = 1.25;
|
|
43
|
+
/**
|
|
44
|
+
* Las piezas una bajo otra, centradas en el alto del bloque y alineadas como se pida (por omisión, a la derecha): el
|
|
45
|
+
* número arriba, la fecha y el texto debajo.
|
|
46
|
+
*/
|
|
47
|
+
export declare const defaultFolioLayout: (box: {
|
|
48
|
+
width: number;
|
|
49
|
+
height: number;
|
|
50
|
+
}, keys: FolioItemKey[], align?: FolioAlign) => FolioLayout;
|
|
51
|
+
/** Cada pieza dentro del bloque: su ancla entre los bordes y su línea sin salirse por abajo. */
|
|
52
|
+
export declare const clampFolioLayout: (layout: FolioLayout, box: {
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
}) => FolioLayout;
|
|
56
|
+
/**
|
|
57
|
+
* Las piezas que lleva la estampa con su texto, y dónde va cada una: la que el bloque ya ubicó, o la que se ubica sola
|
|
58
|
+
* (una bajo otra, con la alineación pedida).
|
|
59
|
+
*/
|
|
60
|
+
export declare const folioStampItems: (parts: Partial<Record<FolioItemKey, string>>, layout: FolioLayout | null | undefined, box: {
|
|
61
|
+
width: number;
|
|
62
|
+
height: number;
|
|
63
|
+
}, align?: FolioAlign) => {
|
|
64
|
+
key: FolioItemKey;
|
|
65
|
+
text: string;
|
|
66
|
+
size: number;
|
|
67
|
+
bold: boolean;
|
|
68
|
+
placement: FolioItemPlacement;
|
|
69
|
+
}[];
|
|
23
70
|
/** Largo máximo del texto fijo de la estampa. */
|
|
24
71
|
export declare const FOLIO_TEXT_MAX = 80;
|
|
25
|
-
/** La estampa del folio que se firmó en un documento: dónde
|
|
72
|
+
/** La estampa del folio que se firmó en un documento: dónde quedó, con qué formato y cómo iban sus piezas. */
|
|
26
73
|
export interface DocumentFolioStamp {
|
|
27
74
|
box: StampBox;
|
|
28
75
|
format: DocumentFolioFormat;
|
|
76
|
+
layout?: FolioLayout;
|
|
29
77
|
}
|
|
30
78
|
/**
|
|
31
79
|
* Lo necesario para proponer la estampa del folio de un documento por foliar, sobre su vista previa: el formato del tipo
|
|
@@ -52,4 +100,6 @@ export interface FolioStampData {
|
|
|
52
100
|
* Las líneas de la estampa del folio, de arriba abajo: el tipo (o su sigla) con el número, la fecha y el texto fijo. Lo
|
|
53
101
|
* usan el ms al firmar la estampa y la vista previa de las pantallas, para que se vean igual.
|
|
54
102
|
*/
|
|
103
|
+
/** Las piezas de la estampa con su texto: el número (con el tipo o su sigla), la fecha y el texto fijo. */
|
|
104
|
+
export declare const folioStampParts: (format: DocumentFolioFormat, data: FolioStampData) => Partial<Record<FolioItemKey, string>>;
|
|
55
105
|
export declare const folioStampLines: (format: DocumentFolioFormat, data: FolioStampData) => string[];
|
|
@@ -1,19 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.folioStampLines = exports.FOLIO_TEXT_MAX = exports.DEFAULT_FOLIO_FORMAT = void 0;
|
|
4
|
-
/** La de siempre: el nombre del tipo con su número, y la fecha larga
|
|
5
|
-
exports.DEFAULT_FOLIO_FORMAT = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
exports.folioStampLines = exports.folioStampParts = exports.FOLIO_TEXT_MAX = exports.folioStampItems = exports.clampFolioLayout = exports.defaultFolioLayout = exports.FOLIO_LINE_HEIGHT = exports.FOLIO_FONT_SIZE = exports.FOLIO_ITEM_KEYS = exports.DEFAULT_FOLIO_FORMAT = void 0;
|
|
4
|
+
/** La de siempre: el nombre del tipo con su número, y la fecha larga. */
|
|
5
|
+
exports.DEFAULT_FOLIO_FORMAT = { label: 'name', number: 'number', date: 'long' };
|
|
6
|
+
exports.FOLIO_ITEM_KEYS = ['number', 'date', 'text'];
|
|
7
|
+
/** Tamaño de letra de cada pieza, en puntos (el número en negrita). */
|
|
8
|
+
exports.FOLIO_FONT_SIZE = { number: 10, date: 9, text: 8 };
|
|
9
|
+
/** Alto de una línea, por punto de letra. */
|
|
10
|
+
exports.FOLIO_LINE_HEIGHT = 1.25;
|
|
11
|
+
/**
|
|
12
|
+
* Las piezas una bajo otra, centradas en el alto del bloque y alineadas como se pida (por omisión, a la derecha): el
|
|
13
|
+
* número arriba, la fecha y el texto debajo.
|
|
14
|
+
*/
|
|
15
|
+
const defaultFolioLayout = (box, keys, align = 'right') => {
|
|
16
|
+
const total = keys.reduce((sum, key) => sum + exports.FOLIO_FONT_SIZE[key] * exports.FOLIO_LINE_HEIGHT, 0);
|
|
17
|
+
const x = align === 'left' ? 2 : align === 'center' ? box.width / 2 : box.width - 2;
|
|
18
|
+
let y = Math.max(0, (box.height - total) / 2);
|
|
19
|
+
const layout = {};
|
|
20
|
+
for (const key of exports.FOLIO_ITEM_KEYS) {
|
|
21
|
+
if (!keys.includes(key))
|
|
22
|
+
continue;
|
|
23
|
+
layout[key] = { x: Math.round(x * 10) / 10, y: Math.round(y * 10) / 10, align };
|
|
24
|
+
y += exports.FOLIO_FONT_SIZE[key] * exports.FOLIO_LINE_HEIGHT;
|
|
25
|
+
}
|
|
26
|
+
return layout;
|
|
10
27
|
};
|
|
28
|
+
exports.defaultFolioLayout = defaultFolioLayout;
|
|
29
|
+
/** Cada pieza dentro del bloque: su ancla entre los bordes y su línea sin salirse por abajo. */
|
|
30
|
+
const clampFolioLayout = (layout, box) => {
|
|
31
|
+
const clamped = {};
|
|
32
|
+
for (const key of exports.FOLIO_ITEM_KEYS) {
|
|
33
|
+
const item = layout[key];
|
|
34
|
+
if (!item)
|
|
35
|
+
continue;
|
|
36
|
+
const lineHeight = exports.FOLIO_FONT_SIZE[key] * exports.FOLIO_LINE_HEIGHT;
|
|
37
|
+
clamped[key] = {
|
|
38
|
+
align: item.align,
|
|
39
|
+
x: Math.round(Math.min(Math.max(item.x, 0), box.width) * 10) / 10,
|
|
40
|
+
y: Math.round(Math.min(Math.max(item.y, 0), Math.max(0, box.height - lineHeight)) * 10) / 10,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return clamped;
|
|
44
|
+
};
|
|
45
|
+
exports.clampFolioLayout = clampFolioLayout;
|
|
46
|
+
/**
|
|
47
|
+
* Las piezas que lleva la estampa con su texto, y dónde va cada una: la que el bloque ya ubicó, o la que se ubica sola
|
|
48
|
+
* (una bajo otra, con la alineación pedida).
|
|
49
|
+
*/
|
|
50
|
+
const folioStampItems = (parts, layout, box, align = 'right') => {
|
|
51
|
+
const keys = exports.FOLIO_ITEM_KEYS.filter(key => parts[key]);
|
|
52
|
+
const fallback = (0, exports.defaultFolioLayout)(box, keys, align);
|
|
53
|
+
const placed = (0, exports.clampFolioLayout)({ ...fallback, ...(layout ?? {}) }, box);
|
|
54
|
+
return keys.map(key => ({
|
|
55
|
+
key,
|
|
56
|
+
text: parts[key],
|
|
57
|
+
size: exports.FOLIO_FONT_SIZE[key],
|
|
58
|
+
bold: key === 'number',
|
|
59
|
+
placement: placed[key],
|
|
60
|
+
}));
|
|
61
|
+
};
|
|
62
|
+
exports.folioStampItems = folioStampItems;
|
|
11
63
|
/** Largo máximo del texto fijo de la estampa. */
|
|
12
64
|
exports.FOLIO_TEXT_MAX = 80;
|
|
13
65
|
/**
|
|
14
66
|
* Las líneas de la estampa del folio, de arriba abajo: el tipo (o su sigla) con el número, la fecha y el texto fijo. Lo
|
|
15
67
|
* usan el ms al firmar la estampa y la vista previa de las pantallas, para que se vean igual.
|
|
16
68
|
*/
|
|
69
|
+
/** Las piezas de la estampa con su texto: el número (con el tipo o su sigla), la fecha y el texto fijo. */
|
|
70
|
+
const folioStampParts = (format, data) => {
|
|
71
|
+
const [number, ...rest] = (0, exports.folioStampLines)(format, data);
|
|
72
|
+
const date = format.date === 'none' ? undefined : rest[0];
|
|
73
|
+
const text = format.text?.trim() || undefined;
|
|
74
|
+
return { number, ...(date ? { date } : {}), ...(text ? { text } : {}) };
|
|
75
|
+
};
|
|
76
|
+
exports.folioStampParts = folioStampParts;
|
|
17
77
|
const folioStampLines = (format, data) => {
|
|
18
78
|
const number = `N° ${data.correlative}${format.number === 'numberYear' ? `/${data.correlativeYear}` : ''}`;
|
|
19
79
|
const label = format.label === 'name'
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type FolioLayout } from './folio';
|
|
1
2
|
/**
|
|
2
3
|
* Formato del editor del gestor que comparten el navegador y el microservicio: tipografías, colores, tamaños de hoja y
|
|
3
4
|
* márgenes. Todo lo que el PDF muestra sale de aquí, así que el editor y el documento oficial se ven igual.
|
|
@@ -198,6 +199,11 @@ export interface RichNumberZone {
|
|
|
198
199
|
align: RichNumberAlign;
|
|
199
200
|
width?: number;
|
|
200
201
|
height?: number;
|
|
202
|
+
/**
|
|
203
|
+
* Dónde va cada pieza de la estampa del folio (el número, la fecha, el texto) dentro del recuadro, si se movieron en
|
|
204
|
+
* el editor. Sin valor, una bajo otra con la alineación del recuadro.
|
|
205
|
+
*/
|
|
206
|
+
layout?: FolioLayout;
|
|
201
207
|
}
|
|
202
208
|
/** Límites del diseño libre del encabezado. */
|
|
203
209
|
export declare const RICH_LETTERHEAD_LIMITS: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RICH_IMAGE_LIMITS = exports.RICH_DEFAULT_LETTERHEAD = exports.richFitLetterhead = exports.richNumberZone = exports.RICH_NUMBER_ZONE_LIMITS = exports.RICH_NUMBER_ZONE = exports.RICH_LETTERHEAD_LIMITS = exports.RICH_DEFAULT_PAGE = exports.RICH_MAX_MARGIN = exports.RICH_MIN_MARGINS = exports.RICH_PAGE_SIZES = exports.RICH_SPACING_LIMITS = exports.RICH_HIGHLIGHTS = exports.RICH_COLORS = exports.RICH_FONT_SIZES = exports.RICH_FONTS = void 0;
|
|
2
4
|
/**
|
|
3
5
|
* Formato del editor del gestor que comparten el navegador y el microservicio: tipografías, colores, tamaños de hoja y
|
|
4
6
|
* márgenes. Todo lo que el PDF muestra sale de aquí, así que el editor y el documento oficial se ven igual.
|
|
5
7
|
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.RICH_IMAGE_LIMITS = exports.RICH_DEFAULT_LETTERHEAD = exports.richFitLetterhead = exports.richNumberZone = exports.RICH_NUMBER_ZONE_LIMITS = exports.RICH_NUMBER_ZONE = exports.RICH_LETTERHEAD_LIMITS = exports.RICH_DEFAULT_PAGE = exports.RICH_MAX_MARGIN = exports.RICH_MIN_MARGINS = exports.RICH_PAGE_SIZES = exports.RICH_SPACING_LIMITS = exports.RICH_HIGHLIGHTS = exports.RICH_COLORS = exports.RICH_FONT_SIZES = exports.RICH_FONTS = void 0;
|
|
8
8
|
/**
|
|
9
9
|
* Tipografías incrustadas en el PDF (PDF/A exige fuentes incrustadas). Liberation Sans, Liberation Serif y Carlito
|
|
10
10
|
* miden igual que Arial, Times New Roman y Calibri: lo que se pegó desde Word ocupa lo mismo.
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import {
|
|
12
12
|
type StampBox,
|
|
13
13
|
type DocumentFolioFormat,
|
|
14
|
+
type FolioLayout,
|
|
14
15
|
type DocumentFolioResponseEntity,
|
|
15
16
|
type DocumentAnnulResponseEntity,
|
|
16
17
|
type DocumentCloseDeliveryResponseEntity,
|
|
@@ -338,6 +339,7 @@ export interface DocumentContract {
|
|
|
338
339
|
// Solo para este documento: dónde va la estampa y cómo se ve (sin ellos, los del tipo y su plantilla)
|
|
339
340
|
box?: StampBox;
|
|
340
341
|
format?: DocumentFolioFormat;
|
|
342
|
+
layout?: FolioLayout;
|
|
341
343
|
actor: DocumentActor;
|
|
342
344
|
};
|
|
343
345
|
response: DocumentFolioResponseEntity;
|
|
@@ -16,26 +16,105 @@ export interface DocumentFolioFormat {
|
|
|
16
16
|
label: FolioLabel;
|
|
17
17
|
number: FolioNumberStyle;
|
|
18
18
|
date: FolioDateStyle;
|
|
19
|
-
/** Un texto fijo
|
|
19
|
+
/** Un texto fijo, aparte (por ejemplo, «Oficina de Partes»). */
|
|
20
20
|
text?: string | null;
|
|
21
|
-
|
|
21
|
+
/** Ya no se usa: cada pieza se alinea en el bloque (`FolioLayout`). Se conserva en lo guardado antes. */
|
|
22
|
+
align?: 'left' | 'center' | 'right';
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
/** La de siempre: el nombre del tipo con su número, y la fecha larga
|
|
25
|
-
export const DEFAULT_FOLIO_FORMAT: DocumentFolioFormat = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
/** La de siempre: el nombre del tipo con su número, y la fecha larga. */
|
|
26
|
+
export const DEFAULT_FOLIO_FORMAT: DocumentFolioFormat = { label: 'name', number: 'number', date: 'long' };
|
|
27
|
+
|
|
28
|
+
/** Las piezas de la estampa del folio: el número (con el tipo o su sigla), la fecha y el texto fijo. */
|
|
29
|
+
export type FolioItemKey = 'number' | 'date' | 'text';
|
|
30
|
+
export const FOLIO_ITEM_KEYS: FolioItemKey[] = ['number', 'date', 'text'];
|
|
31
|
+
export type FolioAlign = 'left' | 'center' | 'right';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Dónde va una pieza dentro del bloque de la estampa, en puntos desde su esquina superior izquierda: `y` es el borde de
|
|
35
|
+
* arriba de su línea y `x` su ancla, que según `align` es su borde izquierdo, su centro o su borde derecho.
|
|
36
|
+
*/
|
|
37
|
+
export interface FolioItemPlacement {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
align: FolioAlign;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Cómo van las piezas dentro del bloque; la que falta se ubica sola. */
|
|
44
|
+
export type FolioLayout = Partial<Record<FolioItemKey, FolioItemPlacement>>;
|
|
45
|
+
|
|
46
|
+
/** Tamaño de letra de cada pieza, en puntos (el número en negrita). */
|
|
47
|
+
export const FOLIO_FONT_SIZE: Record<FolioItemKey, number> = { number: 10, date: 9, text: 8 };
|
|
48
|
+
/** Alto de una línea, por punto de letra. */
|
|
49
|
+
export const FOLIO_LINE_HEIGHT = 1.25;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Las piezas una bajo otra, centradas en el alto del bloque y alineadas como se pida (por omisión, a la derecha): el
|
|
53
|
+
* número arriba, la fecha y el texto debajo.
|
|
54
|
+
*/
|
|
55
|
+
export const defaultFolioLayout = (
|
|
56
|
+
box: { width: number; height: number },
|
|
57
|
+
keys: FolioItemKey[],
|
|
58
|
+
align: FolioAlign = 'right',
|
|
59
|
+
): FolioLayout => {
|
|
60
|
+
const total = keys.reduce((sum, key) => sum + FOLIO_FONT_SIZE[key] * FOLIO_LINE_HEIGHT, 0);
|
|
61
|
+
const x = align === 'left' ? 2 : align === 'center' ? box.width / 2 : box.width - 2;
|
|
62
|
+
let y = Math.max(0, (box.height - total) / 2);
|
|
63
|
+
const layout: FolioLayout = {};
|
|
64
|
+
for (const key of FOLIO_ITEM_KEYS) {
|
|
65
|
+
if (!keys.includes(key)) continue;
|
|
66
|
+
layout[key] = { x: Math.round(x * 10) / 10, y: Math.round(y * 10) / 10, align };
|
|
67
|
+
y += FOLIO_FONT_SIZE[key] * FOLIO_LINE_HEIGHT;
|
|
68
|
+
}
|
|
69
|
+
return layout;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** Cada pieza dentro del bloque: su ancla entre los bordes y su línea sin salirse por abajo. */
|
|
73
|
+
export const clampFolioLayout = (layout: FolioLayout, box: { width: number; height: number }): FolioLayout => {
|
|
74
|
+
const clamped: FolioLayout = {};
|
|
75
|
+
for (const key of FOLIO_ITEM_KEYS) {
|
|
76
|
+
const item = layout[key];
|
|
77
|
+
if (!item) continue;
|
|
78
|
+
const lineHeight = FOLIO_FONT_SIZE[key] * FOLIO_LINE_HEIGHT;
|
|
79
|
+
clamped[key] = {
|
|
80
|
+
align: item.align,
|
|
81
|
+
x: Math.round(Math.min(Math.max(item.x, 0), box.width) * 10) / 10,
|
|
82
|
+
y: Math.round(Math.min(Math.max(item.y, 0), Math.max(0, box.height - lineHeight)) * 10) / 10,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return clamped;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Las piezas que lleva la estampa con su texto, y dónde va cada una: la que el bloque ya ubicó, o la que se ubica sola
|
|
90
|
+
* (una bajo otra, con la alineación pedida).
|
|
91
|
+
*/
|
|
92
|
+
export const folioStampItems = (
|
|
93
|
+
parts: Partial<Record<FolioItemKey, string>>,
|
|
94
|
+
layout: FolioLayout | null | undefined,
|
|
95
|
+
box: { width: number; height: number },
|
|
96
|
+
align: FolioAlign = 'right',
|
|
97
|
+
): { key: FolioItemKey; text: string; size: number; bold: boolean; placement: FolioItemPlacement }[] => {
|
|
98
|
+
const keys = FOLIO_ITEM_KEYS.filter(key => parts[key]);
|
|
99
|
+
const fallback = defaultFolioLayout(box, keys, align);
|
|
100
|
+
const placed = clampFolioLayout({ ...fallback, ...(layout ?? {}) }, box);
|
|
101
|
+
return keys.map(key => ({
|
|
102
|
+
key,
|
|
103
|
+
text: parts[key]!,
|
|
104
|
+
size: FOLIO_FONT_SIZE[key],
|
|
105
|
+
bold: key === 'number',
|
|
106
|
+
placement: placed[key]!,
|
|
107
|
+
}));
|
|
30
108
|
};
|
|
31
109
|
|
|
32
110
|
/** Largo máximo del texto fijo de la estampa. */
|
|
33
111
|
export const FOLIO_TEXT_MAX = 80;
|
|
34
112
|
|
|
35
|
-
/** La estampa del folio que se firmó en un documento: dónde
|
|
113
|
+
/** La estampa del folio que se firmó en un documento: dónde quedó, con qué formato y cómo iban sus piezas. */
|
|
36
114
|
export interface DocumentFolioStamp {
|
|
37
115
|
box: StampBox;
|
|
38
116
|
format: DocumentFolioFormat;
|
|
117
|
+
layout?: FolioLayout;
|
|
39
118
|
}
|
|
40
119
|
|
|
41
120
|
/**
|
|
@@ -65,6 +144,17 @@ export interface FolioStampData {
|
|
|
65
144
|
* Las líneas de la estampa del folio, de arriba abajo: el tipo (o su sigla) con el número, la fecha y el texto fijo. Lo
|
|
66
145
|
* usan el ms al firmar la estampa y la vista previa de las pantallas, para que se vean igual.
|
|
67
146
|
*/
|
|
147
|
+
/** Las piezas de la estampa con su texto: el número (con el tipo o su sigla), la fecha y el texto fijo. */
|
|
148
|
+
export const folioStampParts = (
|
|
149
|
+
format: DocumentFolioFormat,
|
|
150
|
+
data: FolioStampData,
|
|
151
|
+
): Partial<Record<FolioItemKey, string>> => {
|
|
152
|
+
const [number, ...rest] = folioStampLines(format, data);
|
|
153
|
+
const date = format.date === 'none' ? undefined : rest[0];
|
|
154
|
+
const text = format.text?.trim() || undefined;
|
|
155
|
+
return { number, ...(date ? { date } : {}), ...(text ? { text } : {}) };
|
|
156
|
+
};
|
|
157
|
+
|
|
68
158
|
export const folioStampLines = (format: DocumentFolioFormat, data: FolioStampData): string[] => {
|
|
69
159
|
const number = `N° ${data.correlative}${format.number === 'numberYear' ? `/${data.correlativeYear}` : ''}`;
|
|
70
160
|
const label =
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type FolioLayout } from './folio';
|
|
1
2
|
/**
|
|
2
3
|
* Formato del editor del gestor que comparten el navegador y el microservicio: tipografías, colores, tamaños de hoja y
|
|
3
4
|
* márgenes. Todo lo que el PDF muestra sale de aquí, así que el editor y el documento oficial se ven igual.
|
|
@@ -182,6 +183,11 @@ export interface RichNumberZone {
|
|
|
182
183
|
align: RichNumberAlign;
|
|
183
184
|
width?: number;
|
|
184
185
|
height?: number;
|
|
186
|
+
/**
|
|
187
|
+
* Dónde va cada pieza de la estampa del folio (el número, la fecha, el texto) dentro del recuadro, si se movieron en
|
|
188
|
+
* el editor. Sin valor, una bajo otra con la alineación del recuadro.
|
|
189
|
+
*/
|
|
190
|
+
layout?: FolioLayout;
|
|
185
191
|
}
|
|
186
192
|
|
|
187
193
|
/** Límites del diseño libre del encabezado. */
|