@aibrains/pdf-renderer 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/descriptors/index.d.ts +14 -0
- package/dist/descriptors/index.d.ts.map +1 -0
- package/dist/descriptors/index.js +20 -0
- package/dist/descriptors/index.js.map +1 -0
- package/dist/descriptors/registry.d.ts +52 -0
- package/dist/descriptors/registry.d.ts.map +1 -0
- package/dist/descriptors/registry.js +85 -0
- package/dist/descriptors/registry.js.map +1 -0
- package/dist/descriptors/types.d.ts +207 -0
- package/dist/descriptors/types.d.ts.map +1 -0
- package/dist/descriptors/types.js +15 -0
- package/dist/descriptors/types.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface of the descriptor system.
|
|
3
|
+
*
|
|
4
|
+
* Sprint C.0.4 ships the registry + the contract. Concrete descriptors land
|
|
5
|
+
* with their document components in subsequent sprints:
|
|
6
|
+
* - C.1.1 — invoice descriptor
|
|
7
|
+
* - C.1.2 — receipt descriptor
|
|
8
|
+
* - C.3.1 — report-card descriptor
|
|
9
|
+
* - C.5.1 — admit-card descriptor
|
|
10
|
+
* - (and so on for the V1.5 doc types)
|
|
11
|
+
*/
|
|
12
|
+
export { registerDescriptor, getDescriptor, getRegisteredDocTypes, hasDescriptor, } from './registry';
|
|
13
|
+
export type { DocType, Archetype, PdfBranding, PdfLocaleSettings, PdfTemplateConfig, ConfigurableField, DocumentComponentProps, TemplateDescriptor, } from './types';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/descriptors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,aAAa,GACd,MAAM,YAAY,CAAC;AAKpB,YAAY,EACV,OAAO,EACP,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Public surface of the descriptor system.
|
|
4
|
+
*
|
|
5
|
+
* Sprint C.0.4 ships the registry + the contract. Concrete descriptors land
|
|
6
|
+
* with their document components in subsequent sprints:
|
|
7
|
+
* - C.1.1 — invoice descriptor
|
|
8
|
+
* - C.1.2 — receipt descriptor
|
|
9
|
+
* - C.3.1 — report-card descriptor
|
|
10
|
+
* - C.5.1 — admit-card descriptor
|
|
11
|
+
* - (and so on for the V1.5 doc types)
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.hasDescriptor = exports.getRegisteredDocTypes = exports.getDescriptor = exports.registerDescriptor = void 0;
|
|
15
|
+
var registry_1 = require("./registry");
|
|
16
|
+
Object.defineProperty(exports, "registerDescriptor", { enumerable: true, get: function () { return registry_1.registerDescriptor; } });
|
|
17
|
+
Object.defineProperty(exports, "getDescriptor", { enumerable: true, get: function () { return registry_1.getDescriptor; } });
|
|
18
|
+
Object.defineProperty(exports, "getRegisteredDocTypes", { enumerable: true, get: function () { return registry_1.getRegisteredDocTypes; } });
|
|
19
|
+
Object.defineProperty(exports, "hasDescriptor", { enumerable: true, get: function () { return registry_1.hasDescriptor; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/descriptors/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAEH,uCAKoB;AAJlB,8GAAA,kBAAkB,OAAA;AAClB,yGAAA,aAAa,OAAA;AACb,iHAAA,qBAAqB,OAAA;AACrB,yGAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Singleton registry of template descriptors, keyed by `DocType`.
|
|
3
|
+
*
|
|
4
|
+
* Each `descriptors/{doc-type}.ts` file performs a side-effect at module load:
|
|
5
|
+
*
|
|
6
|
+
* import { registerDescriptor } from '../descriptors/registry';
|
|
7
|
+
* registerDescriptor(myDescriptor);
|
|
8
|
+
*
|
|
9
|
+
* The editor UI and render endpoints look up descriptors by `getDescriptor`.
|
|
10
|
+
* Adding a new doc type = adding a new file that calls `registerDescriptor`;
|
|
11
|
+
* NO change to the editor, the registry, or any consumer is needed.
|
|
12
|
+
*
|
|
13
|
+
* The registry deliberately uses module-singleton state. Tests can reset it
|
|
14
|
+
* via `_clearRegistryForTest`.
|
|
15
|
+
*/
|
|
16
|
+
import type { DocType, PdfTemplateConfig, TemplateDescriptor } from './types';
|
|
17
|
+
/**
|
|
18
|
+
* Register a descriptor. Throws on duplicate `docType` — each doc type
|
|
19
|
+
* registers exactly once. Catching the duplicate at registration time
|
|
20
|
+
* surfaces accidental double-imports (e.g., two paths both importing
|
|
21
|
+
* `descriptors/invoice.ts`) as a loud error rather than silent override.
|
|
22
|
+
*/
|
|
23
|
+
export declare function registerDescriptor<TData, TConfig extends PdfTemplateConfig>(descriptor: TemplateDescriptor<TData, TConfig>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Look up a descriptor by `docType`. Throws with a helpful message listing
|
|
26
|
+
* the known docTypes if the requested one isn't registered — guards against
|
|
27
|
+
* typos at endpoint wire-up time.
|
|
28
|
+
*
|
|
29
|
+
* Generics: callers that know the concrete `TData` + `TConfig` for the docType
|
|
30
|
+
* can supply them to get a typed descriptor back. Callers that don't (e.g.,
|
|
31
|
+
* the editor UI iterating over all doc types) get the default
|
|
32
|
+
* `unknown / PdfTemplateConfig` shape and access only the descriptor-level
|
|
33
|
+
* metadata (configurableFields, defaults, sampleData).
|
|
34
|
+
*/
|
|
35
|
+
export declare function getDescriptor<TData = unknown, TConfig extends PdfTemplateConfig = PdfTemplateConfig>(docType: DocType): TemplateDescriptor<TData, TConfig>;
|
|
36
|
+
/**
|
|
37
|
+
* Return the list of currently-registered doc types. Used by the editor's
|
|
38
|
+
* settings page to enumerate template cards.
|
|
39
|
+
*/
|
|
40
|
+
export declare function getRegisteredDocTypes(): readonly DocType[];
|
|
41
|
+
/**
|
|
42
|
+
* Check whether a descriptor is registered without throwing. Useful for the
|
|
43
|
+
* editor when it wants to render disabled cards for not-yet-shipped doc
|
|
44
|
+
* types.
|
|
45
|
+
*/
|
|
46
|
+
export declare function hasDescriptor(docType: DocType): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Test-only escape hatch. Clears the registry so each spec file starts
|
|
49
|
+
* clean. Not exported from the public package surface.
|
|
50
|
+
*/
|
|
51
|
+
export declare function _clearRegistryForTest(): void;
|
|
52
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/descriptors/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAUjB;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,SAAS,iBAAiB,EACzE,UAAU,EAAE,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,GAC7C,IAAI,CAaN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,KAAK,GAAG,OAAO,EACf,OAAO,SAAS,iBAAiB,GAAG,iBAAiB,EACrD,OAAO,EAAE,OAAO,GAAG,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,CAWtD;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,SAAS,OAAO,EAAE,CAE1D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEvD;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Singleton registry of template descriptors, keyed by `DocType`.
|
|
4
|
+
*
|
|
5
|
+
* Each `descriptors/{doc-type}.ts` file performs a side-effect at module load:
|
|
6
|
+
*
|
|
7
|
+
* import { registerDescriptor } from '../descriptors/registry';
|
|
8
|
+
* registerDescriptor(myDescriptor);
|
|
9
|
+
*
|
|
10
|
+
* The editor UI and render endpoints look up descriptors by `getDescriptor`.
|
|
11
|
+
* Adding a new doc type = adding a new file that calls `registerDescriptor`;
|
|
12
|
+
* NO change to the editor, the registry, or any consumer is needed.
|
|
13
|
+
*
|
|
14
|
+
* The registry deliberately uses module-singleton state. Tests can reset it
|
|
15
|
+
* via `_clearRegistryForTest`.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.registerDescriptor = registerDescriptor;
|
|
19
|
+
exports.getDescriptor = getDescriptor;
|
|
20
|
+
exports.getRegisteredDocTypes = getRegisteredDocTypes;
|
|
21
|
+
exports.hasDescriptor = hasDescriptor;
|
|
22
|
+
exports._clearRegistryForTest = _clearRegistryForTest;
|
|
23
|
+
const REGISTRY = new Map();
|
|
24
|
+
/**
|
|
25
|
+
* Register a descriptor. Throws on duplicate `docType` — each doc type
|
|
26
|
+
* registers exactly once. Catching the duplicate at registration time
|
|
27
|
+
* surfaces accidental double-imports (e.g., two paths both importing
|
|
28
|
+
* `descriptors/invoice.ts`) as a loud error rather than silent override.
|
|
29
|
+
*/
|
|
30
|
+
function registerDescriptor(descriptor) {
|
|
31
|
+
if (REGISTRY.has(descriptor.docType)) {
|
|
32
|
+
throw new Error(`[pdf-renderer] Duplicate descriptor registration for docType '${descriptor.docType}'. ` +
|
|
33
|
+
`Each docType must register exactly once. Check for duplicate imports of the same descriptor file.`);
|
|
34
|
+
}
|
|
35
|
+
// Double-cast through `unknown` is required because TS can't directly relate
|
|
36
|
+
// `TemplateDescriptor<TData, TConfig>` to `TemplateDescriptor<unknown, PdfTemplateConfig>`
|
|
37
|
+
// — the generic param positions are invariant. The store-as-unknown /
|
|
38
|
+
// cast-back-at-retrieval pattern is intentional; getDescriptor does the
|
|
39
|
+
// matching reverse cast.
|
|
40
|
+
REGISTRY.set(descriptor.docType, descriptor);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Look up a descriptor by `docType`. Throws with a helpful message listing
|
|
44
|
+
* the known docTypes if the requested one isn't registered — guards against
|
|
45
|
+
* typos at endpoint wire-up time.
|
|
46
|
+
*
|
|
47
|
+
* Generics: callers that know the concrete `TData` + `TConfig` for the docType
|
|
48
|
+
* can supply them to get a typed descriptor back. Callers that don't (e.g.,
|
|
49
|
+
* the editor UI iterating over all doc types) get the default
|
|
50
|
+
* `unknown / PdfTemplateConfig` shape and access only the descriptor-level
|
|
51
|
+
* metadata (configurableFields, defaults, sampleData).
|
|
52
|
+
*/
|
|
53
|
+
function getDescriptor(docType) {
|
|
54
|
+
const descriptor = REGISTRY.get(docType);
|
|
55
|
+
if (!descriptor) {
|
|
56
|
+
const known = [...REGISTRY.keys()];
|
|
57
|
+
throw new Error(`[pdf-renderer] No descriptor registered for docType '${docType}'. ` +
|
|
58
|
+
`Known: ${known.length > 0 ? known.join(', ') : '(none)'}.`);
|
|
59
|
+
}
|
|
60
|
+
// See registerDescriptor — this is the matching cast on the retrieval side.
|
|
61
|
+
return descriptor;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Return the list of currently-registered doc types. Used by the editor's
|
|
65
|
+
* settings page to enumerate template cards.
|
|
66
|
+
*/
|
|
67
|
+
function getRegisteredDocTypes() {
|
|
68
|
+
return [...REGISTRY.keys()];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Check whether a descriptor is registered without throwing. Useful for the
|
|
72
|
+
* editor when it wants to render disabled cards for not-yet-shipped doc
|
|
73
|
+
* types.
|
|
74
|
+
*/
|
|
75
|
+
function hasDescriptor(docType) {
|
|
76
|
+
return REGISTRY.has(docType);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Test-only escape hatch. Clears the registry so each spec file starts
|
|
80
|
+
* clean. Not exported from the public package surface.
|
|
81
|
+
*/
|
|
82
|
+
function _clearRegistryForTest() {
|
|
83
|
+
REGISTRY.clear();
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/descriptors/registry.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAsBH,gDAeC;AAaD,sCAcC;AAMD,sDAEC;AAOD,sCAEC;AAMD,sDAEC;AA3ED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA8B,CAAC;AAEvD;;;;;GAKG;AACH,SAAgB,kBAAkB,CAChC,UAA8C;IAE9C,IAAI,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACb,iEAAiE,UAAU,CAAC,OAAO,KAAK;YACtF,mGAAmG,CACtG,CAAC;IACJ,CAAC;IACD,6EAA6E;IAC7E,2FAA2F;IAC3F,sEAAsE;IACtE,wEAAwE;IACxE,yBAAyB;IACzB,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE,UAA0C,CAAC,CAAC;AAC/E,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,aAAa,CAG3B,OAAgB;IAChB,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACzC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,wDAAwD,OAAO,KAAK;YAClE,UAAU,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAC9D,CAAC;IACJ,CAAC;IACD,4EAA4E;IAC5E,OAAO,UAA2D,CAAC;AACrE,CAAC;AAED;;;GAGG;AACH,SAAgB,qBAAqB;IACnC,OAAO,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,OAAgB;IAC5C,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC/B,CAAC;AAED;;;GAGG;AACH,SAAgB,qBAAqB;IACnC,QAAQ,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type contracts for the TemplateDescriptor registry.
|
|
3
|
+
*
|
|
4
|
+
* A `TemplateDescriptor<TData, TConfig>` is the unit of extensibility in this
|
|
5
|
+
* library. Each future doc type (invoice, receipt, report card, admit card,
|
|
6
|
+
* ID card, certificate, …) ships exactly one descriptor file that registers
|
|
7
|
+
* itself at module load. The editor UI and per-domain render endpoints both
|
|
8
|
+
* look up descriptors by `docType` — neither needs to import the document
|
|
9
|
+
* components directly.
|
|
10
|
+
*
|
|
11
|
+
* Design source of truth: docs/pilot-greenlight/c-epic-pdf-generation-design.md §5.2.
|
|
12
|
+
*/
|
|
13
|
+
import type * as React from 'react';
|
|
14
|
+
import type { ImageSource } from '../core/fonts';
|
|
15
|
+
import type { Lang } from '../core/i18n';
|
|
16
|
+
/**
|
|
17
|
+
* Document types known to the renderer. Each value corresponds to exactly
|
|
18
|
+
* one descriptor registration. Extend this union when adding a new doc type.
|
|
19
|
+
*/
|
|
20
|
+
export type DocType = 'INVOICE' | 'RECEIPT' | 'REPORT_CARD' | 'ADMIT_CARD' | 'TRANSCRIPT' | 'STUDENT_ID_CARD' | 'BONAFIDE_CERTIFICATE' | 'TRANSFER_CERTIFICATE' | 'HALL_TICKET' | 'FEE_STATEMENT' | 'ATTENDANCE_SHEET' | 'MARK_LIST';
|
|
21
|
+
/**
|
|
22
|
+
* Tenant archetype the renderer recognizes when computing defaults.
|
|
23
|
+
* Locked here to match `@aibrains/shared-types` Archetype enum. Reserved
|
|
24
|
+
* archetypes (`CBSE_IN`, `NAIS_US`, `GEMS_UAE`) are accepted in the type
|
|
25
|
+
* but a descriptor's `defaults(archetype, …)` SHOULD fall back to the
|
|
26
|
+
* GENERIC profile for any value it doesn't explicitly handle — V1 only
|
|
27
|
+
* exercises `'PABSON'` and `'GENERIC'`.
|
|
28
|
+
*/
|
|
29
|
+
export type Archetype = 'PABSON' | 'GENERIC' | 'CBSE_IN' | 'NAIS_US' | 'GEMS_UAE';
|
|
30
|
+
/**
|
|
31
|
+
* Minimal branding shape consumed by document Components.
|
|
32
|
+
*
|
|
33
|
+
* Templates accept this as `branding` and forward selected fields to the
|
|
34
|
+
* `BrandedHeader` / `SignatureLine` / `Watermark` primitives. Local to the
|
|
35
|
+
* renderer; consumers map `@aibrains/shared-types`'s `SchoolBranding` to
|
|
36
|
+
* this shape at the endpoint boundary (Sprint C.0.5 + C.1).
|
|
37
|
+
*
|
|
38
|
+
* Property order is alphabetical to keep the type readable as it grows.
|
|
39
|
+
*/
|
|
40
|
+
export interface PdfBranding {
|
|
41
|
+
accentColor?: string;
|
|
42
|
+
addressLines?: string[];
|
|
43
|
+
email?: string;
|
|
44
|
+
formalName?: string;
|
|
45
|
+
letterheadBackgroundSrc?: ImageSource;
|
|
46
|
+
logoSrc?: ImageSource;
|
|
47
|
+
panNumber?: string;
|
|
48
|
+
phone?: string;
|
|
49
|
+
primaryColor?: string;
|
|
50
|
+
principalSignatureSrc?: ImageSource;
|
|
51
|
+
schoolName?: string;
|
|
52
|
+
tagline?: string;
|
|
53
|
+
vatNumber?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Minimal locale + regional settings consumed by document Components.
|
|
57
|
+
* Sourced from `WorkspaceSettings` + `SchoolConfiguration` in production;
|
|
58
|
+
* the descriptor doesn't care which layer of the precedence chain produced
|
|
59
|
+
* each value.
|
|
60
|
+
*/
|
|
61
|
+
export interface PdfLocaleSettings {
|
|
62
|
+
/** BCP 47 — e.g., 'en-US', 'ne-NP'. */
|
|
63
|
+
defaultLocale: string;
|
|
64
|
+
/** ISO 4217 — e.g., 'NPR', 'USD', 'INR'. */
|
|
65
|
+
defaultCurrency: string;
|
|
66
|
+
defaultCalendarSystem: 'gregorian' | 'bikram_sambat';
|
|
67
|
+
/** IANA timezone string. */
|
|
68
|
+
defaultTimeZone?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The shared base config every PDF template has. Per-doc-type config (the
|
|
72
|
+
* `TConfig` generic on `TemplateDescriptor`) extends this with
|
|
73
|
+
* domain-specific options — e.g., an `InvoiceTemplateConfig` adds
|
|
74
|
+
* `lineItemColumns` + `totalsSection`.
|
|
75
|
+
*/
|
|
76
|
+
export interface PdfTemplateConfig {
|
|
77
|
+
pageSize: 'A4' | 'A5' | 'LETTER';
|
|
78
|
+
orientation: 'portrait' | 'landscape';
|
|
79
|
+
margins: {
|
|
80
|
+
top: number;
|
|
81
|
+
right: number;
|
|
82
|
+
bottom: number;
|
|
83
|
+
left: number;
|
|
84
|
+
};
|
|
85
|
+
header: {
|
|
86
|
+
showLogo: boolean;
|
|
87
|
+
showSchoolName: boolean;
|
|
88
|
+
showSchoolAddress: boolean;
|
|
89
|
+
showContact: boolean;
|
|
90
|
+
tagline?: string;
|
|
91
|
+
};
|
|
92
|
+
footer: {
|
|
93
|
+
text?: string;
|
|
94
|
+
showPageNumbers: boolean;
|
|
95
|
+
};
|
|
96
|
+
dateFormat: 'gregorian' | 'bikram_sambat' | 'dual';
|
|
97
|
+
numberFormat: 'south-asian' | 'western' | 'auto-from-workspace';
|
|
98
|
+
currencyDisplay: 'symbol' | 'iso-code' | 'name';
|
|
99
|
+
/**
|
|
100
|
+
* At minimum one entry; two entries enables dual-language label rendering
|
|
101
|
+
* (e.g., `['en', 'ne']` → "Subtotal" + "उप-योग" stacked or inline).
|
|
102
|
+
*
|
|
103
|
+
* Encoded as a **non-empty tuple type** so the compiler rejects empty
|
|
104
|
+
* arrays at the call site — the runtime invariant "every template must
|
|
105
|
+
* have at least one label language" is enforced by the type itself, not
|
|
106
|
+
* by a runtime check buried in the renderer.
|
|
107
|
+
*/
|
|
108
|
+
labelLanguages: readonly [Lang, ...Lang[]];
|
|
109
|
+
/** Per-template branding overrides — rare; most templates inherit school branding. */
|
|
110
|
+
brandingOverrides?: Partial<PdfBranding>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A single configurable form field surfaced in the template editor UI.
|
|
114
|
+
*
|
|
115
|
+
* The editor reads each descriptor's `configurableFields[]` and generates
|
|
116
|
+
* form sections automatically. **Adding a new editable field = appending one
|
|
117
|
+
* entry here; the editor needs no code change.** This is the property that
|
|
118
|
+
* makes the editor work uniformly across all 12+ planned doc types.
|
|
119
|
+
*/
|
|
120
|
+
export interface ConfigurableField {
|
|
121
|
+
/**
|
|
122
|
+
* Dot path into `TConfig` for this field's value.
|
|
123
|
+
* Example: `'lineItemColumns.discount'`, `'header.tagline'`, `'pageSize'`.
|
|
124
|
+
*/
|
|
125
|
+
path: string;
|
|
126
|
+
/** Form-input type. The editor maps each to a primitive from `@edforge/forms`. */
|
|
127
|
+
type: 'text' | 'textarea' | 'toggle' | 'select' | 'multiselect' | 'color' | 'file' | 'number';
|
|
128
|
+
/** i18n key for the field label. Resolved per current editor locale. */
|
|
129
|
+
labelKey: string;
|
|
130
|
+
/** i18n key for an optional help/description tooltip. */
|
|
131
|
+
descriptionKey?: string;
|
|
132
|
+
/** Choices for `select` / `multiselect`. */
|
|
133
|
+
options?: readonly string[];
|
|
134
|
+
/** File `accept` attribute for `file` type. Example: `'.png,.jpg,.svg'`. */
|
|
135
|
+
accept?: string;
|
|
136
|
+
/** Max file size in bytes for `file` type. */
|
|
137
|
+
maxSizeBytes?: number;
|
|
138
|
+
/** Minimum items for `multiselect`. */
|
|
139
|
+
minItems?: number;
|
|
140
|
+
/**
|
|
141
|
+
* Conditional display: only render this field when another field's value
|
|
142
|
+
* equals the given value. Useful for toggling sub-sections on/off.
|
|
143
|
+
*/
|
|
144
|
+
visibleIf?: {
|
|
145
|
+
path: string;
|
|
146
|
+
equals: unknown;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Props every document Component accepts. Stable across all doc types so the
|
|
151
|
+
* editor and render endpoints don't need per-doc-type adapter code.
|
|
152
|
+
*/
|
|
153
|
+
export interface DocumentComponentProps<TData, TConfig extends PdfTemplateConfig> {
|
|
154
|
+
data: TData;
|
|
155
|
+
template: TConfig;
|
|
156
|
+
branding: PdfBranding;
|
|
157
|
+
settings: PdfLocaleSettings;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The contract every doc-type descriptor satisfies.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* import { registerDescriptor, type TemplateDescriptor } from '@aibrains/pdf-renderer';
|
|
164
|
+
*
|
|
165
|
+
* const invoiceDescriptor: TemplateDescriptor<Invoice, InvoiceTemplateConfig> = {
|
|
166
|
+
* docType: 'INVOICE',
|
|
167
|
+
* i18nNamespace: 'invoice',
|
|
168
|
+
* Component: InvoicePdf,
|
|
169
|
+
* defaults: (archetype, locale) => ({ ... }),
|
|
170
|
+
* sampleData: (archetype, locale) => ({ ... }),
|
|
171
|
+
* configurableFields: [ ... ],
|
|
172
|
+
* };
|
|
173
|
+
*
|
|
174
|
+
* registerDescriptor(invoiceDescriptor);
|
|
175
|
+
*/
|
|
176
|
+
export interface TemplateDescriptor<TData, TConfig extends PdfTemplateConfig> {
|
|
177
|
+
/** Globally unique discriminator (e.g., `'INVOICE'`, `'REPORT_CARD'`). */
|
|
178
|
+
docType: DocType;
|
|
179
|
+
/**
|
|
180
|
+
* i18n namespace this descriptor's labels live under. Translations are
|
|
181
|
+
* bundled in `src/i18n/{lang}/{namespace}.json` and loaded by the editor
|
|
182
|
+
* + the document component.
|
|
183
|
+
*/
|
|
184
|
+
i18nNamespace: string;
|
|
185
|
+
/**
|
|
186
|
+
* The React component that renders the document. Both
|
|
187
|
+
* `renderToBuffer` (Node) and `<PDFViewer>` (browser) invoke this with
|
|
188
|
+
* the standard four props.
|
|
189
|
+
*/
|
|
190
|
+
Component: React.ComponentType<DocumentComponentProps<TData, TConfig>>;
|
|
191
|
+
/**
|
|
192
|
+
* Returns the default config for a fresh template, parameterized by
|
|
193
|
+
* archetype + locale. For PABSON tenants this should produce
|
|
194
|
+
* BS+AD dual dates, EN+NE labels, ne-NP locale, NPR, south-asian numbers
|
|
195
|
+
* — sensible defaults so the lazy-seed path produces a usable PDF
|
|
196
|
+
* without any operator action.
|
|
197
|
+
*/
|
|
198
|
+
defaults(archetype: Archetype, locale: string): TConfig;
|
|
199
|
+
/**
|
|
200
|
+
* Returns mock data for the editor's live preview when the operator
|
|
201
|
+
* hasn't yet selected a real document to preview against.
|
|
202
|
+
*/
|
|
203
|
+
sampleData(archetype: Archetype, locale: string): TData;
|
|
204
|
+
/** Editor-form-rendering metadata. The order is the field order in the UI. */
|
|
205
|
+
configurableFields: readonly ConfigurableField[];
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/descriptors/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AACpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC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A8C;IAC9C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC;CAC/C;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB,CAAC,KAAK,EAAE,OAAO,SAAS,iBAAiB;IAC9E,IAAI,EAAE,KAAK,CAAC;IACZ,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,WAAW,CAAC;IACtB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,kBAAkB,CAAC,KAAK,EAAE,OAAO,SAAS,iBAAiB;IAC1E,0EAA0E;IAC1E,OAAO,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,sBAAsB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;IACvE;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IACxD;;;OAGG;IACH,UAAU,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACxD,8EAA8E;IAC9E,kBAAkB,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAClD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Type contracts for the TemplateDescriptor registry.
|
|
4
|
+
*
|
|
5
|
+
* A `TemplateDescriptor<TData, TConfig>` is the unit of extensibility in this
|
|
6
|
+
* library. Each future doc type (invoice, receipt, report card, admit card,
|
|
7
|
+
* ID card, certificate, …) ships exactly one descriptor file that registers
|
|
8
|
+
* itself at module load. The editor UI and per-domain render endpoints both
|
|
9
|
+
* look up descriptors by `docType` — neither needs to import the document
|
|
10
|
+
* components directly.
|
|
11
|
+
*
|
|
12
|
+
* Design source of truth: docs/pilot-greenlight/c-epic-pdf-generation-design.md §5.2.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/descriptors/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Design source of truth: docs/pilot-greenlight/c-epic-pdf-generation-design.md
|
|
16
16
|
*/
|
|
17
|
-
export declare const PDF_RENDERER_PACKAGE_VERSION = "0.
|
|
17
|
+
export declare const PDF_RENDERER_PACKAGE_VERSION = "0.4.0";
|
|
18
18
|
export * from './core';
|
|
19
19
|
export * from './primitives';
|
|
20
20
|
export * from './components';
|
|
21
|
+
export * from './descriptors';
|
|
21
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,4BAA4B,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,4BAA4B,UAAU,CAAC;AAIpD,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -31,9 +31,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
31
31
|
};
|
|
32
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
33
|
exports.PDF_RENDERER_PACKAGE_VERSION = void 0;
|
|
34
|
-
exports.PDF_RENDERER_PACKAGE_VERSION = '0.
|
|
35
|
-
// Re-export the C.0.2 core API surface + C.0.3 primitives + components
|
|
34
|
+
exports.PDF_RENDERER_PACKAGE_VERSION = '0.4.0';
|
|
35
|
+
// Re-export the C.0.2 core API surface + C.0.3 primitives + components
|
|
36
|
+
// + C.0.4 descriptor registry.
|
|
36
37
|
__exportStar(require("./core"), exports);
|
|
37
38
|
__exportStar(require("./primitives"), exports);
|
|
38
39
|
__exportStar(require("./components"), exports);
|
|
40
|
+
__exportStar(require("./descriptors"), exports);
|
|
39
41
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;AAEU,QAAA,4BAA4B,GAAG,OAAO,CAAC;AAEpD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;AAEU,QAAA,4BAA4B,GAAG,OAAO,CAAC;AAEpD,uEAAuE;AACvE,+BAA+B;AAC/B,yCAAuB;AACvB,+CAA6B;AAC7B,+CAA6B;AAC7B,gDAA8B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aibrains/pdf-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "EdForge PDF rendering library. JSX-based document templates built on @react-pdf/renderer, with localization (EN + NE), Bikram Sambat date support, and a TemplateDescriptor registry for cross-domain doc types (invoice, receipt, report card, admit card, etc.).",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -24,6 +24,11 @@
|
|
|
24
24
|
"types": "./dist/components/index.d.ts",
|
|
25
25
|
"require": "./dist/components/index.js",
|
|
26
26
|
"default": "./dist/components/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./descriptors": {
|
|
29
|
+
"types": "./dist/descriptors/index.d.ts",
|
|
30
|
+
"require": "./dist/descriptors/index.js",
|
|
31
|
+
"default": "./dist/descriptors/index.js"
|
|
27
32
|
}
|
|
28
33
|
},
|
|
29
34
|
"files": [
|