@paprize/core 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`paprize-core`]={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,s=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),c=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e},l=(e,r,i)=>(i=e==null?{}:t(a(e)),c(r||!e||!e.__esModule?n(i,`default`,{value:e,enumerable:!0}):i,e)),u=`paprize`,d=`pz-temp-container`,f=`pz-current-element`,p=`pz-current-text`,m=`pz-ignored-element`,h=`pz-ignored-text`,g=`paprize-global-style`,_=`pz-page`,v=`pz-section`,y=`pz-preview`,b=`data-pz-`,x=l(s(((e,t)=>{(function(e,n){"use strict";typeof define==`function`&&define.amd?define(n):typeof t==`object`&&t.exports?t.exports=n():e.log=n()})(e,function(){"use strict";var e=function(){},t=`undefined`,n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),r=[`trace`,`debug`,`info`,`warn`,`error`],i={},a=null;function o(e,t){var n=e[t];if(typeof n.bind==`function`)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch{return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function s(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function c(r){return r===`debug`&&(r=`log`),typeof console===t?!1:r===`trace`&&n?s:console[r]===void 0?console.log===void 0?e:o(console,`log`):o(console,r)}function l(){for(var n=this.getLevel(),i=0;i<r.length;i++){var a=r[i];this[a]=i<n?e:this.methodFactory(a,n,this.name)}if(this.log=this.debug,typeof console===t&&n<this.levels.SILENT)return`No console available for logging`}function u(e){return function(){typeof console!==t&&(l.call(this),this[e].apply(this,arguments))}}function d(e,t,n){return c(e)||u.apply(this,arguments)}function f(e,n){var o=this,s,c,u,f=`loglevel`;typeof e==`string`?f+=`:`+e:typeof e==`symbol`&&(f=void 0);function p(e){var n=(r[e]||`silent`).toUpperCase();if(!(typeof window===t||!f)){try{window.localStorage[f]=n;return}catch{}try{window.document.cookie=encodeURIComponent(f)+`=`+n+`;`}catch{}}}function m(){var e;if(!(typeof window===t||!f)){try{e=window.localStorage[f]}catch{}if(typeof e===t)try{var n=window.document.cookie,r=encodeURIComponent(f),i=n.indexOf(r+`=`);i!==-1&&(e=/^([^;]+)/.exec(n.slice(i+r.length+1))[1])}catch{}return o.levels[e]===void 0&&(e=void 0),e}}function h(){if(!(typeof window===t||!f)){try{window.localStorage.removeItem(f)}catch{}try{window.document.cookie=encodeURIComponent(f)+`=; expires=Thu, 01 Jan 1970 00:00:00 UTC`}catch{}}}function g(e){var t=e;if(typeof t==`string`&&o.levels[t.toUpperCase()]!==void 0&&(t=o.levels[t.toUpperCase()]),typeof t==`number`&&t>=0&&t<=o.levels.SILENT)return t;throw TypeError(`log.setLevel() called with invalid level: `+e)}o.name=e,o.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},o.methodFactory=n||d,o.getLevel=function(){return u??c??s},o.setLevel=function(e,t){return u=g(e),t!==!1&&p(u),l.call(o)},o.setDefaultLevel=function(e){c=g(e),m()||o.setLevel(e,!1)},o.resetLevel=function(){u=null,h(),l.call(o)},o.enableAll=function(e){o.setLevel(o.levels.TRACE,e)},o.disableAll=function(e){o.setLevel(o.levels.SILENT,e)},o.rebuild=function(){if(a!==o&&(s=g(a.getLevel())),l.call(o),a===o)for(var e in i)i[e].rebuild()},s=g(a?a.getLevel():`WARN`);var _=m();_!=null&&(u=g(_)),l.call(o)}a=new f,a.getLogger=function(e){if(typeof e!=`symbol`&&typeof e!=`string`||e===``)throw TypeError(`You must supply a name when creating a logger.`);var t=i[e];return t||=i[e]=new f(e,a.methodFactory),t};var p=typeof window===t?void 0:window.log;return a.noConflict=function(){return typeof window!==t&&window.log===a&&(window.log=p),a},a.getLoggers=function(){return i},a.default=a,a})}))(),1).default.getLogger(u);x.setDefaultLevel(`info`);var ee=!1,te=()=>{x.setLevel(`debug`),ee=!0},S=()=>ee;function C(e){return e.nodeType===Node.ELEMENT_NODE}function ne(e){return e.nodeType===Node.TEXT_NODE}function w(e){let t=e.getBoundingClientRect(),n=getComputedStyle(e),r=parseFloat(n.marginTop)||0,i=parseFloat(n.marginBottom)||0;return t.height+r+i}function T(e){e.style.visibility=`hidden`,e.style.position=`absolute`,e.style.left=`-9999px`,e.style.top=`-9999px`}var E={hyphen:`-`,keepOnSamePage:!1,hyphenationDisabled:!1},D=`${b}hyphen`,O=`${b}keep-on-same-page`,k=`${b}hyphenation-disabled`,A={hyphen:{key:D,reader:e=>String(e)},keepOnSamePage:{key:O,reader:e=>{switch(e){case`true`:return!0;case`false`:return!1;case`prefer`:return`prefer`;default:return E.keepOnSamePage}}},hyphenationDisabled:{key:k,reader:e=>e===`true`}};function re(e){let t={};for(let[n,r]of Object.entries(e)){let e=A[n];e!==void 0&&r!==void 0&&(t[e.key]=String(r))}return t}var ie=new WeakMap;function ae(e,t,n,r){n!=null&&(r[e]=t(n))}function j(e){if(!e)return{};if(!(e instanceof Element))return j(e?.parentNode);let t={};for(let n of Object.keys(E)){let r=n,i=A[r],a=e.getAttribute(i.key);ae(r,i.reader,a,t)}let n={...e.parentNode?ie.get(e.parentNode):void 0,...t};return ie.set(e,n),n}var oe={id:`default`,plugins:[],...E};function se(e,t){let n=j(e);return{...oe,...t,...n}}var M=`\x1B[46mPLUGIN\x1B[0m`;function N(e,t,...n){e.sort((e,t)=>e.order-t.order).forEach(e=>{let r=e[t];if(r){x.debug(M,`executing plugin ${e.name}:${String(t)} ()`,n);try{r(...n),x.debug(M,`plugin ${e.name}:${String(t)} executed`,n)}catch(n){x.debug(M,`plugin ${e.name}:${String(t)} failed`,n)}}})}var P={Element:`element`,Text:`text`},F=class e{_node;config;type=P.Element;transaction;clonedData;constructor(e,t,n,r){this._node=e,this.transaction=t,this.config=n,this.clonedData=r?{clonedFrom:r,cloneCount:r.clonedData.cloneCount+1}:{clonedFrom:void 0,cloneCount:0}}getOriginalNode(){let e=this.clonedData.clonedFrom;for(;e?.clonedData.clonedFrom;)e=e.clonedData.clonedFrom;return e?._node??this._node}appendChild(e){this.transaction.isActive&&this.transaction.addRollbackCallback(()=>{this._node.removeChild(e.getNode())}),this._node.appendChild(e.getNode())}clone(t){let n=new e(this._node.cloneNode(t),this.transaction,this.config,this);return N(this.config.plugins,`onClone`,this.config.id,this._node,n),n}getHeight(){return w(this._node)}remove(){this.transaction.addCommitCallback(()=>{this._node.remove()})}isEmpty(){return this._node.innerHTML===``}getChildrenCount(){return this._node.childNodes.length}getNode(){return this._node}},ce=class{_node;type=P.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 I(e,t,n){if(ne(e))return new ce(e,t,n);if(C(e))return new F(e,t,n);throw Error(`Unsupported node type`)}function le(e){S()&&(e&&e.type==P.Element?e.getNode().classList.add(m):e&&e.type==P.Text&&e.getNode().parentElement?.classList.add(h))}function ue(e){S()&&(e&&e.type==P.Element?e.getNode().classList.add(f):e&&e.type==P.Text&&e.getNode().parentElement?.classList.add(p))}function L(e){S()&&(e&&e.type==P.Element?e.getNode().classList.remove(f):e&&e.type==P.Text&&e.getNode().parentElement?.classList.remove(p))}var R=`\x1B[106mDOM\x1B[0m`,de=class{_transaction;_treeWalker;_config;_completed=!1;_currentNode=null;_previousNode=null;constructor(e,t,n){this._transaction=t,this._config=n,this._treeWalker=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT)}get completed(){return this._completed}get currentNode(){return this._currentNode}get previousNode(){return this._previousNode}goToNextNode(){this._treeWalker.nextNode()||(this._completed=!0),x.debug(R,`moving to next node`),this.setState()}goToNextSiblingOrParentSibling(){let e=0;if(this._treeWalker.nextSibling())return x.debug(R,`moving to next sibling node`),this.setState(),{parentsTraversed:e};for(;this._treeWalker.parentNode();)if(e++,this._treeWalker.nextSibling())return x.debug(R,`moving to parent sibling node, traversed:`,e),this.setState(),{parentsTraversed:e};return this._completed=!0,{parentsTraversed:e}}goToFirstChildOrNextNode(){return this._treeWalker.firstChild()?(x.debug(R,`moving to first child node`),this.setState(),{parentsTraversed:1}):(this.goToNextNode(),{parentsTraversed:0})}setState(){this._previousNode=this._currentNode,this._currentNode=I(this._treeWalker.currentNode,this._transaction,se(this._treeWalker.currentNode,this._config));DEV:ue(this._currentNode);DEV:L(this._previousNode);x.debug(R,`moved to node`,{currentNode:this._currentNode,previousNode:this._previousNode})}},fe=class{_onRollback;_onCommit;isActive;constructor(){this._onRollback=[],this._onCommit=[],this.isActive=!1}start=()=>{if(this.isActive)throw Error(`Transaction already in progress`);this.isActive=!0,this._onRollback=[],this._onCommit=[]};addRollbackCallback=e=>{this._onRollback.push(e)};addCommitCallback=e=>{if(!this.isActive){e();return}this._onCommit.push(e)};rollback=()=>{this.isActive&&(this.isActive=!1,this._onRollback.forEach(e=>e()))};commit=()=>{this.isActive&&(this.isActive=!1,this._onCommit.forEach(e=>e()))}},z=`\x1B[102mPAGE\x1B[0m`,B=class e{currentPage;activeElement;currentElement;parentStack;pageIndex;pageHeight;constructor(e,t,n,r,i,a){this.currentPage=e,this.activeElement=t,this.currentElement=n,this.parentStack=r,this.pageIndex=i,this.pageHeight=a}static create(t,n,r,i){return new e(t,null,t,n,r,i)}clone=()=>new e(this.currentPage,this.activeElement,this.currentElement,[...this.parentStack],this.pageIndex,this.pageHeight)},pe=class e{_pageState;_transaction;_tempContainer;_config;constructor(t,n,r,i){this._tempContainer=t,this._config=i,this._transaction=r;let a=e.createPageHtmlElement(n.width),o=this.createNewPage(a);this._pageState=B.create(o,[],0,n.height),N(this._config.plugins,`onNewPage`,i.id,this)}nextPage(){let e=this.createNewPage(this._pageState.currentPage.getNode().cloneNode(!1)),t=B.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(let t of this._pageState.parentStack){let n=t.clone(!1);e.currentElement.appendChild(n),e.currentElement=n,e.parentStack.push(n)}}cleanupEmptyParent(){let e=[...this._pageState.parentStack];this._transaction.addCommitCallback(()=>{for(let t=e.length-1;t>=0;t--){let n=e[t];n.isEmpty()&&n.remove()}})}enterElement(){if(!this._pageState.activeElement||this._pageState.activeElement.type!==P.Element)throw Error(`Invalid state: activeElement is not an Element`);x.debug(z,`entering an element`,this._pageState.activeElement),this._pageState.currentElement=this._pageState.activeElement,this._pageState.parentStack.push(this._pageState.activeElement)}leaveElement(){this._pageState.activeElement=null;let e=this._pageState.parentStack.pop();x.debug(z,`leaving a parent element`,e);let t=this._pageState.parentStack.at(-1);this._pageState.currentElement=t??this._pageState.currentPage}static createPageHtmlElement(e){let t=document.createElement(`div`);return t.style.width=`${e}px`,t.style.maxWidth=`${e}px`,t.className=_,t}createNewPage(e){return x.debug(z,`creating new page`),this._tempContainer.appendChild(e),this._transaction.isActive&&this._transaction.addRollbackCallback(()=>{this._tempContainer.removeChild(e)}),I(e,this._transaction,this._config)}startTransaction(){this._transaction.start();let e=this._pageState.clone();return this._transaction.addRollbackCallback(()=>{this._pageState=e}),this._transaction}hasEmptySpace(e){return this._pageState.currentPage.getHeight()+(e||1e-4)<=this._pageState.pageHeight}isOverFlow(){return this._pageState.currentPage.getHeight()>this._pageState.pageHeight}appendChild(e,t){let n=e.clone(t);DEV:L(n);return this._pageState.currentElement.appendChild(n),this._pageState.activeElement=n,n}addTextNode(e){if(this._pageState.activeElement?.type===P.Text)return this._pageState.activeElement;let t=I(document.createTextNode(e),this._transaction,this._config);return this._pageState.currentElement.appendChild(t),this._pageState.activeElement=t,t}getPageState(){return this._pageState}},V={None:0,FullNodePlaced:1,SplitChildren:2};function me(e,t){let n=H(e,t);if(n!==V.None)return n;let{rollback:r,commit:i}=t.startTransaction();t.nextPage();let a=H(e,t);return a===V.None?(r(),e.config.keepOnSamePage===`prefer`?U(e,t):V.None):(i(),a)}function H(e,t){if(t.hasEmptySpace(e.getHeight())){let n=t.appendChild(e,!0);if(t.isOverFlow())n.remove();else return V.FullNodePlaced}return e.config.keepOnSamePage===!1?U(e,t):V.None}function U(e,t){if(e.getChildrenCount()===0)return V.None;let n=t.appendChild(e,!1);return t.isOverFlow()?(n.remove(),V.None):V.SplitChildren}function he(e,t){let n=V.FullNodePlaced,r=e.textContent.split(/(\s+)/).filter(e=>e!==``),i,a=0;for(;i||a<r.length;){let o=ge(i??r[a],t,e.config);o.completed||(n=V.None),o.pendingToken?i=o.pendingToken:(i=void 0,a++)}return n}function ge(e,t,n){let r=t.addTextNode(``),i=r.textContent;if(r.textContent+=e,!t.isOverFlow())return{completed:!0};r.textContent=i;let a=_e(e,t,n);return{pendingToken:a.leftovers,completed:a.completed}}function _e(e,t,n){let{rollback:r,commit:i}=t.startTransaction();if(t.nextPage(),t.addTextNode(e),!t.isOverFlow())return i(),{completed:!0};if(r(),n.hyphenationDisabled)return x.warn(`Hyphenation disabled, skipping oversized token:`,e),{completed:!1};t.hasEmptySpace()||t.nextPage();let a=ve(e,n.hyphen,t);return{completed:!0,leftovers:a&&a.length>0?a:void 0}}function ve(e,t,n){let r=n.addTextNode(``),i=``;for(let a=0;a<e.length;a++){let o=e[a],s=i+o;if(r.textContent=s+t,!n.hasEmptySpace())return r.textContent=i?i+t:``,n.nextPage(),e.slice(a);i=s}return null}function ye(e,t){return`${e}-${t+1}`}function W(e,t){return t===`landscape`?{height:e.width,width:e.height}:e}function G(e){if(!e)return`undefined`;let t=e.getNode();if(!(t instanceof Element))return String(t).slice(0,100);let n=t.id?`#${t.id}`:``,r=t.classList.length?`.${Array.from(t.classList).join(`.`)}`:``;return`<${t.tagName.toLowerCase()}${n}${r}>`}var K=`\x1B[103mPAGINATOR\x1B[0m`,q=class e{_domState;_pageManager;_transaction;_tempContainer;_config;constructor(t,n,r){this._config={...oe,...r},this._tempContainer=e.createTempContainer(this._config.id),this._transaction=new fe,this._domState=new de(t,this._transaction,this._config),this._pageManager=new pe(this._tempContainer,n,this._transaction,this._config)}static createTempContainer(e){let t=document.createElement(`div`);return t.style.display=`flex`,t.style.flexDirection=`column`,t.style.gap=`20px`,t.setAttribute(`${b}-section-id`,e),t.classList.add(d),S()||T(t),document.body.appendChild(t),t}static paginate(t,n,r){let i=new e(t,n,r);i.processAllNodes();let a=Array.from(i._tempContainer.childNodes).filter(e=>C(e)).map(e=>e.innerHTML);return S()?Array.from(i._tempContainer.childNodes).forEach(e=>{let t=e;t.style.height=`${n.height}px`,t.style.width=`${n.width}px`}):i._tempContainer.remove(),a}processAllNodes(){N(this._config.plugins,`beforePagination`,this._config.id,this._domState,this._pageManager),this._domState.goToNextNode();do{x.debug(K,`paginating node`,this._domState.currentNode);let e=this.processCurrentNode();switch(N(this._config.plugins,`afterVisitNode`,this._config.id,e,this._domState,this._pageManager),e){case V.None:this.handleNodeSkipped();break;case V.FullNodePlaced:this.handleFullNodePlaced();break;case V.SplitChildren:this.handleChildrenSplit();break}}while(this._domState.completed===!1);N(this._config.plugins,`afterPagination`,this._config.id,this._domState,this._pageManager),x.debug(K,`pagination completed`)}handleNodeSkipped(){x.error(`Node is too big to fit on a page. Skipping node:`,G(this._domState.currentNode),this._domState.currentNode);DEV:le(this._domState.currentNode);this._domState.goToNextSiblingOrParentSibling()}handleFullNodePlaced(){x.debug(K,`node fully paginated`);let{parentsTraversed:e}=this._domState.goToNextSiblingOrParentSibling();for(let t=0;t<e;t++)this._pageManager.leaveElement()}handleChildrenSplit(){x.debug(K,`node partially paginated - splitting children`),this._domState.goToFirstChildOrNextNode().parentsTraversed===1&&this._domState.previousNode?.type===P.Element&&this._pageManager.enterElement()}processCurrentNode(){if(!this._domState.currentNode)return V.None;if(this._domState.currentNode.type===P.Element){let e={};return N(this._config.plugins,`onVisitElement`,this._config.id,this._domState,this._pageManager,e),e.result===void 0?me(this._domState.currentNode,this._pageManager):e.result}else{let e={};return N(this._config.plugins,`onVisitText`,this._config.id,this._domState,this._pageManager,e),e.result===void 0?he(this._domState.currentNode,this._pageManager):e.result}}},J=class{registry=new Map;addEventListener(e,t){let{registry:n}=this,r=new Set(n.get(e));return r.add(t),n.set(e,r),()=>this.removeEventListener(e,t)}removeEventListener(e,t){let{registry:n}=this,r=new Set(n.get(e));r.delete(t),n.set(e,r)}async dispatch(e,...t){let{registry:n}=this,r=n.get(e);if(r)for(let e of r)await e(...t)}},be={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`}},xe={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`}},Se=`__PAPRIZE_IS_INITIALIZED`,Y=`__PAPRIZE_IS_READY`,Ce=`__PAPRIZE_READ_JSON_DATA_FILE`;function we(e){let t=e.getBoundingClientRect(),n=getComputedStyle(e),r=parseFloat(n.marginLeft)||0,i=parseFloat(n.marginRight)||0;return{height:w(e),width:t.width+r+i}}function Te(e,t,n){let{height:r,width:i}=we(e);return{height:r,width:i,sectionHeaderHeight:t?w(t):0,sectionFooterHeight:n?w(n):0}}function Ee(e,t,n){return{name:`sectionPageHeight`,order:1,afterPagination:(e,t,r)=>{n<=0||r.hasEmptySpace(n)||r.nextPage()},onNewPage:(r,i)=>{let a=i.getPageState();a.pageIndex===0?a.pageHeight=e+n:a.pageHeight=e+t+n}}}function De(e){return e?`${e.top} ${e.right} ${e.bottom} ${e.left}`:`0`}function Oe(e){let t=null;return()=>(t||=e(),t)}async function ke(){if(!(`__PAPRIZE_READ_JSON_DATA_FILE`in window))return null;let e=await window[Ce]?.();return e?JSON.parse(e):null}var Ae=`
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`paprize-core`]={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,s=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),c=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e},l=(e,r,i)=>(i=e==null?{}:t(a(e)),c(r||!e||!e.__esModule?n(i,`default`,{value:e,enumerable:!0}):i,e)),u=`paprize`,d=`pz-temp-container`,f=`pz-current-element`,p=`pz-current-text`,m=`pz-ignored-element`,h=`pz-ignored-text`,g=`paprize-global-style`,_=`pz-page`,v=`pz-section`,y=`pz-preview`,b=`data-pz-`,x=l(s(((e,t)=>{(function(e,n){"use strict";typeof define==`function`&&define.amd?define(n):typeof t==`object`&&t.exports?t.exports=n():e.log=n()})(e,function(){"use strict";var e=function(){},t=`undefined`,n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),r=[`trace`,`debug`,`info`,`warn`,`error`],i={},a=null;function o(e,t){var n=e[t];if(typeof n.bind==`function`)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch{return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function s(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function c(r){return r===`debug`&&(r=`log`),typeof console===t?!1:r===`trace`&&n?s:console[r]===void 0?console.log===void 0?e:o(console,`log`):o(console,r)}function l(){for(var n=this.getLevel(),i=0;i<r.length;i++){var a=r[i];this[a]=i<n?e:this.methodFactory(a,n,this.name)}if(this.log=this.debug,typeof console===t&&n<this.levels.SILENT)return`No console available for logging`}function u(e){return function(){typeof console!==t&&(l.call(this),this[e].apply(this,arguments))}}function d(e,t,n){return c(e)||u.apply(this,arguments)}function f(e,n){var o=this,s,c,u,f=`loglevel`;typeof e==`string`?f+=`:`+e:typeof e==`symbol`&&(f=void 0);function p(e){var n=(r[e]||`silent`).toUpperCase();if(!(typeof window===t||!f)){try{window.localStorage[f]=n;return}catch{}try{window.document.cookie=encodeURIComponent(f)+`=`+n+`;`}catch{}}}function m(){var e;if(!(typeof window===t||!f)){try{e=window.localStorage[f]}catch{}if(typeof e===t)try{var n=window.document.cookie,r=encodeURIComponent(f),i=n.indexOf(r+`=`);i!==-1&&(e=/^([^;]+)/.exec(n.slice(i+r.length+1))[1])}catch{}return o.levels[e]===void 0&&(e=void 0),e}}function h(){if(!(typeof window===t||!f)){try{window.localStorage.removeItem(f)}catch{}try{window.document.cookie=encodeURIComponent(f)+`=; expires=Thu, 01 Jan 1970 00:00:00 UTC`}catch{}}}function g(e){var t=e;if(typeof t==`string`&&o.levels[t.toUpperCase()]!==void 0&&(t=o.levels[t.toUpperCase()]),typeof t==`number`&&t>=0&&t<=o.levels.SILENT)return t;throw TypeError(`log.setLevel() called with invalid level: `+e)}o.name=e,o.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},o.methodFactory=n||d,o.getLevel=function(){return u??c??s},o.setLevel=function(e,t){return u=g(e),t!==!1&&p(u),l.call(o)},o.setDefaultLevel=function(e){c=g(e),m()||o.setLevel(e,!1)},o.resetLevel=function(){u=null,h(),l.call(o)},o.enableAll=function(e){o.setLevel(o.levels.TRACE,e)},o.disableAll=function(e){o.setLevel(o.levels.SILENT,e)},o.rebuild=function(){if(a!==o&&(s=g(a.getLevel())),l.call(o),a===o)for(var e in i)i[e].rebuild()},s=g(a?a.getLevel():`WARN`);var _=m();_!=null&&(u=g(_)),l.call(o)}a=new f,a.getLogger=function(e){if(typeof e!=`symbol`&&typeof e!=`string`||e===``)throw TypeError(`You must supply a name when creating a logger.`);var t=i[e];return t||=i[e]=new f(e,a.methodFactory),t};var p=typeof window===t?void 0:window.log;return a.noConflict=function(){return typeof window!==t&&window.log===a&&(window.log=p),a},a.getLoggers=function(){return i},a.default=a,a})}))(),1).default.getLogger(u);x.setDefaultLevel(`info`);var ee=!1,te=()=>{x.setLevel(`debug`),ee=!0},S=()=>ee;function C(e){return e.nodeType===Node.ELEMENT_NODE}function ne(e){return e.nodeType===Node.TEXT_NODE}function w(e){let t=e.getBoundingClientRect(),n=getComputedStyle(e),r=parseFloat(n.marginTop)||0,i=parseFloat(n.marginBottom)||0;return t.height+r+i}function T(e){e.style.visibility=`hidden`,e.style.position=`absolute`,e.style.left=`-9999px`,e.style.top=`-9999px`}var E={hyphen:`-`,keepOnSamePage:!1,hyphenationDisabled:!1},D=`${b}hyphen`,O=`${b}keep-on-same-page`,k=`${b}hyphenation-disabled`,A={hyphen:{key:D,reader:e=>String(e)},keepOnSamePage:{key:O,reader:e=>{switch(e){case`true`:return!0;case`false`:return!1;case`prefer`:return`prefer`;default:return E.keepOnSamePage}}},hyphenationDisabled:{key:k,reader:e=>e===`true`}};function re(e){let t={};for(let[n,r]of Object.entries(e)){let e=A[n];e!==void 0&&r!==void 0&&(t[e.key]=String(r))}return t}var ie=new WeakMap;function ae(e,t,n,r){n!=null&&(r[e]=t(n))}function j(e){if(!e)return{};if(!(e instanceof Element))return j(e?.parentNode);let t={};for(let n of Object.keys(E)){let r=n,i=A[r],a=e.getAttribute(i.key);ae(r,i.reader,a,t)}let n={...e.parentNode?ie.get(e.parentNode):void 0,...t};return ie.set(e,n),n}var oe={id:`default`,plugins:[],...E};function se(e,t){let n=j(e);return{...oe,...t,...n}}var M=`\x1B[46mPLUGIN\x1B[0m`;function N(e,t,...n){e.sort((e,t)=>e.order-t.order).forEach(e=>{let r=e[t];if(r){x.debug(M,`executing plugin ${e.name}:${String(t)} ()`,n);try{r(...n),x.debug(M,`plugin ${e.name}:${String(t)} executed`,n)}catch(n){x.debug(M,`plugin ${e.name}:${String(t)} failed`,n)}}})}var P={Element:`element`,Text:`text`},F=class e{_node;config;type=P.Element;transaction;clonedData;constructor(e,t,n,r){this._node=e,this.transaction=t,this.config=n,this.clonedData=r?{clonedFrom:r,cloneCount:r.clonedData.cloneCount+1}:{clonedFrom:void 0,cloneCount:0}}getOriginalNode(){let e=this.clonedData.clonedFrom;for(;e?.clonedData.clonedFrom;)e=e.clonedData.clonedFrom;return e?._node??this._node}appendChild(e){this.transaction.isActive&&this.transaction.addRollbackCallback(()=>{this._node.removeChild(e.getNode())}),this._node.appendChild(e.getNode())}clone(t){let n=this._node.cloneNode(t),r=new e(n,this.transaction,this.config,this);return N(this.config.plugins,`onClone`,this.config.id,this._node,r),r}getHeight(){return w(this._node)}remove(){this.transaction.addCommitCallback(()=>{this._node.remove()})}isEmpty(){return this._node.innerHTML===``}getChildrenCount(){return this._node.childNodes.length}getNode(){return this._node}},ce=class{_node;type=P.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 I(e,t,n){if(ne(e))return new ce(e,t,n);if(C(e))return new F(e,t,n);throw Error(`Unsupported node type`)}function le(e){S()&&(e&&e.type==P.Element?e.getNode().classList.add(m):e&&e.type==P.Text&&e.getNode().parentElement?.classList.add(h))}function ue(e){S()&&(e&&e.type==P.Element?e.getNode().classList.add(f):e&&e.type==P.Text&&e.getNode().parentElement?.classList.add(p))}function L(e){S()&&(e&&e.type==P.Element?e.getNode().classList.remove(f):e&&e.type==P.Text&&e.getNode().parentElement?.classList.remove(p))}var R=`\x1B[106mDOM\x1B[0m`,de=class{_transaction;_treeWalker;_config;_completed=!1;_currentNode=null;_previousNode=null;constructor(e,t,n){this._transaction=t,this._config=n,this._treeWalker=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT)}get completed(){return this._completed}get currentNode(){return this._currentNode}get previousNode(){return this._previousNode}goToNextNode(){this._treeWalker.nextNode()||(this._completed=!0),x.debug(R,`moving to next node`),this.setState()}goToNextSiblingOrParentSibling(){let e=0;if(this._treeWalker.nextSibling())return x.debug(R,`moving to next sibling node`),this.setState(),{parentsTraversed:e};for(;this._treeWalker.parentNode();)if(e++,this._treeWalker.nextSibling())return x.debug(R,`moving to parent sibling node, traversed:`,e),this.setState(),{parentsTraversed:e};return this._completed=!0,{parentsTraversed:e}}goToFirstChildOrNextNode(){return this._treeWalker.firstChild()?(x.debug(R,`moving to first child node`),this.setState(),{parentsTraversed:1}):(this.goToNextNode(),{parentsTraversed:0})}setState(){this._previousNode=this._currentNode,this._currentNode=I(this._treeWalker.currentNode,this._transaction,se(this._treeWalker.currentNode,this._config));DEV:ue(this._currentNode);DEV:L(this._previousNode);x.debug(R,`moved to node`,{currentNode:this._currentNode,previousNode:this._previousNode})}},fe=class{_onRollback;_onCommit;isActive;constructor(){this._onRollback=[],this._onCommit=[],this.isActive=!1}start=()=>{if(this.isActive)throw Error(`Transaction already in progress`);this.isActive=!0,this._onRollback=[],this._onCommit=[]};addRollbackCallback=e=>{this._onRollback.push(e)};addCommitCallback=e=>{if(!this.isActive){e();return}this._onCommit.push(e)};rollback=()=>{this.isActive&&(this.isActive=!1,this._onRollback.forEach(e=>e()))};commit=()=>{this.isActive&&(this.isActive=!1,this._onCommit.forEach(e=>e()))}},z=`\x1B[102mPAGE\x1B[0m`,B=class e{currentPage;activeElement;currentElement;parentStack;pageIndex;pageHeight;constructor(e,t,n,r,i,a){this.currentPage=e,this.activeElement=t,this.currentElement=n,this.parentStack=r,this.pageIndex=i,this.pageHeight=a}static create(t,n,r,i){return new e(t,null,t,n,r,i)}clone=()=>new e(this.currentPage,this.activeElement,this.currentElement,[...this.parentStack],this.pageIndex,this.pageHeight)},pe=class e{_pageState;_transaction;_tempContainer;_config;constructor(t,n,r,i){this._tempContainer=t,this._config=i,this._transaction=r;let a=e.createPageHtmlElement(n.width),o=this.createNewPage(a);this._pageState=B.create(o,[],0,n.height),N(this._config.plugins,`onNewPage`,i.id,this)}nextPage(){let e=this.createNewPage(this._pageState.currentPage.getNode().cloneNode(!1)),t=B.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(let t of this._pageState.parentStack){let n=t.clone(!1);e.currentElement.appendChild(n),e.currentElement=n,e.parentStack.push(n)}}cleanupEmptyParent(){let e=[...this._pageState.parentStack];this._transaction.addCommitCallback(()=>{for(let t=e.length-1;t>=0;t--){let n=e[t];n.isEmpty()&&n.remove()}})}enterElement(){if(!this._pageState.activeElement||this._pageState.activeElement.type!==P.Element)throw Error(`Invalid state: activeElement is not an Element`);x.debug(z,`entering an element`,this._pageState.activeElement),this._pageState.currentElement=this._pageState.activeElement,this._pageState.parentStack.push(this._pageState.activeElement)}leaveElement(){this._pageState.activeElement=null;let e=this._pageState.parentStack.pop();x.debug(z,`leaving a parent element`,e);let t=this._pageState.parentStack.at(-1);this._pageState.currentElement=t??this._pageState.currentPage}static createPageHtmlElement(e){let t=document.createElement(`div`);return t.style.width=`${e}px`,t.style.maxWidth=`${e}px`,t.className=_,t}createNewPage(e){return x.debug(z,`creating new page`),this._tempContainer.appendChild(e),this._transaction.isActive&&this._transaction.addRollbackCallback(()=>{this._tempContainer.removeChild(e)}),I(e,this._transaction,this._config)}startTransaction(){this._transaction.start();let e=this._pageState.clone();return this._transaction.addRollbackCallback(()=>{this._pageState=e}),this._transaction}hasEmptySpace(e){return this._pageState.currentPage.getHeight()+(e||1e-4)<=this._pageState.pageHeight}isOverFlow(){return this._pageState.currentPage.getHeight()>this._pageState.pageHeight}appendChild(e,t){let n=e.clone(t);DEV:L(n);return this._pageState.currentElement.appendChild(n),this._pageState.activeElement=n,n}addTextNode(e){if(this._pageState.activeElement?.type===P.Text)return this._pageState.activeElement;let t=I(document.createTextNode(e),this._transaction,this._config);return this._pageState.currentElement.appendChild(t),this._pageState.activeElement=t,t}getPageState(){return this._pageState}},V={None:0,FullNodePlaced:1,SplitChildren:2};function me(e,t){let n=H(e,t);if(n!==V.None)return n;let{rollback:r,commit:i}=t.startTransaction();t.nextPage();let a=H(e,t);return a===V.None?(r(),e.config.keepOnSamePage===`prefer`?U(e,t):V.None):(i(),a)}function H(e,t){if(t.hasEmptySpace(e.getHeight())){let n=t.appendChild(e,!0);if(t.isOverFlow())n.remove();else return V.FullNodePlaced}return e.config.keepOnSamePage===!1?U(e,t):V.None}function U(e,t){if(e.getChildrenCount()===0)return V.None;let n=t.appendChild(e,!1);return t.isOverFlow()?(n.remove(),V.None):V.SplitChildren}function he(e,t){let n=V.FullNodePlaced,r=e.textContent.split(/(\s+)/).filter(e=>e!==``),i,a=0;for(;i||a<r.length;){let o=ge(i??r[a],t,e.config);o.completed||(n=V.None),o.pendingToken?i=o.pendingToken:(i=void 0,a++)}return n}function ge(e,t,n){let r=t.addTextNode(``),i=r.textContent;if(r.textContent+=e,!t.isOverFlow())return{completed:!0};r.textContent=i;let a=_e(e,t,n);return{pendingToken:a.leftovers,completed:a.completed}}function _e(e,t,n){let{rollback:r,commit:i}=t.startTransaction();if(t.nextPage(),t.addTextNode(e),!t.isOverFlow())return i(),{completed:!0};if(r(),n.hyphenationDisabled)return x.warn(`Hyphenation disabled, skipping oversized token:`,e),{completed:!1};t.hasEmptySpace()||t.nextPage();let a=ve(e,n.hyphen,t);return{completed:!0,leftovers:a&&a.length>0?a:void 0}}function ve(e,t,n){let r=n.addTextNode(``),i=``;for(let a=0;a<e.length;a++){let o=e[a],s=i+o;if(r.textContent=s+t,!n.hasEmptySpace())return r.textContent=i?i+t:``,n.nextPage(),e.slice(a);i=s}return null}function ye(e,t){return`${e}-${t+1}`}function W(e,t){return t===`landscape`?{height:e.width,width:e.height}:e}function G(e){if(!e)return`undefined`;let t=e.getNode();if(!(t instanceof Element))return String(t).slice(0,100);let n=t.id?`#${t.id}`:``,r=t.classList.length?`.${Array.from(t.classList).join(`.`)}`:``;return`<${t.tagName.toLowerCase()}${n}${r}>`}var K=`\x1B[103mPAGINATOR\x1B[0m`,q=class e{_domState;_pageManager;_transaction;_tempContainer;_config;constructor(t,n,r){this._config={...oe,...r},this._tempContainer=e.createTempContainer(this._config.id),this._transaction=new fe,this._domState=new de(t,this._transaction,this._config),this._pageManager=new pe(this._tempContainer,n,this._transaction,this._config)}static createTempContainer(e){let t=document.createElement(`div`);return t.style.display=`flex`,t.style.flexDirection=`column`,t.style.gap=`20px`,t.setAttribute(`${b}-section-id`,e),t.classList.add(d),S()||T(t),document.body.appendChild(t),t}static paginate(t,n,r){let i=new e(t,n,r);i.processAllNodes();let a=Array.from(i._tempContainer.childNodes).filter(e=>C(e)).map(e=>e.innerHTML);return S()?Array.from(i._tempContainer.childNodes).forEach(e=>{let t=e;t.style.height=`${n.height}px`,t.style.width=`${n.width}px`}):i._tempContainer.remove(),a}processAllNodes(){N(this._config.plugins,`beforePagination`,this._config.id,this._domState,this._pageManager),this._domState.goToNextNode();do{x.debug(K,`paginating node`,this._domState.currentNode);let e=this.processCurrentNode();switch(N(this._config.plugins,`afterVisitNode`,this._config.id,e,this._domState,this._pageManager),e){case V.None:this.handleNodeSkipped();break;case V.FullNodePlaced:this.handleFullNodePlaced();break;case V.SplitChildren:this.handleChildrenSplit();break}}while(this._domState.completed===!1);N(this._config.plugins,`afterPagination`,this._config.id,this._domState,this._pageManager),x.debug(K,`pagination completed`)}handleNodeSkipped(){x.error(`Node is too big to fit on a page. Skipping node:`,G(this._domState.currentNode),this._domState.currentNode);DEV:le(this._domState.currentNode);this._domState.goToNextSiblingOrParentSibling()}handleFullNodePlaced(){x.debug(K,`node fully paginated`);let{parentsTraversed:e}=this._domState.goToNextSiblingOrParentSibling();for(let t=0;t<e;t++)this._pageManager.leaveElement()}handleChildrenSplit(){x.debug(K,`node partially paginated - splitting children`),this._domState.goToFirstChildOrNextNode().parentsTraversed===1&&this._domState.previousNode?.type===P.Element&&this._pageManager.enterElement()}processCurrentNode(){if(!this._domState.currentNode)return V.None;if(this._domState.currentNode.type===P.Element){let e={};return N(this._config.plugins,`onVisitElement`,this._config.id,this._domState,this._pageManager,e),e.result===void 0?me(this._domState.currentNode,this._pageManager):e.result}else{let e={};return N(this._config.plugins,`onVisitText`,this._config.id,this._domState,this._pageManager,e),e.result===void 0?he(this._domState.currentNode,this._pageManager):e.result}}},J=class{registry=new Map;addEventListener(e,t){let{registry:n}=this,r=new Set(n.get(e));return r.add(t),n.set(e,r),()=>this.removeEventListener(e,t)}removeEventListener(e,t){let{registry:n}=this,r=new Set(n.get(e));r.delete(t),n.set(e,r)}async dispatch(e,...t){let{registry:n}=this,r=n.get(e);if(r)for(let e of r)await e(...t)}},be={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`}},xe={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`}},Se=`__PAPRIZE_IS_INITIALIZED`,Y=`__PAPRIZE_IS_READY`,Ce=`__PAPRIZE_READ_JSON_DATA_FILE`;function we(e){let t=e.getBoundingClientRect(),n=getComputedStyle(e),r=parseFloat(n.marginLeft)||0,i=parseFloat(n.marginRight)||0;return{height:w(e),width:t.width+r+i}}function Te(e,t,n){let{height:r,width:i}=we(e);return{height:r,width:i,sectionHeaderHeight:t?w(t):0,sectionFooterHeight:n?w(n):0}}function Ee(e,t,n){return{name:`sectionPageHeight`,order:1,afterPagination:(e,t,r)=>{n<=0||r.hasEmptySpace(n)||r.nextPage()},onNewPage:(r,i)=>{let a=i.getPageState();a.pageIndex===0?a.pageHeight=e+n:a.pageHeight=e+t+n}}}function De(e){return e?`${e.top} ${e.right} ${e.bottom} ${e.left}`:`0`}function Oe(e){let t=null;return()=>(t||=e(),t)}async function ke(){if(!(`__PAPRIZE_READ_JSON_DATA_FILE`in window))return null;let e=await window[Ce]?.();return e?JSON.parse(e):null}var Ae=`
|
|
2
2
|
html {
|
|
3
3
|
box-sizing: border-box;
|
|
4
4
|
}
|