@wavy/react-pdf 0.0.6 → 0.0.8

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,54 +1,12 @@
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
+ 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';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
- import { ComputedStyleProps } from '@wavy/react-ui';
5
- import { SafeOmit } from '@wavy/types';
6
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;
14
- };
15
-
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;
22
- }
23
- declare function Div(props: DivProps): react_jsx_runtime.JSX.Element;
24
-
25
- interface SpanProps extends ComputedStyleProps {
26
- lineLimit?: number;
27
- italic?: boolean;
28
- strikeThrough?: boolean;
29
- underline?: boolean;
30
- text?: string;
31
- ellipsis?: boolean | "native";
32
- }
33
- declare function Span(props: SpanProps): react_jsx_runtime.JSX.Element;
34
-
35
- interface ImgProps extends SafeOmit<ComputedStyleProps, "children"> {
36
- src: string;
37
- }
38
- declare function Img(props: ImgProps): react_jsx_runtime.JSX.Element;
39
-
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[];
49
- }
50
- declare function PDFDocument(props: PDFDocumentProps): react_jsx_runtime.JSX.Element;
51
-
52
10
  type Column<T extends string = string> = {
53
11
  name: T;
54
12
  /**@default 1 */
@@ -76,6 +34,7 @@ declare namespace TableViewProps {
76
34
  width?: string;
77
35
  columnGap?: string;
78
36
  padding?: string;
37
+ contentPadding?: string;
79
38
  entries: Record<T, string>[];
80
39
  children: JSX.Element | [JSX.Element, JSX.Element];
81
40
  }
@@ -85,12 +44,17 @@ declare namespace TableViewProps {
85
44
  padding?: string;
86
45
  /**@default ".25rem" */
87
46
  borderRadius?: string;
47
+ color?: string;
48
+ fontWeight?: string;
49
+ formatColName?: (column: string) => string;
88
50
  }
89
51
  interface BodyProps {
90
52
  /**@default ".5rem" */
91
53
  fontSize?: string;
92
54
  padding?: string;
93
55
  rowGap?: string;
56
+ marginTop?: string;
57
+ marginBottom?: string;
94
58
  styleRow?: (rowIndex: number, entries: Record<string, string>[]) => null | undefined | PDFStyle;
95
59
  styleCell?: (cell: {
96
60
  cellIndex: number;
@@ -189,4 +153,11 @@ interface BasicPDFListItemProps extends BasicViewStylesOptions {
189
153
  }
190
154
  declare function BasicPDFListItem(props: BasicPDFListItemProps): react_jsx_runtime.JSX.Element;
191
155
 
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 };
156
+ declare enum ColorResources {
157
+ paper = "#ffffff",
158
+ onPaper = "#28282B"
159
+ }
160
+ declare const remAsPx: (value: number) => string;
161
+ declare const hexToRgba: (hex: string, alpha?: number) => string;
162
+
163
+ 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,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};
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 h=(n=>(n.paper="#ffffff",n.onPaper="#28282B",n))(h||{}),w=e=>`${e*16}px`,G=e=>/^#([A-Fa-f0-9]{3,4}){1,2}$/.test(e),L=e=>parseInt(e.repeat(2/e.length),16),S=(e,t=1)=>{let n=(m,f)=>m.match(new RegExp(`.{${f}}`,"g")),r=m=>typeof m<"u"?m/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,y]=o.map(L);return `rgba(${s}, ${c}, ${u}, ${r(y)})`};var B=createContext(null);function W(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:e.contentPadding||w(.25)},children:jsx(View,{style:{width:e.width||"100%",padding:e.padding},children:e.children})})}function j(e){let t=useContext(B);return jsx(View,{style:{width:"100%",flexDirection:"row",fontWeight:e.fontWeight,color:e.color||S("#28282B",.5),backgroundColor:S("#28282B",.1),fontSize:e.fontSize||".55rem",borderRadius:e.borderRadius??".25rem",padding:e.padding??t.padding,columnGap:t.columnGap},children:t.columns.map(n=>jsx(Text,{style:{width:n.width,textAlign:n.textAlign,overflow:"hidden"},children:e.formatColName?.(n.name)||camelCaseToLetter(n.name)},n.name))})}function _(e){let t=useContext(B);return jsx(View,{style:{width:"100%",padding:e.padding||t.padding,rowGap:e.rowGap??t.rowGap,marginTop:e.marginTop,marginBottom:e.marginBottom},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:W,Header:j,Body:_};var g=e=>{let{fullWidth:t,fullHeight:n,height:r,width:i,backgroundColor:o,color:s,fontWeight:c,fontSize:u,gap:y,halfFade:m,quarterFade:f,opacity:I,flex:z,corners:R,padding:A}=e,x="auto";return {width:t?"100%":i||x,height:n?"100%":r||x,backgroundColor:o,color:s,fontWeight:c,fontSize:u,gap:y,flex:z,padding:A,borderRadius:R,opacity:m?.5:f?.25:I}};var H=e=>{let{underline:t,lineThrough:n,upperFirst:r,uppercase:i,lowercase:o,caps:s,bold:c}=e;return {...g(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"}},D=H;var q=D;function P(e){let t=()=>e.text||e.children;return jsx(Text,{style:[q({...e}),e.style],children:jsx(t,{})})}var Y=e=>{let{row:t,stretch:n,alignCenter:r,alignEnd:i,justifyCenter:o,justifySpaceBetween:s,justifySpaceEvenly:c,justifyEnd:u}=e;return {...g(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"}},O=Y;var J=O;function C(e){let t=Array.isArray(e.style)?e.style:[e.style];return jsx(View,{style:[J({...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 K=V;function je(e){return jsx(Image,{src:{uri:e.src,method:"GET",headers:{"Cache-Control":"no-cache"}},style:[K(e),e.style]})}function Xe(e){return jsxs(C,{...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,C as BasicView,h as ColorResources,se as TableView,S as hexToRgba,w as remAsPx};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavy/react-pdf",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
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
  },