@paprize/core 0.0.4 → 0.0.5
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/dist/paprize-core.d.ts +259 -15
- package/dist/paprize-core.js +775 -291
- package/dist/paprize-core.js.map +1 -1
- package/dist/paprize-core.umd.cjs +56 -1
- package/dist/paprize-core.umd.cjs.map +1 -1
- package/package.json +7 -8
|
@@ -1,2 +1,57 @@
|
|
|
1
|
-
(function(s,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(s=typeof globalThis<"u"?globalThis:s||self,_(s["paprize-core"]={}))})(this,(function(s){"use strict";const _="paprize",M="pz-temp-container",ae="pz-current-element",se="pz-current-text",le="pz-ignored-element",ce="pz-ignored-text",R="pz-page",v="data-pz-";let z=!1;const de=()=>{z=!0},ue=()=>z;function O(i){return i.nodeType===Node.ELEMENT_NODE}function U(i){return i.nodeType===Node.TEXT_NODE}function V(i){const e=i.getBoundingClientRect(),t=getComputedStyle(i),n=parseFloat(t.marginTop)||0,o=parseFloat(t.marginBottom)||0;return e.height+n+o}function ge(i){i.style.visibility="hidden",i.style.position="absolute",i.style.left="-9999px",i.style.top="-9999px"}class N{name;defaultValue;_reader;constructor(e,t,n){this.name=e,this._reader=t,this.defaultValue=n}read(e){return this._reader(e)}static createStr(e,t){return new N(e,n=>n,t)}static createBool(e,t){return new N(e,n=>n==="true",t)}}const x={hyphen:N.createStr("hyphen","-"),keepOnSamePage:N.createBool("keep-on-same-page",!1),hyphenationEnabled:N.createBool("hyphenation-enabled",!0)};function pe(i){const e={};for(const t in i){const n=i[t];if(n!==void 0){const o=x[t];e[`${v}${o.name}`]=String(n)}}return e}const he=Object.fromEntries(Object.entries(x).map(([i,e])=>[i,e.defaultValue])),q=new WeakMap;function G(i){if(!i)return{};if(!(i instanceof Element))return G(i?.parentNode);const e={};for(const o in x){const r=x[o],l=`${v}${r.name}`,f=i.getAttribute(l);f!==null&&(e[o]=r.read(f))}const n={...i.parentNode?q.get(i.parentNode):void 0,...e};return q.set(i,n),n}const j={id:"default",plugins:[],...he};function fe(i,e){const t=G(i);return{...j,...e,...t}}function me(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var A={exports:{}},_e=A.exports,J;function ve(){return J||(J=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={},l=null;function f(c,u){var a=c[u];if(typeof a.bind=="function")return a.bind(c);try{return Function.prototype.bind.call(a,c)}catch{return function(){return Function.prototype.apply.apply(a,[c,arguments])}}}function Re(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function Oe(c){return c==="debug"&&(c="log"),typeof console===t?!1:c==="trace"&&n?Re:console[c]!==void 0?f(console,c):console.log!==void 0?f(console,"log"):e}function T(){for(var c=this.getLevel(),u=0;u<o.length;u++){var a=o[u];this[a]=u<c?e:this.methodFactory(a,c,this.name)}if(this.log=this.debug,typeof console===t&&c<this.levels.SILENT)return"No console available for logging"}function Be(c){return function(){typeof console!==t&&(T.call(this),this[c].apply(this,arguments))}}function He(c,u,a){return Oe(c)||Be.apply(this,arguments)}function ne(c,u){var a=this,F,W,E,m="loglevel";typeof c=="string"?m+=":"+c:typeof c=="symbol"&&(m=void 0);function De(d){var g=(o[d]||"silent").toUpperCase();if(!(typeof window===t||!m)){try{window.localStorage[m]=g;return}catch{}try{window.document.cookie=encodeURIComponent(m)+"="+g+";"}catch{}}}function ie(){var d;if(!(typeof window===t||!m)){try{d=window.localStorage[m]}catch{}if(typeof d===t)try{var g=window.document.cookie,I=encodeURIComponent(m),re=g.indexOf(I+"=");re!==-1&&(d=/^([^;]+)/.exec(g.slice(re+I.length+1))[1])}catch{}return a.levels[d]===void 0&&(d=void 0),d}}function We(){if(!(typeof window===t||!m)){try{window.localStorage.removeItem(m)}catch{}try{window.document.cookie=encodeURIComponent(m)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}function k(d){var g=d;if(typeof g=="string"&&a.levels[g.toUpperCase()]!==void 0&&(g=a.levels[g.toUpperCase()]),typeof g=="number"&&g>=0&&g<=a.levels.SILENT)return g;throw new TypeError("log.setLevel() called with invalid level: "+d)}a.name=c,a.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},a.methodFactory=u||He,a.getLevel=function(){return E??W??F},a.setLevel=function(d,g){return E=k(d),g!==!1&&De(E),T.call(a)},a.setDefaultLevel=function(d){W=k(d),ie()||a.setLevel(d,!1)},a.resetLevel=function(){E=null,We(),T.call(a)},a.enableAll=function(d){a.setLevel(a.levels.TRACE,d)},a.disableAll=function(d){a.setLevel(a.levels.SILENT,d)},a.rebuild=function(){if(l!==a&&(F=k(l.getLevel())),T.call(a),l===a)for(var d in r)r[d].rebuild()},F=k(l?l.getLevel():"WARN");var oe=ie();oe!=null&&(E=k(oe)),T.call(a)}l=new ne,l.getLogger=function(u){if(typeof u!="symbol"&&typeof u!="string"||u==="")throw new TypeError("You must supply a name when creating a logger.");var a=r[u];return a||(a=r[u]=new ne(u,l.methodFactory)),a};var $e=typeof window!==t?window.log:void 0;return l.noConflict=function(){return typeof window!==t&&window.log===l&&(window.log=$e),l},l.getLoggers=function(){return r},l.default=l,l})})(A)),A.exports}var Ne=ve();const S=me(Ne),h=S.getLogger(_);h.setDefaultLevel("info");const B="\x1B[46mPLUGIN\x1B[0m";function b(i,e,...t){i.sort((n,o)=>n.order-o.order).forEach(n=>{const o=n[e];if(o){h.debug(B,`executing plugin ${n.name}:${String(e)} ()`,t);try{o(...t),h.debug(B,`plugin ${n.name}:${String(e)} executed`,t)}catch(r){h.debug(B,`plugin ${n.name}:${String(e)} failed`,r)}}})}const y={Element:"element",Text:"text"};class H{_node;_transaction;type=y.Element;config;constructor(e,t,n){this._node=e,this._transaction=t,this.config=n}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 H(t,this._transaction,this.config);return b(this.config.plugins,"onClone",this.config.id,this._node,n),n}getHeight(){return V(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 Se{_node;_transaction;type=y.Text;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 $(i,e,t){if(U(i))return new Se(i,e,t);if(O(i))return new H(i,e,t);throw new Error("Unsupported node type")}const C="\x1B[106mDOM\x1B[0m";class be{_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}nextNode(){this._treeWalker.nextNode()||(this._completed=!0),h.debug(C,"moving to next node"),this.setState()}nextSiblingOrParentSibling(){let e=0;if(this._treeWalker.nextSibling())return h.debug(C,"moving to next sibling node"),this.setState(),{parentsTraversed:e};for(;this._treeWalker.parentNode();)if(e++,this._treeWalker.nextSibling())return h.debug(C,"moving to parent sibling node, traversed:",e),this.setState(),{parentsTraversed:e};return this._completed=!0,{parentsTraversed:e}}firstChildOrNextNode(){return this._treeWalker.firstChild()?(h.debug(C,"moving to first child node"),this.setState(),{parentsTraversed:1}):(this.nextNode(),{parentsTraversed:0})}setState(){this._previousNode=this._currentNode,this._currentNode=$(this._treeWalker.currentNode,this._transaction,fe(this._treeWalker.currentNode,this._config)),h.debug(C,"moved to node",{currentNode:this.currentNode,previousNode:this.previousNode})}}class ye{_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 X="\x1B[102mPAGE\x1B[0m";class w{currentPage;activeElement;currentElement;parentStack;pageIsFull;pageIndex;pageHeight;constructor(e,t,n,o,r,l,f){this.currentPage=e,this.activeElement=t,this.currentElement=n,this.parentStack=o,this.pageIsFull=r,this.pageIndex=l,this.pageHeight=f}static create(e,t,n,o){return new w(e,null,e,t,!1,n,o)}clone=()=>new w(this.currentPage,this.activeElement,this.currentElement,[...this.parentStack],this.pageIsFull,this.pageIndex,this.pageHeight)}class D{_pageState;_transaction;_tempContainer;_config;constructor(e,t,n,o){this._tempContainer=e,this._config=o,this._transaction=n;const r=D.createPageHtmlElement(t.width),l=this.createNewPage(r);this._pageState=w.create(l,[],0,t.height),b(this._config.plugins,"onNewPage",o.id,this)}nextPage(){const e=this.createNewPage(this._pageState.currentPage.getNode().cloneNode(!1)),t=w.create(e,[],this._pageState.pageIndex+1,this._pageState.pageHeight);this.cloneParentStackToNewPage(t),this.cleanupEmptyParent(),this._pageState=t,b(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!==y.Element)throw new Error("Invalid state: activeElement is not an Element");h.debug(X,"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();h.debug(X,"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)}),$(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===y.Text)return this._pageState.activeElement;const t=document.createTextNode(e),n=$(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 Ee(i,e){const t=Y(i,e);if(t!==p.None)return t;const{rollback:n,commit:o}=e.startTransaction();e.nextPage();const r=Y(i,e);return r!==p.None?(o(),r):(n(),h.debug("Element is too big to fit on a page",i),p.None)}function Y(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 Ce(i,e){let t=p.FullNodePlaced;const n=i.textContent.split(/(\s+)/).filter(l=>l!=="");let o,r=0;for(;o||r<n.length;){const l=o??n[r],f=we(l,e,i.config);f.completed||(t=p.None),f.pendingToken?o=f.pendingToken:(o=void 0,r++)}return t}function we(i,e,t){e.hasEmptySpace()||e.nextPage();let n=e.addTextNode("");const o=n.textContent;if(n.textContent+=i,!e.isOverFlow())return{completed:!0};n.textContent=o;const r=Pe(i,e,t);return{pendingToken:r.leftovers,completed:r.completed}}function Pe(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.hyphenationEnabled)return h.warn("Hyphenation disabled, skipping oversized token:",i),{completed:!1};const r=Te(i,t.hyphen,e);return{completed:!0,leftovers:r&&r.length>0?r:void 0}}function Te(i,e,t){const n=t.addTextNode("");let o="";for(let r=0;r<i.length;r++){const l=i[r],f=o+l;if(n.textContent=f+e,!t.hasEmptySpace())return n.textContent=o?o+e:"",t.markPageAsFull(),i.slice(r);o=f}return null}const P="\x1B[103mPAGINATOR\x1B[0m";class L{_domState;_pageManager;_transaction;_tempContainer;_config;constructor(e,t,n){this._config={...j,...n},this._tempContainer=L.createTempContainer(this._config.id),this._transaction=new ye,this._domState=new be(e,this._transaction,this._config),this._pageManager=new D(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(`${v}-section-id`,e),t.classList.add(M),document.body.appendChild(t),t}static paginate(e,t,n){const o=new L(e,t,n);return o.processAllNodes(),Array.from(o._tempContainer.childNodes).filter(l=>O(l)).map(l=>l.innerHTML)}processAllNodes(){this._domState.nextNode();do{switch(S.debug(P,"paginating node",this._domState.currentNode),this.processCurrentNode()){case p.None:this.handleNodeSkipped();break;case p.FullNodePlaced:this.handleFullNodePlaced();break;case p.SplitChildren:this.handleChildrenSplit();break}b(this._config.plugins,"afterVisitNode",this._config.id,this._domState,this._pageManager)}while(this._domState.completed===!1);S.debug(P,"pagination completed")}handleNodeSkipped(){S.debug(P,"node skipped - couldn't paginate"),this._domState.nextNode()}handleFullNodePlaced(){S.debug(P,"node fully paginated");const{parentsTraversed:e}=this._domState.nextSiblingOrParentSibling();for(let t=0;t<e;t++)this._pageManager.leaveElement()}handleChildrenSplit(){S.debug(P,"node partially paginated - splitting children"),this._domState.firstChildOrNextNode().parentsTraversed===1&&this._domState.previousNode?.type===y.Element&&this._pageManager.enterElement()}processCurrentNode(){if(!this._domState.currentNode)return p.None;if(this._domState.currentNode.type===y.Element){const e={};return b(this._config.plugins,"onVisitElement",this._config.id,this._domState,this._pageManager,e),e.result!==void 0?e.result:Ee(this._domState.currentNode,this._pageManager)}else{const e={};return b(this._config.plugins,"onVisitText",this._config.id,this._domState,this._pageManager,e),e.result!==void 0?e.result:Ce(this._domState.currentNode,this._pageManager)}}}const Z=["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 ke(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),l=Math.floor(r/Math.pow(2,32)*Z.length);t.push(Z[l])}return t.length>0&&(t[0]=t[0].charAt(0).toUpperCase()+t[0].slice(1)),t.join(" ")+"."}const K="data-pz-page-break",Q="pageBreak",ee={name:Q,order:1,onVisitElement:(i,e,t,n)=>{e.currentNode.getNode().getAttribute(K)==="true"&&(t.markPageAsFull(),n.result=p.FullNodePlaced)}},xe=[ee],Ae={name:"debug",order:Number.MAX_SAFE_INTEGER,onNewPage:(i,e)=>{const t=e.getPageState().currentPage.getNode();t.classList.contains(R)||t.classList.add(R),t.setAttribute(`${v}-element`,"page"),t.setAttribute(`${v}-height`,e.getPageState().pageHeight.toString())}},te="sectionToc";class Le{state=[];name=te;order=1;onVisitElement=(e,t,n)=>{{const o=t.currentNode.getNode(),r=this.getHeadingLevel(o);if(!r||!o.textContent)return;this.state.push({sectionId:e,pageNumber:n.getPageState().pageIndex+1,title:o.textContent,level:r})}};getHeadingLevel(e){const t=e.tagName;return/^H[1-6]$/.test(t)?parseInt(t.charAt(1),10):null}}const Fe="__PAPRIZE_IS_READY",Ie="__PAPRIZE_READ_JSON_DATA_FILE";s.Paginator=L,s.SectionTocPlugin=Le,s.SplitResult=p,s.attributePrefix=v,s.configToAttributeMap=pe,s.createLoremIpsumParagraph=ke,s.currentElementClassName=ae,s.currentTextClassName=se,s.debugPlugin=Ae,s.defaultPlugins=xe,s.enableDebugMode=de,s.getVisibleHeight=V,s.ignoredElementClassName=le,s.ignoredTextClassName=ce,s.isDebugMode=ue,s.isElement=O,s.isTextNode=U,s.logger=h,s.loggerName=_,s.moveOffscreen=ge,s.pageBreakAttributeName=K,s.pageBreakPlugin=ee,s.pageBreakPluginName=Q,s.pageClassName=R,s.paprize_isReady=Fe,s.paprize_readJsonDataFile=Ie,s.sectionTocName=te,s.tempContainerClassName=M,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(a,C){typeof exports=="object"&&typeof module<"u"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(a=typeof globalThis<"u"?globalThis:a||self,C(a["paprize-core"]={}))})(this,(function(a){"use strict";const C="paprize",ee="pz-temp-container",Pe="pz-current-element",Ee="pz-current-text",xe="pz-ignored-element",Te="pz-ignored-text",q="paprize-global-style",B="pz-page",te="pz-section",S="pz-preview",w="data-pz-";let ne=!1;const ke=()=>{ne=!0},ie=()=>ne;function G(i){return i.nodeType===Node.ELEMENT_NODE}function oe(i){return i.nodeType===Node.TEXT_NODE}function A(i){const e=i.getBoundingClientRect(),t=getComputedStyle(i),n=parseFloat(t.marginTop)||0,o=parseFloat(t.marginBottom)||0;return e.height+n+o}function Ae(i){i.style.visibility="hidden",i.style.position="absolute",i.style.left="-9999px",i.style.top="-9999px"}class N{name;defaultValue;_reader;constructor(e,t,n){this.name=e,this._reader=t,this.defaultValue=n}read(e){return this._reader(e)}static createStr(e,t){return new N(e,n=>n,t)}static createBool(e,t){return new N(e,n=>n==="true",t)}}const D={hyphen:N.createStr("hyphen","-"),keepOnSamePage:N.createBool("keep-on-same-page",!1),hyphenationEnabled:N.createBool("hyphenation-enabled",!0)};function Le(i){const e={};for(const t in i){const n=i[t];if(n!==void 0){const o=D[t];e[`${w}${o.name}`]=String(n)}}return e}const Fe=Object.fromEntries(Object.entries(D).map(([i,e])=>[i,e.defaultValue])),re=new WeakMap;function se(i){if(!i)return{};if(!(i instanceof Element))return se(i?.parentNode);const e={};for(const o in D){const r=D[o],s=`${w}${r.name}`,d=i.getAttribute(s);d!==null&&(e[o]=r.read(d))}const n={...i.parentNode?re.get(i.parentNode):void 0,...e};return re.set(i,n),n}const ae={id:"default",plugins:[],...Fe};function Ie(i,e){const t=se(i);return{...ae,...e,...t}}function Re(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var M={exports:{}},He=M.exports,le;function $e(){return le||(le=1,(function(i){(function(e,t){i.exports?i.exports=t():e.log=t()})(He,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,p){var l=c[p];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 z(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function y(c){return c==="debug"&&(c="log"),typeof console===t?!1:c==="trace"&&n?z:console[c]!==void 0?d(console,c):console.log!==void 0?d(console,"log"):e}function v(){for(var c=this.getLevel(),p=0;p<o.length;p++){var l=o[p];this[l]=p<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 K(c,p,l){return y(c)||b.apply(this,arguments)}function Ce(c,p){var l=this,U,Q,k,f="loglevel";typeof c=="string"?f+=":"+c:typeof c=="symbol"&&(f=void 0);function ht(g){var h=(o[g]||"silent").toUpperCase();if(!(typeof window===t||!f)){try{window.localStorage[f]=h;return}catch{}try{window.document.cookie=encodeURIComponent(f)+"="+h+";"}catch{}}}function Se(){var g;if(!(typeof window===t||!f)){try{g=window.localStorage[f]}catch{}if(typeof g===t)try{var h=window.document.cookie,V=encodeURIComponent(f),Ne=h.indexOf(V+"=");Ne!==-1&&(g=/^([^;]+)/.exec(h.slice(Ne+V.length+1))[1])}catch{}return l.levels[g]===void 0&&(g=void 0),g}}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 O(g){var h=g;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: "+g)}l.name=c,l.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},l.methodFactory=p||K,l.getLevel=function(){return k??Q??U},l.setLevel=function(g,h){return k=O(g),h!==!1&&ht(k),v.call(l)},l.setDefaultLevel=function(g){Q=O(g),Se()||l.setLevel(g,!1)},l.resetLevel=function(){k=null,mt(),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&&(U=O(s.getLevel())),v.call(l),s===l)for(var g in r)r[g].rebuild()},U=O(s?s.getLevel():"WARN");var we=Se();we!=null&&(k=O(we)),v.call(l)}s=new Ce,s.getLogger=function(p){if(typeof p!="symbol"&&typeof p!="string"||p==="")throw new TypeError("You must supply a name when creating a logger.");var l=r[p];return l||(l=r[p]=new Ce(p,s.methodFactory)),l};var pt=typeof window!==t?window.log:void 0;return s.noConflict=function(){return typeof window!==t&&window.log===s&&(window.log=pt),s},s.getLoggers=function(){return r},s.default=s,s})})(M)),M.exports}var ze=$e();const P=Re(ze),u=P.getLogger(C);u.setDefaultLevel("info");const J="\x1B[46mPLUGIN\x1B[0m";function E(i,e,...t){i.sort((n,o)=>n.order-o.order).forEach(n=>{const o=n[e];if(o){u.debug(J,`executing plugin ${n.name}:${String(e)} ()`,t);try{o(...t),u.debug(J,`plugin ${n.name}:${String(e)} executed`,t)}catch(r){u.debug(J,`plugin ${n.name}:${String(e)} failed`,r)}}})}const x={Element:"element",Text:"text"};class L{_node;config;type=x.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 L(t,this.transaction,this.config,this);return E(this.config.plugins,"onClone",this.config.id,this._node,n),n}getHeight(){return A(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 Oe{_node;type=x.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 W(i,e,t){if(oe(i))return new Oe(i,e,t);if(G(i))return new L(i,e,t);throw new Error("Unsupported node type")}const F="\x1B[106mDOM\x1B[0m";class Be{_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(F,"moving to next node"),this.setState()}goToNextSiblingOrParentSibling(){let e=0;if(this._treeWalker.nextSibling())return u.debug(F,"moving to next sibling node"),this.setState(),{parentsTraversed:e};for(;this._treeWalker.parentNode();)if(e++,this._treeWalker.nextSibling())return u.debug(F,"moving to parent sibling node, traversed:",e),this.setState(),{parentsTraversed:e};return this._completed=!0,{parentsTraversed:e}}goToFirstChildOrNextNode(){return this._treeWalker.firstChild()?(u.debug(F,"moving to first child node"),this.setState(),{parentsTraversed:1}):(this.goToNextNode(),{parentsTraversed:0})}setState(){this._previousNode=this._currentNode,this._currentNode=W(this._treeWalker.currentNode,this._transaction,Ie(this._treeWalker.currentNode,this._config)),u.debug(F,"moved to node",{currentNode:this._currentNode,previousNode:this._previousNode})}}class De{_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 ce="\x1B[102mPAGE\x1B[0m";class I{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 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 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=I.create(s,[],0,t.height),E(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,E(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!==x.Element)throw new Error("Invalid state: activeElement is not an Element");u.debug(ce,"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(ce,"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)}),W(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===x.Text)return this._pageState.activeElement;const t=document.createTextNode(e),n=W(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 Me(i,e){const t=de(i,e);if(t!==m.None)return t;const{rollback:n,commit:o}=e.startTransaction();e.nextPage();const r=de(i,e);return r!==m.None?(o(),r):(n(),u.debug("Element is too big to fit on a page",i),m.None)}function de(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 We(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],d=je(s,e,i.config);d.completed||(t=m.None),d.pendingToken?o=d.pendingToken:(o=void 0,r++)}return t}function je(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=Ue(i,e,t);return{pendingToken:r.leftovers,completed:r.completed}}function Ue(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.hyphenationEnabled)return u.warn("Hyphenation disabled, skipping oversized token:",i),{completed:!1};const r=Ve(i,t.hyphen,e);return{completed:!0,leftovers:r&&r.length>0?r:void 0}}function Ve(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={...ae,...n},this._tempContainer=H.createTempContainer(this._config.id),this._transaction=new De,this._domState=new Be(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(ee),document.body.appendChild(t),t}static paginate(e,t,n){const o=new H(e,t,n);return o.processAllNodes(),Array.from(o._tempContainer.childNodes).filter(s=>G(s)).map(s=>s.innerHTML)}processAllNodes(){this._domState.goToNextNode();do{P.debug(R,"paginating node",this._domState.currentNode);const e=this.processCurrentNode();switch(E(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);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===x.Element&&this._pageManager.enterElement()}processCurrentNode(){if(!this._domState.currentNode)return m.None;if(this._domState.currentNode.type===x.Element){const e={};return E(this._config.plugins,"onVisitElement",this._config.id,this._domState,this._pageManager,e),e.result!==void 0?e.result:Me(this._domState.currentNode,this._pageManager)}else{const e={};return E(this._config.plugins,"onVisitText",this._config.id,this._domState,this._pageManager,e),e.result!==void 0?e.result:We(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)}dispatch(e,...t){const{registry:n}=this,o=n.get(e);if(o)for(const r of o)r(...t)}}const qe={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"}},Ge={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"}},Je=qe,ge=Ge;function Ze(i){const e=i.getBoundingClientRect(),t=getComputedStyle(i),n=parseFloat(t.marginLeft)||0,o=parseFloat(t.marginRight)||0;return{height:A(i),width:e.width+n+o}}function Xe(i,e,t){const{height:n,width:o}=Ze(i),r=e?A(e):0,s=t?A(t):0;return{height:n,width:o,sectionHeaderHeight:r,sectionFooterHeight:s}}function Ye(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 Ke(i){return i?`${i.top} ${i.right} ${i.bottom} ${i.left}`:"0"}const ue=`
|
|
2
|
+
html {
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
*,
|
|
7
|
+
*:before,
|
|
8
|
+
*:after {
|
|
9
|
+
box-sizing: inherit;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
:root {
|
|
13
|
+
--paprize-page-background-color: #ffffff;
|
|
14
|
+
--paprize-page-margin-bottom: 10px;
|
|
15
|
+
--paprize-page-box-shadow: rgb(142 138 138) -1px 3px 5px 2px;
|
|
16
|
+
--paprize-section-margin-bottom: 10px;
|
|
17
|
+
--paprize-preview-background-color: rgb(218 220 224);
|
|
18
|
+
--paprize-preview-padding: 30px 10px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
body {
|
|
22
|
+
margin: 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@media screen {
|
|
26
|
+
.${S} {
|
|
27
|
+
min-height: 100vh;
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-direction: column;
|
|
30
|
+
align-items: center;
|
|
31
|
+
background-color: var(--paprize-preview-background-color);
|
|
32
|
+
padding: var(--paprize-preview-padding);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.${B} {
|
|
36
|
+
box-shadow: var(--paprize-page-box-shadow);
|
|
37
|
+
margin-bottom: var(--paprize-page-margin-bottom);
|
|
38
|
+
background-color: var(--paprize-page-background-color);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.${te} {
|
|
42
|
+
margin-bottom: var(--paprize-section-margin-bottom);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@media print {
|
|
47
|
+
html:has(.${S}) *:not(.${S}):not(.${S} *):not(:has(.${S})) {
|
|
48
|
+
display: none !important;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`,Qe={display:"flex",flexDirection:"column"},et={position:"absolute",left:"-9999px",top:"-9999px",visibility:"hidden"},tt=(i,e)=>({display:"flex",flexDirection:"column",width:i.width,height:i.height,maxHeight:i.height,position:"relative",padding:Ke(e),zIndex:"1"}),nt={overflow:"hidden",width:"100%",height:"100%"},it={position:"absolute",width:"100%",height:"100%",left:0,top:0},ot=i=>({page:`section-${i}`});function rt(i,e){return`@page section-${i} {
|
|
52
|
+
margin: none;
|
|
53
|
+
size:${e.width} ${e.height};
|
|
54
|
+
width:${e.width};
|
|
55
|
+
height:${e.height};
|
|
56
|
+
}`}const _={globalStyle:ue,component:Qe,outOfScreen:et,page:tt,overlay:it,pageContent:nt,sectionPageMedia:rt,section:ot};function $(i){return i?.cloneNode(!0)??null}function pe(i){return{sectionHeader:$(i.sectionHeader),sectionFooter:$(i.sectionFooter),pageHeader:$(i.pageHeader),pageFooter:$(i.pageFooter),pageContent:$(i.pageContent)}}const he="data-pz-page-break";class me{name="pageBreak";order=1;onVisitElement=(e,t,n,o)=>{t.currentNode.getNode().getAttribute(he)==="true"&&(n.markPageAsFull(),o.result=m.FullNodePlaced)}}class fe{_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(),d=s.tHead;if(!(d!==null))return;const y=s.tBodies;if(!this._isTableBodyEmpty(y))return;if(r.remove(),o.getNode().tHead===null){const b=W(d.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 d=new L(r.cloneNode(!0),n.transaction,n.config);n.appendChild(d)}const s=o.tFoot;if(s&&this._options.cloneFooter===!0){const d=new L(s.cloneNode(!0),n.transaction,n.config);n.appendChild(d)}};_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 _e=[new me,new fe],st={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(`${w}-element`,"page"),t.setAttribute(`${w}-height`,e.getPageState().pageHeight.toString())}},ve="sectionToc";class at{name=ve;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}}const be="__PAPRIZE_IS_INITIALIZED",Y="__PAPRIZE_IS_READY",lt="__PAPRIZE_READ_JSON_DATA_FILE";class j{_promises;monitor;get promise(){return this._promises.length>0?Promise.allSettled(this._promises.map(e=>e.promise)).then(()=>{}):Promise.resolve()}constructor(){this._promises=[],this.monitor=new X}async add(e=[]){if(this._promises.push(...e.map(j.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.finally(()=>{t.status="resolved"}),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")}}const T="\x1B[43mREPORT\x1B[0m";class ct{_sections;_monitor;_paginationInProgress;_pendingPaginateResolvers;_currentAbortController;constructor(){this._sections=new Map,this._monitor=new X,this._paginationInProgress=!1,this._pendingPaginateResolvers=[],this._currentAbortController=null,window[be]=!0,this._injectStyle(_.globalStyle)}get monitor(){return this._monitor}removeSection(e){this._sections.delete(e)}tryAddSection(e,t,n){if(this._sections.has(e.id))return!1;const o={index:this._sections.size,sectionId:e.id,isPaginated:!1,isSuspended:!!e.suspense?.length,pages:[]};return this._sections.set(e.id,{context:o,options:e,components:t,onPaginationCompleted:n}),this._injectStyle(_.sectionPageMedia(e.id,e.dimension)),this._monitor.dispatch("sectionCreated",o),!0}async schedulePaginate(){return this._sections.size===0?(window[Y]=!0,{sections:[],suspension:Promise.resolve()}):(this._paginationInProgress&&this._currentAbortController&&(u.debug(T,"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 _executePagination(){this._paginationInProgress=!0,this._currentAbortController=new AbortController;const e=this._currentAbortController.signal;try{if(u.debug(T,"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 j;await r.add(o.options.suspense),r.monitor.addEventListener("onChange",s=>{u.debug(T,`${s} pending promises in section '${o.options.id}'.`)}),r.promise.then(async()=>{e.aborted||(u.debug(T,`Start paginating section '${o.options.id}'.`),o.context.isSuspended=!1,this._paginateSection(o))}),t.push(r)}const n=new j;return n.monitor.addEventListener("onChange",()=>{u.debug(T,"Report pagination completed."),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.promise)),{sections:[...this._sections.values()].map(o=>o.context),suspension:n.promise.then(()=>{window[Y]=!0})})}finally{this._processPendingPagination(),this._paginationInProgress=!1,this._currentAbortController=null}}async _processPendingPagination(){if(this._pendingPaginateResolvers.length===0)return;u.debug(T,`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(q);t||(t=document.createElement("style"),t.id=q,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.dimension,e.options.margin??ge.None)),ie()||Object.assign(t.style,_.outOfScreen);const n=pe(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:d}=Xe(n.pageContent,n.sectionHeader,n.sectionFooter),z=H.paginate(n.pageContent,{height:o,width:r},{id:e.options.id,plugins:[...e.options.plugins??_e,Ye(o,s,d)]});t.remove();const y=z.map((b,K)=>({index:K,totalPages:z.length,sectionId:e.options.id,pageContentHtml:b}));e.onPaginationCompleted(y);for(const b of y)this._monitor.dispatch("pageCompleted",b);const v={...e.context,isPaginated:!0,isSuspended:!1,pages:y};this._sections.set(e.options.id,{...e,context:v}),this._monitor.dispatch("sectionCompleted",v)}}const ye=["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 dt(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)*ye.length);t.push(ye[s])}return t.length>0&&(t[0]=t[0].charAt(0).toUpperCase()+t[0].slice(1)),t.join(" ")+"."}function gt(i,e){return`${i}-${e+1}`}function ut(i,e){return e==="landscape"?{height:i.width,width:i.height}:i}a.EventDispatcher=X,a.PageBreakPlugin=me,a.Paginator=H,a.ReportBuilder=ct,a.SectionTocPlugin=at,a.SplitResult=m,a.TablePlugin=fe,a.adjustDimension=ut,a.attributePrefix=w,a.buildPageId=gt,a.cloneComponents=pe,a.configToAttributeMap=Le,a.createLoremIpsumParagraph=dt,a.currentElementClassName=Pe,a.currentTextClassName=Ee,a.debugPlugin=st,a.defaultPlugins=_e,a.enableDebugMode=ke,a.getVisibleHeight=A,a.globalStyle=ue,a.globalStyleId=q,a.ignoredElementClassName=xe,a.ignoredTextClassName=Te,a.isDebugMode=ie,a.isElement=G,a.isTextNode=oe,a.logger=u,a.loggerName=C,a.moveOffscreen=Ae,a.pageBreakAttributeName=he,a.pageClassName=B,a.pageMargin=ge,a.pageSize=Je,a.paprize_isInitialized=be,a.paprize_isReady=Y,a.paprize_readJsonDataFile=lt,a.previewClassName=S,a.reportStyles=_,a.sectionClassName=te,a.sectionTocName=ve,a.tempContainerClassName=ee,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
|
2
57
|
//# sourceMappingURL=paprize-core.umd.cjs.map
|