react-invoice 0.1.1

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/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # React Invoice
2
+
3
+ Build invoices with React components and render the same component tree to both HTML and PDF.
4
+
5
+ React Invoice is built on top of [`@react-pdf/renderer`](https://github.com/diegomura/react-pdf) and [`react-pdf-tailwind`](https://github.com/aanckar/react-pdf-tailwind), allowing you to build invoices with familiar React components and Tailwind CSS without maintaining separate templates for web preview and PDF generation.
6
+
7
+ **Documentation:** https://react-invoice.swrg.dev
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install react-invoice
13
+ ```
14
+
15
+ **Peer dependencies**
16
+
17
+ - `react` ^18 || ^19
18
+ - `react-dom` ^18 || ^19
19
+
20
+ ## Quick Start
21
+
22
+ ```tsx
23
+ import { Invoice, renderToPdf } from "react-invoice";
24
+
25
+ const data = {
26
+ items: [
27
+ { id: 1, description: "React Invoice License", amount: 49 },
28
+ { id: 2, description: "Priority Support", amount: 19 },
29
+ ],
30
+ };
31
+
32
+ function InvoiceView() {
33
+ return (
34
+ <Invoice.Root className="bg-white p-10 text-sm">
35
+ <Invoice.Section className="mb-10 flex justify-between">
36
+ <Invoice.Text className="text-2xl font-bold">Invoice</Invoice.Text>
37
+ <Invoice.Text>INV-001</Invoice.Text>
38
+ </Invoice.Section>
39
+
40
+ <Invoice.Section className="border-y py-4">
41
+ {data.items.map((item) => (
42
+ <Invoice.Section key={item.id} className="flex justify-between py-2">
43
+ <Invoice.Text>{item.description}</Invoice.Text>
44
+ <Invoice.Text>${item.amount}</Invoice.Text>
45
+ </Invoice.Section>
46
+ ))}
47
+ </Invoice.Section>
48
+ </Invoice.Root>
49
+ );
50
+ }
51
+ ```
52
+
53
+ Render the component in your React application:
54
+
55
+ ```tsx
56
+ <InvoiceView />
57
+ ```
58
+
59
+ Generate a PDF:
60
+
61
+ ```tsx
62
+ const blob = await renderToPdf(<InvoiceView />);
63
+ ```
64
+
65
+ ## Components
66
+
67
+ | Component | HTML | PDF |
68
+ | ----------------- | ----------- | ------------------- |
69
+ | `Invoice.Root` | `<article>` | `Document` + `Page` |
70
+ | `Invoice.Section` | `<div>` | `View` |
71
+ | `Invoice.Text` | `<p>` | `Text` |
72
+ | `Invoice.Link` | `<a>` | `Link` |
73
+
74
+ ## Documentation
75
+
76
+ The complete documentation is available at:
77
+
78
+ **https://react-invoice.swrg.dev**
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c,1);let l=require("react/jsx-runtime"),u=require("cnfast"),d=require("@react-pdf/renderer"),f=require("react-pdf-tailwind");const p=(0,c.forwardRef)(function({children:e,className:t,style:n,...r},i){return(0,l.jsx)(`article`,{ref:i,className:t,style:n,...r,children:e})});p.displayName=`Invoice.Root`;const m=(0,c.forwardRef)(function({children:e,className:t,style:n,...r},i){return(0,l.jsx)(`p`,{ref:i,className:t,style:n,...r,children:e})});m.displayName=`Invoice.Text`;const h=(0,c.forwardRef)(function({className:e,...t},n){return(0,l.jsx)(`div`,{ref:n,className:(0,u.cn)(`flex flex-col`,e),...t})});h.displayName=`Invoice.Section`;const g=(0,c.forwardRef)(function({children:e,className:t,style:n,...r},i){return(0,l.jsx)(`a`,{ref:i,className:t,style:n,...r,children:e})});g.displayName=`Invoice.Link`;let _={},v=(0,f.createTw)({});function y(e){return _=e??{},v=(0,f.createTw)(_),v}function b(e){_={..._,...e},v=(0,f.createTw)(_)}function x(e){return v(e)}const S=new Map([[p,d.Document],[m,d.Text],[h,d.View],[g,d.Link]]);function C(e,t){let n=e?x(e):{},r=t||{},i={...n,...r};return i.display===`flex`&&!i.flexDirection&&(i.flexDirection=`row`),i}function w(e){return e==null||typeof e==`boolean`}function T(e,t,n){if(w(e))return null;let{type:r,props:i,key:a}=e;if(r===c.default.Fragment){let{children:e}=i;return(0,l.jsx)(l.Fragment,{children:E(e,t,n)})}if(r===p){let{children:e,className:r,style:o}=i,s=C(r,o);return(0,l.jsx)(d.Document,{...t,children:(0,l.jsx)(d.Page,{size:n?.size??`A4`,...n,style:[Object.keys(s).length?s:void 0,n?.style].filter(Boolean),children:E(e,t,n)})},a)}let o=S.get(r);if(o){let{children:e,className:r,style:s,...c}=i,u=o===d.Text||o===d.Link?D(e,t,n):E(e,t,n),f=C(r,s);return(0,l.jsx)(o,{style:Object.keys(f).length?f:void 0,...c,children:u},a??void 0)}if(typeof r==`function`)try{let e=r(i);return c.default.isValidElement(e)?T(e,t,n):e==null?null:(0,l.jsx)(l.Fragment,{children:e})}catch{return null}if(typeof r==`string`){let{children:e,className:o,style:s}=i,c=r===`span`||r===`strong`||r===`em`||r===`b`||r===`i`?D(e,t,n):E(e,t,n),u=C(o,s);return(0,l.jsx)(d.View,{style:Object.keys(u).length?u:void 0,children:c},a??void 0)}return null}function E(e,t,n){return c.default.Children.map(e,e=>w(e)?null:typeof e==`string`?(0,l.jsx)(d.Text,{children:e}):typeof e==`number`?(0,l.jsx)(d.Text,{children:String(e)}):c.default.isValidElement(e)?T(e,t,n):e)}function D(e,t,n){return c.default.Children.map(e,e=>w(e)?null:typeof e==`string`||typeof e==`number`?e:c.default.isValidElement(e)?T(e,t,n):e)}function O(e,t,n){return T(e,t,n)??(0,l.jsx)(d.View,{})}function k(e){let{variable:t,...n}=e;d.Font.register(n),t&&b({fontFamily:{[t.replace(/^font-/,``)]:[n.family]}})}async function A(e,t,n){let r=O(e,t,n),{pdf:i}=await import(`@react-pdf/renderer`);return await i(r).toBlob()}const j={Root:p,Text:m,Section:h,Link:g};exports.Invoice=j,exports.InvoiceLink=g,exports.InvoiceRoot=p,exports.InvoiceSection=h,exports.InvoiceText=m,exports.registerFont=k,exports.renderToPdf=A,exports.setupPdf=y;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["Document","Text","View","Link","React","Page"],"sources":["../src/components/root.tsx","../src/components/text.tsx","../src/components/section.tsx","../src/components/link.tsx","../src/pdf/twind.ts","../src/pdf/mapper.tsx","../src/pdf/index.ts","../src/index.ts"],"sourcesContent":["import React, { forwardRef } from \"react\";\n\nexport interface InvoiceRootProps extends React.HTMLAttributes<HTMLElement> {}\n\nexport const InvoiceRoot = forwardRef<HTMLElement, InvoiceRootProps>(function InvoiceRoot(\n { children, className, style, ...props },\n ref,\n) {\n return (\n <article ref={ref} className={className} style={style} {...props}>\n {children}\n </article>\n );\n});\n\nInvoiceRoot.displayName = \"Invoice.Root\";\n","import { forwardRef } from \"react\";\n\nexport interface InvoiceTextProps extends React.HTMLAttributes<HTMLParagraphElement> {}\n\nexport const InvoiceText = forwardRef<HTMLParagraphElement, InvoiceTextProps>(function InvoiceText(\n { children, className, style, ...props },\n ref,\n) {\n return (\n <p ref={ref} className={className} style={style} {...props}>\n {children}\n </p>\n );\n});\n\nInvoiceText.displayName = \"Invoice.Text\";\n","import { forwardRef } from \"react\";\nimport { cn } from \"cnfast\";\n\nexport const InvoiceSection = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n function InvoiceSection({ className, ...props }, ref) {\n return <div ref={ref} className={cn(\"flex flex-col\", className)} {...props} />;\n },\n);\n\nInvoiceSection.displayName = \"Invoice.Section\";\n\nexport type InvoiceSectionProps = React.HTMLAttributes<HTMLDivElement>;\n","import React, { forwardRef } from \"react\";\n\nexport interface InvoiceLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {}\n\nexport const InvoiceLink = forwardRef<HTMLAnchorElement, InvoiceLinkProps>(function InvoiceLink(\n { children, className, style, ...props },\n ref,\n) {\n return (\n <a ref={ref} className={className} style={style} {...props}>\n {children}\n </a>\n );\n});\n\nInvoiceLink.displayName = \"Invoice.Link\";\n","import { Font } from \"@react-pdf/renderer\";\nimport { createTw } from \"react-pdf-tailwind\";\n\nexport { createTw };\n\nlet twConfig: Record<string, unknown> = {};\nlet twInstance: ReturnType<typeof createTw> = createTw({});\n\nexport function setupPdf(options?: Parameters<typeof createTw>[0]): ReturnType<typeof createTw> {\n twConfig = options ?? {};\n twInstance = createTw(twConfig);\n return twInstance;\n}\n\nexport function extendTwConfig(options: Record<string, unknown>): void {\n twConfig = { ...twConfig, ...options };\n twInstance = createTw(twConfig as Parameters<typeof createTw>[0]);\n}\n\nexport function tw(classes: string): Record<string, unknown> {\n return twInstance(classes) as Record<string, unknown>;\n}\n\nexport { Font };\n\nexport const defaultFonts = [{ family: \"Helvetica\", src: \"Helvetica\" }];\n","import React from \"react\";\nimport { Document, Page, View, Text, Link } from \"@react-pdf/renderer\";\nimport type { DocumentProps, PageProps } from \"@react-pdf/renderer\";\nimport { tw } from \"./twind\";\nimport { InvoiceRoot } from \"../components/root\";\nimport { InvoiceText } from \"../components/text\";\nimport { InvoiceSection } from \"../components/section\";\nimport { InvoiceLink } from \"../components/link\";\n\nconst componentMap = new Map<React.ComponentType, React.ComponentType>([\n [InvoiceRoot, Document],\n [InvoiceText, Text],\n [InvoiceSection, View],\n [InvoiceLink, Link],\n]);\n\nfunction resolveStyles(className?: string, style?: React.CSSProperties): Record<string, unknown> {\n const fromClass = className ? (tw(className) as Record<string, unknown>) : {};\n const fromStyle = style ? (style as unknown as Record<string, unknown>) : {};\n const merged = { ...fromClass, ...fromStyle };\n if (merged.display === \"flex\" && !merged.flexDirection) {\n merged.flexDirection = \"row\";\n }\n return merged;\n}\n\nfunction isEmpty(node: React.ReactNode): boolean {\n return node == null || typeof node === \"boolean\";\n}\n\nfunction convertElement(\n element: React.ReactElement,\n documentOptions?: DocumentProps,\n pageOptions?: PageProps,\n): React.ReactElement | null {\n if (isEmpty(element)) return null;\n\n const { type, props, key } = element;\n\n if (type === React.Fragment) {\n const { children } = props as { children?: React.ReactNode };\n return <>{processChildren(children, documentOptions, pageOptions)}</>;\n }\n\n if (type === InvoiceRoot) {\n const { children, className, style } = props as {\n children?: React.ReactNode;\n className?: string;\n style?: React.CSSProperties;\n };\n const resolvedStyle = resolveStyles(className, style);\n return (\n <Document key={key} {...(documentOptions as any)}>\n <Page\n size={pageOptions?.size ?? \"A4\"}\n {...(pageOptions as any)}\n style={[\n Object.keys(resolvedStyle).length ? (resolvedStyle as any) : undefined,\n pageOptions?.style,\n ].filter(Boolean)}\n >\n {processChildren(children, documentOptions, pageOptions)}\n </Page>\n </Document>\n );\n }\n\n const PdfComponent = componentMap.get(type as React.ComponentType);\n if (PdfComponent) {\n const { children, className, style, ...rest } = props as {\n children?: React.ReactNode;\n className?: string;\n style?: React.CSSProperties;\n [key: string]: unknown;\n };\n const pdfChildren =\n PdfComponent === Text || PdfComponent === Link\n ? processTextChildren(children, documentOptions, pageOptions)\n : processChildren(children, documentOptions, pageOptions);\n const resolvedStyle = resolveStyles(className, style);\n return (\n <PdfComponent\n key={key ?? undefined}\n style={Object.keys(resolvedStyle).length ? resolvedStyle : undefined}\n {...(rest as any)}\n >\n {pdfChildren}\n </PdfComponent>\n );\n }\n\n if (typeof type === \"function\") {\n try {\n const result = (type as (p: Record<string, unknown>) => React.ReactNode)(\n props as Record<string, unknown>,\n );\n if (React.isValidElement(result)) return convertElement(result, documentOptions, pageOptions);\n if (result != null) return <>{result}</>;\n return null;\n } catch {\n return null;\n }\n }\n\n if (typeof type === \"string\") {\n const { children, className, style } = props as {\n children?: React.ReactNode;\n className?: string;\n style?: React.CSSProperties;\n };\n const pdfChildren =\n type === \"span\" || type === \"strong\" || type === \"em\" || type === \"b\" || type === \"i\"\n ? processTextChildren(children, documentOptions, pageOptions)\n : processChildren(children, documentOptions, pageOptions);\n const resolvedStyle = resolveStyles(className, style);\n return (\n <View\n key={key ?? undefined}\n style={Object.keys(resolvedStyle).length ? (resolvedStyle as any) : undefined}\n >\n {pdfChildren}\n </View>\n );\n }\n\n return null;\n}\n\nfunction processChildren(\n children: React.ReactNode,\n documentOptions?: DocumentProps,\n pageOptions?: PageProps,\n): React.ReactNode {\n return React.Children.map(children, (child) => {\n if (isEmpty(child)) return null;\n if (typeof child === \"string\") return <Text>{child}</Text>;\n if (typeof child === \"number\") return <Text>{String(child)}</Text>;\n if (React.isValidElement(child)) return convertElement(child, documentOptions, pageOptions);\n return child;\n });\n}\n\nfunction processTextChildren(\n children: React.ReactNode,\n documentOptions?: DocumentProps,\n pageOptions?: PageProps,\n): React.ReactNode {\n return React.Children.map(children, (child) => {\n if (isEmpty(child)) return null;\n if (typeof child === \"string\") return child;\n if (typeof child === \"number\") return child;\n if (React.isValidElement(child)) return convertElement(child, documentOptions, pageOptions);\n return child;\n });\n}\n\nexport function convertToPdf(\n element: React.ReactElement,\n documentOptions?: DocumentProps,\n pageOptions?: PageProps,\n): React.ReactElement {\n return convertElement(element, documentOptions, pageOptions) ?? <View />;\n}\n","import { type ReactElement } from \"react\";\nimport { Font } from \"@react-pdf/renderer\";\nimport type { DocumentProps, PageProps } from \"@react-pdf/renderer\";\nimport { convertToPdf } from \"./mapper\";\n\nexport { setupPdf, extendTwConfig, tw, createTw, Font, defaultFonts } from \"./twind\";\nimport { extendTwConfig } from \"./twind\";\n\nexport function registerFont(\n options: Parameters<typeof Font.register>[0] & { variable?: string },\n): void {\n const { variable, ...fontOptions } = options;\n Font.register(fontOptions);\n if (variable) {\n const familyKey = variable.replace(/^font-/, \"\");\n extendTwConfig({ fontFamily: { [familyKey]: [fontOptions.family] } });\n }\n}\n\nexport async function renderToPdf(\n element: ReactElement,\n documentOptions?: DocumentProps,\n pageOptions?: PageProps,\n): Promise<Blob> {\n const pdfElement = convertToPdf(element, documentOptions, pageOptions);\n const { pdf } = await import(\"@react-pdf/renderer\");\n return await pdf(pdfElement as ReactElement<DocumentProps>).toBlob();\n}\n","export { InvoiceRoot } from \"./components/root\";\nexport type { InvoiceRootProps } from \"./components/root\";\n\nexport { InvoiceText } from \"./components/text\";\nexport type { InvoiceTextProps } from \"./components/text\";\nexport { InvoiceSection } from \"./components/section\";\nexport type { InvoiceSectionProps } from \"./components/section\";\n\nexport { InvoiceLink } from \"./components/link\";\nexport type { InvoiceLinkProps } from \"./components/link\";\n\nimport { InvoiceRoot } from \"./components/root\";\nimport { InvoiceText } from \"./components/text\";\nimport { InvoiceSection } from \"./components/section\";\nimport { InvoiceLink } from \"./components/link\";\n\nexport const Invoice = {\n Root: InvoiceRoot,\n Text: InvoiceText,\n Section: InvoiceSection,\n Link: InvoiceLink,\n} as const;\n\nexport { renderToPdf, registerFont, setupPdf } from \"./pdf\";\n"],"mappings":"yrBAIA,MAAa,GAAA,EAAA,EAAA,WAAA,CAAwD,SACnE,CAAE,WAAU,YAAW,QAAO,GAAG,GACjC,EACA,CACA,OACE,EAAA,EAAA,IAAA,CAAC,UAAD,CAAc,MAAgB,YAAkB,QAAO,GAAI,EACxD,UACM,CAAA,CAEb,CAAC,EAED,EAAY,YAAc,eCX1B,MAAa,GAAA,EAAA,EAAA,WAAA,CAAiE,SAC5E,CAAE,WAAU,YAAW,QAAO,GAAG,GACjC,EACA,CACA,OACE,EAAA,EAAA,IAAA,CAAC,IAAD,CAAQ,MAAgB,YAAkB,QAAO,GAAI,EAClD,UACA,CAAA,CAEP,CAAC,EAED,EAAY,YAAc,eCZ1B,MAAa,GAAA,EAAA,EAAA,WAAA,CACX,SAAwB,CAAE,YAAW,GAAG,GAAS,EAAK,CACpD,OAAO,EAAA,EAAA,IAAA,CAAC,MAAD,CAAU,MAAK,WAAA,EAAA,EAAA,GAAA,CAAc,gBAAiB,CAAS,EAAG,GAA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,EADX,EAAS,QAAQ,SAAU,EACL,GAAI,CAAC,EAAY,MAAM,CAAE,CAAE,CAAC,CAExE,CAEA,eAAsB,EACpB,EACA,EACA,EACe,CACf,IAAM,EAAa,EAAa,EAAS,EAAiB,CAAW,EAC/D,CAAE,OAAQ,MAAM,OAAO,uBAC7B,OAAO,MAAM,EAAI,CAAyC,CAAC,CAAC,OAAO,CACrE,CCXA,MAAa,EAAU,CACrB,KAAM,EACN,KAAM,EACN,QAAS,EACT,KAAM,CACR"}
@@ -0,0 +1,39 @@
1
+ import React$1, { ReactElement } from "react";
2
+ import { DocumentProps, Font, PageProps } from "@react-pdf/renderer";
3
+ import { createTw } from "react-pdf-tailwind";
4
+
5
+ //#region src/components/root.d.ts
6
+ interface InvoiceRootProps extends React$1.HTMLAttributes<HTMLElement> {}
7
+ declare const InvoiceRoot: React$1.ForwardRefExoticComponent<InvoiceRootProps & React$1.RefAttributes<HTMLElement>>;
8
+ //#endregion
9
+ //#region src/components/text.d.ts
10
+ interface InvoiceTextProps extends React.HTMLAttributes<HTMLParagraphElement> {}
11
+ declare const InvoiceText: import("react").ForwardRefExoticComponent<InvoiceTextProps & import("react").RefAttributes<HTMLParagraphElement>>;
12
+ //#endregion
13
+ //#region src/components/section.d.ts
14
+ declare const InvoiceSection: import("react").ForwardRefExoticComponent<import("react").HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
15
+ type InvoiceSectionProps = React.HTMLAttributes<HTMLDivElement>;
16
+ //#endregion
17
+ //#region src/components/link.d.ts
18
+ interface InvoiceLinkProps extends React$1.AnchorHTMLAttributes<HTMLAnchorElement> {}
19
+ declare const InvoiceLink: React$1.ForwardRefExoticComponent<InvoiceLinkProps & React$1.RefAttributes<HTMLAnchorElement>>;
20
+ //#endregion
21
+ //#region src/pdf/twind.d.ts
22
+ declare function setupPdf(options?: Parameters<typeof createTw>[0]): ReturnType<typeof createTw>;
23
+ //#endregion
24
+ //#region src/pdf/index.d.ts
25
+ declare function registerFont(options: Parameters<typeof Font.register>[0] & {
26
+ variable?: string;
27
+ }): void;
28
+ declare function renderToPdf(element: ReactElement, documentOptions?: DocumentProps, pageOptions?: PageProps): Promise<Blob>;
29
+ //#endregion
30
+ //#region src/index.d.ts
31
+ declare const Invoice: {
32
+ readonly Root: import("react").ForwardRefExoticComponent<InvoiceRootProps & import("react").RefAttributes<HTMLElement>>;
33
+ readonly Text: import("react").ForwardRefExoticComponent<InvoiceTextProps & import("react").RefAttributes<HTMLParagraphElement>>;
34
+ readonly Section: import("react").ForwardRefExoticComponent<import("react").HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
35
+ readonly Link: import("react").ForwardRefExoticComponent<InvoiceLinkProps & import("react").RefAttributes<HTMLAnchorElement>>;
36
+ };
37
+ //#endregion
38
+ export { Invoice, InvoiceLink, type InvoiceLinkProps, InvoiceRoot, type InvoiceRootProps, InvoiceSection, type InvoiceSectionProps, InvoiceText, type InvoiceTextProps, registerFont, renderToPdf, setupPdf };
39
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/components/root.tsx","../src/components/text.tsx","../src/components/section.tsx","../src/components/link.tsx","../src/pdf/twind.ts","../src/pdf/index.ts","../src/index.ts"],"mappings":";;;;;UAEiB,gBAAA,SAAyB,OAAA,CAAM,cAAc,CAAC,WAAA;AAAA,cAElD,WAAA,EAAW,OAAA,CAAA,yBAAA,CAAA,gBAAA,GAAA,OAAA,CAAA,aAAA,CAAA,WAAA;;;UCFP,gBAAA,SAAyB,KAAA,CAAM,cAAc,CAAC,oBAAA;AAAA,cAElD,WAAA,kBAAW,yBAAA,CAAA,gBAAA,mBAAA,aAAA,CAAA,oBAAA;;;cCDX,cAAA,kBAAc,yBAAA,iBAAA,cAAA,CAAA,cAAA,oBAAA,aAAA,CAAA,cAAA;AAAA,KAQf,mBAAA,GAAsB,KAAA,CAAM,cAAc,CAAC,cAAA;;;UCTtC,gBAAA,SAAyB,OAAA,CAAM,oBAAoB,CAAC,iBAAA;AAAA,cAExD,WAAA,EAAW,OAAA,CAAA,yBAAA,CAAA,gBAAA,GAAA,OAAA,CAAA,aAAA,CAAA,iBAAA;;;iBCIR,QAAA,CAAS,OAAA,GAAU,UAAA,QAAkB,QAAA,OAAe,UAAA,QAAkB,QAAA;;;iBCAtE,YAAA,CACd,OAAA,EAAS,UAAU,QAAQ,IAAA,CAAK,QAAA;EAAiB,QAAA;AAAA;AAAA,iBAU7B,WAAA,CACpB,OAAA,EAAS,YAAA,EACT,eAAA,GAAkB,aAAA,EAClB,WAAA,GAAc,SAAA,GACb,OAAA,CAAQ,IAAA;;;cCPE,OAAA;EAAA,yDAKH,gBAAA"}
@@ -0,0 +1,39 @@
1
+ import React$1, { ReactElement } from "react";
2
+ import { DocumentProps, Font, PageProps } from "@react-pdf/renderer";
3
+ import { createTw } from "react-pdf-tailwind";
4
+
5
+ //#region src/components/root.d.ts
6
+ interface InvoiceRootProps extends React$1.HTMLAttributes<HTMLElement> {}
7
+ declare const InvoiceRoot: React$1.ForwardRefExoticComponent<InvoiceRootProps & React$1.RefAttributes<HTMLElement>>;
8
+ //#endregion
9
+ //#region src/components/text.d.ts
10
+ interface InvoiceTextProps extends React.HTMLAttributes<HTMLParagraphElement> {}
11
+ declare const InvoiceText: import("react").ForwardRefExoticComponent<InvoiceTextProps & import("react").RefAttributes<HTMLParagraphElement>>;
12
+ //#endregion
13
+ //#region src/components/section.d.ts
14
+ declare const InvoiceSection: import("react").ForwardRefExoticComponent<import("react").HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
15
+ type InvoiceSectionProps = React.HTMLAttributes<HTMLDivElement>;
16
+ //#endregion
17
+ //#region src/components/link.d.ts
18
+ interface InvoiceLinkProps extends React$1.AnchorHTMLAttributes<HTMLAnchorElement> {}
19
+ declare const InvoiceLink: React$1.ForwardRefExoticComponent<InvoiceLinkProps & React$1.RefAttributes<HTMLAnchorElement>>;
20
+ //#endregion
21
+ //#region src/pdf/twind.d.ts
22
+ declare function setupPdf(options?: Parameters<typeof createTw>[0]): ReturnType<typeof createTw>;
23
+ //#endregion
24
+ //#region src/pdf/index.d.ts
25
+ declare function registerFont(options: Parameters<typeof Font.register>[0] & {
26
+ variable?: string;
27
+ }): void;
28
+ declare function renderToPdf(element: ReactElement, documentOptions?: DocumentProps, pageOptions?: PageProps): Promise<Blob>;
29
+ //#endregion
30
+ //#region src/index.d.ts
31
+ declare const Invoice: {
32
+ readonly Root: import("react").ForwardRefExoticComponent<InvoiceRootProps & import("react").RefAttributes<HTMLElement>>;
33
+ readonly Text: import("react").ForwardRefExoticComponent<InvoiceTextProps & import("react").RefAttributes<HTMLParagraphElement>>;
34
+ readonly Section: import("react").ForwardRefExoticComponent<import("react").HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
35
+ readonly Link: import("react").ForwardRefExoticComponent<InvoiceLinkProps & import("react").RefAttributes<HTMLAnchorElement>>;
36
+ };
37
+ //#endregion
38
+ export { Invoice, InvoiceLink, type InvoiceLinkProps, InvoiceRoot, type InvoiceRootProps, InvoiceSection, type InvoiceSectionProps, InvoiceText, type InvoiceTextProps, registerFont, renderToPdf, setupPdf };
39
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/components/root.tsx","../src/components/text.tsx","../src/components/section.tsx","../src/components/link.tsx","../src/pdf/twind.ts","../src/pdf/index.ts","../src/index.ts"],"mappings":";;;;;UAEiB,gBAAA,SAAyB,OAAA,CAAM,cAAc,CAAC,WAAA;AAAA,cAElD,WAAA,EAAW,OAAA,CAAA,yBAAA,CAAA,gBAAA,GAAA,OAAA,CAAA,aAAA,CAAA,WAAA;;;UCFP,gBAAA,SAAyB,KAAA,CAAM,cAAc,CAAC,oBAAA;AAAA,cAElD,WAAA,kBAAW,yBAAA,CAAA,gBAAA,mBAAA,aAAA,CAAA,oBAAA;;;cCDX,cAAA,kBAAc,yBAAA,iBAAA,cAAA,CAAA,cAAA,oBAAA,aAAA,CAAA,cAAA;AAAA,KAQf,mBAAA,GAAsB,KAAA,CAAM,cAAc,CAAC,cAAA;;;UCTtC,gBAAA,SAAyB,OAAA,CAAM,oBAAoB,CAAC,iBAAA;AAAA,cAExD,WAAA,EAAW,OAAA,CAAA,yBAAA,CAAA,gBAAA,GAAA,OAAA,CAAA,aAAA,CAAA,iBAAA;;;iBCIR,QAAA,CAAS,OAAA,GAAU,UAAA,QAAkB,QAAA,OAAe,UAAA,QAAkB,QAAA;;;iBCAtE,YAAA,CACd,OAAA,EAAS,UAAU,QAAQ,IAAA,CAAK,QAAA;EAAiB,QAAA;AAAA;AAAA,iBAU7B,WAAA,CACpB,OAAA,EAAS,YAAA,EACT,eAAA,GAAkB,aAAA,EAClB,WAAA,GAAc,SAAA,GACb,OAAA,CAAQ,IAAA;;;cCPE,OAAA;EAAA,yDAKH,gBAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import e,{forwardRef as t}from"react";import{Fragment as n,jsx as r}from"react/jsx-runtime";import{cn as i}from"cnfast";import{Document as a,Font as o,Link as s,Page as c,Text as l,View as u}from"@react-pdf/renderer";import{createTw as d}from"react-pdf-tailwind";const f=t(function({children:e,className:t,style:n,...i},a){return r(`article`,{ref:a,className:t,style:n,...i,children:e})});f.displayName=`Invoice.Root`;const p=t(function({children:e,className:t,style:n,...i},a){return r(`p`,{ref:a,className:t,style:n,...i,children:e})});p.displayName=`Invoice.Text`;const m=t(function({className:e,...t},n){return r(`div`,{ref:n,className:i(`flex flex-col`,e),...t})});m.displayName=`Invoice.Section`;const h=t(function({children:e,className:t,style:n,...i},a){return r(`a`,{ref:a,className:t,style:n,...i,children:e})});h.displayName=`Invoice.Link`;let g={},_=d({});function v(e){return g=e??{},_=d(g),_}function y(e){g={...g,...e},_=d(g)}function b(e){return _(e)}const x=new Map([[f,a],[p,l],[m,u],[h,s]]);function S(e,t){let n=e?b(e):{},r=t||{},i={...n,...r};return i.display===`flex`&&!i.flexDirection&&(i.flexDirection=`row`),i}function C(e){return e==null||typeof e==`boolean`}function w(t,i,o){if(C(t))return null;let{type:d,props:p,key:m}=t;if(d===e.Fragment){let{children:e}=p;return r(n,{children:T(e,i,o)})}if(d===f){let{children:e,className:t,style:n}=p,s=S(t,n);return r(a,{...i,children:r(c,{size:o?.size??`A4`,...o,style:[Object.keys(s).length?s:void 0,o?.style].filter(Boolean),children:T(e,i,o)})},m)}let h=x.get(d);if(h){let{children:e,className:t,style:n,...a}=p,c=h===l||h===s?E(e,i,o):T(e,i,o),u=S(t,n);return r(h,{style:Object.keys(u).length?u:void 0,...a,children:c},m??void 0)}if(typeof d==`function`)try{let t=d(p);return e.isValidElement(t)?w(t,i,o):t==null?null:r(n,{children:t})}catch{return null}if(typeof d==`string`){let{children:e,className:t,style:n}=p,a=d===`span`||d===`strong`||d===`em`||d===`b`||d===`i`?E(e,i,o):T(e,i,o),s=S(t,n);return r(u,{style:Object.keys(s).length?s:void 0,children:a},m??void 0)}return null}function T(t,n,i){return e.Children.map(t,t=>C(t)?null:typeof t==`string`?r(l,{children:t}):typeof t==`number`?r(l,{children:String(t)}):e.isValidElement(t)?w(t,n,i):t)}function E(t,n,r){return e.Children.map(t,t=>C(t)?null:typeof t==`string`||typeof t==`number`?t:e.isValidElement(t)?w(t,n,r):t)}function D(e,t,n){return w(e,t,n)??r(u,{})}function O(e){let{variable:t,...n}=e;o.register(n),t&&y({fontFamily:{[t.replace(/^font-/,``)]:[n.family]}})}async function k(e,t,n){let r=D(e,t,n),{pdf:i}=await import(`@react-pdf/renderer`);return await i(r).toBlob()}const A={Root:f,Text:p,Section:m,Link:h};export{A as Invoice,h as InvoiceLink,f as InvoiceRoot,m as InvoiceSection,p as InvoiceText,O as registerFont,k as renderToPdf,v as setupPdf};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/components/root.tsx","../src/components/text.tsx","../src/components/section.tsx","../src/components/link.tsx","../src/pdf/twind.ts","../src/pdf/mapper.tsx","../src/pdf/index.ts","../src/index.ts"],"sourcesContent":["import React, { forwardRef } from \"react\";\n\nexport interface InvoiceRootProps extends React.HTMLAttributes<HTMLElement> {}\n\nexport const InvoiceRoot = forwardRef<HTMLElement, InvoiceRootProps>(function InvoiceRoot(\n { children, className, style, ...props },\n ref,\n) {\n return (\n <article ref={ref} className={className} style={style} {...props}>\n {children}\n </article>\n );\n});\n\nInvoiceRoot.displayName = \"Invoice.Root\";\n","import { forwardRef } from \"react\";\n\nexport interface InvoiceTextProps extends React.HTMLAttributes<HTMLParagraphElement> {}\n\nexport const InvoiceText = forwardRef<HTMLParagraphElement, InvoiceTextProps>(function InvoiceText(\n { children, className, style, ...props },\n ref,\n) {\n return (\n <p ref={ref} className={className} style={style} {...props}>\n {children}\n </p>\n );\n});\n\nInvoiceText.displayName = \"Invoice.Text\";\n","import { forwardRef } from \"react\";\nimport { cn } from \"cnfast\";\n\nexport const InvoiceSection = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n function InvoiceSection({ className, ...props }, ref) {\n return <div ref={ref} className={cn(\"flex flex-col\", className)} {...props} />;\n },\n);\n\nInvoiceSection.displayName = \"Invoice.Section\";\n\nexport type InvoiceSectionProps = React.HTMLAttributes<HTMLDivElement>;\n","import React, { forwardRef } from \"react\";\n\nexport interface InvoiceLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {}\n\nexport const InvoiceLink = forwardRef<HTMLAnchorElement, InvoiceLinkProps>(function InvoiceLink(\n { children, className, style, ...props },\n ref,\n) {\n return (\n <a ref={ref} className={className} style={style} {...props}>\n {children}\n </a>\n );\n});\n\nInvoiceLink.displayName = \"Invoice.Link\";\n","import { Font } from \"@react-pdf/renderer\";\nimport { createTw } from \"react-pdf-tailwind\";\n\nexport { createTw };\n\nlet twConfig: Record<string, unknown> = {};\nlet twInstance: ReturnType<typeof createTw> = createTw({});\n\nexport function setupPdf(options?: Parameters<typeof createTw>[0]): ReturnType<typeof createTw> {\n twConfig = options ?? {};\n twInstance = createTw(twConfig);\n return twInstance;\n}\n\nexport function extendTwConfig(options: Record<string, unknown>): void {\n twConfig = { ...twConfig, ...options };\n twInstance = createTw(twConfig as Parameters<typeof createTw>[0]);\n}\n\nexport function tw(classes: string): Record<string, unknown> {\n return twInstance(classes) as Record<string, unknown>;\n}\n\nexport { Font };\n\nexport const defaultFonts = [{ family: \"Helvetica\", src: \"Helvetica\" }];\n","import React from \"react\";\nimport { Document, Page, View, Text, Link } from \"@react-pdf/renderer\";\nimport type { DocumentProps, PageProps } from \"@react-pdf/renderer\";\nimport { tw } from \"./twind\";\nimport { InvoiceRoot } from \"../components/root\";\nimport { InvoiceText } from \"../components/text\";\nimport { InvoiceSection } from \"../components/section\";\nimport { InvoiceLink } from \"../components/link\";\n\nconst componentMap = new Map<React.ComponentType, React.ComponentType>([\n [InvoiceRoot, Document],\n [InvoiceText, Text],\n [InvoiceSection, View],\n [InvoiceLink, Link],\n]);\n\nfunction resolveStyles(className?: string, style?: React.CSSProperties): Record<string, unknown> {\n const fromClass = className ? (tw(className) as Record<string, unknown>) : {};\n const fromStyle = style ? (style as unknown as Record<string, unknown>) : {};\n const merged = { ...fromClass, ...fromStyle };\n if (merged.display === \"flex\" && !merged.flexDirection) {\n merged.flexDirection = \"row\";\n }\n return merged;\n}\n\nfunction isEmpty(node: React.ReactNode): boolean {\n return node == null || typeof node === \"boolean\";\n}\n\nfunction convertElement(\n element: React.ReactElement,\n documentOptions?: DocumentProps,\n pageOptions?: PageProps,\n): React.ReactElement | null {\n if (isEmpty(element)) return null;\n\n const { type, props, key } = element;\n\n if (type === React.Fragment) {\n const { children } = props as { children?: React.ReactNode };\n return <>{processChildren(children, documentOptions, pageOptions)}</>;\n }\n\n if (type === InvoiceRoot) {\n const { children, className, style } = props as {\n children?: React.ReactNode;\n className?: string;\n style?: React.CSSProperties;\n };\n const resolvedStyle = resolveStyles(className, style);\n return (\n <Document key={key} {...(documentOptions as any)}>\n <Page\n size={pageOptions?.size ?? \"A4\"}\n {...(pageOptions as any)}\n style={[\n Object.keys(resolvedStyle).length ? (resolvedStyle as any) : undefined,\n pageOptions?.style,\n ].filter(Boolean)}\n >\n {processChildren(children, documentOptions, pageOptions)}\n </Page>\n </Document>\n );\n }\n\n const PdfComponent = componentMap.get(type as React.ComponentType);\n if (PdfComponent) {\n const { children, className, style, ...rest } = props as {\n children?: React.ReactNode;\n className?: string;\n style?: React.CSSProperties;\n [key: string]: unknown;\n };\n const pdfChildren =\n PdfComponent === Text || PdfComponent === Link\n ? processTextChildren(children, documentOptions, pageOptions)\n : processChildren(children, documentOptions, pageOptions);\n const resolvedStyle = resolveStyles(className, style);\n return (\n <PdfComponent\n key={key ?? undefined}\n style={Object.keys(resolvedStyle).length ? resolvedStyle : undefined}\n {...(rest as any)}\n >\n {pdfChildren}\n </PdfComponent>\n );\n }\n\n if (typeof type === \"function\") {\n try {\n const result = (type as (p: Record<string, unknown>) => React.ReactNode)(\n props as Record<string, unknown>,\n );\n if (React.isValidElement(result)) return convertElement(result, documentOptions, pageOptions);\n if (result != null) return <>{result}</>;\n return null;\n } catch {\n return null;\n }\n }\n\n if (typeof type === \"string\") {\n const { children, className, style } = props as {\n children?: React.ReactNode;\n className?: string;\n style?: React.CSSProperties;\n };\n const pdfChildren =\n type === \"span\" || type === \"strong\" || type === \"em\" || type === \"b\" || type === \"i\"\n ? processTextChildren(children, documentOptions, pageOptions)\n : processChildren(children, documentOptions, pageOptions);\n const resolvedStyle = resolveStyles(className, style);\n return (\n <View\n key={key ?? undefined}\n style={Object.keys(resolvedStyle).length ? (resolvedStyle as any) : undefined}\n >\n {pdfChildren}\n </View>\n );\n }\n\n return null;\n}\n\nfunction processChildren(\n children: React.ReactNode,\n documentOptions?: DocumentProps,\n pageOptions?: PageProps,\n): React.ReactNode {\n return React.Children.map(children, (child) => {\n if (isEmpty(child)) return null;\n if (typeof child === \"string\") return <Text>{child}</Text>;\n if (typeof child === \"number\") return <Text>{String(child)}</Text>;\n if (React.isValidElement(child)) return convertElement(child, documentOptions, pageOptions);\n return child;\n });\n}\n\nfunction processTextChildren(\n children: React.ReactNode,\n documentOptions?: DocumentProps,\n pageOptions?: PageProps,\n): React.ReactNode {\n return React.Children.map(children, (child) => {\n if (isEmpty(child)) return null;\n if (typeof child === \"string\") return child;\n if (typeof child === \"number\") return child;\n if (React.isValidElement(child)) return convertElement(child, documentOptions, pageOptions);\n return child;\n });\n}\n\nexport function convertToPdf(\n element: React.ReactElement,\n documentOptions?: DocumentProps,\n pageOptions?: PageProps,\n): React.ReactElement {\n return convertElement(element, documentOptions, pageOptions) ?? <View />;\n}\n","import { type ReactElement } from \"react\";\nimport { Font } from \"@react-pdf/renderer\";\nimport type { DocumentProps, PageProps } from \"@react-pdf/renderer\";\nimport { convertToPdf } from \"./mapper\";\n\nexport { setupPdf, extendTwConfig, tw, createTw, Font, defaultFonts } from \"./twind\";\nimport { extendTwConfig } from \"./twind\";\n\nexport function registerFont(\n options: Parameters<typeof Font.register>[0] & { variable?: string },\n): void {\n const { variable, ...fontOptions } = options;\n Font.register(fontOptions);\n if (variable) {\n const familyKey = variable.replace(/^font-/, \"\");\n extendTwConfig({ fontFamily: { [familyKey]: [fontOptions.family] } });\n }\n}\n\nexport async function renderToPdf(\n element: ReactElement,\n documentOptions?: DocumentProps,\n pageOptions?: PageProps,\n): Promise<Blob> {\n const pdfElement = convertToPdf(element, documentOptions, pageOptions);\n const { pdf } = await import(\"@react-pdf/renderer\");\n return await pdf(pdfElement as ReactElement<DocumentProps>).toBlob();\n}\n","export { InvoiceRoot } from \"./components/root\";\nexport type { InvoiceRootProps } from \"./components/root\";\n\nexport { InvoiceText } from \"./components/text\";\nexport type { InvoiceTextProps } from \"./components/text\";\nexport { InvoiceSection } from \"./components/section\";\nexport type { InvoiceSectionProps } from \"./components/section\";\n\nexport { InvoiceLink } from \"./components/link\";\nexport type { InvoiceLinkProps } from \"./components/link\";\n\nimport { InvoiceRoot } from \"./components/root\";\nimport { InvoiceText } from \"./components/text\";\nimport { InvoiceSection } from \"./components/section\";\nimport { InvoiceLink } from \"./components/link\";\n\nexport const Invoice = {\n Root: InvoiceRoot,\n Text: InvoiceText,\n Section: InvoiceSection,\n Link: InvoiceLink,\n} as const;\n\nexport { renderToPdf, registerFont, setupPdf } from \"./pdf\";\n"],"mappings":"uQAIA,MAAa,EAAc,EAA0C,SACnE,CAAE,WAAU,YAAW,QAAO,GAAG,GACjC,EACA,CACA,OACE,EAAC,UAAD,CAAc,MAAgB,YAAkB,QAAO,GAAI,EACxD,UACM,CAAA,CAEb,CAAC,EAED,EAAY,YAAc,eCX1B,MAAa,EAAc,EAAmD,SAC5E,CAAE,WAAU,YAAW,QAAO,GAAG,GACjC,EACA,CACA,OACE,EAAC,IAAD,CAAQ,MAAgB,YAAkB,QAAO,GAAI,EAClD,UACA,CAAA,CAEP,CAAC,EAED,EAAY,YAAc,eCZ1B,MAAa,EAAiB,EAC5B,SAAwB,CAAE,YAAW,GAAG,GAAS,EAAK,CACpD,OAAO,EAAC,MAAD,CAAU,MAAK,UAAW,EAAG,gBAAiB,CAAS,EAAG,GAAI,CAAQ,CAAA,CAC/E,CACF,EAEA,EAAe,YAAc,kBCL7B,MAAa,EAAc,EAAgD,SACzE,CAAE,WAAU,YAAW,QAAO,GAAG,GACjC,EACA,CACA,OACE,EAAC,IAAD,CAAQ,MAAgB,YAAkB,QAAO,GAAI,EAClD,UACA,CAAA,CAEP,CAAC,EAED,EAAY,YAAc,eCV1B,IAAI,EAAoC,CAAC,EACrC,EAA0C,EAAS,CAAC,CAAC,EAEzD,SAAgB,EAAS,EAAuE,CAG9F,MAFA,GAAW,GAAW,CAAC,EACvB,EAAa,EAAS,CAAQ,EACvB,CACT,CAEA,SAAgB,EAAe,EAAwC,CACrE,EAAW,CAAE,GAAG,EAAU,GAAG,CAAQ,EACrC,EAAa,EAAS,CAA0C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AAK,EAAU,KACvB,OAAO,GAAU,UACjB,OAAO,GAAU,SAAiB,EAClC,EAAM,eAAe,CAAK,EAAU,EAAe,EAAO,EAAiB,CAAW,EACnF,CACR,CACH,CAEA,SAAgB,EACd,EACA,EACA,EACoB,CACpB,OAAO,EAAe,EAAS,EAAiB,CAAW,GAAK,EAAC,EAAD,CAAO,CAAA,CACzE,CC1JA,SAAgB,EACd,EACM,CACN,GAAM,CAAE,WAAU,GAAG,GAAgB,EACrC,EAAK,SAAS,CAAW,EACrB,GAEF,EAAe,CAAE,WAAY,EADX,EAAS,QAAQ,SAAU,EACL,GAAI,CAAC,EAAY,MAAM,CAAE,CAAE,CAAC,CAExE,CAEA,eAAsB,EACpB,EACA,EACA,EACe,CACf,IAAM,EAAa,EAAa,EAAS,EAAiB,CAAW,EAC/D,CAAE,OAAQ,MAAM,OAAO,uBAC7B,OAAO,MAAM,EAAI,CAAyC,CAAC,CAAC,OAAO,CACrE,CCXA,MAAa,EAAU,CACrB,KAAM,EACN,KAAM,EACN,QAAS,EACT,KAAM,CACR"}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "react-invoice",
3
+ "version": "0.1.1",
4
+ "description": "Build invoices once with React and Tailwind CSS, then render them as HTML and PDF.",
5
+ "keywords": [
6
+ "billing",
7
+ "document",
8
+ "html",
9
+ "invoice",
10
+ "invoicing",
11
+ "pdf",
12
+ "react",
13
+ "react-pdf",
14
+ "receipt",
15
+ "renderer",
16
+ "tailwind",
17
+ "tailwindcss"
18
+ ],
19
+ "homepage": "https://react-invoice.swrg.dev",
20
+ "bugs": {
21
+ "url": "https://github.com/swargaraj/react-invoice/issues"
22
+ },
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/swargaraj/react-invoice.git"
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "type": "module",
32
+ "sideEffects": false,
33
+ "main": "./dist/index.cjs",
34
+ "module": "./dist/index.mjs",
35
+ "types": "./dist/index.d.mts",
36
+ "exports": {
37
+ ".": {
38
+ "import": {
39
+ "types": "./dist/index.d.mts",
40
+ "default": "./dist/index.mjs"
41
+ },
42
+ "require": {
43
+ "types": "./dist/index.d.cts",
44
+ "default": "./dist/index.cjs"
45
+ }
46
+ }
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "scripts": {
52
+ "build": "tsdown",
53
+ "dev": "tsdown --watch",
54
+ "typecheck": "tsc --noEmit"
55
+ },
56
+ "dependencies": {
57
+ "@react-pdf/renderer": "^4",
58
+ "cnfast": "^0.0.8",
59
+ "react-pdf-tailwind": "^3"
60
+ },
61
+ "devDependencies": {
62
+ "@types/react": "^19",
63
+ "@types/react-dom": "^19",
64
+ "react": "^19",
65
+ "react-dom": "^19",
66
+ "tsdown": "^0.22.3",
67
+ "typescript": "^6.0.0"
68
+ },
69
+ "peerDependencies": {
70
+ "react": "^18 || ^19",
71
+ "react-dom": "^18 || ^19"
72
+ }
73
+ }