@pdfme/ui 5.3.8-dev.16 → 5.3.8-dev.17
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/__mocks__/lucide-react.js +19 -0
- package/dist/index.es.js +4 -2
- package/dist/index.umd.js +1 -1
- package/package.json +6 -2
- package/src/components/CtlBar.tsx +2 -0
- package/tsconfig.json +1 -1
@@ -0,0 +1,19 @@
|
|
1
|
+
// Mock for lucide-react
|
2
|
+
module.exports = {
|
3
|
+
Plus: () => 'Plus',
|
4
|
+
Minus: () => 'Minus',
|
5
|
+
ChevronLeft: () => 'ChevronLeft',
|
6
|
+
ChevronRight: () => 'ChevronRight',
|
7
|
+
ChevronsLeft: () => 'ChevronsLeft',
|
8
|
+
ChevronsRight: () => 'ChevronsRight',
|
9
|
+
Ellipsis: () => 'Ellipsis',
|
10
|
+
X: () => 'X',
|
11
|
+
Menu: () => 'Menu',
|
12
|
+
GripVertical: () => 'GripVertical',
|
13
|
+
CircleAlert: () => 'CircleAlert',
|
14
|
+
Lock: () => 'Lock',
|
15
|
+
ArrowLeft: () => 'ArrowLeft',
|
16
|
+
ArrowRight: () => 'ArrowRight',
|
17
|
+
LoaderCircle: () => 'LoaderCircle',
|
18
|
+
// Add any other icons used in the codebase
|
19
|
+
};
|
package/dist/index.es.js
CHANGED
@@ -82120,8 +82120,10 @@ const DEFAULT_OPACITY = 1, HEX_COLOR_PATTERN = "^#(?:[A-Fa-f0-9]{6})$", getBody$
|
|
82120
82120
|
}
|
82121
82121
|
}, hex2PrintingColor = (a, s) => typeof a == "object" ? a : (s == null ? void 0 : s.toLowerCase()) == "cmyk" ? hex2CmykColor(a) : hex2RgbColor(a), createSvgStr = (a, s) => {
|
82122
82122
|
const $ = (_) => {
|
82123
|
-
|
82124
|
-
|
82123
|
+
if (!Array.isArray(_))
|
82124
|
+
return String(_);
|
82125
|
+
const [_e, tt = {}, nt = []] = _, ot = String(_e) === "svg" ? { ...tt } : tt, rt = Object.entries(ot || {}).map(([lt, et]) => `${lt}="${et}"`).join(" "), st = nt.map((lt) => $(lt)).join("");
|
82126
|
+
return `<${_e} ${rt}>${st}</${_e}>`;
|
82125
82127
|
};
|
82126
82128
|
return $(a);
|
82127
82129
|
}, embedAndGetFontObj = async (a) => {
|
package/dist/index.umd.js
CHANGED
@@ -135,7 +135,7 @@ endstream`,s}copyBytesInto(s,$){this.updateDict();const _=$;$+=this.dict.copyByt
|
|
135
135
|
`);let it=st;it<tt.min?it=tt.min:it>tt.max&&(it=tt.max);const ut=tt.fit??DEFAULT_DYNAMIC_FIT,pt=mt=>{let ct=0,vt=0;const At=mm2pt(at),bt=heightOfFontAtSize(s,mt),xt=pt2mm(bt*rt),$t=pt2mm(mt*rt);return et.forEach((wt,Rt)=>{if(getSplittedLinesBySegmenter(wt,{font:s,fontSize:mt,characterSpacing:lt,boxWidthInPt:At}).forEach((Dt,St)=>{if(ut===DYNAMIC_FIT_VERTICAL){const Et=widthOfTextAtSize(Dt.replace(`
|
136
136
|
`,""),s,mt,lt),It=pt2mm(Et);ct=Math.max(ct,It)}Rt+St===0?vt+=xt:vt+=$t}),ut===DYNAMIC_FIT_HORIZONTAL){const Dt=widthOfTextAtSize(wt,s,mt,lt),St=pt2mm(Dt);ct=Math.max(ct,St)}}),{totalWidthInMm:ct,totalHeightInMm:vt}},ht=(mt,ct)=>it>=tt.max?!1:ut===DYNAMIC_FIT_HORIZONTAL?mt<at:ct<ot,dt=(mt,ct)=>it<=tt.min||it<=0?!1:mt>at||ct>ot;let{totalWidthInMm:gt,totalHeightInMm:ft}=pt(it);for(;ht(gt,ft);){it+=FONT_SIZE_ADJUSTMENT;const{totalWidthInMm:mt,totalHeightInMm:ct}=pt(it);if(ct<ot)gt=mt,ft=ct;else{it-=FONT_SIZE_ADJUSTMENT;break}}for(;dt(gt,ft);)it-=FONT_SIZE_ADJUSTMENT,{totalWidthInMm:gt,totalHeightInMm:ft}=pt(it);return it},splitTextToSize=a=>{const{value:s,characterSpacing:$,fontSize:_,fontKitFont:_e,boxWidthInPt:tt}=a,nt={font:_e,fontSize:_,characterSpacing:$,boxWidthInPt:tt};let at=[];return s.split(/\r\n|\r|\n|\f|\u000B/g).forEach(ot=>{at=at.concat(getSplittedLinesBySegmenter(ot,nt))}),at},isFirefox=()=>navigator.userAgent.toLowerCase().indexOf("firefox")>-1,getSplittedLinesBySegmenter=(a,s)=>{if(a.trim()==="")return[""];const{font:$,fontSize:_,characterSpacing:_e,boxWidthInPt:tt}=s,at=new Intl.Segmenter(void 0,{granularity:"word"}).segment(a.trimEnd())[Symbol.iterator]();let ot=[],rt=0,st=0;for(;;){const lt=at.next();if(lt.done)break;const et=lt.value.segment,it=widthOfTextAtSize(et,$,_,_e);if(st+it<=tt)ot[rt]?(ot[rt]+=et,st+=it+_e):(ot[rt]=et,st=it+_e);else if(et.trim()==="")ot[++rt]="",st=0;else if(it<=tt)ot[++rt]=et,st=it+_e;else for(const ut of et){const pt=widthOfTextAtSize(ut,$,_,_e);st+pt<=tt?ot[rt]?(ot[rt]+=ut,st+=pt+_e):(ot[rt]=ut,st=pt+_e):(ot[++rt]=ut,st=pt+_e)}}return ot.some(containsJapanese)?adjustEndOfLine(filterEndJP(filterStartJP(ot))):adjustEndOfLine(ot)},adjustEndOfLine=a=>a.map((s,$)=>$===a.length-1?s.trimEnd()+`
|
137
137
|
`:s.trimEnd());function containsJapanese(a){return/[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u.test(a)}const filterStartJP=a=>{const s=[];let $=null;return a.slice().reverse().forEach(_=>{if(_.trim().length===0)s.push("");else{const _e=_.charAt(0);LINE_START_FORBIDDEN_CHARS.includes(_e)?_.trim().length===1?(s.push(_),$=null):($?s.push(_.slice(1)+$):s.push(_.slice(1)),$=_e):$?(s.push(_+$),$=null):s.push(_)}}),$?[$+s.slice(0,1)[0],...s.slice(1)].reverse():s.reverse()},filterEndJP=a=>{const s=[];let $=null;return a.forEach(_=>{if(_.trim().length===0)s.push("");else{const _e=_.slice(-1);LINE_END_FORBIDDEN_CHARS.includes(_e)?_.trim().length===1?(s.push(_),$=null):($?s.push($+_.slice(0,-1)):s.push(_.slice(0,-1)),$=_e):$?(s.push($+_),$=null):s.push(_)}}),$?[...s.slice(0,-1),s.slice(-1)[0]+$]:s};let Cell$2=class{constructor(s,$,_){Object.defineProperty(this,"raw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"text",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"styles",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"section",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"contentHeight",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"contentWidth",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"wrappedWidth",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"minReadableWidth",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"minWidth",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"width",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"height",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"x",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"y",{enumerable:!0,configurable:!0,writable:!0,value:0}),this.styles=$,this.section=_,this.raw=s;const _e=/\r\n|\r|\n/g;this.text=s.split(_e)}getContentHeight(){const s=Array.isArray(this.text)?this.text.length:1,$=pt2mm(this.styles.fontSize)*this.styles.lineHeight,_=this.padding("top")+this.padding("bottom"),_e=s*$+_;return Math.max(_e,this.styles.minCellHeight)}padding(s){return this.styles.cellPadding[s]}},Column$2=class{constructor(s){Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"wrappedWidth",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"minReadableWidth",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"minWidth",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"width",{enumerable:!0,configurable:!0,writable:!0,value:0}),this.index=s}getMaxCustomCellWidth(s){let $=0;for(const _ of s.allRows()){const _e=_.cells[this.index];$=Math.max($,_e.styles.cellWidth)}return $}},Row$1=class{constructor(s,$,_,_e){Object.defineProperty(this,"raw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"section",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cells",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"height",{enumerable:!0,configurable:!0,writable:!0,value:0}),this.raw=s,this.index=$,this.section=_,this.cells=_e}getMaxCellHeight(s){return s.reduce(($,_)=>{var _e;return Math.max($,((_e=this.cells[_.index])==null?void 0:_e.height)||0)},0)}getMinimumRowHeight(s){return s.reduce(($,_)=>{const _e=this.cells[_.index];if(!_e)return 0;const nt=_e.padding("top")+_e.padding("bottom")+_e.styles.lineHeight;return nt>$?nt:$},0)}},Table$2=class Vl{constructor(s,$){Object.defineProperty(this,"settings",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"styles",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"columns",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"head",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.settings=s.settings,this.styles=s.styles,this.columns=$.columns,this.head=$.head,this.body=$.body}static async create(s){const{input:$,content:_,font:_e,_cache:tt}=s,nt=new Vl($,_);return await calculateWidths({table:nt,font:_e,_cache:tt}),nt}getHeadHeight(){return this.head.reduce((s,$)=>s+$.getMaxCellHeight(this.columns),0)}getBodyHeight(){return this.body.reduce((s,$)=>s+$.getMaxCellHeight(this.columns),0)}allRows(){return this.head.concat(this.body)}getWidth(){return this.settings.tableWidth}getHeight(){return(this.settings.showHead?this.getHeadHeight():0)+this.getBodyHeight()}};async function calculateWidths(a){const{table:s,font:$,_cache:_}=a,_e=ot=>getFontKitFont(ot,$,_);await calculate$1(s,_e);const tt=[];let nt=0;s.columns.forEach(ot=>{const rt=ot.getMaxCustomCellWidth(s);rt?ot.width=rt:(ot.width=ot.wrappedWidth,tt.push(ot)),nt+=ot.width});let at=s.getWidth()-nt;at&&(at=resizeColumns(tt,at,ot=>Math.max(ot.minReadableWidth,ot.minWidth))),at&&(at=resizeColumns(tt,at,ot=>ot.minWidth)),at=Math.abs(at),applyColSpans(s),await fitContent(s,_e),applyRowSpans(s)}function applyRowSpans(a){const s={};let $=1;const _=a.allRows();for(let _e=0;_e<_.length;_e++){const tt=_[_e];for(const nt of a.columns){const at=s[nt.index];if($>1)$--,delete tt.cells[nt.index];else if(at)at.cell.height+=tt.height,$=1,delete tt.cells[nt.index],at.left--,at.left<=1&&delete s[nt.index];else{const ot=tt.cells[nt.index];if(!ot)continue;ot.height=tt.height}}}}function applyColSpans(a){const s=a.allRows();for(let $=0;$<s.length;$++){const _=s[$];let _e=0,tt=0;for(let nt=0;nt<a.columns.length;nt++){const at=a.columns[nt];if(tt-=1,tt>1&&a.columns[nt+1])_e+=at.width,delete _.cells[at.index];else{const ot=_.cells[at.index];if(!ot)continue;tt=1,_e=0,ot.width=at.width+_e}}}}async function fitContent(a,s){const $={count:0,height:0};for(const _ of a.allRows()){for(const _e of a.columns){const tt=_.cells[_e.index];if(!tt)continue;const nt=await s(tt.styles.fontName);tt.text=splitTextToSize({value:tt.raw,characterSpacing:tt.styles.characterSpacing,boxWidthInPt:mm2pt(tt.width),fontSize:tt.styles.fontSize,fontKitFont:nt}),tt.contentHeight=tt.getContentHeight();let at=tt.contentHeight;$&&$.count>0&&$.height>at&&(at=$.height),at>_.height&&(_.height=at)}$.count--}}function resizeColumns(a,s,$){const _=s,_e=a.reduce((tt,nt)=>tt+nt.wrappedWidth,0);for(let tt=0;tt<a.length;tt++){const nt=a[tt],at=nt.wrappedWidth/_e,ot=_*at,rt=nt.width+ot,st=$(nt),lt=rt<st?st:rt;s-=lt-nt.width,nt.width=lt}if(s=Math.round(s*1e10)/1e10,s){const tt=a.filter(nt=>s<0?nt.width>$(nt):!0);tt.length&&(s=resizeColumns(tt,s,$))}return s}async function calculate$1(a,s){for(const $ of a.allRows())for(const _ of a.columns){const _e=$.cells[_.index];if(!_e)continue;const tt=_e.padding("right")+_e.padding("left"),nt=await s(_e.styles.fontName);_e.contentWidth=getStringWidth(_e,nt)+tt;const at=getStringWidth(Object.assign(_e,{text:_e.text.join(" ").split(/\s+/)}),nt);_e.minReadableWidth=at+tt,_e.minWidth=_e.styles.cellWidth,_e.wrappedWidth=_e.styles.cellWidth}for(const $ of a.allRows())for(const _ of a.columns){const _e=$.cells[_.index];if(_e)_.wrappedWidth=Math.max(_.wrappedWidth,_e.wrappedWidth),_.minWidth=Math.max(_.minWidth,_e.minWidth),_.minReadableWidth=Math.max(_.minReadableWidth,_e.minReadableWidth);else{const tt=a.styles.columnStyles[_.index]||{},nt=tt.cellWidth||tt.minCellWidth;nt&&(_.minWidth=nt,_.wrappedWidth=nt)}}}function getStringWidth(a,s){const $=a.text,_=Array.isArray($)?$:[$],_e=a.styles.fontSize,tt=a.styles.characterSpacing;return _.map(at=>widthOfTextAtSize(at,s,_e,tt)).reduce((at,ot)=>Math.max(at,ot),0)}function parseSection(a,s,$,_,_e){const tt={};return s.map((at,ot)=>{let rt=0;const st={};let lt=0,et=0;for(const it of $)if(tt[it.index]==null||tt[it.index].left===0)if(et===0){let ut;Array.isArray(at)?ut=at[it.index-lt-rt]:ut=at[it.index];const pt=cellStyles(a,it,ot,_,_e),ht=new Cell$2(ut,pt,a);st[it.index]=ht,et=0,tt[it.index]={left:0,times:et}}else et--,lt++;else tt[it.index].left--,et=tt[it.index].times,rt++;return new Row$1(at,ot,a,st)})}function parseContent4Table(a,s){const $=a.content,_=$.columns.map(tt=>new Column$2(tt)),_e=a.styles;return{columns:_,head:parseSection("head",$.head,_,_e,s),body:parseSection("body",$.body,_,_e,s)}}function cellStyles(a,s,$,_,_e){let tt;a==="head"?tt=_.headStyles:a==="body"&&(tt=_.bodyStyles);const nt=Object.assign({},_.styles,tt),at=_.columnStyles[s.index]||_.columnStyles[s.index]||{},ot=a==="body"&&$%2===0?Object.assign({},_.alternateRowStyles):{};return Object.assign({fontName:_e,backgroundColor:"",textColor:"#000000",lineHeight:1,characterSpacing:0,alignment:"left",verticalAlignment:"middle",fontSize:10,cellPadding:5,lineColor:"#000000",lineWidth:0,minCellHeight:0,minCellWidth:0},nt,ot,at)}function mapCellStyle(a){return{fontName:a.fontName,alignment:a.alignment,verticalAlignment:a.verticalAlignment,fontSize:a.fontSize,lineHeight:a.lineHeight,characterSpacing:a.characterSpacing,backgroundColor:a.backgroundColor,textColor:a.fontColor,lineColor:a.borderColor,lineWidth:a.borderWidth,cellPadding:a.padding}}function getTableOptions(a,s){const $=a.headWidthPercentages.reduce((nt,at,ot)=>({...nt,[ot]:{cellWidth:a.width*(at/100)}}),{}),_=Object.entries(a.columnStyles.alignment||{}).reduce((nt,[at,ot])=>({...nt,[at]:{alignment:ot}}),{}),_e=new Set([...Object.keys($).map(Number),...Object.keys(_).map(Number)]),tt=Array.from(_e).reduce((nt,at)=>{const ot=$[at]||{},rt=_[at]||{};return{...nt,[at]:{...ot,...rt}}},{});return{head:[a.head],body:s,showHead:a.showHead,startY:a.position.y,tableWidth:a.width,tableLineColor:a.tableStyles.borderColor,tableLineWidth:a.tableStyles.borderWidth,headStyles:mapCellStyle(a.headStyles),bodyStyles:mapCellStyle(a.bodyStyles),alternateRowStyles:{backgroundColor:a.bodyStyles.alternateBackgroundColor},columnStyles:tt,margin:{top:0,right:0,left:a.position.x,bottom:0}}}function parseStyles(a){const s={styles:{},headStyles:{},bodyStyles:{},alternateRowStyles:{},columnStyles:{}};for(const $ of Object.keys(s))if($==="columnStyles"){const _=a[$];s.columnStyles=Object.assign({},_)}else{const _e=[a].map(tt=>tt[$]||{});s[$]=Object.assign({},_e[0],_e[1],_e[2])}return s}function parseContent4Input(a){const s=a.head||[],$=a.body||[];return{columns:(s[0]||$[0]||[]).map((_e,tt)=>tt),head:s,body:$}}function parseInput(a,s){const $=getTableOptions(a,s),_=parseStyles($),_e={startY:$.startY,margin:$.margin,tableWidth:$.tableWidth,showHead:$.showHead,tableLineWidth:$.tableLineWidth??0,tableLineColor:$.tableLineColor??""};return{content:parseContent4Input($),styles:_,settings:_e}}function createSingleTable(a,s){const{options:$,_cache:_,basePdf:_e}=s;isBlankPdf(_e)||console.warn(`[@pdfme/schema/table]When specifying a custom PDF for basePdf, you cannot use features such as page breaks or re-layout of other elements.To utilize these features, please define basePdf as follows:
|
138
|
-
{ width: number; height: number; padding: [number, number, number, number]; }`);const tt=cloneDeep$1(s.schema),{start:nt}=tt.__bodyRange||{start:0};if(nt%2===1){const lt=tt.bodyStyles.alternateBackgroundColor;tt.bodyStyles.alternateBackgroundColor=tt.bodyStyles.backgroundColor,tt.bodyStyles.backgroundColor=lt}tt.showHead=tt.showHead===!1?!1:!tt.__isSplit;const at=parseInput(tt,a),ot=$.font||getDefaultFont(),rt=getFallbackFontName(ot),st=parseContent4Table(at,rt);return Table$2.create({input:at,content:st,font:ot,_cache:_})}const DEFAULT_OPACITY=1,HEX_COLOR_PATTERN="^#(?:[A-Fa-f0-9]{6})$",getBody$1=a=>typeof a=="string"?JSON.parse(a||"[]"):a||[],getBodyWithRange=(a,s)=>{const $=getBody$1(a);return s?$.slice(s.start,s.end):$},getDynamicHeightsForTable$1=async(a,s)=>{var tt;if(s.schema.type!=="table")return Promise.resolve([s.schema.height]);const $=s.schema,_=((tt=$.__bodyRange)==null?void 0:tt.start)===0?getBody$1(a):getBodyWithRange(a,$.__bodyRange),_e=await createSingleTable(_,s);return $.showHead?_e.allRows().map(nt=>nt.height):[0].concat(_e.body.map(nt=>nt.height))},convertForPdfLayoutProps=({schema:a,pageHeight:s,applyRotateTranslate:$=!0})=>{const{width:_,height:_e,position:tt,rotate:nt,opacity:at}=a,{x:ot,y:rt}=tt,st=nt?-nt:0,lt=mm2pt(_),et=mm2pt(_e);let it=mm2pt(ot),ut=s-mm2pt(rt)-et;if(st&&$){const pt={x:it+lt/2,y:s-mm2pt(rt)-et/2},ht=rotatePoint({x:it,y:ut},pt,st);it=ht.x,ut=ht.y}return{position:{x:it,y:ut},height:et,width:lt,rotate:degrees(st),opacity:at}},rotatePoint=(a,s,$)=>{const _=degreesToRadians($),_e=Math.cos(_)*(a.x-s.x)-Math.sin(_)*(a.y-s.y)+s.x,tt=Math.sin(_)*(a.x-s.x)+Math.cos(_)*(a.y-s.y)+s.y;return{x:_e,y:tt}},getDynamicHeightsForTable=getDynamicHeightsForTable$1,isEditable=(a,s)=>a==="designer"||a==="form"&&s.readOnly!==!0,hex2rgb=a=>(a.slice(0,1)==="#"&&(a=a.slice(1)),a.length===3&&(a=a.slice(0,1)+a.slice(0,1)+a.slice(1,2)+a.slice(1,2)+a.slice(2,3)+a.slice(2,3)),[a.slice(0,2),a.slice(2,4),a.slice(4,6)].map(s=>parseInt(s,16))),hex2RgbColor=a=>{if(a){if(!isHexValid(a))throw new Error(`Invalid hex color value ${a}`);const[$,_,_e]=hex2rgb(a);return rgb($/255,_/255,_e/255)}},hex2CmykColor=a=>{if(a){if(!isHexValid(a))throw new Error(`Invalid hex color value ${a}`);a=a.replace("#","");const $=a.substring(0,6),_=a.substring(6,8),_e=_?parseInt(_,16)/255:1;let tt=parseInt($.substring(0,2),16)/255,nt=parseInt($.substring(2,4),16)/255,at=parseInt($.substring(4,6),16)/255;tt=tt*_e+(1-_e),nt=nt*_e+(1-_e),at=at*_e+(1-_e);const ot=1-Math.max(tt,nt,at),rt=tt===0?0:(1-tt-ot)/(1-ot),st=nt===0?0:(1-nt-ot)/(1-ot),lt=at===0?0:(1-at-ot)/(1-ot);return cmyk(rt,st,lt,ot)}},hex2PrintingColor=(a,s)=>typeof a=="object"?a:(s==null?void 0:s.toLowerCase())=="cmyk"?hex2CmykColor(a):hex2RgbColor(a),createSvgStr=(a,s)=>{const $=_=>{const[_e,tt,nt=[]]=_,
|
138
|
+
{ width: number; height: number; padding: [number, number, number, number]; }`);const tt=cloneDeep$1(s.schema),{start:nt}=tt.__bodyRange||{start:0};if(nt%2===1){const lt=tt.bodyStyles.alternateBackgroundColor;tt.bodyStyles.alternateBackgroundColor=tt.bodyStyles.backgroundColor,tt.bodyStyles.backgroundColor=lt}tt.showHead=tt.showHead===!1?!1:!tt.__isSplit;const at=parseInput(tt,a),ot=$.font||getDefaultFont(),rt=getFallbackFontName(ot),st=parseContent4Table(at,rt);return Table$2.create({input:at,content:st,font:ot,_cache:_})}const DEFAULT_OPACITY=1,HEX_COLOR_PATTERN="^#(?:[A-Fa-f0-9]{6})$",getBody$1=a=>typeof a=="string"?JSON.parse(a||"[]"):a||[],getBodyWithRange=(a,s)=>{const $=getBody$1(a);return s?$.slice(s.start,s.end):$},getDynamicHeightsForTable$1=async(a,s)=>{var tt;if(s.schema.type!=="table")return Promise.resolve([s.schema.height]);const $=s.schema,_=((tt=$.__bodyRange)==null?void 0:tt.start)===0?getBody$1(a):getBodyWithRange(a,$.__bodyRange),_e=await createSingleTable(_,s);return $.showHead?_e.allRows().map(nt=>nt.height):[0].concat(_e.body.map(nt=>nt.height))},convertForPdfLayoutProps=({schema:a,pageHeight:s,applyRotateTranslate:$=!0})=>{const{width:_,height:_e,position:tt,rotate:nt,opacity:at}=a,{x:ot,y:rt}=tt,st=nt?-nt:0,lt=mm2pt(_),et=mm2pt(_e);let it=mm2pt(ot),ut=s-mm2pt(rt)-et;if(st&&$){const pt={x:it+lt/2,y:s-mm2pt(rt)-et/2},ht=rotatePoint({x:it,y:ut},pt,st);it=ht.x,ut=ht.y}return{position:{x:it,y:ut},height:et,width:lt,rotate:degrees(st),opacity:at}},rotatePoint=(a,s,$)=>{const _=degreesToRadians($),_e=Math.cos(_)*(a.x-s.x)-Math.sin(_)*(a.y-s.y)+s.x,tt=Math.sin(_)*(a.x-s.x)+Math.cos(_)*(a.y-s.y)+s.y;return{x:_e,y:tt}},getDynamicHeightsForTable=getDynamicHeightsForTable$1,isEditable=(a,s)=>a==="designer"||a==="form"&&s.readOnly!==!0,hex2rgb=a=>(a.slice(0,1)==="#"&&(a=a.slice(1)),a.length===3&&(a=a.slice(0,1)+a.slice(0,1)+a.slice(1,2)+a.slice(1,2)+a.slice(2,3)+a.slice(2,3)),[a.slice(0,2),a.slice(2,4),a.slice(4,6)].map(s=>parseInt(s,16))),hex2RgbColor=a=>{if(a){if(!isHexValid(a))throw new Error(`Invalid hex color value ${a}`);const[$,_,_e]=hex2rgb(a);return rgb($/255,_/255,_e/255)}},hex2CmykColor=a=>{if(a){if(!isHexValid(a))throw new Error(`Invalid hex color value ${a}`);a=a.replace("#","");const $=a.substring(0,6),_=a.substring(6,8),_e=_?parseInt(_,16)/255:1;let tt=parseInt($.substring(0,2),16)/255,nt=parseInt($.substring(2,4),16)/255,at=parseInt($.substring(4,6),16)/255;tt=tt*_e+(1-_e),nt=nt*_e+(1-_e),at=at*_e+(1-_e);const ot=1-Math.max(tt,nt,at),rt=tt===0?0:(1-tt-ot)/(1-ot),st=nt===0?0:(1-nt-ot)/(1-ot),lt=at===0?0:(1-at-ot)/(1-ot);return cmyk(rt,st,lt,ot)}},hex2PrintingColor=(a,s)=>typeof a=="object"?a:(s==null?void 0:s.toLowerCase())=="cmyk"?hex2CmykColor(a):hex2RgbColor(a),createSvgStr=(a,s)=>{const $=_=>{if(!Array.isArray(_))return String(_);const[_e,tt={},nt=[]]=_,ot=String(_e)==="svg"?{...tt}:tt,rt=Object.entries(ot||{}).map(([lt,et])=>`${lt}="${et}"`).join(" "),st=nt.map(lt=>$(lt)).join("");return`<${_e} ${rt}>${st}</${_e}>`};return $(a)},embedAndGetFontObj=async a=>{const{pdfDoc:s,font:$,_cache:_}=a;if(_.has(s))return _.get(s);const _e=await Promise.all(Object.values($).map(async nt=>{let at=nt.data;return typeof at=="string"&&at.startsWith("http")&&(at=await fetch(at).then(ot=>ot.arrayBuffer())),s.embedFont(at,{subset:typeof nt.subset>"u"?!0:nt.subset})})),tt=Object.keys($).reduce((nt,at,ot)=>Object.assign(nt,{[at]:_e[ot]}),{});return _.set(s,tt),tt},getFontProp=({value:a,fontKitFont:s,schema:$,colorType:_})=>{const _e=$.dynamicFontSize?calculateDynamicFontSize({textSchema:$,fontKitFont:s,value:a}):$.fontSize??DEFAULT_FONT_SIZE,tt=hex2PrintingColor($.fontColor||DEFAULT_FONT_COLOR,_);return{alignment:$.alignment??DEFAULT_ALIGNMENT,verticalAlignment:$.verticalAlignment??DEFAULT_VERTICAL_ALIGNMENT,lineHeight:$.lineHeight??DEFAULT_LINE_HEIGHT,characterSpacing:$.characterSpacing??DEFAULT_CHARACTER_SPACING,fontSize:_e,color:tt}},pdfRender=async a=>{const{value:s,pdfDoc:$,pdfLib:_,page:_e,options:tt,schema:nt,_cache:at}=a;if(!s)return;const{font:ot=getDefaultFont(),colorType:rt}=tt,[st,lt]=await Promise.all([embedAndGetFontObj({pdfDoc:$,font:ot,_cache:at}),getFontKitFont(nt.fontName,ot,at)]),et=getFontProp({value:s,fontKitFont:lt,schema:nt,colorType:rt}),{fontSize:it,color:ut,alignment:pt,verticalAlignment:ht,lineHeight:dt,characterSpacing:gt}=et,ft=nt.fontName?nt.fontName:getFallbackFontName(ot),mt=st&&st[ft],ct=_e.getHeight(),{width:vt,height:At,rotate:bt,position:{x:xt,y:$t},opacity:wt}=convertForPdfLayoutProps({schema:nt,pageHeight:ct,applyRotateTranslate:!1});if(nt.backgroundColor){const yt=hex2PrintingColor(nt.backgroundColor,rt);_e.drawRectangle({x:xt,y:$t,width:vt,height:At,rotate:bt,color:yt})}const Rt=heightOfFontAtSize(lt,it),Pt=getFontDescentInPt(lt,it),Dt=dt===0?0:(dt-1)*it/2,St=splitTextToSize({value:s,characterSpacing:gt,fontSize:it,fontKitFont:lt,boxWidthInPt:vt});let Et=0;if(ht===VERTICAL_ALIGN_TOP)Et=Rt+Dt;else{const yt=dt*it*(St.length-1);ht===VERTICAL_ALIGN_BOTTOM?Et=At-yt+Pt-Dt:ht===VERTICAL_ALIGN_MIDDLE&&(Et=(At-yt-Rt+Pt)/2+Rt)}const It={x:xt+vt/2,y:ct-mm2pt(nt.position.y)-At/2},Ct=new Intl.Segmenter(void 0,{granularity:"grapheme"});St.forEach((yt,Tt)=>{const _t=yt.replace(`
|
139
139
|
`,""),Ot=widthOfTextAtSize(_t,lt,it,gt),Bt=heightOfFontAtSize(lt,it),Ft=dt*it*Tt;yt===""&&(yt=`\r
|
140
140
|
`);let Lt=xt;pt==="center"?Lt+=(vt-Ot)/2:pt==="right"&&(Lt+=vt-Ot);let jt=ct-mm2pt(nt.position.y)-Et-Ft;if(nt.strikethrough&&Ot>0){const Mt=Lt+Ot+1,kt=jt+Bt/3;_e.drawLine({start:rotatePoint({x:Lt,y:kt},It,bt.angle),end:rotatePoint({x:Mt,y:kt},It,bt.angle),thickness:1/12*it,color:ut,opacity:wt})}if(nt.underline&&Ot>0){const Mt=Lt+Ot+1,kt=jt-Bt/12;_e.drawLine({start:rotatePoint({x:Lt,y:kt},It,bt.angle),end:rotatePoint({x:Mt,y:kt},It,bt.angle),thickness:1/12*it,color:ut,opacity:wt})}if(bt.angle!==0){const Mt=rotatePoint({x:Lt,y:jt},It,bt.angle);Lt=Mt.x,jt=Mt.y}let Ht=gt;if(pt==="justify"&&yt.slice(-1)!==`
|
141
141
|
`){const Mt=Ct.segment(_t)[Symbol.iterator](),kt=Array.from(Mt).length;Ht+=(vt-Ot)/kt}_e.pushOperators(_.setCharacterSpacing(Ht)),_e.drawText(_t,{x:Lt,y:jt,rotate:bt,size:it,color:ut,lineHeight:dt*it,font:mt,opacity:wt})})};/**
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pdfme/ui",
|
3
|
-
"version": "5.3.8-dev.
|
3
|
+
"version": "5.3.8-dev.17",
|
4
4
|
"sideEffects": false,
|
5
5
|
"author": "hand-dot",
|
6
6
|
"license": "MIT",
|
@@ -88,7 +88,8 @@
|
|
88
88
|
"^antd/es/": "antd/lib/",
|
89
89
|
"^form-render/es/": "form-render/lib/",
|
90
90
|
"^rc-picker/es/": "rc-picker/lib/",
|
91
|
-
"^lodash-es$": "lodash"
|
91
|
+
"^lodash-es$": "lodash",
|
92
|
+
"\\^lucide-react$": "<rootDir>/__mocks__/lucide-react.js"
|
92
93
|
},
|
93
94
|
"resolver": "ts-jest-resolver",
|
94
95
|
"moduleFileExtensions": [
|
@@ -107,6 +108,9 @@
|
|
107
108
|
"testMatch": [
|
108
109
|
"**/*.test.ts",
|
109
110
|
"**/*.test.tsx"
|
111
|
+
],
|
112
|
+
"transformIgnorePatterns": [
|
113
|
+
"/node_modules/(?!lucide-react)"
|
110
114
|
]
|
111
115
|
},
|
112
116
|
"publishConfig": {
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import React, { useContext } from 'react';
|
2
2
|
import { Size } from '@pdfme/common';
|
3
|
+
// Import icons from lucide-react
|
4
|
+
// Note: In tests, these will be mocked by the mock file in __mocks__/lucide-react.js
|
3
5
|
import { Plus, Minus, ChevronLeft, ChevronRight, Ellipsis } from 'lucide-react';
|
4
6
|
|
5
7
|
import type { MenuProps } from 'antd';
|