@nxgt/material-core 0.1.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.
Files changed (138) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +335 -0
  3. package/dist/chunks/index-0xc5q9tp.js +81 -0
  4. package/dist/chunks/index-0xc5q9tp.js.map +10 -0
  5. package/dist/chunks/index-2gcgcmc0.js +36 -0
  6. package/dist/chunks/index-2gcgcmc0.js.map +10 -0
  7. package/dist/chunks/index-3ca6xe71.js +36 -0
  8. package/dist/chunks/index-3ca6xe71.js.map +10 -0
  9. package/dist/chunks/index-5r6rzp43.js +90 -0
  10. package/dist/chunks/index-5r6rzp43.js.map +10 -0
  11. package/dist/chunks/index-6tn0wjsb.js +13 -0
  12. package/dist/chunks/index-6tn0wjsb.js.map +10 -0
  13. package/dist/chunks/index-8gf9e2d4.js +76 -0
  14. package/dist/chunks/index-8gf9e2d4.js.map +11 -0
  15. package/dist/chunks/index-eh0e5ex7.js +61 -0
  16. package/dist/chunks/index-eh0e5ex7.js.map +10 -0
  17. package/dist/chunks/index-g7rh8fpv.js +57 -0
  18. package/dist/chunks/index-g7rh8fpv.js.map +10 -0
  19. package/dist/chunks/index-h3vjydz7.js +113 -0
  20. package/dist/chunks/index-h3vjydz7.js.map +10 -0
  21. package/dist/chunks/index-paaaedrm.js +37 -0
  22. package/dist/chunks/index-paaaedrm.js.map +10 -0
  23. package/dist/chunks/index-w3ajz57t.js +72 -0
  24. package/dist/chunks/index-w3ajz57t.js.map +10 -0
  25. package/dist/chunks/index-z3yjh0a8.js +642 -0
  26. package/dist/chunks/index-z3yjh0a8.js.map +18 -0
  27. package/dist/index.d.ts +21 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +133 -0
  30. package/dist/index.js.map +9 -0
  31. package/dist/lib/currency-digits.d.ts +8 -0
  32. package/dist/lib/currency-digits.d.ts.map +1 -0
  33. package/dist/lib/currency-digits.js +24 -0
  34. package/dist/lib/currency-digits.js.map +10 -0
  35. package/dist/lib/field-blur-layers.d.ts +35 -0
  36. package/dist/lib/field-blur-layers.d.ts.map +1 -0
  37. package/dist/lib/field-blur-layers.js +52 -0
  38. package/dist/lib/field-blur-layers.js.map +10 -0
  39. package/dist/lib/pdf-download.d.ts +36 -0
  40. package/dist/lib/pdf-download.d.ts.map +1 -0
  41. package/dist/lib/pdf-download.js +15 -0
  42. package/dist/lib/pdf-download.js.map +9 -0
  43. package/dist/lib/pdf-file-name.d.ts +10 -0
  44. package/dist/lib/pdf-file-name.d.ts.map +1 -0
  45. package/dist/lib/pdf-file-name.js +12 -0
  46. package/dist/lib/pdf-file-name.js.map +9 -0
  47. package/dist/lib/pdf-source.d.ts +58 -0
  48. package/dist/lib/pdf-source.d.ts.map +1 -0
  49. package/dist/lib/pdf-source.js +21 -0
  50. package/dist/lib/pdf-source.js.map +9 -0
  51. package/dist/lib/print-format.utils.d.ts +72 -0
  52. package/dist/lib/print-format.utils.d.ts.map +1 -0
  53. package/dist/lib/print-format.utils.js +14 -0
  54. package/dist/lib/print-format.utils.js.map +9 -0
  55. package/dist/lib/print-fraction-digits.d.ts +13 -0
  56. package/dist/lib/print-fraction-digits.d.ts.map +1 -0
  57. package/dist/lib/print-fraction-digits.js +11 -0
  58. package/dist/lib/print-fraction-digits.js.map +9 -0
  59. package/dist/lib/print-table.utils.d.ts +69 -0
  60. package/dist/lib/print-table.utils.d.ts.map +1 -0
  61. package/dist/lib/print-table.utils.js +15 -0
  62. package/dist/lib/print-table.utils.js.map +9 -0
  63. package/dist/lib/print-value.utils.d.ts +41 -0
  64. package/dist/lib/print-value.utils.d.ts.map +1 -0
  65. package/dist/lib/print-value.utils.js +13 -0
  66. package/dist/lib/print-value.utils.js.map +9 -0
  67. package/dist/pdf/file-loader.d.ts +19 -0
  68. package/dist/pdf/file-loader.d.ts.map +1 -0
  69. package/dist/pdf/file-loader.js +11 -0
  70. package/dist/pdf/file-loader.js.map +9 -0
  71. package/dist/pdf/http.d.ts +23 -0
  72. package/dist/pdf/http.d.ts.map +1 -0
  73. package/dist/pdf/http.js +13 -0
  74. package/dist/pdf/http.js.map +9 -0
  75. package/dist/pdf/index.d.ts +12 -0
  76. package/dist/pdf/index.d.ts.map +1 -0
  77. package/dist/pdf/index.js +99 -0
  78. package/dist/pdf/index.js.map +9 -0
  79. package/dist/pdf/model/builders.d.ts +59 -0
  80. package/dist/pdf/model/builders.d.ts.map +1 -0
  81. package/dist/pdf/model/data-table.d.ts +25 -0
  82. package/dist/pdf/model/data-table.d.ts.map +1 -0
  83. package/dist/pdf/model/index.d.ts +5 -0
  84. package/dist/pdf/model/index.d.ts.map +1 -0
  85. package/dist/pdf/model/index.js +60 -0
  86. package/dist/pdf/model/index.js.map +9 -0
  87. package/dist/pdf/model/nodes.d.ts +135 -0
  88. package/dist/pdf/model/nodes.d.ts.map +1 -0
  89. package/dist/pdf/model/theme.d.ts +17 -0
  90. package/dist/pdf/model/theme.d.ts.map +1 -0
  91. package/dist/pdf/model/types.d.ts +124 -0
  92. package/dist/pdf/model/types.d.ts.map +1 -0
  93. package/dist/pdf/render/context.d.ts +51 -0
  94. package/dist/pdf/render/context.d.ts.map +1 -0
  95. package/dist/pdf/render/document.d.ts +22 -0
  96. package/dist/pdf/render/document.d.ts.map +1 -0
  97. package/dist/pdf/render/index.d.ts +9 -0
  98. package/dist/pdf/render/index.d.ts.map +1 -0
  99. package/dist/pdf/render/index.js +44 -0
  100. package/dist/pdf/render/index.js.map +9 -0
  101. package/dist/pdf/render/nodes/blocks.d.ts +20 -0
  102. package/dist/pdf/render/nodes/blocks.d.ts.map +1 -0
  103. package/dist/pdf/render/nodes/header.d.ts +15 -0
  104. package/dist/pdf/render/nodes/header.d.ts.map +1 -0
  105. package/dist/pdf/render/nodes/layout.d.ts +45 -0
  106. package/dist/pdf/render/nodes/layout.d.ts.map +1 -0
  107. package/dist/pdf/render/nodes/table.d.ts +15 -0
  108. package/dist/pdf/render/nodes/table.d.ts.map +1 -0
  109. package/dist/pdf/render/page.d.ts +31 -0
  110. package/dist/pdf/render/page.d.ts.map +1 -0
  111. package/dist/pdf/render/render-node.d.ts +11 -0
  112. package/dist/pdf/render/render-node.d.ts.map +1 -0
  113. package/dist/pdf/render/styles.d.ts +304 -0
  114. package/dist/pdf/render/styles.d.ts.map +1 -0
  115. package/dist/pdf-viewer/index.d.ts +14 -0
  116. package/dist/pdf-viewer/index.d.ts.map +1 -0
  117. package/dist/pdf-viewer/index.js +380 -0
  118. package/dist/pdf-viewer/index.js.map +15 -0
  119. package/dist/pdf-viewer/pdf-document-search.d.ts +44 -0
  120. package/dist/pdf-viewer/pdf-document-search.d.ts.map +1 -0
  121. package/dist/pdf-viewer/pdf-escape.d.ts +7 -0
  122. package/dist/pdf-viewer/pdf-escape.d.ts.map +1 -0
  123. package/dist/pdf-viewer/pdf-page-geometry.d.ts +62 -0
  124. package/dist/pdf-viewer/pdf-page-geometry.d.ts.map +1 -0
  125. package/dist/pdf-viewer/pdf-page-sizes.d.ts +38 -0
  126. package/dist/pdf-viewer/pdf-page-sizes.d.ts.map +1 -0
  127. package/dist/pdf-viewer/pdf-scroll-spy.d.ts +43 -0
  128. package/dist/pdf-viewer/pdf-scroll-spy.d.ts.map +1 -0
  129. package/dist/pdf-viewer/pdf-text-search.d.ts +26 -0
  130. package/dist/pdf-viewer/pdf-text-search.d.ts.map +1 -0
  131. package/dist/vite/index.d.ts +81 -0
  132. package/dist/vite/index.d.ts.map +1 -0
  133. package/dist/vite/index.js +31 -0
  134. package/dist/vite/index.js.map +10 -0
  135. package/docs/README.md +9 -0
  136. package/docs/roadmap.md +35 -0
  137. package/docs/troubleshooting.md +105 -0
  138. package/package.json +187 -0
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lib/pdf-source.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Everything `PdfReader` opens, without touching pdf.js: that is loaded\n * lazily, and this module is safe on a server (no browser global at module\n * scope).\n */\n\n/** A URL fetched with request headers, such as an `Authorization` token. */\nexport type PdfUrlSource = {\n\turl: string | URL;\n\thttpHeaders?: Record<string, string>;\n\t/** Sends cookies with a cross-origin request. */\n\twithCredentials?: boolean;\n};\n\n/**\n * What `PdfReader`'s `file` accepts: a URL, a `File` or `Blob`, the bytes\n * (`ArrayBuffer`, `Uint8Array`), or a URL with headers. Bytes are copied, so\n * your buffer stays usable after the reader opened it.\n */\nexport type PdfSource =\n\t| string\n\t| URL\n\t| Blob\n\t| ArrayBuffer\n\t| Uint8Array\n\t| PdfUrlSource;\n\n/** The parameters pdf.js `getDocument` takes. */\nexport type PdfjsSourceParams =\n\t| {\n\t\t\turl: string;\n\t\t\thttpHeaders?: Record<string, string>;\n\t\t\twithCredentials?: boolean;\n\t }\n\t| { data: Uint8Array };\n\nconst tag = (value: unknown) => Object.prototype.toString.call(value);\n\nfunction isArrayBuffer(value: unknown): value is ArrayBuffer {\n\treturn tag(value) === '[object ArrayBuffer]';\n}\n\nfunction isBytes(value: unknown): value is ArrayBuffer | ArrayBufferView {\n\treturn isArrayBuffer(value) || ArrayBuffer.isView(value);\n}\n\n/** A Blob or a File, also from another realm (an iframe). */\nexport function isBlob(value: unknown): value is Blob {\n\tif (typeof Blob !== 'undefined' && value instanceof Blob) return true;\n\tconst kind = tag(value);\n\treturn kind === '[object Blob]' || kind === '[object File]';\n}\n\nfunction isUrl(value: unknown): value is URL {\n\treturn typeof URL !== 'undefined' && value instanceof URL;\n}\n\nexport function isPdfUrlSource(value: unknown): value is PdfUrlSource {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\t!isBytes(value) &&\n\t\t!isBlob(value) &&\n\t\t!isUrl(value) &&\n\t\t'url' in value\n\t);\n}\n\n/** The URL a source is fetched from; `null` for a Blob or bytes. */\nexport function pdfSourceUrl(source: PdfSource): string | null {\n\tif (typeof source === 'string') return source;\n\tif (isUrl(source)) return source.href;\n\tif (isPdfUrlSource(source)) return String(source.url);\n\treturn null;\n}\n\nconst ids = new WeakMap<object, number>();\nlet lastId = 0;\n\nfunction identity(value: object) {\n\tlet id = ids.get(value);\n\tif (id === undefined) {\n\t\tlastId += 1;\n\t\tid = lastId;\n\t\tids.set(value, id);\n\t}\n\treturn id;\n}\n\n/**\n * A key that changes only when the document does, so a re-render does not\n * reload it: a URL (with its headers) is compared by value, a Blob or a\n * buffer by identity. An inline `{ url, httpHeaders }` object is therefore\n * fine; a new `Uint8Array` on every render reloads every time.\n */\nexport function pdfSourceKey(source: PdfSource | null | undefined): string {\n\tif (source == null) return '';\n\tconst url = pdfSourceUrl(source);\n\tif (url !== null) {\n\t\tif (!isPdfUrlSource(source)) return `url:${url}`;\n\t\tconst headers = Object.entries(source.httpHeaders ?? {}).sort(([a], [b]) =>\n\t\t\ta < b ? -1 : a > b ? 1 : 0,\n\t\t);\n\t\treturn `url+:${JSON.stringify([url, headers, Boolean(source.withCredentials)])}`;\n\t}\n\t// Not a source at all: toPdfjsSource says so when it is loaded.\n\tif (typeof source !== 'object') return `invalid:${String(source)}`;\n\treturn `bytes:${identity(source)}`;\n}\n\n/**\n * A copy of the bytes. A buffer that was already detached (transferred to a\n * worker: it has 0 bytes) gives an empty copy, which pdf.js reports as an\n * empty file, instead of throwing here.\n */\nexport function copyPdfData(\n\tdata: ArrayBuffer | ArrayBufferView,\n): Uint8Array<ArrayBuffer> {\n\tif (data.byteLength === 0) return new Uint8Array(0);\n\tif (isArrayBuffer(data)) return new Uint8Array(data.slice(0));\n\treturn new Uint8Array(data.buffer, data.byteOffset, data.byteLength).slice();\n}\n\n/** The URL parameters pdf.js `getDocument` takes. */\nexport type PdfjsUrlParams = Extract<PdfjsSourceParams, { url: string }>;\n\n/**\n * The source as react-pdf's `file` takes it, synchronously: URL parameters,\n * or a Blob. Bytes are copied into a Blob, and every load reads a fresh\n * buffer from it: pdf.js transfers the buffer it is given to its worker,\n * which would leave yours, or a copy reused by a second load, detached.\n */\nexport function toPdfjsSource(source: PdfSource): Blob | PdfjsUrlParams {\n\tif (isBlob(source)) return source;\n\tif (isBytes(source)) {\n\t\treturn new Blob([copyPdfData(source)], { type: 'application/pdf' });\n\t}\n\tconst url = pdfSourceUrl(source);\n\tif (url === null) {\n\t\tthrow new TypeError(\n\t\t\t`PdfReader cannot open ${tag(source)}: pass a URL, a Blob, an ArrayBuffer, a Uint8Array or { url, httpHeaders }.`,\n\t\t);\n\t}\n\tif (!isPdfUrlSource(source)) return { url };\n\treturn {\n\t\turl,\n\t\t...(source.httpHeaders && { httpHeaders: source.httpHeaders }),\n\t\t...(source.withCredentials && { withCredentials: true }),\n\t};\n}\n\n/** {@link toPdfjsSource} with a Blob read into bytes, for `getDocument`. */\nexport async function toPdfjsParams(\n\tsource: PdfSource,\n): Promise<PdfjsSourceParams> {\n\tconst params = toPdfjsSource(source);\n\tif (!isBlob(params)) return params;\n\treturn { data: new Uint8Array(await params.arrayBuffer()) };\n}\n"
6
+ ],
7
+ "mappings": ";AAoCA,IAAM,MAAM,CAAC,UAAmB,OAAO,UAAU,SAAS,KAAK,KAAK;AAEpE,SAAS,aAAa,CAAC,OAAsC;AAAA,EAC5D,OAAO,IAAI,KAAK,MAAM;AAAA;AAGvB,SAAS,OAAO,CAAC,OAAwD;AAAA,EACxE,OAAO,cAAc,KAAK,KAAK,YAAY,OAAO,KAAK;AAAA;AAIjD,SAAS,OAAM,CAAC,OAA+B;AAAA,EACrD,IAAI,OAAO,SAAS,eAAe,iBAAiB;AAAA,IAAM,OAAO;AAAA,EACjE,MAAM,OAAO,IAAI,KAAK;AAAA,EACtB,OAAO,SAAS,mBAAmB,SAAS;AAAA;AAG7C,SAAS,KAAK,CAAC,OAA8B;AAAA,EAC5C,OAAO,OAAO,QAAQ,eAAe,iBAAiB;AAAA;AAGhD,SAAS,eAAc,CAAC,OAAuC;AAAA,EACrE,OACC,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,QAAQ,KAAK,KACd,CAAC,QAAO,KAAK,KACb,CAAC,MAAM,KAAK,KACZ,SAAS;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AAO,IAAI,WAAW,KAAK,QAAQ,KAAK,YAAY,KAAK,UAAU,EAAE,MAAM;AAAA;AAYrE,SAAS,cAAa,CAAC,QAA0C;AAAA,EACvE,IAAI,QAAO,MAAM;AAAA,IAAG,OAAO;AAAA,EAC3B,IAAI,QAAQ,MAAM,GAAG;AAAA,IACpB,OAAO,IAAI,KAAK,CAAC,aAAY,MAAM,CAAC,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAAA,EACnE;AAAA,EACA,MAAM,MAAM,cAAa,MAAM;AAAA,EAC/B,IAAI,QAAQ,MAAM;AAAA,IACjB,MAAM,IAAI,UACT,yBAAyB,IAAI,MAAM,8EACpC;AAAA,EACD;AAAA,EACA,IAAI,CAAC,gBAAe,MAAM;AAAA,IAAG,OAAO,EAAE,IAAI;AAAA,EAC1C,OAAO;AAAA,IACN;AAAA,OACI,OAAO,eAAe,EAAE,aAAa,OAAO,YAAY;AAAA,OACxD,OAAO,mBAAmB,EAAE,iBAAiB,KAAK;AAAA,EACvD;AAAA;AAID,eAAsB,cAAa,CAClC,QAC6B;AAAA,EAC7B,MAAM,SAAS,eAAc,MAAM;AAAA,EACnC,IAAI,CAAC,QAAO,MAAM;AAAA,IAAG,OAAO;AAAA,EAC5B,OAAO,EAAE,MAAM,IAAI,WAAW,MAAM,OAAO,YAAY,CAAC,EAAE;AAAA;",
8
+ "debugId": "B1F232AD977E14CE64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,13 @@
1
+ // src/lib/print-fraction-digits.ts
2
+ var MAX_FRACTION_DIGITS2 = 20;
3
+ function fractionDigitsOption2(fractionDigits) {
4
+ if (fractionDigits === undefined || !Number.isFinite(fractionDigits)) {
5
+ return;
6
+ }
7
+ return Math.min(MAX_FRACTION_DIGITS2, Math.max(0, Math.trunc(fractionDigits)));
8
+ }
9
+
10
+ export { MAX_FRACTION_DIGITS2, fractionDigitsOption2 };
11
+
12
+ //# debugId=C8DEF566CB9FFF2B64756E2164756E21
13
+ //# sourceMappingURL=index-6tn0wjsb.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lib/print-fraction-digits.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The most decimals every `Intl.NumberFormat` accepts. ES2023 raised the\n * limit to 100; engines before it throw a `RangeError` above 20.\n */\nexport const MAX_FRACTION_DIGITS = 20;\n\n/**\n * A `fractionDigits` option as both amount formatters apply it —\n * `formatAmount` and `CurrencyField` (`currencyFractionDigits`): a finite\n * number, truncated and clamped to 0..20; anything else (`undefined`, `NaN`,\n * `Infinity`) is `undefined`, so the default decimals apply.\n */\nexport function fractionDigitsOption(fractionDigits?: number) {\n\tif (fractionDigits === undefined || !Number.isFinite(fractionDigits)) {\n\t\treturn undefined;\n\t}\n\treturn Math.min(MAX_FRACTION_DIGITS, Math.max(0, Math.trunc(fractionDigits)));\n}\n"
6
+ ],
7
+ "mappings": ";AAIO,IAAM,uBAAsB;AAQ5B,SAAS,qBAAoB,CAAC,gBAAyB;AAAA,EAC7D,IAAI,mBAAmB,aAAa,CAAC,OAAO,SAAS,cAAc,GAAG;AAAA,IACrE;AAAA,EACD;AAAA,EACA,OAAO,KAAK,IAAI,sBAAqB,KAAK,IAAI,GAAG,KAAK,MAAM,cAAc,CAAC,CAAC;AAAA;",
8
+ "debugId": "C8DEF566CB9FFF2B64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,76 @@
1
+ import {
2
+ resolvePrintTable2,
3
+ resolvePrintFields2
4
+ } from "./index-0xc5q9tp.js";
5
+
6
+ // src/pdf/model/builders.ts
7
+ var text2 = (content, options = {}) => ({ type: "text", content, ...options });
8
+ var heading2 = (text, level) => level ? { type: "heading", text, level } : { type: "heading", text };
9
+ var stack2 = (children, options = {}) => ({ type: "stack", children, ...options });
10
+ var row2 = (children, options = {}) => ({ type: "row", children, ...options });
11
+ var section2 = (title, children) => ({ type: "section", title, children });
12
+ var image2 = (src, options = {}) => ({ type: "image", src, ...options });
13
+ var link2 = (href, text) => ({
14
+ type: "link",
15
+ href,
16
+ text
17
+ });
18
+ var spacer2 = (size) => ({
19
+ type: "spacer",
20
+ size
21
+ });
22
+ var divider2 = () => ({ type: "divider" });
23
+ var pageBreak2 = () => ({ type: "pageBreak" });
24
+ var table2 = (options) => ({
25
+ type: "table",
26
+ ...options
27
+ });
28
+ var keyValue2 = (items, options = {}) => ({ type: "keyValue", items, ...options });
29
+ var totals2 = (rows) => ({
30
+ type: "totals",
31
+ rows
32
+ });
33
+ var metric2 = (options) => ({
34
+ type: "metric",
35
+ ...options
36
+ });
37
+ var badge2 = (text, color) => color ? { type: "badge", text, color } : { type: "badge", text };
38
+ var header2 = (options) => ({
39
+ type: "header",
40
+ ...options
41
+ });
42
+ var pageNumber2 = (options = {}) => ({ type: "pageNumber", ...options });
43
+ var page2 = (options) => options;
44
+ var pdfDocument2 = (options) => ({ ...options, version: 1 });
45
+ function definePdfDocument2(build) {
46
+ const run = build;
47
+ return (...args) => ({ ...run(...args), version: 1 });
48
+ }
49
+
50
+ // src/pdf/model/data-table.ts
51
+ function dataTable2(columns, rows, options = {}) {
52
+ const { currency, totalLabel, ...layout } = options;
53
+ const table = resolvePrintTable2(columns, rows, { currency, totalLabel });
54
+ const labelTotals = totalLabel === undefined && Boolean(columns[0]) && !columns[0].total;
55
+ const footer = labelTotals ? table.footer.map(([, ...rest]) => [null, ...rest]) : table.footer;
56
+ return {
57
+ type: "table",
58
+ columns: table.columns,
59
+ rows: table.rows,
60
+ ...footer.length > 0 && { footer, ...labelTotals && { labelTotals } },
61
+ ...layout
62
+ };
63
+ }
64
+ function keyValueOf2(fields, data, options = {}) {
65
+ const { currency, ...layout } = options;
66
+ return {
67
+ type: "keyValue",
68
+ items: resolvePrintFields2(fields, data, { currency }),
69
+ ...layout
70
+ };
71
+ }
72
+
73
+ export { text2, heading2, stack2, row2, section2, image2, link2, spacer2, divider2, pageBreak2, table2, keyValue2, totals2, metric2, badge2, header2, pageNumber2, page2, pdfDocument2, definePdfDocument2, dataTable2, keyValueOf2 };
74
+
75
+ //# debugId=21BEC37B276F963B64756E2164756E21
76
+ //# sourceMappingURL=index-8gf9e2d4.js.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/pdf/model/builders.ts", "../src/pdf/model/data-table.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Plain functions that return model nodes, so a document reads as code\n * rather than as nested object literals. Each returns data only.\n */\nimport type {\n\tPdfDocument,\n\tPdfInline,\n\tPdfNode,\n\tPdfPage,\n\tPrintValue,\n} from './types';\n\ntype NodeOf<T extends PdfNode['type']> = Extract<PdfNode, { type: T }>;\ntype Options<T extends PdfNode['type'], K extends string = never> = Omit<\n\tNodeOf<T>,\n\t'type' | K\n>;\n\nexport const text = (\n\tcontent: string | PdfInline[],\n\toptions: Omit<Options<'text'>, 'content'> = {},\n): NodeOf<'text'> => ({ type: 'text', content, ...options });\n\nexport const heading = (text: string, level?: 1 | 2 | 3): NodeOf<'heading'> =>\n\tlevel ? { type: 'heading', text, level } : { type: 'heading', text };\n\nexport const stack = (\n\tchildren: PdfNode[],\n\toptions: Omit<Options<'stack'>, 'children'> = {},\n): NodeOf<'stack'> => ({ type: 'stack', children, ...options });\n\nexport const row = (\n\tchildren: PdfNode[],\n\toptions: Omit<Options<'row'>, 'children'> = {},\n): NodeOf<'row'> => ({ type: 'row', children, ...options });\n\nexport const section = (\n\ttitle: string,\n\tchildren: PdfNode[],\n): NodeOf<'section'> => ({ type: 'section', title, children });\n\nexport const image = (\n\tsrc: string,\n\toptions: Omit<Options<'image'>, 'src'> = {},\n): NodeOf<'image'> => ({ type: 'image', src, ...options });\n\nexport const link = (href: string, text: string): NodeOf<'link'> => ({\n\ttype: 'link',\n\thref,\n\ttext,\n});\n\nexport const spacer = (size: number): NodeOf<'spacer'> => ({\n\ttype: 'spacer',\n\tsize,\n});\n\nexport const divider = (): NodeOf<'divider'> => ({ type: 'divider' });\n\nexport const pageBreak = (): NodeOf<'pageBreak'> => ({ type: 'pageBreak' });\n\nexport const table = (options: Options<'table'>): NodeOf<'table'> => ({\n\ttype: 'table',\n\t...options,\n});\n\nexport const keyValue = (\n\titems: { label: string; value: PrintValue }[],\n\toptions: Omit<Options<'keyValue'>, 'items'> = {},\n): NodeOf<'keyValue'> => ({ type: 'keyValue', items, ...options });\n\nexport const totals = (rows: NodeOf<'totals'>['rows']): NodeOf<'totals'> => ({\n\ttype: 'totals',\n\trows,\n});\n\nexport const metric = (options: Options<'metric'>): NodeOf<'metric'> => ({\n\ttype: 'metric',\n\t...options,\n});\n\nexport const badge = (text: string, color?: string): NodeOf<'badge'> =>\n\tcolor ? { type: 'badge', text, color } : { type: 'badge', text };\n\nexport const header = (options: Options<'header'>): NodeOf<'header'> => ({\n\ttype: 'header',\n\t...options,\n});\n\nexport const pageNumber = (\n\toptions: Options<'pageNumber'> = {},\n): NodeOf<'pageNumber'> => ({ type: 'pageNumber', ...options });\n\nexport const page = (options: PdfPage): PdfPage => options;\n\n/** A whole document; `version` is stamped for you. */\nexport const pdfDocument = (\n\toptions: Omit<PdfDocument, 'version'>,\n): PdfDocument => ({ ...options, version: 1 });\n\n/**\n * What `definePdfDocument` accepts: a function from your data (and more\n * parameters, if you like) to a document without its `version`. A method\n * signature, so that its parameters are checked both ways: an annotated\n * `(inv: Invoice)` fits, while an unannotated first parameter is typed\n * `unknown` (use it only after narrowing) and a later one with a default\n * (`language = 'en'`) takes its type from the default.\n */\ntype PdfTemplate = {\n\tbuild(data: unknown, ...rest: never[]): Omit<PdfDocument, 'version'>;\n}['build'];\n\n/**\n * Types a template: a function from your data to a document. It returns the\n * function unchanged, stamping `version` on what it builds. Annotate the\n * data parameter; the others may have defaults (`language = 'en'`). Left\n * unannotated, the data is `unknown`, so reading a property of it fails to\n * compile in the template rather than where the template is called.\n *\n * @example\n * const invoicePdf = definePdfDocument((inv: Invoice, language = 'en') => ({\n * language,\n * pages: [page({ pageNumbers: true, body: [heading(inv.number)] })],\n * }));\n */\nexport function definePdfDocument<F extends PdfTemplate>(\n\tbuild: F,\n): (...args: Parameters<F>) => PdfDocument {\n\t// `F`'s own parameters are what the returned function takes.\n\tconst run = build as unknown as (\n\t\t...args: Parameters<F>\n\t) => Omit<PdfDocument, 'version'>;\n\treturn (...args) => ({ ...run(...args), version: 1 });\n}\n",
6
+ "import {\n\ttype PrintColumn,\n\ttype PrintTableOptions,\n\tresolvePrintFields,\n\tresolvePrintTable,\n} from '../../lib/print-table.utils';\nimport type { PdfNode } from './types';\n\ntype TableNode = Extract<PdfNode, { type: 'table' }>;\ntype KeyValueNode = Extract<PdfNode, { type: 'keyValue' }>;\n\nexport type DataTableOptions = PrintTableOptions &\n\tPick<\n\t\tTableNode,\n\t\t'striped' | 'repeatHeader' | 'keepRowsWhole' | 'emptyText' | 'hideWhenEmpty'\n\t>;\n\n/**\n * A `table` node from column definitions and plain rows — the model twin of\n * `PrintDataTable`. Without `totalLabel`, the totals row reads \"Total\" in the\n * document's language.\n *\n * @example\n * dataTable(definePrintColumns<Line>([\n * { key: 'item', label: 'Item', flex: 3 },\n * { key: 'amount', label: 'Amount', format: 'amount', total: 'sum' },\n * ]), invoice.lines, { currency: 'EUR' })\n */\nexport function dataTable<T>(\n\tcolumns: PrintColumn<T>[],\n\trows: T[],\n\toptions: DataTableOptions = {},\n): TableNode {\n\tconst { currency, totalLabel, ...layout } = options;\n\tconst table = resolvePrintTable(columns, rows, { currency, totalLabel });\n\tconst labelTotals =\n\t\ttotalLabel === undefined && Boolean(columns[0]) && !columns[0].total;\n\tconst footer = labelTotals\n\t\t? table.footer.map(([, ...rest]) => [null, ...rest])\n\t\t: table.footer;\n\treturn {\n\t\ttype: 'table',\n\t\tcolumns: table.columns,\n\t\trows: table.rows,\n\t\t...(footer.length > 0 && { footer, ...(labelTotals && { labelTotals }) }),\n\t\t...layout,\n\t};\n}\n\n/** A `keyValue` node from one row, read through column definitions. */\nexport function keyValueOf<T>(\n\tfields: PrintColumn<T>[],\n\tdata: T,\n\toptions: Pick<PrintTableOptions, 'currency'> &\n\t\tPick<KeyValueNode, 'columns' | 'keepEmpty'> = {},\n): KeyValueNode {\n\tconst { currency, ...layout } = options;\n\treturn {\n\t\ttype: 'keyValue',\n\t\titems: resolvePrintFields(fields, data, { currency }),\n\t\t...layout,\n\t};\n}\n"
7
+ ],
8
+ "mappings": ";;;;;;AAkBO,IAAM,QAAO,CACnB,SACA,UAA4C,CAAC,OACxB,EAAE,MAAM,QAAQ,YAAY,QAAQ;AAEnD,IAAM,WAAU,CAAC,MAAc,UACrC,QAAQ,EAAE,MAAM,WAAW,MAAM,MAAM,IAAI,EAAE,MAAM,WAAW,KAAK;AAE7D,IAAM,SAAQ,CACpB,UACA,UAA8C,CAAC,OACzB,EAAE,MAAM,SAAS,aAAa,QAAQ;AAEtD,IAAM,OAAM,CAClB,UACA,UAA4C,CAAC,OACzB,EAAE,MAAM,OAAO,aAAa,QAAQ;AAElD,IAAM,WAAU,CACtB,OACA,cACwB,EAAE,MAAM,WAAW,OAAO,SAAS;AAErD,IAAM,SAAQ,CACpB,KACA,UAAyC,CAAC,OACpB,EAAE,MAAM,SAAS,QAAQ,QAAQ;AAEjD,IAAM,QAAO,CAAC,MAAc,UAAkC;AAAA,EACpE,MAAM;AAAA,EACN;AAAA,EACA;AACD;AAEO,IAAM,UAAS,CAAC,UAAoC;AAAA,EAC1D,MAAM;AAAA,EACN;AACD;AAEO,IAAM,WAAU,OAA0B,EAAE,MAAM,UAAU;AAE5D,IAAM,aAAY,OAA4B,EAAE,MAAM,YAAY;AAElE,IAAM,SAAQ,CAAC,aAAgD;AAAA,EACrE,MAAM;AAAA,KACH;AACJ;AAEO,IAAM,YAAW,CACvB,OACA,UAA8C,CAAC,OACtB,EAAE,MAAM,YAAY,UAAU,QAAQ;AAEzD,IAAM,UAAS,CAAC,UAAsD;AAAA,EAC5E,MAAM;AAAA,EACN;AACD;AAEO,IAAM,UAAS,CAAC,aAAkD;AAAA,EACxE,MAAM;AAAA,KACH;AACJ;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2164756E21",
10
+ "names": []
11
+ }
@@ -0,0 +1,61 @@
1
+ import {
2
+ formatAmount2,
3
+ formatDate2
4
+ } from "./index-w3ajz57t.js";
5
+
6
+ // src/lib/print-value.utils.ts
7
+ var EMPTY = "—";
8
+ function formatNumber(value, style, fractionDigits, locale) {
9
+ const digits = Math.min(100, Math.max(0, Math.trunc(fractionDigits ?? (style === "percent" ? 0 : 3))));
10
+ try {
11
+ return new Intl.NumberFormat(locale, {
12
+ style,
13
+ maximumFractionDigits: digits
14
+ }).format(value);
15
+ } catch {
16
+ return String(style === "percent" ? `${value * 100}%` : value);
17
+ }
18
+ }
19
+ function isEmptyPrintValue2(value) {
20
+ if (value == null || value === "")
21
+ return true;
22
+ if (typeof value !== "object")
23
+ return false;
24
+ if ("amount" in value)
25
+ return value.amount == null;
26
+ if ("date" in value)
27
+ return value.date == null || value.date === "";
28
+ return value.number == null;
29
+ }
30
+ function formatPrintValue2(value, options = {}) {
31
+ const { locale, timeZone, empty = EMPTY } = options;
32
+ if (isEmptyPrintValue2(value))
33
+ return empty;
34
+ if (typeof value === "string")
35
+ return value;
36
+ if (typeof value === "number") {
37
+ return formatNumber(value, "decimal", undefined, locale);
38
+ }
39
+ if (value == null)
40
+ return empty;
41
+ if ("amount" in value) {
42
+ return formatAmount2(value.amount, value.currency, {
43
+ locale,
44
+ fractionDigits: value.fractionDigits
45
+ });
46
+ }
47
+ if ("date" in value) {
48
+ return formatDate2(value.date, {
49
+ locale,
50
+ timeZone,
51
+ dateStyle: value.dateStyle,
52
+ timeStyle: value.timeStyle
53
+ });
54
+ }
55
+ return formatNumber(value.number, value.style ?? "decimal", value.fractionDigits, locale);
56
+ }
57
+
58
+ export { isEmptyPrintValue2, formatPrintValue2 };
59
+
60
+ //# debugId=B2A49140567D037E64756E2164756E21
61
+ //# sourceMappingURL=index-eh0e5ex7.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lib/print-value.utils.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * A value a printed document shows, kept as data until it is rendered.\n *\n * Documents are plain data (they may be built on a server, sent as JSON and\n * rendered elsewhere), so an amount or a date stays `{ amount, currency }` or\n * `{ date }` until the renderer formats it with the document's locale and\n * time zone. Framework-free: only `Intl`, through `print-format.utils`.\n */\nimport { formatAmount, formatDate } from './print-format.utils';\n\nconst EMPTY = '—';\n\nexport type PrintAmountValue = {\n\tamount: number | null;\n\t/** ISO 4217 code, such as `'EUR'`. Without one, a plain decimal. */\n\tcurrency?: string | null;\n\t/** Decimals to show; defaults to the currency's own. */\n\tfractionDigits?: number;\n};\n\nexport type PrintDateValue = {\n\t/** `'2026-03-01'`, an ISO date-time or epoch milliseconds. */\n\tdate: string | number | null;\n\tdateStyle?: 'full' | 'long' | 'medium' | 'short';\n\ttimeStyle?: 'full' | 'long' | 'medium' | 'short';\n};\n\nexport type PrintNumberValue = {\n\tnumber: number | null;\n\t/** `'percent'` shows `0.2` as `20%`. */\n\tstyle?: 'decimal' | 'percent';\n\t/** Maximum decimals; defaults to 3 (0 for a percentage). */\n\tfractionDigits?: number;\n};\n\n/** Text, a number, or an amount, date or number formatted when rendered. */\nexport type PrintValue =\n\t| string\n\t| number\n\t| null\n\t| undefined\n\t| PrintAmountValue\n\t| PrintDateValue\n\t| PrintNumberValue;\n\nexport type PrintValueOptions = {\n\t/** BCP 47 locale, such as `'fr-FR'`. Defaults to the runtime's locale. */\n\tlocale?: string;\n\t/** IANA time zone for dates with a time. */\n\ttimeZone?: string;\n\t/** What an empty value shows; `'—'` by default. */\n\tempty?: string;\n};\n\nfunction formatNumber(\n\tvalue: number,\n\tstyle: 'decimal' | 'percent',\n\tfractionDigits: number | undefined,\n\tlocale: string | undefined,\n) {\n\tconst digits = Math.min(\n\t\t100,\n\t\tMath.max(0, Math.trunc(fractionDigits ?? (style === 'percent' ? 0 : 3))),\n\t);\n\ttry {\n\t\treturn new Intl.NumberFormat(locale, {\n\t\t\tstyle,\n\t\t\tmaximumFractionDigits: digits,\n\t\t}).format(value);\n\t} catch {\n\t\treturn String(style === 'percent' ? `${value * 100}%` : value);\n\t}\n}\n\n/** Whether a value is empty: `null`, `undefined`, `''` or an empty wrapper. */\nexport function isEmptyPrintValue(value: PrintValue): boolean {\n\tif (value == null || value === '') return true;\n\tif (typeof value !== 'object') return false;\n\tif ('amount' in value) return value.amount == null;\n\tif ('date' in value) return value.date == null || value.date === '';\n\treturn value.number == null;\n}\n\n/**\n * Formats a {@link PrintValue} as the text a document prints. An empty value\n * gives `options.empty` (`'—'`).\n *\n * @example formatPrintValue({ amount: 1234.5, currency: 'EUR' }, { locale: 'fr-FR' }) // '1 234,50 €'\n * @example formatPrintValue({ number: 0.2, style: 'percent' }, { locale: 'en-US' }) // '20%'\n */\nexport function formatPrintValue(\n\tvalue: PrintValue,\n\toptions: PrintValueOptions = {},\n): string {\n\tconst { locale, timeZone, empty = EMPTY } = options;\n\tif (isEmptyPrintValue(value)) return empty;\n\tif (typeof value === 'string') return value;\n\tif (typeof value === 'number') {\n\t\treturn formatNumber(value, 'decimal', undefined, locale);\n\t}\n\tif (value == null) return empty;\n\tif ('amount' in value) {\n\t\treturn formatAmount(value.amount, value.currency, {\n\t\t\tlocale,\n\t\t\tfractionDigits: value.fractionDigits,\n\t\t});\n\t}\n\tif ('date' in value) {\n\t\treturn formatDate(value.date, {\n\t\t\tlocale,\n\t\t\ttimeZone,\n\t\t\tdateStyle: value.dateStyle,\n\t\t\ttimeStyle: value.timeStyle,\n\t\t});\n\t}\n\treturn formatNumber(\n\t\tvalue.number as number,\n\t\tvalue.style ?? 'decimal',\n\t\tvalue.fractionDigits,\n\t\tlocale,\n\t);\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;AAUA,IAAM,QAAQ;AA4Cd,SAAS,YAAY,CACpB,OACA,OACA,gBACA,QACC;AAAA,EACD,MAAM,SAAS,KAAK,IACnB,KACA,KAAK,IAAI,GAAG,KAAK,MAAM,mBAAmB,UAAU,YAAY,IAAI,EAAE,CAA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,gBACN,MACD;AAAA;",
8
+ "debugId": "B2A49140567D037E64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,57 @@
1
+ // src/pdf/file-loader.ts
2
+ var IDLE_PDF_FILE2 = {
3
+ blob: null,
4
+ url: null,
5
+ loading: false,
6
+ error: null
7
+ };
8
+ function createPdfFileLoader2(onChange, render) {
9
+ let generation = 0;
10
+ let url = null;
11
+ let snapshot = IDLE_PDF_FILE2;
12
+ const set = (next) => {
13
+ snapshot = next;
14
+ onChange(next);
15
+ };
16
+ const revoke = () => {
17
+ if (url)
18
+ URL.revokeObjectURL(url);
19
+ url = null;
20
+ };
21
+ return {
22
+ async load(input, options) {
23
+ const mine = ++generation;
24
+ if (input === null) {
25
+ revoke();
26
+ set(IDLE_PDF_FILE2);
27
+ return;
28
+ }
29
+ set({ ...snapshot, loading: true, error: null });
30
+ try {
31
+ const blob = await render(input, options);
32
+ if (mine !== generation)
33
+ return;
34
+ revoke();
35
+ url = URL.createObjectURL(blob);
36
+ set({ blob, url, loading: false, error: null });
37
+ } catch (error) {
38
+ if (mine !== generation)
39
+ return;
40
+ revoke();
41
+ set({
42
+ ...IDLE_PDF_FILE2,
43
+ error: error instanceof Error ? error : new Error(String(error))
44
+ });
45
+ }
46
+ },
47
+ dispose() {
48
+ generation++;
49
+ revoke();
50
+ }
51
+ };
52
+ }
53
+
54
+ export { IDLE_PDF_FILE2, createPdfFileLoader2 };
55
+
56
+ //# debugId=4A188CEAEA9D308864756E2164756E21
57
+ //# sourceMappingURL=index-g7rh8fpv.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/pdf/file-loader.ts"],
4
+ "sourcesContent": [
5
+ "export type PdfFileSnapshot = {\n\tblob: Blob | null;\n\t/** An object URL of `blob`, for an `<iframe>`, a `PdfReader` or a link. */\n\turl: string | null;\n\tloading: boolean;\n\terror: Error | null;\n};\n\nexport const IDLE_PDF_FILE: PdfFileSnapshot = {\n\tblob: null,\n\turl: null,\n\tloading: false,\n\terror: null,\n};\n\n/**\n * What `usePdfFile` (React) and `usePdf` (Vue) run, framework-free: renders a\n * document with `render`, keeps one object URL alive at a time and revokes it\n * when replaced or disposed, and drops the result of a render that a newer\n * `load` (or `dispose`) overtook.\n */\nexport function createPdfFileLoader<I, O = undefined>(\n\tonChange: (snapshot: PdfFileSnapshot) => void,\n\trender: (input: I, options?: O) => Promise<Blob>,\n) {\n\tlet generation = 0;\n\tlet url: string | null = null;\n\tlet snapshot = IDLE_PDF_FILE;\n\tconst set = (next: PdfFileSnapshot) => {\n\t\tsnapshot = next;\n\t\tonChange(next);\n\t};\n\tconst revoke = () => {\n\t\tif (url) URL.revokeObjectURL(url);\n\t\turl = null;\n\t};\n\n\treturn {\n\t\tasync load(input: I | null, options?: O) {\n\t\t\tconst mine = ++generation;\n\t\t\tif (input === null) {\n\t\t\t\trevoke();\n\t\t\t\tset(IDLE_PDF_FILE);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tset({ ...snapshot, loading: true, error: null });\n\t\t\ttry {\n\t\t\t\tconst blob = await render(input, options);\n\t\t\t\tif (mine !== generation) return;\n\t\t\t\trevoke();\n\t\t\t\turl = URL.createObjectURL(blob);\n\t\t\t\tset({ blob, url, loading: false, error: null });\n\t\t\t} catch (error) {\n\t\t\t\tif (mine !== generation) return;\n\t\t\t\trevoke();\n\t\t\t\tset({\n\t\t\t\t\t...IDLE_PDF_FILE,\n\t\t\t\t\terror: error instanceof Error ? error : new Error(String(error)),\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tdispose() {\n\t\t\tgeneration++;\n\t\t\trevoke();\n\t\t},\n\t};\n}\n"
6
+ ],
7
+ "mappings": ";AAQO,IAAM,iBAAiC;AAAA,EAC7C,MAAM;AAAA,EACN,KAAK;AAAA,EACL,SAAS;AAAA,EACT,OAAO;AACR;AAQO,SAAS,oBAAqC,CACpD,UACA,QACC;AAAA,EACD,IAAI,aAAa;AAAA,EACjB,IAAI,MAAqB;AAAA,EACzB,IAAI,WAAW;AAAA,EACf,MAAM,MAAM,CAAC,SAA0B;AAAA,IACtC,WAAW;AAAA,IACX,SAAS,IAAI;AAAA;AAAA,EAEd,MAAM,SAAS,MAAM;AAAA,IACpB,IAAI;AAAA,MAAK,IAAI,gBAAgB,GAAG;AAAA,IAChC,MAAM;AAAA;AAAA,EAGP,OAAO;AAAA,SACA,KAAI,CAAC,OAAiB,SAAa;AAAA,MACxC,MAAM,OAAO,EAAE;AAAA,MACf,IAAI,UAAU,MAAM;AAAA,QACnB,OAAO;AAAA,QACP,IAAI,cAAa;AAAA,QACjB;AAAA,MACD;AAAA,MACA,IAAI,KAAK,UAAU,SAAS,MAAM,OAAO,KAAK,CAAC;AAAA,MAC/C,IAAI;AAAA,QACH,MAAM,OAAO,MAAM,OAAO,OAAO,OAAO;AAAA,QACxC,IAAI,SAAS;AAAA,UAAY;AAAA,QACzB,OAAO;AAAA,QACP,MAAM,IAAI,gBAAgB,IAAI;AAAA,QAC9B,IAAI,EAAE,MAAM,KAAK,SAAS,OAAO,OAAO,KAAK,CAAC;AAAA,QAC7C,OAAO,OAAO;AAAA,QACf,IAAI,SAAS;AAAA,UAAY;AAAA,QACzB,OAAO;AAAA,QACP,IAAI;AAAA,aACA;AAAA,UACH,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AAAA,QAChE,CAAC;AAAA;AAAA;AAAA,IAGH,OAAO,GAAG;AAAA,MACT;AAAA,MACA,OAAO;AAAA;AAAA,EAET;AAAA;",
8
+ "debugId": "4A188CEAEA9D308864756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,113 @@
1
+ import {
2
+ isBlob2,
3
+ isPdfUrlSource2,
4
+ pdfSourceUrl2,
5
+ copyPdfData2
6
+ } from "./index-5r6rzp43.js";
7
+ import {
8
+ resolvePdfFileName2
9
+ } from "./index-paaaedrm.js";
10
+
11
+ // src/lib/pdf-download.ts
12
+ var OBJECT_URL_TTL_MS2 = 60000;
13
+ function fetchInit(source) {
14
+ if (!isPdfUrlSource2(source))
15
+ return;
16
+ return {
17
+ headers: source.httpHeaders,
18
+ credentials: source.withCredentials ? "include" : "same-origin"
19
+ };
20
+ }
21
+ async function resolvePdfBlob(source, getData) {
22
+ const url = pdfSourceUrl2(source);
23
+ if (url === null) {
24
+ return isBlob2(source) ? source : new Blob([copyPdfData2(source)], {
25
+ type: "application/pdf"
26
+ });
27
+ }
28
+ try {
29
+ const bytes = await getData?.();
30
+ if (bytes?.byteLength) {
31
+ return new Blob([copyPdfData2(bytes)], { type: "application/pdf" });
32
+ }
33
+ } catch {}
34
+ try {
35
+ const init = fetchInit(source);
36
+ const response = await (init ? fetch(url, init) : fetch(url));
37
+ return response.ok ? await response.blob() : null;
38
+ } catch {
39
+ return null;
40
+ }
41
+ }
42
+ function revokeLater(url) {
43
+ window.setTimeout(() => URL.revokeObjectURL(url), OBJECT_URL_TTL_MS2);
44
+ }
45
+ function clickLink(href, attributes) {
46
+ const link = document.createElement("a");
47
+ link.href = href;
48
+ for (const [name, value] of Object.entries(attributes)) {
49
+ link.setAttribute(name, value);
50
+ }
51
+ link.style.display = "none";
52
+ document.body.append(link);
53
+ link.click();
54
+ link.remove();
55
+ }
56
+ function saveBlob(blob, fileName) {
57
+ const url = URL.createObjectURL(blob);
58
+ clickLink(url, { download: fileName });
59
+ revokeLater(url);
60
+ }
61
+ function openInNewTab(href) {
62
+ clickLink(href, { target: "_blank", rel: "noopener" });
63
+ }
64
+ function fallbackUrl(source) {
65
+ if (isPdfUrlSource2(source) && source.httpHeaders)
66
+ return null;
67
+ return pdfSourceUrl2(source);
68
+ }
69
+ async function downloadPdfFile2(source, options = {}) {
70
+ const name = resolvePdfFileName2(source, options.fileName, options.defaultName);
71
+ const blob = await resolvePdfBlob(source, options.getData);
72
+ const url = fallbackUrl(source);
73
+ if (blob)
74
+ saveBlob(blob, name);
75
+ else if (url !== null)
76
+ openInNewTab(url);
77
+ }
78
+ async function printPdfFile2(source, options = {}) {
79
+ const blob = await resolvePdfBlob(source, options.getData);
80
+ if (!blob) {
81
+ const url = fallbackUrl(source);
82
+ if (url !== null)
83
+ openInNewTab(url);
84
+ return;
85
+ }
86
+ const url = URL.createObjectURL(blob);
87
+ const frame = document.createElement("iframe");
88
+ frame.setAttribute("aria-hidden", "true");
89
+ frame.style.position = "fixed";
90
+ frame.style.right = "0";
91
+ frame.style.bottom = "0";
92
+ frame.style.width = "0";
93
+ frame.style.height = "0";
94
+ frame.style.border = "0";
95
+ frame.src = url;
96
+ frame.onload = () => {
97
+ try {
98
+ frame.contentWindow?.focus();
99
+ frame.contentWindow?.print();
100
+ } catch {
101
+ openInNewTab(url);
102
+ } finally {
103
+ window.setTimeout(() => frame.remove(), 1000);
104
+ revokeLater(url);
105
+ }
106
+ };
107
+ document.body.append(frame);
108
+ }
109
+
110
+ export { OBJECT_URL_TTL_MS2, downloadPdfFile2, printPdfFile2 };
111
+
112
+ //# debugId=77B6E1C9EF4463B464756E2164756E21
113
+ //# sourceMappingURL=index-h3vjydz7.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lib/pdf-download.ts"],
4
+ "sourcesContent": [
5
+ "import { resolvePdfFileName } from './pdf-file-name';\nimport {\n\tcopyPdfData,\n\tisBlob,\n\tisPdfUrlSource,\n\ttype PdfSource,\n\tpdfSourceUrl,\n} from './pdf-source';\n\n/**\n * How long an object URL outlives the click that started its download or\n * opened its tab. Revoking it synchronously cancels the download in Firefox\n * and Safari, which read the URL after `click()` returns.\n */\nexport const OBJECT_URL_TTL_MS = 60_000;\n\nexport type PdfFileOptions = {\n\t/** Name of the saved file; `.pdf` is added when missing. */\n\tfileName?: string;\n\t/**\n\t * Name used when neither `fileName`, a `File`'s name nor the URL gives\n\t * one: `document`, or its translation.\n\t */\n\tdefaultName?: string;\n\t/**\n\t * Bytes of the document the reader already loaded. Saving them needs no\n\t * second request, and works for a cross-origin URL, where the `download`\n\t * attribute is ignored.\n\t */\n\tgetData?: () =>\n\t\t| Uint8Array\n\t\t| null\n\t\t| undefined\n\t\t| Promise<Uint8Array | null | undefined>;\n};\n\nfunction fetchInit(source: PdfSource): RequestInit | undefined {\n\tif (!isPdfUrlSource(source)) return undefined;\n\treturn {\n\t\theaders: source.httpHeaders,\n\t\tcredentials: source.withCredentials ? 'include' : 'same-origin',\n\t};\n}\n\nasync function resolvePdfBlob(\n\tsource: PdfSource,\n\tgetData: PdfFileOptions['getData'],\n): Promise<Blob | null> {\n\tconst url = pdfSourceUrl(source);\n\tif (url === null) {\n\t\t// A Blob or bytes: a Blob copies what it is given.\n\t\treturn isBlob(source)\n\t\t\t? source\n\t\t\t: new Blob([copyPdfData(source as ArrayBuffer | Uint8Array)], {\n\t\t\t\t\ttype: 'application/pdf',\n\t\t\t\t});\n\t}\n\ttry {\n\t\tconst bytes = await getData?.();\n\t\tif (bytes?.byteLength) {\n\t\t\treturn new Blob([copyPdfData(bytes)], { type: 'application/pdf' });\n\t\t}\n\t} catch {\n\t\t/* the document may be gone; fetch it instead */\n\t}\n\ttry {\n\t\tconst init = fetchInit(source);\n\t\tconst response = await (init ? fetch(url, init) : fetch(url));\n\t\treturn response.ok ? await response.blob() : null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction revokeLater(url: string) {\n\twindow.setTimeout(() => URL.revokeObjectURL(url), OBJECT_URL_TTL_MS);\n}\n\nfunction clickLink(href: string, attributes: Record<string, string>) {\n\tconst link = document.createElement('a');\n\tlink.href = href;\n\tfor (const [name, value] of Object.entries(attributes)) {\n\t\tlink.setAttribute(name, value);\n\t}\n\tlink.style.display = 'none';\n\t// Firefox ignores a click on a link that is not in the document.\n\tdocument.body.append(link);\n\tlink.click();\n\tlink.remove();\n}\n\n/** Saves a Blob under `fileName`, and revokes its URL once the save began. */\nfunction saveBlob(blob: Blob, fileName: string) {\n\tconst url = URL.createObjectURL(blob);\n\tclickLink(url, { download: fileName });\n\trevokeLater(url);\n}\n\nfunction openInNewTab(href: string) {\n\tclickLink(href, { target: '_blank', rel: 'noopener' });\n}\n\n/**\n * The URL a new tab may open when the document could not be read. None for\n * a URL with headers: a tab sends no `Authorization`, so it would only show\n * the server's refusal.\n */\nfunction fallbackUrl(source: PdfSource) {\n\tif (isPdfUrlSource(source) && source.httpHeaders) return null;\n\treturn pdfSourceUrl(source);\n}\n\n/**\n * Downloads the PDF under its resolved name. A URL is saved from the loaded\n * bytes or fetched; when neither works (CORS), it opens in a new tab, which\n * a popup blocker may stop once the click's activation has expired. A URL\n * with headers never opens in a tab: it would load without them.\n */\nexport async function downloadPdfFile(\n\tsource: PdfSource,\n\toptions: PdfFileOptions = {},\n) {\n\tconst name = resolvePdfFileName(\n\t\tsource,\n\t\toptions.fileName,\n\t\toptions.defaultName,\n\t);\n\tconst blob = await resolvePdfBlob(source, options.getData);\n\tconst url = fallbackUrl(source);\n\tif (blob) saveBlob(blob, name);\n\telse if (url !== null) openInNewTab(url);\n}\n\n/**\n * Prints the PDF from a same-origin object URL in a hidden frame. When the\n * browser refuses (a PDF plugin that blocks `print()`, a cross-origin URL\n * that could not be fetched), the document opens in a new tab instead.\n */\nexport async function printPdfFile(\n\tsource: PdfSource,\n\toptions: Pick<PdfFileOptions, 'getData'> = {},\n) {\n\tconst blob = await resolvePdfBlob(source, options.getData);\n\tif (!blob) {\n\t\tconst url = fallbackUrl(source);\n\t\tif (url !== null) openInNewTab(url);\n\t\treturn;\n\t}\n\tconst url = URL.createObjectURL(blob);\n\tconst frame = document.createElement('iframe');\n\tframe.setAttribute('aria-hidden', 'true');\n\tframe.style.position = 'fixed';\n\tframe.style.right = '0';\n\tframe.style.bottom = '0';\n\tframe.style.width = '0';\n\tframe.style.height = '0';\n\tframe.style.border = '0';\n\tframe.src = url;\n\tframe.onload = () => {\n\t\ttry {\n\t\t\tframe.contentWindow?.focus();\n\t\t\tframe.contentWindow?.print();\n\t\t} catch {\n\t\t\topenInNewTab(url);\n\t\t} finally {\n\t\t\twindow.setTimeout(() => frame.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e,MAAM;AAAA,EACxC,MAAM,MAAM,WAAW;AAAA,EACvB,MAAM,MAAM,QAAQ;AAAA,EACpB,MAAM,MAAM,SAAS;AAAA,EACrB,MAAM,MAAM,QAAQ;AAAA,EACpB,MAAM,MAAM,SAAS;AAAA,EACrB,MAAM,MAAM,SAAS;AAAA,EACrB,MAAM,MAAM;AAAA,EACZ,MAAM,SAAS,MAAM;AAAA,IACpB,IAAI;AAAA,MACH,MAAM,eAAe,MAAM;AAAA,MAC3B,MAAM,eAAe,MAAM;AAAA,MAC1B,MAAM;AAAA,MACP,aAAa,GAAG;AAAA,cACf;AAAA,MACD,OAAO,WAAW,MAAM,MAAM,OAAO,GAAG,IAAI;AAAA,MAC5C,YAAY,GAAG;AAAA;AAAA;AAAA,EAGjB,SAAS,KAAK,OAAO,KAAK;AAAA;",
8
+ "debugId": "77B6E1C9EF4463B464756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,37 @@
1
+ import {
2
+ isBlob2,
3
+ pdfSourceUrl2
4
+ } from "./index-5r6rzp43.js";
5
+
6
+ // src/lib/pdf-file-name.ts
7
+ var DEFAULT_PDF_FILE_NAME2 = "document";
8
+ function withPdfExtension(name) {
9
+ return /\.pdf$/i.test(name) ? name : `${name}.pdf`;
10
+ }
11
+ function lastPathSegment(url) {
12
+ try {
13
+ const { pathname, protocol } = new URL(url, "http://localhost/");
14
+ if (protocol === "blob:" || protocol === "data:")
15
+ return "";
16
+ return decodeURIComponent(pathname.split("/").pop() ?? "").replace(/[\\/]/g, "_");
17
+ } catch {
18
+ return "";
19
+ }
20
+ }
21
+ function ownName(source) {
22
+ if (isBlob2(source)) {
23
+ const { name } = source;
24
+ return typeof name === "string" ? name : "";
25
+ }
26
+ const url = pdfSourceUrl2(source);
27
+ return url === null ? "" : lastPathSegment(url);
28
+ }
29
+ function resolvePdfFileName2(source, fileName, fallback = DEFAULT_PDF_FILE_NAME2) {
30
+ const name = fileName?.trim() || ownName(source).trim() || fallback.trim();
31
+ return withPdfExtension(name || DEFAULT_PDF_FILE_NAME2);
32
+ }
33
+
34
+ export { DEFAULT_PDF_FILE_NAME2, resolvePdfFileName2 };
35
+
36
+ //# debugId=9BDA8B0AC7C1F52764756E2164756E21
37
+ //# sourceMappingURL=index-paaaedrm.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lib/pdf-file-name.ts"],
4
+ "sourcesContent": [
5
+ "import { isBlob, type PdfSource, pdfSourceUrl } from './pdf-source';\n\n/** The name a download takes when nothing else gives one, before `.pdf`. */\nexport const DEFAULT_PDF_FILE_NAME = 'document';\n\nfunction withPdfExtension(name: string) {\n\treturn /\\.pdf$/i.test(name) ? name : `${name}.pdf`;\n}\n\nfunction lastPathSegment(url: string) {\n\ttry {\n\t\tconst { pathname, protocol } = new URL(url, 'http://localhost/');\n\t\tif (protocol === 'blob:' || protocol === 'data:') return '';\n\t\t// `%2F` decodes to a slash, which no file name may hold.\n\t\treturn decodeURIComponent(pathname.split('/').pop() ?? '').replace(\n\t\t\t/[\\\\/]/g,\n\t\t\t'_',\n\t\t);\n\t} catch {\n\t\treturn '';\n\t}\n}\n\nfunction ownName(source: PdfSource) {\n\tif (isBlob(source)) {\n\t\tconst { name } = source as Blob & { name?: unknown };\n\t\treturn typeof name === 'string' ? name : '';\n\t}\n\tconst url = pdfSourceUrl(source);\n\treturn url === null ? '' : lastPathSegment(url);\n}\n\n/**\n * The saved file's name: `fileName`, then the `File`'s own name, then the\n * last segment of the URL's path, then `fallback` (`document`, or its\n * translation). `.pdf` is added when missing.\n */\nexport function resolvePdfFileName(\n\tsource: PdfSource,\n\tfileName?: string,\n\tfallback: string = DEFAULT_PDF_FILE_NAME,\n) {\n\tconst name = fileName?.trim() || ownName(source).trim() || fallback.trim();\n\treturn withPdfExtension(name || DEFAULT_PDF_FILE_NAME);\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;AAGO,IAAM,yBAAwB;AAErC,SAAS,gBAAgB,CAAC,MAAc;AAAA,EACvC,OAAO,UAAU,KAAK,IAAI,IAAI,OAAO,GAAG;AAAA;AAGzC,SAAS,eAAe,CAAC,KAAa;AAAA,EACrC,IAAI;AAAA,IACH,QAAQ,UAAU,aAAa,IAAI,IAAI,KAAK,mBAAmB;AAAA,IAC/D,IAAI,aAAa,WAAW,aAAa;AAAA,MAAS,OAAO;AAAA,IAEzD,OAAO,mBAAmB,SAAS,MAAM,GAAG,EAAE,IAAI,KAAK,EAAE,EAAE,QAC1D,UACA,GACD;AAAA,IACC,MAAM;AAAA,IACP,OAAO;AAAA;AAAA;AAIT,SAAS,OAAO,CAAC,QAAmB;AAAA,EACnC,IAAI,QAAO,MAAM,GAAG;AAAA,IACnB,QAAQ,SAAS;AAAA,IACjB,OAAO,OAAO,SAAS,WAAW,OAAO;AAAA,EAC1C;AAAA,EACA,MAAM,MAAM,cAAa,MAAM;AAAA,EAC/B,OAAO,QAAQ,OAAO,KAAK,gBAAgB,GAAG;AAAA;AAQxC,SAAS,mBAAkB,CACjC,QACA,UACA,WAAmB,wBAClB;AAAA,EACD,MAAM,OAAO,UAAU,KAAK,KAAK,QAAQ,MAAM,EAAE,KAAK,KAAK,SAAS,KAAK;AAAA,EACzE,OAAO,iBAAiB,QAAQ,sBAAqB;AAAA;",
8
+ "debugId": "9BDA8B0AC7C1F52764756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,72 @@
1
+ import {
2
+ fractionDigitsOption2
3
+ } from "./index-6tn0wjsb.js";
4
+
5
+ // src/lib/print-format.utils.ts
6
+ var EMPTY = "—";
7
+ var DATE_ONLY = /^(\d{4})-(\d{2})-(\d{2})$/;
8
+ function formatAmount2(value, currency, options = {}) {
9
+ if (value == null)
10
+ return EMPTY;
11
+ const { locale, fractionDigits } = options;
12
+ const digits = fractionDigitsOption2(fractionDigits) ?? (currency ? undefined : 2);
13
+ try {
14
+ return new Intl.NumberFormat(locale, {
15
+ style: currency ? "currency" : "decimal",
16
+ currency: currency || undefined,
17
+ minimumFractionDigits: digits,
18
+ maximumFractionDigits: digits
19
+ }).format(value);
20
+ } catch {
21
+ return `${value.toFixed(digits ?? 2)}${currency ? ` ${currency}` : ""}`;
22
+ }
23
+ }
24
+ function formatDate2(value, options = {}) {
25
+ if (value == null || value === "")
26
+ return EMPTY;
27
+ const { locale, timeZone, dateStyle = "medium", timeStyle } = options;
28
+ const dateOnly = typeof value === "string" ? DATE_ONLY.exec(value) : null;
29
+ try {
30
+ if (dateOnly) {
31
+ const [, year, month, day] = dateOnly;
32
+ const utc = new Date(0);
33
+ utc.setUTCFullYear(+year, +month - 1, +day);
34
+ if (utc.getUTCMonth() !== +month - 1 || utc.getUTCDate() !== +day) {
35
+ return value;
36
+ }
37
+ return new Intl.DateTimeFormat(locale, {
38
+ dateStyle,
39
+ timeZone: "UTC"
40
+ }).format(utc);
41
+ }
42
+ const date = value instanceof Date ? value : new Date(value);
43
+ if (Number.isNaN(date.getTime())) {
44
+ return typeof value === "string" ? value : EMPTY;
45
+ }
46
+ return new Intl.DateTimeFormat(locale, {
47
+ dateStyle,
48
+ timeStyle,
49
+ timeZone
50
+ }).format(date);
51
+ } catch {
52
+ return typeof value === "string" ? value : EMPTY;
53
+ }
54
+ }
55
+ function createFormatters2(defaults = {}) {
56
+ return {
57
+ formatAmount: (value, currency, options) => formatAmount2(value, currency, {
58
+ ...options,
59
+ locale: options?.locale ?? defaults.locale
60
+ }),
61
+ formatDate: (value, options) => formatDate2(value, {
62
+ ...options,
63
+ locale: options?.locale ?? defaults.locale,
64
+ timeZone: options?.timeZone ?? defaults.timeZone
65
+ })
66
+ };
67
+ }
68
+
69
+ export { formatAmount2, formatDate2, createFormatters2 };
70
+
71
+ //# debugId=DD36C19E6625613264756E2164756E21
72
+ //# sourceMappingURL=index-w3ajz57t.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lib/print-format.utils.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Amount and date formatting, written for printed documents and used\n * everywhere.\n *\n * This lives in `lib/` because it depends on nothing but `Intl`, so a screen\n * that formats an amount never imports the print entry and its optional\n * peers. The print entry re-exports it.\n *\n * Without a `locale`, the runtime's locale applies (as before); pass one, or\n * use `useFormatters()`, for output that is the same on a server and in the\n * browser.\n */\n\nimport { fractionDigitsOption } from './print-fraction-digits';\n\nconst EMPTY = '—';\nconst DATE_ONLY = /^(\\d{4})-(\\d{2})-(\\d{2})$/;\n\nexport type FormatAmountOptions = {\n\t/** BCP 47 locale, such as `'fr-FR'`. Defaults to the runtime's locale. */\n\tlocale?: string;\n\t/**\n\t * Decimals to show, 0 to 20. With a currency it defaults to the\n\t * currency's own (ISO 4217: JPY 0, EUR 2, KWD 3); without one, to 2. Pass\n\t * `2` to keep two decimals whatever the currency. `NaN` or `Infinity`\n\t * counts as not given.\n\t */\n\tfractionDigits?: number;\n};\n\nexport type FormatDateOptions = {\n\t/** BCP 47 locale, such as `'fr-FR'`. Defaults to the runtime's locale. */\n\tlocale?: string;\n\t/**\n\t * IANA time zone for values with a time, such as `'Europe/Paris'`.\n\t * Defaults to the runtime's. A date-only value (`'2026-03-01'`) ignores it\n\t * and always shows its own calendar day.\n\t */\n\ttimeZone?: string;\n\t/** Defaults to `'medium'` (`Mar 1, 2026`). */\n\tdateStyle?: 'full' | 'long' | 'medium' | 'short';\n\t/** Adds the time; ignored for a date-only value. */\n\ttimeStyle?: 'full' | 'long' | 'medium' | 'short';\n};\n\nexport type DateInput = string | number | Date | null | undefined;\n\n/**\n * Formats an amount, in a currency when one is given. `null` and\n * `undefined` give `'—'`.\n *\n * @example formatAmount(1234.5, 'EUR', { locale: 'fr-FR' }) // '1 234,50 €'\n * @example formatAmount(1234.5, 'JPY', { locale: 'en-US' }) // '¥1,235'\n */\nexport function formatAmount(\n\tvalue: number | null | undefined,\n\tcurrency?: string | null,\n\toptions: FormatAmountOptions = {},\n): string {\n\tif (value == null) return EMPTY;\n\tconst { locale, fractionDigits } = options;\n\tconst digits =\n\t\tfractionDigitsOption(fractionDigits) ?? (currency ? undefined : 2);\n\ttry {\n\t\treturn new Intl.NumberFormat(locale, {\n\t\t\tstyle: currency ? 'currency' : 'decimal',\n\t\t\tcurrency: currency || undefined,\n\t\t\tminimumFractionDigits: digits,\n\t\t\tmaximumFractionDigits: digits,\n\t\t}).format(value);\n\t} catch {\n\t\treturn `${value.toFixed(digits ?? 2)}${currency ? ` ${currency}` : ''}`;\n\t}\n}\n\n/**\n * Formats a date. A date-only string (`YYYY-MM-DD`) keeps its calendar day\n * in every time zone; other values are shown in `timeZone`. Empty values\n * give `'—'`; a string that is not a date is returned as it is.\n *\n * @example formatDate('2026-03-01', { locale: 'en-US' }) // 'Mar 1, 2026'\n */\nexport function formatDate(\n\tvalue: DateInput,\n\toptions: FormatDateOptions = {},\n): string {\n\tif (value == null || value === '') return EMPTY;\n\tconst { locale, timeZone, dateStyle = 'medium', timeStyle } = options;\n\tconst dateOnly = typeof value === 'string' ? DATE_ONLY.exec(value) : null;\n\ttry {\n\t\tif (dateOnly) {\n\t\t\tconst [, year, month, day] = dateOnly;\n\t\t\tconst utc = new Date(0);\n\t\t\tutc.setUTCFullYear(+year, +month - 1, +day);\n\t\t\t// `2024-02-31` or `2024-13-01` rolls over: not a date.\n\t\t\tif (utc.getUTCMonth() !== +month - 1 || utc.getUTCDate() !== +day) {\n\t\t\t\treturn value as string;\n\t\t\t}\n\t\t\treturn new Intl.DateTimeFormat(locale, {\n\t\t\t\tdateStyle,\n\t\t\t\ttimeZone: 'UTC',\n\t\t\t}).format(utc);\n\t\t}\n\t\tconst date = value instanceof Date ? value : new Date(value);\n\t\tif (Number.isNaN(date.getTime())) {\n\t\t\treturn typeof value === 'string' ? value : EMPTY;\n\t\t}\n\t\treturn new Intl.DateTimeFormat(locale, {\n\t\t\tdateStyle,\n\t\t\ttimeStyle,\n\t\t\ttimeZone,\n\t\t}).format(date);\n\t} catch {\n\t\treturn typeof value === 'string' ? value : EMPTY;\n\t}\n}\n\nexport type FormattersOptions = {\n\tlocale?: string;\n\ttimeZone?: string;\n};\n\nexport type Formatters = {\n\tformatAmount: (\n\t\tvalue: number | null | undefined,\n\t\tcurrency?: string | null,\n\t\toptions?: FormatAmountOptions,\n\t) => string;\n\tformatDate: (value: DateInput, options?: FormatDateOptions) => string;\n};\n\n/**\n * `formatAmount` and `formatDate` bound to a locale and a time zone, for a\n * server route or a document builder. Options given per call win, unless\n * they are `undefined`.\n *\n * @example\n * const { formatAmount, formatDate } = createFormatters({ locale: 'fr-FR', timeZone: 'Europe/Paris' });\n */\nexport function createFormatters(defaults: FormattersOptions = {}): Formatters {\n\treturn {\n\t\tformatAmount: (value, currency, options) =>\n\t\t\tformatAmount(value, currency, {\n\t\t\t\t...options,\n\t\t\t\tlocale: options?.locale ?? defaults.locale,\n\t\t\t}),\n\t\tformatDate: (value, options) =>\n\t\t\tformatDate(value, {\n\t\t\t\t...options,\n\t\t\t\tlocale: options?.locale ?? defaults.locale,\n\t\t\t\ttimeZone: options?.timeZone ?? defaults.timeZone,\n\t\t\t}),\n\t};\n}\n"
6
+ ],
7
+ "mappings": ";;;;;AAeA,IAAM,QAAQ;AACd,IAAM,YAAY;AAsCX,SAAS,aAAY,CAC3B,OACA,UACA,UAA+B,CAAC,GACvB;AAAA,EACT,IAAI,SAAS;AAAA,IAAM,OAAO;AAAA,EAC1B,QAAQ,QAAQ,mBAAmB;AAAA,EACnC,MAAM,SACL,sBAAqB,cAAc,MAAM,WAAW,YAAY;AAAA,EACjE,IAAI;AAAA,IACH,OAAO,IAAI,KAAK,aAAa,QAAQ;AAAA,MACpC,OAAO,WAAW,aAAa;AAAA,MAC/B,UAAU,YAAY;AAAA,MACtB,uBAAuB;AAAA,MACvB,uBAAuB;AAAA,IACxB,CAAC,EAAE,OAAO,KAAK;AAAA,IACd,MAAM;AAAA,IACP,OAAO,GAAG,MAAM,QAAQ,UAAU,CAAC,IAAI,WAAW,IAAI,aAAa;AAAA;AAAA;AAW9D,SAAS,WAAU,CACzB,OACA,UAA6B,C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