diff --git a/layouts/print/single.html b/layouts/print/single.html index 74c9e45..c979ea2 100644 --- a/layouts/print/single.html +++ b/layouts/print/single.html @@ -1,31 +1,119 @@ {{- define "print" -}} {{- $currentPage := . -}} - {{- range $source := $currentPage.Params.print[0].render.static -}} - {{- with site.GetPage (printf "%s" $source) -}} - {{- $sourcePage := . -}} - {{- partial "single-page-graph.html" . -}} - {{- partial "page-header.html" . -}} -
-
{{ $sourcePage.Section }}⁄{{ $sourcePage.Title }}
- -
{{ $sourcePage.Content }}
-
- {{- range $param := $currentPage.Params.print.iterate -}} - {{- printf "Iterate params: %#v" . -}} - {{- with index $sourcePage.Params $param -}} - {{- printf "Iteration: %#v" . -}} + {{- $populateDict := dict -}} + {{- $renderPaths := slice -}} + {{- range $printItem := .Params.print -}} + {{- with $printItem.render.static -}} + {{- $renderPaths = $renderPaths|append . -}} + {{- with site.GetPage . -}} + {{- $staticPage := . -}} + {{- range $printer := $printItem.populate -}} + {{- $section := "" -}} + {{- range $populateVar, $sectionGraph := $printer -}} + {{- if not $sectionGraph -}} + {{- continue -}} + {{- end -}} + {{- if ne $populateVar "exclude" -}} + {{- if hasPrefix $sectionGraph "_" -}} + {{- $section = partial "GetSingularSectionName.html" (strings.TrimPrefix "_" $sectionGraph) -}} + {{- else if strings.Contains $sectionGraph "_" -}} + {{- $section = partial "GetSingularSectionName.html" (index (last 1 (split $sectionGraph "_")) 0) -}} + {{- end -}} + {{- with (index $staticPage.Params $sectionGraph) -}} + {{- range $page := index $staticPage.Params $sectionGraph -}} + {{- $pages := index $populateDict $populateVar| default slice -}} + {{- $pages = $pages|append (printf "/%s/%s" $section $page) -}} + {{- $populateDict = merge $populateDict (dict $populateVar $pages) -}} + {{- end -}} + {{- end -}} + {{- else -}} + {{- $populateDict = merge $populateDict (dict $populateVar (index $staticPage.Params $sectionGraph)) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- with $printItem.render.loop -}} + {{- $loopItem := . -}} + {{- with (index $populateDict $loopItem) -}} + {{- if not (reflect.IsSlice .) -}} + {{- continue -}} + {{- end -}} + {{- range $pagePath := index $populateDict $loopItem -}} + {{- with site.GetPage . -}} + {{- $staticPage := . -}} + {{- range $printer := $printItem.populate -}} + {{- $section := "" -}} + {{- range $populateVar, $sectionGraph := $printer -}} + {{- if not $sectionGraph -}} + {{- continue -}} + {{- end -}} + {{- if ne $populateVar "exclude" -}} + {{- if hasPrefix $sectionGraph "_" -}} + {{- $section = partial "GetSingularSectionName.html" (strings.TrimPrefix "_" $sectionGraph) -}} + {{- else if strings.Contains $sectionGraph "_" -}} + {{- $section = partial "GetSingularSectionName.html" (index (last 1 (split $sectionGraph "_")) 0) -}} + {{- end -}} + {{- with (index $staticPage.Params $sectionGraph) -}} + {{- range $page := index $staticPage.Params $sectionGraph -}} + {{- $pages := index $populateDict $populateVar| default slice -}} + {{- $pages = $pages|append (printf "/%s/%s" $section $page) -}} + {{- $populateDict = merge $populateDict (dict $populateVar $pages) -}} + {{- end -}} + {{- end -}} + {{- else -}} + {{- $populateDict = merge $populateDict (dict $populateVar (index $staticPage.Params $sectionGraph)) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- with $printItem.render.loopIn -}} + {{- range $printer := $printItem.populate -}} + {{- $section := "" -}} + {{- range $populateVar, $sectionGraph := $printer -}} + {{- $populateDict = merge $populateDict (dict $populateVar $sectionGraph) -}} + {{- end -}} + {{- end -}} + {{- $loopParts := split . "." -}} + {{- $loopIn := index $loopParts 0 -}} + {{- $loopOut := index $loopParts 1 -}} + {{- range $i, $page := (index $populateDict $loopIn) -}} + {{- $loopInKey := (printf "%s_%d" $loopIn $i) -}} + {{- $pages := index $populateDict $loopInKey| default slice -}} + {{- with site.GetPage $page -}} + {{- $pages = $pages|append $page -}} + {{- end -}} + {{- $populateDict = merge $populateDict (dict $loopInKey $pages) -}} + {{- end -}} + {{- end -}} + {{- with $printItem.render.loopOut -}} + {{- $loopParts := split . "." -}} + {{- $loopIn := index $loopParts 1 -}} + {{- $loopOut := index $loopParts 0 -}} + {{- range $outI, $outPage := (index $populateDict $loopIn) -}} + {{- with $page := site.GetPage $outPage -}} + {{- $sectionGraph := index $populateDict $loopOut -}} + {{- range $inI, $inPage := (index $page.Params $sectionGraph) -}} + {{- $section := "" -}} + {{- if hasPrefix $sectionGraph "_" -}} + {{- $section = partial "GetSingularSectionName.html" (strings.TrimPrefix "_" $sectionGraph) -}} + {{- else if strings.Contains $sectionGraph "_" -}} + {{- $section = partial "GetSingularSectionName.html" (index (last 1 (split $sectionGraph "_")) 0) -}} + {{- end -}} + {{- $key := (printf "%s_%d" $loopIn $outI) -}} + {{- $pages := index $populateDict $key | default slice -}} + {{/*- with site.GetPage $inPage -*/}} + {{- $pages = $pages|append (printf "/%s/%s" $section $inPage) -}} + {{/*- end -*/}} + {{- $populateDict = merge $populateDict (dict $key $pages) -}} + {{- end -}} {{- end -}} {{- end -}} {{- end -}} {{- end -}} +

{{- printf "Populate dict: %s" $populateDict -}}

+

{{- printf "Render paths: %s" $renderPaths -}}

{{- end -}} diff --git a/static/js/paged.min.js b/static/js/paged.min.js new file mode 100644 index 0000000..4b000d3 --- /dev/null +++ b/static/js/paged.min.js @@ -0,0 +1,7 @@ +UNPKG

UNPKG

pagedjs

Version:

Chunks up a document into paged media flows and applies print styles

4 lines 503 kB
/** + * @license Paged.js v0.4.3 | MIT | https://gitlab.coko.foundation/pagedjs/pagedjs + */ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).PagedModule={})}(this,(function(e){"use strict";function t(e){if(!e)return;let t;if(void 0!==e.getBoundingClientRect)t=e.getBoundingClientRect();else{let n=document.createRange();n.selectNode(e),t=n.getBoundingClientRect()}return t}function n(e){if(!e)return;let t;if(void 0!==e.getClientRects)t=e.getClientRects();else{let n=document.createRange();n.selectNode(e),t=n.getClientRects()}return t}function r(){var e=(new Date).getTime();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)}))}function a(e,t){for(var n=0;n<t.length;n++)if(e.hasAttribute(t[n]))return e.getAttribute(t[n])}function i(e){if(0==arguments.length)throw new TypeError("`CSS.escape` requires an argument.");for(var t,n=String(e),r=n.length,a=-1,i="",o=n.charCodeAt(0);++a<r;)0!=(t=n.charCodeAt(a))?t>=1&&t<=31||127==t||0==a&&t>=48&&t<=57||1==a&&t>=48&&t<=57&&45==o?i+="\\"+t.toString(16)+" ":0!=a||1!=r||45!=t?46!=t||"#"!=n.charAt(0)?i+=t>=128||45==t||95==t||35==t||46==t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(a):"\\"+n.charAt(a):i+="\\.":i+="\\"+n.charAt(a):i+="�";return i}function o(){this.resolve=null,this.reject=null,this.id=r(),this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t})),Object.freeze(this)}const s="undefined"!=typeof window&&("requestIdleCallback"in window?window.requestIdleCallback:window.requestAnimationFrame);function l(e){return e.value+(e.unit||"")}function d(e){return e&&1===e.nodeType}function p(e){return e&&3===e.nodeType}function*c(e,t){let n=e;for(;n;)if(yield n,n.childNodes.length)n=n.firstChild;else if(n.nextSibling){if(t&&n===t){n=void 0;break}n=n.nextSibling}else for(;n;){if(n=n.parentNode,t&&n===t){n=void 0;break}if(n&&n.nextSibling){n=n.nextSibling;break}}}function u(e,t){if(t&&e===t)return;let n=B(e);if(n)return n;if(e.parentNode)for(;e=e.parentNode;){if(t&&e===t)return;if(n=B(e),n)return n}}function m(e,t){if(t&&e===t)return;let n=E(e);if(n)return n;if(e.parentNode)for(;e=e.parentNode;){if(t&&e===t)return;if(n=E(e),n)return n}}function h(e,t){let n=u(e,t);for(;n&&1!==n.nodeType;)n=u(n,t);return n}function g(e,t){let n=m(e,t);for(;n&&1!==n.nodeType;)n=m(n,t);return n}function f(e,t){let n=h(e,t);for(;n&&n.dataset.undisplayed;)n=h(n,t);return n}function y(e,t){let n=g(e,t);for(;n&&n.dataset.undisplayed;)n=g(n,t);return n}function b(e){let t,n,r=[],a=[],i=document.createDocumentFragment();if("TR"===e.nodeName){let t=e.previousElementSibling,n=1;for(;t;){if(t.childElementCount>e.childElementCount){const r=Array.from(e.children);for(;e.firstChild;)e.firstChild.remove();let a=0;for(let i=0;i<t.children.length;i++){let o=t.children[i];if(o.rowSpan&&o.rowSpan>n){const t=o.cloneNode(!0);t.rowSpan=o.rowSpan-n,e.appendChild(t)}else{const t=r[a++];t&&e.appendChild(t)}}}t=t.previousElementSibling,n++}}let o=e;for(;o.parentNode&&1===o.parentNode.nodeType;)r.unshift(o.parentNode),o=o.parentNode;for(var s=0;s<r.length;s++){if(n=r[s],t=n.cloneNode(!1),t.setAttribute("data-split-from",t.getAttribute("data-ref")),t.hasAttribute("id")){let e=t.getAttribute("id");t.setAttribute("data-id",e),t.removeAttribute("id")}if(t.hasAttribute("data-break-before")&&t.removeAttribute("data-break-before"),t.hasAttribute("data-previous-break-after")&&t.removeAttribute("data-previous-break-after"),a.length){a[a.length-1].appendChild(t)}else i.appendChild(t);if(a.push(t),"TD"===t.nodeName&&n.parentElement.contains(n)){let e=n,r=t;for(;e=e.previousElementSibling;){let n=e.cloneNode(!1);t.parentElement.insertBefore(n,r),r=n}}}return a=void 0,i}function S(e){return void 0!==e&&void 0!==e.dataset&&void 0!==e.dataset.breakBefore&&("always"===e.dataset.breakBefore||"page"===e.dataset.breakBefore||"left"===e.dataset.breakBefore||"right"===e.dataset.breakBefore||"recto"===e.dataset.breakBefore||"verso"===e.dataset.breakBefore)}function v(e,t){if(void 0===e||!t||A(e))return!1;if(e.dataset&&e.dataset.undisplayed)return!1;let n=t.dataset?t.dataset.page:void 0;if(void 0===n){const e=j(t);e&&(n=e.dataset.page)}let r=e.dataset?e.dataset.page:void 0;if(void 0===r){const n=j(e,t);n&&(r=n.dataset.page)}return r!==n}function*x(e){let t,n=e.startContainer,r=n.length,a=e.startOffset;for(;a<r;)t=document.createRange(),t.setStart(n,a),t.setEnd(n,a+1),yield t,a+=1}function k(e){let t;if(void 0===e.tagName)return!0;if(e.style&&"none"===e.style.display)return!1;switch(e.tagName){case"A":case"ABBR":case"ACRONYM":case"B":case"BDO":case"BIG":case"BR":case"BUTTON":case"CITE":case"CODE":case"DFN":case"EM":case"I":case"IMG":case"INPUT":case"KBD":case"LABEL":case"MAP":case"OBJECT":case"Q":case"SAMP":case"SCRIPT":case"SELECT":case"SMALL":case"SPAN":case"STRONG":case"SUB":case"SUP":case"TEXTAREA":case"TIME":case"TT":case"VAR":case"P":case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":case"FIGCAPTION":case"BLOCKQUOTE":case"PRE":case"LI":case"TD":case"DT":case"DD":case"VIDEO":case"CANVAS":t=!1;break;default:t=!0}return t}function w(e,t,n){return function(e,t,n){return!n&&t.indexOfRefs&&t.indexOfRefs[e]?t.indexOfRefs[e]:t.querySelector(`[data-ref='${e}']`)}(e.getAttribute("data-ref"),t,n)}function C(e){return!!p(e)||!(!d(e)||!e.dataset.ref)}function T(e){for(;!C(e)&&(e=e.previousSibling?e.previousSibling:e.parentNode););return e}function _(e,t){return e.childNodes[t]}function z(e){return!!d(e)||!(!p(e)||!e.textContent.trim().length)}function O(e,t){if(!p(e))return-1;let n,r=e.textContent,a=-1;for(var i=0;i<t.childNodes.length;i++)if(n=t.childNodes[i],3===n.nodeType){if(t.childNodes[i].textContent.includes(r)){a=i;break}}return a}function A(e){return 8===e.nodeType||3===e.nodeType&&function(e){return!/[^\t\n\r ]/.test(e.textContent)}(e)}function E(e){for(;e=e.previousSibling;)if(!A(e))return e;return null}function j(e,t){if(e&&e.dataset&&e.dataset.page)return e;if(e.parentNode)for(;e=e.parentNode;){if(t&&e===t)return;if(e.dataset&&e.dataset.page)return e}return null}function W(e){for(;e=e.parentNode;)if(e&&e.dataset&&"avoid"===e.dataset.breakInside)return e;return null}function L(e,t,n){if((!n||e!==n)&&e.parentNode)for(;e=e.parentNode;){if(n&&e===n)return;if(e.nodeName===t)return e}}function B(e){for(;e=e.nextSibling;)if(!A(e))return e;return null}function P(e,t,n){const r=document.createTreeWalker(e||this.dom,n||NodeFilter.SHOW_ALL,t?{acceptNode:t}:null,!1);let a,i;for(a=r.nextNode();a;)i=a,a=r.nextNode(),i.parentNode.removeChild(i)}class q{constructor(e,t){this.node=e,this.offset=t}equals(e){return!!e&&((!this.node||!e.node||this.node===e.node)&&(!this.offset||!e.offset||this.offset===e.offset))}toJSON(e){let t,n=0;if(!this.node)return{};if(d(this.node)&&this.node.dataset.ref?t=this.node.dataset.ref:e&&(t=this.node.parentElement.dataset.ref),this.node.parentElement){n=Array.from(this.node.parentElement.childNodes).indexOf(this.node)}return JSON.stringify({node:t,index:n,offset:this.offset})}}class M{constructor(e,t){this.breakToken=e,this.error=t}}class I extends Error{constructor(e,t){super(e),this.items=t}}function D(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var R,N,G={exports:{}},F={exports:{}};var V,U,H,$,Y=function(){},K=Y(),Z=function(e){return e!==K&&null!==e};function Q(){return $||($=1,H=(N?R:(N=1,R=function(){try{return Object.keys("primitive"),!0}catch(e){return!1}}))()?Object.keys:function(){if(U)return V;U=1;var e=Z,t=Object.keys;return V=function(n){return t(e(n)?Object(n):n)}}()),H}var J,X,ee=Z,te=function(e){if(!ee(e))throw new TypeError("Cannot use null or undefined");return e};var ne,re,ae=function(){var e,t=Object.assign;return"function"==typeof t&&(t(e={foo:"raz"},{bar:"dwa"},{trzy:"trzy"}),e.foo+e.bar+e.trzy==="razdwatrzy")}()?Object.assign:function(){if(X)return J;X=1;var e=Q(),t=te,n=Math.max;return J=function(r,a){var i,o,s,l=n(arguments.length,2);for(r=Object(t(r)),s=function(e){try{r[e]=a[e]}catch(e){i||(i=e)}},o=1;o<l;++o)e(a=arguments[o]).forEach(s);if(void 0!==i)throw i;return r},J}(),ie=Z,oe=Array.prototype.forEach,se=Object.create,le="razdwatrzy";var de,pe="function"==typeof le.contains&&!0===le.contains("dwa")&&!1===le.contains("foo")?String.prototype.contains:function(){if(re)return ne;re=1;var e=String.prototype.indexOf;return ne=function(t){return e.call(this,t,arguments[1])>-1},ne}(),ce=ae,ue=function(e){var t=se(null);return oe.call(arguments,(function(e){ie(e)&&function(e,t){var n;for(n in e)t[n]=e[n]}(Object(e),t)})),t},me=function(e){return"function"==typeof e},he=pe;de=F.exports=function(e,t){var n,r,a,i,o;return arguments.length<2||"string"!=typeof e?(i=t,t=e,e=null):i=arguments[2],null==e?(n=a=!0,r=!1):(n=he.call(e,"c"),r=he.call(e,"e"),a=he.call(e,"w")),o={value:t,configurable:n,enumerable:r,writable:a},i?ce(ue(i),o):o},de.gs=function(e,t,n){var r,a,i,o;return"string"!=typeof e?(i=n,n=t,t=e,e=null):i=arguments[3],null==t?t=void 0:me(t)?null==n?n=void 0:me(n)||(i=n,n=void 0):(i=t,t=n=void 0),null==e?(r=!0,a=!1):(r=he.call(e,"c"),a=he.call(e,"e")),o={get:t,set:n,configurable:r,enumerable:a},i?ce(ue(i),o):o};var ge=F.exports,fe=function(e){if("function"!=typeof e)throw new TypeError(e+" is not a function");return e};!function(e,t){var n,r,a,i,o,s,l,d=ge,p=fe,c=Function.prototype.apply,u=Function.prototype.call,m=Object.create,h=Object.defineProperty,g=Object.defineProperties,f=Object.prototype.hasOwnProperty,y={configurable:!0,enumerable:!1,writable:!0};n=function(e,t){var n;return p(t),f.call(this,"__ee__")?n=this.__ee__:(n=y.value=m(null),h(this,"__ee__",y),y.value=null),n[e]?"object"==typeof n[e]?n[e].push(t):n[e]=[n[e],t]:n[e]=t,this},r=function(e,t){var r,i;return p(t),i=this,n.call(this,e,r=function(){a.call(i,e,r),c.call(t,this,arguments)}),r.__eeOnceListener__=t,this},a=function(e,t){var n,r,a,i;if(p(t),!f.call(this,"__ee__"))return this;if(!(n=this.__ee__)[e])return this;if("object"==typeof(r=n[e]))for(i=0;a=r[i];++i)a!==t&&a.__eeOnceListener__!==t||(2===r.length?n[e]=r[i?0:1]:r.splice(i,1));else r!==t&&r.__eeOnceListener__!==t||delete n[e];return this},i=function(e){var t,n,r,a,i;if(f.call(this,"__ee__")&&(a=this.__ee__[e]))if("object"==typeof a){for(n=arguments.length,i=new Array(n-1),t=1;t<n;++t)i[t-1]=arguments[t];for(a=a.slice(),t=0;r=a[t];++t)c.call(r,this,i)}else switch(arguments.length){case 1:u.call(a,this);break;case 2:u.call(a,this,arguments[1]);break;case 3:u.call(a,this,arguments[1],arguments[2]);break;default:for(n=arguments.length,i=new Array(n-1),t=1;t<n;++t)i[t-1]=arguments[t];c.call(a,this,i)}},o={on:n,once:r,off:a,emit:i},s={on:d(n),once:d(r),off:d(a),emit:d(i)},l=g({},s),e.exports=t=function(e){return null==e?m(l):g(Object(e),s)},t.methods=o}(G,G.exports);var ye=G.exports,be=D(ye);class Se{constructor(e){this.context=e||this,this.hooks=[]}register(){for(var e=0;e<arguments.length;++e)if("function"==typeof arguments[e])this.hooks.push(arguments[e]);else for(var t=0;t<arguments[e].length;++t)this.hooks.push(arguments[e][t])}trigger(){var e=arguments,t=this.context,n=[];return this.hooks.forEach((function(r){var a=r.apply(t,e);a&&"function"==typeof a.then?n.push(a):n.push(new Promise(((e,t)=>{e(a)})))})),Promise.all(n)}triggerSync(){var e=arguments,t=this.context,n=[];return this.hooks.forEach((function(r){var a=r.apply(t,e);n.push(a)})),n}list(){return this.hooks}clear(){return this.hooks=[]}}class ve{constructor(e,t,n){this.element=e,this.bounds=this.element.getBoundingClientRect(),this.parentBounds=this.element.offsetParent.getBoundingClientRect();let r=parseFloat(window.getComputedStyle(this.element).columnGap);if(r){let e=this.bounds.left-this.parentBounds.left;this.gap=r-e}else this.gap=0;t?this.hooks=t:(this.hooks={},this.hooks.onPageLayout=new Se,this.hooks.layout=new Se,this.hooks.renderNode=new Se,this.hooks.layoutNode=new Se,this.hooks.beforeOverflow=new Se,this.hooks.onOverflow=new Se,this.hooks.afterOverflowRemoved=new Se,this.hooks.onBreakToken=new Se,this.hooks.beforeRenderResult=new Se),this.settings=n||{},this.maxChars=this.settings.maxChars||1500,this.forceRenderBreak=!1}async renderTo(e,t,n,r=this.bounds){let a,i,o,s,l,d=this.getStart(t,n),p=c(d,t),m=!1,h=0,g=n||new q(d);for(this.hooks&&this.hooks.onPageLayout.trigger(e,g,this);!o&&!l;){if(s=p.next(),i=a,a=s.value,o=s.done,!a){this.hooks&&this.hooks.layout.trigger(e,this);let n=e.querySelectorAll("img");return n.length&&await this.waitForImages(n),l=this.findBreakToken(e,t,r,g),l&&l.equals(g)?(console.warn("Unable to layout item: ",i),this.hooks&&this.hooks.beforeRenderResult.trigger(void 0,e,this),new M(void 0,new I("Unable to layout item",[i]))):(this.rebuildTableFromBreakToken(l,e),this.hooks&&this.hooks.beforeRenderResult.trigger(l,e,this),new M(l))}if(this.hooks&&this.hooks.layoutNode.trigger(a),m&&this.shouldBreak(a,d)){this.hooks&&this.hooks.layout.trigger(e,this);let n=e.querySelectorAll("img");if(n.length&&await this.waitForImages(n),l=this.findBreakToken(e,t,r,g),l?this.rebuildTableFromBreakToken(l,e):l=this.breakAt(a),l&&l.equals(g)){console.warn("Unable to layout item: ",a);let e=l.node&&u(l.node);if(!e)return new M(void 0,new I("Unable to layout item",[a]));l=new q(e)}h=0;break}if(a.dataset&&a.dataset.page){let e=a.dataset.page,t=this.element.closest(".pagedjs_page");t.classList.add("pagedjs_named_page"),t.classList.add("pagedjs_"+e+"_page"),a.dataset.splitFrom||t.classList.add("pagedjs_"+e+"_first_page")}let f=k(a);if(h+=this.append(a,e,n,f).textContent.length,m||(m=z(a)),f||(p=c(u(a,t),t)),this.forceRenderBreak){this.hooks&&this.hooks.layout.trigger(e,this),l=this.findBreakToken(e,t,r,g),l?this.rebuildTableFromBreakToken(l,e):l=this.breakAt(a),h=0,this.forceRenderBreak=!1;break}if(h>=this.maxChars){this.hooks&&this.hooks.layout.trigger(e,this);let n=e.querySelectorAll("img");if(n.length&&await this.waitForImages(n),l=this.findBreakToken(e,t,r,g),l&&(h=0,this.rebuildTableFromBreakToken(l,e)),l&&l.equals(g)){console.warn("Unable to layout item: ",a);let t=l.node&&u(l.node);if(!t)return this.hooks&&this.hooks.beforeRenderResult.trigger(void 0,e,this),new M(void 0,new I("Unable to layout item",[a]));l=new q(t)}}}return this.hooks&&this.hooks.beforeRenderResult.trigger(l,e,this),new M(l)}breakAt(e,t=0){let n=new q(e,t);return this.hooks.onBreakToken.triggerSync(n,void 0,e,this).forEach((e=>{void 0!==e&&(n=e)})),n}shouldBreak(e,t){let n,r=m(e,t),a=e.parentNode;return S(e)&&a&&!r&&S(a)&&(n=e.dataset.breakBefore===a.dataset.breakBefore),!n&&S(e)||function(e){return void 0!==e&&void 0!==e.dataset&&void 0!==e.dataset.previousBreakAfter&&("always"===e.dataset.previousBreakAfter||"page"===e.dataset.previousBreakAfter||"left"===e.dataset.previousBreakAfter||"right"===e.dataset.previousBreakAfter||"recto"===e.dataset.previousBreakAfter||"verso"===e.dataset.previousBreakAfter)}(e)||v(e,r)}forceBreak(){this.forceRenderBreak=!0}getStart(e,t){let n,r=t&&t.node;return n=r||e.firstChild,n}append(e,t,n,r=!0,a=!0){let i=function(e,t=!1){return e.cloneNode(t)}(e,!r);if(e.parentNode&&d(e.parentNode)){let r=w(e.parentNode,t);if(r)r.appendChild(i);else if(a){let a=b(e);r=w(e.parentNode,a),r?n&&p(n.node)&&n.offset>0?(i.textContent=i.textContent.substring(n.offset),r.appendChild(i)):r.appendChild(i):t.appendChild(i),t.appendChild(a)}else t.appendChild(i)}else t.appendChild(i);return i.dataset&&i.dataset.ref&&(t.indexOfRefs||(t.indexOfRefs={}),t.indexOfRefs[i.dataset.ref]=i),this.hooks.renderNode.triggerSync(i,e,this).forEach((e=>{void 0!==e&&(i=e)})),i}rebuildTableFromBreakToken(e,t){if(!e||!e.node)return;let n=e.node,r=d(n)?n.closest("td"):n.parentElement.closest("td");if(r){if(!w(r,t,!0))return;for(;r=r.nextElementSibling;)this.append(r,t,null,!0)}}async waitForImages(e){let t=Array.from(e).map((async e=>this.awaitImageLoaded(e)));await Promise.all(t)}async awaitImageLoaded(e){return new Promise((t=>{if(!0!==e.complete)e.onload=function(){let{width:n,height:r}=window.getComputedStyle(e);t(n,r)},e.onerror=function(n){let{width:r,height:a}=window.getComputedStyle(e);t(r,a,n)};else{let{width:n,height:r}=window.getComputedStyle(e);t(n,r)}}))}avoidBreakInside(e,t){let n;if(e!==t){for(;e.parentNode&&(e=e.parentNode)!==t;)if("avoid"===window.getComputedStyle(e)["break-inside"]){n=e;break}return n}}createBreakToken(e,t,n){let r,a,i,o,s,l=e.startContainer,p=e.startOffset;if(d(l))if(s=_(l,p),d(s))if(a=w(s,t),a)r=w(a,n),p=0;else{let e=T(s);if(d(e)||(e=e.parentElement),a=w(e,t),!s.nextSibling){const e=w(a,n);if(!w(document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT).lastChild(),t))return}r=w(a,n).nextSibling,p=0}else a=w(l,t),a||(a=w(T(l),t)),i=w(a,n),o=O(s,i),0===o?(r=i,p=0):(r=_(i,o),p=0);else{if(a=w(l.parentNode,t),a||(a=w(T(l.parentNode),t)),i=w(a,n),o=O(l,i),-1===o)return;r=_(i,o),p+=r.textContent.indexOf(l.textContent)}if(r)return new q(r,p)}findBreakToken(e,t,n=this.bounds,r,a=!0){let i,o,s=this.findOverflow(e,n);if(this.hooks.onOverflow.triggerSync(s,e,n,this).forEach((e=>{void 0!==e&&(s=e)})),s){if(i=this.createBreakToken(s,e,t),this.hooks.onBreakToken.triggerSync(i,s,e,this).forEach((e=>{void 0!==e&&(i=e)})),i&&i.equals(r))return i;if(o=i&&i.node&&i.offset&&i.node.textContent?i.node.textContent.charAt(i.offset):void 0,i&&i.node&&a){let t=this.removeOverflow(s,o);this.hooks&&this.hooks.afterOverflowRemoved.trigger(t,e,this)}}return i}hasOverflow(e,t=this.bounds){let n=e&&e.parentNode,{width:r,height:a}=e.getBoundingClientRect(),i=n?n.scrollWidth:0,o=n?n.scrollHeight:0;return Math.max(Math.floor(r),i)>Math.round(t.width)||Math.max(Math.floor(a),o)>Math.round(t.height)}findOverflow(e,r=this.bounds,a=this.gap){if(!this.hasOverflow(e,r))return;let i,o,s,l,h,g,f,y,b,S=Math.floor(r.left),v=Math.round(r.right+a),x=Math.round(r.top),k=Math.round(r.bottom),w=c(e.firstChild,e);for(;!s;)if(o=w.next(),s=o.done,l=o.value,g=!1,f=!1,y=void 0,b=void 0,l){let r=t(l),a=Math.round(r.left),s=Math.floor(r.right),T=Math.round(r.top),_=Math.floor(r.bottom);if(!i&&(a>=v||T>=k)){let t=!1;const n=L(l,"TD",e);if(n&&"avoid"===window.getComputedStyle(n)["break-inside"])y=n.parentElement;else if(d(l)){let n=window.getComputedStyle(l);t="none"!==n.getPropertyValue("float"),g="avoid"===n.getPropertyValue("break-inside"),f="avoid"===l.dataset.breakBefore||"avoid"===l.dataset.previousBreakAfter,y=f&&m(l,e),b="BR"===l.tagName||"WBR"===l.tagName}let r;if(r="TR"===l.nodeName?l:L(l,"TR",e),r){let t=r.parentElement;if(["TBODY","THEAD"].includes(t.nodeName)){"avoid"===window.getComputedStyle(t).getPropertyValue("break-inside")&&(y=t)}const n=L(r,"TABLE",e),a=n.querySelector("[colspan]");if(n&&a){let e=0;for(const t of Array.from(n.rows[0].cells))e+=parseInt(t.getAttribute("colspan")||"1");if(r.cells.length!==e){let t,n=r.previousElementSibling;for(;null!==n;){t=0;for(const e of Array.from(n.cells))t+=parseInt(e.getAttribute("colspan")||"1");if(t===e)break;n=n.previousElementSibling}t===e&&(y=n)}}}if(y){i=document.createRange(),i.selectNode(y);break}if(!b&&!t&&d(l)){i=document.createRange(),i.selectNode(l);break}if(p(l)&&l.textContent.trim().length){i=document.createRange(),i.selectNode(l);break}}if(!i&&p(l)&&l.textContent.trim().length&&!W(l.parentNode)){let e,t=n(l);a=0,T=0;for(var C=0;C!=t.length;C++)e=t[C],e.width>0&&(!a||e.left>a)&&(a=e.left),e.height>0&&(!T||e.top>T)&&(T=e.top);if(a>=v||T>=k){i=document.createRange(),h=this.textBreak(l,S,v,x,k),h?i.setStart(l,h):i=void 0;break}}(g||s<=v&&_<=k)&&(o=u(l,e),o&&(w=c(o,e)))}return i?(i.setEndAfter(e.lastChild),i):void 0}findEndToken(e,t){if(0===e.childNodes.length)return;let n,r=e.lastChild;for(;r&&r.lastChild;)if(C(r)){if(!C(r.lastChild)){r=T(r.lastChild);break}r=r.lastChild}else r=r.previousSibling;p(r)&&(r.parentNode.dataset.ref?(n=function(e){let t=e.parentNode;return t?Array.prototype.indexOf.call(t.childNodes,e):0}(r),r=r.parentNode):r=r.previousSibling);let a=w(r,t);n&&(a=a.childNodes[n]);let i=u(a);return this.breakAt(i)}textBreak(e,n,r,a,i){let o,s,l,d,p,c=function*(e){let t,n,r=e.nodeValue,a=r.length,i=0;const o=e.parentElement&&"PRE"===e.parentElement.nodeName;for(;i<a;)t=r[i],/^[\S\u202F\u00A0]$/.test(t)||o?n||(n=document.createRange(),n.setStart(e,i)):n&&(n.setEnd(e,i),yield n,n=void 0),i+=1;n&&(n.setEnd(e,i),yield n)}(e),u=0,m=0,h=0,g=0;for(;!l&&(s=c.next(),o=s.value,l=s.done,o);){if(d=t(o),u=Math.floor(d.left),m=Math.floor(d.right),h=Math.floor(d.top),g=Math.floor(d.bottom),u>=r||h>=i){p=o.startOffset;break}if(m>r||g>i){let e,n,a,s=x(o);for(;!a&&(n=s.next(),e=n.value,a=n.done,e);)if(d=t(e),u=Math.floor(d.left),h=Math.floor(d.top),u>=r||h>=i){p=e.startOffset,l=!0;break}}}return p}removeOverflow(e,t){let{startContainer:n}=e,r=e.extractContents();return this.hyphenateAtBreak(n,t),r}hyphenateAtBreak(e,t){if(p(e)){let n=e.textContent,r=n[n.length-1];(t&&/^\w|\u00AD$/.test(r)&&/^\w|\u00AD$/.test(t)||!t&&/^\w|\u00AD$/.test(r))&&(e.parentNode.classList.add("pagedjs_hyphen"),e.textContent+=this.settings.hyphenGlyph||"‑")}}equalTokens(e,t){return!(!e||!t)&&((!e.node||!t.node||e.node===t.node)&&(!e.offset||!t.offset||e.offset===t.offset))}}be(ve.prototype);class xe{constructor(e,t,n,r,a){this.pagesArea=e,this.pageTemplate=t,this.blank=n,this.width=void 0,this.height=void 0,this.hooks=r,this.settings=a||{}}create(e,t){let n,r,a=document.importNode(this.pageTemplate.content,!0);t?(this.pagesArea.insertBefore(a,t.nextElementSibling),r=Array.prototype.indexOf.call(this.pagesArea.children,t.nextElementSibling),n=this.pagesArea.children[r]):(this.pagesArea.appendChild(a),n=this.pagesArea.lastChild);let i=n.querySelector(".pagedjs_pagebox"),o=n.querySelector(".pagedjs_page_content"),s=n.querySelector(".pagedjs_footnote_area"),l=o.getBoundingClientRect();return o.style.columnWidth=Math.round(l.width)+"px",o.style.columnGap="calc(var(--pagedjs-margin-right) + var(--pagedjs-margin-left) + var(--pagedjs-bleed-right) + var(--pagedjs-bleed-left) + var(--pagedjs-column-gap-offset))",this.width=Math.round(l.width),this.height=Math.round(l.height),this.element=n,this.pagebox=i,this.area=o,this.footnotesArea=s,n}createWrapper(){let e=document.createElement("div");return this.area.appendChild(e),this.wrapper=e,e}index(e){this.position=e;let t=this.element,n=e+1,r=`page-${n}`;this.id=r,t.dataset.pageNumber=n,t.setAttribute("id",r),this.name&&t.classList.add("pagedjs_"+this.name+"_page"),this.blank&&t.classList.add("pagedjs_blank_page"),0===e&&t.classList.add("pagedjs_first_page"),e%2!=1?(t.classList.remove("pagedjs_left_page"),t.classList.add("pagedjs_right_page")):(t.classList.remove("pagedjs_right_page"),t.classList.add("pagedjs_left_page"))}async layout(e,t,n){this.clear(),this.startToken=t;let r=this.settings;!r.maxChars&&n&&(r.maxChars=n),this.layoutMethod=new ve(this.area,this.hooks,r);let a=(await this.layoutMethod.renderTo(this.wrapper,e,t)).breakToken;return this.addListeners(e),this.endToken=a,a}async append(e,t){if(!this.layoutMethod)return this.layout(e,t);let n=(await this.layoutMethod.renderTo(this.wrapper,e,t)).breakToken;return this.endToken=n,n}getByParent(e,t){let n;for(var r=0;r<t.length;r++)if(n=t[r],n.dataset.ref===e)return n}onOverflow(e){this._onOverflow=e}onUnderflow(e){this._onUnderflow=e}clear(){this.removeListeners(),this.wrapper&&this.wrapper.remove(),this.createWrapper()}addListeners(e){return"undefined"!=typeof ResizeObserver?this.addResizeObserver(e):(this._checkOverflowAfterResize=this.checkOverflowAfterResize.bind(this,e),this.element.addEventListener("overflow",this._checkOverflowAfterResize,!1),this.element.addEventListener("underflow",this._checkOverflowAfterResize,!1)),this._onScroll=function(){this.listening&&(this.element.scrollLeft=0)}.bind(this),this.element.addEventListener("scroll",this._onScroll),this.listening=!0,!0}removeListeners(){this.listening=!1,"undefined"!=typeof ResizeObserver&&this.ro?this.ro.disconnect():this.element&&(this.element.removeEventListener("overflow",this._checkOverflowAfterResize,!1),this.element.removeEventListener("underflow",this._checkOverflowAfterResize,!1)),this.element&&this.element.removeEventListener("scroll",this._onScroll)}addResizeObserver(e){let t=this.wrapper,n=t.getBoundingClientRect().height;this.ro=new ResizeObserver((r=>{this.listening&&requestAnimationFrame((()=>{for(let a of r){const r=a.contentRect;r.height>n?(this.checkOverflowAfterResize(e),n=t.getBoundingClientRect().height):r.height<n&&(this.checkUnderflowAfterResize(e),n=r.height)}}))})),this.ro.observe(t)}checkOverflowAfterResize(e){if(!this.listening||!this.layoutMethod)return;let t=this.layoutMethod.findBreakToken(this.wrapper,e,this.startToken);t&&(this.endToken=t,this._onOverflow&&this._onOverflow(t))}checkUnderflowAfterResize(e){if(!this.listening||!this.layoutMethod)return;let t=this.layoutMethod.findEndToken(this.wrapper,e);t&&this._onUnderflow&&this._onUnderflow(t)}destroy(){this.removeListeners(),this.element.remove(),this.element=void 0,this.wrapper=void 0}}be(xe.prototype);class ke{constructor(e,t){return e&&e.nodeType?this.dom=this.add(e):"string"==typeof e&&(this.dom=this.parse(e)),this.dom}parse(e,t){let n=document.createRange().createContextualFragment(e);return this.addRefs(n),n}add(e){return this.addRefs(e),e}addRefs(e){var t=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,null,!1);let n=t.nextNode();for(;n;){if(!n.hasAttribute("data-ref")){let e=r();n.setAttribute("data-ref",e)}n.id&&n.setAttribute("data-id",n.id),n=t.nextNode()}}find(e){return this.refs[e]}destroy(){this.refs=void 0,this.dom=void 0}}class we{constructor(e){this._q=[],this.context=e,this.tick=requestAnimationFrame,this.running=!1,this.paused=!1}enqueue(){var e,t,n=[].shift.call(arguments),r=arguments;if(!n)throw new Error("No Task Provided");return t="function"==typeof n?{task:n,args:r,deferred:e=new o,promise:e.promise}:{promise:n},this._q.push(t),0!=this.paused||this.running||this.run(),t.promise}dequeue(){var e,t,n;return!this._q.length||this.paused?((e=new o).deferred.resolve(),e.promise):(t=(e=this._q.shift()).task)?(n=t.apply(this.context,e.args))&&"function"==typeof n.then?n.then(function(){e.deferred.resolve.apply(this.context,arguments)}.bind(this),function(){e.deferred.reject.apply(this.context,arguments)}.bind(this)):(e.deferred.resolve.apply(this.context,n),e.promise):e.promise?e.promise:void 0}dump(){for(;this._q.length;)this.dequeue()}run(){return this.running||(this.running=!0,this.defered=new o),this.tick.call(window,(()=>{this._q.length?this.dequeue().then(function(){this.run()}.bind(this)):(this.defered.resolve(),this.running=void 0)})),1==this.paused&&(this.paused=!1),this.defered.promise}flush(){return this.running?this.running:this._q.length?(this.running=this.dequeue().then(function(){return this.running=void 0,this.flush()}.bind(this)),this.running):void 0}clear(){this._q=[]}length(){return this._q.length}pause(){this.paused=!0}stop(){this._q=[],this.running=!1,this.paused=!0}}class Ce{constructor(e,t,n){this.settings=n||{},this.hooks={},this.hooks.beforeParsed=new Se(this),this.hooks.filter=new Se(this),this.hooks.afterParsed=new Se(this),this.hooks.beforePageLayout=new Se(this),this.hooks.onPageLayout=new Se(this),this.hooks.layout=new Se(this),this.hooks.renderNode=new Se(this),this.hooks.layoutNode=new Se(this),this.hooks.onOverflow=new Se(this),this.hooks.afterOverflowRemoved=new Se(this),this.hooks.onBreakToken=new Se,this.hooks.beforeRenderResult=new Se(this),this.hooks.afterPageLayout=new Se(this),this.hooks.finalizePage=new Se(this),this.hooks.afterRendered=new Se(this),this.pages=[],this.total=0,this.q=new we(this),this.stopped=!1,this.rendered=!1,this.content=e,this.charsPerBreak=[],this.maxChars,e&&this.flow(e,t)}setup(e){this.pagesArea=document.createElement("div"),this.pagesArea.classList.add("pagedjs_pages"),e?e.appendChild(this.pagesArea):document.querySelector("body").appendChild(this.pagesArea),this.pageTemplate=document.createElement("template"),this.pageTemplate.innerHTML='\n<div class="pagedjs_page">\n\t<div class="pagedjs_sheet">\n\t\t<div class="pagedjs_bleed pagedjs_bleed-top">\n\t\t\t<div class="pagedjs_marks-crop"></div>\n\t\t\t<div class="pagedjs_marks-middle">\n\t\t\t\t<div class="pagedjs_marks-cross"></div>\n\t\t\t</div>\n\t\t\t<div class="pagedjs_marks-crop"></div>\n\t\t</div>\n\t\t<div class="pagedjs_bleed pagedjs_bleed-bottom">\n\t\t\t<div class="pagedjs_marks-crop"></div>\n\t\t\t<div class="pagedjs_marks-middle">\n\t\t\t\t<div class="pagedjs_marks-cross"></div>\n\t\t\t</div>\t\t<div class="pagedjs_marks-crop"></div>\n\t\t</div>\n\t\t<div class="pagedjs_bleed pagedjs_bleed-left">\n\t\t\t<div class="pagedjs_marks-crop"></div>\n\t\t\t<div class="pagedjs_marks-middle">\n\t\t\t\t<div class="pagedjs_marks-cross"></div>\n\t\t\t</div>\t\t<div class="pagedjs_marks-crop"></div>\n\t\t</div>\n\t\t<div class="pagedjs_bleed pagedjs_bleed-right">\n\t\t\t<div class="pagedjs_marks-crop"></div>\n\t\t\t<div class="pagedjs_marks-middle">\n\t\t\t\t<div class="pagedjs_marks-cross"></div>\n\t\t\t</div>\n\t\t\t<div class="pagedjs_marks-crop"></div>\n\t\t</div>\n\t\t<div class="pagedjs_pagebox">\n\t\t\t<div class="pagedjs_margin-top-left-corner-holder">\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-top-left-corner"><div class="pagedjs_margin-content"></div></div>\n\t\t\t</div>\n\t\t\t<div class="pagedjs_margin-top">\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-top-left"><div class="pagedjs_margin-content"></div></div>\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-top-center"><div class="pagedjs_margin-content"></div></div>\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-top-right"><div class="pagedjs_margin-content"></div></div>\n\t\t\t</div>\n\t\t\t<div class="pagedjs_margin-top-right-corner-holder">\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-top-right-corner"><div class="pagedjs_margin-content"></div></div>\n\t\t\t</div>\n\t\t\t<div class="pagedjs_margin-right">\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-right-top"><div class="pagedjs_margin-content"></div></div>\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-right-middle"><div class="pagedjs_margin-content"></div></div>\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-right-bottom"><div class="pagedjs_margin-content"></div></div>\n\t\t\t</div>\n\t\t\t<div class="pagedjs_margin-left">\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-left-top"><div class="pagedjs_margin-content"></div></div>\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-left-middle"><div class="pagedjs_margin-content"></div></div>\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-left-bottom"><div class="pagedjs_margin-content"></div></div>\n\t\t\t</div>\n\t\t\t<div class="pagedjs_margin-bottom-left-corner-holder">\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-bottom-left-corner"><div class="pagedjs_margin-content"></div></div>\n\t\t\t</div>\n\t\t\t<div class="pagedjs_margin-bottom">\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-bottom-left"><div class="pagedjs_margin-content"></div></div>\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-bottom-center"><div class="pagedjs_margin-content"></div></div>\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-bottom-right"><div class="pagedjs_margin-content"></div></div>\n\t\t\t</div>\n\t\t\t<div class="pagedjs_margin-bottom-right-corner-holder">\n\t\t\t\t<div class="pagedjs_margin pagedjs_margin-bottom-right-corner"><div class="pagedjs_margin-content"></div></div>\n\t\t\t</div>\n\t\t\t<div class="pagedjs_area">\n\t\t\t\t<div class="pagedjs_page_content"></div>\n\t\t\t\t<div class="pagedjs_footnote_area">\n\t\t\t\t\t<div class="pagedjs_footnote_content pagedjs_footnote_empty">\n\t\t\t\t\t\t<div class="pagedjs_footnote_inner_content"></div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n</div>'}async flow(e,t){let n;await this.hooks.beforeParsed.trigger(e,this),n=new ke(e),this.hooks.filter.triggerSync(n),this.source=n,this.breakToken=void 0,this.pagesArea&&this.pageTemplate?(this.q.clear(),this.removePages()):this.setup(t),this.emit("rendering",n),await this.hooks.afterParsed.trigger(n,this),await this.loadFonts();let r=await this.render(n,this.breakToken);for(;r.canceled;)this.start(),r=await this.render(n,this.breakToken);return this.rendered=!0,this.pagesArea.style.setProperty("--pagedjs-page-count",this.total),await this.hooks.afterRendered.trigger(this.pages,this),this.emit("rendered",this.pages),this}async render(e,t){let n,r=this.layout(e,t),a=!1;for(;!a;)n=await this.q.enqueue((()=>this.renderAsync(r))),a=n.done;return n}start(){this.rendered=!1,this.stopped=!1}stop(){this.stopped=!0}renderOnIdle(e){return new Promise((t=>{s((async()=>{if(this.stopped)return t({done:!0,canceled:!0});let n=await e.next();this.stopped?t({done:!0,canceled:!0}):t(n)}))}))}async renderAsync(e){if(this.stopped)return{done:!0,canceled:!0};let t=await e.next();return this.stopped?{done:!0,canceled:!0}:t}async handleBreaks(e,t){let n,r,a,i=this.total+1,o=i%2==0?"left":"right",s=i%2==0?"verso":"recto";1!==i&&(e&&void 0!==e.dataset&&void 0!==e.dataset.previousBreakAfter&&(n=e.dataset.previousBreakAfter),e&&void 0!==e.dataset&&void 0!==e.dataset.breakBefore&&(r=e.dataset.breakBefore),t?a=this.addPage(!0):(!n||"left"!==n&&"right"!==n||n===o)&&(!n||"verso"!==n&&"recto"!==n||n===s)&&(!r||"left"!==r&&"right"!==r||r===o)&&(!r||"verso"!==r&&"recto"!==r||r===s)||(a=this.addPage(!0)),a&&(await this.hooks.beforePageLayout.trigger(a,void 0,void 0,this),this.emit("page",a),await this.hooks.afterPageLayout.trigger(a.element,a,void 0,this),await this.hooks.finalizePage.trigger(a.element,a,void 0,this),this.emit("renderedPage",a)))}async*layout(e,t){let n=t||!1,r=[];for(;void 0!==n;){n&&n.node?await this.handleBreaks(n.node):await this.handleBreaks(e.firstChild);let t=this.addPage();if(await this.hooks.beforePageLayout.trigger(t,e,n,this),this.emit("page",t),n=await t.layout(e,n,this.maxChars),n){let e=n.toJSON(!0);if(r.lastIndexOf(e)>-1){let e=new I("Layout repeated",[n.node]);return console.error("Layout repeated at: ",n.node),e}r.push(e)}await this.hooks.afterPageLayout.trigger(t.element,t,n,this),await this.hooks.finalizePage.trigger(t.element,t,void 0,this),this.emit("renderedPage",t),this.recoredCharLength(t.wrapper.textContent.length),yield n}}recoredCharLength(e){0!==e&&(this.charsPerBreak.push(e),this.charsPerBreak.length>4&&this.charsPerBreak.shift(),this.maxChars=this.charsPerBreak.reduce(((e,t)=>e+t),0)/this.charsPerBreak.length)}removePages(e=0){if(!(e>=this.pages.length)){for(let t=e;t<this.pages.length;t++)this.pages[t].destroy();e>0?this.pages.splice(e):this.pages=[],this.total=this.pages.length}}addPage(e){let t=this.pages[this.pages.length-1],n=new xe(this.pagesArea,this.pageTemplate,e,this.hooks,this.settings);return this.pages.push(n),n.create(void 0,t&&t.element),n.index(this.total),e||(n.onOverflow((e=>{if(console.warn("overflow on",n.id,e),this.rendered)return;let t=this.pages.indexOf(n)+1;this.stop(),this.breakToken=e,this.removePages(t),!0===this.rendered&&(this.rendered=!1,this.q.enqueue((async()=>{this.start(),await this.render(this.source,this.breakToken),this.rendered=!0})))})),n.onUnderflow((e=>{}))),this.total=this.pages.length,n}async clonePage(e){let t=this.pages[this.pages.length-1],n=new xe(this.pagesArea,this.pageTemplate,!1,this.hooks);this.pages.push(n),n.create(void 0,t&&t.element),n.index(this.total),await this.hooks.beforePageLayout.trigger(n,void 0,void 0,this),this.emit("page",n);for(const t of e.element.classList)"pagedjs_left_page"!==t&&"pagedjs_right_page"!==t&&n.element.classList.add(t);await this.hooks.afterPageLayout.trigger(n.element,n,void 0,this),await this.hooks.finalizePage.trigger(n.element,n,void 0,this),this.emit("renderedPage",n)}loadFonts(){let e=[];return(document.fonts||[]).forEach((t=>{if("loaded"!==t.status){let n=t.load().then((e=>t.family),(e=>(console.warn("Failed to preload font-family:",t.family),t.family)));e.push(n)}})),Promise.all(e).catch((e=>{console.warn(e)}))}destroy(){this.pagesArea.remove(),this.pageTemplate.remove()}}be(Ce.prototype);var Te={exports:{}},_e={};function ze(e){return{prev:null,next:null,data:e}}function Oe(e,t,n){var r;return null!==Ee?(r=Ee,Ee=Ee.cursor,r.prev=t,r.next=n,r.cursor=e.cursor):r={prev:t,next:n,cursor:e.cursor},e.cursor=r,r}function Ae(e){var t=e.cursor;e.cursor=t.cursor,t.prev=null,t.next=null,t.cursor=Ee,Ee=t}var Ee=null,je=function(){this.cursor=null,this.head=null,this.tail=null};je.createItem=ze,je.prototype.createItem=ze,je.prototype.updateCursors=function(e,t,n,r){for(var a=this.cursor;null!==a;)a.prev===e&&(a.prev=t),a.next===n&&(a.next=r),a=a.cursor},je.prototype.getSize=function(){for(var e=0,t=this.head;t;)e++,t=t.next;return e},je.prototype.fromArray=function(e){var t=null;this.head=null;for(var n=0;n<e.length;n++){var r=ze(e[n]);null!==t?t.next=r:this.head=r,r.prev=t,t=r}return this.tail=t,this},je.prototype.toArray=function(){for(var e=this.head,t=[];e;)t.push(e.data),e=e.next;return t},je.prototype.toJSON=je.prototype.toArray,je.prototype.isEmpty=function(){return null===this.head},je.prototype.first=function(){return this.head&&this.head.data},je.prototype.last=function(){return this.tail&&this.tail.data},je.prototype.each=function(e,t){var n;void 0===t&&(t=this);for(var r=Oe(this,null,this.head);null!==r.next;)n=r.next,r.next=n.next,e.call(t,n.data,n,this);Ae(this)},je.prototype.forEach=je.prototype.each,je.prototype.eachRight=function(e,t){var n;void 0===t&&(t=this);for(var r=Oe(this,this.tail,null);null!==r.prev;)n=r.prev,r.prev=n.prev,e.call(t,n.data,n,this);Ae(this)},je.prototype.forEachRight=je.prototype.eachRight,je.prototype.reduce=function(e,t,n){var r;void 0===n&&(n=this);for(var a=Oe(this,null,this.head),i=t;null!==a.next;)r=a.next,a.next=r.next,i=e.call(n,i,r.data,r,this);return Ae(this),i},je.prototype.reduceRight=function(e,t,n){var r;void 0===n&&(n=this);for(var a=Oe(this,this.tail,null),i=t;null!==a.prev;)r=a.prev,a.prev=r.prev,i=e.call(n,i,r.data,r,this);return Ae(this),i},je.prototype.nextUntil=function(e,t,n){if(null!==e){var r;void 0===n&&(n=this);for(var a=Oe(this,null,e);null!==a.next&&(r=a.next,a.next=r.next,!t.call(n,r.data,r,this)););Ae(this)}},je.prototype.prevUntil=function(e,t,n){if(null!==e){var r;void 0===n&&(n=this);for(var a=Oe(this,e,null);null!==a.prev&&(r=a.prev,a.prev=r.prev,!t.call(n,r.data,r,this)););Ae(this)}},je.prototype.some=function(e,t){var n=this.head;for(void 0===t&&(t=this);null!==n;){if(e.call(t,n.data,n,this))return!0;n=n.next}return!1},je.prototype.map=function(e,t){var n=new je,r=this.head;for(void 0===t&&(t=this);null!==r;)n.appendData(e.call(t,r.data,r,this)),r=r.next;return n},je.prototype.filter=function(e,t){var n=new je,r=this.head;for(void 0===t&&(t=this);null!==r;)e.call(t,r.data,r,this)&&n.appendData(r.data),r=r.next;return n},je.prototype.clear=function(){this.head=null,this.tail=null},je.prototype.copy=function(){for(var e=new je,t=this.head;null!==t;)e.insert(ze(t.data)),t=t.next;return e},je.prototype.prepend=function(e){return this.updateCursors(null,e,this.head,e),null!==this.head?(this.head.prev=e,e.next=this.head):this.tail=e,this.head=e,this},je.prototype.prependData=function(e){return this.prepend(ze(e))},je.prototype.append=function(e){return this.insert(e)},je.prototype.appendData=function(e){return this.insert(ze(e))},je.prototype.insert=function(e,t){if(null!=t)if(this.updateCursors(t.prev,e,t,e),null===t.prev){if(this.head!==t)throw new Error("before doesn't belong to list");this.head=e,t.prev=e,e.next=t,this.updateCursors(null,e)}else t.prev.next=e,e.prev=t.prev,t.prev=e,e.next=t;else this.updateCursors(this.tail,e,null,e),null!==this.tail?(this.tail.next=e,e.prev=this.tail):this.head=e,this.tail=e;return this},je.prototype.insertData=function(e,t){return this.insert(ze(e),t)},je.prototype.remove=function(e){if(this.updateCursors(e,e.prev,e,e.next),null!==e.prev)e.prev.next=e.next;else{if(this.head!==e)throw new Error("item doesn't belong to list");this.head=e.next}if(null!==e.next)e.next.prev=e.prev;else{if(this.tail!==e)throw new Error("item doesn't belong to list");this.tail=e.prev}return e.prev=null,e.next=null,e},je.prototype.push=function(e){this.insert(ze(e))},je.prototype.pop=function(){if(null!==this.tail)return this.remove(this.tail)},je.prototype.unshift=function(e){this.prepend(ze(e))},je.prototype.shift=function(){if(null!==this.head)return this.remove(this.head)},je.prototype.prependList=function(e){return this.insertList(e,this.head)},je.prototype.appendList=function(e){return this.insertList(e)},je.prototype.insertList=function(e,t){return null===e.head||(null!=t?(this.updateCursors(t.prev,e.tail,t,e.head),null!==t.prev?(t.prev.next=e.head,e.head.prev=t.prev):this.head=e.head,t.prev=e.tail,e.tail.next=t):(this.updateCursors(this.tail,e.tail,null,e.head),null!==this.tail?(this.tail.next=e.head,e.head.prev=this.tail):this.head=e.head,this.tail=e.tail),e.head=null,e.tail=null),this},je.prototype.replace=function(e,t){"head"in t?this.insertList(t,e):this.insert(t,e),this.remove(e)};var We=je,Le=function(e,t){var n=Object.create(SyntaxError.prototype),r=new Error;return n.name=e,n.message=t,Object.defineProperty(n,"stack",{get:function(){return(r.stack||"").replace(/^(.+\n){1,3}/,e+": "+t+"\n")}}),n},Be=Le,Pe=100,qe=60,Me=" ";function Ie(e,t){function n(e,t){return r.slice(e,t).map((function(t,n){for(var r=String(e+n+1);r.length<l;)r=" "+r;return r+" |"+t})).join("\n")}var r=e.source.split(/\r\n?|\n|\f/),a=e.line,i=e.column,o=Math.max(1,a-t)-1,s=Math.min(a+t,r.length+1),l=Math.max(4,String(s).length)+1,d=0;(i+=(Me.length-1)*(r[a-1].substr(0,i-1).match(/\t/g)||[]).length)>Pe&&(d=i-qe+3,i=qe-2);for(var p=o;p<=s;p++)p>=0&&p<r.length&&(r[p]=r[p].replace(/\t/g,Me),r[p]=(d>0&&r[p].length>d?"…":"")+r[p].substr(d,Pe-2)+(r[p].length>d+Pe-1?"…":""));return[n(o,a),new Array(i+l+2).join("-")+"^",n(a,s)].filter(Boolean).join("\n")}var De=function(e,t,n,r,a){var i=Be("SyntaxError",e);return i.source=t,i.offset=n,i.line=r,i.column=a,i.sourceFragment=function(e){return Ie(i,isNaN(e)?0:e)},Object.defineProperty(i,"formattedMessage",{get:function(){return"Parse error: "+i.message+"\n"+Ie(i,2)}}),i.parseError={offset:n,line:r,column:a},i},Re={EOF:0,Ident:1,Function:2,AtKeyword:3,Hash:4,String:5,BadString:6,Url:7,BadUrl:8,Delim:9,Number:10,Percentage:11,Dimension:12,WhiteSpace:13,CDO:14,CDC:15,Colon:16,Semicolon:17,Comma:18,LeftSquareBracket:19,RightSquareBracket:20,LeftParenthesis:21,RightParenthesis:22,LeftCurlyBracket:23,RightCurlyBracket:24,Comment:25},Ne=Object.keys(Re).reduce((function(e,t){return e[Re[t]]=t,e}),{}),Ge={TYPE:Re,NAME:Ne},Fe=0;function Ve(e){return e>=48&&e<=57}function Ue(e){return e>=65&&e<=90}function He(e){return e>=97&&e<=122}function $e(e){return Ue(e)||He(e)}function Ye(e){return e>=128}function Ke(e){return $e(e)||Ye(e)||95===e}function Ze(e){return e>=0&&e<=8||11===e||e>=14&&e<=31||127===e}function Qe(e){return 10===e||13===e||12===e}function Je(e){return Qe(e)||32===e||9===e}function Xe(e,t){return 92===e&&(!Qe(t)&&t!==Fe)}var et=new Array(128);nt.Eof=128,nt.WhiteSpace=130,nt.Digit=131,nt.NameStart=132,nt.NonPrintable=133;for(var tt=0;tt<et.length;tt++)switch(!0){case Je(tt):et[tt]=nt.WhiteSpace;break;case Ve(tt):et[tt]=nt.Digit;break;case Ke(tt):et[tt]=nt.NameStart;break;case Ze(tt):et[tt]=nt.NonPrintable;break;default:et[tt]=tt||nt.Eof}function nt(e){return e<128?et[e]:nt.NameStart}var rt={isDigit:Ve,isHexDigit:function(e){return Ve(e)||e>=65&&e<=70||e>=97&&e<=102},isUppercaseLetter:Ue,isLowercaseLetter:He,isLetter:$e,isNonAscii:Ye,isNameStart:Ke,isName:function(e){return Ke(e)||Ve(e)||45===e},isNonPrintable:Ze,isNewline:Qe,isWhiteSpace:Je,isValidEscape:Xe,isIdentifierStart:function(e,t,n){return 45===e?Ke(t)||45===t||Xe(t,n):!!Ke(e)||92===e&&Xe(e,t)},isNumberStart:function(e,t,n){return 43===e||45===e?Ve(t)?2:46===t&&Ve(n)?3:0:46===e?Ve(t)?2:0:Ve(e)?1:0},isBOM:function(e){return 65279===e||65534===e?1:0},charCodeCategory:nt},at=rt.isDigit,it=rt.isHexDigit,ot=rt.isUppercaseLetter,st=rt.isName,lt=rt.isWhiteSpace,dt=rt.isValidEscape;function pt(e,t){return t<e.length?e.charCodeAt(t):0}function ct(e,t,n){return 13===n&&10===pt(e,t+1)?2:1}function ut(e,t,n){var r=e.charCodeAt(t);return ot(r)&&(r|=32),r===n}function mt(e,t){for(;t<e.length&&at(e.charCodeAt(t));t++);return t}function ht(e,t){if(it(pt(e,(t+=2)-1))){for(var n=Math.min(e.length,t+5);t<n&&it(pt(e,t));t++);var r=pt(e,t);lt(r)&&(t+=ct(e,t,r))}return t}var gt={consumeEscaped:ht,consumeName:function(e,t){for(;t<e.length;t++){var n=e.charCodeAt(t);if(!st(n)){if(!dt(n,pt(e,t+1)))break;t=ht(e,t)-1}}return t},consumeNumber:function(e,t){var n=e.charCodeAt(t);if(43!==n&&45!==n||(n=e.charCodeAt(t+=1)),at(n)&&(t=mt(e,t+1),n=e.charCodeAt(t)),46===n&&at(e.charCodeAt(t+1))&&(n=e.charCodeAt(t+=2),t=mt(e,t)),ut(e,t,101)){var r=0;45!==(n=e.charCodeAt(t+1))&&43!==n||(r=1,n=e.charCodeAt(t+2)),at(n)&&(t=mt(e,t+1+r+1))}return t},consumeBadUrlRemnants:function(e,t){for(;t<e.length;t++){var n=e.charCodeAt(t);if(41===n){t++;break}dt(n,pt(e,t+1))&&(t=ht(e,t))}return t},cmpChar:ut,cmpStr:function(e,t,n,r){if(n-t!==r.length)return!1;if(t<0||n>e.length)return!1;for(var a=t;a<n;a++){var i=e.charCodeAt(a),o=r.charCodeAt(a-t);if(ot(i)&&(i|=32),i!==o)return!1}return!0},getNewlineLength:ct,findWhiteSpaceStart:function(e,t){for(;t>=0&&lt(e.charCodeAt(t));t--);return t+1},findWhiteSpaceEnd:function(e,t){for(;t<e.length&&lt(e.charCodeAt(t));t++);return t}},ft=Ge.TYPE,yt=Ge.NAME,bt=gt.cmpStr,St=ft.EOF,vt=ft.WhiteSpace,xt=ft.Comment,kt=16777215,wt=24,Ct=function(){this.offsetAndType=null,this.balance=null,this.reset()};Ct.prototype={reset:function(){this.eof=!1,this.tokenIndex=-1,this.tokenType=0,this.tokenStart=this.firstCharOffset,this.tokenEnd=this.firstCharOffset},lookupType:function(e){return(e+=this.tokenIndex)<this.tokenCount?this.offsetAndType[e]>>wt:St},lookupOffset:function(e){return(e+=this.tokenIndex)<this.tokenCount?this.offsetAndType[e-1]&kt:this.source.length},lookupValue:function(e,t){return(e+=this.tokenIndex)<this.tokenCount&&bt(this.source,this.offsetAndType[e-1]&kt,this.offsetAndType[e]&kt,t)},getTokenStart:function(e){return e===this.tokenIndex?this.tokenStart:e>0?e<this.tokenCount?this.offsetAndType[e-1]&kt:this.offsetAndType[this.tokenCount]&kt:this.firstCharOffset},getRawLength:function(e,t){var n,r=e,a=this.offsetAndType[Math.max(r-1,0)]&kt;e:for(;r<this.tokenCount&&!((n=this.balance[r])<e);r++)switch(t(this.offsetAndType[r]>>wt,this.source,a)){case 1:break e;case 2:r++;break e;default:this.balance[n]===r&&(r=n),a=this.offsetAndType[r]&kt}return r-this.tokenIndex},isBalanceEdge:function(e){return this.balance[this.tokenIndex]<e},isDelim:function(e,t){return t?this.lookupType(t)===ft.Delim&&this.source.charCodeAt(this.lookupOffset(t))===e:this.tokenType===ft.Delim&&this.source.charCodeAt(this.tokenStart)===e},getTokenValue:function(){return this.source.substring(this.tokenStart,this.tokenEnd)},getTokenLength:function(){return this.tokenEnd-this.tokenStart},substrToCursor:function(e){return this.source.substring(e,this.tokenStart)},skipWS:function(){for(var e=this.tokenIndex,t=0;e<this.tokenCount&&this.offsetAndType[e]>>wt===vt;e++,t++);t>0&&this.skip(t)},skipSC:function(){for(;this.tokenType===vt||this.tokenType===xt;)this.next()},skip:function(e){var t=this.tokenIndex+e;t<this.tokenCount?(this.tokenIndex=t,this.tokenStart=this.offsetAndType[t-1]&kt,t=this.offsetAndType[t],this.tokenType=t>>wt,this.tokenEnd=t&kt):(this.tokenIndex=this.tokenCount,this.next())},next:function(){var e=this.tokenIndex+1;e<this.tokenCount?(this.tokenIndex=e,this.tokenStart=this.tokenEnd,e=this.offsetAndType[e],this.tokenType=e>>wt,this.tokenEnd=e&kt):(this.tokenIndex=this.tokenCount,this.eof=!0,this.tokenType=St,this.tokenStart=this.tokenEnd=this.source.length)},forEachToken(e){for(var t=0,n=this.firstCharOffset;t<this.tokenCount;t++){var r=n,a=this.offsetAndType[t],i=a&kt;n=i,e(a>>wt,r,i,t)}},dump(){var e=new Array(this.tokenCount);return this.forEachToken(((t,n,r,a)=>{e[a]={idx:a,type:yt[t],chunk:this.source.substring(n,r),balance:this.balance[a]}})),e}};var Tt=Ct;function _t(e){return e}function zt(e,t,n,r){var a,i;switch(e.type){case"Group":a=function(e,t,n,r){var a=" "===e.combinator||r?e.combinator:" "+e.combinator+" ",i=e.terms.map((function(e){return zt(e,t,n,r)})).join(a);return(e.explicit||n)&&(i=(r||","===i[0]?"[":"[ ")+i+(r?"]":" ]")),i}(e,t,n,r)+(e.disallowEmpty?"!":"");break;case"Multiplier":return zt(e.term,t,n,r)+t(0===(i=e).min&&0===i.max?"*":0===i.min&&1===i.max?"?":1===i.min&&0===i.max?i.comma?"#":"+":1===i.min&&1===i.max?"":(i.comma?"#":"")+(i.min===i.max?"{"+i.min+"}":"{"+i.min+","+(0!==i.max?i.max:"")+"}"),e);case"Type":a="<"+e.name+(e.opts?t(function(e){if("Range"===e.type)return" ["+(null===e.min?"-∞":e.min)+","+(null===e.max?"∞":e.max)+"]";throw new Error("Unknown node type `"+e.type+"`")}(e.opts),e.opts):"")+">";break;case"Property":a="<'"+e.name+"'>";break;case"Keyword":a=e.name;break;case"AtKeyword":a="@"+e.name;break;case"Function":a=e.name+"(";break;case"String":case"Token":a=e.value;break;case"Comma":a=",";break;default:throw new Error("Unknown node type `"+e.type+"`")}return t(a,e)}var Ot=function(e,t){var n=_t,r=!1,a=!1;return"function"==typeof t?n=t:t&&(r=Boolean(t.forceBraces),a=Boolean(t.compact),"function"==typeof t.decorate&&(n=t.decorate)),zt(e,n,r,a)};const At=Le,Et=Ot,jt={offset:0,line:1,column:1};function Wt(e,t){const n=e&&e.loc&&e.loc[t];return n?"line"in n?Lt(n):n:null}function Lt({offset:e,line:t,column:n},r){const a={offset:e,line:t,column:n};if(r){const e=r.split(/\n|\r\n?|\f/);a.offset+=r.length,a.line+=e.length-1,a.column=1===e.length?a.column+r.length:e.pop().length+1}return a}var Bt=function(e,t){const n=At("SyntaxReferenceError",e+(t?" `"+t+"`":""));return n.reference=t,n},Pt=function(e,t,n,r){const a=At("SyntaxMatchError",e),{css:i,mismatchOffset:o,mismatchLength:s,start:
\ No newline at end of file