react-vector-pdf 0.3.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 +254 -0
- package/dist/components/PdfBox.d.ts +10 -0
- package/dist/components/PdfImage.d.ts +12 -0
- package/dist/components/PdfList.d.ts +11 -0
- package/dist/components/PdfProvider.d.ts +22 -0
- package/dist/components/PdfTable.d.ts +33 -0
- package/dist/components/PdfText.d.ts +10 -0
- package/dist/components/PdfView.d.ts +8 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/core/PdfRenderer.d.ts +82 -0
- package/dist/core/types.d.ts +80 -0
- package/dist/core/utils.d.ts +14 -0
- package/dist/demo/CodeBlock.d.ts +6 -0
- package/dist/demo/DemoApp.d.ts +2 -0
- package/dist/demo/DemoPdfDocument.d.ts +30 -0
- package/dist/index.d.ts +4 -0
- package/dist/main.d.ts +0 -0
- package/dist/react-vector-pdf.es.js +901 -0
- package/dist/react-vector-pdf.umd.js +6 -0
- package/package.json +63 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
(function(H,C){typeof exports=="object"&&typeof module<"u"?C(exports,require("react"),require("jspdf")):typeof define=="function"&&define.amd?define(["exports","react","jspdf"],C):(H=typeof globalThis<"u"?globalThis:H||self,C(H.ReactVectorPdf={},H.React,H.jsPDF))})(this,(function(H,C,at){"use strict";var J={exports:{}},V={};var et;function ft(){if(et)return V;et=1;var i=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function r(n,o,s){var f=null;if(s!==void 0&&(f=""+s),o.key!==void 0&&(f=""+o.key),"key"in o){s={};for(var l in o)l!=="key"&&(s[l]=o[l])}else s=o;return o=s.ref,{$$typeof:i,type:n,key:f,ref:o!==void 0?o:null,props:s}}return V.Fragment=t,V.jsx=r,V.jsxs=r,V}var G={};var rt;function ct(){return rt||(rt=1,process.env.NODE_ENV!=="production"&&(function(){function i(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===R?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case u:return"Fragment";case X:return"Profiler";case A:return"StrictMode";case K:return"Suspense";case m:return"SuspenseList";case W:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case S:return"Portal";case U:return e.displayName||"Context";case q:return(e._context.displayName||"Context")+".Consumer";case N:var c=e.render;return e=e.displayName,e||(e=c.displayName||c.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case v:return c=e.displayName||null,c!==null?c:i(e.type)||"Memo";case _:c=e._payload,e=e._init;try{return i(e(c))}catch{}}return null}function t(e){return""+e}function r(e){try{t(e);var c=!1}catch{c=!0}if(c){c=console;var d=c.error,P=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return d.call(c,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",P),t(e)}}function n(e){if(e===u)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===_)return"<...>";try{var c=i(e);return c?"<"+c+">":"<...>"}catch{return"<...>"}}function o(){var e=p.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function f(e){if(z.call(e,"key")){var c=Object.getOwnPropertyDescriptor(e,"key").get;if(c&&c.isReactWarning)return!1}return e.key!==void 0}function l(e,c){function d(){E||(E=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",c))}d.isReactWarning=!0,Object.defineProperty(e,"key",{get:d,configurable:!0})}function g(){var e=i(this.type);return b[e]||(b[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function T(e,c,d,P,I,y){var k=d.ref;return e={$$typeof:j,type:e,key:c,props:d,_owner:P},(k!==void 0?k:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:g}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:I}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:y}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function a(e,c,d,P,I,y){var k=c.children;if(k!==void 0)if(P)if(Y(k)){for(P=0;P<k.length;P++)x(k[P]);Object.freeze&&Object.freeze(k)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else x(k);if(z.call(c,"key")){k=i(e);var M=Object.keys(c).filter(function(xt){return xt!=="key"});P=0<M.length?"{key: someKey, "+M.join(": ..., ")+": ...}":"{key: someKey}",O[k+P]||(M=0<M.length?"{"+M.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
|
+
let props = %s;
|
|
3
|
+
<%s {...props} />
|
|
4
|
+
React keys must be passed directly to JSX without using spread:
|
|
5
|
+
let props = %s;
|
|
6
|
+
<%s key={someKey} {...props} />`,P,k,M,k),O[k+P]=!0)}if(k=null,d!==void 0&&(r(d),k=""+d),f(c)&&(r(c.key),k=""+c.key),"key"in c){d={};for(var tt in c)tt!=="key"&&(d[tt]=c[tt])}else d=c;return k&&l(d,typeof e=="function"?e.displayName||e.name||"Unknown":e),T(e,k,d,o(),I,y)}function x(e){h(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===_&&(e._payload.status==="fulfilled"?h(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function h(e){return typeof e=="object"&&e!==null&&e.$$typeof===j}var D=C,j=Symbol.for("react.transitional.element"),S=Symbol.for("react.portal"),u=Symbol.for("react.fragment"),A=Symbol.for("react.strict_mode"),X=Symbol.for("react.profiler"),q=Symbol.for("react.consumer"),U=Symbol.for("react.context"),N=Symbol.for("react.forward_ref"),K=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),v=Symbol.for("react.memo"),_=Symbol.for("react.lazy"),W=Symbol.for("react.activity"),R=Symbol.for("react.client.reference"),p=D.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,z=Object.prototype.hasOwnProperty,Y=Array.isArray,L=console.createTask?console.createTask:function(){return null};D={react_stack_bottom_frame:function(e){return e()}};var E,b={},F=D.react_stack_bottom_frame.bind(D,s)(),w=L(n(s)),O={};G.Fragment=u,G.jsx=function(e,c,d){var P=1e4>p.recentlyCreatedOwnerStacks++;return a(e,c,d,!1,P?Error("react-stack-top-frame"):F,P?L(n(e)):w)},G.jsxs=function(e,c,d){var P=1e4>p.recentlyCreatedOwnerStacks++;return a(e,c,d,!0,P?Error("react-stack-top-frame"):F,P?L(n(e)):w)}})()),G}var ot;function lt(){return ot||(ot=1,process.env.NODE_ENV==="production"?J.exports=ft():J.exports=ct()),J.exports}var $=lt();function Q(i){return!i&&i!==0?{top:0,right:0,bottom:0,left:0}:typeof i=="number"?{top:i,right:i,bottom:i,left:i}:{top:i.top??0,right:i.right??0,bottom:i.bottom??0,left:i.left??0}}function Z(i){const t=i.replace("#","");if(t.length===3){const r=parseInt(t[0]+t[0],16),n=parseInt(t[1]+t[1],16),o=parseInt(t[2]+t[2],16);return[r,n,o]}if(t.length===6){const r=parseInt(t.slice(0,2),16),n=parseInt(t.slice(2,4),16),o=parseInt(t.slice(4,6),16);return[r,n,o]}return null}function nt(i,t=!0){if(i<=0)return String(i);const r=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]];let n=i,o="";for(const[s,f]of r)for(;n>=s;)o+=f,n-=s;return t?o:o.toLowerCase()}class it{constructor(t={}){this.cursorX=0,this.cursorY=0,this.contentWidth=0,this.margin={top:15,right:15,bottom:15,left:15},this.defaultFont={name:void 0,style:"normal",size:12},this.defaultColor="#111827",this.defaultLineHeight=1.25,this.pendingTasks=new Set,this.opQueue=Promise.resolve(),this.margin=t.margin??this.margin,this.defaultFont={name:t.font?.name,style:t.font?.style??"normal",size:t.font?.size??12},this.defaultColor=t.color??this.defaultColor,this.defaultLineHeight=t.lineHeight??this.defaultLineHeight,this.pdf=new at.jsPDF({unit:t.unit??"mm",format:t.format??"a4",orientation:t.orientation??"p"}),this.pageWidth=this.pdf.internal.pageSize.getWidth(),this.pageHeight=this.pdf.internal.pageSize.getHeight(),this.resetFlowCursor(),this.applyBaseFont()}get instance(){return this.pdf}get width(){return this.pageWidth}get height(){return this.pageHeight}get contentLeft(){return this.margin.left}get contentRight(){return this.pageWidth-this.margin.right}get contentTop(){return this.margin.top}get contentBottom(){return this.pageHeight-this.margin.bottom}get contentHeight(){return this.contentBottom-this.contentTop}get contentAreaWidth(){return this.contentWidth}get baseFont(){return this.defaultFont}get baseLineHeight(){return this.defaultLineHeight}resetFlowCursor(){this.cursorX=this.margin.left,this.cursorY=this.margin.top,this.contentWidth=this.pageWidth-this.margin.left-this.margin.right}setHeaderFooter(t,r){this.headerDrawer=t,this.footerDrawer=r}applyBaseFont(){const t=this.defaultFont.name??this.pdf.getFont().fontName;this.pdf.setFont(t,this.defaultFont.style),this.pdf.setFontSize(this.defaultFont.size);const r=Z(this.defaultColor);r&&this.pdf.setTextColor(...r)}addPage(){this.pdf.addPage(),this.resetFlowCursor()}ensureSpace(t){this.cursorY+t>this.contentBottom&&this.addPage()}setTextStyle(t){if(t){if(t.fontSize&&this.pdf.setFontSize(t.fontSize),t.fontStyle){const r=this.pdf.getFont().fontName;this.pdf.setFont(r,t.fontStyle)}if(t.color){const r=Z(t.color);r&&this.pdf.setTextColor(...r)}}}textRaw(t,r,n,o,s,f="left"){this.setTextStyle(o);const l={align:f};typeof s=="number"&&(l.maxWidth=s),this.pdf.text(t,r,n,l),this.applyBaseFont()}box(t,r,n,o,s){const f=s??{};if(f.fillColor){const l=Z(f.fillColor);l&&this.pdf.setFillColor(...l),this.pdf.rect(t,r,n,o,"F")}if(f.borderWidth||f.borderColor){if(f.borderWidth&&this.pdf.setLineWidth(f.borderWidth),f.borderColor){const l=Z(f.borderColor);l&&this.pdf.setDrawColor(...l)}this.pdf.rect(t,r,n,o),this.pdf.setLineWidth(.2),this.pdf.setDrawColor(0,0,0)}}line(t,r,n,o){this.pdf.line(t,r,n,o)}async imageFromUrl(t,r={}){const n=(async()=>{try{const{dataUrl:o,width:s,height:f}=await this.loadImageAsDataURL(t),l=.264583,g=s*l,T=f*l;let a=r.w,x=r.h;a===void 0&&x===void 0?(a=g,x=T):a===void 0&&x!==void 0?a=x*(g/T):x===void 0&&a!==void 0&&(x=a*(T/g));const h=a??g,D=x??T;let j=r.x,S=r.y??this.cursorY;if(r.y===void 0&&S+D>this.contentBottom&&(this.addPage(),S=this.cursorY),j===void 0){const u=r.align??"left";u==="left"?j=this.contentLeft:u==="center"?j=(this.contentLeft+this.contentRight)/2-h/2:u==="right"&&(j=this.contentRight-h)}return this.pdf.addImage(o,r.mime??"PNG",j,S,h,D),{width:h,height:D,x:j,y:S}}catch(o){return console.error("Failed to load image",t,o),{width:0,height:0,x:0,y:0}}})();return this.registerTask(n),n}queueOperation(t){const r=this.opQueue.then(async()=>{try{await t()}catch(n){console.error("Operation failed",n)}});this.opQueue=r,this.registerTask(r)}registerTask(t){this.pendingTasks.add(t),t.finally(()=>{this.pendingTasks.delete(t)})}async waitForTasks(){await Promise.all(this.pendingTasks),await this.opQueue}loadImageAsDataURL(t){return new Promise((r,n)=>{const o=new Image;o.crossOrigin="anonymous",o.onload=()=>{const s=document.createElement("canvas");s.width=o.width,s.height=o.height;const f=s.getContext("2d");if(!f)return n(new Error("Canvas 2D context not available"));f.drawImage(o,0,0),r({dataUrl:s.toDataURL("image/png"),width:o.width,height:o.height})},o.onerror=s=>n(s),o.src=t})}paragraph(t,r,n){const o=n??this.contentWidth;this.setTextStyle(r);const s=r?.lineHeight??this.defaultLineHeight,f=r?.fontSize??this.defaultFont.size,l=f*s*.3528,g=this.pdf.splitTextToSize(t,o),T=r?.align??"left";let a=0;return g.forEach(x=>{this.cursorY+l>this.contentBottom&&this.addPage();const h=this.cursorY+f*.3528;this.pdf.text(x,this.cursorX,h,{align:T,maxWidth:o}),this.cursorY+=l,a+=l}),this.cursorY+=1,this.applyBaseFont(),a}moveCursor(t,r){this.cursorX+=t,this.cursorY+=r}setCursor(t,r){this.cursorX=t,this.cursorY=r}getCursor(){return{x:this.cursorX,y:this.cursorY}}getPageCount(){return this.pdf.getNumberOfPages()}applyHeaderFooter(){const t=this.getPageCount();if(!(!this.headerDrawer&&!this.footerDrawer)){for(let r=1;r<=t;r++)this.pdf.setPage(r),this.headerDrawer&&this.headerDrawer(this.pdf,r,t,this),this.footerDrawer&&this.footerDrawer(this.pdf,r,t,this);this.pdf.setPage(t)}}measureText(t,r,n){this.setTextStyle(r);const o=r?.fontSize??this.defaultFont.size,s=r?.lineHeight??this.defaultLineHeight,f=o*s*.3528;if(n){const l=this.pdf.splitTextToSize(t,n);return{width:n,height:l.length*f}}else{const l=this.pdf.getTextDimensions(t);return{width:l.w,height:l.h}}}setMetadata(t){t.title&&this.pdf.setDocumentProperties({title:t.title}),t.author&&this.pdf.setDocumentProperties({author:t.author}),t.subject&&this.pdf.setDocumentProperties({subject:t.subject}),t.keywords&&this.pdf.setDocumentProperties({keywords:t.keywords.join(", ")})}save(t){this.applyHeaderFooter(),this.pdf.save(t)}}const st=C.createContext(null),B=()=>{const i=C.useContext(st);if(!i)throw new Error("usePdf must be used within <PdfDocument>");return i},ut=({options:i,header:t,footer:r,pageNumbers:n,centerLabel:o,metadata:s,children:f,onReady:l,filename:g,autoSave:T=!1})=>{const[a]=C.useState(()=>new it(i));return C.useEffect(()=>{s&&a.setMetadata(s)},[a,s]),C.useEffect(()=>{const x=(S,u)=>!u||u==="all"?!0:u==="first-only"?S===1:u==="except-first"?S>1:Array.isArray(u)?u.includes(S):!0,h=(S,u)=>u==="roman-upper"?nt(S,!0):u==="roman-lower"?nt(S,!1):String(S),D=(S,u,A)=>{if(!n?.enabled||!x(u,n.scope))return;const X=n.preset??"page-slash-total",U=(n.template??(X==="page-slash-total"?"Page {page}/{total}":X==="page-of-total"?"Page {page} of {total}":"{page}/{total}")).replace("{page}",h(u,n.format)).replace("{total}",h(A,n.format)),N=n.align??"right",K=N==="left"?a.contentLeft+(n.offsetX??0):N==="right"?a.contentRight-(n.offsetX??0):(a.contentLeft+a.contentRight)/2+(n.offsetX??0),m=S==="header"?10:a.height-7,v=typeof n.y=="number"?n.y:m;a.textRaw(U,K,v,n.style,void 0,N)},j=(S,u,A)=>{if(!o?.enabled||!x(u,o.scope))return;const X="center",q=(a.contentLeft+a.contentRight)/2+(o.offsetX??0),U=S==="header"?10:a.height-7,N=typeof o.y=="number"?o.y:U;a.textRaw(o.text,q,N,o.style,void 0,X)};a.setHeaderFooter((S,u,A)=>{t&&t(a,u,A),n?.position==="header"&&D("header",u,A),o?.position==="header"&&j("header",u)},(S,u,A)=>{n?.position==="footer"&&D("footer",u,A),r&&r(a,u,A),o?.position==="footer"&&j("footer",u)}),a.waitForTasks().then(()=>{l?.(a)})},[]),C.useEffect(()=>{T&&g&&a.save(g)},[T,g]),$.jsx(st.Provider,{value:a,children:f})},ht=({x:i,y:t,w:r,h:n,children:o,...s})=>{const f=B(),l=Q(s.padding),g={top:s.paddingTop??l.top,right:s.paddingRight??l.right,bottom:s.paddingBottom??l.bottom,left:s.paddingLeft??l.left},T=C.useRef({}).current;return typeof i=="number"&&typeof t=="number"&&typeof r=="number"&&typeof n=="number"?(C.useEffect(()=>{f.queueOperation(()=>{f.box(i,t,r,n,s)})},[i,t,r,n]),$.jsx(C.Fragment,{children:o})):(C.useEffect(()=>{f.queueOperation(()=>{const a=f.getCursor();T.start={...a};const x=a.x+g.left,h=a.y+g.top;f.setCursor(x,h)})},[]),$.jsxs(C.Fragment,{children:[o,$.jsx(dt,{boxState:T,pad:g,style:s})]}))},dt=({boxState:i,style:t,pad:r})=>{const n=B();return C.useEffect(()=>{n.queueOperation(()=>{const o=i.start;if(!o)return;const s=n.getCursor(),l=Math.max(s.y-o.y-r.top,0)+r.top+r.bottom;n.box(o.x,o.y,n.contentAreaWidth,l,t),n.setCursor(o.x,o.y+l)})},[]),null},gt=({src:i,x:t,y:r,w:n,h:o,mime:s="PNG",flow:f,align:l="left"})=>{const g=B();return C.useEffect(()=>{const T=f===!0||t===void 0&&r===void 0,a=t,x=r;g.queueOperation(async()=>{const h=await g.imageFromUrl(i,{x:a,y:x,w:n,h:o,mime:s,align:l});T&&h&&g.moveCursor(0,h.height+2)})},[i,t,r,n,o,s,f,l]),null},pt=({items:i,ordered:t=!1,style:r,indent:n=5,markerWidth:o=5,spacing:s=2})=>{const f=B();return C.useEffect(()=>{f.queueOperation(()=>{i.forEach((l,g)=>{const T=t?`${g+1}.`:"•",a=f.getCursor().y,x=f.getCursor().x,h=x+n+o,D=r?.fontSize??f.baseFont.size,j=a+D*.3528;f.textRaw(T,x+n,j,r,o,"right"),f.setCursor(h,a);const S=f.contentRight-h;f.paragraph(l,r,S);const u=f.getCursor().y;f.setCursor(x,u+s)})})},[i,t,r,n,o,s]),null},mt=({data:i,columns:t,width:r="100%",borderWidth:n=.1,borderColor:o="#000000",cellPadding:s=2,headerStyle:f,rowStyle:l,alternateRowStyle:g,headerHeight:T})=>{const a=B();return C.useEffect(()=>{a.queueOperation(()=>{const x=typeof r=="number"?r:parseFloat(r)/100*a.contentAreaWidth,h=t.map(m=>typeof m.width=="number"?m.width:typeof m.width=="string"&&m.width.endsWith("%")?parseFloat(m.width)/100*x:0),D=h.reduce((m,v)=>m+v,0),j=Math.max(0,x-D),S=h.filter(m=>m===0).length;if(S>0){const m=j/S;for(let v=0;v<h.length;v++)h[v]===0&&(h[v]=m)}const u=(m,v,_,W,R,p,z="left",Y=!0)=>{Y&&a.box(v,_,W,R,{borderColor:p.borderColor??o,borderWidth:p.borderWidth??n,fillColor:p.fillColor});const L=Q(p.padding??s),E={top:p.paddingTop??L.top,right:p.paddingRight??L.right,bottom:p.paddingBottom??L.bottom,left:p.paddingLeft??L.left},b=W-E.left-E.right,F=a.instance.splitTextToSize(m,b,p),w=(p.fontSize??a.baseFont.size)*(p.lineHeight??a.baseLineHeight)*.3528,O=(p.fontSize??a.baseFont.size)*.3528,e=F.length*w,c=R-E.top-E.bottom;let d=0;p.verticalAlign==="middle"?d=Math.max(0,(c-e)/2):p.verticalAlign==="bottom"&&(d=Math.max(0,c-e));let P=_+E.top+d+O;const I=p.align??z,y=a.getCursor();F.forEach(k=>{let M=v+E.left;I==="center"?M=v+W/2:I==="right"&&(M=v+W-E.right),a.textRaw(k,M,P,p,void 0,I),P+=w}),a.setCursor(y.x,y.y)};let A=a.getCursor().y;const X=a.getCursor().x,q=T??10;A+q>a.contentBottom&&(a.addPage(),A=a.getCursor().y);let U=X;t.forEach((m,v)=>{const _=h[v];u(m.header??"",U,A,_,q,f??{fontStyle:"bold"},m.align??"left"),U+=_}),A+=q,a.setCursor(X,A);const N=(m,v,_)=>{const W=Q(s),R={top:_.paddingTop??W.top,right:_.paddingRight??W.right,bottom:_.paddingBottom??W.bottom,left:_.paddingLeft??W.left},p=v-R.left-R.right;return a.measureText(m,_,p).height+R.top+R.bottom};new Array(t.length).fill(0),(()=>{const m=new Array(i.length).fill(0);for(let R=0;R<i.length;R++){const p=i[R];let z=0;for(let Y=0;Y<t.length;Y++){const L=t[Y],E=typeof L.accessor=="function"?L.accessor(p):p[L.accessor];let b="",F=l,w=1,O=1;if(E&&typeof E=="object"&&E.content!==void 0?(b=String(E.content),E.style&&(F=E.style),E.colSpan&&(w=E.colSpan),E.rowSpan&&(O=E.rowSpan)):b=String(E??""),O>1){Y+=w-1;continue}let e=h[Y];for(let d=1;d<w;d++)Y+d<h.length&&(e+=h[Y+d]);const c=N(b,e,F??{});c>z&&(z=c),Y+=w-1}z<8&&(z=8),m[R]=z}let v=A;const _=new Array(t.length).fill(0),W=a.getCursor().x;for(let R=0;R<i.length;R++){const p=i[R],z=m[R];let Y=z;for(let b=0;b<t.length;b++){const F=t[b],w=typeof F.accessor=="function"?F.accessor(p):p[F.accessor];let O=1;if(w&&typeof w=="object"&&w.rowSpan&&(O=w.rowSpan),O>1){let e=0;for(let c=0;c<O;c++)R+c<m.length&&(e+=m[R+c]);e>Y&&(Y=e)}}const L=Math.abs(v-(a.contentTop+(T??10)))<1;if(v+Y>a.contentBottom&&!L&&(a.addPage(),v=a.getCursor().y,T!==0)){let b=W;t.forEach((F,w)=>{const O=h[w];u(F.header??"",b,v,O,T??10,f??{fontStyle:"bold"},F.align??"left"),b+=O}),v+=T??10}let E=W;for(let b=0;b<t.length;b++){if(_[b]>0){_[b]--,E+=h[b];continue}const F=t[b],w=typeof F.accessor=="function"?F.accessor(p):p[F.accessor];let O=1,e=1,c=R%2===1&&g?g:l,d="";w&&typeof w=="object"&&w.content!==void 0?(d=String(w.content),w.colSpan&&(O=w.colSpan),w.rowSpan&&(e=w.rowSpan),w.style&&(c={...c,...w.style})):d=String(w??"");let P=h[b];for(let y=1;y<O;y++)b+y<h.length&&(P+=h[b+y]);let I=z;if(e>1)for(let y=1;y<e;y++)R+y<m.length&&(I+=m[R+y]);if(u(d,E,v,P,I,c??{},F.align??"left",!0),e>1){_[b]=e-1;for(let y=1;y<O;y++)b+y<_.length&&(_[b+y]=e-1)}E+=P,b+=O-1}v+=z}a.setCursor(W,v)})()})},[i,t,r]),null},bt=({children:i,x:t,y:r,maxWidth:n,spacingBelow:o=2,...s})=>{const f=B();return C.useEffect(()=>{f.queueOperation(()=>{if(typeof t=="number"&&typeof r=="number")f.textRaw(i,t,r,s,n,s.align);else{f.paragraph(i,s,n);const l=f.getCursor();f.setCursor(l.x,l.y+o)}})},[i,t,r,n,o,s.fontSize,s.align]),null};function wt(i){return typeof i=="number"?{top:i,right:i,bottom:i,left:i}:{top:i?.top??0,right:i?.right??0,bottom:i?.bottom??0,left:i?.left??0}}const vt=({style:i={},children:t})=>{const r=B(),n=Q(i.padding),o={top:i.paddingTop??n.top,right:i.paddingRight??n.right,bottom:i.paddingBottom??n.bottom,left:i.paddingLeft??n.left},s=wt(i.margin),f={top:i.marginTop??s.top,right:i.marginRight??s.right,bottom:i.marginBottom??s.bottom,left:i.marginLeft??s.left},l=C.useRef({}).current;return C.useEffect(()=>{r.queueOperation(()=>{f.top>0&&r.moveCursor(0,f.top);const g=r.getCursor();l.start={...g},r.setCursor(g.x+o.left,g.y+o.top)})},[]),$.jsxs(C.Fragment,{children:[t,$.jsx(Tt,{viewState:l,style:i,pad:o,margin:f})]})},Tt=({viewState:i,style:t,pad:r,margin:n})=>{const o=B();return C.useEffect(()=>{o.queueOperation(()=>{const s=i.start;if(!s)return;const f=o.getCursor();let g=Math.max(f.y-s.y-r.top,0)+r.top+r.bottom;t.height&&(g=t.height);let T=o.contentAreaWidth;typeof t.width=="number"&&(T=t.width),(t.borderColor||t.fillColor||t.borderWidth)&&o.box(s.x,s.y,T,g,t);const a=s.y+g+n.bottom;o.setCursor(s.x,a)})},[]),null};H.PdfBox=ht,H.PdfDocument=ut,H.PdfImage=gt,H.PdfList=pt,H.PdfRenderer=it,H.PdfTable=mt,H.PdfText=bt,H.PdfView=vt,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-vector-pdf",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Vector (text-selectable) PDF engine with React UI to configure page numbers, formats, scopes, and center labels. Powered by jsPDF.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/adithyavalsaraj/react-vector-pdf.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/adithyavalsaraj/react-vector-pdf/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/adithyavalsaraj/react-vector-pdf#readme",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/react-vector-pdf.umd.js",
|
|
16
|
+
"module": "./dist/react-vector-pdf.es.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/react-vector-pdf.es.js",
|
|
25
|
+
"require": "./dist/react-vector-pdf.umd.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"dev": "vite",
|
|
30
|
+
"build": "vite build",
|
|
31
|
+
"preview": "vite preview"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"pdf",
|
|
35
|
+
"jsPDF",
|
|
36
|
+
"vector",
|
|
37
|
+
"react",
|
|
38
|
+
"typescript",
|
|
39
|
+
"text-selectable",
|
|
40
|
+
"page numbers",
|
|
41
|
+
"roman numerals"
|
|
42
|
+
],
|
|
43
|
+
"author": "Adithya Valsaraj",
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"react": ">=18",
|
|
47
|
+
"react-dom": ">=18"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"jspdf": "^3.0.4"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^25.0.3",
|
|
54
|
+
"@types/react": "^19.2.7",
|
|
55
|
+
"@types/react-dom": "^19.2.3",
|
|
56
|
+
"@vitejs/plugin-react": "^5.1.2",
|
|
57
|
+
"baseline-browser-mapping": "^2.9.11",
|
|
58
|
+
"sass": "^1.97.1",
|
|
59
|
+
"typescript": "^5.9.3",
|
|
60
|
+
"vite": "^7.3.0",
|
|
61
|
+
"vite-plugin-dts": "^4.5.4"
|
|
62
|
+
}
|
|
63
|
+
}
|