this.pages.at(-1).pageBottom){this._debug._parseNode&&console.log("🪁 Tail: _parents[i].bottom > this.pages.at(-1).pageBottom",e[t].bottom,">",this.pages.at(-1).pageBottom,e[t].element);const i=this._node.createNeutral();if(i.classList.add("service"),this._DOM.insertAtEnd(e[t].element,i),this._registerPageStart({element:i,context:"_isTailLongerThanPage"}),this._debug._parseNode&&console.log("_registerPageStart",i),this._node.markProcessed(i,"node is ForcedPageBreak"),this._debug._parseNode&&console.log(this.pages.at(-1).pageBottom,c),!(c>this.pages.at(-1).pageBottom))return this._debug._parseNode&&console.log("%c END _parseNode (bottom Tail of parents)",un),void(this._debug._parseNode&&console.groupEnd());this._debug._&&console.log("🧧 • arrayParentBottomEdge > this.pages.at(-1).pageBottom")}return this._debug._parseNode&&console.log("%c END _parseNode (bottom Tail of parents)",un),void(this._debug._parseNode&&console.groupEnd())}this._debug._parseNode&&console.log("🪁 Tail: currentElementBottom > this.pages.at(-1).pageBottom","DOING NOTHING")}
//! currentParentBottomEdge is refreshed right before, so descendants see live parent boundaries.
-const g=c??l;if(this._debug._parseNode&&console.log("[_parseNode]",{currentBlockBottom:g,currentParentBottomEdge:c,currentElementBottom:l}),this.pages.at(-1).pageStart===o&&(this._node.isNotBreakable(o)||g<=this.pages.at(-1).pageBottom))return this._node.markProcessed(o,"node is already registered and fits in the page"),this._debug._parseNode&&console.log("%c END _parseNode (node is already registered and fits in the next page)",tn),void(this._debug._parseNode&&console.groupEnd());if(d>=this.pages.at(-1).pageBottom&&l-d){const t=e&&Boolean(r)?this._node.getTopForPageStartCandidate(r,this._root):void 0,i=Boolean(t)&&d-t>=this._referenceHeight;if(i)this._debug._parseNode&&console.log("🪁 beginning Tail",{parentTop:t,currentParentBottomEdge:c,currentElementTop:d,pageBottom:this.pages.at(-1).pageBottom},{currentElement:o,arrayTopParent:r});else{const e=this._DOM.getComputedStyle(o)?.display||"";if(e.includes("inline")||"contents"===e)return this._debug._parseNode&&console.log("🧅 current in thin wrapper"),this._registerPageStart({element:o,improveResult:!0,context:"🧅 current in thin wrapper"}),this._debug._parseNode&&console.log("%c END _parseNode (registered new page start)",tn),void(this._debug._parseNode&&console.groupEnd())}this._registerPageStart({element:o,improveResult:!i,context:"currentElementTop >= this.pages.at(-1).pageBottom"})}if(this._node.isForcedPageBreak(o))return this._registerPageStart({element:o,context:"currentElement is ForcedPageBreak"}),this._node.markProcessed(o,"node is ForcedPageBreak"),this._debug._parseNode&&console.log("%c END _parseNode (isForcedPageBreak)",tn),void(this._debug._parseNode&&console.groupEnd());this.strictAssert(this._DOM.getElementOffsetParent(o),"it is expected that the element has an offset parent",o);const u=this._node.getTop(n,this._root);if(this._debug._parseNode&&console.log(...a,"• pageBottom",this.pages.at(-1).pageBottom,"\n","• nextElementTop",u),u<=this.pages.at(-1).pageBottom)return this._debug._parseNode&&console.log("nextElementTop <= this.pages.at(-1).pageBottom",u,"<=",this.pages.at(-1).pageBottom),this._node.markProcessed(o,"node fits"),this._node.findAllForcedPageBreakInside(o).forEach(e=>{this._node.markProcessed(e,"node is ForcedPageBreak (inside a node that fits)"),this._registerPageStart({element:e,context:"All Forced Page Break Inside currentElement"})}),this._debug._parseNode&&console.log("%c END _parseNode (node pass)",tn),void(this._debug._parseNode&&console.groupEnd());{if(this._debug._parseNode&&console.log("nextElementTop > this.pages.at(-1).pageBottom",u,">",this.pages.at(-1).pageBottom),g<=this.pages.at(-1).pageBottom)return this._debug._parseNode&&console.log("currentBlockBottom <= this.pages.at(-1).pageBottom",g,"<=",this.pages.at(-1).pageBottom,"\n register nextElement as pageStart"),this._node.isNoHanging(o)?(this._debug._parseNode&&console.log("currentElement fits / last, and _isNoHanging => move it to the next page"),this._node.markProcessed(o,"it fits & last & _isNoHanging => move it to the next page"),this._registerPageStart({element:o,improveResult:!0,context:"currentElement is NoHanging"}),this._debug._parseNode&&console.log("%c END _parseNode (isNoHanging)",tn),void(this._debug._parseNode&&console.groupEnd())):(this._registerPageStart({element:n,type:"next",context:"currentBlockBottom <= PgBtt && nextElementTop > PgBtt"}),this._node.markProcessed(o,"fits, its bottom falls exactly on the cut"),this._node.markProcessed(n,"starts new page, its top is exactly on the cut"),this._debug._parseNode&&console.log("%c END _parseNode (currentElement fits, register the next element)",tn),void(this._debug._parseNode&&console.groupEnd()));const t=this._node.resolveReplacedElement(o,{prefer:"first"});if(t){const i=this._node.isSVG(t),s=i?this._node.createSignpost(t):t,a=this._node.getTop(s,this._root),l=this._node.getBottom(s,this._root),d=e&&r?this._node.getTop(r,this._root):void 0,g=r||this._DOM.getParentNode(s),u=this._node.estimateInlineImgGapBelow(g);let p=this.pages.at(-1).pageBottom-a-u;p-=h?h-l:0;const _=this._DOM.getElementOffsetHeight(s),f=this._DOM.getElementOffsetWidth(s);if(this._debug._parseNode&&console.log("🖼️🖼️🖼️🖼️🖼️🖼️ (if mediaElement)",t,{_imageParent:g,arrayTopParent:r,arrayParentBottomEdge:h,availableImageNodeSpace:p,currentParentBottomEdge:c,currentElement:o,currentImage:s,currentImageHeight:_,currentImageWidth:f,isSvgMedia:i,imgGapBelow:u,parentTopForImage:d}),f>this._referenceWidth&&this._debug._parseNode&&console.warn("%c IMAGE is too wide","color: red"),_this._imageReductionRatio)return this._debug._parseNode&&console.log("Register next elements; 🖼️🖼️🖼️ IMG RESIZE to availableImageNodeSpace:",p,o),this._node.markProcessed(o,`IMG with ratio ${m}, and next starts on next`),this._node.fitElementWithinBoundaries({element:t,height:_,width:f,vspace:p,hspace:this._referenceWidth}),this._registerPageStart({element:n,type:"next",context:"current IMG was RESIZED to availableImageNodeSpace"}),this._debug._parseNode&&console.log("%c END _parseNode 🖼️ IMG scaled",tn),void(this._debug._parseNode&&console.groupEnd());this._node.markProcessed(o,"IMG starts on next");const b=i?s:t;this._registerPageStart({element:b,improveResult:!0,context:"move IMG it to next page"}),this._debug._parseNode&&console.log("🖼️ register Page Start",o);let w=this.pages.at(-1).pageBottom-a-u;const S=h?null:this._node.findLastChildParent(o,this._contentFlow),M=h||this._node.getBottom(S||o,this._root);return M>l&&(w-=M-l),_>w&&(this._node.fitElementWithinBoundaries({element:t,height:_,width:f,vspace:w,hspace:this._referenceWidth}),this._node.markProcessed(o,"IMG starts on next and resized"),this._debug._parseNode&&console.log("🖼️ ..and fit it to full page",o)),this._debug._parseNode&&console.log("%c END",tn),void(this._debug._parseNode&&console.groupEnd())}if(o.style.height){this._debug._parseNode&&console.log("🥁 currentElement has HEIGHT",o.style.height);const e=this.pages.at(-1).pageBottom-d,t=u-d,i=e/t,r=this._referenceHeight/t;return this._debug._parseNode&&console.log("\n🥁 currentElementTop",d,"\n🥁 pageBottom",this.pages.at(-1).pageBottom,"\n🥁 availableSpace",e,"\n🥁 currentElementContextualHeight",t,"\n🥁 availableSpaceFactor",i,"\n🥁 fullPageFactor",r),this.strictAssert(i<1),i>.8?(this._debug._parseNode&&console.log("🥁 availableSpaceFactor > 0.8: ",i),this._DOM.setStyles(o,{transform:`scale(${i})`,"transform-origin":"top center"}),this._registerPageStart({element:n,type:"next",context:"IMMEDIATELY scale currentElement to the remaining space; availableSpaceFactor > 0.8; currentElement.style.height"}),this._node.markProcessed(o,"processed as a image, has been scaled down within 20%, the next one starts a new page"),this._node.markProcessed(n,"the previous one was scaled down within 20%, and this one starts a new page."),this._debug._parseNode&&console.log("%c END _parseNode (has height & scale)",tn),void(this._debug._parseNode&&console.groupEnd())):(r<1&&(this._debug._parseNode&&console.log("🥁 fullPageFactor < 1: ",r),this._node.markProcessed(o,"processed as a image, has been scaled down, and starts new page"),this._DOM.setStyles(o,{transform:`scale(${r})`,"transform-origin":"top center"})),this._debug._parseNode&&console.log("🥁 _registerPageStart",o),this._registerPageStart({element:o,improveResult:!0,context:'has height & processed "as a image", has been scaled down, and starts new page'}),this._node.markProcessed(o,"processed as a image, starts new page"),this._debug._parseNode&&console.log("%c END _parseNode (has height & put on next page)",tn),void(this._debug._parseNode&&console.groupEnd()))}if(this._debug._parseNode&&console.log("split or not? \n","currentBlockBottom",g),this._debug._parseNode&&console.log("currentParentBottomEdge || currentElementBottom",{currentParentBottomEdge:c,currentElementBottom:l},"currentBlockBottom > this.pages.at(-1).pageBottom",g,">",this.pages.at(-1).pageBottom),this._DOM.getElementOffsetHeight(o) this.pages.at(-1).pageBottom"}),this._node.markProcessed(o,"starts new page, #fewLines"),this._debug._parseNode&&console.log("%c END _parseNode #fewLines",tn),void(this._debug._parseNode&&console.groupEnd());const p=this._node.getSplitChildren(o,this.pages.at(-1).pageBottom,this._referenceHeight,this._root);this._debug._parseNode&&console.log("try to break it and loop the children:",p);if(p.length){const e=r||o,t=s||o,a=this._node.isSliced(o)||this._node.isSlough(o);this._debug._parseNode&&console.log({isSlicedParent:a,arrayTopParent:r}),this._parseNodes({array:p,previous:i,next:n,arrayTopParent:a?void 0:e,arrayBottomParent:a?void 0:t}),this._node.markProcessed(o,"getSplitChildren and _parseNodes")}else this._debug._parseNode&&console.log(...a,"_registerPageStart (from _parseNode): \n",o),this._registerPageStart({element:o,improveResult:!0,context:"does not fit, has no children, register it (or parents if improved)"}),this._node.markProcessed(o,"doesn't fit, has no children, register it or parents")}this._debug._parseNode&&console.log("%c END _parseNode [•••]",tn,{currentElement:o}),this._debug._parseNode&&console.groupEnd()}}class nn{constructor({config:e,DOM:t,node:i,selector:o,layout:n}){this._debug=e.debugMode?{...e.debugConfig.paper}:{},this._DOM=t,this._selector=o,this._node=i,this._frontpageTemplate=n.frontpageTemplate,this._headerTemplate=n.headerTemplate,this._footerTemplate=n.footerTemplate,this._pageChromeSelector=o?.pageChrome||".pageChrome",this._pageBodySpacerSelector=o?.pageBodySpacer||".pageBodySpacer",this._pageHeaderSelector=o?.pageHeader||".pageHeader",this._pageFooterSelector=o?.pageFooter||".pageFooter",this._headerContentSelector=o?.headerContent||".headerContent",this._footerContentSelector=o?.footerContent||".footerContent",this._frontpageElementSelector=o?.frontpageElement||".frontpageElement",this._frontpageContentSelector=o?.frontpageContent||".frontpageContent",this._virtualPaperSelector=o?.virtualPaper||".virtualPaper",this._virtualPaperTopMarginSelector=o?.virtualPaperTopMargin||".virtualPaperTopMargin",this._virtualPaperBottomMarginSelector=o?.virtualPaperBottomMargin||".virtualPaperBottomMargin",this._pageNumberRootSelector=o?.pageNumberRoot?R(o.pageNumberRoot):void 0,this._pageNumberCurrentSelector=o?.pageNumberCurrent?R(o.pageNumberCurrent):void 0,this._pageNumberTotalSelector=o?.pageNumberTotal?R(o.pageNumberTotal):void 0,this._paperHeight,this._frontpageFactor,this.headerHeight,this.footerHeight,this.bodyHeight,this.bodyWidth,this._calculatePaperParams()}createPageChrome({pageNumber:e,pageCount:t}){const i=this._node.create(this._pageChromeSelector);this._node.markPageNumber(i,e);const o=this._composePageElements({pageNumber:e,pageCount:t});return this._DOM.insertAtEnd(i,o),i}_composePageElements({pageNumber:e,pageCount:t}){const i=this._DOM.createDocumentFragment(),o=this._createPageBodySpacer(this.bodyHeight);this._node.markPageNumber(o,e);const n=this._createPageHeader(this._headerTemplate),r=this._createPageFooter(this._footerTemplate);return this._DOM.insertAtEnd(i,this.createVirtualTopMargin(),n,o,r,this.createVirtualBottomMargin()),e&&t&&(this._setPageNumber(n,e,t),this._setPageNumber(r,e,t)),i}createFrontpage(){if(!this._frontpageTemplate)return void(this._debug&&console.warn("[paper • createFrontpage()] called without a template"));const e=this._node.create(this._frontpageElementSelector);this._DOM.setStyles(e,{height:this.bodyHeight+"px",display:"inline-block",width:"100%","vertical-align":"top"});const t=this._createFrontpageContent(this._frontpageTemplate,this._frontpageFactor);return this._DOM.setStyles(t,{display:"flow-root","transform-origin":"top center",height:"100%"}),this._DOM.insertAtStart(e,t),e}createVirtualTopMargin(){return this._node.create(this._virtualPaperTopMarginSelector)}createVirtualBottomMargin(){return this._node.create(this._virtualPaperBottomMarginSelector)}createVirtualPaper(e){const t=this._node.create(this._virtualPaperSelector);return e&&this._DOM.insertAtEnd(t,this.createVirtualTopMargin(),e,this.createVirtualBottomMargin()),t}_createFrontpageContent(e,t){const i=this._node.create(this._frontpageContentSelector);return e&&this._DOM.setInnerHTML(i,e),t&&this._DOM.setStyles(i,{transform:`scale(${t})`}),i}_createPageBodySpacer(e,t){const i=this._node.create(this._pageBodySpacerSelector);return this._DOM.setStyles(i,{height:e+"px"}),t&&this._DOM.insertAtEnd(i,t),i}_createPageHeader(e){const t=this._node.create(this._pageHeaderSelector);if(e){const i=this._node.create(this._headerContentSelector);this._DOM.setInnerHTML(i,e),this._DOM.insertAtEnd(t,i)}return t}_createPageFooter(e){const t=this._node.create(this._pageFooterSelector);if(e){const i=this._node.create(this._footerContentSelector);this._DOM.setInnerHTML(i,e),this._DOM.insertAtEnd(t,i)}return t}_setPageNumber(e,t,i){const o=this._pageNumberRootSelector?this._DOM.getElement(this._pageNumberRootSelector,e):this._pageNumberRootSelector;if(o){const e=this._DOM.getElement(this._pageNumberCurrentSelector,o),n=this._DOM.getElement(this._pageNumberTotalSelector,o);this._DOM.setInnerHTML(e,t),this._DOM.setInnerHTML(n,i)}}_calculatePaperParams(){const e=this._createPageBodySpacer(),t=this._createPageHeader(this._headerTemplate),i=this._createPageFooter(this._footerTemplate),o=this._node.create(this._virtualPaperSelector);this._DOM.insertAtEnd(o,this.createVirtualTopMargin(),t,e,i,this.createVirtualBottomMargin());const n=this._node.create("#workbench");this._DOM.setStyles(n,{position:"absolute",left:"-3000px"}),this._DOM.insertAtEnd(n,o),this._DOM.insertAtStart(this._DOM.body,n);const r=this._DOM.getElementBCR(o).height,s=this._DOM.getElementBCR(t).height||0,a=this._DOM.getElementBCR(i).height||0,l=this._DOM.getElementBCR(e).height,h=this._DOM.getElementBCR(e).width,c=this._createFrontpageContent(this._frontpageTemplate);this._DOM.insertAtStart(e,c);const d=this._DOM.getElementBCR(e).height,g=d>l?l/d:1;this._DOM.removeNode(n),s>.2*r&&console.warn("It seems that your custom header is too high"),a>.15*r&&console.warn("It seems that your custom footer is too high"),g<1&&console.warn("It seems that your frontpage content is too large. We made it smaller to fit on the page. Check out how it looks! It might make sense to fix this with styles or reduce the text amount."),this._paperHeight=r,this.headerHeight=s,this.footerHeight=a,this.bodyHeight=l,this.bodyWidth=h,this._frontpageFactor=g}}class rn{constructor({config:e,DOM:t,selector:o,node:n,pages:r,layout:s,paper:a}){this._config=e,this._debug=e.debugMode?{...e.debugConfig.preview}:{},this._assert=!!e.consoleAssert,Object.assign(this,i),this._accumulatedAssertions={},this._DOM=t,this._selector=o,this._node=n,this._virtualPaperGapSelector=o.virtualPaperGap,this._runningSafetySelector=o.runningSafety,this._printPageBreakSelector=o.printPageBreak,this._pageDivider=o.pageDivider,this._virtualPaper=o.virtualPaper,this._virtualPaperTopMargin=o.virtualPaperTopMargin,this._pageBodySpacer=o.pageBodySpacer,this._pages=r,this._root=s.root,this._contentFlow=s.contentFlow,this._paperFlow=s.paperFlow,this._overlayFlow=s.overlayFlow,this._paper=a,this._hasFrontPage=!!s.frontpageTemplate}create(){return this._processFrontPage(),this._processPages(),(!0===this._config.mask||"true"===this._config.mask)&&this._addMask(),this._makeRootVisible(),this._accumulatedAssertions}_addMask(){const e=parseInt(this._config.virtualPagesGap),t=parseInt(this._config.paperHeight),i=parseInt(this._config.printTopMargin),o=parseInt(this._config.printBottomMargin),n=parseInt(this._config.headerMargin),r=parseInt(this._config.footerMargin),s=this._paper.headerHeight,a=this._paper.footerHeight,l=this._paper.bodyHeight,h=s?Math.ceil(n/2):0,c=a?Math.ceil(r/2):0,d=s-h,g=a-c,u=l+h+c,p=i+d,_=t+e;this.strictAssert(t===u+d+i+g+o,"Paper size calculation params do not match");const f=function({maskStep:e,maskWindow:t,maskFirstShift:i}){return`\n -webkit-mask-image: linear-gradient(\n black 0,\n black ${t}px,\n transparent ${t}px,\n transparent ${e}px\n );\n mask-image: linear-gradient(\n black 0,\n black ${t}px,\n transparent ${t}px,\n transparent ${e}px\n );\n -webkit-mask-repeat: no-repeat;\n mask-repeat: no-repeat;\n -webkit-mask-size: 100% ${e}px;\n mask-size: 100% ${e}px;\n -webkit-mask-position: 100% ${i}px;\n mask-position: 100% ${i}px;\n -webkit-mask-repeat: repeat-y;\n mask-repeat: repeat-y;\n -webkit-mask-origin: border-box;\n mask-origin: border-box;\n `}({maskFirstShift:p,maskStep:_,maskWindow:u}),m=`\n @media screen {\n ${this._selector.contentFlow} {\n ${f}\n }\n }\n @media print {\n ${this._selector.root}::after {\n /* Safety placeholder for the bottom margin of the paper.\n Remove if the margins at the bottom of the page are replaced with padding.\n Placed under the footer.\n */\n --paper-color: ${this._config.paperColor};\n background: var(--paper-color, white);\n content: '';\n position: fixed;\n pointer-events: none;\n z-index: 11;\n inset: 0;\n top: unset;\n height: ${o+a}px;\n }\n }`;this._node.insertStyle(m,"mask")}_makeRootVisible(){this._DOM.setStyles(this._root,{visibility:"visible"})}_processFrontPage(){if(this._hasFrontPage){const e=this._paper.createFrontpage();this._DOM.insertAtStart(this._contentFlow,e),this._pages.unshift({pageStart:e,pageEnd:e}),this._pages[1].prevPageEnd=e}}_processPages(){for(let e=0;e0&&this._debug._&&console.warn(`[preview] There is no page end element before ${e}. Perhaps it's a 'beginningTail'.`)}_createPageBreaker(e,t){const i=this._node.create(this._pageDivider);return this._DOM.setAttribute(i,"[page]",`${e+1}`),this._node.registerPageDivider(i,e+1),t&&this._paper.footerHeight&&this._DOM.setStyles(i,{marginTop:this._paper.footerHeight+"px"}),this._paper.headerHeight&&this._DOM.setStyles(i,{paddingBottom:this._paper.headerHeight+"px"}),i}_updatePageNumberElementAttrValue(e){this._hasFrontPage&&this._node.markPageStart(this._pages[e].pageStart,`${e+1}`),this._node.markPageEnd(this._pages[e].pageEnd,`${e+1}`)}_insertPaper(e,t,i){i?this._DOM.insertAtEnd(e,i,t):this._DOM.insertAtEnd(e,t)}_createVirtualPaperGap(){return this._node.create(this._virtualPaperGapSelector)}_createVirtualPaperTopMargin(){return this._paper.createVirtualTopMargin()}_createVirtualPaperBottomMargin(){return this._paper.createVirtualBottomMargin()}_insertFrontpageSpacer(e,t){const i=this._node.create();return this._DOM.setStyles(i,{paddingBottom:t+"px"}),this._DOM.setAttribute(i,".printFrontpageSpacer"),this._DOM.insertAtStart(e,i),i}_insertHeaderSpacer(e,t){const i=this._DOM.createDocumentFragment(),o=this._node.create(this._runningSafetySelector);this._DOM.insertAtEnd(i,this._createVirtualPaperTopMargin(),o),this._DOM.insertAtEnd(e,i)}_insertFooterSpacer({target:e,footerHeight:t,pageSeparator:i,paperSeparator:o,pageIndex:n}){const r=this._DOM.createDocumentFragment(),s=this._createVirtualPaperGap(),a=this._node.create(this._runningSafetySelector);this._DOM.insertAtEnd(r,a,this._createVirtualPaperBottomMargin(),this._node.create(this._printPageBreakSelector),s),this._DOM.insertAtStart(e,r),this._balanceFooter({balancingFooter:a,contentSeparator:s,pageSeparator:i,paperSeparator:o,pageIndex:n})}_balanceFooter({balancingFooter:e,contentSeparator:t,pageSeparator:i,paperSeparator:o,pageIndex:n}){const r=this._node.getTop(i,this._root),s=this._node.getTop(o,this._root),a=this._node.getTop(t,this._root);this.strictAssert(s==r,"balancers in paper layers are misaligned",{pageIndex:n,balancingFooter:e,contentSeparator:t,pageSeparator:i,paperSeparator:o,paperSeparatorTop:s,pageSeparatorTop:r});const l=r-a;this._debug._&&console.log({balancingFooter:e,contentSeparatorTop:a,paperSeparatorTop:s,pageSeparatorTop:r}),this._DOM.setStyles(e,{"margin-bottom":l+"px"});l<-1&&(this._debug._&&console.warn(`[pages: ${n}-${n+1}] balancer is negative: ${l} < 0. Submitted to the Validator.`,t),this._accumulatedAssertions[n]={balancer:l,contentSeparator:t,pageNumber:n})}}class sn{constructor({config:e,DOM:t,selector:i,node:o,layout:n}){this._globalDebugMode=e.debugMode,this._debug=e.debugMode?{...e.debugConfig.toc}:{},this._assert=!!e.consoleAssert,this._DOM=t,this._node=o,this._tocPageNumberSelector=e.tocPageNumberSelector,this._root=n.root,this._contentFlow=n.contentFlow,this._pageDividerSelector=i.pageDivider}render(){this._globalDebugMode&&console.time("Processing TOC"),this._debug._&&console.log(`\n📑 TOC: I am here!\n\ntocPageNumberSelector:\n • ${this._tocPageNumberSelector}\n pageDividerSelector:\n • ${this._pageDividerSelector}\n `);const e=this._DOM.getAll(this._tocPageNumberSelector,this._contentFlow);if(this._debug._&&console.log("📑 tocPageNumberBoxes",e.length),!e.length)return void(this._debug._&&console.log("📑 no valid toc"));const t=this._node.getRegisteredPageDividers?.(),i=(t&&t.size?[...t.entries()]:this._DOM.getAll(this._pageDividerSelector,this._contentFlow).map((e,t)=>[t+1,e])).reduce((e,[t,i])=>{const o=this._node.getTop(i,this._root)-1,n=String(t);return e[o]=n,e},{});this._debug._&&console.log("📑 dataFromPagesMarkers",i);const o=e.reduce((e,t)=>{const i=this._DOM.getDataId(t),o=this._DOM.getElementById(i),n=this._node.getTop(o,this._root);return e[n]={box:t,id:i,targetTop:n},e},{});this._debug._&&console.log("📑 dataFromTOC",o);const n={...i,...o};let r=0;this._debug._&&console.groupCollapsed("Processing obj");for(const e in n){const t=n[e];this._debug._&&console.log(`Processing ${e}: ${t}`),"string"==typeof t?r=t:(t.page=r,this._DOM.setInnerHTML(t.box,r))}this._debug._&&console.groupEnd("Processing obj"),this._debug._&&console.log("📑 tocObject",n),this._globalDebugMode&&console.timeEnd("Processing TOC")}}class an{constructor({config:e,DOM:t,selector:o,node:n,layout:r,pages:s,previewValidations:a}){this._config=e,this._selector=o,this._DOM=t,this._node=n,this._layout=r,this._root=r.root,this._pageCount=s.length,this._accumulatedAssertions=a,this._assert=!!e.consoleAssert,Object.assign(this,i)}init(){this._config.debugMode&&console.log("🐙 i am Validator!");const e=this._collectPageOverflowAssertions();for(const[t,i]of Object.entries(e))this._accumulatedAssertions[t]={...this._accumulatedAssertions[t]||{},...i};this.strictAssert(0===Object.keys(this._accumulatedAssertions).length,"Page overflow detected:",this._accumulatedAssertions)}_collectPageOverflowAssertions(){const e=`${this._selector.paperFlow} ${this._selector.virtualPaperGap}`,t=`${this._selector.contentFlow} ${this._selector.virtualPaperGap}`,i=(this._selector.contentFlow,this._selector.contentFlowEnd,`${this._selector.pageChrome} ${this._selector.pageBodySpacer}`),o={},n=[...this._DOM.getAllElements(e)],r=[...this._DOM.getAllElements(t)];this._assertElementsCount(this._pageCount-1,{paperGapElements:n,pageGapElements:r});const s=n.map(e=>this._node.getTop(e,this._root)),a=r.map(e=>this._node.getTop(e,this._root));for(let e=0;ee?this._node.getBottom(e,this._root):void 0),u=c.map(e=>e?this._node.getBottom(e,this._root):void 0);for(let e=0;e{e<=.1&&(clearInterval(t),this._preloader.remove()),this._preloader.style.opacity=e,e-=.1*e},50);this._debugMode&&console.log("%c Preloader removed ",ln)}_insertStyle(){const e=document.querySelector("head"),t=document.createElement("style");t.append(document.createTextNode(this._css())),t.setAttribute("data-preloader-style",""),e.append(t)}_css(){return`\n /* PRELOADER */\n .lds-dual-ring {\n position: absolute;\n z-index: 99999;\n top: 0; left: 0; bottom: 0; right: 0;\n background: ${this._preloaderBackground};\n display: flex;\n justify-content: center;\n align-items: center;\n }\n /*\n .lds-dual-ring:after {\n content: " ";\n display: block;\n width: 64px;\n height: 64px;\n margin: 8px;\n border-radius: 50%;\n border: 6px solid #eee;\n border-color: #eee transparent #eee transparent;\n animation: lds-dual-ring 1.2s linear infinite;\n }\n @keyframes lds-dual-ring {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n }\n */\n `}_resolveTarget(e){const t=(e.preloaderTarget||"").trim();return t&&document.querySelector(t)}}class cn{constructor(e){this._debugMode=e.debugMode}run(){let e=[...document.querySelectorAll("object")];this._debugMode&&console.log(e);let t=[];return e.forEach(e=>{const i=new Promise(t=>{e.addEventListener("load",i=>{this._debugMode&&console.log("⏰ EVENT: object load",e.clientHeight,e.clientWidth,e),t()})});t.push(i)}),Promise.all(t)}}const dn=e=>!0===e||"true"===e;function gn(e){const t=Array.isArray(e)?[]:{};return Object.entries(e).forEach(([e,i])=>{t[e]=!i||"object"!=typeof i||gn(i)}),t}const un={DOM:{_:!1},layout:{_:!1},pages:{_:!1,_parseNode:!1,_parseNodes:!1,_registerPageStart:!1},paper:{_:!1},preview:{_:!1},toc:{_:!1},node:{_:!1,children:!1,creators:!1,flowFilters:!1,fitters:!1,getters:!1,markers:!1,pageBreaks:!1,positioning:!1,selectors:!1,selectorHeuristics:!1,slicers:!1,splitters:!1,wrappers:!1,pagination:!1},paragraph:{_:!1},grid:{_:!1},pre:{_:!1},table:{_:!1},tableLike:{_:!1},testSignals:{forcedModeLog:!1}};function pn(e){const t=function(e){let t={debugMode:!1,forcedDebugMode:!1,consoleAssert:!1,markupDebugMode:!1,preloader:!1,preloaderTarget:"",preloaderBackground:"",mask:!0,noHangingSelectors:"",forcedPageBreakSelectors:"",pageBreakBeforeSelectors:"",pageBreakAfterSelectors:"",noBreakSelectors:"",tocPageNumberSelector:"html2pdf4doc-toc-page-number",printLeftMargin:"21mm",printRightMargin:"21mm",printTopMargin:"12mm",printBottomMargin:"12mm",printFontSize:"12pt",paperColor:"white",paperWidth:"210mm",paperHeight:"297mm",headerMargin:"16px",footerMargin:"16px",virtualPagesGap:"16px",splitLabelHeight:"24px"};const i={paperWidth:"210mm",paperHeight:"297mm"},o={paperWidth:"148.5mm",paperHeight:"210mm"};switch((e=function(e){const t={...e};for(const e in t){const i=t[e];if("string"==typeof i){const o=i.toLowerCase();"true"===o||"1"===o?t[e]=!0:"false"!==o&&"0"!==o&&""!==o||(t[e]=!1)}}return t}(e)).printPaperSize){case"A5":case"a5":t={...t,...o};break;default:t={...t,...i}}t={...t,initialRoot:R(N.init),tocPageNumberSelector:R(N.tocPageNumber),...e},console.info("[HTML2PDF4DOC] Config:",t);const n={printLeftMargin:t.printLeftMargin,printRightMargin:t.printRightMargin,printTopMargin:t.printTopMargin,printBottomMargin:t.printBottomMargin,printFontSize:t.printFontSize,paperWidth:t.paperWidth,paperHeight:t.paperHeight,headerMargin:t.headerMargin,footerMargin:t.footerMargin,virtualPagesGap:t.virtualPagesGap},r=document.createElement("div");return r.style="\n position:absolute;\n z-index:1000;\n left: 200%;\n ",document.body.append(r),Object.entries(n).forEach(([e,t])=>{r.style.width=t,n[e]=`${Math.trunc(r.getBoundingClientRect().width)}px`}),r.remove(),t={...t,...n},t.noHangingSelectors=t.noHangingSelectors+" H1 H2 H3 H4 H5 H6",t.forcedPageBreakSelectors=t.forcedPageBreakSelectors+" "+R(N.printForcedPageBreak),t.debugMode&&console.info("Config with converted units:",t),t}(e);t.forcedDebugMode&&(t.debugMode=!0,t.consoleAssert=!0,t.markupDebugMode=!0);const i=t.forcedDebugMode?gn(un):un;return{...t,debugConfig:i}}const _n="color:Gray;border:1px solid;";console.info("[HTML2PDF4DOC] Version:","0.3.0");const fn=document.currentScript.dataset,mn=new class{constructor(e){this.params=function(e={}){const t={...e};return[["printWidth","paperWidth","data-print-width","data-paper-width"],["printHeight","paperHeight","data-print-height","data-paper-height"]].forEach(([e,i,o,n])=>{Object.prototype.hasOwnProperty.call(t,e)&&(console.warn(`[HTML2PDF4DOC] Config option "${o}" is deprecated. Use "${n}" instead.`),Object.prototype.hasOwnProperty.call(t,i)||(t[i]=t[e]),delete t[e])}),t}(e),this.forcedDebugMode=dn(e.forcedDebugMode),this.debugMode=dn(e.debugMode)||this.forcedDebugMode,this.preloader=e.preloader,this.selector=N,this.config}async render(){console.time("[HTML2PDF4DOC] Total time"),this.debugMode&&console.log("🏁 document.readyState",document.readyState),document.addEventListener("readystatechange",e=>{this.debugMode&&console.log("🏁 readystatechange",document.readyState)}),this.debugMode&&console.time("⏱️ await DOMContentLoaded time"),await new Promise(e=>{window.addEventListener("DOMContentLoaded",t=>{this.debugMode&&console.log("⏰ EVENT: DOMContentLoaded"),e()})}),this.debugMode&&console.timeEnd("⏱️ await DOMContentLoaded time"),this.debugMode&&console.time("⏱️ create Preloader time");const e=new hn(this.params);"true"===this.preloader&&e.create(),this.debugMode&&console.timeEnd("⏱️ create Preloader time"),this.debugMode&&console.time("⏱️ Config time"),this.debugMode&&console.groupCollapsed("%c config ",_n+"color:LightGray"),this.config=pn(this.params),this.debugMode&&console.groupEnd(),this.debugMode&&console.info("⚙️ Current config with debugConfig:",this.config),this.debugMode&&console.timeEnd("⏱️ Config time"),this.config.debugConfig.testSignals.forcedModeLog&&console.info("[HTML2PDF4DOC] 🛠️ Forced debug mode is active."),this.config.consoleAssert&&console.info("[HTML2PDF4DOC] 🧧 Assertions enabled."),this.debugMode&&console.time("⏱️ DOM helpers init time");const t=new I({DOM:window.document,config:this.config});this.debugMode&&console.timeEnd("⏱️ DOM helpers init time"),this.debugMode&&console.time("⏱️ node helpers init time");const i=new Xo({config:this.config,DOM:t,selector:this.selector});this.debugMode&&console.timeEnd("⏱️ node helpers init time"),this.debugMode&&console.time("⏱️ await window load time"),await new Promise(e=>{window.addEventListener("load",t=>{this.debugMode&&console.log("⏰ EVENT: window load"),e()})}),this.debugMode&&console.timeEnd("⏱️ await window load time"),this.debugMode&&console.time("⏱️ Layout time"),this.debugMode&&console.groupCollapsed("%c Layout ",_n);const o=new $({config:this.config,DOM:t,selector:this.selector,node:i});if(o.create(),this.debugMode&&console.groupEnd(),this.debugMode&&console.timeEnd("⏱️ Layout time"),!o.success)return void(this.debugMode&&console.error("Failed to create layout.\n\nWe have to interrupt the process of creating PDF preview."));this.debugMode&&console.info("%c calculate Paper params ",_n),this.debugMode&&console.time("⏱️ Paper time");const n=new nn({config:this.config,DOM:t,selector:this.selector,node:i,layout:o});if(this.debugMode&&console.timeEnd("⏱️ Paper time"),!n||!n.bodyHeight||!n.bodyWidth)return void(this.debugMode&&console.error("Failed to create paper calculations.\n\nWe have to interrupt the process of creating PDF preview."));this.debugMode&&console.time("⏱️ Preprocess time"),this.debugMode&&console.groupCollapsed("%c Preprocess ",_n),await new cn(this.config).run(),this.debugMode&&console.groupEnd(),this.debugMode&&console.timeEnd("⏱️ Preprocess time"),this.debugMode&&console.time("⏱️ Pages time"),this.debugMode&&console.group("%c Pages ",_n);const r=new on({config:this.config,DOM:t,selector:this.selector,node:i,layout:o,referenceHeight:n.bodyHeight,referenceWidth:n.bodyWidth}).calculate();this.debugMode&&console.groupEnd(),this.debugMode&&console.timeEnd("⏱️ Pages time"),this.debugMode&&console.time("⏱️ Preview time"),this.debugMode&&console.groupCollapsed("%c Preview ",_n);const s=new rn({config:this.config,DOM:t,selector:this.selector,node:i,layout:o,paper:n,pages:r}).create();this.debugMode&&console.groupEnd(),this.debugMode&&console.timeEnd("⏱️ Preview time"),this.debugMode&&console.time("⏱️ Toc time"),new sn({config:this.config,DOM:t,selector:this.selector,node:i,layout:o}).render(),this.debugMode&&console.timeEnd("⏱️ Toc time"),this.debugMode&&console.time("⏱️ Validator time"),new an({config:this.config,DOM:t,selector:this.selector,node:i,layout:o,pages:r,previewValidations:s}).init(),this.debugMode&&console.timeEnd("⏱️ Validator time"),t.setAttribute(o.root,"[success]"),t.setAttribute(o.root,"[pages]",r.length),e.remove(),console.info("[HTML2PDF4DOC] Page count:",r.length),console.timeEnd("[HTML2PDF4DOC] Total time")}}(fn),bn="manual"===fn.init;function wn(){bn&&mn.render()}bn&&console.info("HTML2PDF4DOC in manual initialization mode"),!bn&&mn.render(),HTML2PDF4DOC=t})();
\ No newline at end of file
+const g=h??l;if(this._debug._parseNode&&console.log("[_parseNode]",{currentBlockBottom:g,currentParentBottomEdge:h,currentElementBottom:l}),this.pages.at(-1).pageStart===o&&(this._node.isNotBreakable(o)||g<=this.pages.at(-1).pageBottom))return this._node.markProcessed(o,"node is already registered and fits in the page"),this._debug._parseNode&&console.log("%c END _parseNode (node is already registered and fits in the next page)",un),void(this._debug._parseNode&&console.groupEnd());if(d>=this.pages.at(-1).pageBottom&&l-d){const t=e&&Boolean(r)?this._node.getTopForPageStartCandidate(r,this._root):void 0,i=Boolean(t)&&d-t>=this._referenceHeight;if(i)this._debug._parseNode&&console.log("🪁 beginning Tail",{parentTop:t,currentParentBottomEdge:h,currentElementTop:d,pageBottom:this.pages.at(-1).pageBottom},{currentElement:o,arrayTopParent:r});else{const e=this._DOM.getComputedStyle(o)?.display||"";if(e.includes("inline")||"contents"===e)return this._debug._parseNode&&console.log("🧅 current in thin wrapper"),this._registerPageStart({element:o,improveResult:!0,context:"🧅 current in thin wrapper"}),this._debug._parseNode&&console.log("%c END _parseNode (registered new page start)",un),void(this._debug._parseNode&&console.groupEnd())}this._registerPageStart({element:o,improveResult:!i,context:"currentElementTop >= this.pages.at(-1).pageBottom"})}if(this._node.isForcedPageBreak(o))return this._registerPageStart({element:o,context:"currentElement is ForcedPageBreak"}),this._node.markProcessed(o,"node is ForcedPageBreak"),this._debug._parseNode&&console.log("%c END _parseNode (isForcedPageBreak)",un),void(this._debug._parseNode&&console.groupEnd());this.strictAssert(this._DOM.getElementOffsetParent(o),"it is expected that the element has an offset parent",o);const u=this._node.getTop(n,this._root);if(this._debug._parseNode&&console.log(...a,"• pageBottom",this.pages.at(-1).pageBottom,"\n","• nextElementTop",u),u<=this.pages.at(-1).pageBottom)return this._debug._parseNode&&console.log("nextElementTop <= this.pages.at(-1).pageBottom",u,"<=",this.pages.at(-1).pageBottom),this._node.markProcessed(o,"node fits"),this._node.findAllForcedPageBreakInside(o).forEach(e=>{this._node.markProcessed(e,"node is ForcedPageBreak (inside a node that fits)"),this._registerPageStart({element:e,context:"All Forced Page Break Inside currentElement"})}),this._debug._parseNode&&console.log("%c END _parseNode (node pass)",un),void(this._debug._parseNode&&console.groupEnd());{if(this._debug._parseNode&&console.log("nextElementTop > this.pages.at(-1).pageBottom",u,">",this.pages.at(-1).pageBottom),g<=this.pages.at(-1).pageBottom)return this._debug._parseNode&&console.log("currentBlockBottom <= this.pages.at(-1).pageBottom",g,"<=",this.pages.at(-1).pageBottom,"\n register nextElement as pageStart"),this._node.isNoHanging(o)?(this._debug._parseNode&&console.log("currentElement fits / last, and _isNoHanging => move it to the next page"),this._node.markProcessed(o,"it fits & last & _isNoHanging => move it to the next page"),this._registerPageStart({element:o,improveResult:!0,context:"currentElement is NoHanging"}),this._debug._parseNode&&console.log("%c END _parseNode (isNoHanging)",un),void(this._debug._parseNode&&console.groupEnd())):(this._registerPageStart({element:n,type:"next",context:"currentBlockBottom <= PgBtt && nextElementTop > PgBtt"}),this._node.markProcessed(o,"fits, its bottom falls exactly on the cut"),this._node.markProcessed(n,"starts new page, its top is exactly on the cut"),this._debug._parseNode&&console.log("%c END _parseNode (currentElement fits, register the next element)",un),void(this._debug._parseNode&&console.groupEnd()));const t=this._node.resolveReplacedElement(o,{prefer:"first"});if(t){const i=this._node.isSVG(t),s=i?this._node.createSignpost(t):t,a=this._node.getTop(s,this._root),l=this._node.getBottom(s,this._root),d=e&&r?this._node.getTop(r,this._root):void 0,g=r||this._DOM.getParentNode(s),u=this._node.estimateInlineImgGapBelow(g);let p=this.pages.at(-1).pageBottom-a-u;p-=c?c-l:0;const _=this._DOM.getElementOffsetHeight(s),f=this._DOM.getElementOffsetWidth(s);if(this._debug._parseNode&&console.log("🖼️🖼️🖼️🖼️🖼️🖼️ (if mediaElement)",t,{_imageParent:g,arrayTopParent:r,arrayParentBottomEdge:c,availableImageNodeSpace:p,currentParentBottomEdge:h,currentElement:o,currentImage:s,currentImageHeight:_,currentImageWidth:f,isSvgMedia:i,imgGapBelow:u,parentTopForImage:d}),f>this._referenceWidth&&this._debug._parseNode&&console.warn("%c IMAGE is too wide","color: red"),_this._imageReductionRatio)return this._debug._parseNode&&console.log("Register next elements; 🖼️🖼️🖼️ IMG RESIZE to availableImageNodeSpace:",p,o),this._node.markProcessed(o,`IMG with ratio ${m}, and next starts on next`),this._node.fitElementWithinBoundaries({element:t,height:_,width:f,vspace:p,hspace:this._referenceWidth}),this._registerPageStart({element:n,type:"next",context:"current IMG was RESIZED to availableImageNodeSpace"}),this._debug._parseNode&&console.log("%c END _parseNode 🖼️ IMG scaled",un),void(this._debug._parseNode&&console.groupEnd());this._node.markProcessed(o,"IMG starts on next");const b=i?s:t;this._registerPageStart({element:b,improveResult:!0,context:"move IMG it to next page"}),this._debug._parseNode&&console.log("🖼️ register Page Start",o);let w=this.pages.at(-1).pageBottom-a-u;const S=c?null:this._node.findLastChildParent(o,this._contentFlow),M=c||this._node.getBottom(S||o,this._root);return M>l&&(w-=M-l),_>w&&(this._node.fitElementWithinBoundaries({element:t,height:_,width:f,vspace:w,hspace:this._referenceWidth}),this._node.markProcessed(o,"IMG starts on next and resized"),this._debug._parseNode&&console.log("🖼️ ..and fit it to full page",o)),this._debug._parseNode&&console.log("%c END",un),void(this._debug._parseNode&&console.groupEnd())}if(o.style.height){this._debug._parseNode&&console.log("🥁 currentElement has HEIGHT",o.style.height);const e=this.pages.at(-1).pageBottom-d,t=u-d,i=e/t,r=this._referenceHeight/t;this._debug._parseNode&&console.log("\n🥁 currentElementTop",d,"\n🥁 pageBottom",this.pages.at(-1).pageBottom,"\n🥁 availableSpace",e,"\n🥁 currentElementContextualHeight",t,"\n🥁 availableSpaceFactor",i,"\n🥁 fullPageFactor",r),this.strictAssert(i<1);const s=e=>{this._DOM.setStyles(o,{transform:`scale(${e})`,"transform-origin":"top center"});const i=Math.max(0,Math.trunc(t*e)),n=this._DOM.getParentNode(o);if(n&&this._node.isNeutral(n))return void this._DOM.setStyles(n,{height:`${i}px`});const r=this._node.createNeutral();this._DOM.setStyles(r,{display:"inline-block",verticalAlign:"top",width:"100%",height:`${i}px`}),this._DOM.wrap(o,r)};return i>.8?(this._debug._parseNode&&console.log("🥁 availableSpaceFactor > 0.8: ",i),s(i),this._registerPageStart({element:n,type:"next",context:"IMMEDIATELY scale currentElement to the remaining space; availableSpaceFactor > 0.8; currentElement.style.height"}),this._node.markProcessed(o,"processed as a image, has been scaled down within 20%, the next one starts a new page"),this._node.markProcessed(n,"the previous one was scaled down within 20%, and this one starts a new page."),this._debug._parseNode&&console.log("%c END _parseNode (has height & scale)",un),void(this._debug._parseNode&&console.groupEnd())):(r<1&&(this._debug._parseNode&&console.log("🥁 fullPageFactor < 1: ",r),this._node.markProcessed(o,"processed as a image, has been scaled down, and starts new page"),s(r)),this._debug._parseNode&&console.log("🥁 _registerPageStart",o),this._registerPageStart({element:o,improveResult:!0,context:'has height & processed "as a image", has been scaled down, and starts new page'}),this._node.markProcessed(o,"processed as a image, starts new page"),this._debug._parseNode&&console.log("%c END _parseNode (has height & put on next page)",un),void(this._debug._parseNode&&console.groupEnd()))}if(this._debug._parseNode&&console.log("split or not? \n","currentBlockBottom",g),this._debug._parseNode&&console.log("currentParentBottomEdge || currentElementBottom",{currentParentBottomEdge:h,currentElementBottom:l},"currentBlockBottom > this.pages.at(-1).pageBottom",g,">",this.pages.at(-1).pageBottom),this._DOM.getElementOffsetHeight(o) this.pages.at(-1).pageBottom"}),this._node.markProcessed(o,"starts new page, #fewLines"),this._debug._parseNode&&console.log("%c END _parseNode #fewLines",un),void(this._debug._parseNode&&console.groupEnd());const p=this._node.getSplitChildren(o,this.pages.at(-1).pageBottom,this._referenceHeight,this._root);this._debug._parseNode&&console.log("try to break it and loop the children:",p);if(p.length){const e=r||o,t=s||o,a=this._node.isSliced(o)||this._node.isSlough(o);this._debug._parseNode&&console.log({isSlicedParent:a,arrayTopParent:r}),this._parseNodes({array:p,previous:i,next:n,arrayTopParent:a?void 0:e,arrayBottomParent:a?void 0:t}),this._node.markProcessed(o,"getSplitChildren and _parseNodes")}else this._debug._parseNode&&console.log(...a,"_registerPageStart (from _parseNode): \n",o),this._registerPageStart({element:o,improveResult:!0,context:"does not fit, has no children, register it (or parents if improved)"}),this._node.markProcessed(o,"doesn't fit, has no children, register it or parents")}this._debug._parseNode&&console.log("%c END _parseNode [•••]",un,{currentElement:o}),this._debug._parseNode&&console.groupEnd()}}class _n{constructor({config:e,DOM:t,node:i,selector:o,layout:n}){this._debug=e.debugMode?{...e.debugConfig.paper}:{},this._DOM=t,this._selector=o,this._node=i,this._frontpageTemplate=n.frontpageTemplate,this._headerTemplate=n.headerTemplate,this._footerTemplate=n.footerTemplate,this._pageChromeSelector=o?.pageChrome||".pageChrome",this._pageBodySpacerSelector=o?.pageBodySpacer||".pageBodySpacer",this._pageHeaderSelector=o?.pageHeader||".pageHeader",this._pageFooterSelector=o?.pageFooter||".pageFooter",this._headerContentSelector=o?.headerContent||".headerContent",this._footerContentSelector=o?.footerContent||".footerContent",this._frontpageElementSelector=o?.frontpageElement||".frontpageElement",this._frontpageContentSelector=o?.frontpageContent||".frontpageContent",this._virtualPaperSelector=o?.virtualPaper||".virtualPaper",this._virtualPaperTopMarginSelector=o?.virtualPaperTopMargin||".virtualPaperTopMargin",this._virtualPaperBottomMarginSelector=o?.virtualPaperBottomMargin||".virtualPaperBottomMargin",this._pageNumberRootSelector=o?.pageNumberRoot?N(o.pageNumberRoot):void 0,this._pageNumberCurrentSelector=o?.pageNumberCurrent?N(o.pageNumberCurrent):void 0,this._pageNumberTotalSelector=o?.pageNumberTotal?N(o.pageNumberTotal):void 0,this._paperHeight,this._frontpageFactor,this.headerHeight,this.footerHeight,this.bodyHeight,this.bodyWidth,this._calculatePaperParams()}createPageChrome({pageNumber:e,pageCount:t}){const i=this._node.create(this._pageChromeSelector);this._node.markPageNumber(i,e);const o=this._composePageElements({pageNumber:e,pageCount:t});return this._DOM.insertAtEnd(i,o),i}_composePageElements({pageNumber:e,pageCount:t}){const i=this._DOM.createDocumentFragment(),o=this._createPageBodySpacer(this.bodyHeight);this._node.markPageNumber(o,e);const n=this._createPageHeader(this._headerTemplate),r=this._createPageFooter(this._footerTemplate);return this._DOM.insertAtEnd(i,this.createVirtualTopMargin(),n,o,r,this.createVirtualBottomMargin()),e&&t&&(this._setPageNumber(n,e,t),this._setPageNumber(r,e,t)),i}createFrontpage(){if(!this._frontpageTemplate)return void(this._debug&&console.warn("[paper • createFrontpage()] called without a template"));const e=this._node.create(this._frontpageElementSelector);this._DOM.setStyles(e,{height:this.bodyHeight+"px",display:"inline-block",width:"100%","vertical-align":"top"});const t=this._createFrontpageContent(this._frontpageTemplate,this._frontpageFactor);return this._DOM.setStyles(t,{display:"flow-root","transform-origin":"top center",height:"100%"}),this._DOM.insertAtStart(e,t),e}createVirtualTopMargin(){return this._node.create(this._virtualPaperTopMarginSelector)}createVirtualBottomMargin(){return this._node.create(this._virtualPaperBottomMarginSelector)}createVirtualPaper(e){const t=this._node.create(this._virtualPaperSelector);return e&&this._DOM.insertAtEnd(t,this.createVirtualTopMargin(),e,this.createVirtualBottomMargin()),t}_createFrontpageContent(e,t){const i=this._node.create(this._frontpageContentSelector);return e&&this._DOM.setInnerHTML(i,e),t&&this._DOM.setStyles(i,{transform:`scale(${t})`}),i}_createPageBodySpacer(e,t){const i=this._node.create(this._pageBodySpacerSelector);return this._DOM.setStyles(i,{height:e+"px"}),t&&this._DOM.insertAtEnd(i,t),i}_createPageHeader(e){const t=this._node.create(this._pageHeaderSelector);if(e){const i=this._node.create(this._headerContentSelector);this._DOM.setInnerHTML(i,e),this._DOM.insertAtEnd(t,i)}return t}_createPageFooter(e){const t=this._node.create(this._pageFooterSelector);if(e){const i=this._node.create(this._footerContentSelector);this._DOM.setInnerHTML(i,e),this._DOM.insertAtEnd(t,i)}return t}_setPageNumber(e,t,i){const o=this._pageNumberRootSelector?this._DOM.getElement(this._pageNumberRootSelector,e):this._pageNumberRootSelector;if(o){const e=this._DOM.getElement(this._pageNumberCurrentSelector,o),n=this._DOM.getElement(this._pageNumberTotalSelector,o);this._DOM.setInnerHTML(e,t),this._DOM.setInnerHTML(n,i)}}_calculatePaperParams(){const e=this._createPageBodySpacer(),t=this._createPageHeader(this._headerTemplate),i=this._createPageFooter(this._footerTemplate),o=this._node.create(this._virtualPaperSelector);this._DOM.insertAtEnd(o,this.createVirtualTopMargin(),t,e,i,this.createVirtualBottomMargin());const n=this._node.create("#workbench");this._DOM.setStyles(n,{position:"absolute",left:"-3000px"}),this._DOM.insertAtEnd(n,o),this._DOM.insertAtStart(this._DOM.body,n);const r=this._DOM.getElementBCR(o).height,s=this._DOM.getElementBCR(t).height||0,a=this._DOM.getElementBCR(i).height||0,l=this._DOM.getElementBCR(e).height,c=this._DOM.getElementBCR(e).width,h=this._createFrontpageContent(this._frontpageTemplate);this._DOM.insertAtStart(e,h);const d=this._DOM.getElementBCR(e).height,g=d>l?l/d:1;this._DOM.removeNode(n),s>.2*r&&console.warn("It seems that your custom header is too high"),a>.15*r&&console.warn("It seems that your custom footer is too high"),g<1&&console.warn("It seems that your frontpage content is too large. We made it smaller to fit on the page. Check out how it looks! It might make sense to fix this with styles or reduce the text amount."),this._paperHeight=r,this.headerHeight=s,this.footerHeight=a,this.bodyHeight=l,this.bodyWidth=c,this._frontpageFactor=g}}class fn{constructor({config:e,DOM:t,selector:o,node:n,pages:r,layout:s,paper:a,mutationQueue:l}){this._config=e,this._debug=e.debugMode?{...e.debugConfig.preview}:{},this._assert=!!e.consoleAssert,Object.assign(this,i),this._accumulatedAssertions={},this._DOM=t,this._selector=o,this._node=n,this._virtualPaperGapSelector=o.virtualPaperGap,this._runningSafetySelector=o.runningSafety,this._printPageBreakSelector=o.printPageBreak,this._pageDivider=o.pageDivider,this._virtualPaper=o.virtualPaper,this._virtualPaperTopMargin=o.virtualPaperTopMargin,this._pageBodySpacer=o.pageBodySpacer,this._pages=r,this._root=s.root,this._contentFlow=s.contentFlow,this._paperFlow=s.paperFlow,this._overlayFlow=s.overlayFlow,this._paper=a,this._mutationQueue=l,this._hasFrontPage=!!s.frontpageTemplate}create(){return this._mutationQueue?.flush(),this._processFrontPage(),this._processPages(),(!0===this._config.mask||"true"===this._config.mask)&&this._addMask(),this._makeRootVisible(),this._accumulatedAssertions}_addMask(){const e=parseInt(this._config.virtualPagesGap),t=parseInt(this._config.paperHeight),i=parseInt(this._config.printTopMargin),o=parseInt(this._config.printBottomMargin),n=parseInt(this._config.headerMargin),r=parseInt(this._config.footerMargin),s=this._paper.headerHeight,a=this._paper.footerHeight,l=this._paper.bodyHeight,c=s?Math.ceil(n/2):0,h=a?Math.ceil(r/2):0,d=s-c,g=a-h,u=l+c+h,p=i+d,_=t+e;this.strictAssert(t===u+d+i+g+o,"Paper size calculation params do not match");const f=function({maskStep:e,maskWindow:t,maskFirstShift:i}){return`\n -webkit-mask-image: linear-gradient(\n black 0,\n black ${t}px,\n transparent ${t}px,\n transparent ${e}px\n );\n mask-image: linear-gradient(\n black 0,\n black ${t}px,\n transparent ${t}px,\n transparent ${e}px\n );\n -webkit-mask-repeat: no-repeat;\n mask-repeat: no-repeat;\n -webkit-mask-size: 100% ${e}px;\n mask-size: 100% ${e}px;\n -webkit-mask-position: 100% ${i}px;\n mask-position: 100% ${i}px;\n -webkit-mask-repeat: repeat-y;\n mask-repeat: repeat-y;\n -webkit-mask-origin: border-box;\n mask-origin: border-box;\n `}({maskFirstShift:p,maskStep:_,maskWindow:u}),m=`\n @media screen {\n ${this._selector.contentFlow} {\n ${f}\n }\n }\n @media print {\n ${this._selector.root}::after {\n /* Safety placeholder for the bottom margin of the paper.\n Remove if the margins at the bottom of the page are replaced with padding.\n Placed under the footer.\n */\n --paper-color: ${this._config.paperColor};\n background: var(--paper-color, white);\n content: '';\n position: fixed;\n pointer-events: none;\n z-index: 11;\n inset: 0;\n top: unset;\n height: ${o+a}px;\n }\n }`;this._node.insertStyle(m,"mask")}_makeRootVisible(){this._DOM.setStyles(this._root,{visibility:"visible"})}_processFrontPage(){if(this._hasFrontPage){const e=this._paper.createFrontpage();this._DOM.insertAtStart(this._contentFlow,e),this._pages.unshift({pageStart:e,pageEnd:e}),this._pages[1].prevPageEnd=e}}_processPages(){for(let e=0;e{this._DOM.setStyles(e,{"margin-top":["0","important"]})})}else this.strictAssert(0,"[preview] [_preventPageOverflow] current page First Element do not pass! page:",e);if(i){this._DOM.setStyles(i,{"margin-bottom":["0","important"]});this._node.getBottomCollapseChain(i,this._root).forEach(e=>{this._DOM.setStyles(e,{"margin-bottom":["0","important"]})}),this._node.isIMG(i)&&this._DOM.setStyles(i,{"vertical-align":["top","important"]})}else e>0&&this._debug._&&console.warn(`[preview] There is no page end element before ${e}. Perhaps it's a 'beginningTail'.`)}_createPageBreaker(e,t){const i=this._node.create(this._pageDivider);return this._DOM.setAttribute(i,"[page]",`${e+1}`),this._node.registerPageDivider(i,e+1),t&&this._paper.footerHeight&&this._DOM.setStyles(i,{marginTop:this._paper.footerHeight+"px"}),this._paper.headerHeight&&this._DOM.setStyles(i,{paddingBottom:this._paper.headerHeight+"px"}),i}_updatePageNumberElementAttrValue(e){this._hasFrontPage&&this._node.markPageStart(this._pages[e].pageStart,`${e+1}`),this._node.markPageEnd(this._pages[e].pageEnd,`${e+1}`)}_insertPaper(e,t,i){i?this._DOM.insertAtEnd(e,i,t):this._DOM.insertAtEnd(e,t)}_createVirtualPaperGap(){return this._node.create(this._virtualPaperGapSelector)}_createVirtualPaperTopMargin(){return this._paper.createVirtualTopMargin()}_createVirtualPaperBottomMargin(){return this._paper.createVirtualBottomMargin()}_insertFrontpageSpacer(e,t){const i=this._node.create();return this._DOM.setStyles(i,{paddingBottom:t+"px"}),this._DOM.setAttribute(i,".printFrontpageSpacer"),this._DOM.insertAtStart(e,i),i}_insertHeaderSpacer(e,t){const i=this._DOM.createDocumentFragment(),o=this._node.create(this._runningSafetySelector);this._DOM.insertAtEnd(i,this._createVirtualPaperTopMargin(),o),this._DOM.insertAtEnd(e,i)}_insertFooterSpacer({target:e,footerHeight:t,pageSeparator:i,paperSeparator:o,pageIndex:n}){const r=this._DOM.createDocumentFragment(),s=this._createVirtualPaperGap(),a=this._node.create(this._runningSafetySelector);this._DOM.insertAtEnd(r,a,this._createVirtualPaperBottomMargin(),this._node.create(this._printPageBreakSelector),s),this._DOM.insertAtStart(e,r),this._balanceFooter({balancingFooter:a,contentSeparator:s,pageSeparator:i,paperSeparator:o,pageIndex:n})}_balanceFooter({balancingFooter:e,contentSeparator:t,pageSeparator:i,paperSeparator:o,pageIndex:n}){const r=this._node.getTop(i,this._root),s=this._node.getTop(o,this._root),a=this._node.getTop(t,this._root);this.strictAssert(s==r,"balancers in paper layers are misaligned",{pageIndex:n,balancingFooter:e,contentSeparator:t,pageSeparator:i,paperSeparator:o,paperSeparatorTop:s,pageSeparatorTop:r});const l=r-a;this._debug._&&console.log({balancingFooter:e,contentSeparatorTop:a,paperSeparatorTop:s,pageSeparatorTop:r}),this._DOM.setStyles(e,{"margin-bottom":l+"px"});l<-1&&(this._debug._&&console.warn(`[pages: ${n}-${n+1}] balancer is negative: ${l} < 0. Submitted to the Validator.`,t),this._accumulatedAssertions[n]={balancer:l,contentSeparator:t,pageNumber:n})}}class mn{constructor({config:e,DOM:t,selector:i,node:o,layout:n}){this._globalDebugMode=e.debugMode,this._debug=e.debugMode?{...e.debugConfig.toc}:{},this._assert=!!e.consoleAssert,this._DOM=t,this._node=o,this._tocPageNumberSelector=e.tocPageNumberSelector,this._root=n.root,this._contentFlow=n.contentFlow,this._pageDividerSelector=i.pageDivider}render(){this._globalDebugMode&&console.time("Processing TOC"),this._debug._&&console.log(`\n📑 TOC: I am here!\n\ntocPageNumberSelector:\n • ${this._tocPageNumberSelector}\n pageDividerSelector:\n • ${this._pageDividerSelector}\n `);const e=this._DOM.getAll(this._tocPageNumberSelector,this._contentFlow);if(this._debug._&&console.log("📑 tocPageNumberBoxes",e.length),!e.length)return void(this._debug._&&console.log("📑 no valid toc"));const t=this._node.getRegisteredPageDividers?.(),i=(t&&t.size?[...t.entries()]:this._DOM.getAll(this._pageDividerSelector,this._contentFlow).map((e,t)=>[t+1,e])).reduce((e,[t,i])=>{const o=this._node.getTop(i,this._root)-1,n=String(t);return e[o]=n,e},{});this._debug._&&console.log("📑 dataFromPagesMarkers",i);const o=e.reduce((e,t)=>{const i=this._DOM.getDataId(t),o=this._DOM.getElementById(i),n=this._node.getTop(o,this._root);return e[n]={box:t,id:i,targetTop:n},e},{});this._debug._&&console.log("📑 dataFromTOC",o);const n={...i,...o};let r=0;this._debug._&&console.groupCollapsed("Processing obj");for(const e in n){const t=n[e];this._debug._&&console.log(`Processing ${e}: ${t}`),"string"==typeof t?r=t:(t.page=r,this._DOM.setInnerHTML(t.box,r))}this._debug._&&console.groupEnd("Processing obj"),this._debug._&&console.log("📑 tocObject",n),this._globalDebugMode&&console.timeEnd("Processing TOC")}}class bn{constructor({config:e,DOM:t,selector:o,node:n,layout:r,pages:s,previewValidations:a}){this._config=e,this._selector=o,this._DOM=t,this._node=n,this._layout=r,this._root=r.root,this._pageCount=s.length,this._accumulatedAssertions=a,this._assert=!!e.consoleAssert,Object.assign(this,i)}init(){this._config.debugMode&&console.log("🐙 i am Validator!"),this._validateLayout()}_validateLayout(){const e=this._collectPageOverflowAssertions();for(const[t,i]of Object.entries(e))this._accumulatedAssertions[t]={...this._accumulatedAssertions[t]||{},...i};this.strictAssert(0===Object.keys(this._accumulatedAssertions).length,"Page overflow detected:",this._accumulatedAssertions)}_collectPageOverflowAssertions(){const e=`${this._selector.paperFlow} ${this._selector.virtualPaperGap}`,t=`${this._selector.contentFlow} ${this._selector.virtualPaperGap}`,i=(this._selector.contentFlow,this._selector.contentFlowEnd,`${this._selector.pageChrome} ${this._selector.pageBodySpacer}`),o={},n=[...this._DOM.getAllElements(e)],r=[...this._DOM.getAllElements(t)];this._assertElementsCount(this._pageCount-1,{paperGapElements:n,pageGapElements:r});const s=n.map(e=>this._node.getTop(e,this._root)),a=r.map(e=>this._node.getTop(e,this._root));for(let e=0;ee?this._node.getBottom(e,this._root):void 0),u=h.map(e=>e?this._node.getBottom(e,this._root):void 0);for(let e=0;e{e<=.1&&(clearInterval(t),this._preloader.remove()),this._preloader.style.opacity=e,e-=.1*e},50);this._debugMode&&console.log("%c Preloader removed ",wn)}_insertStyle(){const e=document.querySelector("head"),t=document.createElement("style");t.append(document.createTextNode(this._css())),t.setAttribute("data-preloader-style",""),e.append(t)}_css(){return`\n /* PRELOADER */\n .lds-dual-ring {\n position: absolute;\n z-index: 99999;\n top: 0; left: 0; bottom: 0; right: 0;\n background: ${this._preloaderBackground};\n display: flex;\n justify-content: center;\n align-items: center;\n }\n /*\n .lds-dual-ring:after {\n content: " ";\n display: block;\n width: 64px;\n height: 64px;\n margin: 8px;\n border-radius: 50%;\n border: 6px solid #eee;\n border-color: #eee transparent #eee transparent;\n animation: lds-dual-ring 1.2s linear infinite;\n }\n @keyframes lds-dual-ring {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n }\n */\n `}_resolveTarget(e){const t=(e.preloaderTarget||"").trim();return t&&document.querySelector(t)}}const Mn="html2pdf4doc-resource-status";class yn{constructor(e,t){this._config=e,this._DOM=t,this._debugMode=e.debugMode,this._resourceIssues=[]}async run(){return await this._awaitResources(),this._resourceIssues}async _awaitResources(){const e=this._config.resourceTimeout??this._config.resourceTimeoutMs??2e3,t=this._config.initialRoot,i=t&&this._DOM.document.querySelector(t)||this._DOM.body,o=i?[i,...i.querySelectorAll("*")]:[];this._DOM.document.fonts?.ready&&await this._DOM.document.fonts.ready;const n=[...i.querySelectorAll("img")].map(t=>this._waitForImageElement(t,e)),r=[...i.querySelectorAll("svg image")].map(t=>{const i=t.getAttribute("href")||t.getAttribute("xlink:href");return i?this._preloadUrl(i,t,e):Promise.resolve()}),s=o.flatMap(t=>function(e){if(!e||"none"===e)return[];const t=[],i=/url\((['"]?)(.*?)\1\)/g;let o;for(;null!==(o=i.exec(e));)o[2]&&t.push(o[2]);return t}(window.getComputedStyle(t).backgroundImage).map(i=>this._preloadUrl(i,t,e))),a=[...i.querySelectorAll("object, embed")].map(t=>Pn(new Promise(e=>{t.addEventListener("load",()=>{"OBJECT"!==t.tagName||t.contentDocument||this._markResourceStatus(t,"error"),e()},{once:!0}),t.addEventListener("error",()=>{this._markResourceStatus(t,"error"),e()},{once:!0})}),e,()=>this._markResourceStatus(t,"timeout")));await Promise.all([...n,...r,...s,...a])}_waitForImageElement(e,t){if(e.complete&&0===e.naturalWidth)return this._markResourceStatus(e,"error"),Promise.resolve();return Pn(e.decode?e.decode().catch(()=>{this._markResourceStatus(e,"error")}):e.complete?Promise.resolve():new Promise(t=>{e.addEventListener("load",t,{once:!0}),e.addEventListener("error",()=>{this._markResourceStatus(e,"error"),t()},{once:!0})}),t,()=>this._markResourceStatus(e,"timeout"))}_preloadUrl(e,t,i){if(!e||e.startsWith("data:"))return Promise.resolve();const o=new Image,n=new Promise(e=>{o.addEventListener("load",e,{once:!0}),o.addEventListener("error",()=>{this._markResourceStatus(t,"error"),e()},{once:!0})});return o.src=e,Pn(n,i,()=>this._markResourceStatus(t,"timeout"))}_markResourceStatus(e,t){e&&!e.hasAttribute(Mn)&&(this._DOM.setAttribute(e,`[${Mn}]`,t),this._debugMode&&console.log(`[HTML2PDF4DOC] Resource status: ${t}`,e),this._handleResourceIssue({element:e,status:t}))}_handleResourceIssue(e){if(!e||!e.element)return;const t={status:e.status,element:e.element,tag:e.element.tagName};this._resourceIssues.push(t),this._warnResourceIssue(t),this._emitResourceIssue(t)}_warnResourceIssue(e){console.warn(`[HTML2PDF4DOC] Resource ${e.status}`,e.element)}_emitResourceIssue(e){this._DOM.document.dispatchEvent(new CustomEvent("html2pdf4doc:resource-issue",{detail:e}))}}function Pn(e,t,i){return!t||t<=0?e.catch(()=>{}):new Promise(o=>{let n=!1;const r=setTimeout(()=>{n||(n=!0,i(),o())},t);e.catch(()=>{}).finally(()=>{n||(n=!0,clearTimeout(r),o())})})}const Cn=e=>!0===e||"true"===e;function En(e){const t=Array.isArray(e)?[]:{};return Object.entries(e).forEach(([e,i])=>{t[e]=!i||"object"!=typeof i||En(i)}),t}const Tn={DOM:{_:!1},layout:{_:!1},pages:{_:!1,_parseNode:!1,_parseNodes:!1,_registerPageStart:!1},paper:{_:!1},preview:{_:!1},toc:{_:!1},node:{_:!1,children:!1,creators:!1,flowFilters:!1,fitters:!1,getters:!1,markers:!1,media:!1,normalizer:!1,pageBreaks:!1,positioning:!1,selectors:!1,selectorHeuristics:!1,slicers:!1,splitters:!1,wrappers:!1,pagination:!1},paragraph:{_:!1},grid:{_:!1},pre:{_:!1},table:{_:!1},tableLike:{_:!1},testSignals:{forcedModeLog:!1}};function On(e){const t=function(e){let t={debugMode:!1,forcedDebugMode:!1,consoleAssert:!1,markupDebugMode:!1,resourceTimeoutMs:2e3,preloader:!1,preloaderTarget:"",preloaderBackground:"",mask:!0,noHangingSelectors:"",forcedPageBreakSelectors:"",pageBreakBeforeSelectors:"",pageBreakAfterSelectors:"",noBreakSelectors:"",tocPageNumberSelector:"html2pdf4doc-toc-page-number",printLeftMargin:"21mm",printRightMargin:"21mm",printTopMargin:"12mm",printBottomMargin:"12mm",printFontSize:"12pt",paperColor:"white",paperWidth:"210mm",paperHeight:"297mm",headerMargin:"16px",footerMargin:"16px",virtualPagesGap:"16px",splitLabelHeight:"24px"};const i={paperWidth:"210mm",paperHeight:"297mm"},o={paperWidth:"148.5mm",paperHeight:"210mm"};switch((e=function(e){const t={...e};for(const e in t){const i=t[e];if("string"==typeof i){const o=i.toLowerCase();"true"===o||"1"===o?t[e]=!0:"false"!==o&&"0"!==o&&""!==o||(t[e]=!1)}}return t}(e)).printPaperSize){case"A5":case"a5":t={...t,...o};break;default:t={...t,...i}}t={...t,initialRoot:N(x.init),tocPageNumberSelector:N(x.tocPageNumber),...e},console.info("[HTML2PDF4DOC] Config:",t);const n={printLeftMargin:t.printLeftMargin,printRightMargin:t.printRightMargin,printTopMargin:t.printTopMargin,printBottomMargin:t.printBottomMargin,printFontSize:t.printFontSize,paperWidth:t.paperWidth,paperHeight:t.paperHeight,headerMargin:t.headerMargin,footerMargin:t.footerMargin,virtualPagesGap:t.virtualPagesGap},r=document.createElement("div");return r.style="\n position:absolute;\n z-index:1000;\n left: 200%;\n ",document.body.append(r),Object.entries(n).forEach(([e,t])=>{r.style.width=t,n[e]=`${Math.trunc(r.getBoundingClientRect().width)}px`}),r.remove(),t={...t,...n},t.noHangingSelectors=t.noHangingSelectors+" H1 H2 H3 H4 H5 H6",t.forcedPageBreakSelectors=t.forcedPageBreakSelectors+" "+N(x.printForcedPageBreak),t.debugMode&&console.info("Config with converted units:",t),t}(e);t.forcedDebugMode&&(t.debugMode=!0,t.consoleAssert=!0,t.markupDebugMode=!0);const i=t.forcedDebugMode?En(Tn):Tn;return{...t,debugConfig:i}}const vn="color:Gray;border:1px solid;";class Dn{constructor(e){this.params=function(e={}){const t={...e};return[["printWidth","paperWidth","data-print-width","data-paper-width"],["printHeight","paperHeight","data-print-height","data-paper-height"]].forEach(([e,i,o,n])=>{Object.prototype.hasOwnProperty.call(t,e)&&(console.warn(`[HTML2PDF4DOC] Config option "${o}" is deprecated. Use "${n}" instead.`),Object.prototype.hasOwnProperty.call(t,i)||(t[i]=t[e]),delete t[e])}),t}(e),this.forcedDebugMode=Cn(e.forcedDebugMode),this.debugMode=Cn(e.debugMode)||this.forcedDebugMode,this.preloader=e.preloader,this.selector=x,this.config}async render(){console.time("[HTML2PDF4DOC] Total time"),function({kickReload:e=!1}={}){const t=document.createElement("style");t.setAttribute("data-html2pdf-sanitize",""),t.textContent="html2pdf4doc-content-flow * { contain: none !important; content-visibility: visible !important; }",document.head.appendChild(t);const i=["data-src","data-lazy-src","data-original","data-url"],o=["data-srcset","data-lazy-srcset"],n=(e,t)=>{for(const i of t){const t=e.getAttribute(i);if(t&&t.trim())return t.trim()}return""};for(const t of document.images){if("lazy"===t.getAttribute("loading")&&t.setAttribute("loading","eager"),!t.getAttribute("src")){const e=n(t,i);e&&t.setAttribute("src",e)}if(!t.getAttribute("srcset")){const e=n(t,o);e&&t.setAttribute("srcset",e)}if(e){const e=t.getAttribute("src"),i=t.getAttribute("srcset");e&&(t.setAttribute("src",""),t.setAttribute("src",e)),i&&(t.setAttribute("srcset",""),t.setAttribute("srcset",i))}}for(const e of document.querySelectorAll("picture source"))if(!e.getAttribute("srcset")){const t=n(e,o);t&&e.setAttribute("srcset",t)}}(),this.debugMode&&console.log("🏁 document.readyState:",document.readyState),document.addEventListener("readystatechange",e=>{this.debugMode&&console.log("🏁 readystatechange:",document.readyState)}),this.debugMode&&console.time("⏱️ await DOMContentLoaded time"),"loading"===document.readyState?await new Promise(e=>{window.addEventListener("DOMContentLoaded",t=>{this.debugMode&&console.log("⏰ EVENT: DOMContentLoaded"),e()})}):this.debugMode&&console.log("🕰️ EVENT: DOMContentLoaded (event fired before init)"),this.debugMode&&console.timeEnd("⏱️ await DOMContentLoaded time"),this.debugMode&&console.time("⏱️ create Preloader time");const e=new Sn(this.params);"true"===this.preloader&&e.create(),this.debugMode&&console.timeEnd("⏱️ create Preloader time"),this.debugMode&&console.time("⏱️ Config time"),this.debugMode&&console.groupCollapsed("%c config ",vn+"color:LightGray"),this.config=On(this.params),this.debugMode&&console.groupEnd(),this.debugMode&&console.info("⚙️ Current config with debugConfig:",this.config),this.debugMode&&console.timeEnd("⏱️ Config time"),this.config.debugConfig.testSignals.forcedModeLog&&console.info("[HTML2PDF4DOC] 🛠️ Forced debug mode is active."),this.config.consoleAssert&&console.info("[HTML2PDF4DOC] 🧧 Assertions enabled."),this.debugMode&&console.time("⏱️ DOM helpers init time");const t=new L({DOM:window.document,config:this.config});this.debugMode&&console.timeEnd("⏱️ DOM helpers init time"),this.debugMode&&console.time("⏱️ node helpers init time");const i=new ln({config:this.config,DOM:t,selector:this.selector});this.debugMode&&console.timeEnd("⏱️ node helpers init time"),this.debugMode&&console.time("⏱️ await window load time"),"complete"!==document.readyState?await new Promise(e=>{window.addEventListener("load",t=>{this.debugMode&&console.log("⏰ EVENT: window load"),e()})}):this.debugMode&&console.log("🕰️ EVENT: window load (event fired before init)"),this.debugMode&&console.timeEnd("⏱️ await window load time"),this.debugMode&&console.time("⏱️ Layout time"),this.debugMode&&console.groupCollapsed("%c Layout ",vn);const o=new G({config:this.config,DOM:t,selector:this.selector,node:i});if(o.create(),this.debugMode&&console.groupEnd(),this.debugMode&&console.timeEnd("⏱️ Layout time"),!o.success)return void(this.debugMode&&console.error("Failed to create layout.\n\nWe have to interrupt the process of creating PDF preview."));this.debugMode&&console.time("⏱️ Preprocess time"),this.debugMode&&console.groupCollapsed("%c Preprocess ",vn),await new yn(this.config,t).run(),this.debugMode&&console.groupEnd(),this.debugMode&&console.timeEnd("⏱️ Preprocess time"),this.debugMode&&console.info("%c calculate Paper params ",vn),this.debugMode&&console.time("⏱️ Paper time");const n=new _n({config:this.config,DOM:t,selector:this.selector,node:i,layout:o});if(this.debugMode&&console.timeEnd("⏱️ Paper time"),!n||!n.bodyHeight||!n.bodyWidth)return void(this.debugMode&&console.error("Failed to create paper calculations.\n\nWe have to interrupt the process of creating PDF preview."));this.debugMode&&console.time("⏱️ Pages time"),this.debugMode&&console.group("%c Pages ",vn);const r=function(){const e=[];return{enqueue(t){"function"==typeof t&&e.push(t)},flush(){for(const t of e)t();e.length=0}}}(),s=new pn({config:this.config,DOM:t,selector:this.selector,node:i,layout:o,referenceHeight:n.bodyHeight,referenceWidth:n.bodyWidth,mutationQueue:r}).calculate();this.debugMode&&console.groupEnd(),this.debugMode&&console.timeEnd("⏱️ Pages time"),this.debugMode&&console.time("⏱️ Preview time"),this.debugMode&&console.groupCollapsed("%c Preview ",vn);const a=new fn({config:this.config,DOM:t,selector:this.selector,node:i,layout:o,paper:n,pages:s,mutationQueue:r}).create();this.debugMode&&console.groupEnd(),this.debugMode&&console.timeEnd("⏱️ Preview time"),this.debugMode&&console.time("⏱️ Toc time"),new mn({config:this.config,DOM:t,selector:this.selector,node:i,layout:o}).render(),this.debugMode&&console.timeEnd("⏱️ Toc time"),this.debugMode&&console.time("⏱️ Validator time"),window.scrollTo(0,document.body.scrollHeight),await new Promise(e=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{window.scrollTo(0,0),e()})})}),new bn({config:this.config,DOM:t,selector:this.selector,node:i,layout:o,pages:s,previewValidations:a}).init(),this.debugMode&&console.timeEnd("⏱️ Validator time"),t.setAttribute(o.root,"[success]"),t.setAttribute(o.root,"[pages]",s.length),e.remove(),console.info("[HTML2PDF4DOC] Page count:",s.length),console.timeEnd("[HTML2PDF4DOC] Total time")}}console.info("[HTML2PDF4DOC] Version:","0.3.0");const kn=document.currentScript,Rn=kn&&kn.dataset;let Nn=null,xn=!1;function Bn(){xn&&Nn&&Nn.render()}Rn?(Nn=new Dn(Rn),xn="manual"===Rn.init,xn&&console.info("HTML2PDF4DOC in manual initialization mode"),!xn&&Nn.render()):console.warn('[HTML2PDF4DOC] ⛔ Unable to read parameters from the current