@wavy/react-pdf 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.d.ts +144 -4
- package/dist/main.js +1 -1
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { ViewProps, DocumentProps, Styles } from '@react-pdf/renderer';
|
|
2
|
+
export { BlobProvider, Image, ImageProps, PDFViewer, PDFViewerProps, Page, PageProps, Text, TextProps, View, ViewProps, pdf, usePDF } from '@react-pdf/renderer';
|
|
1
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
4
|
import { ComputedStyleProps } from '@wavy/react-ui';
|
|
3
5
|
import { SafeOmit } from '@wavy/types';
|
|
4
|
-
import { JSX } from 'react';
|
|
5
|
-
import { DocumentProps } from '@react-pdf/renderer';
|
|
6
|
-
export { BlobProvider, Image, ImageProps, PDFViewer, PDFViewerProps, Page, PageProps, Text, TextProps, View, ViewProps, pdf, usePDF } from '@react-pdf/renderer';
|
|
6
|
+
import { JSX, PropsWithChildren } from 'react';
|
|
7
7
|
|
|
8
8
|
type PDFStyle = ViewProps["style"] extends object[]
|
|
9
9
|
? never
|
|
@@ -49,4 +49,144 @@ interface PDFDocumentProps extends DocumentProps {
|
|
|
49
49
|
}
|
|
50
50
|
declare function PDFDocument(props: PDFDocumentProps): react_jsx_runtime.JSX.Element;
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
type Column<T extends string = string> = {
|
|
53
|
+
name: T;
|
|
54
|
+
/**@default 1 */
|
|
55
|
+
opacity?: number;
|
|
56
|
+
width?: string;
|
|
57
|
+
textAlign?: "left" | "center" | "right";
|
|
58
|
+
/**@default "-" */
|
|
59
|
+
placeholder?: string;
|
|
60
|
+
};
|
|
61
|
+
declare function Root<T extends string>(props: TableViewProps.RootProps<T>): react_jsx_runtime.JSX.Element;
|
|
62
|
+
declare function Header(props: TableViewProps.HeaderProps): react_jsx_runtime.JSX.Element;
|
|
63
|
+
declare function Body(props: TableViewProps.BodyProps): react_jsx_runtime.JSX.Element;
|
|
64
|
+
declare const TableView: {
|
|
65
|
+
Root: typeof Root;
|
|
66
|
+
Header: typeof Header;
|
|
67
|
+
Body: typeof Body;
|
|
68
|
+
};
|
|
69
|
+
declare namespace TableViewProps {
|
|
70
|
+
interface RootProps<T extends string> {
|
|
71
|
+
columns: (T | Column<T>)[];
|
|
72
|
+
/**@default ".25rem" */
|
|
73
|
+
gap?: string;
|
|
74
|
+
rowGap?: string;
|
|
75
|
+
/**@default "100%" */
|
|
76
|
+
width?: string;
|
|
77
|
+
columnGap?: string;
|
|
78
|
+
padding?: string;
|
|
79
|
+
entries: Record<T, string>[];
|
|
80
|
+
children: JSX.Element | [JSX.Element, JSX.Element];
|
|
81
|
+
}
|
|
82
|
+
interface HeaderProps {
|
|
83
|
+
/**@default ".55rem" */
|
|
84
|
+
fontSize?: string;
|
|
85
|
+
padding?: string;
|
|
86
|
+
/**@default ".25rem" */
|
|
87
|
+
borderRadius?: string;
|
|
88
|
+
}
|
|
89
|
+
interface BodyProps {
|
|
90
|
+
/**@default ".5rem" */
|
|
91
|
+
fontSize?: string;
|
|
92
|
+
padding?: string;
|
|
93
|
+
rowGap?: string;
|
|
94
|
+
styleRow?: (rowIndex: number, entries: Record<string, string>[]) => null | undefined | PDFStyle;
|
|
95
|
+
styleCell?: (cell: {
|
|
96
|
+
cellIndex: number;
|
|
97
|
+
rowIndex: number;
|
|
98
|
+
columnName: string;
|
|
99
|
+
siblingData: {
|
|
100
|
+
previous?: string | null | undefined;
|
|
101
|
+
next?: string | null | undefined;
|
|
102
|
+
};
|
|
103
|
+
data: string | null;
|
|
104
|
+
}) => null | undefined | void | PDFStyle;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
type PDFBuilderStyle = Styles[""];
|
|
109
|
+
interface BasePDFBuilderStyleOptions {
|
|
110
|
+
fullWidth?: boolean;
|
|
111
|
+
fullHeight?: boolean;
|
|
112
|
+
height?: string | number;
|
|
113
|
+
width?: string | number;
|
|
114
|
+
backgroundColor?: string;
|
|
115
|
+
padding?: string | number;
|
|
116
|
+
color?: string;
|
|
117
|
+
fontWeight?: PDFBuilderStyle["fontWeight"];
|
|
118
|
+
fontSize?: string | number;
|
|
119
|
+
gap?: string | number;
|
|
120
|
+
opacity?: number;
|
|
121
|
+
halfFade?: boolean;
|
|
122
|
+
flex?: string;
|
|
123
|
+
corners?: string | number;
|
|
124
|
+
quarterFade?: boolean;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
interface BasicTextStylesOptions extends BasePDFBuilderStyleOptions {
|
|
128
|
+
underline?: boolean;
|
|
129
|
+
lineThrough?: boolean;
|
|
130
|
+
bold?: boolean;
|
|
131
|
+
upperFirst?: boolean;
|
|
132
|
+
uppercase?: boolean;
|
|
133
|
+
lowercase?: boolean;
|
|
134
|
+
caps?: boolean;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interface BasicTextProps extends BasicTextStylesOptions {
|
|
138
|
+
text?: string;
|
|
139
|
+
style?: PDFBuilderStyle;
|
|
140
|
+
}
|
|
141
|
+
declare function BasicText(props: PropsWithChildren<BasicTextProps>): react_jsx_runtime.JSX.Element;
|
|
142
|
+
|
|
143
|
+
interface BasicViewStylesOptions extends BasePDFBuilderStyleOptions {
|
|
144
|
+
row?: boolean;
|
|
145
|
+
stretch?: boolean;
|
|
146
|
+
alignCenter?: boolean;
|
|
147
|
+
alignEnd?: boolean;
|
|
148
|
+
justifySpaceBetween?: boolean;
|
|
149
|
+
justifySpaceEvenly?: boolean;
|
|
150
|
+
justifyCenter?: boolean;
|
|
151
|
+
justifyEnd?: boolean;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
interface BasicViewProps extends BasicViewStylesOptions {
|
|
155
|
+
style?: PDFBuilderStyle | PDFBuilderStyle[];
|
|
156
|
+
}
|
|
157
|
+
declare function BasicView(props: PropsWithChildren<BasicViewProps>): react_jsx_runtime.JSX.Element;
|
|
158
|
+
|
|
159
|
+
interface BasicImageStylesOptions {
|
|
160
|
+
circle?: boolean;
|
|
161
|
+
corners?: string;
|
|
162
|
+
size?: string | number;
|
|
163
|
+
padding?: string | number;
|
|
164
|
+
backgroundColor?: string;
|
|
165
|
+
objectFit?: PDFBuilderStyle["objectFit"];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
interface BasicImageProps extends BasicImageStylesOptions {
|
|
169
|
+
src: string;
|
|
170
|
+
style?: PDFBuilderStyle;
|
|
171
|
+
}
|
|
172
|
+
declare function BasicImage(props: BasicImageProps): react_jsx_runtime.JSX.Element;
|
|
173
|
+
|
|
174
|
+
interface BasicPDFListItemProps extends BasicViewStylesOptions {
|
|
175
|
+
primary: string;
|
|
176
|
+
secondary?: string;
|
|
177
|
+
primaryFontSize?: string | number;
|
|
178
|
+
secondaryFontSize?: string | number;
|
|
179
|
+
slotProps?: {
|
|
180
|
+
primary?: {
|
|
181
|
+
quickStyle?: BasicTextStylesOptions;
|
|
182
|
+
style?: PDFBuilderStyle;
|
|
183
|
+
};
|
|
184
|
+
secondary?: {
|
|
185
|
+
quickStyle?: BasicTextStylesOptions;
|
|
186
|
+
style?: PDFBuilderStyle;
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
declare function BasicPDFListItem(props: BasicPDFListItemProps): react_jsx_runtime.JSX.Element;
|
|
191
|
+
|
|
192
|
+
export { BasicImage, type BasicImageProps, BasicPDFListItem, type BasicPDFListItemProps, BasicText, type BasicTextProps, BasicView, type BasicViewProps, Div, type DivProps, Img, type ImgProps, PDFDocument, type PDFDocumentProps, type PDFStyle, Span, TableView, TableViewProps, usePDFDocument };
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {createContext,useContext}from'react';import {View,Text,Image,Document}from'@react-pdf/renderer';export{BlobProvider,Image,PDFViewer,Page,Text,View,pdf,usePDF}from'@react-pdf/renderer';import {useComputedStyle,restrictLineCount,nativeEllipsis,ellipsis}from'@wavy/react-ui';import {jsx,Fragment}from'react/jsx-runtime';import'@wavy/fn';var
|
|
1
|
+
import {createContext,useContext}from'react';import {View,Text,Image,Document}from'@react-pdf/renderer';export{BlobProvider,Image,PDFViewer,Page,Text,View,pdf,usePDF}from'@react-pdf/renderer';import {useComputedStyle,restrictLineCount,nativeEllipsis,ellipsis,remAsPx,resolveBasicColor}from'@wavy/react-ui';import {jsx,Fragment,jsxs}from'react/jsx-runtime';import {camelCaseToLetter}from'@wavy/fn';var c=createContext({asPdf:false});function we(){return {renderedAsPdf:useContext(c).asPdf}}function Ee(e){let{style:t}=useComputedStyle("div",e,{inject:()=>({display:e.style?.display||e.display||"flex",flexDirection:e.style?.flexDirection||(e.row?"row":"column")})}),{asPdf:i}=useContext(c);return i?jsx(View,{style:t,children:e.children}):jsx("div",{style:t,children:e.children})}function We(e){let t=e.text||e.children,{style:i}=useComputedStyle("span",{...e,children:t},{inject:()=>({textDecoration:e.style?.textDecoration||[e.underline?"underline":"",e.strikeThrough?"line-through":""].join(" "),fontStyle:e.style?.fontStyle||e.italic?"italic":void 0,...e.ellipsis==="native"?nativeEllipsis():e.ellipsis?ellipsis():{},...e.lineLimit?restrictLineCount(e.lineLimit):{}})}),{asPdf:o}=useContext(c);return o?jsx(Text,{style:i,children:t}):jsx("span",{style:i,children:t})}function Ue(e){let{asPdf:t}=useContext(c),{style:i}=useComputedStyle("img",e);return t?jsx(Image,{style:i,src:e.src}):jsx("img",{style:i,src:e.src})}function $e(e){let t=e.asPdf??false;return jsx(c.Provider,{value:{asPdf:t},children:t?jsx(Document,{...e}):jsx(Fragment,{children:e.children})})}var g=createContext(null);function ne(e){let t=()=>e.columns.map(o=>{let n=typeof o=="object"?o:{},r={textAlign:"left",width:"100%"};return typeof o=="string"?n={name:o,...r}:["textAlign","width"].forEach(a=>{a in n&&n[a]||(n[a]=r[a]);}),n}),i=e.gap??".25rem";return jsx(g.Provider,{value:{entries:e.entries,columns:t(),rowGap:e.rowGap??i,columnGap:e.columnGap??i,padding:remAsPx(.25)},children:jsx(View,{style:{width:e.width||"100%",padding:e.padding},children:e.children})})}function oe(e){let t=useContext(g);return jsx(View,{style:{width:"100%",flexDirection:"row",color:resolveBasicColor("onPaper[0.5]"),backgroundColor:resolveBasicColor("onPaper[0.1]"),fontSize:e.fontSize||".55rem",borderRadius:e.borderRadius??".25rem",padding:t.padding??e.padding,columnGap:t.columnGap},children:t.columns.map(i=>jsx(Text,{style:{width:i.width,textAlign:i.textAlign,overflow:"hidden"},children:camelCaseToLetter(i.name)},i.name))})}function re(e){let t=useContext(g);return jsx(View,{style:{width:"100%",padding:e.padding||t.padding,rowGap:e.rowGap??t.rowGap},children:t.entries.map((i,o)=>jsx(View,{style:{flexDirection:"row",fontSize:e.fontSize||".5rem",...e.styleRow?.(o,t.entries)||{},alignItems:"center",width:"100%",overflow:"hidden",columnGap:t.columnGap},children:t.columns.map((n,r)=>jsx(Text,{style:{textAlign:n.textAlign,opacity:n.opacity??1,...e.styleCell?.({cellIndex:t.columns.length*o+r,rowIndex:o,columnName:n.name,siblingData:{previous:i?.[t.columns[r-1]?.name||""]||null,next:i?.[t.columns[r+1]?.name||""]||null},data:i?.[n.name]})||{},width:n.width},children:i?.[n.name]||n.placeholder||"-"},n.name+r))}))})}var lt={Root:ne,Header:oe,Body:re};var p=e=>{let{fullWidth:t,fullHeight:i,height:o,width:n,backgroundColor:r,color:a,fontWeight:m,fontSize:y,gap:I,halfFade:v,quarterFade:L,opacity:z,flex:G,corners:R,padding:A}=e,S="auto";return {width:t?"100%":n||S,height:i?"100%":o||S,backgroundColor:r,color:a,fontWeight:m,fontSize:y,gap:I,flex:G,padding:A,borderRadius:R,opacity:v?.5:L?.25:z}};var se=e=>{let{underline:t,lineThrough:i,upperFirst:o,uppercase:n,lowercase:r,caps:a,bold:m}=e;return {...p(e),fontWeight:m&&"bold",textDecoration:t&&i?"underline line-through":t?"underline":i?"line-through":"none",textTransform:o?"upperfirst":n?"uppercase":r?"lowercase":a?"capitalize":"none"}},F=se;var ae=F;function P(e){let t=()=>e.text||e.children;return jsx(Text,{style:[ae({...e}),e.style],children:jsx(t,{})})}var ce=e=>{let{row:t,stretch:i,alignCenter:o,alignEnd:n,justifyCenter:r,justifySpaceBetween:a,justifySpaceEvenly:m,justifyEnd:y}=e;return {...p(e),flexDirection:t?"row":"column",alignItems:i?"stretch":o?"center":n?"flex-end":"flex-start",justifyContent:r?"center":y?"flex-end":a?"space-between":m?"space-evenly":"flex-start"}},T=ce;var me=T;function O(e){let t=Array.isArray(e.style)?e.style:[e.style];return jsx(View,{style:[me({...e}),...t],children:e.children})}var pe=e=>{let{size:t,padding:i,backgroundColor:o,objectFit:n,circle:r,corners:a}=e;return {height:t,width:t,borderRadius:r?t:a,padding:i||(r?1:0),backgroundColor:o,objectFit:n}},V=pe;var fe=V;function jt(e){return jsx(Image,{src:{uri:e.src,method:"GET",headers:{"Cache-Control":"no-cache"}},style:[fe(e),e.style]})}function Ut(e){return jsxs(O,{...e,children:[jsx(P,{...e.slotProps?.primary?.quickStyle,fontSize:e.primaryFontSize,text:e.primary,style:e.slotProps?.primary?.style}),e.secondary&&jsx(P,{...e.slotProps?.secondary?.quickStyle,halfFade:true,fontSize:e.secondaryFontSize||12,text:e.secondary,style:e.slotProps?.secondary?.style})]})}export{jt as BasicImage,Ut as BasicPDFListItem,P as BasicText,O as BasicView,Ee as Div,Ue as Img,$e as PDFDocument,We as Span,lt as TableView,we as usePDFDocument};
|