@aibrains/pdf-renderer 0.2.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/components/KeyValueTable.d.ts +23 -0
- package/dist/components/KeyValueTable.d.ts.map +1 -0
- package/dist/components/KeyValueTable.js +37 -0
- package/dist/components/KeyValueTable.js.map +1 -0
- package/dist/components/LineItemTable.d.ts +53 -0
- package/dist/components/LineItemTable.d.ts.map +1 -0
- package/dist/components/LineItemTable.js +99 -0
- package/dist/components/LineItemTable.js.map +1 -0
- package/dist/components/SignatureLine.d.ts +24 -0
- package/dist/components/SignatureLine.d.ts.map +1 -0
- package/dist/components/SignatureLine.js +34 -0
- package/dist/components/SignatureLine.js.map +1 -0
- package/dist/components/TotalsBlock.d.ts +41 -0
- package/dist/components/TotalsBlock.d.ts.map +1 -0
- package/dist/components/TotalsBlock.js +59 -0
- package/dist/components/TotalsBlock.js.map +1 -0
- package/dist/components/index.d.ts +20 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +23 -0
- package/dist/components/index.js.map +1 -0
- package/dist/core/fonts.d.ts +87 -0
- package/dist/core/fonts.d.ts.map +1 -0
- package/dist/core/fonts.js +159 -0
- package/dist/core/fonts.js.map +1 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +6 -1
- package/dist/core/index.js.map +1 -1
- 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 +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/primitives/BrandedFooter.d.ts +18 -0
- package/dist/primitives/BrandedFooter.d.ts.map +1 -0
- package/dist/primitives/BrandedFooter.js +35 -0
- package/dist/primitives/BrandedFooter.js.map +1 -0
- package/dist/primitives/BrandedHeader.d.ts +41 -0
- package/dist/primitives/BrandedHeader.d.ts.map +1 -0
- package/dist/primitives/BrandedHeader.js +52 -0
- package/dist/primitives/BrandedHeader.js.map +1 -0
- package/dist/primitives/Document.d.ts +21 -0
- package/dist/primitives/Document.d.ts.map +1 -0
- package/dist/primitives/Document.js +19 -0
- package/dist/primitives/Document.js.map +1 -0
- package/dist/primitives/Page.d.ts +27 -0
- package/dist/primitives/Page.d.ts.map +1 -0
- package/dist/primitives/Page.js +32 -0
- package/dist/primitives/Page.js.map +1 -0
- package/dist/primitives/Watermark.d.ts +25 -0
- package/dist/primitives/Watermark.d.ts.map +1 -0
- package/dist/primitives/Watermark.js +35 -0
- package/dist/primitives/Watermark.js.map +1 -0
- package/dist/primitives/index.d.ts +21 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +24 -0
- package/dist/primitives/index.js.map +1 -0
- package/fonts/NotoSans-Bold.woff +0 -0
- package/fonts/NotoSans-Regular.woff +0 -0
- package/fonts/NotoSansDevanagari-Bold.woff +0 -0
- package/fonts/NotoSansDevanagari-Regular.woff +0 -0
- package/package.json +31 -5
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Font registration for @aibrains/pdf-renderer.
|
|
4
|
+
*
|
|
5
|
+
* Two font families ship with the package:
|
|
6
|
+
* - `Noto Sans` — Latin script (Regular + Bold)
|
|
7
|
+
* - `Noto Sans Devanagari` — Devanagari script for Nepali (Regular + Bold)
|
|
8
|
+
*
|
|
9
|
+
* Both are sourced from @fontsource/* at build time and copied to ./fonts/ at the
|
|
10
|
+
* package root (see scripts/copy-fonts.js). At runtime, paths resolve identically
|
|
11
|
+
* from `src/core/fonts.ts` and `dist/core/fonts.js` because both live two
|
|
12
|
+
* directories below the package root (../../fonts/).
|
|
13
|
+
*
|
|
14
|
+
* Devanagari rendering uses Yoga + Fontkit + Harfbuzz inside @react-pdf/renderer v4
|
|
15
|
+
* to handle complex script shaping (conjuncts, vowel marks). This is the canary for
|
|
16
|
+
* Risk R45 (Devanagari shaping defects in production); snapshot tests in the
|
|
17
|
+
* primitives + components directories exercise the pipeline.
|
|
18
|
+
*
|
|
19
|
+
* Call `registerFonts()` exactly once per process before the first render. The
|
|
20
|
+
* `Document` primitive (in `primitives/Document.tsx`) does this automatically.
|
|
21
|
+
*
|
|
22
|
+
* For browser consumers (Shell live-preview via `<PDFViewer>`), the same fonts
|
|
23
|
+
* are bundled in the published tarball; consumers' bundlers (Rsbuild, Webpack)
|
|
24
|
+
* pick them up via the relative path. URL-based registration for CDN deployments
|
|
25
|
+
* is a Sprint C.2 concern.
|
|
26
|
+
*/
|
|
27
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
30
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
31
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
32
|
+
}
|
|
33
|
+
Object.defineProperty(o, k2, desc);
|
|
34
|
+
}) : (function(o, m, k, k2) {
|
|
35
|
+
if (k2 === undefined) k2 = k;
|
|
36
|
+
o[k2] = m[k];
|
|
37
|
+
}));
|
|
38
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
39
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
40
|
+
}) : function(o, v) {
|
|
41
|
+
o["default"] = v;
|
|
42
|
+
});
|
|
43
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
44
|
+
var ownKeys = function(o) {
|
|
45
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
46
|
+
var ar = [];
|
|
47
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
48
|
+
return ar;
|
|
49
|
+
};
|
|
50
|
+
return ownKeys(o);
|
|
51
|
+
};
|
|
52
|
+
return function (mod) {
|
|
53
|
+
if (mod && mod.__esModule) return mod;
|
|
54
|
+
var result = {};
|
|
55
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
56
|
+
__setModuleDefault(result, mod);
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
})();
|
|
60
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
+
exports.FONT_FAMILY_DEVANAGARI = exports.FONT_FAMILY_LATIN = void 0;
|
|
62
|
+
exports.pickFontFamily = pickFontFamily;
|
|
63
|
+
exports.registerFonts = registerFonts;
|
|
64
|
+
exports._resetFontsForTest = _resetFontsForTest;
|
|
65
|
+
const path = __importStar(require("node:path"));
|
|
66
|
+
const renderer_1 = require("@react-pdf/renderer");
|
|
67
|
+
const PACKAGE_ROOT = path.resolve(__dirname, '..', '..');
|
|
68
|
+
const FONT_DIR = path.join(PACKAGE_ROOT, 'fonts');
|
|
69
|
+
/** Latin font family registered by `registerFonts()`. */
|
|
70
|
+
exports.FONT_FAMILY_LATIN = 'Noto Sans';
|
|
71
|
+
/** Devanagari (Nepali) font family registered by `registerFonts()`. */
|
|
72
|
+
exports.FONT_FAMILY_DEVANAGARI = 'Noto Sans Devanagari';
|
|
73
|
+
// Unicode range U+0900..U+097F covers the full Devanagari block. Any codepoint
|
|
74
|
+
// in that range means the run contains Devanagari script and needs the
|
|
75
|
+
// Devanagari font. Latin (Basic Latin + Latin-1 Supplement) lives outside
|
|
76
|
+
// this range — we route it to the default Latin family. Mixed runs are split
|
|
77
|
+
// into multiple <Text> elements by the component layer.
|
|
78
|
+
const DEVANAGARI_RANGE = /[ऀ-ॿ]/;
|
|
79
|
+
/**
|
|
80
|
+
* Pick the correct font family for a text run.
|
|
81
|
+
*
|
|
82
|
+
* `@react-pdf/renderer` does NOT support CSS-style font-fallback chains —
|
|
83
|
+
* each text run uses exactly one font family. For mixed-script content
|
|
84
|
+
* (e.g., dual-language labels "Invoice / बिल"), components must split into
|
|
85
|
+
* separate `<Text>` elements and call this helper per segment.
|
|
86
|
+
*
|
|
87
|
+
* Detection rule: **any-Devanagari-wins**. The implementation tests
|
|
88
|
+
* `DEVANAGARI_RANGE.test(str)`, which returns true if ANY codepoint in the
|
|
89
|
+
* string falls in the Devanagari block — regardless of position. So
|
|
90
|
+
* `pickFontFamily('Invoice / बिल')` returns `FONT_FAMILY_DEVANAGARI` even
|
|
91
|
+
* though Latin appears first. This is intentional for V1: when a Devanagari
|
|
92
|
+
* character is present, we always need its font to render correctly; the
|
|
93
|
+
* Latin characters in `Noto Sans Devanagari` render acceptably (the font
|
|
94
|
+
* includes Basic Latin glyphs). If first-script-wins semantics are ever
|
|
95
|
+
* needed, change `DEVANAGARI_RANGE.test(str)` to scan only the first script
|
|
96
|
+
* cluster.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* pickFontFamily('Subtotal') // 'Noto Sans'
|
|
100
|
+
* pickFontFamily('उप-योग') // 'Noto Sans Devanagari'
|
|
101
|
+
* pickFontFamily('Invoice / बिल') // 'Noto Sans Devanagari' (any-Devanagari-wins)
|
|
102
|
+
* pickFontFamily('बिल / Invoice') // 'Noto Sans Devanagari'
|
|
103
|
+
* pickFontFamily('') // 'Noto Sans' (default for empty / null / undefined)
|
|
104
|
+
*/
|
|
105
|
+
function pickFontFamily(text) {
|
|
106
|
+
if (text === null || text === undefined || text === '')
|
|
107
|
+
return exports.FONT_FAMILY_LATIN;
|
|
108
|
+
const str = String(text);
|
|
109
|
+
return DEVANAGARI_RANGE.test(str) ? exports.FONT_FAMILY_DEVANAGARI : exports.FONT_FAMILY_LATIN;
|
|
110
|
+
}
|
|
111
|
+
let registered = false;
|
|
112
|
+
/**
|
|
113
|
+
* Register the bundled fonts with `@react-pdf/renderer`. Idempotent — safe to
|
|
114
|
+
* call multiple times; subsequent calls short-circuit.
|
|
115
|
+
*
|
|
116
|
+
* Throws if the font files are not on disk (which means `npm run build` was
|
|
117
|
+
* never run after installation). Surfaces a clear error rather than silently
|
|
118
|
+
* rendering with the default font.
|
|
119
|
+
*/
|
|
120
|
+
function registerFonts() {
|
|
121
|
+
if (registered)
|
|
122
|
+
return;
|
|
123
|
+
// @react-pdf/renderer uses NUMERIC fontWeight internally (400 for normal,
|
|
124
|
+
// 700 for bold). Passing the string 'normal'/'bold' to Font.register stores
|
|
125
|
+
// them as strings but the resolver looks up numerics, so the registration
|
|
126
|
+
// doesn't match at render time. Use numeric weights at registration to match.
|
|
127
|
+
renderer_1.Font.register({
|
|
128
|
+
family: exports.FONT_FAMILY_LATIN,
|
|
129
|
+
fonts: [
|
|
130
|
+
{
|
|
131
|
+
src: path.join(FONT_DIR, 'NotoSans-Regular.woff'),
|
|
132
|
+
fontWeight: 400,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
src: path.join(FONT_DIR, 'NotoSans-Bold.woff'),
|
|
136
|
+
fontWeight: 700,
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
});
|
|
140
|
+
renderer_1.Font.register({
|
|
141
|
+
family: exports.FONT_FAMILY_DEVANAGARI,
|
|
142
|
+
fonts: [
|
|
143
|
+
{
|
|
144
|
+
src: path.join(FONT_DIR, 'NotoSansDevanagari-Regular.woff'),
|
|
145
|
+
fontWeight: 400,
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
src: path.join(FONT_DIR, 'NotoSansDevanagari-Bold.woff'),
|
|
149
|
+
fontWeight: 700,
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
});
|
|
153
|
+
registered = true;
|
|
154
|
+
}
|
|
155
|
+
/** Test-only escape hatch — resets the registration guard so a test can re-register. */
|
|
156
|
+
function _resetFontsForTest() {
|
|
157
|
+
registered = false;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=fonts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fonts.js","sourceRoot":"","sources":["../../src/core/fonts.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CH,wCAMC;AAgCD,sCAoCC;AAGD,gDAEC;AA3HD,gDAAkC;AAClC,kDAA2C;AAE3C,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACzD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AAElD,yDAAyD;AAC5C,QAAA,iBAAiB,GAAG,WAAoB,CAAC;AACtD,uEAAuE;AAC1D,QAAA,sBAAsB,GAAG,sBAA+B,CAAC;AAEtE,+EAA+E;AAC/E,uEAAuE;AACvE,0EAA0E;AAC1E,6EAA6E;AAC7E,wDAAwD;AACxD,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,cAAc,CAC5B,IAAwC;IAExC,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,yBAAiB,CAAC;IACjF,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACzB,OAAO,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,8BAAsB,CAAC,CAAC,CAAC,yBAAiB,CAAC;AACjF,CAAC;AAsBD,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB;;;;;;;GAOG;AACH,SAAgB,aAAa;IAC3B,IAAI,UAAU;QAAE,OAAO;IAEvB,0EAA0E;IAC1E,4EAA4E;IAC5E,0EAA0E;IAC1E,8EAA8E;IAC9E,eAAI,CAAC,QAAQ,CAAC;QACZ,MAAM,EAAE,yBAAiB;QACzB,KAAK,EAAE;YACL;gBACE,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,uBAAuB,CAAC;gBACjD,UAAU,EAAE,GAAG;aAChB;YACD;gBACE,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,oBAAoB,CAAC;gBAC9C,UAAU,EAAE,GAAG;aAChB;SACF;KACF,CAAC,CAAC;IAEH,eAAI,CAAC,QAAQ,CAAC;QACZ,MAAM,EAAE,8BAAsB;QAC9B,KAAK,EAAE;YACL;gBACE,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,iCAAiC,CAAC;gBAC3D,UAAU,EAAE,GAAG;aAChB;YACD;gBACE,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,8BAA8B,CAAC;gBACxD,UAAU,EAAE,GAAG;aAChB;SACF;KACF,CAAC,CAAC;IAEH,UAAU,GAAG,IAAI,CAAC;AACpB,CAAC;AAED,wFAAwF;AACxF,SAAgB,kBAAkB;IAChC,UAAU,GAAG,KAAK,CAAC;AACrB,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -11,4 +11,6 @@ export { t, tDual } from './i18n';
|
|
|
11
11
|
export type { Lang, Namespace } from './i18n';
|
|
12
12
|
export { formatDate, formatNumber, formatCurrency } from './format';
|
|
13
13
|
export type { DateFormat, NumberGrouping } from './format';
|
|
14
|
+
export { registerFonts, pickFontFamily, FONT_FAMILY_LATIN, FONT_FAMILY_DEVANAGARI, } from './fonts';
|
|
15
|
+
export type { ImageSource } from './fonts';
|
|
14
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAClC,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACpE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAClC,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACpE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE3D,OAAO,EACL,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* and reusable components on top of these.
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.formatCurrency = exports.formatNumber = exports.formatDate = exports.tDual = exports.t = exports.DEFAULT_MARGINS_MM = exports.DEFAULT_FONT_SIZE = exports.DEFAULT_SPACING = exports.DEFAULT_COLORS = void 0;
|
|
10
|
+
exports.FONT_FAMILY_DEVANAGARI = exports.FONT_FAMILY_LATIN = exports.pickFontFamily = exports.registerFonts = exports.formatCurrency = exports.formatNumber = exports.formatDate = exports.tDual = exports.t = exports.DEFAULT_MARGINS_MM = exports.DEFAULT_FONT_SIZE = exports.DEFAULT_SPACING = exports.DEFAULT_COLORS = void 0;
|
|
11
11
|
var theme_1 = require("./theme");
|
|
12
12
|
Object.defineProperty(exports, "DEFAULT_COLORS", { enumerable: true, get: function () { return theme_1.DEFAULT_COLORS; } });
|
|
13
13
|
Object.defineProperty(exports, "DEFAULT_SPACING", { enumerable: true, get: function () { return theme_1.DEFAULT_SPACING; } });
|
|
@@ -20,4 +20,9 @@ var format_1 = require("./format");
|
|
|
20
20
|
Object.defineProperty(exports, "formatDate", { enumerable: true, get: function () { return format_1.formatDate; } });
|
|
21
21
|
Object.defineProperty(exports, "formatNumber", { enumerable: true, get: function () { return format_1.formatNumber; } });
|
|
22
22
|
Object.defineProperty(exports, "formatCurrency", { enumerable: true, get: function () { return format_1.formatCurrency; } });
|
|
23
|
+
var fonts_1 = require("./fonts");
|
|
24
|
+
Object.defineProperty(exports, "registerFonts", { enumerable: true, get: function () { return fonts_1.registerFonts; } });
|
|
25
|
+
Object.defineProperty(exports, "pickFontFamily", { enumerable: true, get: function () { return fonts_1.pickFontFamily; } });
|
|
26
|
+
Object.defineProperty(exports, "FONT_FAMILY_LATIN", { enumerable: true, get: function () { return fonts_1.FONT_FAMILY_LATIN; } });
|
|
27
|
+
Object.defineProperty(exports, "FONT_FAMILY_DEVANAGARI", { enumerable: true, get: function () { return fonts_1.FONT_FAMILY_DEVANAGARI; } });
|
|
23
28
|
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,iCAKiB;AAJf,uGAAA,cAAc,OAAA;AACd,wGAAA,eAAe,OAAA;AACf,0GAAA,iBAAiB,OAAA;AACjB,2GAAA,kBAAkB,OAAA;AAIpB,+BAAkC;AAAzB,yFAAA,CAAC,OAAA;AAAE,6FAAA,KAAK,OAAA;AAGjB,mCAAoE;AAA3D,oGAAA,UAAU,OAAA;AAAE,sGAAA,YAAY,OAAA;AAAE,wGAAA,cAAc,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,iCAKiB;AAJf,uGAAA,cAAc,OAAA;AACd,wGAAA,eAAe,OAAA;AACf,0GAAA,iBAAiB,OAAA;AACjB,2GAAA,kBAAkB,OAAA;AAIpB,+BAAkC;AAAzB,yFAAA,CAAC,OAAA;AAAE,6FAAA,KAAK,OAAA;AAGjB,mCAAoE;AAA3D,oGAAA,UAAU,OAAA;AAAE,sGAAA,YAAY,OAAA;AAAE,wGAAA,cAAc,OAAA;AAGjD,iCAKiB;AAJf,sGAAA,aAAa,OAAA;AACb,uGAAA,cAAc,OAAA;AACd,0GAAA,iBAAiB,OAAA;AACjB,+GAAA,sBAAsB,OAAA"}
|
|
@@ -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":"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"}
|
|
@@ -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,6 +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
|
+
export * from './primitives';
|
|
20
|
+
export * from './components';
|
|
21
|
+
export * from './descriptors';
|
|
19
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"}
|