@paprize/core 0.0.12 → 0.2.0

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.
@@ -1,4 +1,4 @@
1
- (function(a,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(a=typeof globalThis<"u"?globalThis:a||self,S(a["paprize-core"]={}))})(this,(function(a){"use strict";const S="paprize",ne="pz-temp-container",Ie="pz-current-element",Fe="pz-current-text",Le="pz-ignored-element",Oe="pz-ignored-text",V="paprize-global-style",A="pz-page",ie="pz-section",C="pz-preview",w="data-pz-";let oe=!1;const Re=()=>{oe=!0},B=()=>oe;function J(i){return i.nodeType===Node.ELEMENT_NODE}function re(i){return i.nodeType===Node.TEXT_NODE}function I(i){const e=i.getBoundingClientRect(),t=getComputedStyle(i),n=parseFloat(t.marginTop)||0,o=parseFloat(t.marginBottom)||0;return e.height+n+o}function se(i){i.style.visibility="hidden",i.style.position="absolute",i.style.left="-9999px",i.style.top="-9999px"}const ae={hyphen:"-",keepOnSamePage:!1,hyphenationDisabled:!1},le=`${w}hyphen`,ce=`${w}keep-on-same-page`,de=`${w}hyphenation-disabled`,ge={hyphen:{key:le,reader:i=>String(i)},keepOnSamePage:{key:ce,reader:i=>i==="true"},hyphenationDisabled:{key:de,reader:i=>i==="true"}};function He(i){const e={};for(const[t,n]of Object.entries(i)){const o=ge[t];o!==void 0&&n!==void 0&&(e[o.key]=String(n))}return e}const ue=new WeakMap;function $e(i,e,t,n){if(t==null)return;const o=e(t);o!==void 0&&(n[i]=o)}function q(i){if(!i)return{};if(!(i instanceof Element))return q(i?.parentNode);const e={};for(const o of Object.keys(ae)){const r=o,s=ge[r],d=i.getAttribute(s.key);$e(r,s.reader,d,e)}const n={...i.parentNode?ue.get(i.parentNode):void 0,...e};return ue.set(i,n),n}const pe={id:"default",plugins:[],...ae};function ze(i,e){const t=q(i);return{...pe,...e,...t}}function De(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var j={exports:{}},Be=j.exports,he;function je(){return he||(he=1,(function(i){(function(e,t){i.exports?i.exports=t():e.log=t()})(Be,function(){var e=function(){},t="undefined",n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"],r={},s=null;function d(c,h){var l=c[h];if(typeof l.bind=="function")return l.bind(c);try{return Function.prototype.bind.call(l,c)}catch{return function(){return Function.prototype.apply.apply(l,[c,arguments])}}}function b(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function T(c){return c==="debug"&&(c="log"),typeof console===t?!1:c==="trace"&&n?b:console[c]!==void 0?d(console,c):console.log!==void 0?d(console,"log"):e}function v(){for(var c=this.getLevel(),h=0;h<o.length;h++){var l=o[h];this[l]=h<c?e:this.methodFactory(l,c,this.name)}if(this.log=this.debug,typeof console===t&&c<this.levels.SILENT)return"No console available for logging"}function y(c){return function(){typeof console!==t&&(v.call(this),this[c].apply(this,arguments))}}function ee(c,h,l){return T(c)||y.apply(this,arguments)}function xe(c,h){var l=this,W,te,k,f="loglevel";typeof c=="string"?f+=":"+c:typeof c=="symbol"&&(f=void 0);function _t(g){var m=(o[g]||"silent").toUpperCase();if(!(typeof window===t||!f)){try{window.localStorage[f]=m;return}catch{}try{window.document.cookie=encodeURIComponent(f)+"="+m+";"}catch{}}}function Te(){var g;if(!(typeof window===t||!f)){try{g=window.localStorage[f]}catch{}if(typeof g===t)try{var m=window.document.cookie,U=encodeURIComponent(f),Ae=m.indexOf(U+"=");Ae!==-1&&(g=/^([^;]+)/.exec(m.slice(Ae+U.length+1))[1])}catch{}return l.levels[g]===void 0&&(g=void 0),g}}function vt(){if(!(typeof window===t||!f)){try{window.localStorage.removeItem(f)}catch{}try{window.document.cookie=encodeURIComponent(f)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}function D(g){var m=g;if(typeof m=="string"&&l.levels[m.toUpperCase()]!==void 0&&(m=l.levels[m.toUpperCase()]),typeof m=="number"&&m>=0&&m<=l.levels.SILENT)return m;throw new TypeError("log.setLevel() called with invalid level: "+g)}l.name=c,l.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},l.methodFactory=h||ee,l.getLevel=function(){return k??te??W},l.setLevel=function(g,m){return k=D(g),m!==!1&&_t(k),v.call(l)},l.setDefaultLevel=function(g){te=D(g),Te()||l.setLevel(g,!1)},l.resetLevel=function(){k=null,vt(),v.call(l)},l.enableAll=function(g){l.setLevel(l.levels.TRACE,g)},l.disableAll=function(g){l.setLevel(l.levels.SILENT,g)},l.rebuild=function(){if(s!==l&&(W=D(s.getLevel())),v.call(l),s===l)for(var g in r)r[g].rebuild()},W=D(s?s.getLevel():"WARN");var ke=Te();ke!=null&&(k=D(ke)),v.call(l)}s=new xe,s.getLogger=function(h){if(typeof h!="symbol"&&typeof h!="string"||h==="")throw new TypeError("You must supply a name when creating a logger.");var l=r[h];return l||(l=r[h]=new xe(h,s.methodFactory)),l};var ft=typeof window!==t?window.log:void 0;return s.noConflict=function(){return typeof window!==t&&window.log===s&&(window.log=ft),s},s.getLoggers=function(){return r},s.default=s,s})})(j)),j.exports}var Me=je();const P=De(Me),u=P.getLogger(S);u.setDefaultLevel("info");const G="\x1B[46mPLUGIN\x1B[0m";function N(i,e,...t){i.sort((n,o)=>n.order-o.order).forEach(n=>{const o=n[e];if(o){u.debug(G,`executing plugin ${n.name}:${String(e)} ()`,t);try{o(...t),u.debug(G,`plugin ${n.name}:${String(e)} executed`,t)}catch(r){u.debug(G,`plugin ${n.name}:${String(e)} failed`,r)}}})}const E={Element:"element",Text:"text"};class F{_node;config;type=E.Element;transaction;clonedFrom;cloneCount;constructor(e,t,n,o){this._node=e,this.transaction=t,this.config=n,this.clonedFrom=o,this.cloneCount=o?o.cloneCount+1:0}getOriginalNode(){let e=this.clonedFrom;for(;e?.clonedFrom;)e=e.clonedFrom;return e?._node}appendChild(e){this.transaction.isActive&&this.transaction.addRollbackCallback(()=>{this._node.removeChild(e.getNode())}),this._node.appendChild(e.getNode())}clone(e){const t=this._node.cloneNode(e),n=new F(t,this.transaction,this.config,this);return N(this.config.plugins,"onClone",this.config.id,this._node,n),n}getHeight(){return I(this._node)}remove(){this.transaction.addCommitCallback(()=>{this._node.remove()})}isEmpty(){return this._node.innerHTML===""}getChildrenCount(){return this._node.childNodes.length}getNode(){return this._node}}class We{_node;type=E.Text;transaction;config;constructor(e,t,n){this._node=e,this.transaction=t,this.config=n}get textContent(){return this._node.textContent??""}set textContent(e){this._node.textContent=e}remove(){this.transaction.addCommitCallback(()=>{this._node.remove()})}getNode(){return this._node}}function M(i,e,t){if(re(i))return new We(i,e,t);if(J(i))return new F(i,e,t);throw new Error("Unsupported node type")}const L="\x1B[106mDOM\x1B[0m";class Ue{_transaction;_treeWalker;_config;_completed=!1;_currentNode=null;_previousNode=null;constructor(e,t,n){this._transaction=t,this._config=n,this._treeWalker=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT)}get completed(){return this._completed}get currentNode(){return this._currentNode}get previousNode(){return this._previousNode}goToNextNode(){this._treeWalker.nextNode()||(this._completed=!0),u.debug(L,"moving to next node"),this.setState()}goToNextSiblingOrParentSibling(){let e=0;if(this._treeWalker.nextSibling())return u.debug(L,"moving to next sibling node"),this.setState(),{parentsTraversed:e};for(;this._treeWalker.parentNode();)if(e++,this._treeWalker.nextSibling())return u.debug(L,"moving to parent sibling node, traversed:",e),this.setState(),{parentsTraversed:e};return this._completed=!0,{parentsTraversed:e}}goToFirstChildOrNextNode(){return this._treeWalker.firstChild()?(u.debug(L,"moving to first child node"),this.setState(),{parentsTraversed:1}):(this.goToNextNode(),{parentsTraversed:0})}setState(){this._previousNode=this._currentNode,this._currentNode=M(this._treeWalker.currentNode,this._transaction,ze(this._treeWalker.currentNode,this._config)),u.debug(L,"moved to node",{currentNode:this._currentNode,previousNode:this._previousNode})}}class Ve{_onRollback;_onCommit;isActive;constructor(){this._onRollback=[],this._onCommit=[],this.isActive=!1}start=()=>{if(this.isActive)throw new Error("Transaction already in progress");this.isActive=!0,this._onRollback=[],this._onCommit=[]};addRollbackCallback=e=>{this._onRollback.push(e)};addCommitCallback=e=>{if(!this.isActive){e();return}this._onCommit.push(e)};rollback=()=>{this.isActive&&(this.isActive=!1,this._onRollback.forEach(e=>e()))};commit=()=>{this.isActive&&(this.isActive=!1,this._onCommit.forEach(e=>e()))}}const K="\x1B[102mPAGE\x1B[0m";class O{currentPage;activeElement;currentElement;parentStack;pageIsFull;pageIndex;pageHeight;constructor(e,t,n,o,r,s,d){this.currentPage=e,this.activeElement=t,this.currentElement=n,this.parentStack=o,this.pageIsFull=r,this.pageIndex=s,this.pageHeight=d}static create(e,t,n,o){return new O(e,null,e,t,!1,n,o)}clone=()=>new O(this.currentPage,this.activeElement,this.currentElement,[...this.parentStack],this.pageIsFull,this.pageIndex,this.pageHeight)}class Z{_pageState;_transaction;_tempContainer;_config;constructor(e,t,n,o){this._tempContainer=e,this._config=o,this._transaction=n;const r=Z.createPageHtmlElement(t.width),s=this.createNewPage(r);this._pageState=O.create(s,[],0,t.height),N(this._config.plugins,"onNewPage",o.id,this)}nextPage(){const e=this.createNewPage(this._pageState.currentPage.getNode().cloneNode(!1)),t=O.create(e,[],this._pageState.pageIndex+1,this._pageState.pageHeight);this.cloneParentStackToNewPage(t),this.cleanupEmptyParent(),this._pageState=t,N(this._config.plugins,"onNewPage",this._config.id,this)}cloneParentStackToNewPage(e){for(const t of this._pageState.parentStack){const n=t.clone(!1);e.currentElement.appendChild(n),e.currentElement=n,e.parentStack.push(n)}}cleanupEmptyParent(){const e=[...this._pageState.parentStack],t=()=>{for(let n=e.length-1;n>=0;n--){const o=e[n];o.isEmpty()&&o.remove()}};this._transaction.addCommitCallback(t)}enterElement(){if(!this._pageState.activeElement||this._pageState.activeElement.type!==E.Element)throw new Error("Invalid state: activeElement is not an Element");u.debug(K,"entering an element",this._pageState.activeElement),this._pageState.currentElement=this._pageState.activeElement,this._pageState.parentStack.push(this._pageState.activeElement)}leaveElement(){this._pageState.activeElement=null;const e=this._pageState.parentStack.pop();u.debug(K,"leaving a parent element",e);const t=this._pageState.parentStack.at(-1);this._pageState.currentElement=t??this._pageState.currentPage}static createPageHtmlElement(e){const t=document.createElement("div");return t.style.width=`${e}px`,t.style.maxWidth=`${e}px`,t.className=A,t}createNewPage(e){return u.debug(K,"creating new page"),this._tempContainer.appendChild(e),this._transaction.isActive&&this._transaction.addRollbackCallback(()=>{this._tempContainer.removeChild(e)}),M(e,this._transaction,this._config)}startTransaction(){this._transaction.start();const e=this._pageState.clone();return this._transaction.addRollbackCallback(()=>{this._pageState=e}),this._transaction}hasEmptySpace(e){return!this._pageState.pageIsFull&&this._pageState.currentPage.getHeight()+(e||1e-4)<=this._pageState.pageHeight}isOverFlow(){return this._pageState.currentPage.getHeight()>this._pageState.pageHeight}markPageAsFull(){this._pageState.pageIsFull=!0}appendChild(e,t){const n=e.clone(t);return this._pageState.currentElement.appendChild(n),this._pageState.activeElement=n,n}addTextNode(e){if(this._pageState.activeElement?.type===E.Text)return this._pageState.activeElement;const t=document.createTextNode(e),n=M(t,this._transaction,this._config);return this._pageState.currentElement.appendChild(n),this._pageState.activeElement=n,n}getPageState(){return this._pageState}}const p={None:0,FullNodePlaced:1,SplitChildren:2};function Je(i,e){const t=me(i,e);if(t!==p.None)return t;const{rollback:n,commit:o}=e.startTransaction();e.nextPage();const r=me(i,e);return r!==p.None?(o(),r):(n(),u.debug("Element is too big to fit on a page",i),p.None)}function me(i,e){if(e.hasEmptySpace(i.getHeight())){const n=e.appendChild(i,!0);if(e.isOverFlow())n.remove();else return p.FullNodePlaced}if(i.config.keepOnSamePage||i.getChildrenCount()===0)return p.None;const t=e.appendChild(i,!1);return e.isOverFlow()?(t.remove(),p.None):p.SplitChildren}function qe(i,e){let t=p.FullNodePlaced;const n=i.textContent.split(/(\s+)/).filter(s=>s!=="");let o,r=0;for(;o||r<n.length;){const s=o??n[r],d=Ge(s,e,i.config);d.completed||(t=p.None),d.pendingToken?o=d.pendingToken:(o=void 0,r++)}return t}function Ge(i,e,t){const n=e.addTextNode(""),o=n.textContent;if(n.textContent+=i,!e.isOverFlow())return{completed:!0};n.textContent=o;const r=Ke(i,e,t);return{pendingToken:r.leftovers,completed:r.completed}}function Ke(i,e,t){const{rollback:n,commit:o}=e.startTransaction();if(e.nextPage(),e.addTextNode(i),!e.isOverFlow())return o(),{completed:!0};if(n(),t.hyphenationDisabled)return u.warn("Hyphenation disabled, skipping oversized token:",i),{completed:!1};e.hasEmptySpace()||e.nextPage();const r=Ze(i,t.hyphen,e);return{completed:!0,leftovers:r&&r.length>0?r:void 0}}function Ze(i,e,t){const n=t.addTextNode("");let o="";for(let r=0;r<i.length;r++){const s=i[r],d=o+s;if(n.textContent=d+e,!t.hasEmptySpace())return n.textContent=o?o+e:"",t.markPageAsFull(),i.slice(r);o=d}return null}const R="\x1B[103mPAGINATOR\x1B[0m";class H{_domState;_pageManager;_transaction;_tempContainer;_config;constructor(e,t,n){this._config={...pe,...n},this._tempContainer=H.createTempContainer(this._config.id),this._transaction=new Ve,this._domState=new Ue(e,this._transaction,this._config),this._pageManager=new Z(this._tempContainer,t,this._transaction,this._config)}static createTempContainer(e){const t=document.createElement("div");return t.style.display="flex",t.style.flexDirection="column",t.style.gap="20px",t.setAttribute(`${w}-section-id`,e),t.classList.add(ne),B()||se(t),document.body.appendChild(t),t}static paginate(e,t,n){const o=new H(e,t,n);o.processAllNodes();const r=Array.from(o._tempContainer.childNodes).filter(s=>J(s)).map(s=>s.innerHTML);return B()?Array.from(o._tempContainer.childNodes).forEach(s=>{const d=s;d.style.height=`${t.height}px`,d.style.width=`${t.width}px`}):o._tempContainer.remove(),r}processAllNodes(){this._domState.goToNextNode();do{P.debug(R,"paginating node",this._domState.currentNode);const e=this.processCurrentNode();switch(N(this._config.plugins,"afterVisitNode",this._config.id,e,this._domState,this._pageManager),e){case p.None:this.handleNodeSkipped();break;case p.FullNodePlaced:this.handleFullNodePlaced();break;case p.SplitChildren:this.handleChildrenSplit();break}}while(this._domState.completed===!1);N(this._config.plugins,"afterPagination",this._config.id,this._domState,this._pageManager),P.debug(R,"pagination completed")}handleNodeSkipped(){P.debug(R,"node skipped - couldn't paginate"),this._domState.goToNextNode()}handleFullNodePlaced(){P.debug(R,"node fully paginated");const{parentsTraversed:e}=this._domState.goToNextSiblingOrParentSibling();for(let t=0;t<e;t++)this._pageManager.leaveElement()}handleChildrenSplit(){P.debug(R,"node partially paginated - splitting children"),this._domState.goToFirstChildOrNextNode().parentsTraversed===1&&this._domState.previousNode?.type===E.Element&&this._pageManager.enterElement()}processCurrentNode(){if(!this._domState.currentNode)return p.None;if(this._domState.currentNode.type===E.Element){const e={};return N(this._config.plugins,"onVisitElement",this._config.id,this._domState,this._pageManager,e),e.result!==void 0?e.result:Je(this._domState.currentNode,this._pageManager)}else{const e={};return N(this._config.plugins,"onVisitText",this._config.id,this._domState,this._pageManager,e),e.result!==void 0?e.result:qe(this._domState.currentNode,this._pageManager)}}}class X{registry=new Map;addEventListener(e,t){const{registry:n}=this,o=new Set(n.get(e));return o.add(t),n.set(e,o),()=>this.removeEventListener(e,t)}removeEventListener(e,t){const{registry:n}=this,o=new Set(n.get(e));o.delete(t),n.set(e,o)}async dispatch(e,...t){const{registry:n}=this,o=n.get(e);if(o)for(const r of o)await r(...t)}}const Xe={A1:{height:"841mm",width:"594mm"},A2:{height:"594mm",width:"420mm"},A3:{height:"420mm",width:"297mm"},A4:{height:"297mm",width:"210mm"},A5:{height:"210mm",width:"148mm"},A6:{height:"148mm",width:"105mm"},B3:{height:"500mm",width:"353mm"},B4:{height:"353mm",width:"250mm"},B5:{height:"250mm",width:"176mm"},Letter:{height:"8.5in",width:"11in"},Legal:{height:"11in",width:"8.5in"},Tabloid:{height:"11in",width:"17in"}},fe={Normal:{top:"1in",right:"1in",bottom:"1in",left:"1in"},Narrow:{top:"0.4in",right:"0.6in",bottom:"0.6in",left:"0.6in"},Wide:{top:"0.5in",right:"2in",bottom:"0.5in",left:"2in"},None:{top:"0in",right:"0in",bottom:"0in",left:"0in"}},_e="__PAPRIZE_IS_INITIALIZED",Y="__PAPRIZE_IS_READY",Q="__PAPRIZE_READ_JSON_DATA_FILE";function Ye(i){const e=i.getBoundingClientRect(),t=getComputedStyle(i),n=parseFloat(t.marginLeft)||0,o=parseFloat(t.marginRight)||0;return{height:I(i),width:e.width+n+o}}function Qe(i,e,t){const{height:n,width:o}=Ye(i),r=e?I(e):0,s=t?I(t):0;return{height:n,width:o,sectionHeaderHeight:r,sectionFooterHeight:s}}function et(i,e,t){return{name:"sectionPageHeight",order:1,afterPagination:(n,o,r)=>{t<=0||r.hasEmptySpace(t)||r.nextPage()},onNewPage:(n,o)=>{const r=o.getPageState();r.pageIndex===0?r.pageHeight=i+t:r.pageHeight=i+e+t}}}function tt(i){return i?`${i.top} ${i.right} ${i.bottom} ${i.left}`:"0"}function nt(i){let e=null;return()=>(e||(e=i()),e)}async function it(){if(!(Q in window))return null;const i=await window[Q]?.();return i?JSON.parse(i):null}const ve=`
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`paprize-core`]={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,s=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),c=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e},l=(e,r,i)=>(i=e==null?{}:t(a(e)),c(r||!e||!e.__esModule?n(i,`default`,{value:e,enumerable:!0}):i,e)),u=`paprize`,d=`pz-temp-container`,f=`pz-current-element`,p=`pz-current-text`,m=`pz-ignored-element`,h=`pz-ignored-text`,g=`paprize-global-style`,_=`pz-page`,v=`pz-section`,y=`pz-preview`,b=`data-pz-`,x=l(s(((e,t)=>{(function(e,n){"use strict";typeof define==`function`&&define.amd?define(n):typeof t==`object`&&t.exports?t.exports=n():e.log=n()})(e,function(){"use strict";var e=function(){},t=`undefined`,n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),r=[`trace`,`debug`,`info`,`warn`,`error`],i={},a=null;function o(e,t){var n=e[t];if(typeof n.bind==`function`)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch{return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function s(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function c(r){return r===`debug`&&(r=`log`),typeof console===t?!1:r===`trace`&&n?s:console[r]===void 0?console.log===void 0?e:o(console,`log`):o(console,r)}function l(){for(var n=this.getLevel(),i=0;i<r.length;i++){var a=r[i];this[a]=i<n?e:this.methodFactory(a,n,this.name)}if(this.log=this.debug,typeof console===t&&n<this.levels.SILENT)return`No console available for logging`}function u(e){return function(){typeof console!==t&&(l.call(this),this[e].apply(this,arguments))}}function d(e,t,n){return c(e)||u.apply(this,arguments)}function f(e,n){var o=this,s,c,u,f=`loglevel`;typeof e==`string`?f+=`:`+e:typeof e==`symbol`&&(f=void 0);function p(e){var n=(r[e]||`silent`).toUpperCase();if(!(typeof window===t||!f)){try{window.localStorage[f]=n;return}catch{}try{window.document.cookie=encodeURIComponent(f)+`=`+n+`;`}catch{}}}function m(){var e;if(!(typeof window===t||!f)){try{e=window.localStorage[f]}catch{}if(typeof e===t)try{var n=window.document.cookie,r=encodeURIComponent(f),i=n.indexOf(r+`=`);i!==-1&&(e=/^([^;]+)/.exec(n.slice(i+r.length+1))[1])}catch{}return o.levels[e]===void 0&&(e=void 0),e}}function h(){if(!(typeof window===t||!f)){try{window.localStorage.removeItem(f)}catch{}try{window.document.cookie=encodeURIComponent(f)+`=; expires=Thu, 01 Jan 1970 00:00:00 UTC`}catch{}}}function g(e){var t=e;if(typeof t==`string`&&o.levels[t.toUpperCase()]!==void 0&&(t=o.levels[t.toUpperCase()]),typeof t==`number`&&t>=0&&t<=o.levels.SILENT)return t;throw TypeError(`log.setLevel() called with invalid level: `+e)}o.name=e,o.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},o.methodFactory=n||d,o.getLevel=function(){return u??c??s},o.setLevel=function(e,t){return u=g(e),t!==!1&&p(u),l.call(o)},o.setDefaultLevel=function(e){c=g(e),m()||o.setLevel(e,!1)},o.resetLevel=function(){u=null,h(),l.call(o)},o.enableAll=function(e){o.setLevel(o.levels.TRACE,e)},o.disableAll=function(e){o.setLevel(o.levels.SILENT,e)},o.rebuild=function(){if(a!==o&&(s=g(a.getLevel())),l.call(o),a===o)for(var e in i)i[e].rebuild()},s=g(a?a.getLevel():`WARN`);var _=m();_!=null&&(u=g(_)),l.call(o)}a=new f,a.getLogger=function(e){if(typeof e!=`symbol`&&typeof e!=`string`||e===``)throw TypeError(`You must supply a name when creating a logger.`);var t=i[e];return t||=i[e]=new f(e,a.methodFactory),t};var p=typeof window===t?void 0:window.log;return a.noConflict=function(){return typeof window!==t&&window.log===a&&(window.log=p),a},a.getLoggers=function(){return i},a.default=a,a})}))(),1),S=x.default.getLogger(u);S.setDefaultLevel(`info`);var ee=!1,te=()=>{S.setLevel(`debug`),ee=!0},C=()=>ee;function w(e){return e.nodeType===Node.ELEMENT_NODE}function ne(e){return e.nodeType===Node.TEXT_NODE}function T(e){let t=e.getBoundingClientRect(),n=getComputedStyle(e),r=parseFloat(n.marginTop)||0,i=parseFloat(n.marginBottom)||0;return t.height+r+i}function E(e){e.style.visibility=`hidden`,e.style.position=`absolute`,e.style.left=`-9999px`,e.style.top=`-9999px`}var D={hyphen:`-`,keepOnSamePage:!1,hyphenationDisabled:!1},O=`${b}hyphen`,k=`${b}keep-on-same-page`,A=`${b}hyphenation-disabled`,j={hyphen:{key:O,reader:e=>String(e)},keepOnSamePage:{key:k,reader:e=>{switch(e){case`true`:return!0;case`false`:return!1;case`prefer`:return`prefer`;default:return D.keepOnSamePage}}},hyphenationDisabled:{key:A,reader:e=>e===`true`}};function re(e){let t={};for(let[n,r]of Object.entries(e)){let e=j[n];e!==void 0&&r!==void 0&&(t[e.key]=String(r))}return t}var M=new WeakMap;function ie(e,t,n,r){n!=null&&(r[e]=t(n))}function N(e){if(!e)return{};if(!(e instanceof Element))return N(e?.parentNode);let t={};for(let n of Object.keys(D)){let r=n,i=j[r],a=e.getAttribute(i.key);ie(r,i.reader,a,t)}let n={...e.parentNode?M.get(e.parentNode):void 0,...t};return M.set(e,n),n}var ae={id:`default`,plugins:[],...D};function oe(e,t){let n=N(e);return{...ae,...t,...n}}var P=`\x1B[46mPLUGIN\x1B[0m`;function F(e,t,...n){e.sort((e,t)=>e.order-t.order).forEach(e=>{let r=e[t];if(r){S.debug(P,`executing plugin ${e.name}:${String(t)} ()`,n);try{r(...n),S.debug(P,`plugin ${e.name}:${String(t)} executed`,n)}catch(n){S.debug(P,`plugin ${e.name}:${String(t)} failed`,n)}}})}var I={Element:`element`,Text:`text`},L=class e{_node;config;type=I.Element;transaction;clonedData;constructor(e,t,n,r){this._node=e,this.transaction=t,this.config=n,this.clonedData=r?{clonedFrom:r,cloneCount:r.clonedData.cloneCount+1}:{clonedFrom:void 0,cloneCount:0}}getOriginalNode(){let e=this.clonedData.clonedFrom;for(;e?.clonedData.clonedFrom;)e=e.clonedData.clonedFrom;return e?._node??this._node}appendChild(e){this.transaction.isActive&&this.transaction.addRollbackCallback(()=>{this._node.removeChild(e.getNode())}),this._node.appendChild(e.getNode())}clone(t){let n=new e(this._node.cloneNode(t),this.transaction,this.config,this);return F(this.config.plugins,`onClone`,this.config.id,this._node,n),n}getHeight(){return T(this._node)}remove(){this.transaction.addCommitCallback(()=>{this._node.remove()})}isEmpty(){return this._node.innerHTML===``}getChildrenCount(){return this._node.childNodes.length}getNode(){return this._node}},se=class{_node;type=I.Text;transaction;config;constructor(e,t,n){this._node=e,this.transaction=t,this.config=n}get textContent(){return this._node.textContent??``}set textContent(e){this._node.textContent=e}remove(){this.transaction.addCommitCallback(()=>{this._node.remove()})}getNode(){return this._node}};function R(e,t,n){if(ne(e))return new se(e,t,n);if(w(e))return new L(e,t,n);throw Error(`Unsupported node type`)}function ce(e){C()&&(e&&e.type==I.Element?e.getNode().classList.add(m):e&&e.type==I.Text&&e.getNode().parentElement?.classList.add(h))}function le(e){C()&&(e&&e.type==I.Element?e.getNode().classList.add(f):e&&e.type==I.Text&&e.getNode().parentElement?.classList.add(p))}function z(e){C()&&(e&&e.type==I.Element?e.getNode().classList.remove(f):e&&e.type==I.Text&&e.getNode().parentElement?.classList.remove(p))}var B=`\x1B[106mDOM\x1B[0m`,ue=class{_transaction;_treeWalker;_config;_completed=!1;_currentNode=null;_previousNode=null;constructor(e,t,n){this._transaction=t,this._config=n,this._treeWalker=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT)}get completed(){return this._completed}get currentNode(){return this._currentNode}get previousNode(){return this._previousNode}goToNextNode(){this._treeWalker.nextNode()||(this._completed=!0),S.debug(B,`moving to next node`),this.setState()}goToNextSiblingOrParentSibling(){let e=0;if(this._treeWalker.nextSibling())return S.debug(B,`moving to next sibling node`),this.setState(),{parentsTraversed:e};for(;this._treeWalker.parentNode();)if(e++,this._treeWalker.nextSibling())return S.debug(B,`moving to parent sibling node, traversed:`,e),this.setState(),{parentsTraversed:e};return this._completed=!0,{parentsTraversed:e}}goToFirstChildOrNextNode(){return this._treeWalker.firstChild()?(S.debug(B,`moving to first child node`),this.setState(),{parentsTraversed:1}):(this.goToNextNode(),{parentsTraversed:0})}setState(){this._previousNode=this._currentNode,this._currentNode=R(this._treeWalker.currentNode,this._transaction,oe(this._treeWalker.currentNode,this._config));DEV:le(this._currentNode);DEV:z(this._previousNode);S.debug(B,`moved to node`,{currentNode:this._currentNode,previousNode:this._previousNode})}},de=class{_onRollback;_onCommit;isActive;constructor(){this._onRollback=[],this._onCommit=[],this.isActive=!1}start=()=>{if(this.isActive)throw Error(`Transaction already in progress`);this.isActive=!0,this._onRollback=[],this._onCommit=[]};addRollbackCallback=e=>{this._onRollback.push(e)};addCommitCallback=e=>{if(!this.isActive){e();return}this._onCommit.push(e)};rollback=()=>{this.isActive&&(this.isActive=!1,this._onRollback.forEach(e=>e()))};commit=()=>{this.isActive&&(this.isActive=!1,this._onCommit.forEach(e=>e()))}},V=`\x1B[102mPAGE\x1B[0m`,H=class e{currentPage;activeElement;currentElement;parentStack;pageIsFull;pageIndex;pageHeight;constructor(e,t,n,r,i,a,o){this.currentPage=e,this.activeElement=t,this.currentElement=n,this.parentStack=r,this.pageIsFull=i,this.pageIndex=a,this.pageHeight=o}static create(t,n,r,i){return new e(t,null,t,n,!1,r,i)}clone=()=>new e(this.currentPage,this.activeElement,this.currentElement,[...this.parentStack],this.pageIsFull,this.pageIndex,this.pageHeight)},fe=class e{_pageState;_transaction;_tempContainer;_config;constructor(t,n,r,i){this._tempContainer=t,this._config=i,this._transaction=r;let a=e.createPageHtmlElement(n.width),o=this.createNewPage(a);this._pageState=H.create(o,[],0,n.height),F(this._config.plugins,`onNewPage`,i.id,this)}nextPage(){let e=this.createNewPage(this._pageState.currentPage.getNode().cloneNode(!1)),t=H.create(e,[],this._pageState.pageIndex+1,this._pageState.pageHeight);this.cloneParentStackToNewPage(t),this.cleanupEmptyParent(),this._pageState=t,F(this._config.plugins,`onNewPage`,this._config.id,this)}cloneParentStackToNewPage(e){for(let t of this._pageState.parentStack){let n=t.clone(!1);e.currentElement.appendChild(n),e.currentElement=n,e.parentStack.push(n)}}cleanupEmptyParent(){let e=[...this._pageState.parentStack];this._transaction.addCommitCallback(()=>{for(let t=e.length-1;t>=0;t--){let n=e[t];n.isEmpty()&&n.remove()}})}enterElement(){if(!this._pageState.activeElement||this._pageState.activeElement.type!==I.Element)throw Error(`Invalid state: activeElement is not an Element`);S.debug(V,`entering an element`,this._pageState.activeElement),this._pageState.currentElement=this._pageState.activeElement,this._pageState.parentStack.push(this._pageState.activeElement)}leaveElement(){this._pageState.activeElement=null;let e=this._pageState.parentStack.pop();S.debug(V,`leaving a parent element`,e);let t=this._pageState.parentStack.at(-1);this._pageState.currentElement=t??this._pageState.currentPage}static createPageHtmlElement(e){let t=document.createElement(`div`);return t.style.width=`${e}px`,t.style.maxWidth=`${e}px`,t.className=_,t}createNewPage(e){return S.debug(V,`creating new page`),this._tempContainer.appendChild(e),this._transaction.isActive&&this._transaction.addRollbackCallback(()=>{this._tempContainer.removeChild(e)}),R(e,this._transaction,this._config)}startTransaction(){this._transaction.start();let e=this._pageState.clone();return this._transaction.addRollbackCallback(()=>{this._pageState=e}),this._transaction}hasEmptySpace(e){return!this._pageState.pageIsFull&&this._pageState.currentPage.getHeight()+(e||1e-4)<=this._pageState.pageHeight}isOverFlow(){return this._pageState.pageIsFull||this._pageState.currentPage.getHeight()>this._pageState.pageHeight}markPageAsFull(){S.debug(V,`marking page as full`,this._pageState.activeElement),this._pageState.pageIsFull=!0}appendChild(e,t){let n=e.clone(t);DEV:z(n);return this._pageState.currentElement.appendChild(n),this._pageState.activeElement=n,n}addTextNode(e){if(this._pageState.activeElement?.type===I.Text)return this._pageState.activeElement;let t=R(document.createTextNode(e),this._transaction,this._config);return this._pageState.currentElement.appendChild(t),this._pageState.activeElement=t,t}getPageState(){return this._pageState}},U={None:0,FullNodePlaced:1,SplitChildren:2};function pe(e,t){let n=W(e,t);if(n!==U.None)return n;let{rollback:r,commit:i}=t.startTransaction();t.nextPage();let a=W(e,t);return a===U.None?(r(),e.config.keepOnSamePage===`prefer`?G(e,t):(S.error(`Element is too big to fit on a page`,e),U.None)):(i(),a)}function W(e,t){if(t.hasEmptySpace(e.getHeight())){let n=t.appendChild(e,!0);if(t.isOverFlow())n.remove();else return U.FullNodePlaced}return e.config.keepOnSamePage===!1?G(e,t):U.None}function G(e,t){if(e.getChildrenCount()===0)return U.None;let n=t.appendChild(e,!1);return t.isOverFlow()?(n.remove(),U.None):U.SplitChildren}function me(e,t){let n=U.FullNodePlaced,r=e.textContent.split(/(\s+)/).filter(e=>e!==``),i,a=0;for(;i||a<r.length;){let o=he(i??r[a],t,e.config);o.completed||(n=U.None),o.pendingToken?i=o.pendingToken:(i=void 0,a++)}return n}function he(e,t,n){let r=t.addTextNode(``),i=r.textContent;if(r.textContent+=e,!t.isOverFlow())return{completed:!0};r.textContent=i;let a=ge(e,t,n);return{pendingToken:a.leftovers,completed:a.completed}}function ge(e,t,n){let{rollback:r,commit:i}=t.startTransaction();if(t.nextPage(),t.addTextNode(e),!t.isOverFlow())return i(),{completed:!0};if(r(),n.hyphenationDisabled)return S.warn(`Hyphenation disabled, skipping oversized token:`,e),{completed:!1};t.hasEmptySpace()||t.nextPage();let a=_e(e,n.hyphen,t);return{completed:!0,leftovers:a&&a.length>0?a:void 0}}function _e(e,t,n){let r=n.addTextNode(``),i=``;for(let a=0;a<e.length;a++){let o=e[a],s=i+o;if(r.textContent=s+t,!n.hasEmptySpace())return r.textContent=i?i+t:``,n.markPageAsFull(),e.slice(a);i=s}return null}var K=`\x1B[103mPAGINATOR\x1B[0m`,q=class e{_domState;_pageManager;_transaction;_tempContainer;_config;constructor(t,n,r){this._config={...ae,...r},this._tempContainer=e.createTempContainer(this._config.id),this._transaction=new de,this._domState=new ue(t,this._transaction,this._config),this._pageManager=new fe(this._tempContainer,n,this._transaction,this._config)}static createTempContainer(e){let t=document.createElement(`div`);return t.style.display=`flex`,t.style.flexDirection=`column`,t.style.gap=`20px`,t.setAttribute(`${b}-section-id`,e),t.classList.add(d),C()||E(t),document.body.appendChild(t),t}static paginate(t,n,r){let i=new e(t,n,r);i.processAllNodes();let a=Array.from(i._tempContainer.childNodes).filter(e=>w(e)).map(e=>e.innerHTML);return C()?Array.from(i._tempContainer.childNodes).forEach(e=>{let t=e;t.style.height=`${n.height}px`,t.style.width=`${n.width}px`}):i._tempContainer.remove(),a}processAllNodes(){F(this._config.plugins,`beforePagination`,this._config.id,this._domState,this._pageManager),this._domState.goToNextNode();do{x.default.debug(K,`paginating node`,this._domState.currentNode);let e=this.processCurrentNode();switch(F(this._config.plugins,`afterVisitNode`,this._config.id,e,this._domState,this._pageManager),e){case U.None:this.handleNodeSkipped();break;case U.FullNodePlaced:this.handleFullNodePlaced();break;case U.SplitChildren:this.handleChildrenSplit();break}}while(this._domState.completed===!1);F(this._config.plugins,`afterPagination`,this._config.id,this._domState,this._pageManager),x.default.debug(K,`pagination completed`)}handleNodeSkipped(){x.default.debug(K,`node skipped - couldn't paginate`);DEV:ce(this._domState.currentNode);this._domState.goToNextSiblingOrParentSibling()}handleFullNodePlaced(){x.default.debug(K,`node fully paginated`);let{parentsTraversed:e}=this._domState.goToNextSiblingOrParentSibling();for(let t=0;t<e;t++)this._pageManager.leaveElement()}handleChildrenSplit(){x.default.debug(K,`node partially paginated - splitting children`),this._domState.goToFirstChildOrNextNode().parentsTraversed===1&&this._domState.previousNode?.type===I.Element&&this._pageManager.enterElement()}processCurrentNode(){if(!this._domState.currentNode)return U.None;if(this._domState.currentNode.type===I.Element){let e={};return F(this._config.plugins,`onVisitElement`,this._config.id,this._domState,this._pageManager,e),e.result===void 0?pe(this._domState.currentNode,this._pageManager):e.result}else{let e={};return F(this._config.plugins,`onVisitText`,this._config.id,this._domState,this._pageManager,e),e.result===void 0?me(this._domState.currentNode,this._pageManager):e.result}}},J=class{registry=new Map;addEventListener(e,t){let{registry:n}=this,r=new Set(n.get(e));return r.add(t),n.set(e,r),()=>this.removeEventListener(e,t)}removeEventListener(e,t){let{registry:n}=this,r=new Set(n.get(e));r.delete(t),n.set(e,r)}async dispatch(e,...t){let{registry:n}=this,r=n.get(e);if(r)for(let e of r)await e(...t)}},ve={A1:{height:`841mm`,width:`594mm`},A2:{height:`594mm`,width:`420mm`},A3:{height:`420mm`,width:`297mm`},A4:{height:`297mm`,width:`210mm`},A5:{height:`210mm`,width:`148mm`},A6:{height:`148mm`,width:`105mm`},B3:{height:`500mm`,width:`353mm`},B4:{height:`353mm`,width:`250mm`},B5:{height:`250mm`,width:`176mm`},Letter:{height:`8.5in`,width:`11in`},Legal:{height:`11in`,width:`8.5in`},Tabloid:{height:`11in`,width:`17in`}},ye={Normal:{top:`1in`,right:`1in`,bottom:`1in`,left:`1in`},Narrow:{top:`0.4in`,right:`0.6in`,bottom:`0.6in`,left:`0.6in`},Wide:{top:`0.5in`,right:`2in`,bottom:`0.5in`,left:`2in`},None:{top:`0in`,right:`0in`,bottom:`0in`,left:`0in`}},be=`__PAPRIZE_IS_INITIALIZED`,Y=`__PAPRIZE_IS_READY`,xe=`__PAPRIZE_READ_JSON_DATA_FILE`;function Se(e){let t=e.getBoundingClientRect(),n=getComputedStyle(e),r=parseFloat(n.marginLeft)||0,i=parseFloat(n.marginRight)||0;return{height:T(e),width:t.width+r+i}}function Ce(e,t,n){let{height:r,width:i}=Se(e);return{height:r,width:i,sectionHeaderHeight:t?T(t):0,sectionFooterHeight:n?T(n):0}}function we(e,t,n){return{name:`sectionPageHeight`,order:1,afterPagination:(e,t,r)=>{n<=0||r.hasEmptySpace(n)||r.nextPage()},onNewPage:(r,i)=>{let a=i.getPageState();a.pageIndex===0?a.pageHeight=e+n:a.pageHeight=e+t+n}}}function Te(e){return e?`${e.top} ${e.right} ${e.bottom} ${e.left}`:`0`}function Ee(e){let t=null;return()=>(t||=e(),t)}async function De(){if(!(`__PAPRIZE_READ_JSON_DATA_FILE`in window))return null;let e=await window[xe]?.();return e?JSON.parse(e):null}var Oe=`
2
2
  html {
3
3
  box-sizing: border-box;
4
4
  }
@@ -22,7 +22,7 @@
22
22
  }
23
23
 
24
24
  @media screen {
25
- .${C} {
25
+ .${y} {
26
26
  min-height: 100vh;
27
27
  display: flex;
28
28
  flex-direction: column;
@@ -31,25 +31,25 @@
31
31
  padding: var(--paprize-preview-padding);
32
32
  }
33
33
 
34
- .${A} {
34
+ .${_} {
35
35
  box-shadow: var(--paprize-page-box-shadow);
36
36
  background-color: var(--paprize-page-background-color);
37
37
  }
38
38
 
39
- .${ie} {
39
+ .${v} {
40
40
  margin-bottom: var(--paprize-section-margin-bottom);
41
41
  }
42
42
  }
43
43
 
44
44
  @media print {
45
- html:has(.${C}) *:not(.${C}):not(.${C} *):not(:has(.${C})) {
45
+ html:has(.${y}) *:not(.${y}):not(.${y} *):not(:has(.${y})) {
46
46
  display: none !important;
47
47
  }
48
48
  }
49
- `,ot={display:"flex",flexDirection:"column"},rt={position:"absolute",left:"-9999px",top:"-9999px",visibility:"hidden"},st=(i,e)=>({display:"flex",flexDirection:"column",width:i.width,height:i.height,maxHeight:i.height,position:"relative",padding:tt(e),zIndex:"1"}),at={overflow:"hidden",width:"100%",height:"100%"},lt={position:"absolute",width:"100%",height:"100%",left:0,top:0},ct=i=>({page:`section-${i}`});function dt(i,e){return`@page section-${i} {
49
+ `,ke={display:`flex`,flexDirection:`column`},Ae={position:`absolute`,left:`-9999px`,top:`-9999px`,visibility:`hidden`},je=(e,t)=>({display:`flex`,flexDirection:`column`,width:e.width,height:e.height,maxHeight:e.height,position:`relative`,padding:Te(t),zIndex:`1`}),Me={overflow:`hidden`,width:`100%`,height:`100%`},Ne={position:`absolute`,width:`100%`,height:`100%`,left:0,top:0},Pe=e=>({page:`section-${e}`});function Fe(e,t){return`@page section-${e} {
50
50
  margin: none;
51
- size:${e.width} ${e.height};
52
- width:${e.width};
53
- height:${e.height};
54
- }`}const _={globalStyle:ve,component:ot,outOfScreen:rt,page:st,overlay:lt,pageContent:at,sectionPageMedia:dt,section:ct};function $(i){return i?.cloneNode(!0)??null}function be(i){return{sectionHeader:$(i.sectionHeader),sectionFooter:$(i.sectionFooter),pageHeader:$(i.pageHeader),pageFooter:$(i.pageFooter),pageContent:$(i.pageContent)}}const ye="data-pz-page-break";class we{name="pageBreak";order=1;onVisitElement=(e,t,n,o)=>{t.currentNode.getNode().getAttribute(ye)==="true"&&(n.markPageAsFull(),o.result=p.FullNodePlaced)}}class Ne{_options={};name="table";order=1;constructor(e={}){this._options=e}onNewPage=(e,t)=>{if(this._options.includeHeaderOnlyTables)return;const o=t.getPageState().parentStack.find(y=>this._isTable(y.getNode()));if(!o||!o.clonedFrom)return;const r=o.clonedFrom,s=r.getNode(),d=s.tHead;if(!(d!==null))return;const T=s.tBodies;if(!this._isTableBodyEmpty(T))return;if(r.remove(),o.getNode().tHead===null){const y=M(d.cloneNode(!0),o.transaction,o.config);o.appendChild(y)}};onVisitElement=(e,t,n,o)=>{const r=t.currentNode.getNode();r.tagName==="TR"?t.currentNode.config.keepOnSamePage=!0:(r.tagName==="TFOOT"&&this._options.cloneFooter||r.tagName==="THEAD"&&this._options.cloneHeader)&&(o.result=p.FullNodePlaced)};onClone=(e,t,n)=>{if(!this._isTable(t)||!n.clonedFrom)return;const o=n.getNode();if(o.tHead||o.tFoot)return;const r=n.getOriginalNode(),s=r.tHead;if(s&&this._options.cloneHeader===!0){const b=new F(s.cloneNode(!0),n.transaction,n.config);n.appendChild(b)}const d=r.tFoot;if(d&&this._options.cloneFooter===!0){const b=new F(d.cloneNode(!0),n.transaction,n.config);n.appendChild(b)}};_isTable(e){return e.tagName==="TABLE"}_isTableBodyEmpty(e){if(e.length===0)return!0;const t=e[0];if(t.rows.length===0)return!0;if(t.rows.length>1)return!1;const n=t.rows[0];return n.cells.length===0?!0:n.cells.length>1?!1:n.cells[0].textContent?.trim().length===0}}const Se=[new we,new Ne],gt={name:"debug",order:Number.MAX_SAFE_INTEGER,onNewPage:(i,e)=>{const t=e.getPageState().currentPage.getNode();t.classList.contains(A)||t.classList.add(A),t.setAttribute(`${w}-element`,"page"),t.setAttribute(`${w}-height`,e.getPageState().pageHeight.toString())}},Ce="sectionToc";class ut{name=Ce;order=1;_state=new Map;getContentList=()=>Array.from(this._state.values()).flat();onVisitElement=(e,t,n)=>{{const o=t.currentNode.getNode(),r=this.getHeadingLevel(o);if(!r||!o.textContent)return;const s=n.getPageState().pageIndex;s===0&&this._state.set(e,[]),this._state.get(e)?.push({sectionId:e,pageIndex:s,title:o.textContent,level:r})}};getHeadingLevel(e){const t=e.tagName;return/^H[1-6]$/.test(t)?parseInt(t.charAt(1),10):null}}class z{_promises;monitor;constructor(){this._promises=[],this.monitor=new X}toPromise(){return this._promises.length>0?Promise.allSettled(this._promises.map(e=>e.promise)).then(e=>{const t=e.find(n=>n.status==="rejected");return t?Promise.reject(t.reason):Promise.resolve()}):Promise.resolve()}then(e){this._promises.push(z.toTracked(this.toPromise().then(e)))}async add(e=[]){if(this._promises.push(...e.map(z.toTracked)),await new Promise(t=>setTimeout(t,0)),this.getPending().length===0){this.monitor.dispatch("onChange",0);return}this._promises.forEach(t=>this.injectEvents(t))}static toTracked(e){const t={promise:e,status:"pending"};return t.promise.then(()=>{t.status="resolved"}).catch(()=>{t.status="rejected"}),t}async injectEvents(e){e.promise.finally(()=>{const t=this.getPending();this.monitor.dispatch("onChange",t.length)})}getPending(){return Array.from(this._promises.values()).filter(e=>e.status==="pending")}}function pt(i,e){return`${i}-${e+1}`}function Pe(i,e){return e==="landscape"?{height:i.width,width:i.height}:i}const x="\x1B[43mREPORT\x1B[0m";class ht{_sections;_monitor;_paginationInProgress;_pendingPaginateResolvers;_currentAbortController;constructor(){this._sections=new Map,this._monitor=new X,this._paginationInProgress=!1,this._pendingPaginateResolvers=[],this._currentAbortController=null,window[_e]=!0,this._injectStyle(_.globalStyle)}get monitor(){return this._monitor}removeSection(e){this._sections.delete(e)}async tryAddSection(e,t,n){if(this._sections.has(e.id))return!1;const o={sectionIndex:this._sections.size,sectionId:e.id,isPaginated:!1,isSuspended:!!e.suspense?.length,pages:[],options:{...e,size:Pe(e.size,e.orientation??"portrait")},components:t};return this._sections.set(e.id,{context:o,onPaginationCompleted:n}),this._injectStyle(_.sectionPageMedia(e.id,e.size)),await this._monitor.dispatch("sectionCreated",o),!0}async schedulePagination(){return this._sections.size===0?(window[Y]=!0,{sections:[],suspension:Promise.resolve()}):(this._paginationInProgress&&this._currentAbortController&&(u.debug(x,"Cancelling previous pagination operation."),this._currentAbortController.abort("Cancelled by new paginate call")),this._paginationInProgress?new Promise((e,t)=>{this._pendingPaginateResolvers.push({resolve:e,reject:t})}):this._executePagination())}async getJsonData(e){return await this._lazyJsonDataReader().catch(()=>e)??e??null}_lazyJsonDataReader=nt(it);async _executePagination(){this._paginationInProgress=!0,this._currentAbortController=new AbortController;const e=this._currentAbortController.signal;try{if(u.debug(x,"Schedule paginate."),await document.fonts.ready,e.aborted)return new Promise((o,r)=>{this._pendingPaginateResolvers.push({resolve:o,reject:r})});const t=[];for(const o of this._sections.values()){o.context.isPaginated=!1;const r=new z;await r.add(o.context.options.suspense),r.monitor.addEventListener("onChange",s=>{u.debug(x,`${s} pending promises in section '${o.context.sectionId}'.`)}),r.then(async()=>{e.aborted||(u.debug(x,`Start paginating section '${o.context.sectionId}'.`),o.context.isSuspended=!1,await this._paginateSection(o))}),t.push(r)}const n=new z;return n.monitor.addEventListener("onChange",async()=>{u.debug(x,"Report pagination completed."),await this._monitor.dispatch("paginationCycleCompleted",{sections:[...this._sections.values()].map(o=>o.context)})}),e.aborted?new Promise((o,r)=>{this._pendingPaginateResolvers.push({resolve:o,reject:r})}):(await n.add(t.map(o=>o.toPromise())),{sections:[...this._sections.values()].map(o=>o.context),suspension:n.toPromise().then(()=>{window[Y]=!0})})}finally{this._processPendingPagination(),this._paginationInProgress=!1,this._currentAbortController=null}}async _processPendingPagination(){if(this._pendingPaginateResolvers.length===0)return;u.debug(x,`Processing ${this._pendingPaginateResolvers.length} pending paginate calls.`);const e=[...this._pendingPaginateResolvers];this._pendingPaginateResolvers=[];const t=await this._executePagination();for(const n of e)n.resolve(t)}_injectStyle(e){let t=document.getElementById(V);t||(t=document.createElement("style"),t.id=V,t.textContent="",document.head.appendChild(t)),t.textContent=(t.textContent+e).replace(/\s+/g," ").replace(/\s*([:;{}])\s*/g,"$1").trim()}async _paginateSection(e){const t=document.createElement("div");Object.assign(t.style,_.page(e.context.options.size,e.context.options.margin??fe.None)),B()||Object.assign(t.style,_.outOfScreen);const n=be(e.context.components);n.sectionHeader&&(Object.assign(n.sectionHeader.style,_.component),t.appendChild(n.sectionHeader)),n.pageHeader&&(Object.assign(n.pageHeader.style,_.component),t.appendChild(n.pageHeader)),Object.assign(n.pageContent.style,_.pageContent),t.appendChild(n.pageContent),n.pageFooter&&(Object.assign(n.pageFooter.style,_.component),t.appendChild(n.pageFooter)),n.sectionFooter&&(Object.assign(n.sectionFooter.style,_.component),t.appendChild(n.sectionFooter)),document.body.appendChild(t);const{height:o,width:r,sectionHeaderHeight:s,sectionFooterHeight:d}=Qe(n.pageContent,n.sectionHeader,n.sectionFooter);if(o===0)throw u.error(`Pagination failed for section '${e.context.sectionId}': insufficient space for page content or content is empty. Ensure that the section has content and that the header and footer do not occupy all available space.`),t.remove(),new Error(`Pagination failed: no available space for content in section '${e.context.sectionId}'.`);const b=H.paginate(n.pageContent,{height:o,width:r},{id:e.context.sectionId,plugins:[...e.context.options.plugins??Se,et(o,s,d)]});t.remove();const T=b.map((y,ee)=>({pageIndex:ee,totalPages:b.length,sectionId:e.context.sectionId,pageContentHtml:y})),v={...e.context,isPaginated:!0,isSuspended:!1,pages:T};this._sections.set(e.context.sectionId,{...e,context:v}),await e.onPaginationCompleted(v);for(const y of T)await this._monitor.dispatch("pageCompleted",y);await this._monitor.dispatch("sectionCompleted",v)}}const Ee=["ad","adipisicing","aliqua","aliquip","amet","anim","aute","cillum","commodo","consectetur","consequat","culpa","cupidatat","deserunt","do","dolor","dolore","duis","ea","eiusmod","elit","enim","esse","est","et","eu","ex","excepteur","exercitation","fugiat","id","in","incididunt","ipsum","irure","labore","laboris","laborum","Lorem","magna","minim","mollit","nisi","non","nostrud","nulla","occaecat","officia","pariatur","proident","qui","quis","reprehenderit","sint","sit","sunt","tempor","ullamco","ut","velit","veniam","voluptate"];function mt(i,e){if(i<=0)return"";const t=[],n=Math.floor(e*982451653);for(let o=0;o<i;o++){const r=(n+o*2654435761)%Math.pow(2,32),s=Math.floor(r/Math.pow(2,32)*Ee.length);t.push(Ee[s])}return t.length>0&&(t[0]=t[0].charAt(0).toUpperCase()+t[0].slice(1)),t.join(" ")+"."}a.EventDispatcher=X,a.PageBreakPlugin=we,a.Paginator=H,a.ReportBuilder=ht,a.SectionTocPlugin=ut,a.SplitResult=p,a.TablePlugin=Ne,a.adjustPageSize=Pe,a.attributePrefix=w,a.buildPageId=pt,a.cloneComponents=be,a.createLoremIpsumParagraph=mt,a.currentElementClassName=Ie,a.currentTextClassName=Fe,a.debugPlugin=gt,a.defaultPlugins=Se,a.enableDebugMode=Re,a.getNodeLayoutOptionsFromAttribute=q,a.getVisibleHeight=I,a.globalStyle=ve,a.globalStyleId=V,a.ignoredElementClassName=Le,a.ignoredTextClassName=Oe,a.isDebugMode=B,a.isElement=J,a.isTextNode=re,a.layoutOptionHyphenAttribute=le,a.layoutOptionHyphenationDisabledAttribute=de,a.layoutOptionKeepOnSamePageAttribute=ce,a.layoutOptionsToAttributes=He,a.logger=u,a.loggerName=S,a.moveOffscreen=se,a.pageBreakAttributeName=ye,a.pageClassName=A,a.pageMargin=fe,a.pageSize=Xe,a.paprize_isInitialized=_e,a.paprize_isReady=Y,a.paprize_readJsonDataFile=Q,a.previewClassName=C,a.reportStyles=_,a.sectionClassName=ie,a.sectionTocName=Ce,a.tempContainerClassName=ne,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
55
- //# sourceMappingURL=paprize-core.umd.cjs.map
51
+ size:${t.width} ${t.height};
52
+ width:${t.width};
53
+ height:${t.height};
54
+ }`}var X={globalStyle:Oe,component:ke,outOfScreen:Ae,page:je,overlay:Ne,pageContent:Me,sectionPageMedia:Fe,section:Pe};function Z(e){return e?.cloneNode(!0)??null}function Ie(e){return{sectionHeader:Z(e.sectionHeader),sectionFooter:Z(e.sectionFooter),pageHeader:Z(e.pageHeader),pageFooter:Z(e.pageFooter),pageContent:Z(e.pageContent)}}var Le=class{_originalItemCount=new Map;name=`orderedList`;order=1;onClone=(e,t,n)=>{if(!this._isListItem(t)||!(n.clonedData.cloneCount>1))return;let r=n.getNode();r.style.listStyleType=`none`;let i=n.clonedData.clonedFrom?.getNode().parentElement,a=n.getOriginalNode().parentElement;if(!i||!a||!this._isOrderedList(i)||!this._isOrderedList(a))return;let o=this._readRenderedItemCount(a,e=>e===i);this._setListItemCount(a,i,o-1)};afterVisitNode=(e,t,n,r)=>{let i=r.getPageState().currentElement,a=i.getNode();if(!this._isOrderedList(a))return;let o=i.getOriginalNode(),s=this._readRenderedItemCount(o,e=>e!==a);a.start=o.start+s;let c=this._getListItemCount(a);this._setListItemCount(o,a,c)};beforePagination=()=>{this._originalItemCount.clear()};_isListItem(e){return e.tagName===`LI`}_isOrderedList(e){return e.tagName===`OL`}_setListItemCount(e,t,n){let r=this._originalItemCount.get(e)??new Map;r.set(t,n),this._originalItemCount.set(e,r)}_readRenderedItemCount(e,t){let n=this._originalItemCount.get(e);return n?[...n.entries()].filter(e=>t(e[0])).reduce((e,t)=>e+t[1],0):0}_getListItemCount(e){return[...e.children].filter(e=>this._isListItem(e)).length}},Re=`${b}page-break`,Q=class{name=`pageBreak`;order=1;onVisitElement=(e,t,n,r)=>{let i=t.currentNode.getNode().getAttribute(Re);(i===`true`||i===``)&&(n.markPageAsFull(),r.result=U.FullNodePlaced)}},ze=class{_options={};name=`table`;order=1;constructor(e={}){this._options=e}onNewPage=(e,t)=>{if(this._options.includeHeaderOnlyTables)return;let n=t.getPageState().parentStack.find(e=>this._isTable(e.getNode()));if(!n||!n.clonedData.clonedFrom)return;let r=n.clonedData.clonedFrom,i=r.getNode(),a=i.tHead;if(a===null)return;let o=i.tBodies;if(this._isTableBodyEmpty(o)&&(r.remove(),n.getNode().tHead===null)){let e=R(a.cloneNode(!0),n.transaction,n.config);n.appendChild(e)}};onVisitElement=(e,t,n,r)=>{let i=t.currentNode.getNode();i.tagName===`TR`?t.currentNode.config.keepOnSamePage=`prefer`:(i.tagName===`TFOOT`&&this._options.cloneFooter||i.tagName===`THEAD`&&this._options.cloneHeader)&&(r.result=U.FullNodePlaced)};onClone=(e,t,n)=>{if(!this._isTable(t)||!n.clonedData.clonedFrom)return;let r=n.getNode();if(r.tHead||r.tFoot)return;let i=n.getOriginalNode(),a=i.tHead;if(a&&this._options.cloneHeader===!0){let e=new L(a.cloneNode(!0),n.transaction,n.config);n.appendChild(e)}let o=i.tFoot;if(o&&this._options.cloneFooter===!0){let e=new L(o.cloneNode(!0),n.transaction,n.config);n.appendChild(e)}};_isTable(e){return e.tagName===`TABLE`}_isTableBodyEmpty(e){if(e.length===0)return!0;let t=e[0];if(t.rows.length===0)return!0;if(t.rows.length>1)return!1;let n=t.rows[0];return n.cells.length===0?!0:n.cells.length>1?!1:n.cells[0].textContent?.trim().length===0}},Be=[new Q,new ze,new Le],Ve={name:`debug`,order:2**53-1,onNewPage:(e,t)=>{let n=t.getPageState().currentPage.getNode();n.classList.contains(`pz-page`)||n.classList.add(_),n.setAttribute(`${b}-element`,`page`),n.setAttribute(`${b}-height`,t.getPageState().pageHeight.toString())}},He=`sectionToc`,Ue=class{name=He;order=1;_state=new Map;getContentList=()=>Array.from(this._state.values()).flat();beforePagination=e=>{this._state.set(e,[])};onVisitElement=(e,t,n)=>{{let r=t.currentNode.getNode(),i=this.getHeadingLevel(r);if(!i||!r.textContent)return;let a=n.getPageState().pageIndex;this._state.get(e)?.push({sectionId:e,pageIndex:a,title:r.textContent,level:i})}};getHeadingLevel(e){let t=e.tagName;return/^H[1-6]$/.test(t)?parseInt(t.charAt(1),10):null}},We=class e{_promises;monitor;constructor(){this._promises=[],this.monitor=new J}toPromise(){return this._promises.length>0?Promise.allSettled(this._promises.map(e=>e.promise)).then(e=>{let t=e.find(e=>e.status===`rejected`);return t?Promise.reject(t.reason):Promise.resolve()}):Promise.resolve()}then(t){this._promises.push(e.toTracked(this.toPromise().then(t)))}async add(t=[]){if(this._promises.push(...t.map(e.toTracked)),await new Promise(e=>setTimeout(e,0)),this.getPending().length===0){this.monitor.dispatch(`onChange`,0);return}this._promises.forEach(e=>this.injectEvents(e))}static toTracked(e){let t={promise:e,status:`pending`};return t.promise.then(()=>{t.status=`resolved`}).catch(()=>{t.status=`rejected`}),t}async injectEvents(e){e.promise.finally(()=>{let e=this.getPending();this.monitor.dispatch(`onChange`,e.length)})}getPending(){return Array.from(this._promises.values()).filter(e=>e.status===`pending`)}};function Ge(e,t){return`${e}-${t+1}`}function Ke(e,t){return t===`landscape`?{height:e.width,width:e.height}:e}var $=`\x1B[43mREPORT\x1B[0m`,qe=class{_sections;_monitor;_paginationInProgress;_pendingPaginateResolvers;_currentAbortController;constructor(){this._sections=new Map,this._monitor=new J,this._paginationInProgress=!1,this._pendingPaginateResolvers=[],this._currentAbortController=null,window[be]=!0,this._injectStyle(X.globalStyle)}get monitor(){return this._monitor}removeSection(e){this._sections.delete(e)}async tryAddSection(e,t,n){if(this._sections.has(e.id))return!1;let r={sectionIndex:this._sections.size,sectionId:e.id,isPaginated:!1,isSuspended:!!e.suspense?.length,pages:[],options:{...e,size:Ke(e.size,e.orientation??`portrait`)},components:t};return this._sections.set(e.id,{context:r,onPaginationCompleted:n}),this._injectStyle(X.sectionPageMedia(e.id,e.size)),await this._monitor.dispatch(`sectionCreated`,r),!0}async schedulePagination(){return this._sections.size===0?(window[Y]=!0,{sections:[],suspension:Promise.resolve()}):(this._paginationInProgress&&this._currentAbortController&&(S.debug($,`Cancelling previous pagination operation.`),this._currentAbortController.abort(`Cancelled by new paginate call`)),this._paginationInProgress?new Promise((e,t)=>{this._pendingPaginateResolvers.push({resolve:e,reject:t})}):this._executePagination())}async getJsonData(e){return await this._lazyJsonDataReader().catch(()=>e)??e??null}_lazyJsonDataReader=Ee(De);async _executePagination(){this._paginationInProgress=!0,this._currentAbortController=new AbortController;let e=this._currentAbortController.signal;try{if(S.debug($,`Schedule paginate.`),await document.fonts.ready,e.aborted)return new Promise((e,t)=>{this._pendingPaginateResolvers.push({resolve:e,reject:t})});let t=[];for(let n of this._sections.values()){n.context.isPaginated=!1;let r=new We;await r.add(n.context.options.suspense),r.monitor.addEventListener(`onChange`,e=>{S.debug($,`${e} pending promises in section '${n.context.sectionId}'.`)}),r.then(async()=>{e.aborted||(S.debug($,`Start paginating section '${n.context.sectionId}'.`),n.context.isSuspended=!1,await this._paginateSection(n))}),t.push(r)}let n=new We;return n.monitor.addEventListener(`onChange`,async()=>{S.debug($,`Report pagination completed.`),await this._monitor.dispatch(`paginationCycleCompleted`,{sections:[...this._sections.values()].map(e=>e.context)})}),e.aborted?new Promise((e,t)=>{this._pendingPaginateResolvers.push({resolve:e,reject:t})}):(await n.add(t.map(e=>e.toPromise())),{sections:[...this._sections.values()].map(e=>e.context),suspension:n.toPromise().then(()=>{window[Y]=!0})})}finally{this._processPendingPagination(),this._paginationInProgress=!1,this._currentAbortController=null}}async _processPendingPagination(){if(this._pendingPaginateResolvers.length===0)return;S.debug($,`Processing ${this._pendingPaginateResolvers.length} pending paginate calls.`);let e=[...this._pendingPaginateResolvers];this._pendingPaginateResolvers=[];let t=await this._executePagination();for(let n of e)n.resolve(t)}_injectStyle(e){let t=document.getElementById(g);t||(t=document.createElement(`style`),t.id=g,t.textContent=``,document.head.appendChild(t)),t.textContent=(t.textContent+e).replace(/\s+/g,` `).replace(/\s*([:;{}])\s*/g,`$1`).trim()}async _paginateSection(e){let t=document.createElement(`div`);Object.assign(t.style,X.page(e.context.options.size,e.context.options.margin??ye.None)),C()||Object.assign(t.style,X.outOfScreen);let n=Ie(e.context.components);n.sectionHeader&&(Object.assign(n.sectionHeader.style,X.component),t.appendChild(n.sectionHeader)),n.pageHeader&&(Object.assign(n.pageHeader.style,X.component),t.appendChild(n.pageHeader)),Object.assign(n.pageContent.style,X.pageContent),t.appendChild(n.pageContent),n.pageFooter&&(Object.assign(n.pageFooter.style,X.component),t.appendChild(n.pageFooter)),n.sectionFooter&&(Object.assign(n.sectionFooter.style,X.component),t.appendChild(n.sectionFooter)),document.body.appendChild(t);let{height:r,width:i,sectionHeaderHeight:a,sectionFooterHeight:o}=Ce(n.pageContent,n.sectionHeader,n.sectionFooter);if(r===0)throw S.error(`Pagination failed for section '${e.context.sectionId}': insufficient space for page content or content is empty. Ensure that the section has content and that the header and footer do not occupy all available space.`),t.remove(),Error(`Pagination failed: no available space for content in section '${e.context.sectionId}'.`);let s=q.paginate(n.pageContent,{height:r,width:i},{id:e.context.sectionId,plugins:[...e.context.options.plugins??Be,we(r,a,o)]});t.remove();let c=s.map((t,n)=>({pageIndex:n,totalPages:s.length,sectionId:e.context.sectionId,pageContentHtml:t})),l={...e.context,isPaginated:!0,isSuspended:!1,pages:c};this._sections.set(e.context.sectionId,{...e,context:l}),await e.onPaginationCompleted(l);for(let e of c)await this._monitor.dispatch(`pageCompleted`,e);await this._monitor.dispatch(`sectionCompleted`,l)}},Je=`ad.adipisicing.aliqua.aliquip.amet.anim.aute.cillum.commodo.consectetur.consequat.culpa.cupidatat.deserunt.do.dolor.dolore.duis.ea.eiusmod.elit.enim.esse.est.et.eu.ex.excepteur.exercitation.fugiat.id.in.incididunt.ipsum.irure.labore.laboris.laborum.Lorem.magna.minim.mollit.nisi.non.nostrud.nulla.occaecat.officia.pariatur.proident.qui.quis.reprehenderit.sint.sit.sunt.tempor.ullamco.ut.velit.veniam.voluptate`.split(`.`);function Ye(e,t){if(e<=0)return``;let n=[],r=Math.floor(t*982451653);for(let t=0;t<e;t++){let e=(r+t*2654435761)%2**32,i=Math.floor(e/2**32*Je.length);n.push(Je[i])}return n.length>0&&(n[0]=n[0].charAt(0).toUpperCase()+n[0].slice(1)),n.join(` `)+`.`}e.EventDispatcher=J,e.OrderedListPlugin=Le,e.PageBreakPlugin=Q,e.Paginator=q,e.ReportBuilder=qe,e.SectionTocPlugin=Ue,e.SplitResult=U,e.TablePlugin=ze,e.adjustPageSize=Ke,e.attributePrefix=b,e.buildPageId=Ge,e.cloneComponents=Ie,e.createLoremIpsumParagraph=Ye,e.currentElementClassName=f,e.currentTextClassName=p,e.debugPlugin=Ve,e.defaultPlugins=Be,e.enableDebugMode=te,e.getNodeLayoutOptionsFromAttribute=N,e.getVisibleHeight=T,e.globalStyle=Oe,e.globalStyleId=g,e.ignoredElementClassName=m,e.ignoredTextClassName=h,e.isDebugMode=C,e.isElement=w,e.isTextNode=ne,e.layoutOptionHyphenAttribute=O,e.layoutOptionHyphenationDisabledAttribute=A,e.layoutOptionKeepOnSamePageAttribute=k,e.layoutOptionsToAttributes=re,e.logger=S,e.loggerName=u,e.moveOffscreen=E,e.pageBreakAttributeName=Re,e.pageClassName=_,e.pageMargin=ye,e.pageSize=ve,e.paprize_isInitialized=be,e.paprize_isReady=Y,e.paprize_readJsonDataFile=xe,e.previewClassName=y,e.reportStyles=X,e.sectionClassName=v,e.sectionTocName=He,e.tempContainerClassName=d});
55
+ //# sourceMappingURL=paprize-core.umd.cjs.map