@wavy/react-pdf 0.0.5 → 0.0.7

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 CHANGED
@@ -1,52 +1,157 @@
1
+ import { ViewProps, Styles } from '@react-pdf/renderer';
2
+ export { BlobProvider, BlobProviderProps, Document, DocumentProps, 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
- import { ComputedStyleProps } from '@wavy/react-ui';
3
- 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';
4
+ import { JSX, PropsWithChildren } from 'react';
7
5
 
8
6
  type PDFStyle = ViewProps["style"] extends object[]
9
7
  ? never
10
8
  : ViewProps["style"];
11
9
 
12
- declare function usePDFDocument(): {
13
- renderedAsPdf: boolean;
10
+ type Column<T extends string = string> = {
11
+ name: T;
12
+ /**@default 1 */
13
+ opacity?: number;
14
+ width?: string;
15
+ textAlign?: "left" | "center" | "right";
16
+ /**@default "-" */
17
+ placeholder?: string;
14
18
  };
19
+ declare function Root<T extends string>(props: TableViewProps.RootProps<T>): react_jsx_runtime.JSX.Element;
20
+ declare function Header(props: TableViewProps.HeaderProps): react_jsx_runtime.JSX.Element;
21
+ declare function Body(props: TableViewProps.BodyProps): react_jsx_runtime.JSX.Element;
22
+ declare const TableView: {
23
+ Root: typeof Root;
24
+ Header: typeof Header;
25
+ Body: typeof Body;
26
+ };
27
+ declare namespace TableViewProps {
28
+ interface RootProps<T extends string> {
29
+ columns: (T | Column<T>)[];
30
+ /**@default ".25rem" */
31
+ gap?: string;
32
+ rowGap?: string;
33
+ /**@default "100%" */
34
+ width?: string;
35
+ columnGap?: string;
36
+ padding?: string;
37
+ entries: Record<T, string>[];
38
+ children: JSX.Element | [JSX.Element, JSX.Element];
39
+ }
40
+ interface HeaderProps {
41
+ /**@default ".55rem" */
42
+ fontSize?: string;
43
+ padding?: string;
44
+ /**@default ".25rem" */
45
+ borderRadius?: string;
46
+ }
47
+ interface BodyProps {
48
+ /**@default ".5rem" */
49
+ fontSize?: string;
50
+ padding?: string;
51
+ rowGap?: string;
52
+ styleRow?: (rowIndex: number, entries: Record<string, string>[]) => null | undefined | PDFStyle;
53
+ styleCell?: (cell: {
54
+ cellIndex: number;
55
+ rowIndex: number;
56
+ columnName: string;
57
+ siblingData: {
58
+ previous?: string | null | undefined;
59
+ next?: string | null | undefined;
60
+ };
61
+ data: string | null;
62
+ }) => null | undefined | void | PDFStyle;
63
+ }
64
+ }
15
65
 
16
- interface DivProps extends ComputedStyleProps {
17
- /**@default "flex" */
18
- display?: React.CSSProperties["display"];
19
- /**Sets the flexDirection to `row`
20
- * @default false */
21
- row?: boolean;
66
+ type PDFBuilderStyle = Styles[""];
67
+ interface BasePDFBuilderStyleOptions {
68
+ fullWidth?: boolean;
69
+ fullHeight?: boolean;
70
+ height?: string | number;
71
+ width?: string | number;
72
+ backgroundColor?: string;
73
+ padding?: string | number;
74
+ color?: string;
75
+ fontWeight?: PDFBuilderStyle["fontWeight"];
76
+ fontSize?: string | number;
77
+ gap?: string | number;
78
+ opacity?: number;
79
+ halfFade?: boolean;
80
+ flex?: string;
81
+ corners?: string | number;
82
+ quarterFade?: boolean;
22
83
  }
23
- declare function Div(props: DivProps): react_jsx_runtime.JSX.Element;
24
84
 
25
- interface SpanProps extends ComputedStyleProps {
26
- lineLimit?: number;
27
- italic?: boolean;
28
- strikeThrough?: boolean;
85
+ interface BasicTextStylesOptions extends BasePDFBuilderStyleOptions {
29
86
  underline?: boolean;
87
+ lineThrough?: boolean;
88
+ bold?: boolean;
89
+ upperFirst?: boolean;
90
+ uppercase?: boolean;
91
+ lowercase?: boolean;
92
+ caps?: boolean;
93
+ }
94
+
95
+ interface BasicTextProps extends BasicTextStylesOptions {
30
96
  text?: string;
31
- ellipsis?: boolean | "native";
97
+ style?: PDFBuilderStyle;
98
+ }
99
+ declare function BasicText(props: PropsWithChildren<BasicTextProps>): react_jsx_runtime.JSX.Element;
100
+
101
+ interface BasicViewStylesOptions extends BasePDFBuilderStyleOptions {
102
+ row?: boolean;
103
+ stretch?: boolean;
104
+ alignCenter?: boolean;
105
+ alignEnd?: boolean;
106
+ justifySpaceBetween?: boolean;
107
+ justifySpaceEvenly?: boolean;
108
+ justifyCenter?: boolean;
109
+ justifyEnd?: boolean;
110
+ }
111
+
112
+ interface BasicViewProps extends BasicViewStylesOptions {
113
+ style?: PDFBuilderStyle | PDFBuilderStyle[];
32
114
  }
33
- declare function Span(props: SpanProps): react_jsx_runtime.JSX.Element;
115
+ declare function BasicView(props: PropsWithChildren<BasicViewProps>): react_jsx_runtime.JSX.Element;
34
116
 
35
- interface ImgProps extends SafeOmit<ComputedStyleProps, "children"> {
117
+ interface BasicImageStylesOptions {
118
+ circle?: boolean;
119
+ corners?: string;
120
+ size?: string | number;
121
+ padding?: string | number;
122
+ backgroundColor?: string;
123
+ objectFit?: PDFBuilderStyle["objectFit"];
124
+ }
125
+
126
+ interface BasicImageProps extends BasicImageStylesOptions {
36
127
  src: string;
128
+ style?: PDFBuilderStyle;
129
+ }
130
+ declare function BasicImage(props: BasicImageProps): react_jsx_runtime.JSX.Element;
131
+
132
+ interface BasicPDFListItemProps extends BasicViewStylesOptions {
133
+ primary: string;
134
+ secondary?: string;
135
+ primaryFontSize?: string | number;
136
+ secondaryFontSize?: string | number;
137
+ slotProps?: {
138
+ primary?: {
139
+ quickStyle?: BasicTextStylesOptions;
140
+ style?: PDFBuilderStyle;
141
+ };
142
+ secondary?: {
143
+ quickStyle?: BasicTextStylesOptions;
144
+ style?: PDFBuilderStyle;
145
+ };
146
+ };
37
147
  }
38
- declare function Img(props: ImgProps): react_jsx_runtime.JSX.Element;
148
+ declare function BasicPDFListItem(props: BasicPDFListItemProps): react_jsx_runtime.JSX.Element;
39
149
 
40
- /**
41
- * This component represent the PDF document itself. It must be the root of your tree element structure,
42
- * and under no circumstances should it be used as children of another react-pdf component.
43
- * In addition, it should only have childs of type .
44
- */
45
- interface PDFDocumentProps extends DocumentProps {
46
- /**@default false */
47
- asPdf?: boolean;
48
- children: JSX.Element | JSX.Element[];
150
+ declare enum ColorResources {
151
+ paper = "#ffffff",
152
+ onPaper = "#28282B"
49
153
  }
50
- declare function PDFDocument(props: PDFDocumentProps): react_jsx_runtime.JSX.Element;
154
+ declare const remAsPx: (value: number) => string;
155
+ declare const hexToRgba: (hex: string, alpha?: number) => string;
51
156
 
52
- export { Div, type DivProps, Img, type ImgProps, PDFDocument, type PDFDocumentProps, type PDFStyle, Span, usePDFDocument };
157
+ export { BasicImage, type BasicImageProps, BasicPDFListItem, type BasicPDFListItemProps, BasicText, type BasicTextProps, BasicView, type BasicViewProps, ColorResources, type PDFStyle, TableView, TableViewProps, hexToRgba, remAsPx };
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 o=createContext({asPdf:false});function G(){return {renderedAsPdf:useContext(o).asPdf}}function j(e){let{style:n}=useComputedStyle("div",e,{inject:()=>({display:e.style?.display||e.display||"flex",flexDirection:e.style?.flexDirection||(e.row?"row":"column")})}),{asPdf:r}=useContext(o);return r?jsx(View,{style:n,children:e.children}):jsx("div",{style:n,children:e.children})}function M(e){let n=e.text||e.children,{style:r}=useComputedStyle("span",{...e,children:n},{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:c}=useContext(o);return c?jsx(Text,{style:r,children:n}):jsx("span",{style:r,children:n})}function oe(e){let{asPdf:n}=useContext(o),{style:r}=useComputedStyle("img",e);return n?jsx(Image,{style:r,src:e.src}):jsx("img",{style:r,src:e.src})}function ce(e){let n=e.asPdf??false;return jsx(o.Provider,{value:{asPdf:n},children:n?jsx(Document,{...e}):jsx(Fragment,{children:e.children})})}createContext(null);export{j as Div,oe as Img,ce as PDFDocument,M as Span,G as usePDFDocument};
1
+ import {View,Text,Image}from'@react-pdf/renderer';export{BlobProvider,Document,Image,PDFViewer,Page,Text,View,pdf,usePDF}from'@react-pdf/renderer';import {camelCaseToLetter}from'@wavy/fn';import {createContext,useContext}from'react';import {jsx,jsxs}from'react/jsx-runtime';var w=(n=>(n.paper="#ffffff",n.onPaper="#28282B",n))(w||{}),Z=e=>`${e*16}px`,G=e=>/^#([A-Fa-f0-9]{3,4}){1,2}$/.test(e),A=e=>parseInt(e.repeat(2/e.length),16),S=(e,t=1)=>{let n=(p,f)=>p.match(new RegExp(`.{${f}}`,"g")),r=p=>typeof p<"u"?p/255:typeof t!="number"||t<0||t>1?1:t;if(!G(e))throw new Error(`Invalid HEX: ${e}`);let i=Math.floor((e.length-1)/3),o=n(e.slice(1),i),[s,c,u,g]=o.map(A);return `rgba(${s}, ${c}, ${u}, ${r(g)})`};var B=createContext(null);function v(e){let t=()=>e.columns.map(r=>{let i=typeof r=="object"?r:{},o={textAlign:"left",width:"100%"};return typeof r=="string"?i={name:r,...o}:["textAlign","width"].forEach(s=>{s in i&&i[s]||(i[s]=o[s]);}),i}),n=e.gap??".25rem";return jsx(B.Provider,{value:{entries:e.entries,columns:t(),rowGap:e.rowGap??n,columnGap:e.columnGap??n,padding:`${.25*16}px`},children:jsx(View,{style:{width:e.width||"100%",padding:e.padding},children:e.children})})}function W(e){let t=useContext(B);return jsx(View,{style:{width:"100%",flexDirection:"row",color:S("#28282B",.5),backgroundColor:S("#28282B",.1),fontSize:e.fontSize||".55rem",borderRadius:e.borderRadius??".25rem",padding:t.padding??e.padding,columnGap:t.columnGap},children:t.columns.map(n=>jsx(Text,{style:{width:n.width,textAlign:n.textAlign,overflow:"hidden"},children:camelCaseToLetter(n.name)},n.name))})}function j(e){let t=useContext(B);return jsx(View,{style:{width:"100%",padding:e.padding||t.padding,rowGap:e.rowGap??t.rowGap},children:t.entries.map((n,r)=>jsx(View,{style:{flexDirection:"row",fontSize:e.fontSize||".5rem",...e.styleRow?.(r,t.entries)||{},alignItems:"center",width:"100%",overflow:"hidden",columnGap:t.columnGap},children:t.columns.map((i,o)=>jsx(Text,{style:{textAlign:i.textAlign,opacity:i.opacity??1,...e.styleCell?.({cellIndex:t.columns.length*r+o,rowIndex:r,columnName:i.name,siblingData:{previous:n?.[t.columns[o-1]?.name||""]||null,next:n?.[t.columns[o+1]?.name||""]||null},data:n?.[i.name]})||{},width:i.width},children:n?.[i.name]||i.placeholder||"-"},i.name+o))}))})}var se={Root:v,Header:W,Body:j};var y=e=>{let{fullWidth:t,fullHeight:n,height:r,width:i,backgroundColor:o,color:s,fontWeight:c,fontSize:u,gap:g,halfFade:p,quarterFade:f,opacity:E,flex:I,corners:z,padding:R}=e,x="auto";return {width:t?"100%":i||x,height:n?"100%":r||x,backgroundColor:o,color:s,fontWeight:c,fontSize:u,gap:g,flex:I,padding:R,borderRadius:z,opacity:p?.5:f?.25:E}};var _=e=>{let{underline:t,lineThrough:n,upperFirst:r,uppercase:i,lowercase:o,caps:s,bold:c}=e;return {...y(e),fontWeight:c&&"bold",textDecoration:t&&n?"underline line-through":t?"underline":n?"line-through":"none",textTransform:r?"upperfirst":i?"uppercase":o?"lowercase":s?"capitalize":"none"}},F=_;var H=F;function P(e){let t=()=>e.text||e.children;return jsx(Text,{style:[H({...e}),e.style],children:jsx(t,{})})}var q=e=>{let{row:t,stretch:n,alignCenter:r,alignEnd:i,justifyCenter:o,justifySpaceBetween:s,justifySpaceEvenly:c,justifyEnd:u}=e;return {...y(e),flexDirection:t?"row":"column",alignItems:n?"stretch":r?"center":i?"flex-end":"flex-start",justifyContent:o?"center":u?"flex-end":s?"space-between":c?"space-evenly":"flex-start"}},T=q;var X=T;function O(e){let t=Array.isArray(e.style)?e.style:[e.style];return jsx(View,{style:[X({...e}),...t],children:e.children})}var U=e=>{let{size:t,padding:n,backgroundColor:r,objectFit:i,circle:o,corners:s}=e;return {height:t,width:t,borderRadius:o?t:s,padding:n||(o?1:0),backgroundColor:r,objectFit:i}},V=U;var M=V;function je(e){return jsx(Image,{src:{uri:e.src,method:"GET",headers:{"Cache-Control":"no-cache"}},style:[M(e),e.style]})}function Xe(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{je as BasicImage,Xe as BasicPDFListItem,P as BasicText,O as BasicView,w as ColorResources,se as TableView,S as hexToRgba,Z as remAsPx};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavy/react-pdf",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "",
5
5
  "main": "dist/main.js",
6
6
  "scripts": {
@@ -12,12 +12,9 @@
12
12
  "license": "MIT",
13
13
  "type": "module",
14
14
  "devDependencies": {
15
- "@types/react": "^19.2.6",
16
- "@types/react-dom": "^19.2.3",
17
- "@wavy/react-ui": "^0.0.6",
15
+ "@types/react": "^19.2.7",
18
16
  "@wavy/types": "^0.0.51",
19
- "react": "^19.2.0",
20
- "react-dom": "^19.2.0",
17
+ "react": "^19.2.1",
21
18
  "tsup": "^8.5.1",
22
19
  "typescript": "^5.9.3"
23
20
  },