@paprize/core 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/paprize-core.d.ts +26 -8
- package/dist/paprize-core.js +299 -285
- package/dist/paprize-core.js.map +1 -1
- package/dist/paprize-core.umd.cjs +5 -7
- package/dist/paprize-core.umd.cjs.map +1 -1
- package/package.json +3 -3
|
@@ -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",ee="pz-temp-container",Te="pz-current-element",ke="pz-current-text",Ae="pz-ignored-element",Le="pz-ignored-text",V="paprize-global-style",B="pz-page",te="pz-section",C="pz-preview",y="data-pz-";let ne=!1;const Ie=()=>{ne=!0},D=()=>ne;function J(i){return i.nodeType===Node.ELEMENT_NODE}function ie(i){return i.nodeType===Node.TEXT_NODE}function k(i){const e=i.getBoundingClientRect(),t=getComputedStyle(i),n=parseFloat(t.marginTop)||0,o=parseFloat(t.marginBottom)||0;return e.height+n+o}function oe(i){i.style.visibility="hidden",i.style.position="absolute",i.style.left="-9999px",i.style.top="-9999px"}const re={hyphen:"-",keepOnSamePage:!1,hyphenationDisabled:!1},se={hyphen:{key:`${y}hyphen`,reader:i=>String(i)},keepOnSamePage:{key:`${y}keep-on-same-page`,reader:i=>i==="true"},hyphenationDisabled:{key:`${y}hyphenation-disabled`,reader:i=>i==="true"}};function Fe(i){const e={};for(const[t,n]of Object.entries(i)){const o=se[t];o!==void 0&&n!==void 0&&(e[o.key]=String(n))}return e}const ae=new WeakMap;function Re(i,e,t,n){if(t==null)return;const o=e(t);o!==void 0&&(n[i]=o)}function le(i){if(!i)return{};if(!(i instanceof Element))return le(i?.parentNode);const e={};for(const o of Object.keys(re)){const r=o,s=se[r],g=i.getAttribute(s.key);Re(r,s.reader,g,e)}const n={...i.parentNode?ae.get(i.parentNode):void 0,...e};return ae.set(i,n),n}const ce={id:"default",plugins:[],...re};function Oe(i,e){const t=le(i);return{...ce,...e,...t}}function He(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var j={exports:{}},$e=j.exports,de;function ze(){return de||(de=1,(function(i){(function(e,t){i.exports?i.exports=t():e.log=t()})($e,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 g(c,u){var l=c[u];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 $(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function w(c){return c==="debug"&&(c="log"),typeof console===t?!1:c==="trace"&&n?$:console[c]!==void 0?g(console,c):console.log!==void 0?g(console,"log"):e}function v(){for(var c=this.getLevel(),u=0;u<o.length;u++){var l=o[u];this[l]=u<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 b(c){return function(){typeof console!==t&&(v.call(this),this[c].apply(this,arguments))}}function Y(c,u,l){return w(c)||b.apply(this,arguments)}function Ne(c,u){var l=this,W,Q,T,f="loglevel";typeof c=="string"?f+=":"+c:typeof c=="symbol"&&(f=void 0);function ht(d){var h=(o[d]||"silent").toUpperCase();if(!(typeof window===t||!f)){try{window.localStorage[f]=h;return}catch{}try{window.document.cookie=encodeURIComponent(f)+"="+h+";"}catch{}}}function Pe(){var d;if(!(typeof window===t||!f)){try{d=window.localStorage[f]}catch{}if(typeof d===t)try{var h=window.document.cookie,U=encodeURIComponent(f),xe=h.indexOf(U+"=");xe!==-1&&(d=/^([^;]+)/.exec(h.slice(xe+U.length+1))[1])}catch{}return l.levels[d]===void 0&&(d=void 0),d}}function mt(){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 z(d){var h=d;if(typeof h=="string"&&l.levels[h.toUpperCase()]!==void 0&&(h=l.levels[h.toUpperCase()]),typeof h=="number"&&h>=0&&h<=l.levels.SILENT)return h;throw new TypeError("log.setLevel() called with invalid level: "+d)}l.name=c,l.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},l.methodFactory=u||Y,l.getLevel=function(){return T??Q??W},l.setLevel=function(d,h){return T=z(d),h!==!1&&ht(T),v.call(l)},l.setDefaultLevel=function(d){Q=z(d),Pe()||l.setLevel(d,!1)},l.resetLevel=function(){T=null,mt(),v.call(l)},l.enableAll=function(d){l.setLevel(l.levels.TRACE,d)},l.disableAll=function(d){l.setLevel(l.levels.SILENT,d)},l.rebuild=function(){if(s!==l&&(W=z(s.getLevel())),v.call(l),s===l)for(var d in r)r[d].rebuild()},W=z(s?s.getLevel():"WARN");var Ee=Pe();Ee!=null&&(T=z(Ee)),v.call(l)}s=new Ne,s.getLogger=function(u){if(typeof u!="symbol"&&typeof u!="string"||u==="")throw new TypeError("You must supply a name when creating a logger.");var l=r[u];return l||(l=r[u]=new Ne(u,s.methodFactory)),l};var ut=typeof window!==t?window.log:void 0;return s.noConflict=function(){return typeof window!==t&&window.log===s&&(window.log=ut),s},s.getLoggers=function(){return r},s.default=s,s})})(j)),j.exports}var Be=ze();const N=He(Be),p=N.getLogger(S);p.setDefaultLevel("info");const q="\x1B[46mPLUGIN\x1B[0m";function P(i,e,...t){i.sort((n,o)=>n.order-o.order).forEach(n=>{const o=n[e];if(o){p.debug(q,`executing plugin ${n.name}:${String(e)} ()`,t);try{o(...t),p.debug(q,`plugin ${n.name}:${String(e)} executed`,t)}catch(r){p.debug(q,`plugin ${n.name}:${String(e)} failed`,r)}}})}const E={Element:"element",Text:"text"};class A{_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 A(t,this.transaction,this.config,this);return P(this.config.plugins,"onClone",this.config.id,this._node,n),n}getHeight(){return k(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 De{_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(ie(i))return new De(i,e,t);if(J(i))return new A(i,e,t);throw new Error("Unsupported node type")}const L="\x1B[106mDOM\x1B[0m";class je{_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),p.debug(L,"moving to next node"),this.setState()}goToNextSiblingOrParentSibling(){let e=0;if(this._treeWalker.nextSibling())return p.debug(L,"moving to next sibling node"),this.setState(),{parentsTraversed:e};for(;this._treeWalker.parentNode();)if(e++,this._treeWalker.nextSibling())return p.debug(L,"moving to parent sibling node, traversed:",e),this.setState(),{parentsTraversed:e};return this._completed=!0,{parentsTraversed:e}}goToFirstChildOrNextNode(){return this._treeWalker.firstChild()?(p.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,Oe(this._treeWalker.currentNode,this._config)),p.debug(L,"moved to node",{currentNode:this._currentNode,previousNode:this._previousNode})}}class Me{_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 ge="\x1B[102mPAGE\x1B[0m";class I{currentPage;activeElement;currentElement;parentStack;pageIsFull;pageIndex;pageHeight;constructor(e,t,n,o,r,s,g){this.currentPage=e,this.activeElement=t,this.currentElement=n,this.parentStack=o,this.pageIsFull=r,this.pageIndex=s,this.pageHeight=g}static create(e,t,n,o){return new I(e,null,e,t,!1,n,o)}clone=()=>new I(this.currentPage,this.activeElement,this.currentElement,[...this.parentStack],this.pageIsFull,this.pageIndex,this.pageHeight)}class G{_pageState;_transaction;_tempContainer;_config;constructor(e,t,n,o){this._tempContainer=e,this._config=o,this._transaction=n;const r=G.createPageHtmlElement(t.width),s=this.createNewPage(r);this._pageState=I.create(s,[],0,t.height),P(this._config.plugins,"onNewPage",o.id,this)}nextPage(){const e=this.createNewPage(this._pageState.currentPage.getNode().cloneNode(!1)),t=I.create(e,[],this._pageState.pageIndex+1,this._pageState.pageHeight);this.cloneParentStackToNewPage(t),this.cleanupEmptyParent(),this._pageState=t,P(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");p.debug(ge,"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();p.debug(ge,"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}createNewPage(e){return 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 m={None:0,FullNodePlaced:1,SplitChildren:2};function We(i,e){const t=pe(i,e);if(t!==m.None)return t;const{rollback:n,commit:o}=e.startTransaction();e.nextPage();const r=pe(i,e);return r!==m.None?(o(),r):(n(),p.debug("Element is too big to fit on a page",i),m.None)}function pe(i,e){if(e.hasEmptySpace(i.getHeight())){const n=e.appendChild(i,!0);if(e.isOverFlow())n.remove();else return m.FullNodePlaced}if(i.config.keepOnSamePage||i.getChildrenCount()===0)return m.None;const t=e.appendChild(i,!1);return e.isOverFlow()?(t.remove(),m.None):m.SplitChildren}function Ue(i,e){let t=m.FullNodePlaced;const n=i.textContent.split(/(\s+)/).filter(s=>s!=="");let o,r=0;for(;o||r<n.length;){const s=o??n[r],g=Ve(s,e,i.config);g.completed||(t=m.None),g.pendingToken?o=g.pendingToken:(o=void 0,r++)}return t}function Ve(i,e,t){e.hasEmptySpace()||e.nextPage();const n=e.addTextNode(""),o=n.textContent;if(n.textContent+=i,!e.isOverFlow())return{completed:!0};n.textContent=o;const r=Je(i,e,t);return{pendingToken:r.leftovers,completed:r.completed}}function Je(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 p.warn("Hyphenation disabled, skipping oversized token:",i),{completed:!1};const r=qe(i,t.hyphen,e);return{completed:!0,leftovers:r&&r.length>0?r:void 0}}function qe(i,e,t){const n=t.addTextNode("");let o="";for(let r=0;r<i.length;r++){const s=i[r],g=o+s;if(n.textContent=g+e,!t.hasEmptySpace())return n.textContent=o?o+e:"",t.markPageAsFull(),i.slice(r);o=g}return null}const F="\x1B[103mPAGINATOR\x1B[0m";class R{_domState;_pageManager;_transaction;_tempContainer;_config;constructor(e,t,n){this._config={...ce,...n},this._tempContainer=R.createTempContainer(this._config.id),this._transaction=new Me,this._domState=new je(e,this._transaction,this._config),this._pageManager=new G(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(`${y}-section-id`,e),t.classList.add(ee),D()||oe(t),document.body.appendChild(t),t}static paginate(e,t,n){const o=new R(e,t,n);o.processAllNodes();const r=Array.from(o._tempContainer.childNodes).filter(s=>J(s)).map(s=>s.innerHTML);return D()||o._tempContainer.remove(),r}processAllNodes(){this._domState.goToNextNode();do{N.debug(F,"paginating node",this._domState.currentNode);const e=this.processCurrentNode();switch(P(this._config.plugins,"afterVisitNode",this._config.id,e,this._domState,this._pageManager),e){case m.None:this.handleNodeSkipped();break;case m.FullNodePlaced:this.handleFullNodePlaced();break;case m.SplitChildren:this.handleChildrenSplit();break}}while(this._domState.completed===!1);N.debug(F,"pagination completed")}handleNodeSkipped(){N.debug(F,"node skipped - couldn't paginate"),this._domState.goToNextNode()}handleFullNodePlaced(){N.debug(F,"node fully paginated");const{parentsTraversed:e}=this._domState.goToNextSiblingOrParentSibling();for(let t=0;t<e;t++)this._pageManager.leaveElement()}handleChildrenSplit(){N.debug(F,"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 m.None;if(this._domState.currentNode.type===E.Element){const e={};return P(this._config.plugins,"onVisitElement",this._config.id,this._domState,this._pageManager,e),e.result!==void 0?e.result:We(this._domState.currentNode,this._pageManager)}else{const e={};return P(this._config.plugins,"onVisitText",this._config.id,this._domState,this._pageManager,e),e.result!==void 0?e.result:Ue(this._domState.currentNode,this._pageManager)}}}class Z{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 Ge={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"}},ue={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"}},he="__PAPRIZE_IS_INITIALIZED",X="__PAPRIZE_IS_READY",K="__PAPRIZE_READ_JSON_DATA_FILE";function Ze(i){const e=i.getBoundingClientRect(),t=getComputedStyle(i),n=parseFloat(t.marginLeft)||0,o=parseFloat(t.marginRight)||0;return{height:k(i),width:e.width+n+o}}function Xe(i,e,t){const{height:n,width:o}=Ze(i),r=e?k(e):0,s=t?k(t):0;return{height:n,width:o,sectionHeaderHeight:r,sectionFooterHeight:s}}function Ke(i,e,t){return{name:"sectionPageHeight",order:1,afterVisitNode:(n,o,r,s)=>{!r.completed||t<=0||s.hasEmptySpace(t)||s.nextPage()},onNewPage:(n,o)=>{const r=o.getPageState();r.pageIndex===0?r.pageHeight=i+t:r.pageHeight=i+e+t}}}function Ye(i){return i?`${i.top} ${i.right} ${i.bottom} ${i.left}`:"0"}function Qe(i){let e=null;return()=>(e||(e=i()),e)}async function et(){if(!(K in window))return null;const i=await window[K]?.();return i?JSON.parse(i):null}const me=`
|
|
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=`
|
|
2
2
|
html {
|
|
3
3
|
box-sizing: border-box;
|
|
4
4
|
}
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
:root {
|
|
13
13
|
--paprize-page-background-color: #ffffff;
|
|
14
|
-
--paprize-page-margin-bottom: 10px;
|
|
15
14
|
--paprize-page-box-shadow: rgb(142 138 138) -1px 3px 5px 2px;
|
|
16
15
|
--paprize-section-margin-bottom: 10px;
|
|
17
16
|
--paprize-preview-background-color: rgb(218 220 224);
|
|
@@ -32,13 +31,12 @@
|
|
|
32
31
|
padding: var(--paprize-preview-padding);
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
.${
|
|
34
|
+
.${A} {
|
|
36
35
|
box-shadow: var(--paprize-page-box-shadow);
|
|
37
|
-
margin-bottom: var(--paprize-page-margin-bottom);
|
|
38
36
|
background-color: var(--paprize-page-background-color);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
.${
|
|
39
|
+
.${ie} {
|
|
42
40
|
margin-bottom: var(--paprize-section-margin-bottom);
|
|
43
41
|
}
|
|
44
42
|
}
|
|
@@ -48,10 +46,10 @@
|
|
|
48
46
|
display: none !important;
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
|
-
`,
|
|
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} {
|
|
52
50
|
margin: none;
|
|
53
51
|
size:${e.width} ${e.height};
|
|
54
52
|
width:${e.width};
|
|
55
53
|
height:${e.height};
|
|
56
|
-
}`}const _={globalStyle:me,component:tt,outOfScreen:nt,page:it,overlay:rt,pageContent:ot,sectionPageMedia:at,section:st};function O(i){return i?.cloneNode(!0)??null}function fe(i){return{sectionHeader:O(i.sectionHeader),sectionFooter:O(i.sectionFooter),pageHeader:O(i.pageHeader),pageFooter:O(i.pageFooter),pageContent:O(i.pageContent)}}const _e="data-pz-page-break";class ve{name="pageBreak";order=1;onVisitElement=(e,t,n,o)=>{t.currentNode.getNode().getAttribute(_e)==="true"&&(n.markPageAsFull(),o.result=m.FullNodePlaced)}}class be{_options={};name="table";order=1;constructor(e={}){this._options=e}onNewPage=(e,t)=>{if(this._options.includeHeaderOnlyTables)return;const o=t.getPageState().parentStack.find(b=>this._isTable(b.getNode()));if(!o||!o.clonedFrom)return;const r=o.clonedFrom,s=r.getNode(),g=s.tHead;if(!(g!==null))return;const w=s.tBodies;if(!this._isTableBodyEmpty(w))return;if(r.remove(),o.getNode().tHead===null){const b=M(g.cloneNode(!0),o.transaction,o.config);o.appendChild(b)}};onClone=(e,t,n)=>{if(t.tagName==="TR"){n.config.keepOnSamePage=!0;return}if(!this._isTable(t)||!n.clonedFrom||n.cloneCount===1)return;const o=n.getOriginalNode(),r=o.tHead;if(r&&this._options.cloneHeader===!0){const g=new A(r.cloneNode(!0),n.transaction,n.config);n.appendChild(g)}const s=o.tFoot;if(s&&this._options.cloneFooter===!0){const g=new A(s.cloneNode(!0),n.transaction,n.config);n.appendChild(g)}};_isTable(e){return e.tagName==="TABLE"}_isTableBodyEmpty(e){if(e.length===0)return!0;const t=e[0];if(t.rows.length!==1)return!1;const n=t.rows[0];return n.cells.length!==1?!1:n.cells[0].textContent.trim()===""}}const ye=[new ve,new be],lt={name:"debug",order:Number.MAX_SAFE_INTEGER,onNewPage:(i,e)=>{const t=e.getPageState().currentPage.getNode();t.classList.contains(B)||t.classList.add(B),t.setAttribute(`${y}-element`,"page"),t.setAttribute(`${y}-height`,e.getPageState().pageHeight.toString())}},we="sectionToc";class ct{name=we;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 H{_promises;monitor;constructor(){this._promises=[],this.monitor=new Z}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(H.toTracked(this.toPromise().then(e)))}async add(e=[]){if(this._promises.push(...e.map(H.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 dt(i,e){return`${i}-${e+1}`}function Se(i,e){return e==="landscape"?{height:i.width,width:i.height}:i}const x="\x1B[43mREPORT\x1B[0m";class gt{_sections;_monitor;_paginationInProgress;_pendingPaginateResolvers;_currentAbortController;constructor(){this._sections=new Map,this._monitor=new Z,this._paginationInProgress=!1,this._pendingPaginateResolvers=[],this._currentAbortController=null,window[he]=!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:[]};return this._sections.set(e.id,{context:o,options:{...e,size:Se(e.size,e.orientation??"portrait")},components:t,onPaginationCompleted:n}),this._injectStyle(_.sectionPageMedia(e.id,e.size)),await this._monitor.dispatch("sectionCreated",o),!0}async schedulePagination(){return this._sections.size===0?(window[X]=!0,{sections:[],suspension:Promise.resolve()}):(this._paginationInProgress&&this._currentAbortController&&(p.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=Qe(et);async _executePagination(){this._paginationInProgress=!0,this._currentAbortController=new AbortController;const e=this._currentAbortController.signal;try{if(p.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 H;await r.add(o.options.suspense),r.monitor.addEventListener("onChange",s=>{p.debug(x,`${s} pending promises in section '${o.options.id}'.`)}),r.then(async()=>{e.aborted||(p.debug(x,`Start paginating section '${o.options.id}'.`),o.context.isSuspended=!1,await this._paginateSection(o))}),t.push(r)}const n=new H;return n.monitor.addEventListener("onChange",async()=>{p.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[X]=!0})})}finally{this._processPendingPagination(),this._paginationInProgress=!1,this._currentAbortController=null}}async _processPendingPagination(){if(this._pendingPaginateResolvers.length===0)return;p.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.options.size,e.options.margin??ue.None)),D()||Object.assign(t.style,_.outOfScreen);const n=fe(e.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:g}=Xe(n.pageContent,n.sectionHeader,n.sectionFooter);if(o===0)throw p.error(`Pagination failed for section '${e.options.id}': 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.options.id}'.`);const $=R.paginate(n.pageContent,{height:o,width:r},{id:e.options.id,plugins:[...e.options.plugins??ye,Ke(o,s,g)]});t.remove();const w=$.map((b,Y)=>({pageIndex:Y,totalPages:$.length,sectionId:e.options.id,pageContentHtml:b}));await e.onPaginationCompleted(w);for(const b of w)await this._monitor.dispatch("pageCompleted",b);const v={...e.context,isPaginated:!0,isSuspended:!1,pages:w};this._sections.set(e.options.id,{...e,context:v}),await this._monitor.dispatch("sectionCompleted",v)}}const Ce=["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 pt(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)*Ce.length);t.push(Ce[s])}return t.length>0&&(t[0]=t[0].charAt(0).toUpperCase()+t[0].slice(1)),t.join(" ")+"."}a.EventDispatcher=Z,a.PageBreakPlugin=ve,a.Paginator=R,a.ReportBuilder=gt,a.SectionTocPlugin=ct,a.SplitResult=m,a.TablePlugin=be,a.adjustPageSize=Se,a.attributePrefix=y,a.buildPageId=dt,a.cloneComponents=fe,a.createLoremIpsumParagraph=pt,a.currentElementClassName=Te,a.currentTextClassName=ke,a.debugPlugin=lt,a.defaultPlugins=ye,a.enableDebugMode=Ie,a.getVisibleHeight=k,a.globalStyle=me,a.globalStyleId=V,a.ignoredElementClassName=Ae,a.ignoredTextClassName=Le,a.isDebugMode=D,a.isElement=J,a.isTextNode=ie,a.layoutOptionsToAttributes=Fe,a.logger=p,a.loggerName=S,a.moveOffscreen=oe,a.pageBreakAttributeName=_e,a.pageClassName=B,a.pageMargin=ue,a.pageSize=Ge,a.paprize_isInitialized=he,a.paprize_isReady=X,a.paprize_readJsonDataFile=K,a.previewClassName=C,a.reportStyles=_,a.sectionClassName=te,a.sectionTocName=we,a.tempContainerClassName=ee,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
|
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"})}));
|
|
57
55
|
//# sourceMappingURL=paprize-core.umd.cjs.map
|