@vivliostyle/core 2.36.3 → 2.36.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/vivliostyle.js +1 -1
- package/lib/vivliostyle.js.map +3 -3
- package/package.json +2 -2
package/lib/vivliostyle.js
CHANGED
|
@@ -1514,7 +1514,7 @@ span[data-viv-leader] {
|
|
|
1514
1514
|
`);for(let s of Kd(this.properties))n.append(s),n.append(": "),this.properties[s].appendTo(n,!0),n.append(`;
|
|
1515
1515
|
`);if(e){n.append('src: url("');let s=Sh(e);n.append(s),this.blobURLs.push(s),this.blobs.push(e),n.append('")')}else n.append("src: "),n.append(t);return n.append(`;
|
|
1516
1516
|
}
|
|
1517
|
-
`),n.toString()}},Ha=class{constructor(t){this.deobfuscator=t;p(this,"familyMap",{})}registerFamily(t,e){let n=t.family,s=this.familyMap[n],o=e.family;if(s){if(s!=o)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${t.family}`)}else this.familyMap[n]=o}filterFontFamily(t){if(t instanceof fe){let e=t.values,n=[];for(let s of e){let o=this.familyMap[s.stringValue()];o&&n.push(L(o)),n.push(s)}return new fe(n)}else{let e=this.familyMap[t.stringValue()];return e?new fe([L(e),t]):t}}},za=class{constructor(t,e,n){this.head=t;this.body=e;p(this,"srcURLMap",{});p(this,"familyPrefix");p(this,"familyCounter",0);this.familyPrefix=n||"Fnt_"}getViewFontFamily(t,e){let n=t.family,s=e.familyMap[n];return s||(s=this.familyPrefix+ ++this.familyCounter,e.familyMap[n]=s,s)}initFont(t,e,n){let s=A("initFont"),o=t.src,i={};for(let u of Kd(t.properties))i[u]=t.properties[u];let a=this.getViewFontFamily(t,n);i["font-family"]=L(a);let l=new Mi(i),c=this.head.ownerDocument.createElement("style");return c.textContent=l.makeAtRule(o,e),this.head.appendChild(c),F.debug("Load font:",o),s.finish(l),s.result()}loadFont(t,e){let n=t.src,s=t.family+";"+n,o=this.srcURLMap[s];return o?o.piggyback(i=>{let a=i;a.traitsEqual(t)?(e.registerFamily(t,a),F.debug("Found already-loaded font:",n)):F.warn("E_FONT_FACE_INCOMPATIBLE",t.src)}):(o=new nn(()=>{let i=A("loadFont"),a=n.replace(/^url\("([^"]+)"\).*$/,"$1"),l=e.deobfuscator?e.deobfuscator(a):null;return l?xs(a,"blob").then(c=>{if(!c.responseBlob){i.finish(null);return}l(c.responseBlob).then(u=>{this.initFont(t,u,e).thenFinish(i)})}):this.initFont(t,null,e).thenFinish(i),i.result()},`loadFont ${n}`),this.srcURLMap[s]=o,o.start()),o}findOrLoadFonts(t,e){let n=[];for(let s of t){if(!s.src||!s.family){F.warn("E_FONT_FACE_INVALID");continue}n.push(this.loadFont(s,e))}return On(n).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let t=this.head.ownerDocument.fonts,e=0;if(t.forEach(s=>{s.status==="unloaded"&&(e++,s.load().catch(o=>{}))}),e===0)return T(!0);let n=A("waitFontLoading");return n.loop(()=>n.sleep(20).thenAsync(()=>t.status==="loading"?T(!0):T(!1))).thenFinish(n),n.result()}};var lb=1,Io=class{constructor(t,e,n,s,o){this.name=e;this.pseudoName=n;this.classes=s;this.parent=o;p(this,"specified",{});p(this,"children",[]);p(this,"pageMaster",null);p(this,"index",0);p(this,"key");p(this,"_scope");this._scope=t,this.key=`p${lb++}`,o&&(this.index=o.children.length,o.children.push(this))}get scope(){return this._scope}createInstance(t){throw new Error("E_UNEXPECTED_CALL")}clone(t){throw new Error("E_UNEXPECTED_CALL")}copySpecified(t){let e=this.specified,n=t.specified;for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}cloneChildren(t){for(let e=0;e<this.children.length;e++)this.children[e].clone({parent:t})}},Ga=class extends Io{constructor(t){super(t,null,null,[],null),this.specified.width=new H(Fn,0),this.specified.height=new H(Bn,0)}},Wa=class extends ds{constructor(e,n){super(e,o);this.pageMaster=n;let s=this;function o(i,a){let l=i.match(/^([^.]+)\.([^.]+)$/);if(l){let c=s.pageMaster.keyMap[l[1]];if(c){let d=this.lookupInstance(c);if(d)return a?d.resolveFunc(l[2]):d.resolveName(l[2])}}return null}}},Vo=class r extends Io{constructor(e,n,s,o,i,a,l){super(e,n,s,o,i);this.condition=a;this.specificity=l;p(this,"keyMap",{});e instanceof Wa||(this._scope=new Wa(e,this)),this.pageMaster=this,this.specified.width=new H(Fn,0),this.specified.height=new H(Bn,0),this.specified["wrap-flow"]=new H(b.auto,0),this.specified.position=new H(b.relative,0),this.specified.overflow=new H(b.visible,0)}createInstance(e){return new zs(e,this)}clone(e){let n=new r(this.scope,this.name,e.pseudoName||this.pseudoName,this.classes,this.parent,this.condition,this.specificity);return this.copySpecified(n),this.cloneChildren(n),n}resetScope(){this.scope.pageMaster=this}},$a=class r extends Io{constructor(t,e,n,s,o){super(t,e,n,s,o),this.pageMaster=o.pageMaster,e&&(this.pageMaster.keyMap[e]=this.key),this.specified["wrap-flow"]=new H(b.auto,0)}createInstance(t){return new qd(t,this)}clone(t){let e=new r(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(e),this.cloneChildren(e),e}},ns=class r extends Io{constructor(t,e,n,s,o){super(t,e,n,s,o),this.pageMaster=o.pageMaster,e&&(this.pageMaster.keyMap[e]=this.key)}createInstance(t){return new dn(t,this)}clone(t){let e=new r(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(e),this.cloneChildren(e),e}};function cb(r,t,e){return!t||U(t)?new ie(r,e):t.toExpr(r,r.zero)}function ee(r,t,e){return!t||t===b.auto||U(t)?null:t.toExpr(r,e)}function ub(r,t,e){return!t||t===b.normal||U(t)?null:t.toExpr(r,e)}function nt(r,t,e){return!t||t===b.auto||U(t)?r.zero:t.toExpr(r,e)}function Qd(r,t,e){return!t||U(t)?r.zero:t===b.auto?null:t.toExpr(r,e)}function $t(r,t,e,n){return!t||e===b.none||U(t)?r.zero:t.toExpr(r,n)}function Cg(r,t,e){return!t||U(t)?e:t===b._true?r._true:t===b._false?r._false:t.toExpr(r,r.zero)}var Fo=class{constructor(t,e){this.parentInstance=t;this.pageBox=e;p(this,"cascaded",{});p(this,"style",{});p(this,"autoWidth",null);p(this,"autoHeight",null);p(this,"children",[]);p(this,"isAutoWidth",!1);p(this,"isAutoHeight",!1);p(this,"isTopDependentOnAutoHeight",!1);p(this,"isRightDependentOnAutoWidth",!1);p(this,"calculatedWidth",0);p(this,"calculatedHeight",0);p(this,"pageMasterInstance",null);p(this,"namedValues",{});p(this,"namedFuncs",{});p(this,"vertical",!1);p(this,"rtl",!1);p(this,"suppressEmptyBoxGeneration",!1);p(this,"borderBoxSizing",!1);t&&t.children.push(this)}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(t,e){let n=this.resolveName(t),s=this.resolveName(e);if(!n||!s)throw new Error("E_INTERNAL");return G(this.pageBox.scope,n,s)}resolveName(t){let e=this.namedValues[t];if(e)return e;let n=this.style[t];switch(n&&(e=n.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),t){case"margin-left-edge":e=this.resolveName("left");break;case"margin-top-edge":e=this.resolveName("top");break;case"margin-right-edge":e=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":e=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":e=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":e=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":e=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":e=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":e=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":e=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":e=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":e=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":e=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":e=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":e=this.addNamedValues("left-edge","width");break;case"bottom-edge":e=this.addNamedValues("top-edge","height");break}if(!e){let s;if(t=="extent")s=this.vertical?"width":"height";else if(t=="measure")s=this.vertical?"height":"width";else{let o=this.vertical?$u:Xu;s=t;for(let i in o)s=s.replace(i,o[i])}s!=t&&(e=this.resolveName(s))}return e&&(this.namedValues[t]=e),e}resolveFunc(t){let e=this.namedFuncs[t];if(e)return e;switch(t){case"columns":{let n=this.pageBox.scope,s=new Js(n,0),o=this.resolveName("column-count"),i=this.resolveName("column-width"),a=this.resolveName("column-gap");e=Y(n,eo(n,new gn(n,"min",[s,o]),G(n,i,a)),a);break}}return e&&(this.namedFuncs[t]=e),e}initEnabled(){let t=this.pageBox.scope,e=this.style,n=Cg(t,e.enabled,t._true),s=ee(t,e.page,t.zero);if(s){let a=new J(t,"page-number");n=Qe(t,n,new Vn(t,s,a))}let o=ee(t,e["min-page-width"],t.zero);o&&(n=Qe(t,n,new ps(t,new J(t,"page-width"),o)));let i=ee(t,e["min-page-height"],t.zero);i&&(n=Qe(t,n,new ps(t,new J(t,"page-height"),i))),n=this.boxSpecificEnabled(n),e.enabled=new B(n)}boxSpecificEnabled(t){return t}initHorizontal(){let t=this.pageBox.scope,e=this.style,n=this.parentInstance?this.parentInstance.style.width.toExpr(t,null):null,s=ee(t,e.left,n),o=ee(t,e["margin-left"],n),i=$t(t,e["border-left-width"],e["border-left-style"],n),a=nt(t,e["padding-left"],n),l=ee(t,e.width,n),c=ee(t,e["max-width"],n),u=nt(t,e["padding-right"],n),d=$t(t,e["border-right-width"],e["border-right-style"],n),h=ee(t,e["margin-right"],n),f=ee(t,e.right,n),g=G(t,i,a),m=G(t,i,u);if(s&&f&&l){let C=Y(t,n,G(t,l,G(t,G(t,s,g),m)));o?h?f=Y(t,C,h):h=Y(t,C,G(t,f,o)):(C=Y(t,C,f),h?o=Y(t,C,h):(o=eo(t,C,new ie(t,.5)),h=o))}else{o||(o=t.zero),h||(h=t.zero),!s&&!f&&!l&&(s=t.zero),!s&&!l?(l=this.autoWidth,this.isAutoWidth=!0):!s&&!f?s=t.zero:!l&&!f&&(l=this.autoWidth,this.isAutoWidth=!0);let C=Y(t,n,G(t,G(t,o,g),G(t,h,m)));this.isAutoWidth&&(c||(c=Y(t,C,s||f)),!this.vertical&&(ee(t,e["column-width"],null)||ee(t,e["column-count"],null))&&(l=c,this.isAutoWidth=!1)),s?l?f||(f=Y(t,C,G(t,s,l))):l=Y(t,C,G(t,s,f)):s=Y(t,C,G(t,f,l))}let x=e["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),E=nt(t,x,n);e.left=new B(s),e["margin-left"]=new B(o),e["border-left-width"]=new B(i),e["padding-left"]=new B(a),e.width=new B(l),e["max-width"]=new B(c||l),e["padding-right"]=new B(u),e["border-right-width"]=new B(d),e["margin-right"]=new B(h),e.right=new B(f),e["snap-width"]=new B(E)}initVertical(){let t=this.pageBox.scope,e=this.style,n=this.parentInstance?this.parentInstance.style.width.toExpr(t,null):null,s=this.parentInstance?this.parentInstance.style.height.toExpr(t,null):null,o=ee(t,e.top,s),i=ee(t,e["margin-top"],n),a=$t(t,e["border-top-width"],e["border-top-style"],n),l=nt(t,e["padding-top"],n),c=ee(t,e.height,s),u=ee(t,e["max-height"],s),d=nt(t,e["padding-bottom"],n),h=$t(t,e["border-bottom-width"],e["border-bottom-style"],n),f=ee(t,e["margin-bottom"],n),g=ee(t,e.bottom,s),m=G(t,a,l),x=G(t,h,d);if(o&&g&&c){let y=Y(t,s,G(t,c,G(t,G(t,o,m),x)));i?f?g=Y(t,y,i):f=Y(t,y,G(t,g,i)):(y=Y(t,y,g),f?i=Y(t,y,f):(i=eo(t,y,new ie(t,.5)),f=i))}else{i||(i=t.zero),f||(f=t.zero),!o&&!g&&!c&&(o=t.zero),!o&&!c?(c=this.autoHeight,this.isAutoHeight=!0):!o&&!g?o=t.zero:!c&&!g&&(c=this.autoHeight,this.isAutoHeight=!0);let y=Y(t,s,G(t,G(t,i,m),G(t,f,x)));this.isAutoHeight&&(u||(u=Y(t,y,o||g)),this.vertical&&(ee(t,e["column-width"],null)||ee(t,e["column-count"],null))&&(c=u,this.isAutoHeight=!1)),o?c?g||(g=Y(t,y,G(t,o,c))):c=Y(t,y,G(t,g,o)):o=Y(t,y,G(t,g,c))}let E=e["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),C=nt(t,E,n);e.top=new B(o),e["margin-top"]=new B(i),e["border-top-width"]=new B(a),e["padding-top"]=new B(l),e.height=new B(c),e["max-height"]=new B(u||c),e["padding-bottom"]=new B(d),e["border-bottom-width"]=new B(h),e["margin-bottom"]=new B(f),e.bottom=new B(g),e["snap-height"]=new B(C)}initColumns(){let t=this.pageBox.scope,e=this.style,n=ee(t,e[this.vertical?"height":"width"],null),s=ee(t,e["column-width"],n),o=ee(t,e["column-count"],null),i=ub(t,e["column-gap"],null);i||(i=new Dt(t,1,"em")),s&&!o&&(o=new gn(t,"floor",[Ko(t,G(t,n,i),G(t,s,i))]),o=new gn(t,"max",[t.one,o])),o||(o=t.one),s=Y(t,Ko(t,G(t,n,i),o),i),e["column-width"]=new B(s),e["column-count"]=new B(o),e["column-gap"]=new B(i)}depends(t,e,n){return this.style[t].toExpr(this.pageBox.scope,null).depend(e,n)}init(t){var l;t.registerInstance(this.pageBox.key,this);let n=this.pageBox.scope,s=this.style,o=this.parentInstance?this.parentInstance.getActiveRegions(t):null,i=Ta(this.cascaded,t,o,!1,null);this.vertical=Na(i,t,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=va(i,t,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((l=i["box-sizing"])==null?void 0:l.value)===b.border_box;let a=!!(t instanceof ss&&t.currentLayoutPosition&&new J(n,"left-page").evaluate(t));wa(i,s,this.vertical,this.rtl,a,(c,u)=>u.value),this.autoWidth=new q(n,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new q(n,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(t,e){var s,o;let n=this.style[e];return!n&&Zn(e)&&this.pageMasterInstance instanceof pn&&(e==="font-size"&&t.isRelativeRootFontSize&&t.rootFontSize?n=new P(t.rootFontSize,"px"):n=(o=((s=t.styler)==null?void 0:s.rootStyle)[e])==null?void 0:o.value),n&&(n=Ni(t,n,e)),n}getPropAsNumber(t,e){var s,o;let n=this.style[e];if(n){let i=/\b(height|top|bottom)\b/.test(e)?(s=t.pageAreaHeight)!=null?s:t.pageHeight():(o=t.pageAreaWidth)!=null?o:t.pageWidth();n=Ni(t,n,e,i)}return Pe(n,t)}getSpecial(t,e){let n=ju(this.cascaded,e);if(n){let s=[];for(let o=0;o<n.length;o++){let i=n[o].evaluate(t,"");i&&i!==D&&s.push(i)}if(s.length)return s}return null}getActiveRegions(t){let e=this.getSpecial(t,"region-id");if(e){let n=[];for(let s=0;s<e.length;s++)n[s]=e[s].toString();return n}return null}propagateProperty(t,e,n,s){this.propagatePropertyToElement(t,e.element,n,s)}propagatePropertyToElement(t,e,n,s){let o=this.getProp(t,n);o&&(o.isNumeric()&&Pr(o.unit)&&(o=Lr(o,t)),n==="font-family"&&(o=s.filterFontFamily(o)),(n.startsWith("background")||n==="z-index")&&e.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(e=e.parentElement),w(e,n,o.toString()))}propagateDelayedProperty(t,e,n,s){let o=this.getProp(t,n);o&&s.push(new zn(e.element,n,o))}assignLeftPosition(t,e){let n=this.getPropAsNumber(t,"left"),s=this.getPropAsNumber(t,"margin-left"),o=this.getPropAsNumber(t,"padding-left"),i=this.getPropAsNumber(t,"border-left-width"),a=this.getPropAsNumber(t,"width");e.setHorizontalPosition(n,a),w(e.element,"margin-left",`${s}px`),w(e.element,"padding-left",`${o}px`),w(e.element,"border-left-width",`${i}px`),e.marginLeft=s,e.borderLeft=i,e.paddingLeft=o}assignRightPosition(t,e){let n=this.getPropAsNumber(t,"right"),s=this.getPropAsNumber(t,"snap-height"),o=this.getPropAsNumber(t,"margin-right"),i=this.getPropAsNumber(t,"padding-right"),a=this.getPropAsNumber(t,"border-right-width");if(w(e.element,"margin-right",`${o}px`),w(e.element,"padding-right",`${i}px`),w(e.element,"border-right-width",`${a}px`),e.marginRight=o,e.borderRight=a,this.vertical&&s>0){let l=n+e.getInsetRight(),c=l-Math.floor(l/s)*s;c>0&&(e.snapOffsetX=s-c,i+=e.snapOffsetX)}e.paddingRight=i,e.snapWidth=s}assignTopPosition(t,e){let n=this.getPropAsNumber(t,"snap-height"),s=this.getPropAsNumber(t,"top"),o=this.getPropAsNumber(t,"margin-top"),i=this.getPropAsNumber(t,"padding-top"),a=this.getPropAsNumber(t,"border-top-width");if(e.top=s,e.marginTop=o,e.borderTop=a,e.snapHeight=n,!this.vertical&&n>0){let l=s+e.getInsetTop(),c=l-Math.floor(l/n)*n;c>0&&(e.snapOffsetY=n-c,i+=e.snapOffsetY)}e.paddingTop=i,w(e.element,"top",`${s}px`),w(e.element,"margin-top",`${o}px`),w(e.element,"padding-top",`${i}px`),w(e.element,"border-top-width",`${a}px`)}assignBottomPosition(t,e){let n=this.getPropAsNumber(t,"margin-bottom"),s=this.getPropAsNumber(t,"padding-bottom"),o=this.getPropAsNumber(t,"border-bottom-width"),i=this.getPropAsNumber(t,"height")-e.snapOffsetY;w(e.element,"height",`${i}px`),w(e.element,"margin-bottom",`${n}px`),w(e.element,"padding-bottom",`${s}px`),w(e.element,"border-bottom-width",`${o}px`),e.height=i-e.snapOffsetY,e.marginBottom=n,e.borderBottom=o,e.paddingBottom=s}assignBeforePosition(t,e){this.vertical?this.assignRightPosition(t,e):this.assignTopPosition(t,e)}assignAfterPosition(t,e){this.vertical?this.assignLeftPosition(t,e):this.assignBottomPosition(t,e)}assignStartEndPosition(t,e){this.vertical?(this.assignTopPosition(t,e),this.assignBottomPosition(t,e)):(this.assignRightPosition(t,e),this.assignLeftPosition(t,e))}sizeWithMaxHeight(t,e){w(e.element,"border-top-width","0px");let n=this.getPropAsNumber(t,"max-height");this.isTopDependentOnAutoHeight?e.setVerticalPosition(0,n):(this.assignTopPosition(t,e),n-=e.snapOffsetY,e.height=n,w(e.element,"height",`${n}px`))}sizeWithMaxWidth(t,e){w(e.element,"border-left-width","0px");let n=this.getPropAsNumber(t,"max-width");if(this.isRightDependentOnAutoWidth)e.setHorizontalPosition(0,n);else{this.assignRightPosition(t,e),n-=e.snapOffsetX,e.width=n;let s=this.getPropAsNumber(t,"right");w(e.element,"right",`${s}px`),w(e.element,"width",`${n}px`)}}prepareContainer(t,e,n,s,o){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&w(e.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&w(e.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(t,e):this.sizeWithMaxHeight(t,e):(this.assignBeforePosition(t,e),this.assignAfterPosition(t,e)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(t,e):this.sizeWithMaxWidth(t,e):this.assignStartEndPosition(t,e);for(let i=0;i<pg.length;i++)this.propagateProperty(t,e,pg[i],s)}transferContentProps(t,e,n,s){for(let o=0;o<fg.length;o++)this.propagateProperty(t,e,fg[o],s);if(this.style["text-overflow"]){let o=e.element.firstElementChild;w(o,"text-overflow","inherit"),w(o,"overflow","inherit")}}transferSingleUriContentProps(t,e,n){let s=()=>{var a,l;let i=(l=(a=this.cascaded.width)!=null?a:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:l.value;return!!i&&i!==b.auto&&!U(i)},o=()=>{var a,l;let i=(l=(a=this.cascaded.height)!=null?a:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:l.value;return!!i&&i!==b.auto&&!U(i)};for(let i=0;i<gg.length;i++){let a=gg[i];if(a==="width"||a==="height"){if(a==="width"&&!s()||a==="height"&&!o())continue;w(e,a,"100%");continue}this.propagatePropertyToElement(t,e,a,n)}}finishContainer(t,e,n,s,o,i,a){this.vertical?this.calculatedWidth=e.computedBlockSize+e.snapOffsetX:this.calculatedHeight=e.computedBlockSize+e.snapOffsetY;let l=(this.vertical||!s)&&this.isAutoHeight,c=(!this.vertical||!s)&&this.isAutoWidth,u=null;if(c||l){c&&w(e.element,"width","auto"),l&&w(e.element,"height","auto");let d=s&&Kc(s);d&&Yc(s),u=i.getElementClientRect(s?s.element:e.element),d&&pi(s),c&&(this.calculatedWidth=Math.ceil(u.right-u.left-e.paddingLeft-e.borderLeft-e.paddingRight-e.borderRight),this.vertical&&(this.calculatedWidth+=e.snapOffsetX)),l&&(this.calculatedHeight=u.bottom-u.top-e.paddingTop-e.borderTop-e.paddingBottom-e.borderBottom,this.vertical||(this.calculatedHeight+=e.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(t,e),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(t,e),this.assignAfterPosition(t,e)),o>1){let d=this.getPropAsNumber(t,"column-rule-width"),h=this.getProp(t,"column-rule-style"),f=this.getProp(t,"column-rule-color");if(d>0&&h&&h!=b.none&&f!=b.transparent){let g=this.getPropAsNumber(t,"column-gap"),m=this.vertical?e.height:e.width,x=this.vertical?"border-top":"border-left";for(let E=1;E<o;E++){let C=this.vertical?(m+g)*E/o-g/2+e.paddingTop-d/2:(m+g)*E/o-g/2+e.paddingLeft-d/2,y=this.vertical?e.width+e.paddingLeft+e.paddingRight:e.height+e.paddingTop+e.paddingBottom,N=e.element.ownerDocument.createElement("div");w(N,"position","absolute"),w(N,this.vertical?"left":"top","0px"),w(N,this.vertical?"top":"left",`${C}px`),w(N,this.vertical?"height":"width","0px"),w(N,this.vertical?"width":"height",`${y}px`),w(N,x,`${d}px ${h.toString()}${f?` ${f.toString()}`:""}`),e.element.insertBefore(N,e.element.firstChild)}}}for(let d=0;d<hg.length;d++)this.propagateProperty(t,e,hg[d],a);for(let d=0;d<mg.length;d++)this.propagateDelayedProperty(t,e,mg[d],n.delayedItems)}applyCascadeAndInit(t,e){let n=this.cascaded,s=this.pageBox.specified;for(let i in s)this instanceof pn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(i==="writing-mode"||i==="direction")||Rs(i)&&vn(n,i,pe(s,i));if(this.pageBox.pseudoName==Ui)for(let i in e)(i.match(/^background-/)||i=="writing-mode")&&(n[i]=e[i]);if(this.pageBox.pseudoName=="layout-host")for(let i in e)!i.match(/^background-/)&&i!="writing-mode"&&(n[i]=e[i]);t.pushRule(this.pageBox.classes,null,n);let o=n.content;o&&(n.content=o.filterValue(new To(t,null,t.counterResolver))),this.init(t.context);for(let i of this.pageBox.children)i.createInstance(this).applyCascadeAndInit(t,e);t.popRule()}resolveAutoSizing(t){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,t)||this.depends("margin-right",this.autoWidth,t)||this.depends("border-right-width",this.autoWidth,t)||this.depends("padding-right",this.autoWidth,t)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,t)||this.depends("margin-top",this.autoHeight,t)||this.depends("border-top-width",this.autoHeight,t)||this.depends("padding-top",this.autoHeight,t));for(let e of this.children)e.resolveAutoSizing(t)}},pg=["border-left-style","border-right-style","border-top-style","border-bottom-style","border-left-color","border-right-color","border-top-color","border-bottom-color","box-sizing","outline-style","outline-color","outline-width","overflow","visibility"],hg=["border-top-left-radius","border-top-right-radius","border-bottom-right-radius","border-bottom-left-radius","border-start-start-radius","border-start-end-radius","border-end-start-radius","border-end-end-radius","border-image-source","border-image-slice","border-image-width","border-image-outset","border-image-repeat","background-attachment","background-color","background-image","background-repeat","background-position","background-clip","background-origin","background-size","box-shadow","opacity","z-index","background-blend-mode","isolation","mix-blend-mode","filter"],fg=["color","font-family","font-size","font-style","font-weight","line-height","letter-spacing","text-align","text-align-last","text-decoration","text-indent","text-transform","white-space","text-wrap","text-wrap-mode","text-wrap-style","word-spacing","font-feature-settings","font-kerning","font-size-adjust","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian","font-stretch","text-combine-upright","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-fill-color","text-orientation","text-shadow","text-stroke-color","text-stroke-width","text-underline-offset","text-underline-position","text-overflow"],gg=["width","height","image-resolution","object-fit","object-position"],mg=["transform","transform-origin"],Ui="background-host",Xa=class extends Fo{constructor(t){super(null,t)}applyCascadeAndInit(t,e){super.applyCascadeAndInit(t,e),this.children.sort((s,o)=>o.pageBox.specificity-s.pageBox.specificity||s.pageBox.index-o.pageBox.index)}},zs=class extends Fo{constructor(t,e){super(t,e),this.pageMasterInstance=this}boxSpecificEnabled(t){let e=this.pageBox.pageMaster;return e.condition&&(t=Qe(e.scope,t,e.condition)),t}adjustPageLayout(t,e,n){}},qd=class extends Fo{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}},dn=class extends Fo{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}processPartitionList(t,e,n){let s=null;if(e instanceof Ce&&(s=[e]),e instanceof fe&&(s=e.values),s){let o=this.pageBox.scope;for(let i=0;i<s.length;i++)if(s[i]instanceof Ce){let a=Yo(s[i].name,"enabled"),l=new J(o,a);n&&(l=new bt(o,l)),t=Qe(o,t,l)}}return t}boxSpecificEnabled(t){let e=this.pageBox.scope,n=this.style,s=Cg(e,n.required,e._false)!==e._false;if(s||this.isAutoHeight){let o=cb(e,n["flow-from"],"body"),i=new gn(e,"has-content",[o]);t=Qe(e,t,i)}if(t=this.processPartitionList(t,n["required-partitions"],!1),t=this.processPartitionList(t,n["conflicting-partitions"],!0),s){let o=this.pageMasterInstance.style.enabled,i=o?o.toExpr(e,null):e._true;i=Qe(e,i,t),this.pageMasterInstance.style.enabled=new B(i)}return t}prepareContainer(t,e,n,s,o){var i;this.pageBox.pageMaster instanceof Hi||(w(e.element,"overflow","hidden"),e.element.setAttribute("data-vivliostyle-page-partition",(i=this.pageBox.name)!=null?i:"")),super.prepareContainer(t,e,n,s,o)}},_i=class extends sn{constructor(e,n,s,o){super(e,n,!1);this.target=s;this.validatorSet=o}property(e,n,s){this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}unknownProperty(e,n){this.report(`E_INVALID_PROPERTY ${e}: ${n.toString()}`)}invalidPropertyValue(e,n){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${n.toString()}`)}simpleProperty(e,n,s){this.target.specified[e]=new H(n,s?zr:Gr)}},ja=class extends _i{constructor(t,e,n,s){super(t,e,n,s)}},Zd=class r extends _i{constructor(t,e,n,s){super(t,e,n,s),n.specified.width=new H($l,0),n.specified.height=new H($l,0)}startPartitionRule(t,e,n){let s=new ns(this.scope,t,e,n,this.target),o=new ja(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,e,n){let s=new $a(this.scope,t,e,n,this.target),o=new r(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}},Ya=class extends _i{constructor(t,e,n,s){super(t,e,n,s)}startPartitionRule(t,e,n){let s=new ns(this.scope,t,e,n,this.target),o=new ja(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,e,n){let s=new $a(this.scope,t,e,n,this.target),o=new Zd(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}};function mp(r){var n,s;let t=(n=r["writing-mode"])==null?void 0:n.value,e=(s=r.direction)==null?void 0:s.value;return t===b.vertical_lr||t!==b.vertical_rl&&e!==b.rtl?"ltr":"rtl"}var db={a10:{width:new P(26,"mm"),height:new P(37,"mm")},a9:{width:new P(37,"mm"),height:new P(52,"mm")},a8:{width:new P(52,"mm"),height:new P(74,"mm")},a7:{width:new P(74,"mm"),height:new P(105,"mm")},a6:{width:new P(105,"mm"),height:new P(148,"mm")},a5:{width:new P(148,"mm"),height:new P(210,"mm")},a4:{width:new P(210,"mm"),height:new P(297,"mm")},a3:{width:new P(297,"mm"),height:new P(420,"mm")},a2:{width:new P(420,"mm"),height:new P(594,"mm")},a1:{width:new P(594,"mm"),height:new P(841,"mm")},a0:{width:new P(841,"mm"),height:new P(1189,"mm")},b10:{width:new P(31,"mm"),height:new P(44,"mm")},b9:{width:new P(44,"mm"),height:new P(62,"mm")},b8:{width:new P(62,"mm"),height:new P(88,"mm")},b7:{width:new P(88,"mm"),height:new P(125,"mm")},b6:{width:new P(125,"mm"),height:new P(176,"mm")},b5:{width:new P(176,"mm"),height:new P(250,"mm")},b4:{width:new P(250,"mm"),height:new P(353,"mm")},b3:{width:new P(353,"mm"),height:new P(500,"mm")},b2:{width:new P(500,"mm"),height:new P(707,"mm")},b1:{width:new P(707,"mm"),height:new P(1e3,"mm")},b0:{width:new P(1e3,"mm"),height:new P(1414,"mm")},c10:{width:new P(28,"mm"),height:new P(40,"mm")},c9:{width:new P(40,"mm"),height:new P(57,"mm")},c8:{width:new P(57,"mm"),height:new P(81,"mm")},c7:{width:new P(81,"mm"),height:new P(114,"mm")},c6:{width:new P(114,"mm"),height:new P(162,"mm")},c5:{width:new P(162,"mm"),height:new P(229,"mm")},c4:{width:new P(229,"mm"),height:new P(324,"mm")},c3:{width:new P(324,"mm"),height:new P(458,"mm")},c2:{width:new P(458,"mm"),height:new P(648,"mm")},c1:{width:new P(648,"mm"),height:new P(917,"mm")},c0:{width:new P(917,"mm"),height:new P(1297,"mm")},"jis-b10":{width:new P(32,"mm"),height:new P(45,"mm")},"jis-b9":{width:new P(45,"mm"),height:new P(64,"mm")},"jis-b8":{width:new P(64,"mm"),height:new P(91,"mm")},"jis-b7":{width:new P(91,"mm"),height:new P(128,"mm")},"jis-b6":{width:new P(128,"mm"),height:new P(182,"mm")},"jis-b5":{width:new P(182,"mm"),height:new P(257,"mm")},"jis-b4":{width:new P(257,"mm"),height:new P(364,"mm")},"jis-b3":{width:new P(364,"mm"),height:new P(515,"mm")},"jis-b2":{width:new P(515,"mm"),height:new P(728,"mm")},"jis-b1":{width:new P(728,"mm"),height:new P(1030,"mm")},"jis-b0":{width:new P(1030,"mm"),height:new P(1456,"mm")},letter:{width:new P(8.5,"in"),height:new P(11,"in")},legal:{width:new P(8.5,"in"),height:new P(14,"in")},ledger:{width:new P(11,"in"),height:new P(17,"in")}},pb=new P(.24,"pt"),my=new P(3,"mm"),hb=new P(10,"mm"),fb=new P(13,"mm");function ji(r){let t={width:Fn,height:Bn,bleed:ne,bleedOffset:ne,cropOffset:ne},e=r.size;if(!(!e||e.value===b.auto)){let c=e.value,u,d;if(c.isSpaceList()?(u=c.values[0],d=c.values[1]):(u=c,d=null),u.isNumeric())t.width=u,t.height=d||u;else{let h=u.name&&db[u.name.toLowerCase()];h&&(d&&d===b.landscape?(t.width=h.height,t.height=h.width):(t.width=h.width,t.height=h.height))}}let n=r.marks,s=r.bleed,o=n&&!U(n.value)?n.value:b.none,i=s&&!U(s.value)?s.value:b.auto;if(i===b.auto){if(o!==b.none){let c=!1;o.isSpaceList()?c=o.values.some(u=>u===b.crop):c=o===b.crop,c&&(t.bleed=new P(6,"pt"))}}else i.isNumeric()&&(t.bleed=i);let a=r["crop-offset"],l=a&&!U(a.value)?a.value:b.auto;return l===b.auto?o!==b.none&&(t.bleedOffset=fb):l.isNumeric()&&(t.cropOffset=l),t}function Cp(r,t){let e={},n=Math.max(0,r.bleed.num)*t.queryUnitSize(r.bleed.unit,!1),s=!r.cropOffset.num&&r.bleedOffset.num?r.bleedOffset.num*t.queryUnitSize(r.bleedOffset.unit,!1):Math.max(0,r.cropOffset.num*t.queryUnitSize(r.cropOffset.unit,!1)-n),o=n+s,i=r.width;i===Fn?t.pref.defaultPaperSize?e.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):e.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-o*2:e.pageWidth=i.num*t.queryUnitSize(i.unit,!1);let a=r.height;return a===Bn?t.pref.defaultPaperSize?e.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):e.pageHeight=t.viewportHeight-o*2:e.pageHeight=a.num*t.queryUnitSize(a.unit,!1),e.bleed=n,e.bleedOffset=s,e.cropOffset=o,e}function xg(r,t,e){let n=r.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("width",t),n.setAttribute("height",e),n.style.position="absolute",n}function zi(r,t,e,n){n=n||"polyline";let s=r.createElementNS("http://www.w3.org/2000/svg",n);return s.setAttribute("stroke",e===b.auto?"#010101":e.toString()),s.setAttribute("stroke-width",t),s.setAttribute("fill","none"),s}var Jd=(s=>(s.TOP_LEFT="top left",s.TOP_RIGHT="top right",s.BOTTOM_LEFT="bottom left",s.BOTTOM_RIGHT="bottom right",s))(Jd||{});function gb(r,t,e,n,s,o,i){let a=s;a<=o+2*K.mm&&(a=o+s/2);let l=Math.max(s,a),c=o+l+e/2,u=xg(r,c,c),d=[[0,o+s],[s,o+s],[s,o+s-a]],h=d.map(m=>[m[1],m[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(m=>[o+l-m[0],m[1]]),h=h.map(m=>[o+l-m[0],m[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(m=>[m[0],o+l-m[1]]),h=h.map(m=>[m[0],o+l-m[1]]));let f=zi(r,e,n);f.setAttribute("points",d.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=zi(r,e,n);return g.setAttribute("points",h.map(m=>m.join(",")).join(" ")),u.appendChild(g),t.split(" ").forEach(m=>{u.style[m]=`${i}px`}),u}var Gi=(s=>(s.TOP="top",s.BOTTOM="bottom",s.LEFT="left",s.RIGHT="right",s))(Gi||{});function mb(r,t,e,n,s,o){let i=s*2,a,l;t==="top"||t==="bottom"?(a=i,l=s):(a=s,l=i);let c=xg(r,a,l),u=zi(r,e,n);u.setAttribute("points",`0,${l/2} ${a},${l/2}`),c.appendChild(u);let d=zi(r,e,n);d.setAttribute("points",`${a/2},0 ${a/2},${l}`),c.appendChild(d);let h=zi(r,e,n,"circle");h.setAttribute("cx",a/2),h.setAttribute("cy",l/2),h.setAttribute("r",s/4),c.appendChild(h);let f;switch(t){case"top":f="bottom";break;case"bottom":f="top";break;case"left":f="right";break;case"right":f="left";break}return Object.keys(Gi).forEach(g=>{let m=Gi[g];m===t?c.style[m]=`${o}px`:m!==f&&(c.style[m]="0",c.style[`margin-${m}`]="auto")}),c}function yg(r,t,e,n){let s=!1,o=!1,i=r.marks;if(i){let m=i.value;m instanceof j?m.values.forEach(x=>{x===b.crop?s=!0:x===b.cross&&(o=!0)}):m===b.crop?s=!0:m===b.cross&&(o=!0)}let a=t.bleed;if(!s&&!o)return;let l=e.container,c=l.ownerDocument;let u=Pe(pb,n),d=Math.max(0,t.bleedOffset-Pe(hb,n)),h=t.bleedOffset-d,f=r["crop-marks-line-color"],g=f&&!U(f.value)?f.value:b.auto;s&&Object.keys(Jd).forEach(m=>{let x=Jd[m],E=gb(c,x,u,g,h,a,d);l.appendChild(E)}),o&&Object.keys(Gi).forEach(m=>{let x=Gi[m],E=mb(c,x,u,g,h,d);l.appendChild(E)})}var ep=(()=>{let r=["left","right","top","bottom","before","after","start","end","block-start","block-end","inline-start","inline-end","inside","outside"],t={width:!0,height:!0,"block-size":!0,"inline-size":!0,margin:!0,padding:!0,border:!0,outline:!0,"outline-width":!0,"outline-style":!0,"outline-color":!0,"border-radius":!0,"border-top-left-radius":!0,"border-top-right-radius":!0,"border-bottom-right-radius":!0,"border-bottom-left-radius":!0,"border-start-start-radius":!0,"border-start-end-radius":!0,"border-end-start-radius":!0,"border-end-end-radius":!0,"box-shadow":!0,"box-sizing":!0};return r.forEach(e=>{t[`margin-${e}`]=!0,t[`padding-${e}`]=!0,t[`border-${e}-width`]=!0,t[`border-${e}-style`]=!0,t[`border-${e}-color`]=!0}),t})();var bp={"top-left-corner":{order:1,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:null},"top-left":{order:2,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"start"},"top-center":{order:3,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"center"},"top-right":{order:4,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"end"},"top-right-corner":{order:5,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:null},"right-top":{order:6,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:"start"},"right-middle":{order:7,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:"center"},"right-bottom":{order:8,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:"end"},"bottom-right-corner":{order:9,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:null},"bottom-right":{order:10,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"end"},"bottom-center":{order:11,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"center"},"bottom-left":{order:12,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"start"},"bottom-left-corner":{order:13,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:null},"left-bottom":{order:14,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:"end"},"left-middle":{order:15,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:"center"},"left-top":{order:16,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:"start"}},Cb=(()=>{let r=bp;return Object.keys(r).sort((t,e)=>r[t].order-r[e].order)})(),Qa="vivliostyle-page-rule-master",Wi="_marginBoxes",Hi=class extends Vo{constructor(e,n,s){super(e,null,Qa,[],n,null,0);p(this,"pageMarginBoxes",{});let o=ji(s),i=new tp(this.scope,this,s,o);this.createPageMarginBoxes(s),this.applySpecified(s,o)}createPageMarginBoxes(e){let n=e[Wi];n&&Cb.forEach(s=>{n[s]&&(this.pageMarginBoxes[s]=new sp(this.scope,this,s,e))})}applySpecified(e,n){this.specified.position=new H(b.relative,0),this.specified.width=new H(n.width,0),this.specified.height=new H(n.height,0);for(let s in e)!ep[s]&&s!=="background-clip"&&(this.specified[s]=e[s])}createInstance(e){return new pn(e,this)}},tp=class extends ns{constructor(e,n,s,o){super(e,null,null,[],n);this.pageSize=o;let i=new np(this.scope,this);this.applySpecified(s)}applySpecified(e){this.specified["wrap-flow"]=new H(b.auto,0),this.specified["z-index"]=new H(new ct(0),0),this.specified.position=new H(b.absolute,0),this.specified.overflow=new H(b.visible,0);for(let n in ep)ep.hasOwnProperty(n)&&(this.specified[n]=e[n])}createInstance(e){return new ip(e,this)}},np=class extends ns{constructor(t,e){super(t,null,null,[],e),this.specified["flow-from"]=new H(L("body"),0)}createInstance(t){return new $i(t,this)}},sp=class extends ns{constructor(e,n,s,o){super(e,null,null,[],n);this.marginBoxName=s;this.applySpecified(o)}applySpecified(e){let n=e[Wi][this.marginBoxName];for(let s in e){let o=e[s],i=n[s];(Wu[s]||i&&i.value===b.inherit)&&(this.specified[s]=o)}for(let s in n)if(Object.prototype.hasOwnProperty.call(n,s)){let o=n[s];o&&o.value!==D&&o.value!==b.inherit&&o.value!==b.unset&&o.value!==b.revert&&(this.specified[s]=o)}}createInstance(e){return new Xi(e,this)}},pn=class extends zs{constructor(e,n){super(e,n);p(this,"pageAreaDimension",null);p(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,n){let s=this.cascaded;for(let o in n)if(Object.prototype.hasOwnProperty.call(n,o))switch(o){case"writing-mode":case"direction":s[o]=n[o]}super.applyCascadeAndInit(e,n)}initHorizontal(){let e=this.style;e.left=ne,e["margin-left"]=ne,e["border-left-width"]=ne,e["padding-left"]=ne,e["padding-right"]=ne,e["border-right-width"]=ne,e["margin-right"]=ne,e.right=ne}initVertical(){let e=this.style;e.top=ne,e["margin-top"]=ne,e["border-top-width"]=ne,e["padding-top"]=ne,e["padding-bottom"]=ne,e["border-bottom-width"]=ne,e["margin-bottom"]=ne,e.bottom=ne}setPageAreaDimension(e){this.pageAreaDimension=e;let n=this.style;n.width=new B(e.borderBoxWidth),n.height=new B(e.borderBoxHeight),n["padding-left"]=new B(e.marginLeft),n["padding-right"]=new B(e.marginRight),n["padding-top"]=new B(e.marginTop),n["padding-bottom"]=new B(e.marginBottom)}adjustPageLayout(e,n,s){let o=n.marginBoxes,i={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},a={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(o.top,!0,i,e,s),this.sizeMarginBoxesAlongVariableDimension(o.bottom,!0,i,e,s),this.sizeMarginBoxesAlongVariableDimension(o.left,!1,a,e,s),this.sizeMarginBoxesAlongVariableDimension(o.right,!1,a,e,s)}sizeMarginBoxesAlongVariableDimension(e,n,s,o,i){let a="start",l="center",c="end",u=this.pageBox.scope,d={},h={},f={};for(let S in e){let v=bp[S];if(v){let k=e[S],R=this.pageMarginBoxInstances[S],z=new Bo(k,R.style,n,u,i);d[v.positionAlongVariableDimension]=k,h[v.positionAlongVariableDimension]=R,f[v.positionAlongVariableDimension]=z}}let g={start:s.start.evaluate(o),end:s.end.evaluate(o),extent:s.extent.evaluate(o)},m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),x=!1,E={};Object.keys(d).forEach(S=>{let v=S,k=ee(u,h[v].style[n?"max-width":"max-height"],s.extent);if(k){let R=k.evaluate(o);if(m[v]>R){let z=f[v]=new Ka(d[v],h[v].style,n,u,i,R);E[v]=z.getOuterSize(),x=!0}}}),x&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),x=!1,[a,l,c].forEach(S=>{var v;m[S]=(v=E[S])!=null?v:m[S]}));let C={};Object.keys(d).forEach(S=>{let v=S,k=ee(u,h[v].style[n?"min-width":"min-height"],s.extent);if(k){let R=k.evaluate(o);if(m[v]<R){let z=f[v]=new Ka(d[v],h[v].style,n,u,i,R);C[v]=z.getOuterSize(),x=!0}}}),x&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),[a,l,c].forEach(S=>{m[S]=C[S]||m[S]}));let y=g.start+g.extent,N=g.start+(g.start+g.extent);[a,l,c].forEach(S=>{let v=m[S];if(v!=null){let k=d[S],R=0;switch(S){case a:R=n?k.left:k.top;break;case l:R=(N-v)/2;break;case c:R=y-v;break}n?k.setHorizontalPosition(R,v-k.getInsetLeft()-k.getInsetRight()):k.setVerticalPosition(R,v-k.getInsetTop()-k.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,n){var l;let s=e.start,o=e.center,i=e.end,a={};if(o){let c=[s,i],u=new op(c),d=this.distributeAutoMarginBoxSizes(o,u,n);d.xSize!=null&&(a.center=d.xSize);let h=(l=d.xSize)!=null?l:o.getOuterSize(),f=Math.max((n-h)/2,0);s&&(a.start=s.hasAutoSize()?f:s.getOuterSize()),i&&(a.end=i.hasAutoSize()?f:i.getOuterSize())}else{let c=this.distributeAutoMarginBoxSizes(s,i,n);c.xSize!=null&&(a.start=c.xSize),c.ySize!=null&&(a.end=c.ySize)}return a}distributeAutoMarginBoxSizes(e,n,s){let o={xSize:null,ySize:null};if(e instanceof Bo&&e.minMaxFitContent&&(o.xSize=e.getOuterSize()),n instanceof Bo&&n.minMaxFitContent&&(o.ySize=n.getOuterSize()),e&&n)if(e.hasAutoSize()&&n.hasAutoSize()){let i=e.getOuterMaxContentSize(),a=n.getOuterMaxContentSize();if(i>0&&a>0){let l=i+a;if(l<s)o.xSize=s*i/l;else{let c=e.getOuterMinContentSize(),u=n.getOuterMinContentSize(),d=c+u;d<s?o.xSize=c+(s-d)*(i-c)/(l-d):d>0&&(o.xSize=s*c/d)}o.xSize>0&&(o.ySize=s-o.xSize)}else i>0?o.xSize=s:a>0&&(o.ySize=s)}else e.hasAutoSize()?o.xSize=Math.max(s-n.getOuterSize(),0):n.hasAutoSize()&&(o.ySize=Math.max(s-e.getOuterSize(),0));else e?e.hasAutoSize()&&(o.xSize=s):n&&n.hasAutoSize()&&(o.ySize=s);return o}prepareContainer(e,n,s,o,i){n.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,n,s,o,i)}},Bo=class{constructor(t,e,n,s,o){this.container=t;this.isHorizontal=n;this.clientLayout=o;p(this,"hasAutoSize_");p(this,"size",null);p(this,"minMaxFitContent",null);let i=e[n?"width":"height"];if(this.hasAutoSize_=!i||i===b.auto||U(i),this.minMaxFitContent=i instanceof Ce&&(i.name==="min-content"||i.name==="max-content"||i.name==="fit-content")?i.name:null,this.minMaxFitContent){let a=this.getSize();if(this.isHorizontal){let l=a[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,l)}else{let l=a[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,l)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let t=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=ho(this.clientLayout,this.container.element,t)}return this.size}getOuterMaxContentSize(){let t=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+t["max-content width"]+this.container.getInsetRight():this.container.getInsetTop()+t["max-content height"]+this.container.getInsetBottom()}getOuterMinContentSize(){let t=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+t["min-content width"]+this.container.getInsetRight():this.container.getInsetTop()+t["min-content height"]+this.container.getInsetBottom()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.container.width+this.container.getInsetRight():this.container.getInsetTop()+this.container.height+this.container.getInsetBottom()}},op=class{constructor(t){this.params=t}hasAutoSize(){return this.params.some(t=>{var e;return(e=t==null?void 0:t.hasAutoSize())!=null?e:!1})}getOuterMaxContentSize(){let t=this.params.map(e=>{var n;return(n=e==null?void 0:e.getOuterMaxContentSize())!=null?n:0});return Math.max.apply(null,t)*t.length}getOuterMinContentSize(){let t=this.params.map(e=>{var n;return(n=e==null?void 0:e.getOuterMinContentSize())!=null?n:0});return Math.max.apply(null,t)*t.length}getOuterSize(){let t=this.params.map(e=>{var n;return(n=e==null?void 0:e.getOuterSize())!=null?n:0});return Math.max.apply(null,t)*t.length}},Ka=class extends Bo{constructor(e,n,s,o,i,a){super(e,n,s,o,i);p(this,"fixedSize");this.fixedSize=a}hasAutoSize(){return!1}getOuterMaxContentSize(){return this.getOuterSize()}getOuterMinContentSize(){return this.getOuterSize()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.fixedSize+this.container.getInsetRight():this.container.getInsetTop()+this.fixedSize+this.container.getInsetBottom()}},ip=class extends dn{constructor(e,n){super(e,n);p(this,"borderBoxWidth",null);p(this,"borderBoxHeight",null);p(this,"contentBoxWidth",null);p(this,"contentBoxHeight",null);p(this,"marginTop",null);p(this,"marginRight",null);p(this,"marginBottom",null);p(this,"marginLeft",null)}applyCascadeAndInit(e,n){for(let o in n)o.match(/^background-/)&&(this.cascaded[o]=n[o]);super.applyCascadeAndInit(e,n),this.parentInstance.setPageAreaDimension({borderBoxWidth:this.borderBoxWidth,borderBoxHeight:this.borderBoxHeight,marginTop:this.marginTop,marginRight:this.marginRight,marginBottom:this.marginBottom,marginLeft:this.marginLeft})}initHorizontal(){let e=this.resolvePageBoxDimensions({start:"left",end:"right",extent:"width"});this.borderBoxWidth=e.borderBoxExtent,this.contentBoxWidth=e.contentBoxExtent,this.marginLeft=e.marginStart,this.marginRight=e.marginEnd}initVertical(){let e=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.borderBoxHeight=e.borderBoxExtent,this.contentBoxHeight=e.contentBoxExtent,this.marginTop=e.marginStart,this.marginBottom=e.marginEnd}resolvePageBoxDimensions(e){let n=this.style,s=this.pageBox.pageSize,o=this.pageBox.scope,i=e.start,a=e.end,l=e.extent,c=s[l].toExpr(o,null),u=ee(o,n[l],c),d=ee(o,n[`margin-${i}`],c),h=ee(o,n[`margin-${a}`],c),f=nt(o,n[`padding-${i}`],c),g=nt(o,n[`padding-${a}`],c),m=$t(o,n[`border-${i}-width`],n[`border-${i}-style`],c),x=$t(o,n[`border-${a}-width`],n[`border-${a}-style`],c),E=G(o,G(o,m,f),G(o,x,g)),C,y,N;return u?(this.borderBoxSizing?(y=u,N=Y(o,y,E)):(N=u,y=G(o,N,E)),C=Y(o,c,y),!d&&!h?(d=eo(o,C,new ie(o,.5)),h=d):d?h=Y(o,C,d):d=Y(o,C,h)):(d||(d=o.zero),h||(h=o.zero),C=G(o,d,h),y=Y(o,c,C),N=Y(o,y,E),u=this.borderBoxSizing?y:N),n[i]=new B(d),n[a]=new B(h),n[`margin-${i}`]=ne,n[`margin-${a}`]=ne,n[`border-${i}-width`]=new B(m),n[`border-${a}-width`]=new B(x),n[`padding-${i}`]=new B(f),n[`padding-${a}`]=new B(g),n[l]=new B(u),n[`max-${l}`]=new B(u),{borderBoxExtent:y,contentBoxExtent:N,marginStart:d,marginEnd:h}}prepareContainer(e,n,s,o,i){n.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,n,s,o,i)}},$i=class extends dn{constructor(t,e){super(t,e)}applyCascadeAndInit(t,e){for(let n in e)n.match(/^column.*$/)&&(this.cascaded[n]=e[n]);super.applyCascadeAndInit(t,{})}initHorizontal(){let t=this.style,e=this.parentInstance.style,n=this.pageBox.scope;t.left=e["padding-left"],t.width=new B(this.parentInstance.contentBoxWidth),t["margin-left"]=new B(new Qt(n,e.left.toExpr(n,null))),t["margin-right"]=new B(new Qt(n,e.right.toExpr(n,null))),t["border-left-width"]=e.left,t["border-right-width"]=e.right,t["border-left-style"]=b.solid,t["border-right-style"]=b.solid,t["border-left-color"]=b.transparent,t["border-right-color"]=b.transparent}initVertical(){let t=this.style,e=this.parentInstance.style,n=this.pageBox.scope;t.top=e["padding-top"],t.height=new B(this.parentInstance.contentBoxHeight),t["margin-top"]=new B(new Qt(n,e.top.toExpr(n,null))),t["margin-bottom"]=new B(new Qt(n,e.bottom.toExpr(n,null))),t["border-top-width"]=e.top,t["border-bottom-width"]=e.bottom,t["border-top-style"]=b.solid,t["border-bottom-style"]=b.solid,t["border-top-color"]=b.transparent,t["border-bottom-color"]=b.transparent}prepareContainer(t,e,n,s,o){e.element.setAttribute("data-vivliostyle-page-area",!0),n.pageAreaElement=e.element,super.prepareContainer(t,e,n,s,o),t.pageAreaWidth=e.width,t.pageAreaHeight=e.height}},Xi=class extends dn{constructor(e,n){super(e,n);p(this,"boxInfo");p(this,"suppressEmptyBoxGeneration",!0);let s=n.marginBoxName;this.boxInfo=bp[s];let o=e;o.pageMarginBoxInstances[s]=this}prepareContainer(e,n,s,o,i){n.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,n.element),super.prepareContainer(e,n,s,o,i)}applyVerticalAlign(e,n){w(n,"display","flex"),w(n,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let s=this.getProp(e,"vertical-align"),o=null;s===L("middle")?o="center":s===L("top")?o="flex-start":s===L("bottom")&&(o="flex-end"),o&&w(n,"justify-content",o);let i=this.getProp(e,"content");if(this.vertical||i instanceof Fe||i instanceof B&&i.expr instanceof q&&i.expr.str.startsWith("running-element-")){let a="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?a=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(a=this.vertical||this.rtl?"end":"start")),w(n,"align-items",a)}}positionAlongVariableDimension(e,n){let s=this.style,o=this.pageBox.scope,i=e.start,a=e.end,l=e.extent,c=i==="left",u=c?n.borderBoxWidth:n.borderBoxHeight,d=ee(o,s[l],u),h=c?n.marginLeft:n.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")s[i]=new B(h);else if(d){let f=nt(o,s[`margin-${i}`],u),g=nt(o,s[`margin-${a}`],u),m=nt(o,s[`padding-${i}`],u),x=nt(o,s[`padding-${a}`],u),E=$t(o,s[`border-${i}-width`],s[`border-${i}-style`],u),C=$t(o,s[`border-${a}-width`],s[`border-${a}-style`],u),y=G(o,d,G(o,this.borderBoxSizing?o.zero:G(o,G(o,m,x),G(o,E,C)),G(o,f,g)));switch(this.boxInfo.positionAlongVariableDimension){case"center":s[i]=new B(G(o,h,Ko(o,Y(o,u,y),new ie(o,2))));break;case"end":s[i]=new B(Y(o,G(o,h,u),y));break}}}positionAndSizeAlongFixedDimension(e,n){let s=this.style,o=this.pageBox.scope,i=this.borderBoxSizing,a=e.inside,l=e.outside,c=e.extent,u=n[`margin${l.charAt(0).toUpperCase()}${l.substring(1)}`],d=Qd(o,s[`margin-${a}`],u),h=Qd(o,s[`margin-${l}`],u),f=nt(o,s[`padding-${a}`],u),g=nt(o,s[`padding-${l}`],u),m=$t(o,s[`border-${a}-width`],s[`border-${a}-style`],u),x=$t(o,s[`border-${l}-width`],s[`border-${l}-style`],u),E=ee(o,s[c],u),C=null;function y(N){if(C)return C;C={extent:E?E.evaluate(N):null,marginInside:d?d.evaluate(N):null,marginOutside:h?h.evaluate(N):null};let S=u.evaluate(N),v=0;return i||[m,f,g,x].forEach(k=>{k&&(v+=k.evaluate(N))}),(C.marginInside===null||C.marginOutside===null)&&v+C.extent+C.marginInside+C.marginOutside>S&&(C.marginInside===null&&(C.marginInside=0),C.marginOutside===null&&(C.marginOutside=0)),C.extent!==null&&C.marginInside!==null&&C.marginOutside!==null&&(C.marginOutside=null),C.extent===null?(C.extent=S-v-C.marginInside-C.marginOutside,C.marginInside===null&&(C.marginInside=0),C.marginOutside===null&&(C.marginOutside=0)):typeof C.extent=="number"&&(C.marginInside===null&&typeof C.marginOutside=="number"?C.marginInside=S-v-C.extent-C.marginOutside:typeof C.marginInside=="number"&&C.marginOutside===null?C.marginOutside=S-v-C.extent-C.marginInside:C.marginInside=C.marginOutside=(S-v-C.extent)/2),C}s[c]=new B(new q(o,function(){let N=y(this).extent;return N===null?"auto":N},c)),s[`margin-${a}`]=new B(new q(o,function(){let N=y(this).marginInside;return N===null?"auto":N},`margin-${a}`)),s[`margin-${l}`]=new B(new q(o,function(){let N=y(this).marginOutside;return N===null?"auto":N},`margin-${l}`)),a==="left"?s.left=new B(G(o,n.marginLeft,n.borderBoxWidth)):a==="top"&&(s.top=new B(G(o,n.marginTop,n.borderBoxHeight)))}initHorizontal(){let n=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},n):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},n):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},n)}initVertical(){let n=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},n):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},n):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},n)}finishContainer(e,n,s,o,i,a,l){super.finishContainer(e,n,s,o,i,a,l);let c=s.marginBoxes,u=this.pageBox.marginBoxName,d=this.boxInfo;!d.isInLeftColumn&&!d.isInRightColumn?d.isInTopRow?c.top[u]=n:d.isInBottomRow&&(c.bottom[u]=n):!d.isInTopRow&&!d.isInBottomRow&&(d.isInLeftColumn?c.left[u]=n:d.isInRightColumn&&(c.right[u]=n));let h=this.parentInstance.pageAreaDimension,f=this.getProp(e,"width"),g=f instanceof Ce&&(f.name==="min-content"||f.name==="max-content"||f.name==="fit-content")?f.name:null,m=this.getPropAsNumber(e,"min-width"),x=this.getPropAsNumber(e,"max-width");if(g||m||x){g&&w(n.element,"width",g),m&&w(n.element,"min-width",`${m}px`),x&&w(n.element,"max-width",`${x}px`);let S=this.getProp(e,"margin-left"),v=this.getProp(e,"margin-right");if(d.isInLeftColumn){let k=h.borderBoxWidth.evaluate(e)+h.marginRight.evaluate(e);w(n.element,"right",`${k}px`),(S===b.auto||v!==b.auto)&&w(n.element,"margin-left","auto"),v===b.auto&&w(n.element,"margin-right","auto")}else d.isInRightColumn&&(w(n.element,"right","0"),(v===b.auto||S!==b.auto)&&w(n.element,"margin-right","auto"),S===b.auto&&w(n.element,"margin-left","auto"))}let E=this.getProp(e,"height"),C=E instanceof Ce&&(E.name==="min-content"||E.name==="max-content"||E.name==="fit-content")?E.name:null,y=this.getPropAsNumber(e,"min-height"),N=this.getPropAsNumber(e,"max-height");if(C||y||N){C&&w(n.element,"height",C),y&&w(n.element,"min-height",`${y}px`),N&&w(n.element,"max-height",`${N}px`);let S=this.getProp(e,"margin-top"),v=this.getProp(e,"margin-bottom");if(d.isInTopRow){let k=h.borderBoxHeight.evaluate(e)+h.marginBottom.evaluate(e);w(n.element,"bottom",`${k}px`),(S===b.auto||v!==b.auto)&&w(n.element,"margin-top","auto"),v===b.auto&&w(n.element,"margin-bottom","auto")}else d.isInBottomRow&&(w(n.element,"bottom","0"),(v===b.auto||S!==b.auto)&&w(n.element,"margin-bottom","auto"),S===b.auto&&w(n.element,"margin-top","auto"))}}},qa=class{constructor(t,e,n,s,o){this.cascadeInstance=t;this.pageScope=e;this.rootPageBoxInstance=n;this.context=s;this.docElementStyle=o;p(this,"pageMasterCache",{});this.definePageProgression()}definePageProgression(){let t=this.pageScope,e=this.context,n=e.isVersoFirstPage,s=new J(t,"page-number"),o=new Vn(t,new Qs(t,s,new ie(t,2)),n?t.one:t.zero);t.defineName("recto-page",new bt(t,o)),t.defineName("verso-page",o),(e.pageProgression||mp(this.docElementStyle))==="ltr"?(t.defineName("left-page",o),t.defineName("right-page",new bt(t,o))):(t.defineName("left-page",new bt(t,o)),t.defineName("right-page",o))}getCascadedPageStyle(t){let e={};return this.cascadeInstance.pushRule([],t,e),this.cascadeInstance.popRule(),e}getPageRulePageMaster(t,e){let n=t.pageBox;if(Object.keys(e).length===0)return n.resetScope(),t;let s=this.makeCacheKey(e,n),o=this.pageMasterCache[s];return o||(n.pseudoName===Ui?o=this.generatePageRuleMaster(e):o=this.generateCascadedPageMaster(e,n),this.pageMasterCache[s]=o),o.pageBox.resetScope(),o}makeCacheKey(t,e){var o;let n=this.makeCascadeValueObjectKey(t),s=((o=this.context.currentLayoutPosition)==null?void 0:o.page)%2;return`${e.key}^${n}^${s}`}makeCascadeValueObjectKey(t){let e=[];for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n)){let s=t[n],o;s instanceof H?o=`${s.value}`:o=this.makeCascadeValueObjectKey(s),e.push(n+o+(s.priority||""))}return e.sort().join("^")}generatePageRuleMaster(t){let n=new Hi(this.pageScope,this.rootPageBoxInstance.pageBox,t).createInstance(this.rootPageBoxInstance);return n.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),n.resolveAutoSizing(this.context),n}generateCascadedPageMaster(t,e){let n=e.clone({pseudoName:Qa}),s=n.specified,o=t.size;if(o&&!U(o.value)){let a=ji(t),l=o.priority;un(s,"width",new H(a.width,l),this.context),un(s,"height",new H(a.height,l),this.context)}["counter-reset","counter-increment"].forEach(a=>{s[a]&&(t[a]=s[a])});let i=n.createInstance(this.rootPageBoxInstance);return i.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),i.resolveAutoSizing(this.context),i}},rp=class extends Z{constructor(e){super();this.pageType=e}apply(e){e.currentPageType===this.pageType&&this.chained.apply(e)}getPriority(){return 3}makePrimary(e){return this.chained&&e.insertInTable(e.pagetypes,this.pageType,this.chained),!0}},ap=class extends Z{constructor(e){super();this.scope=e}apply(e){new J(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},lp=class extends Z{constructor(e){super();this.scope=e}apply(e){new J(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},cp=class extends Z{constructor(e){super();this.scope=e}apply(e){new J(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},up=class extends Z{constructor(e){super();this.scope=e}apply(e){new J(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},dp=class extends Z{constructor(e){super();this.scope=e}apply(e){new J(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},pp=class extends Z{constructor(e){super();this.scope=e}apply(e){new J(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},hp=class extends qn{constructor(e,n,s){super(n,s);this.scope=e;this.a=n;this.b=s}apply(e){let n=e.context,s=n.layoutPositionAtPageStart.page;n.blankPageAtStart&&s--,s&&this.matchANPlusB(s)&&this.chained.apply(e)}getPriority(){return 2}},fp=class extends Is{constructor(t,e){super(t,e,null,null,null)}apply(t){bb(t.context,t.currentStyle,this.style,this.specificity,t)}};function bb(r,t,e,n,s){Si(r,t,e,n,null,null,null);let o=e[Wi];if(o){let i=Po(t,Wi);for(let a in o)if(o.hasOwnProperty(a)){let l=i[a];l||(l={},i[a]=l),Si(r,l,o[a],n,null,null,null)}}}var Za=class extends wn{constructor(e,n,s,o,i){super(e,n,s==null?void 0:s.condition,s,null,o,!1);this.pageProps=i;p(this,"currentPageSelectors",[]);p(this,"currentNamedPageSelector","");p(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,n){this.currentNamedPageSelector=n,n&&(this.chain.push(new rp(n)),this.specificity+=65536)}pseudoclassSelector(e,n){if(e=e.toLowerCase(),n)switch(e){case"nth":{let[s,o]=n;this.currentPseudoPageClassSelectors.push(`:${e}(${s}n${o<0?o:"+"+o})`),this.chain.push(new hp(this.scope,s,o)),this.specificity+=256}break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}(${n.join("")})`);break}else switch(this.currentPseudoPageClassSelectors.push(`:${e}`),e){case"first":this.chain.push(new ap(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new lp(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new cp(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new up(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new dp(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new pp(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}`);break}}finishSelector(){let e;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?e=null:e=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:e,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(e,n,s){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(a=>a.selectors===null))return;super.simpleProperty(e,n,s);let o=pe(this.elementStyle,e),i=this.pageProps;if(e==="bleed"||e==="marks")i[""]||(i[""]={}),Object.keys(i).forEach(a=>{vn(i[a],e,o)});else if(e==="size"){let a=i[""];this.currentPageSelectors.forEach(l=>{let c=new H(o.value,o.priority+l.specificity),u=l.selectors?l.selectors.join(""):"",d=i[u];d?un(d,e,c):(d=i[u]={},vn(d,e,c),a&&["bleed","marks"].forEach(h=>{a[h]&&vn(d,h,a[h])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new fp(this.elementStyle,e)}startPageMarginBoxRule(e){let n=Po(this.elementStyle,Wi),s=n[e];s||(s={},n[e]=s);let o=new gp(this.scope,this.owner,this.validatorSet,s);this.owner.pushHandler(o)}},gp=class extends sn{constructor(e,n,s,o){super(e,n,!1);this.validatorSet=s;this.boxStyle=o}property(e,n,s){this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}invalidPropertyValue(e,n){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${n.toString()}`)}unknownProperty(e,n){this.report(`E_INVALID_PROPERTY ${e}: ${n.toString()}`)}simpleProperty(e,n,s){let o=s?this.getImportantSpecificity():this.getBaseSpecificity(),i=new H(n,o);vn(this.boxStyle,e,i)}};var Xt=!0;function Sg(r){Xt=r}var Gs=[];function Eg(r,t){return r===t||(r.src||t.src?r.src===t.src:r.textContent===t.textContent)}function Ng(r){let t=Array.from(r.querySelectorAll("body > :not(script):not(link):not(style) ~ script"));return Array.from(r.querySelectorAll("head > script, body > script")).filter(e=>!t.includes(e))}function Ja(r,t,e){var u,d;if(!Xt)return T(!1);if(!(e!=null&&e.inHead)&&!(e!=null&&e.atEnd)&&Ng(r.ownerDocument).includes(r))return T(!1);let n=r.textContent,s=r.src,o=r.type==="module",i=(o||s)&&r.async,a=o&&!i||s&&r.defer,l=!(e!=null&&e.atEnd)&&((e==null?void 0:e.forceDefer)||a||i);if(xp(t)||(t.onload=null),l)return Gs.some(h=>Eg(h,r))||Gs.push(r),T(!0);if(s.includes("/mathjax")){let h=t.document.head.querySelector("script[src*='MathJax.js']:not([data-vivliostyle-scripting])");if(h){if(s.includes("/mathjax@3"))t.document.head.removeChild(h),(d=(u=t.MathJax)==null?void 0:u.version)!=null&&d.startsWith("2.")&&delete t.MathJax;else if(s.includes("/MathJax.js"))return T(!0)}}for(let h of t.document.head.getElementsByTagName("script"))h.hasAttribute("data-vivliostyle-scripting")&&Eg(h,r)&&t.document.head.removeChild(h);let c=t.document.createElement("script");c.textContent=n,s&&(c.src=s),c.async=i,c.defer=a,c.setAttribute("data-vivliostyle-scripting","true");for(let h of r.attributes)["src","async","defer"].includes(h.name)||c.setAttribute(h.name,h.value);if(F.debug("script:",s),s){let h=Dn(c);return t.document.head.appendChild(c),On([h])}else return t.document.head.appendChild(c),T(!0)}function yb(r,t){var o;let e={},n=i=>{var c;let a=(c=i["font-family"])==null?void 0:c.value;if(a)if(a.values)for(let u of a.values)e[u.stringValue()]=!0;else e[a.stringValue()]=!0;let l=i._marginBoxes;if(l)for(let u of Object.values(l))n(u)},s=i=>{if(i instanceof Is)n(i.style);else if(i instanceof Tn||Array.isArray(i))for(let a of Object.values(i))s(a)};for(let i of Object.values(t.cascade.code))for(let a of Object.values(i!=null?i:{}))s(a);for(let i of r.querySelectorAll("[style]"))(o=i.style)!=null&&o.fontFamily&&(e[i.style.fontFamily]=!0);return Object.keys(e).join(",")}function Eb(r,t,e){var s;let n=(s=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?s:t.document.createElement("div");return n.style.position="fixed",n.style.fontSize="0",n.setAttribute("data-vivliostyle-textcontent","true"),n.setAttribute("aria-hidden","true"),n.style.fontFamily=yb(r,e),n.textContent=r.documentElement.textContent,t.document.body.appendChild(n),n}function vg(r,t,e){if(!Xt)return T(!1);let n=Ng(r);if(n.length===0)return T(!1);let s=n.some(u=>!(u.async||u.defer||u.type==="module")),o=s?Eb(r,t,e):null,i=t.document.fonts,a=t.$,l=!1,c=A("loadScripts");return c.loop(()=>{if(n.length===0)return s?c.sleep(20).thenAsync(()=>{var d,h;return i.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(d=t.FontJSON)!=null&&d.Font&&((h=t.ret)!=null&&h.readyState)&&t.ret.readyState<4?T(!0):T(!1)}):T(!1);let u=n.shift();return Ja(u,t,{inHead:!0,forceDefer:l}).thenAsync(()=>(!l&&t.$!==a&&(Gs.push(u),l=!0),n.length===0&&s&&(F.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),T(!0)))}).then(()=>{o&&o.remove(),c.finish(!0)}),c.result()}function Tg(r){if(!Xt)return T(!1);let t=A("loadScripts");return t.loop(()=>Gs.length===0?T(!1):Ja(Gs.shift(),r,{atEnd:!0}).thenReturn(Gs.length>0)).then(()=>{F.debug("dispatchEvent: DOMContentLoaded (window)"),r.dispatchEvent(new Event("DOMContentLoaded")),F.debug("dispatchEvent: load (window)"),r.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function xp(r){return Xt?Gs.length>0||!!r.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var wg=(r,t,e)=>r.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,s)=>`url("${e.transformURL(s,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,s)=>`url('${e.transformURL(s,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,s)=>`url(${e.transformURL(s,t)}`);var Nb={};function vb(r){r.addEventListener("load",()=>{r.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(t,e){switch(t){case"mouse-events":return!0}return!1}}},!1)}var Yi=class Yi extends Ln{constructor(e,n,s,o,i,a,l,c,u,d,h,f,g){super();this.flowName=e;this.context=n;this.viewport=s;this.styler=o;this.regionIds=i;this.xmldoc=a;this.docFaces=l;this.footnoteStyle=c;this.stylerProducer=u;this.page=d;this.customRenderer=h;this.fallbackMap=f;this.documentURLTransformer=g;p(this,"document");p(this,"exprContentListener");p(this,"nodeContext",null);p(this,"viewRoot",null);p(this,"isFootnote",!1);p(this,"sourceNode",null);p(this,"offsetInNode",0);p(this,"viewNode",null);this.document=s.document,this.exprContentListener=o.counterListener.getExprContentListener()}clone(){return new Yi(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer)}createPseudoelementShadow(e,n,s,o,i,a,l,c){let u=this.getPseudoMap(s,this.regionIds,this.isFootnote,this.nodeContext,a);if(!u)return c;let d=[],h=Ao.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=h;for(let m of Uf){let x;if(m){if(!u[m]||m=="footnote-marker"&&!(n&&this.isFootnote))continue;if(m.match(/^first-/)){let E=o.display;if(!E||E===b.inline)continue;let C=e.firstElementChild;if(C&&de(C.previousSibling)){let y=i.getStyle(C,!1);if(y){let N=pe(y,"display");if(N!=null&&N.value&&N.value!==b.inline)continue}}}if(m==="before"||m==="after"){let E=u[m].content;if(!E||!vt(E.value))continue}d.push(m),x=Ao.createElementNS("http://www.w3.org/1999/xhtml","span"),Ti(x,m)}else x=Ao.createElementNS("http://www.pyroxy.com/ns/shadow","content");f.appendChild(x),m.match(/^first-/)&&(f=x)}if(!d.length)return c;let g=new vi(e,s,i,a,this.exprContentListener);return new vs(e,h,null,l,c,Nt.ROOTLESS,g)}getPseudoMap(e,n,s,o,i){let a=Pt(e,"_pseudos");if(!a)return null;let l={};for(let c in a){let u=l[c]={};ko(u,a[c],i),ba(u,i,a[c]),qu(a[c],n,s,(d,h)=>{ko(u,h,i),Ku(h,f=>{ko(u,f,i)})})}return l}createRefShadow(e,n,s,o,i){let a=A("createRefShadow");return this.xmldoc.store.load(e).then(l=>{let c=l;if(c){let u=c.getElement(e);if(u){let d=this.stylerProducer.getStylerForDoc(c);i=new vs(s,u,c,o,i,n,d)}}a.finish(i)}),a.result()}createShadows(e,n,s,o,i,a,l){let c=A("createShadows"),u=null,d=o.template,h;if(d instanceof Fe||d===b.footnote){let f=d instanceof Fe?d.url:Q("user-agent.xml#footnote",Kt);h=this.createRefShadow(f,Nt.ROOTLESS,e,l,u)}else h=T(u);return h.then(f=>{let g=null;if(e.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&e.localName=="include"){let x=e.getAttribute("href"),E=null;x?E=l?l.xmldoc:this.xmldoc:l&&(l.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?x=l.owner.getAttribute("href"):x=l.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),E=l.parentShadow?l.parentShadow.xmldoc:this.xmldoc),x&&(x=Q(x,E.url),g=this.createRefShadow(x,Nt.ROOTED,e,l,f))}g==null&&(g=T(f));let m=null;g.then(x=>{if(o.display===b.table_cell){let E=Q("user-agent.xml#table-cell",Kt);m=this.createRefShadow(E,Nt.ROOTLESS,e,l,x)}else m=T(x);m.then(E=>{E=this.createPseudoelementShadow(e,n,s,o,i,a,l,E),c.finish(E)})})}),c.result()}setViewRoot(e,n){this.viewRoot=e,this.isFootnote=n}computeStyle(e,n,s,o){var E;let i=this.context,a=Ta(s,i,this.regionIds,this.isFootnote,this.nodeContext),l=!((E=this.nodeContext)!=null&&E.parent);l&&(!a["writing-mode"]&&this.styler.rootStyle["writing-mode"]&&(a["writing-mode"]=this.styler.rootStyle["writing-mode"]),!a.direction&&this.styler.rootStyle.direction&&(a.direction=this.styler.rootStyle.direction));let c=e;e=Na(a,i,e);let u=!l&&e!==c;n=va(a,i,n);let d=(C,y)=>{let N;u&&(e?/^(min-|max-)?(height|inline-size)$/.test(C)&&(N=i.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(C)&&(N=i.pageAreaWidth));let S=y.evaluate(i,C,N,e);return C=="font-family"&&(S=this.docFaces.filterFontFamily(S)),S},h=!!new J(i.style.pageScope,"left-page").evaluate(i);if(wa(a,o,e,n,h,d),u){let C=o[e?"height":"width"];(!C||C===b.auto)&&(o[e?"height":"width"]=b.max_content)}if(ui(o.position))return o.position=b.fixed,o.visibility=b.hidden,e;let f=o.position,g=o.float,m=o.display||(this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?b.inline:void 0),x=Xc(m,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(C=>{x[C]&&(o[C]=x[C])}),e}inheritFromSourceParent(e){let n=this.nodeContext.sourceNode,s=[],o=null,i=this.nodeContext.shadowContext,a=-1;for(;n&&n.nodeType==1;){let h=i&&i.root==n;if(!h||i.type==Nt.ROOTLESS){let g=(i?i.styler:this.styler).getStyle(n,!1);s.push(g),o=o||Uo(n)}h?(n=i.owner,i=i.parentShadow):(n=n.parentNode,a++)}let l=a===0,c=this.context.queryUnitSize("em",l),u={"font-size":new H(new P(c,"px"),0)},d=new ha(u,this.context);for(let h=s.length-1;h>=0;--h){let f=s[h],g=[];for(let E in f)Zn(E)&&g.push(E);g.sort(Xl);let m,x;for(let E of g){d.setPropName(E);let C=pe(f,E),y=C;if(!U(C.value)){if(E==="font-size"&&h===s.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)y=new H(new P(this.context.rootFontSize,"px"),C.priority);else if(E==="line-height"&&h===s.length-1&&this.context.rootLineHeight&&C.value instanceof P&&(C.value.unit==="lh"||C.value.unit==="rlh"))y=new H(new P(this.context.rootLineHeight,"px"),C.priority);else if(h===0&&C.value instanceof P&&C.value.unit==="lh"){let N=this.getLineHeightUnitSize(E,m,x);N!=null&&(y=new H(new P(C.value.num*N,"px"),C.priority))}else yt(E)||(y=C.filterValue(d));E==="font-size"?m=y.value:E==="line-height"&&(x=y.value),u[E]=y}}}for(let h in e)Zn(h)||(u[h]=e[h]);return{lang:o,elementStyle:u}}resolveURL(e){return e=Q(e,this.xmldoc.url),this.fallbackMap[e]||e}inheritLangAttribute(){this.nodeContext.lang=Uo(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(e){let n=yf().filter(s=>e[s]);if(n.length){let s=this.nodeContext.inheritedProps;if(this.nodeContext.parent){s=this.nodeContext.inheritedProps={};for(let o in this.nodeContext.parent.inheritedProps)s[o]=this.nodeContext.parent.inheritedProps[o]}n.forEach(o=>{let i=e[o];if(i){if(U(i))i===b.initial&&(s[o]=void 0);else if(i instanceof ct)s[o]=i.num;else if(i instanceof Ce)s[o]=i.name;else if(i instanceof P){let a=i;switch(a.unit){case"dpi":case"dpcm":case"dppx":s[o]=a.num*K[a.unit];break;default:s[o]=i}}else s[o]=i;["widows","orphans"].includes(o)||delete e[o]}})}}resolveFormattingContext(e,n,s,o,i,a){let l=He("RESOLVE_FORMATTING_CONTEXT");for(let c=0;c<l.length;c++){let u=l[c](e,n,s,o,i,a);if(u){e.formattingContext=u;return}}}createElementView(e,n){var E,C,y,N;let s=!0,o=A("createElementView"),i=this.sourceNode,a=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,l=a.getStyle(i,!1);if(!this.nodeContext.shadowContext){let S=this.xmldoc.getElementOffset(i);Kn.registerFragmentIndex(S,this.nodeContext.fragmentIndex,0)}let c={};if(!this.nodeContext.parent){let S=this.inheritFromSourceParent(l);l=S.elementStyle,this.nodeContext.lang=S.lang}let u=l.position,d=l.float,h=l["float-reference"],f=d&&!U(d.value)&&d.value!==b.none&&h&&!U(h.value)?ef(h.value.toString()):null;if(this.nodeContext.parent&&(ui(u==null?void 0:u.value)||f&&Wn(f))){let S=this.inheritFromSourceParent(l);l=S.elementStyle,this.nodeContext.lang=S.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,c),f&&Wn(f)&&c.display===b.block&&(c.display=b.flow_root),a.processContent(i,c,(C=this.nodeContext.viewNode)!=null?C:(E=this.nodeContext.parent)==null?void 0:E.viewNode),this.transferPolyfilledInheritedProps(c),this.inheritLangAttribute(),c.direction&&(this.nodeContext.direction=c.direction.toString());let g=c["flow-into"];if(g&&g.toString()!=this.flowName)return o.finish(!1),o.result();if(Xt&&i.localName==="script"&&i.namespaceURI==="http://www.w3.org/1999/xhtml")return Ja(i,this.viewport.window).thenFinish(o),o.result();let m=c.display;if(U(m)&&(m===b.initial||m===b.unset?m=b.inline:m===b.inherit?m=((y=this.nodeContext.parent)==null?void 0:y.display)&&L((N=this.nodeContext.parent)==null?void 0:N.display):m=null),m===b.none)return o.finish(!1),o.result();let x=this.nodeContext.parent==null;return this.nodeContext.flexContainer=m===b.flex,this.createShadows(i,x,l,c,a,this.context,this.nodeContext.shadowContext).then(S=>{var Vp,Fp;this.nodeContext.nodeShadow=S;let v=c.position,k=c.float,R=c.clear,z=this.nodeContext.vertical?b.vertical_rl:b.horizontal_tb,te=this.nodeContext.parent?this.nodeContext.parent.vertical?b.vertical_rl:b.horizontal_tb:z,Ke=nf(i),ht=c["column-count"],Ue=c["column-width"],qe=ht&&ht!==b.auto&&!U(ht)||Ue&&Ue!==b.auto&&!U(Ue);this.nodeContext.establishesBFC=of(m,v,k,c.overflow,z,te,qe||Ke),this.nodeContext.containingBlockForAbsolute=rf(v),this.nodeContext.isInsideBFC()&&k!==b.footnote&&!(f&&Wn(f))&&(k=null,R=null);let st=k instanceof j||k===b.left||k===b.right||k===b.top||k===b.bottom||k===b.inline_start||k===b.inline_end||k===b.block_start||k===b.block_end||k===b.snap_block||k===b.snap_inline||k===b.inside||k===b.outside||k===b.footnote;k&&(delete c.float,k===b.footnote&&(this.isFootnote?(st=!1,c.display=b.block):c.display=b.inline)),R&&(R===b.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(R=L(this.nodeContext.parent.clearSide)),(R===b.left||R===b.right||R===b.top||R===b.bottom||R===b.inline_start||R===b.inline_end||R===b.block_start||R===b.block_end||R===b.inside||R===b.outside||R===b.both||R===b.all||R===b.same||R===b.column||R===b.region||R===b.page)&&(delete c.clear,c.display&&c.display!=b.inline&&(this.nodeContext.clearSide=R.toString())));let I=m===b.list_item&&c["ua-list-item-count"],O=c["break-inside"];(st||O&&!U(O)&&O!==b.auto)&&this.nodeContext.breakPenalty++,m&&m!==b.inline&&Gt(m)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!st&&!m||Gt(m)||aa(m),this.nodeContext.display=m?m.toString():"inline",this.nodeContext.floatSide=st?k.toString():null,this.nodeContext.floatReference=f||le.INLINE;let V=c["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=V&&!U(V)?V:null;let _=this.isInsideNonRootMultiColumn(),W=c["column-span"];if(this.nodeContext.columnSpan=!_&&W&&!U(W)?W:null,!this.nodeContext.inline){let M=c["break-after"];M&&!U(M)&&!(_&&M===b.column)&&(this.nodeContext.breakAfter=M.toString(),Xr[this.nodeContext.breakAfter]&&(c["break-after"]=b.column));let ot=c["break-before"];ot&&!U(ot)&&!(_&&ot===b.column)&&(this.nodeContext.breakBefore=ot.toString(),Xr[this.nodeContext.breakBefore]&&(c["break-before"]=b.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let kt=c.page,it=kt&&!U(kt)&&kt.toString();!it&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||m===b.table_header_group||m===b.table_footer_group)&&(it=this.styler.cascade.currentPageType),!it||it.toLowerCase()==="auto"?it=this.nodeContext.pageType:this.nodeContext.pageType=it,this.styler.cascade.currentPageType!==it&&!(!it&&c.position===b.fixed)&&(this.nodeContext.fragmentIndex===1&&!_n(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),it!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=it)}this.nodeContext.verticalAlign=c["vertical-align"]&&c["vertical-align"].toString()||"baseline",this.nodeContext.captionSide=c["caption-side"]&&c["caption-side"].toString()||"top";let ae=c["border-collapse"];if(!ae||ae===L("separate")){let M=c["border-spacing"],ot,kt;M&&(M instanceof j?(ot=M.values[0],kt=M.values[1]):ot=kt=M,ot.isNumeric()&&(this.nodeContext.inlineBorderSpacing=Pe(ot,this.context)),kt.isNumeric()&&(this.nodeContext.blockBorderSpacing=Pe(kt,this.context)))}let ft=c["footnote-policy"];this.nodeContext.footnotePolicy=ft&&!U(ft)?ft:null;let is=c["x-first-pseudo"];if(is){let M=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Qr(M,is.num)}this.nodeContext.inline||this.processAfterIfcontinues(i,l,a,this.context);let Rp=c["white-space"];if(Rp){let M=na(Rp.toString());M!==null&&(this.nodeContext.whitespace=M)}let fl=c["hyphenate-character"];fl&&fl instanceof ue&&(this.nodeContext.hyphenateCharacter=fl.str);let Mg=c["word-break"],_g=c["line-break"],Ip=c["overflow-wrap"];(Mg===b.break_all||_g===b.anywhere||Ip===b.break_word||Ip===b.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,e,m,v,k,x),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(e=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,e)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(c),this.findAndProcessRepeatingElements(i,a));let rs=!1,gl=null,Oo=[],Ft=i.namespaceURI,$=i.localName,er=$;if(Ft=="http://www.w3.org/1999/xhtml"?($=="html"||$=="body"||$=="script"||$=="link"||$=="meta"?$="div":$=="vide_"?$="video":$=="audi_"?$="audio":$=="object"&&(rs=!!this.customRenderer),i.getAttribute(Pa)&&(Fp=(Vp=l.content)==null?void 0:Vp.value)!=null&&Fp.url&&($="img")):Ft=="http://www.idpf.org/2007/ops"?($="span",Ft="http://www.w3.org/1999/xhtml"):Ft=="http://www.pyroxy.com/ns/shadow"?(Ft="http://www.w3.org/1999/xhtml",$=this.nodeContext.inline?"span":"div"):rs=!!this.customRenderer,I)e?$="li":($="div",m=b.block,c.display=m);else if($=="body"||$=="li")$="div";else if($=="q")$="span";else if($=="a"){let M=c["hyperlink-processing"];M&&M.toString()!="normal"&&($="span")}c.behavior&&c.behavior.toString()!="none"&&this.customRenderer&&(rs=!0),i.dataset&&i.getAttribute("data-math-typeset")==="true"&&(rs=!0);let ml;if(rs){let M=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;ml=this.customRenderer(i,M,c)}else ml=T(null);ml.then(M=>{var Dp,Mp,_p;if(M)rs&&(s=M.getAttribute("data-adapt-process-children")=="true");else if(c.display===b.none){o.finish(!1);return}else M=this.createElement(Ft,$);!x&&qe&&c["column-fill"]===b.auto&&(M.setAttribute("data-vivliostyle-column-fill","auto"),c["column-fill"]=b.balance),$!=er&&(M.setAttribute("data-vivliostyle-original-tag",er),(er==="html"||er==="body")&&(M.role="presentation")),$=="a"&&M.addEventListener("click",this.page.hrefHandler,!1),gl&&(this.applyPseudoelementStyle(this.nodeContext,"inner",gl),M.appendChild(gl)),M.localName=="iframe"&&M.namespaceURI=="http://www.w3.org/1999/xhtml"&&vb(M);let ot=this.nodeContext.inheritedProps["image-resolution"],kt=[],it=c.width,Cl=c.height,Ug=i.getAttribute("width"),Hg=i.getAttribute("height"),bl=it===b.auto||!it&&!Ug,xl=Cl===b.auto||!Cl&&!Hg,Bp=i.attributes,zg=Bp.length,tr=null,Op=null;m===b.table_cell&&((_p=(Mp=(Dp=this.nodeContext.parent)==null?void 0:Dp.viewNode)==null?void 0:Mp.lastElementChild)==null?void 0:_p.localName)==="a"&&M.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let Ze=0;Ze<zg;Ze++){let jt=Bp[Ze],rt=jt.namespaceURI,oe=jt.localName,he=jt.nodeValue;if(rt){if(rt=="http://www.w3.org/2000/xmlns/")continue;rt=="http://www.w3.org/1999/xlink"&&oe=="href"&&(he=this.documentURLTransformer.transformURL(this.resolveURL(he),this.xmldoc.url))}else{if(!Xt&&oe.match(/^on/)||oe=="style")continue;if((oe=="id"||oe=="name")&&e){let We=this.documentURLTransformer.transformFragment(he,this.xmldoc.url);M.setAttribute(oe,he),M.setAttribute("data-vivliostyle-id",We);let gt=M.ownerDocument.createElement("a");gt.setAttribute(oe,We),gt.setAttribute(an,"1"),gt.style.position="absolute",M.appendChild(gt),this.page.registerElementWithId(M,We);continue}if(oe=="src"||oe=="href"||oe=="poster")he=this.resolveURL(he),oe==="href"&&(he=this.documentURLTransformer.transformURL(he,this.xmldoc.url));else if(oe=="srcset")he=he.split(",").map(We=>this.resolveURL(We.trim())).join(",");else if(oe==="data"&&rs&&$==="object"&&M.hasAttribute("data"))continue;if(oe==="poster"&&$==="video"&&Ft==="http://www.w3.org/1999/xhtml"&&bl&&xl){let We=new Image,gt=Dn(We,he);Oo.push(gt),kt.push({image:We,element:M,fetcher:gt})}}if(Ft=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(oe)&&(oe=oe.toLowerCase()),this.isSVGUrlAttribute(oe)&&(he=wg(he,this.xmldoc.url,this.documentURLTransformer)),rt){let We=Nb[rt];We&&(oe=`${We}:${oe}`)}if(oe=="src"&&!rt&&($=="img"||$=="input")&&Ft=="http://www.w3.org/1999/xhtml")tr=he;else if(oe=="alt"&&!rt&&$=="img"&&Ft=="http://www.w3.org/1999/xhtml")Op=he;else if(oe=="href"&&$=="image"&&Ft=="http://www.w3.org/2000/svg"&&rt=="http://www.w3.org/1999/xlink")this.page.fetchers.push(Dn(M,he));else if(rt)M.setAttributeNS(rt,oe,he);else try{M.setAttribute(oe,he)}catch(We){F.warn(We)}}if(tr){let Ze=$==="input"?new Image:M,jt=Dn(Ze,tr,Op);Ze!==M&&(M.src=tr);let rt=()=>{var he,We;if(c.position===b.fixed)return!0;for(let gt=(he=this.nodeContext.parent)==null?void 0:he.viewNode;gt&>!==this.viewRoot;gt=gt.parentElement)if(((We=gt.style)==null?void 0:We.position)==="fixed")return!0;return!1};!bl&&!xl&&!(()=>{let he=this.nodeContext.vertical?it:Cl;return he instanceof P&&he.unit==="%"})()&&!rt()?this.page.fetchers.push(jt):(bl&&xl&&ot&&ot!==1&&kt.push({image:Ze,element:M,fetcher:jt}),Oo.push(jt))}delete c.content;let yl=c["list-style-image"];if(yl&&yl instanceof Fe){let Ze=yl.url;Oo.push(Dn(new Image,Ze))}if(this.preprocessElementStyle(c),this.applyComputedStyles(M,c),this.nodeContext.inline)e||(dt(M,"inline-start"),Ss(M)&&dt(M,"clone"));else if(e){if(!ia(c.position)){let Ze=c["margin-break"],jt=this.getBreakTypeAt(this.nodeContext),rt=jt!==null,oe=jt==="auto";(Ze===b.discard&&rt||Ze!==b.keep&&oe&&!this.nodeContext.floatSide)&&$r(M,"block-start")}}else{let Ze=this.nodeContext.vertical?"width":"height";Ot(M,Ze)&&w(M,Ze,this.nodeContext.display==="table-row"?"0.01px":""),dt(M,"block-start"),Ss(M)&&dt(M,"clone"),$r(M,"block-start")}I&&M.setAttribute("value",c["ua-list-item-count"].stringValue()),this.viewNode=M,Oo.length?On(Oo).then(()=>{ot>0&&this.modifyElemDimensionWithImageResolution(kt,ot,c,this.nodeContext.vertical),o.finish(s)}):o.timeSlice().then(()=>{o.finish(s)})})}),o.result()}isInsideNonRootMultiColumn(){var n;let e=(n=this.nodeContext.parent)==null?void 0:n.viewNode;return!!(e&&hi(e))}getBreakTypeAt(e){var s,o,i,a,l;if(this.isInsideTable(e))return null;for(let c=e;c&&!c.after;c=c.parent){if(Re(c.breakBefore))return c.breakBefore;if(c.fragmentIndex===1&&!c.parent)return c.sourceNode===c.sourceNode.ownerDocument.documentElement?"page":null;if((s=c.parent)!=null&&s.floatSide)return null;let u=(o=c.parent)==null?void 0:o.viewNode;if(u){let d=this.viewport.window.getComputedStyle(u),h=parseFloat(d.paddingBlockStart),f=parseFloat(d.borderBlockStartWidth);if(h||f)return null;let g=u==null?void 0:u.firstChild;for(;g&&(de(g,c.parent.whitespace)||!c.floatSide&&ws(g));)g=g.nextSibling;if(g&&g!==c.viewNode)return null}}let n=(l=(a=(i=this.context)==null?void 0:i.currentLayoutPosition)==null?void 0:a.flowPositions[this.flowName])==null?void 0:l.startBreakType;return Re(n)?n:"auto"}isInsideTable(e){for(let n=e;n&&!n.after;n=n.parent)if(n.display&&n.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(e,n,s,o){let i=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(i&&i["after-if-continues"]&&i["after-if-continues"].content){let a=new vi(e,n,s,o,this.exprContentListener);this.nodeContext.afterIfContinues=new ka(e,a)}}isSVGUrlAttribute(e){return Yi.SVG_URL_ATTRIBUTES.includes(e.toLowerCase())}modifyElemDimensionWithImageResolution(e,n,s,o){e.forEach(i=>{if(i.fetcher.get().get()==="load"){let a=i.image,l=a.width/n,c=a.height/n,u=i.element;if(l>0&&c>0){if(s["box-sizing"]===b.border_box&&(s["border-left-style"]!==b.none&&(l+=Pe(s["border-left-width"],this.context)),s["border-right-style"]!==b.none&&(l+=Pe(s["border-right-width"],this.context)),s["border-top-style"]!==b.none&&(c+=Pe(s["border-top-width"],this.context)),s["border-bottom-style"]!==b.none&&(c+=Pe(s["border-bottom-width"],this.context))),n>1){let d=s["max-width"]||b.none,h=s["max-height"]||b.none;if(d===b.none&&h===b.none)w(u,"max-width",`${l}px`);else if(d!==b.none&&h===b.none)w(u,"width",`${l}px`);else if(d===b.none&&h!==b.none)w(u,"height",`${c}px`);else{d.isNumeric(),h.isNumeric();let f=d,g=h;f.unit!=="%"?w(u,"max-width",`${Math.min(l,Pe(f,this.context))}px`):g.unit!=="%"?w(u,"max-height",`${Math.min(c,Pe(g,this.context))}px`):o?w(u,"height",`${c}px`):w(u,"width",`${l}px`)}}else if(n<1){let d=s["min-width"]||ne,h=s["min-height"]||ne;d.isNumeric(),d.isNumeric();let f=d,g=h;f.num===0&&g.num===0?w(u,"min-width",`${l}px`):f.num!==0&&g.num===0?w(u,"width",`${l}px`):f.num===0&&g.num!==0?w(u,"height",`${c}px`):f.unit!=="%"?w(u,"min-width",`${Math.max(l,Pe(f,this.context))}px`):g.unit!=="%"?w(u,"min-height",`${Math.max(c,Pe(g,this.context))}px`):o?w(u,"height",`${c}px`):w(u,"width",`${l}px`)}}}})}preprocessElementStyle(e){He("PREPROCESS_ELEMENT_STYLE").forEach(s=>{s(this.nodeContext,e)})}findAndProcessRepeatingElements(e,n){for(let s=e.firstChild;s;s=s.nextSibling){if(s.nodeType!==1)continue;let o={},i=n.getStyle(s,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",i,o),!this.processRepeatOnBreak(o))continue;if(this.nodeContext.formattingContext instanceof Wt&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let l=this.nodeContext.parent,c=l&&l.formattingContext;this.nodeContext.formattingContext=new Wt(c,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(e){let n=e["repeat-on-break"];return n!==b.none&&((n===b.auto||U(n))&&(e.display===b.table_header_group?n=b.header:e.display===b.table_footer_group?n=b.footer:n=b.none),n&&n!==b.none)?n.toString():null}createTextNodeView(){let e=A("createTextNodeView");return this.preprocessTextContent().then(()=>{let n=this.offsetInNode||0,s=Mc(this.nodeContext.preprocessedTextContent).substr(n);this.viewNode=document.createTextNode(s),e.finish(!0)}),e.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return T(!0);let e,n=e=this.sourceNode.textContent,s=A("preprocessTextContent"),o=He("PREPROCESS_TEXT_CONTENT"),i=0;return s.loop(()=>i>=o.length?T(!1):o[i++](this.nodeContext,n).thenAsync(a=>(n=a,T(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Gh(e,n),s.finish(!0)}),s.result()}createNodeView(e,n){let s=A("createNodeView"),o,i=!0;return this.sourceNode.nodeType==1?o=this.createElementView(e,n):this.sourceNode.nodeType==8?(this.viewNode=null,o=T(!0)):o=this.createTextNodeView(),o.then(a=>{var l;if(i=a,this.nodeContext.viewNode=this.viewNode,this.viewNode){let c=(h,f)=>(h==null?void 0:h.nodeType)===1&&Bs(h)===f,u=this.nodeContext.parent,d=u?c(this.viewNode,"after")&&c(u.viewNode,"first-letter")&&((l=u.viewNode)!=null&&l.hasChildNodes())?u.parent.viewNode:u.viewNode:this.viewRoot;d&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&de(this.viewNode))&&!d.hasChildNodes()&&Ic(d).includes("block-start")&&dt(d,"text-start"),d.appendChild(this.viewNode),uf(this.viewNode))}s.finish(i)}),s.result()}setCurrent(e,n,s){return this.nodeContext=e,e?(this.sourceNode=e.sourceNode,this.offsetInNode=e.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(n,!!s):T(!0)}processShadowContent(e){if(e.shadowContext==null||e.sourceNode.localName!="content"||e.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return e;let n=e.boxOffset,s=e.shadowContext,o=e.parent,i,a,l=s.subShadow||s.parentShadow;s.subShadow?(i=s.root,a=s.type,a==Nt.ROOTLESS&&(i=i.firstChild)):(i=s.owner.firstChild,a=Nt.ROOTLESS);let c=e.sourceNode.nextSibling;if(c?(e.sourceNode=c,e.resetView()):e.shadowSibling?e=e.shadowSibling:i?e=null:(e=e.parent.modify(),e.after=!0),i){let u=new Gn(i,o,n);return u.shadowContext=l,u.shadowType=a,u.shadowSibling=e,u}return e.boxOffset=n,e}nextPositionInTree(e){let n=e.boxOffset+1;if(e.after){if(!e.parent)return null;if(e.shadowType!=Nt.ROOTED){let s=e.sourceNode.nextSibling;if(s)return e=e.modify(),e.boxOffset=n,e.sourceNode=s,e.resetView(),this.processShadowContent(e)}return e.shadowSibling?(e=e.shadowSibling.modify(),e.boxOffset=n,e):(e=e.parent.modify(),e.boxOffset=n,e.after=!0,e)}else{if(e.nodeShadow){let o=e.nodeShadow.root;if(e.nodeShadow.type==Nt.ROOTLESS&&(o=o.firstChild),o){let i=new Gn(o,e,n);return i.shadowContext=e.nodeShadow,i.shadowType=e.nodeShadow.type,this.processShadowContent(i)}}let s=e.sourceNode.firstChild;if(s)return this.processShadowContent(new Gn(s,e,n));if(e.sourceNode.nodeType!=1){let o=Mc(e.preprocessedTextContent);n+=o.length-1-e.offsetInNode}return e=e.modify(),e.boxOffset=n,e.after=!0,e}}isTransclusion(e,n,s){let o=pe(n,"hyperlink-processing");if(!o)return!1;let i=o.evaluate(this.context,"hyperlink-processing");return i?i.toString()==s:!1}nextInTree(e,n){let s=this.nextPositionInTree(e);if(!s||s.after)return T(s);let o=A("nextInTree");return this.setCurrent(s,!0,n).then(i=>{(!s.viewNode||!i)&&(s=s.modify(),s.after=!0,s.viewNode||(s.inline=!0)),this.dispatchEvent({type:"nextInTree",nodeContext:s}),o.finish(s)}),o.result()}addImageFetchers(e){if(e instanceof fe){let n=e.values;for(let s=0;s<n.length;s++)this.addImageFetchers(n[s])}else if(e instanceof Fe){let n=e.url;this.page.fetchers.push(Dn(new Image,n))}}applyComputedStyles(e,n){var u,d,h;let s=n["background-image"];s&&this.addImageFetchers(s);let o=n.position===b.relative,i=((u=this.nodeContext)==null?void 0:u.parent)===null&&((d=this.sourceNode)==null?void 0:d.parentElement)===null&&!!((h=this.viewRoot)!=null&&h.parentElement),a=Object.keys(n);a.sort(Xl);let l,c;for(let f of a){if(Tb[f])continue;let g=n[f];if(!(!g||g===D&&!yt(f))){if(g=g.visit(new Fr(this.xmldoc.url,this.documentURLTransformer)),g instanceof P)if(g.unit==="em"){let m=this.getEmUnitSize(f,l);m!=null&&(g=new P(g.num*m,"px"))}else if(g.unit==="lh"){let m=this.getLineHeightUnitSize(f,l,c);m!=null&&(g=new P(g.num*m,"px"))}else Pr(g.unit)&&(g=Lr(g,this.context));if((f==="font-size"||f==="line-height")&&(f==="font-size"?l=g:c=g,this.viewport.layoutUnitAdj&&g instanceof P&&g.unit!=="%"&&g.unit!=="em"&&g.unit!=="lh"&&(g=new en(`calc(${g.toString()} - var(--viv-layoutUnitAdj))`))),jh[f]||o&&Yh[f]){this.page.delayedItems.push(new zn(e,f,g));continue}i&&this.page.pageAreaElement&&Zn(f)?w(this.page.pageAreaElement.parentElement.parentElement,f,g.toString()):w(e,f,g.toString())}}}parsePlusLayoutUnitAdj(e){if(e.endsWith("px")){let n=parseFloat(e);if(!isNaN(n))return Math.round((n+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getLineHeightUnitSize(e,n,s){var l,c,u,d;let o=((c=(l=this.nodeContext.parent)==null?void 0:l.viewNode)==null?void 0:c.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,i=o?this.parsePlusLayoutUnitAdj(o.lineHeight):this.context.rootLineHeight;if(e==="line-height"||e==="font-size")return i;let a=null;if(s)if(s instanceof Je||s instanceof P&&(s.unit==="em"||s.unit==="%"))a=s instanceof P&&s.unit==="%"?s.num/100:s.num;else{if(s instanceof P&&s.unit!=="lh"){let h=this.context.queryUnitSize(s.unit,!1);if(h!=null)return s.num*h}return null}if(a==null)for(let h=(u=this.nodeContext.parent)==null?void 0:u.viewNode;h&&h.nodeType===1;h=h.parentNode){let f=(d=h==null?void 0:h.style)==null?void 0:d.lineHeight;if(f){/^[0-9.]+$/.test(f)&&(a=parseFloat(f));break}}if(a!=null){if(n&&!(n instanceof P))return null;let h=o?this.parsePlusLayoutUnitAdj(o.fontSize):this.context.rootFontSize;if(n instanceof P){let f=Ea(n,h,this.context).num;return typeof f!="number"||isNaN(f)?null:a*f}else return h==null?null:a*h}return i}getEmUnitSize(e,n){var i,a;let s=((a=(i=this.nodeContext.parent)==null?void 0:i.viewNode)==null?void 0:a.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,o=s?this.parsePlusLayoutUnitAdj(s.fontSize):this.context.rootFontSize;if(e==="font-size"||n==null)return o;if(n instanceof P){let l=Ea(n,o,this.context).num;if(typeof l=="number"&&!isNaN(l))return l}return null}applyPseudoelementStyle(e,n,s){if(e.after)return;let o=this.sourceNode,a=(e.shadowContext?e.shadowContext.styler:this.styler).getStyle(o,!1),l=Pt(a,"_pseudos");if(!l||(a=l[n],!a))return;let c={};e.vertical=this.computeStyle(e.vertical,e.direction==="rtl",a,c);let u=c.content;vt(u)&&(u.visit(new bn(s,this.context,u,this.exprContentListener)),delete c.content),this.applyComputedStyles(s,c)}peelOff(e,n){let s=A("peelOff"),o=e.firstPseudo,i=e.offsetInNode,a=e.after;if(n>0){let h=e.viewNode.textContent;e.viewNode.textContent=h.substr(0,n),i+=n}else if(!a&&e.viewNode&&i==0){let h=e.viewNode.parentNode;h&&h.removeChild(e.viewNode)}let l=e.boxOffset+n,c=[];for(;e.firstPseudo===o;)c.push(e),e=e.parent;let u=c.pop(),d=u.shadowSibling;return s.loop(()=>{for(;c.length>0;){u=c.pop(),e=new Gn(u.sourceNode,e,l),c.length==0&&(e.offsetInNode=i,e.after=a),e.shadowType=u.shadowType,e.shadowContext=u.shadowContext,e.nodeShadow=u.nodeShadow,e.shadowSibling=u.shadowSibling?u.shadowSibling:d,d=null;let h=this.setCurrent(e,!1);if(h.isPending())return h}return T(!1)}).then(()=>{s.finish(e)}),s.result()}createElement(e,n){return e=="http://www.w3.org/1999/xhtml"?this.document.createElement(n):this.document.createElementNS(e,n)}applyFootnoteStyle(e,n,s){let o={},i=Pt(this.footnoteStyle,"_pseudos");if(e=this.computeStyle(e,n,this.footnoteStyle,o),i&&i.before){let a={},l=this.createElement("http://www.w3.org/1999/xhtml","span");Ti(l,"before"),s.appendChild(l),this.computeStyle(e,n,i.before,a),delete a.content,this.applyComputedStyles(l,a)}return delete o.content,this.applyComputedStyles(s,o),e}processFragmentedBlockEdge(e){var i,a,l;let n=!e.inline&&e.after?e.parent:e,s=!1;if(e.inline&&e.after&&!e.shadowContext&&((i=e.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let c=e.sourceNode.nextSibling,u=(a=pe(this.styler.getStyle(c,!1),"display"))==null?void 0:a.value.toString();s=u&&!Gt(u)||c.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(c.textContent)}let o=0;for(let c=n;c;c=c.parent){if(((l=c.viewNode)==null?void 0:l.nodeType)!==1)continue;let u=c.viewNode;if(u.style)if(c.inline){if(dt(u,"inline-end"),Ss(u)){let d=c.vertical?u.offsetWidth:u.offsetHeight;dt(u,"clone"),(c.vertical?u.offsetWidth:u.offsetHeight)>d&&this.fixClonedBoxDecorationOverflow(u)}}else{let d=this.nodeContext.vertical?"width":"height";if(Ot(u,d)&&w(u,d,""),dt(u,"block-end"),!o++&&c!==n){let{textAlign:h}=this.viewport.window.getComputedStyle(u);if(h==="justify"&&!s){let f=this.createChildAnonymousBlockIfNeeded(u);f?f!==u?Vc(f,["block-start","text-start","block-end","text-end","justify"]):(dt(u,"text-end"),dt(u,"justify")):dt(u,"text-end")}else dt(u,"text-end")}Ss(u)&&dt(u,"clone"),$r(u,"block-end")}}}fixClonedBoxDecorationOverflow(e){let n=this.viewport.window.getComputedStyle(e),s=parseFloat(n.paddingInlineEnd),o=parseFloat(n.borderInlineEndWidth),i=-(s+o);isNaN(i)||(e.style.marginInlineEnd=`${i}px`)}createChildAnonymousBlockIfNeeded(e){let n=i=>{let{display:a,position:l,float:c}=this.viewport.window.getComputedStyle(i);if(i.localName==="ruby"||Zt[i.localName])return!1;if(i.localName==="br")return!0;if((a==="inline"||a==="contents")&&i.hasChildNodes()){let u=i.lastElementChild;if(u&&(!u.nextSibling||u.nextSibling===i.lastChild&&de(u.nextSibling))){let d=n(u);if(d||d===null)return d}for(let d=u==null?void 0:u.previousElementSibling;d;d=d.previousElementSibling){let h=n(d);if(h||h===null)return null}return!1}if(a==="none"||l==="absolute"||l==="fixed"||c&&c!=="none"||i.hasAttribute(an)){let u=i.previousElementSibling;return u&&(u.nextSibling===i||u.nextSibling===i.previousSibling&&de(u.nextSibling))?n(u):!1}return!(!a||Gt(a))},s=null;for(let i=e.lastElementChild;i;i=i.previousElementSibling){let a=n(i);if(a){s=i;break}if(a===null)return null}if(!s)return e;if(s===e.lastElementChild&&(!s.nextSibling||s.nextSibling===e.lastChild&&de(s.nextSibling)))return null;let o=e.ownerDocument.createElement("span");o.className="viv-anonymous-block";for(let i=s.nextSibling,a=null;i;i=a)a=i.nextSibling,o.appendChild(i);return e.appendChild(o),o}convertLengthToPx(e,n,s){let o=e.num,i=e.unit;if(th(i)){let a=n;for(;a&&a.nodeType!==1;)a=a.parentNode;let l=parseFloat(s.getElementComputedStyle(a)["font-size"]);return this.context,ya(e,l,this.context).num}else{let a=this.context.queryUnitSize(i,!1);return a?o*a:e}}isSameNodePositionStep(e,n){if(e.shadowContext){if(!n.shadowContext)return!1;let s=e.node.nodeType===1?e.node:e.node.parentElement,o=n.node.nodeType===1?n.node:n.node.parentElement;return e.shadowContext.owner===n.shadowContext.owner&&Bs(s)===Bs(o)}else return e.node===n.node}isSameNodePosition(e,n){return e.offsetInNode===n.offsetInNode&&e.after==n.after&&e.steps.length===n.steps.length&&e.steps.every((s,o)=>{let i=n.steps[o];return this.isSameNodePositionStep(s,i)})}isPseudoelement(e){return!!Bs(e)}};p(Yi,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var el=Yi,Tb={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-policy":!0,"margin-break":!0,page:!0},tl=class{constructor(t){p(this,"layoutBox");p(this,"window");p(this,"scaleRatio");p(this,"layoutUnitPerPixel");this.layoutBox=t.layoutBox,this.window=t.window,this.scaleRatio=t.scaleRatio,this.layoutUnitPerPixel=t.layoutUnitPerPixel}subtractOffsets(t,e){let n=e.left,s=e.top;return{left:t.left-n,top:t.top-s,right:t.right-n,bottom:t.bottom-s,width:t.width,height:t.height}}getRangeClientRects(t){let e=t.getClientRects(),n=this.layoutBox.getBoundingClientRect();return Array.from(e).map(s=>this.subtractOffsets(s,n))}getElementClientRect(t){let n=t.getBoundingClientRect();if(n.left===0&&n.top===0&&n.right===0&&n.bottom===0)return n;let s=this.layoutBox.getBoundingClientRect();return this.subtractOffsets(n,s)}getElementComputedStyle(t){return this.window.getComputedStyle(t,null)}adjustLengthValue(t){return this.layoutUnitPerPixel?Math.floor(t*this.layoutUnitPerPixel)/this.layoutUnitPerPixel:t}},An=class{constructor(t,e,n,s,o,i){this.window=t;this.fontSize=e;this.pixelRatio=n;p(this,"document");p(this,"root");p(this,"outerZoomBox");p(this,"contentContainer");p(this,"layoutBox");p(this,"width");p(this,"height");p(this,"scaleRatio",1);p(this,"layoutUnitPerPixel");p(this,"layoutUnitAdj",0);this.document=t.document,this.root=s||this.document.body;let a=this.root.firstElementChild;a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-outer-zoom-box","true"),a.role="presentation",this.root.appendChild(a));let l=a.firstElementChild;switch(l||(l=this.document.createElement("div"),l.setAttribute("data-vivliostyle-spread-container","true"),l.role="presentation",a.appendChild(l)),n>0&&CSS.supports("zoom","8")&&(w(this.root,"--viv-outputPixelRatio",`${n}`),w(this.root,"--viv-devicePixelRatio",`${t.devicePixelRatio}`),this.scaleRatio=n/t.devicePixelRatio),ar){case"chromium":this.layoutUnitPerPixel=64*(this.pixelRatio||t.devicePixelRatio),this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"firefox":this.layoutUnitPerPixel=60,this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"webkit":default:this.layoutUnitPerPixel=64,this.layoutUnitAdj=0}this.layoutUnitAdj&&w(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let c=a.nextElementSibling;c||(c=this.document.createElement("div"),c.setAttribute("data-vivliostyle-layout-box","true"),c.role="presentation",this.root.appendChild(c)),this.outerZoomBox=a,this.contentContainer=l,this.layoutBox=c,this.width=o||parseFloat(t.getComputedStyle(this.root).width)||this.root.offsetWidth||t.innerWidth,this.height=i||parseFloat(t.getComputedStyle(this.root).height)||this.root.offsetHeight||t.innerHeight;let u={width:794,height:1056},d=!t.outerWidth&&!t.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&t.innerWidth===800&&t.innerHeight===600;(!this.width||!o&&d)&&(this.width=u.width),(!this.height||!i&&d)&&(this.height=u.height)}resetZoom(){w(this.outerZoomBox,"width",""),w(this.outerZoomBox,"height",""),w(this.contentContainer,"width",""),w(this.contentContainer,"height",""),w(this.contentContainer,"transform","")}zoom(t,e,n){w(this.root,"--viv-outputScale",`${n}`),w(this.outerZoomBox,"width",`${t*n}px`),w(this.outerZoomBox,"height",`${e*n}px`),w(this.contentContainer,"width",`${t}px`),w(this.contentContainer,"height",`${e}px`)}clear(){let t=this.root;for(;t.lastChild;)t.removeChild(t.lastChild)}};var Ki=class{constructor(t,e,n){this.store=t;this.url=e;this.document=n;p(this,"lang",null);p(this,"totalOffset",-1);p(this,"root");p(this,"body");p(this,"head");p(this,"last");p(this,"lastOffset",1);p(this,"idMap");this.root=n.documentElement;let s=null,o=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let i=this.root.firstChild;i;i=i.nextSibling){if(i.nodeType!=1)continue;let a=i;if(a.namespaceURI=="http://www.w3.org/1999/xhtml")switch(a.localName){case"head":o=a;break;case"body":s=a;break}}this.lang=this.root.getAttribute("lang")}this.body=s,this.head=o,this.last=this.root,this.last.setAttribute(Bt,"0")}doc(){return new ol([this.document])}getElementOffset(t){let e=t.getAttribute(Bt);if(e)return parseInt(e,10);let n=this.lastOffset,s=this.last;for(;s!=t;){let o=s.firstChild;if(!o){for(;o=s.nextSibling,!o;)if(s=s.parentNode,s==null)throw new Error("Internal error")}s=o,o.nodeType==1?(o.setAttribute(Bt,n.toString()),++n):n+=o.textContent.length}return this.lastOffset=n,this.last=t,n-1}getNodeOffset(t,e,n){let s=0,o=t,i=null;if(o.nodeType==1){if(!n)return this.getElementOffset(o)}else{if(s=e,i=o.previousSibling,!i)return o=o.parentNode,s+=1,this.getElementOffset(o)+s;o=i}for(;;){for(;o.lastChild;)o=o.lastChild;if(o.nodeType==1)break;if(s+=o.textContent.length,i=o.previousSibling,!i){o=o.parentNode;break}o=i}return s+=1,this.getElementOffset(o)+s}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(t){let e,n=this.root;for(;;){if(e=this.getElementOffset(n),e>=t)return n;let l=n.children;if(!l)break;let c=Ct(l.length,u=>{let d=l[u];return this.getElementOffset(d)>t});if(c==0)break;n=l[c-1]}let s=e+1,o=n,i=o.firstChild||o.nextSibling,a=null;for(;;){if(i){if(i.nodeType==1||(o=i,a=o,s+=i.textContent.length,s>t&&!/^\s*$/.test(i.textContent)))break}else if(o=o.parentNode,!o)break;i=o.nextSibling}return i&&a&&/^\s*$/.test(a.textContent)&&(a=i),a||n}buildIdMap(t){let e=t.getAttribute("id");e&&!this.idMap[e]&&(this.idMap[e]=t);let n=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");n&&!this.idMap[n]&&(this.idMap[n]=t);for(let s=t.firstElementChild;s;s=s.nextElementSibling)this.buildIdMap(s)}getElement(t){let e=t.match(/([^#]*)#(.+)$/);if(!e||e[1]&&e[1]!=this.url)return null;let n=e[2],s=this.document.getElementById(n);return!s&&this.document.getElementsByName&&(s=this.document.getElementsByName(n)[0]),s||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),s=this.idMap[n]),s}},Ep=(o=>(o.TEXT_HTML="text/html",o.TEXT_XML="text/xml",o.APPLICATION_XML="application/xml",o.APPLICATION_XHTML_XML="application/xhtml+xml",o.IMAGE_SVG_XML="image/svg+xml",o))(Ep||{});function sl(r,t,e){let n=e||new DOMParser,s;try{s=n.parseFromString(r,t)}catch(o){}if(s){let o=s.documentElement,i="parsererror";if(o.localName===i)return null;for(let a=o.firstElementChild;a;a=a.nextElementSibling)if(a.localName===i)return null}else return null;return s}function wb(r){let t=r.contentType;if(t){let n=Object.keys(Ep);for(let s=0;s<n.length;s++)if(Ep[n[s]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let e=r.url.match(/\.([^./#?]+)([#?]|$)/);if(e)switch(e[1]){case"html":case"htm":return"text/html";case"xhtml":case"xht":return"application/xhtml+xml";case"svg":case"svgz":return"image/svg+xml";case"opf":case"xml":return"application/xml"}return null}function Np(r,t){let e=r.responseXML;if(!e){let s=new DOMParser,o=r.responseText;if(o){let i=wb(r);if(e=sl(o,i||"application/xml",s),e&&!i){let a=e.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?e=sl(o,"text/html",s):a.localName.toLowerCase()==="svg"&&e.contentType!=="image/svg+xml"&&(e=sl(o,"image/svg+xml",s))}e||(e=sl(o,"text/html",s))}}let n=e?new Ki(t,r.url,e):null;return T(n)}function Pg(){return new bs(Np,"document")}var Sp=class r{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,e){return new r(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==e)}withChild(t,e){return new r(n=>{if(!this.check(n))return!1;let s=new ol([n]);return s=s.child(t),e&&(s=s.predicate(e)),s.size()>0})}},vp=new Sp(r=>!0),ol=class r{constructor(t){this.nodes=t}asArray(){return this.nodes}size(){return this.nodes.length}predicate(t){let e=[];for(let n of this.nodes)t.check(n)&&e.push(n);return new r(e)}forEachNode(t){let e=[],n=s=>{e.push(s)};for(let s=0;s<this.nodes.length;s++)t(this.nodes[s],n);return new r(e)}forEach(t){let e=[];for(let n=0;n<this.nodes.length;n++)e.push(t(this.nodes[n]));return e}forEachNonNull(t){let e=[];for(let n=0;n<this.nodes.length;n++){let s=t(this.nodes[n]);s!=null&&e.push(s)}return e}child(t){return this.forEachNode((e,n)=>{for(let s=e.firstChild;s;s=s.nextSibling)s.nodeType==1&&s.localName==t&&n(s)})}childElements(){return this.forEachNode((t,e)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&e(n)})}attribute(t){return this.forEachNonNull(e=>e.nodeType==1?e.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}};var Pb=new nn(()=>{let r=A("uaStylesheetBase"),t=Yd(),e=Q("user-agent-base.css",Kt),n=new wn(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),wf(n.cascade),Wr(Nc,n,e,null,null).thenFinish(r),r.result()},"uaStylesheetBaseFetcher");function kb(){return Pb.get()}var Tp=class{constructor(t,e,n,s,o,i,a,l,c,u){this.store=t;this.rootScope=e;this.pageScope=n;this.cascade=s;this.rootBox=o;this.fontFaces=i;this.footnoteProps=a;this.flowProps=l;this.viewportProps=c;this.pageProps=u;p(this,"fontDeobfuscator");p(this,"validatorSet");this.fontDeobfuscator=t.fontDeobfuscator,this.validatorSet=t.validatorSet,this.pageScope.defineBuiltIn("has-content",function(d){d=d;let h=this,f=h.currentLayoutPosition,g=f.firstFlowChunkOfFlow(d);return h.matchPageSide(f.startSideOfFlow(d))&&f.hasContent(d,h.lookupOffset)&&!!g&&!h.flowChunkIsAfterParentFlowForcedBreak(g)}),this.pageScope.defineName("page-number",new q(this.pageScope,function(){let d=this;return d.pageNumberOffset+d.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new q(this.pageScope,function(){let h=this.currentLayoutPosition;return h==null?void 0:h.isBlankPage},"blank-page"))}sizeViewport(t,e,n,s){if(this.viewportProps.length){let o=new Ys(this.rootScope,t,e,n),i=vf(o,this.viewportProps),a=i.width,l=i.height,c=i["text-zoom"],u=1;if(a&&l||c){let d=K.em;if((c?c.evaluate(o,"text-zoom"):null)===b.scale&&(u=d/n,n=d,t*=u,e*=u),a&&l){let f=Pe(a.evaluate(o,"width"),o),g=Pe(l.evaluate(o,"height"),o);if(f>0&&g>0)return{width:s&&s.spreadView?(f+s.pageBorder)*2:f,height:g,fontSize:n}}}}return{width:t,height:e,fontSize:n}}},ss=class extends Ys{constructor(e,n,s,o,i,a,l,c,u,d,h,f,g){super(e.rootScope,o.width,o.height,o.fontSize);this.style=e;this.xmldoc=n;this.viewport=o;this.clientLayout=i;this.fontMapper=a;this.customRenderer=l;this.fallbackMap=c;this.pageNumberOffset=u;this.documentURLTransformer=d;this.counterStore=h;p(this,"lang");p(this,"primaryFlows",{body:!0});p(this,"rootPageBoxInstance",null);p(this,"styler",null);p(this,"stylerMap",null);p(this,"currentLayoutPosition",null);p(this,"layoutPositionAtPageStart",null);p(this,"lookupOffset",0);p(this,"faces");p(this,"pageBoxInstances",{});p(this,"pageManager",null);p(this,"rootPageFloatLayoutContext");p(this,"pageBreaks",{});p(this,"pageProgression",null);p(this,"isVersoFirstPage",!1);p(this,"blankPageAtStart",!1);p(this,"pageSheetSize",{});p(this,"pageSheetHeight",0);p(this,"pageSheetWidth",0);this.lang=n.lang||s,this.faces=new Ha(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new xn(null,null,null,null,null,null,null),this.pageProgression=f||null,this.isVersoFirstPage=!!g;for(let m in e.flowProps){let x=e.flowProps[m],E=pe(x,"flow-consume");E&&(E.evaluate(this,"flow-consume")==b.all?this.primaryFlows[m]=!0:delete this.primaryFlows[m])}}init(){let e=A("StyleInstance.init"),n=this.counterStore.createCounterListener(this.xmldoc.url),s=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new Ii(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,n,s),s.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let o=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=mp(o)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let i=this.style.rootBox;this.rootPageBoxInstance=new Xa(i);let a=this.style.cascade.createInstance(this,n,s,this.lang);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(a,o),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new qa(a,this.style.pageScope,this.rootPageBoxInstance,this,o);let l=[];for(let u of this.style.fontFaces){if(u.condition&&!u.condition.evaluate(this))continue;let d=ug(u.properties,this),h=new Mi(d);l.push(h)}this.fontMapper.findOrLoadFonts(l,this.faces).then(()=>{vg(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let c=this.style.pageProps;return c[""]||(c[""]={}),Object.keys(c).forEach(u=>{let d=c[u];this.styler.cascade.applyVarFilter([d],this.styler,null),this.styler.cascade.applyCalcFilter(d,this.styler.context);let h=Cp(ji(d),this);this.pageSheetSize[u]={width:h.pageWidth+h.cropOffset*2,height:h.pageHeight+h.cropOffset*2}}),e.result()}matchStartPageSide(e){let n=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),s=this.pageProgression=="ltr";switch(e){case"left":return n!==s;case"right":return n===s;case"recto":return n;case"verso":return!n;default:return!0}}getStylerForDoc(e){let n=this.stylerMap[e.url];if(!n){let s=this.style.store.getStyleForDoc(e),o=new Ys(s.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),i=this.counterStore.createCounterListener(e.url),a=this.counterStore.createCounterResolver(e.url,s.rootScope,s.pageScope);n=new Ii(e,s.cascade,s.rootScope,o,this.primaryFlows,s.validatorSet,i,a),this.stylerMap[e.url]=n}return n}registerInstance(e,n){this.pageBoxInstances[e]=n}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,n){let s=this.currentLayoutPosition;if(s){s.flows[e.flowName]?n=s.flows[e.flowName]:s.flows[e.flowName]=n;let o=s.flowPositions[e.flowName];o||(o=new ea,s.flowPositions[e.flowName]=o);let i=Qh(e.element),a=new pt(i),l=new Jr(a,e);o.positions.push(l)}}evalSupportsTest(e,n,s){if(s)return e==="selector"?this.evalSupportsSelector(n):!1;if(!e)return!1;let o=!0;class i{unknownProperty(d,h){o=!1}invalidPropertyValue(d,h){o=!1}simpleProperty(d,h,f){}}let a=new i,l=on(this.style.rootScope,new Be(n,null),"");return l?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,l,!1,a),o):!1}evalSupportsSelector(e){let n=new il(null),s=new Be(e+"{}",n);return new Mn(ge,s,n,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!n.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let n=Number.POSITIVE_INFINITY;for(let s=0;s<e.positions.length;s++){let o=e.positions[s].chunkPosition.primary,i=o.steps[0].node,a=o.offsetInNode,l=o.after,c=0;for(;i.ownerDocument!=this.xmldoc.document;)c++,i=o.steps[c].node,l=!1,a=0;let u=this.xmldoc.getNodeOffset(i,a,l);u<n&&(n=u)}return n}getPosition(e,n){if(!e)return 0;let s=Number.POSITIVE_INFINITY;for(let o in this.primaryFlows){let i=e.flowPositions[o];if(!n&&(!i||i.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(o),i=this.currentLayoutPosition.flowPositions[o],e!=this.currentLayoutPosition&&i&&(i=i.clone(),e.flowPositions[o]=i)),i){let a=this.getConsumedOffset(i);a<s&&(s=a)}}return s}dumpLocation(e){F.debug("Location - page",this.currentLayoutPosition.page),F.debug(" current:",e),F.debug(" lookup:",this.lookupOffset);for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let o of s.positions)F.debug(" Chunk",`${n}:`,o.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new J(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let n in e.flowPositions){let s=e.flowPositions[n];if(s&&s.positions.length>0){let o=s.positions[0].flowChunk;if(this.getConsumedOffset(s)===o.startOffset){let i=s.positions[0].flowChunk.breakBefore,a=s.startBreakType;s.startBreakType=Fc(Ie(a,i))}}}}selectPageMaster(e){let n=this.currentLayoutPosition,s=this.getPosition(n);if(s==Number.POSITIVE_INFINITY)return null;let o=this.rootPageBoxInstance.children,i;for(let a=0;a<o.length;a++){if(i=o[a],i.pageBox.pseudoName===Qa)continue;let l=1;i.pageBox.pseudoName===Ui&&!(this.actualPageWidth&&this.actualPageHeight)&&(l=1/0);let c=i.getProp(this,"utilization");c&&c.isNum()&&(l=c.num);let u=this.queryUnitSize("em",!1),d=this.pageWidth()*this.pageHeight(),h=Math.ceil(l*d/(u*u)),f=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(s,h),this.styler.cascade.currentPageType=f,this.updateStartSide(n),this.layoutPositionAtPageStart=n.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let g=i.getProp(this,"enabled");if(!g||g===b._true){if(n.page===1&&this.blankPageAtStart){i.style={};let m=e.size;e={},m&&(e.size=m)}return this.pageManager.getPageRulePageMaster(i,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let n=this.layoutPositionAtPageStart.flows,s=n[e.flowName].parentFlowName;if(s){let o=e.startOffset,i=n[s].forcedBreakOffsets;if(!i.length||o<i[0])return!1;let a=Ct(i.length,d=>i[d]>o)-1,l=i[a],c=this.layoutPositionAtPageStart.flowPositions[s],u=this.getConsumedOffset(c);return l<u?!1:u<l?!0:!this.matchPageSide(c.startBreakType)}return!1}setFormattingContextToColumn(e,n){let s=this.currentLayoutPosition.flows[n];s.formattingContext||(s.formattingContext=new yo(null)),e.flowRootFormattingContext=s.formattingContext}layoutDeferredPageFloats(e){let n=e.pageFloatLayoutContext,s=n.getDeferredPageFloatContinuations(),o=c=>{if(c.floatReference!==le.PAGE)return!1;let u=this.layoutPositionAtPageStart.flowPositions.body,d=u&&this.getConsumedOffset(u),h=this.xmldoc.getNodeOffset(c.nodePosition.steps[0].node,0,!1);return h!=null&&d!=null&&h>d},i=A("layoutDeferredPageFloats"),a=!1,l=0;return i.loopWithFrame(c=>{if(l===s.length){c.breakLoop();return}let u=s[l++],d=u.float;if(o(d)){c.breakLoop();return}let h=new zt().findByFloat(d),f=h.findPageFloatFragment(d,n);if(f&&f.hasFloat(d)){c.continueLoop();return}else if(n.isForbidden(d)||n.hasPrecedingFloatsDeferredToNext(d)){n.deferPageFloat(u),c.breakLoop();return}e.layoutPageFloatInner(u,h,null,f).then(g=>{if(!g){c.breakLoop();return}let m=n.parent.isInvalidated();if(m){c.breakLoop();return}else n.isInvalidated()&&!m&&(a=!0,n.validate());c.continueLoop()})}).then(()=>{a&&n.invalidate(),i.finish(!0)}),i.result()}getLastAfterPositionIfDeferredFloatsExists(e,n){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return n?(i=n.clone(),i.primary=e.lastAfterPosition):i=new pt(e.lastAfterPosition),i}else return null;else return null}layoutColumn(e,n){let s=this.currentLayoutPosition.flowPositions[n];if(!s||!this.matchPageSide(s.startBreakType))return T(!0);this.setFormattingContextToColumn(e,n),e.init(),this.primaryFlows[n]&&e.bands.length>0&&(e.forceNonfitting=!1);let o=A("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){o.finish(!0);return}let i=[],a=[],l=!0;o.loopWithFrame(c=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(n)){c.breakLoop();return}for(;s.positions.length-a.length>0;){let u=0;for(;a.includes(u);)u++;let d=s.positions[u];if(d.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(d.flowChunk))break;for(let g=u+1;g<s.positions.length;g++){if(a.includes(g))continue;let m=s.positions[g];if(m.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(m.flowChunk))break;m.flowChunk.isBetter(d.flowChunk)&&(d=m,u=g)}let h=d.flowChunk,f=!0;if(e.layout(d.chunkPosition,l,s.breakAfter).then(g=>{if(e.pageFloatLayoutContext.isInvalidated()){c.breakLoop();return}if(l=!1,d.flowChunk.repeated&&(g===null||h.exclusive)&&i.push(u),h.exclusive){a.push(u),c.breakLoop();return}else{let m=!!g||!!e.pageBreakType,x=this.getLastAfterPositionIfDeferredFloatsExists(e,g);if(e.pageBreakType&&x?(d.chunkPosition=x,s.breakAfter=e.pageBreakType,e.pageBreakType=null):(a.push(u),(g||x)&&(d.chunkPosition=g||x,i.push(u)),s.startBreakType=Fc(e.pageBreakType)),m){c.breakLoop();return}}e.forceNonfitting=!1,f?f=!1:c.continueLoop()}),f){f=!1;return}}c.breakLoop()}).then(()=>{if(!e.pageFloatLayoutContext.isInvalidated()){s.positions=s.positions.filter((u,d)=>i.includes(d)||!a.includes(d)),s.breakAfter==="column"&&(s.breakAfter=null),e.saveDistanceToBlockEndFloats();let c=e.pageFloatLayoutContext.getMaxReachedAfterEdge();e.updateMaxReachedAfterEdge(c)}o.finish(!0)})}),o.result()}createLayoutConstraint(e){let n=this.currentLayoutPosition.page-1,s=this.counterStore.createLayoutConstraint(n);return new Aa([s].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,n,s,o,i,a,l,c,u,d,h,f,g,m){let x=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,E=i.element,C=new xn(c,le.COLUMN,null,l,null,null,null),y=this.currentLayoutPosition.clone(),N=A("createAndLayoutColumn"),S;return N.loopWithFrame(v=>{let k=this.createLayoutConstraint(C);if(u>1){let R=this.viewport.document.createElement("div");if(w(R,"position","absolute"),E.appendChild(R),S=new Ds(R,g,this.clientLayout,k,C),S.forceNonfitting=m,S.vertical=i.vertical,S.rtl=i.rtl,S.snapHeight=i.snapHeight,S.snapWidth=i.snapWidth,i.vertical){let z=(i.rtl?u-a-1:a)*(h+d)+i.paddingTop,te=parseFloat(E.style.width);S.setHorizontalPosition(i.paddingLeft+te-i.width,i.width),S.setVerticalPosition(z,h)}else{let z=(i.rtl?u-a-1:a)*(h+d)+i.paddingLeft;S.setVerticalPosition(i.paddingTop,i.height),S.setHorizontalPosition(z,h)}S.originX=n,S.originY=s}else S=new Ds(E,g,this.clientLayout,k,C),S.copyFrom(i);S.exclusions=x?[]:o.concat(),S.innerShape=f,C.setContainer(S),(S.vertical?S.height:S.width)>=0?this.layoutColumn(S,l).then(()=>{C.isInvalidated()||C.finish(),S.pageFloatLayoutContext.isInvalidated()&&!c.isInvalidated()?(S.pageFloatLayoutContext.validate(),this.currentLayoutPosition=y.clone(),S.element!==E&&E.removeChild(S.element),v.continueLoop()):v.breakLoop()}):(C.finish(),v.breakLoop())}).then(()=>{N.finish(S)}),N.result()}setPagePageFloatLayoutContextContainer(e,n,s){(n instanceof $i||n instanceof zs&&!(n instanceof pn))&&e.setContainer(s)}getRegionPageFloatLayoutContext(e,n,s,o){n instanceof dn;let i=n.getProp(this,"writing-mode")||null,a=n.getProp(this,"direction")||null;return new xn(e,le.REGION,s,o,null,i,a)}layoutFlowColumnsWithBalancing(e,n,s,o,i,a,l,c,u){let d=this.currentLayoutPosition.clone(),h=this.getRegionPageFloatLayoutContext(a,n,l,c),f=!0,g=()=>(this.currentLayoutPosition=d.clone(),this.layoutFlowColumns(e,n,s,o,i,a,h,l,c,u,f).thenAsync(m=>m?T({columns:m,position:this.currentLayoutPosition}):T(null)));return g().thenAsync(m=>{if(!m)return T(null);if(u<=1)return T(m.columns);let x=n.getProp(this,"column-fill")||b.balance,E=this.currentLayoutPosition.flowPositions[c];let C=Jf(u,x,g,h,l,m.columns,E);return C?(f=!1,a.lock(),h.lock(),C.balanceColumns(m).thenAsync(y=>(a.unlock(),a.validate(),h.unlock(),this.currentLayoutPosition=y.position,T(y.columns)))):T(m.columns)})}layoutFlowColumns(e,n,s,o,i,a,l,c,u,d,h){let f=A("layoutFlowColumns"),g=this.currentLayoutPosition.clone(),m=n.getPropAsNumber(this,"column-gap"),x=d>1?n.getPropAsNumber(this,"column-width"):c.vertical?c.height:c.width,E=n.getActiveRegions(this),C=n.getProp(this,"shape-inside"),y=Br(C,0,0,c.width,c.height,this),N=new el(u,this,this.viewport,this.styler,E,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer),S=0,v=null,k=[];return f.loopWithFrame(R=>{this.createAndLayoutColumn(n,s,o,i,c,S++,u,l,d,m,x,y,N,h).then(z=>{if(a.isInvalidated()){k=null,R.breakLoop();return}if((!!z.pageBreakType&&z.pageBreakType!=="column"||S===d)&&!l.isInvalidated()&&l.finish(),l.isInvalidated()){S=0,this.currentLayoutPosition=g.clone(),l.validate(),l.isLocked()?(k=null,R.breakLoop()):R.continueLoop();return}v=z,k[S-1]=v,v.pageBreakType&&v.pageBreakType!="column"&&(S=d,v.pageBreakType!="region"&&(this.pageBreaks[u]=!0)),S<d?R.continueLoop():R.breakLoop()})}).then(()=>{f.finish(k)}),f.result()}layoutContainer(e,n,s,o,i,a,l){n.reset();let c=n.getProp(this,"enabled");if(c&&c!==b._true)return T(!0);let u=A("layoutContainer"),h=n.getProp(this,"wrap-flow")===b.auto,f=n.getProp(this,"flow-from"),g=this.viewport.document.createElement("div");g.role=n instanceof Xi?"complementary":"presentation";let m=n.getProp(this,"position");w(g,"position",m?m.name:"absolute");let x=n instanceof pn;n instanceof dn?s.appendChild(g):s.insertBefore(g,s.firstChild);let C=new Co(g);C.vertical=n.vertical,C.rtl=n.rtl,C.borderBoxSizing=n.borderBoxSizing,C.exclusions=a,n.prepareContainer(this,C,e,this.faces,this.clientLayout),n instanceof pn&&(C.width<=0||C.height<=0)&&F.warn("Negative or zero page area size"),C.originX=o,C.originY=i,o+=C.left+C.marginLeft+C.borderLeft,i+=C.top+C.marginTop+C.borderTop,this.setPagePageFloatLayoutContextContainer(l,n,C);let y,N=!1;if(!f||!f.isIdent()){let S=n.getProp(this,"content");if(S instanceof B&&S.expr instanceof q&&S.expr.str.startsWith("running-element-"))S.visit(new bn(g,this,S,this.counterStore.getExprContentListener()));else if(S&&vt(S)){let v="span";S.url&&(v="img");let k=this.viewport.document.createElement(v);S.visit(new bn(k,this,S,this.counterStore.getExprContentListener())),g.appendChild(k),v=="img"&&n.transferSingleUriContentProps(this,k,this.faces),n.transferContentProps(this,C,e,this.faces),v=="span"&&Mf(k,n.getProp(this,"text-autospace"),n.getProp(this,"text-spacing-trim"),n.getProp(this,"hanging-punctuation"),this.lang,n.vertical)}else n.suppressEmptyBoxGeneration&&(s.removeChild(g),N=!0);N||n.finishContainer(this,C,e,null,1,this.clientLayout,this.faces),y=T(!0)}else if(this.pageBreaks[f.toString()])l.isInvalidated()||n.finishContainer(this,C,e,null,1,this.clientLayout,this.faces),y=T(!0);else{let S=A("layoutContainer.inner"),v=f.toString(),k=n.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,n,o,i,a,l,C,v,k).then(R=>{if(!l.isInvalidated()){let z=R[0];z.element===g&&(C=z),C.computedBlockSize=Math.max.apply(null,R.map(Ke=>Ke.computedBlockSize)),n.finishContainer(this,C,e,z,k,this.clientLayout,this.faces);let te=this.currentLayoutPosition.flowPositions[v];te&&te.breakAfter==="region"&&(te.breakAfter=null)}S.finish(!0)}),y=S.result()}return y.then(()=>{if(l.isInvalidated()){u.finish(!0);return}if(!n.isAutoHeight||Math.floor(C.computedBlockSize)>0){if(!N&&!h){let v=n.getProp(this,"shape-outside"),k=C.getOuterShape(v,this);a.push(k)}}else if(n.children.length==0){s.removeChild(g),u.finish(!0);return}let S=x?0:n.children.length-1;u.loop(()=>{for(;S>=0&&S<n.children.length;){let v=n.children[x?S++:S--],k=this.layoutContainer(e,v,g,o,i,a,l);if(k.isPending())return k.thenAsync(()=>T(!l.isInvalidated()));if(l.isInvalidated())break}return T(!1)}).then(()=>{u.finish(!0)})}),u.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let o=s.positions.length-1;o>=0;o--){let i=s.positions[o];i.flowChunk.startPage>=0&&i.flowChunk.startPage+i.flowChunk.linger-1<=e&&s.positions.splice(o,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let o=s.positions.length-1;o>=0;o--){let i=s.positions[o];i.flowChunk.startPage<0&&i.flowChunk.startOffset<this.lookupOffset&&(i.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let n in this.primaryFlows){let s=e.flowPositions[n];if(s&&s.positions.length>0)return!1}return!0}layoutNextPage(e,n){var g;let s=e.container===e.bleedBox;this.pageBreaks={},n?(this.currentLayoutPosition=n.clone(),this.styler.replayFlowElementsFromOffset(n.highestSeenOffset)):(this.currentLayoutPosition=new ta,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),n=this.currentLayoutPosition;let o=1e4;if(n.page>o)throw new Error(`Too many pages generated (over ${o} pages)`);let i=n.startSideOfFlow("body");n.isBlankPage=_n(i)&&this.matchPageSide(i),e.isBlankPage=n.isBlankPage,n.page++,e.pageType==null&&(e.pageType=(g=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?g:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=n.clone();let a=s?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.styler.cascade.applyVarFilter([a],this.styler,null),this.styler.cascade.applyCalcFilter(a,this.styler.context),!s){let m=new J(this.style.pageScope,"left-page");e.side=m.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let l=this.selectPageMaster(a);if(!l)return T(null);let c=0;if(!s){e.setAutoPageWidth(l.pageBox.specified.width.value===Fn),e.setAutoPageHeight(l.pageBox.specified.height.value===Bn),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(a,this);let m=Cp(ji(a),this);this.setPageSizeAndBleed(m,e),yg(a,m,e,this),c=m.bleedOffset+m.bleed}let u=!s&&l.getProp(this,"writing-mode")||b.horizontal_tb;this.pageVertical=u!=b.horizontal_tb;let d=l.getProp(this,"direction")||b.ltr,h=new xn(this.rootPageFloatLayoutContext,le.PAGE,null,null,null,u,d),f=A("layoutNextPage");return f.loopWithFrame(m=>{this.layoutContainer(e,l,e.bleedBox,c,c,[],h).then(()=>{h.isInvalidated()||h.finish(),h.isInvalidated()?(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),h.validate(),m.continueLoop()):m.breakLoop()})}).then(()=>{l.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),n=this.currentLayoutPosition,Object.keys(n.flowPositions).forEach(x=>{let E=n.flowPositions[x],C=E.breakAfter;C&&(C==="page"||!this.matchPageSide(C))&&(E.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,n.highestSeenOffset=this.styler.getReachedOffset();let m=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(m,this.clientLayout),this.noMorePrimaryFlows(n)&&(n=null),f.finish(n)}),f.result()}setPageSizeAndBleed(e,n){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,n.container.style.width=`${this.pageSheetWidth}px`,n.container.style.height=`${this.pageSheetHeight}px`,n.bleedBox.style.left=`${e.bleedOffset}px`,n.bleedBox.style.right=`${e.bleedOffset}px`,n.bleedBox.style.top=`${e.bleedOffset}px`,n.bleedBox.style.bottom=`${e.bleedOffset}px`,n.bleedBox.style.padding=`${e.bleed}px`}},wp=class r extends wn{constructor(e,n,s,o){super(e.rootScope,e,n,s,o,e.validatorSet,!s);this.masterHandler=e;p(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(e,n,s){let o=new Vo(this.masterHandler.pageScope,e,n,s,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new Ya(o.scope,this.masterHandler,o,this.validatorSet))}startWhenRule(e){let n=e.expr;this.condition!=null&&(n=Qe(this.scope,this.condition,n)),this.masterHandler.pushHandler(new r(this.masterHandler,n,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new Ca(this.scope,this.owner))}startFontFaceRule(){let e={};this.masterHandler.fontFaces.push({properties:e,condition:this.condition}),this.masterHandler.pushHandler(new Fs(this.scope,this.owner,null,e,this.masterHandler.validatorSet,"font-face"))}startFlowRule(e){let n=this.masterHandler.flowProps[e];n||(n={},this.masterHandler.flowProps[e]=n),this.masterHandler.pushHandler(new Fs(this.scope,this.owner,null,n,this.masterHandler.validatorSet))}startViewportRule(){let e={};this.masterHandler.viewportProps.push(e),this.masterHandler.pushHandler(new Fs(this.scope,this.owner,this.condition,e,this.masterHandler.validatorSet))}startFootnoteRule(e){let n=this.masterHandler.footnoteProps;if(e){let s=Po(n,"_pseudos");n=s[e],n||(n={},s[e]=n)}this.masterHandler.pushHandler(new Fs(this.scope,this.owner,null,n,this.masterHandler.validatorSet))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let e=new Za(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(e),e.startPageRule()}startRuleBody(){if(wn.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let e=`R${this.masterHandler.regionCount++}`;this.special("region-id",L(e)),this.endRule();let n=new r(this.masterHandler,this.condition,this,e);this.masterHandler.pushHandler(n),n.startRuleBody()}}},il=class extends _r{constructor(e){super();this.validatorSet=e;p(this,"rootScope");p(this,"pageScope");p(this,"rootBox");p(this,"cascadeParserHandler");p(this,"regionCount",0);p(this,"fontFaces",[]);p(this,"footnoteProps",{});p(this,"flowProps",{});p(this,"viewportProps",[]);p(this,"pageProps",{});this.rootScope=new ds(null),this.pageScope=new ds(this.rootScope),this.rootBox=new Ga(this.rootScope),this.cascadeParserHandler=new wp(this,null,null,null),this.slave=this.cascadeParserHandler}};function Ab(r,t){return t.parseOPSResource(r)}var rl=class extends bs{constructor(e){super(Ab,"document");this.fontDeobfuscator=e;p(this,"styleByKey",{});p(this,"styleFetcherByKey",{});p(this,"styleByDocURL",{});p(this,"triggersByDocURL",{});p(this,"validatorSet",null);p(this,"styleSheets",[]);p(this,"triggerSingleDocumentPreprocessing",!1)}init(e,n){this.setStyleSheets(e,n);let s=A("OPSDocStore.init");return this.validatorSet=Yd(),kb().then(()=>{this.triggerSingleDocumentPreprocessing=!0,s.finish(!0)}),s.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,n){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),n&&n.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let n=e.url;n&&(n=Q(Rn(n),hn)),this.styleSheets.push({url:n,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let n=e.url;n&&(n=Q(Rn(n),hn)),this.styleSheets.push({url:n,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let n=A("OPSDocStore.load"),s=e.url,o=s.endsWith("?viv-toc-box");return Np(e,this).then(i=>{var f;if(!i){n.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let g=He("PREPROCESS_SINGLE_DOCUMENT");for(let m=0;m<g.length;m++)try{g[m](i.document)}catch(x){F.warn("Error during single document preprocessing:",x)}}let a=[],l=i.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let g=0;g<l.length;g++){let m=l[g],x=m.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),E=m.getAttributeNS("http://www.w3.org/2001/xml-events","event"),C=m.getAttribute("action"),y=m.getAttribute("ref");x&&E&&C&&y&&a.push({observer:x,event:E,action:C,ref:y})}this.triggersByDocURL[s]=a;let c=[];if(c.push({url:Q("user-agent-page.css",Kt),text:Sc,flavor:"UA",classes:null,media:null}),o)c.push({url:Q("user-agent-toc.css",Kt),text:vc,flavor:"UA",classes:null,media:null});else{let g=i.document.querySelectorAll("style, link, meta");for(let m of g){let x=m.namespaceURI,E=m.localName;if(x=="http://www.w3.org/1999/xhtml")if(E=="style"){let C=m.getAttribute("class"),y=m.getAttribute("media"),N=m.getAttribute("title");c.push({url:s,text:m.textContent,flavor:"Author",classes:N?C:null,media:y})}else if(E=="link"){let C=m.getAttribute("href"),y=(f=m.getAttribute("rel"))==null?void 0:f.split(/\s+/),N=m.getAttribute("class"),S=m.getAttribute("media");if(C&&(y!=null&&y.includes("stylesheet"))&&(!y.includes("alternate")||N)){let v=Q(C,s),k=m.getAttribute("title");c.push({url:v,text:null,classes:k?N:null,media:S,flavor:"Author"})}}else E=="meta"&&m.getAttribute("name")=="viewport"&&c.push({url:s,text:this.processViewportMeta(m),flavor:"Author",classes:null,media:null})}for(let m=0;m<this.styleSheets.length;m++)c.push(this.styleSheets[m])}let u="";for(let g=0;g<c.length;g++)u+=c[g].url,u+="^",c[g].text&&(u+=c[g].text),u+="^";let d=this.styleByKey[u];if(d){this.styleByDocURL[s]=d,n.finish(i);return}let h=this.styleFetcherByKey[u];h||(h=new nn(()=>{let g=A("fetchStylesheet"),m=0,x=new il(this.validatorSet);return g.loop(()=>{if(m<c.length){let E=c[m++];return x.startStylesheet(E.flavor),E.text!==null?Wr(E.text,x,E.url,E.classes,E.media).thenReturn(!0):kc(E.url,x,E.classes,E.media)}return T(!1)}).then(()=>{let E=x.cascadeParserHandler.finish();d=new Tp(this,x.rootScope,x.pageScope,E,x.rootBox,x.fontFaces,x.footnoteProps,x.flowProps,x.viewportProps,x.pageProps),this.styleByKey[u]=d,delete this.styleFetcherByKey[u],g.finish(d)}),g.result()},`FetchStylesheet ${s}`),this.styleFetcherByKey[u]=h,h.start()),h.get().then(g=>{this.styleByDocURL[s]=g,n.finish(i)})}),n.result()}processViewportMeta(e){return""}};var qi="\u25B8",Lg="\u25BE",Lb="\u25B9";function ll(r){let t=Array.from(r.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(r.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let e="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of r.querySelectorAll(e)){if(t.find(o=>o.contains(n)))continue;let s=n;/^h[1-6]$/.test(s.localName)&&(s.previousElementSibling?s=s.nextElementSibling:s=s.parentElement),s&&s.querySelector("li a[href]")&&t.push(s)}return t}function Rg(r){let t=ll(r),e=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))e.push(s);return e}var al=class{constructor(t,e,n,s,o,i,a,l,c,u){this.store=t;this.url=e;this.lang=n;this.clientLayout=s;this.fontMapper=o;this.rendererFactory=a;this.fallbackMap=l;this.documentURLTransformer=c;this.counterStore=u;p(this,"pref");p(this,"page",null);p(this,"instance",null);this.pref=wr(i),this.pref.spreadView=!1}setAutoHeight(t,e){if(e--!=0){for(let n=t.firstChild;n;n=n.nextSibling)if(n.nodeType==1){let s=n;Ot(s,"height","auto")!="auto"&&(w(s,"height","auto"),this.setAutoHeight(s,e)),Ot(s,"position","static")=="absolute"&&(w(s,"position","relative"),this.setAutoHeight(s,e))}}}makeCustomRenderer(t){let e=this.rendererFactory.makeCustomRenderer(t);return(n,s,o)=>{let i=o.behavior;if(i)switch(i.toString()){case"toc-node-anchor":o.color=b.inherit,o["text-decoration"]=b.none;break;case"toc-node":o.display=b.block,o.margin=ne,o.padding=ne,o["padding-inline-start"]=new P(1.25,"em");break;case"toc-node-first-child":o.display=b.inline_block,o.margin=new P(.2,"em"),o["vertical-align"]=b.top,o.color=b.inherit,o["text-decoration"]=b.none;break;case"toc-container":o.padding=ne;break}if(!i||i.toString()!="toc-node"&&i.toString()!="toc-container")return e(n,s,o);let a=n.firstChild;a&&a.nodeType!==1&&de(a)&&n.replaceChild(n.ownerDocument.createComment(a.textContent),a);let l=s.getAttribute("data-adapt-class");if(l=="toc-node"){let u=s.firstChild;u.textContent!=qi&&(u.textContent=qi,w(u,"cursor","pointer"),u.addEventListener("click",Rb,!1),u.setAttribute("role","button"),u.setAttribute("aria-expanded","false"),s.setAttribute("aria-expanded","false"),s.style.height!=="0px"&&(u.tabIndex=0))}let c=s.ownerDocument.createElement("div");if(c.setAttribute("data-adapt-process-children","true"),i.toString()=="toc-node"){let u=s.ownerDocument.createElement("div");if(u.textContent=Lb,w(u,"margin","0.2em 0 0 -1em"),w(u,"margin-inline-start","-1em"),w(u,"margin-inline-end","0"),w(u,"display","inline-block"),w(u,"width","1em"),w(u,"text-align","center"),w(u,"vertical-align","top"),w(u,"cursor","default"),w(u,"font-family","Menlo,sans-serif"),c.appendChild(u),w(c,"overflow","hidden"),c.setAttribute("data-adapt-class","toc-node"),c.setAttribute("role","treeitem"),l=="toc-node"||l=="toc-container"){w(c,"height","0px");let d=n.firstElementChild;d&&d.localName==="a"&&(d.tabIndex=-1)}else s.setAttribute("role","tree")}else l=="toc-node"&&(c.setAttribute("data-adapt-class","toc-container"),c.setAttribute("role","group"),c.setAttribute("aria-hidden","true"));return T(c)}}showTOC(t,e,n,s,o){if(this.page)return T(this.page);let i=A("showTOC"),a=new mo(t,t);this.page=a;let l=At(this.url)+"?viv-toc-box";return this.store.load(l).then(c=>{for(let g of ll(c.document))g.setAttribute("data-vivliostyle-role","doc-toc");let u=this.store.getStyleForDoc(c),d=u.sizeViewport(n,1e5,o);e=new An(e.window,d.fontSize,0,e.root,d.width,d.height);let h=this.makeCustomRenderer(c),f=new ss(u,c,this.lang,e,this.clientLayout,this.fontMapper,h,this.fallbackMap,0,this.documentURLTransformer,this.counterStore);this.instance=f,f.pref=this.pref,f.init().then(()=>{f.layoutNextPage(a,null).then(()=>{this.setAutoHeight(t,2),i.finish(a)})})}),i.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function t(s){if(!s)return[];let o=s.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(o).map(e)}function e(s){let o=new URL(s.href),[,i]=o.hash.match(/^#?(.*)$/),a=s.innerText,l=s.parentElement.querySelector("[role=group]"),c=t(l);return{id:i,title:a,children:c}}let n=this.page.container.querySelector("[role=tree]");return t(n)}};function Rb(r){let t=r.target,e=t.textContent==qi;t.textContent=e?Lg:qi;let n=t.parentNode;t.setAttribute("aria-expanded",e?"true":"false"),n.setAttribute("aria-expanded",e?"true":"false");let s=n.firstChild;for(;s;){if(s.nodeType===1){let o=s,i=o.getAttribute("data-adapt-class");if(i==="toc-container"){if(o.setAttribute("aria-hidden",e?"false":"true"),o.firstChild){s=o.firstChild;continue}}else if(i==="toc-node"&&(o.style.height=e?"auto":"0px",o.children.length>=2&&(o.children[1].tabIndex=e?0:-1),o.children.length>=3&&(o.children[0].tabIndex=e?0:-1,!e))){let a=o.children[0];if(a.textContent==Lg){a.textContent=qi,a.setAttribute("aria-expanded","false"),o.setAttribute("aria-expanded","false"),s=o.children[2];continue}}}for(;!s.nextSibling&&s.parentNode!==n;)s=s.parentNode;s=s.nextSibling}r.stopPropagation()}var Qi=class extends rl{constructor(){super(null);p(this,"plainXMLStore");p(this,"jsonStore");p(this,"opfByURL",{});p(this,"primaryOPFByEPubURL",{});p(this,"deobfuscators",{});p(this,"documents",{});this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=Pg(),this.jsonStore=Nh()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,n,s){return this.plainXMLStore.load(e,n,s)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,n,s){return this.jsonStore.load(e,n,s)}loadPubDoc(e){let n=A("loadPubDoc");return xs(e,null,"HEAD").then(s=>{if(s.status>=400)this.loadEPUBDoc(e).then(o=>{if(o){n.finish(o);return}F.error(`Failed to fetch a source document from ${e} (${s.status}${s.statusText?" "+s.statusText:""})`),n.finish(null)});else if(!s.status&&!s.responseXML&&!s.responseText&&!s.responseBlob&&!s.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),s.contentType=="application/oebps-package+xml"||/\.opf(?:[#?]|$)/.test(e)){let[,o,i]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(o,i).thenFinish(n)}else s.contentType=="application/ld+json"||s.contentType=="application/webpub+json"||s.contentType=="application/audiobook+json"||s.contentType=="application/json"||/\.json(?:ld)?(?:[#?]|$)/.test(e)?this.loadAsJSON(e,!0).then(o=>{if(!o){this.reportLoadError(e),n.finish(null);return}let i=new Ws(this,e);i.initWithWebPubManifest(o,void 0,e).then(()=>{n.finish(i)})}):this.loadWebPub(e).then(o=>{if(o){n.finish(o);return}this.loadEPUBDoc(e).then(i=>{if(i){n.finish(i);return}F.error(`Failed to load ${e}.`),n.finish(null)})})}),n.result()}loadEPUBDoc(e){let n=A("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let s=e+"META-INF/container.xml";return this.loadAsPlainXML(s).then(o=>{if(o){let i=o.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let a of i)if(a){this.loadOPF(e,a).thenFinish(n);return}}n.finish(null)}),n.result()}loadOPF(e,n){let s=e+n,o=this.opfByURL[s];if(o)return T(o);let i=A("loadOPF");return this.loadAsPlainXML(s,!0,`Failed to fetch EPUB OPF ${s}`).then(a=>{a?(o=new Ws(this,e),this.opfByURL[s]=o,this.primaryOPFByEPubURL[e]=o,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(l=>{o.initWithXMLDoc(a,l).then(()=>{i.finish(o)})}):o.initWithXMLDoc(a,null).then(()=>{i.finish(o)})):this.reportLoadError(s)}),i.result()}loadWebPub(e){let n=A("loadWebPub");return this.load(e).then(s=>{if(!s)this.reportLoadError(e);else if(s.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))n.finish(null);else{let o=s.document,i=new Ws(this,e),a=o.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(a){let l=a.getAttribute("href");if(/^#/.test(l)){let c=js(o.getElementById(l.substr(1)).textContent);i.initWithWebPubManifest(c,o).then(()=>{n.finish(i)})}else{let c=Q(a.getAttribute("href"),e);this.loadAsJSON(c,!0,`Failed to fetch Publication Manifest ${c}`).then(u=>{i.initWithWebPubManifest(u,o,c).then(()=>{n.finish(i)})})}}else i.initWithWebPubManifest({},o).then(()=>{i.toc&&i.toc.src===s.url&&ll(o).length===0&&(i.toc=null),n.finish(i)})}}),n.result()}addDocument(e,n){let s=A("EPUBDocStore.load"),o=At(e);return(this.documents[o]=this.parseOPSResource({status:200,statusText:"",url:o,contentType:n.contentType,responseText:null,responseXML:n,responseBlob:null})).thenFinish(s),s.result()}reportLoadError(e){let n=o=>o.replace(/([^:/?#]|^)[/?#].*/,"$1"),s=()=>{let o=n(e);return!(o===n(hn)||Object.keys(this.resources).find(a=>this.resources[a]&&n(a)===o)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?F.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&hn.startsWith("https:")?F.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):s()?F.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):F.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let n=At(e),s=this.documents[n];if(s)return s.isPending()?s:T(s.get());{let o=A("EPUBDocStore.load");return s=super.load(n,!0,`Failed to fetch a source document from ${n}`),s.then(i=>{i?o.finish(i):this.reportLoadError(n)}),o.result()}}processViewportMeta(e){let n=e.getAttribute("content");if(!n)return"";let s={},o;for(;(o=n.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)n=n.substr(o[0].length),s[o[1]]=o[2];let i=s.width-0,a=s.height-0;if(i&&a){let l=!!Object.values(this.primaryOPFByEPubURL).find(c=>c.prePaginated);return`@-epubx-viewport{width:${i}px;height:${a}px;}`+(l?`@page{size:${i}px ${a}px;margin:0;}`:"@page{margin:0;}")}return""}},ul=class{constructor(){p(this,"id",null);p(this,"src","");p(this,"mediaType",null);p(this,"title",null);p(this,"itemRefElement",null);p(this,"spineIndex",-1);p(this,"compressedSize",0);p(this,"compressed",null);p(this,"epage",0);p(this,"epageCount",0);p(this,"startPage",null);p(this,"skipPagesBefore",null);p(this,"itemProperties");this.itemProperties=Wp}initWithElement(t,e){this.id=t.getAttribute("id"),this.src=Q(t.getAttribute("href"),e),this.mediaType=t.getAttribute("media-type");let n=t.getAttribute("properties");n&&(this.itemProperties=jp(n.split(/\s+/)))}initWithParam(t){this.spineIndex=t.index,this.id=`item${t.index+1}`,this.src=t.url,this.startPage=t.startPage,this.skipPagesBefore=t.skipPagesBefore}};function Vb(r){return r.id}function Fb(r){return t=>{let e=A("deobfuscator");return Bb("SHA-1",r).then(n=>{let s=t.slice(0,1040),o=t.slice(1040,t.size);Eh(s).then(i=>{let a=new DataView(i);for(let l=0;l<a.byteLength;l++){let c=a.getUint8(l);c^=n[l%20],a.setUint8(l,c)}e.finish(wc([a,o]))})}),e.result()}}function Bb(r,t){let e=A("makeDigest"),n=e.suspend();return window.crypto.subtle.digest(r,new TextEncoder().encode(t)).then(s=>{n.schedule(new Uint8Array(s))}),e.result()}var os={dcterms:"http://purl.org/dc/terms/",marc:"http://id.loc.gov/vocabulary/",media:"http://www.idpf.org/epub/vocab/overlays/#",rendition:"http://www.idpf.org/vocab/rendition/#",onix:"http://www.editeur.org/ONIX/book/codelists/current.html#",xsd:"http://www.w3.org/2001/XMLSchema#",opf:"http://www.idpf.org/2007/opf"},Zi="http://idpf.org/epub/vocab/package/meta/#",Ne={language:`${os.dcterms}language`,title:`${os.dcterms}title`,creator:`${os.dcterms}creator`,layout:`${os.rendition}layout`,titleType:`${Zi}title-type`,displaySeq:`${Zi}display-seq`,alternateScript:`${Zi}alternate-script`,role:`${Zi}role`};function Ob(r,t){let e={};return(n,s)=>{var d,h,f,g,m,x;let o,i,a=n.r||e,l=s.r||e;if(r==Ne.title&&(o=((d=a[Ne.titleType])==null?void 0:d[0].v)=="main",i=((h=l[Ne.titleType])==null?void 0:h[0].v)=="main",o!=i))return o?-1:1;let c=parseInt((f=a[Ne.displaySeq])==null?void 0:f[0].v,10);isNaN(c)&&(c=Number.MAX_VALUE);let u=parseInt((g=l[Ne.displaySeq])==null?void 0:g[0].v,10);return isNaN(u)&&(u=Number.MAX_VALUE),c!=u?c-u:r!=Ne.language&&t&&(o=((m=a[Ne.language]||a[Ne.alternateScript])==null?void 0:m[0].v)==t,i=((x=l[Ne.language]||l[Ne.alternateScript])==null?void 0:x[0].v)==t,o!=i)?o?-1:1:n.o-s.o}}function Db(r,t){let e;if(!t)e=os;else{e={};for(let h in os)e[h]=os[h];let d;for(;(d=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(d[0].length),e[d[1]]=d[2]}let n=d=>{if(d){let h=d.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(h){let f=h[2]?e[h[2]]:Zi;if(f)return f+h[3]}}return null},s=1,o=r.childElements().forEachNonNull(d=>{if(d.localName=="meta"){let h=n(d.getAttribute("property"));if(h)return{name:h,value:d.textContent,id:d.getAttribute("id"),order:s++,refines:d.getAttribute("refines"),lang:null,scheme:n(d.getAttribute("scheme")),role:null}}else if(d.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:os.dcterms+d.localName,order:s++,lang:d.getAttribute("xml:lang"),value:d.textContent,id:d.getAttribute("id"),refines:null,scheme:null,role:d.getAttribute("role")||d.getAttribute("opf:role")};return null}),i=cr(o,d=>d.refines),a=d=>Yp(d,(h,f)=>h.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let x=i[`#${g.id}`]||[];if(x.length||g.lang||g.role){g.lang&&x.push({name:Ne.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&x.push({name:Ne.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let E=cr(x,C=>C.name);m.r=a(E)}return m})),l=a(cr(o,d=>d.refines?null:d.name)),c=null;l[Ne.language]&&(c=l[Ne.language][0].v);let u=d=>{for(let h in d){let f=d[h];f.sort(Ob(h,c));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(l),l}function Mb(){let r=window.MathJax;return r?r.Hub:null}var Ig={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Pp="viv-id-",Ws=class{constructor(t,e){this.store=t;this.pubURL=e;p(this,"opfXML",null);p(this,"encXML",null);p(this,"items",null);p(this,"spine",null);p(this,"itemMap",null);p(this,"itemMapByPath",null);p(this,"uid",null);p(this,"bindings",{});p(this,"lang",null);p(this,"epageCount",0);p(this,"prePaginated",!1);p(this,"epageIsRenderedPage",!0);p(this,"epageCountCallback",null);p(this,"metadata",{});p(this,"toc",null);p(this,"cover",null);p(this,"fallbackMap",{});p(this,"pageProgression",null);p(this,"documentURLTransformer");this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let t=this;class e{transformFragment(s,o){let i=o+(s?`#${s}`:"");return Pp+Fl(i,":")}transformURL(s,o){let i=s.match(/^([^#]*)#?(.*)$/);if(i){let a=i[1]||o.replace(/\?viv-toc-box$/,""),l=decodeURIComponent(i[2]);if(a&&t.spine.some(c=>c.src===a))return`#${this.transformFragment(l,a)}`}return s}restoreURL(s){s.charAt(0)==="#"&&(s=s.substring(1)),s.indexOf(Pp)===0&&(s=s.substring(Pp.length));let i=Xp(s,":").match(/^([^#]*)#?(.*)$/);return i?[i[1],i[2]]:[]}}return new e}getMetadata(){return this.metadata}getPathFromURL(t){if(t.startsWith("data:"))return t===this.pubURL?"":t;if(this.pubURL){let e=Q("",this.pubURL);return t===e||t+"/"===e?"":(e.charAt(e.length-1)!="/"&&(e+="/"),t.substr(0,e.length)==e?decodeURIComponent(t.substr(e.length)):null)}else return t}initWithXMLDoc(t,e){this.opfXML=t,this.encXML=e;let n=t.doc().child("package"),s=n.attribute("unique-identifier")[0];if(s){let c=t.getElement(`${t.url}#${s}`);c&&(this.uid=c.textContent.replace(/[ \n\r\t]/g,""))}let o={};this.items=n.child("manifest").child("item").asArray().map(c=>{let u=new ul,d=c;u.initWithElement(d,t.url);let h=d.getAttribute("fallback");return h&&!Ig[u.mediaType]&&(o[u.src]=h),!this.toc&&u.itemProperties.nav&&(this.toc=u),!this.cover&&u.itemProperties["cover-image"]&&(this.cover=u),u}),this.itemMap=Bl(this.items,Vb),this.itemMapByPath=Bl(this.items,c=>this.getPathFromURL(c.src));for(let c in o){let u=c;for(;;){let d=this.itemMap[o[u]];if(!d)break;if(Ig[d.mediaType]){this.fallbackMap[c]=d.src;break}u=d.src}}this.spine=n.child("spine").child("itemref").asArray().map((c,u)=>{let d=c,h=d.getAttribute("idref"),f=this.itemMap[h];return f&&(f.itemRefElement=d,f.spineIndex=u),f});let i=n.child("spine").attribute("page-progression-direction")[0];i&&(this.pageProgression=Sl(i));let a=e?e.doc().child("encryption").child("EncryptedData").predicate(vp.withChild("EncryptionMethod",vp.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],l=n.child("bindings").child("mediaType").asArray();for(let c=0;c<l.length;c++){let u=l[c].getAttribute("handler"),d=l[c].getAttribute("media-type");d&&u&&this.itemMap[u]&&(this.bindings[d]=this.itemMap[u].src)}if(this.metadata=Db(n.child("metadata"),n.attribute("prefix")[0]),this.metadata[Ne.language]&&(this.lang=this.metadata[Ne.language][0].v),this.metadata[Ne.layout]&&(this.prePaginated=this.metadata[Ne.layout][0].v==="pre-paginated"),a.length>0&&this.uid){let c=Fb(this.uid);for(let u=0;u<a.length;u++)this.store.deobfuscators[this.pubURL+a[u]]=c}return this.prePaginated&&this.assignAutoPages(),T(!0)}assignAutoPages(){let t=0;for(let e of this.spine){let n=this.prePaginated?1:Math.ceil(e.compressedSize/1024);e.epage=t,e.epageCount=n,t+=n}this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(t){this.epageIsRenderedPage=t||this.prePaginated}countEPages(t){if(this.epageCountCallback=t,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),T(!0);let e=0,n=0,s=A("countEPages");return s.loopWithFrame(o=>{if(n===this.spine.length){o.breakLoop();return}let i=this.spine[n++];i.epage=e,this.store.load(i.src).then(a=>{let l=1800,c=a.lang||this.lang;c&&c.match(/^(ja|ko|zh)/)&&(l/=3),i.epageCount=Math.ceil(a.getTotalOffset()/l),e+=i.epageCount,this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount),o.continueLoop()})}).thenFinish(s),s.result()}initWithChapters(t,e){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let n=this.opfXML=new Ki(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return t.forEach(s=>{let o=new ul;o.initWithParam(s),o.id;let i=n.document.createElement("itemref");i.setAttribute("idref",o.id),n.root.appendChild(i),o.itemRefElement=i,this.itemMap[o.id]=o;let a=this.getPathFromURL(s.url);a==null&&(a=s.url),this.itemMapByPath[a]=o,this.items.push(o)}),e?this.store.addDocument(t[0].url,e):T(null)}initWithWebPubManifest(t,e,n){var h,f,g,m;t.readingProgression&&(this.pageProgression=t.readingProgression),this.metadata===void 0&&(this.metadata={});let s=t.name||((h=t.metadata)==null?void 0:h.title)||(e==null?void 0:e.title);s&&(this.metadata[Ne.title]=(Array.isArray(s)?s:[s]).map(x=>{var E;return{v:(E=x.value)!=null?E:x}}));let o=t.author||t.creator||((f=t.metadata)==null?void 0:f.author)||Array.from((g=e==null?void 0:e.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?g:[]).map(x=>x.content);o&&o.length!==0&&(this.metadata[Ne.creator]=(Array.isArray(o)?o:[o]).map(x=>{var E;return{v:(E=x.name)!=null?E:x}}));let i=t.inLanguage||((m=t.metadata)==null?void 0:m.language)||(e==null?void 0:e.documentElement.lang)||(e==null?void 0:e.documentElement.getAttribute("xml:lang"));i&&(this.metadata[Ne.language]=(Array.isArray(i)?i:[i]).map(x=>({v:x})));let a=this.getPathFromURL(this.pubURL);if(!t.readingOrder&&e&&a!==null){t.readingOrder=[encodeURI(a)];for(let x of Rg(e)){let E=x.getAttribute("href");if(/^(https?:)?\/\//.test(E)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(E))continue;let C=At(Q(E,this.pubURL)),y=this.getPathFromURL(C),N=y!==null?encodeURI(y):C;t.readingOrder.indexOf(N)==-1&&t.readingOrder.push(N)}}let l=[],c=0,u=-1;[t.readingOrder,t.resources].forEach(x=>{x instanceof Array&&x.forEach(E=>{let C=x===t.readingOrder,y=typeof E=="string"?E:E.url||E.href,N=typeof E=="string"?"":E.encodingFormat||E.href&&E.type||"";if(C||N==="text/html"||N==="application/xhtml+xml"||!N&&E.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(y)){let S=n?n.replace(/\/[^/]+$/,"/"):this.pubURL,v={url:Q(Rn(y),S),index:c++,startPage:null,skipPagesBefore:null};E.rel==="contents"&&u===-1&&(u=v.index),l.push(v)}})});let d=A("initWithWebPubManifest");return this.initWithChapters(l).then(()=>{var E,C;u!==-1&&(this.toc=this.items[u]),this.toc||(this.toc=n?(E=this.items)==null?void 0:E[0]:this.itemMapByPath[a]);let x=(C=t.readingOrder)==null?void 0:C.length;x&&x<this.items.length&&this.items.splice(x),d.finish(!0)}),d.result()}getCFI(t,e){let n=this.spine[t],s=A("getCFI");return this.store.load(n.src).then(o=>{let i=o.getNodeByOffset(e),a=null;if(i){let l=o.getNodeOffset(i,0,!1),c=e-l,u=new Ho;u.prependPathFromNode(i,c,!1,null),n.itemRefElement&&u.prependPathFromNode(n.itemRefElement,0,!1,null),a=u.toString()}s.finish(a)}),s.result()}resolveFragment(t){return Cn("resolveFragment",e=>{if(!t){e.finish(null);return}let n=new Ho;n.fromString(t);let s;if(this.opfXML){let o=n.navigate(this.opfXML.document);if(o.node.nodeType!=1||o.after||!o.ref){e.finish(null);return}let i=o.node,a=i.getAttribute("idref");if(i.localName!="itemref"||!a||!this.itemMap[a]){e.finish(null);return}s=this.itemMap[a],n=o.ref}else s=this.spine[0];this.store.load(s.src).then(o=>{let i=n.navigate(o.document),a=o.getNodeOffset(i.node,i.offset,i.after);e.finish({spineIndex:s.spineIndex,offsetInItem:a,pageIndex:-1})})},(e,n)=>{F.warn(n,"Cannot resolve fragment:",t),e.finish(null)})}resolveEPage(t){return Cn("resolveEPage",e=>{if(t<=0){e.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let o=this.spine.findIndex(l=>l.epage==0&&l.epageCount==0||l.epage<=t&&l.epage+l.epageCount>t);o==-1&&(o=this.spine.length-1);let i=this.spine[o];(!i||i.epageCount==0)&&(i=this.spine[--o]);let a=Math.floor(t-i.epage);e.finish({spineIndex:o,offsetInItem:-1,pageIndex:a});return}let n=Ct(this.spine.length,o=>{let i=this.spine[o];return i.epage+i.epageCount>t});n==this.spine.length&&n--;let s=this.spine[n];this.store.load(s.src).then(o=>{t-=s.epage,t>s.epageCount&&(t=s.epageCount);let i=0;if(t>0){let a=o.getTotalOffset();i=Math.round(a*t/s.epageCount),i==a&&i--}e.finish({spineIndex:n,offsetInItem:i,pageIndex:-1})})},(e,n)=>{F.warn(n,"Cannot resolve epage:",t),e.finish(null)})}getEPageFromPosition(t){let e=this.spine[t.spineIndex];if(this.epageIsRenderedPage){let s=e.epage+t.pageIndex;return T(s)}if(t.offsetInItem<=0)return T(e.epage);let n=A("getEPage");return this.store.load(e.src).then(s=>{let o=s.getTotalOffset(),i=Math.min(o,t.offsetInItem);n.finish(e.epage+i*e.epageCount/o)}),n.result()}},cl=(r,t)=>({page:r,position:{spineIndex:r.spineIndex,pageIndex:t,offsetInItem:r.offset}}),dl=class{constructor(t,e,n,s,o){this.opf=t;this.viewport=e;this.fontMapper=n;this.pageSheetSizeReporter=o;p(this,"spineItems",[]);p(this,"spineItemLoadingContinuations",[]);p(this,"pref");p(this,"clientLayout");p(this,"counterStore");p(this,"tocAutohide",!1);p(this,"tocVisible",!1);p(this,"tocView");this.pref=wr(s),this.clientLayout=new tl(e),this.counterStore=new Or(t.documentURLTransformer)}getPage(t){let e=this.spineItems[t.spineIndex];return e?e.pages[t.pageIndex]:null}getCurrentPageProgression(t){if(this.opf.pageProgression)return this.opf.pageProgression;{let e=this.spineItems[t?t.spineIndex:0];return e?e.instance.pageProgression:null}}finishPageContainer(t,e,n){e.container.style.display="none",e.container.style.visibility="visible",e.container.style.position="",e.container.style.top="",e.container.style.left="",e.container.setAttribute("data-vivliostyle-page-side",e.side);let s=t.pages[n];if(e.isFirstPage=t.item.spineIndex==0&&n==0,t.pages[n]=e,this.opf.epageIsRenderedPage){if(n==0&&t.item.spineIndex>0){let o=this.opf.spine[t.item.spineIndex-1];t.item.epage=o.epage+o.epageCount}t.item.epageCount=t.pages.length,this.opf.epageCount=this.opf.spine.reduce((o,i)=>o+i.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(s)t.instance.viewport.contentContainer.replaceChild(e.container,s.container),s.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:e});else{let o=null;if(n>0)o=t.pages[n-1].container.nextElementSibling;else for(let i=t.item.spineIndex+1;i<this.spineItems.length;i++){let a=this.spineItems[i];if(a&&a.pages[0]){o=a.pages[0].container;break}}t.instance.viewport.contentContainer.insertBefore(e.container,o)}this.pageSheetSizeReporter({width:t.instance.pageSheetWidth,height:t.instance.pageSheetHeight},t.instance.pageSheetSize,t.item.spineIndex,t.instance.pageNumberOffset+n)}renderSinglePage(t,e){let n=A("renderSinglePage"),s=t.pages[e?e.page:0],o=this.makePage(t,e);return s&&(o.pageType=s.pageType),t.instance.layoutNextPage(o,e).then(i=>{e=i;let a=e?e.page-1:t.layoutPositions.length-1;this.finishPageContainer(t,o,a),this.counterStore.finishPage(o.spineIndex,a);let l=null;if(e){let c=t.layoutPositions[e.page];t.layoutPositions[e.page]=e,c&&t.pages[e.page]&&(e.isSamePosition(c)||(l=this.renderSinglePage(t,e)))}l||(l=T(!0)),l.then(()=>{let c=this.counterStore.getUnresolvedRefsToPage(o),u=0;n.loopWithFrame(d=>{if(u++,u>c.length){d.breakLoop();return}let h=c[u-1];if(h.refs=h.refs.filter(f=>!f.isResolved()),h.refs.length===0){d.continueLoop();return}this.getPageViewItem(h.spineIndex).then(f=>{if(!f){d.continueLoop();return}let{currentPageType:g,previousPageType:m}=f.instance.styler.cascade,x=f.instance.scopes;f.instance.scopes={},this.counterStore.pushPageCounters(h.pageCounters),this.counterStore.pushReferencesToSolve(h.refs);let E=f.layoutPositions[h.pageIndex];this.renderSinglePage(f,E).then(C=>{f.instance.styler.cascade.currentPageType=g,f.instance.styler.cascade.previousPageType=m,f.instance.scopes=x,this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve();let y=C.pageAndPosition.position;y.spineIndex===o.spineIndex&&y.pageIndex===a&&(o=C.pageAndPosition.page),d.continueLoop()})})}).then(()=>{o.container.parentElement||(o=t.pages[a]),o.isLastPage=!e&&t.item.spineIndex===this.opf.spine.length-1,o.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),o.container.setAttribute("data-vivliostyle-page-index",a),o.container.setAttribute("data-vivliostyle-spine-index",o.spineIndex),n.finish({pageAndPosition:cl(o,a),nextLayoutPosition:e})})})}),n.result()}normalizeSeekPosition(t,e){let n=t.pageIndex,s=-1;if(n<0){s=t.offsetInItem;let o=Ct(e.layoutPositions.length,i=>e.instance.getPosition(e.layoutPositions[i],!0)>s);o===e.layoutPositions.length?e.complete?n=e.layoutPositions.length-1:n=Number.POSITIVE_INFINITY:n=o-1}else n===Number.POSITIVE_INFINITY&&t.offsetInItem!==-1&&(s=t.offsetInItem);return{spineIndex:t.spineIndex,pageIndex:n,offsetInItem:s}}findPage(t,e){let n=A("findPage");return this.getPageViewItem(t.spineIndex).then(s=>{if(!s){n.finish(null);return}let o=null,i;n.loopWithFrame(a=>{let l=this.normalizeSeekPosition(t,s);i=l.pageIndex,o=s.pages[i],o?a.breakLoop():s.complete?(i=s.layoutPositions.length-1,o=s.pages[i],a.breakLoop()):e?this.renderPage(l).then(c=>{c&&(o=c.page,i=c.position.pageIndex),a.breakLoop()}):n.sleep(100).then(()=>{a.continueLoop()})}).then(()=>{n.finish(cl(o,i))})}),n.result()}renderPage(t){let e=A("renderPage");return this.getPageViewItem(t.spineIndex).then(n=>{if(!n){e.finish(null);return}let s=this.normalizeSeekPosition(t,n),o=s.pageIndex,i=s.offsetInItem,a=n.pages[o];if(a){e.finish(cl(a,o));return}e.loopWithFrame(l=>{if(o<n.layoutPositions.length){l.breakLoop();return}if(n.complete){o=n.layoutPositions.length-1,l.breakLoop();return}let c=n.layoutPositions[n.layoutPositions.length-1];this.renderSinglePage(n,c).then(u=>{let d=u.pageAndPosition.page;if(c=u.nextLayoutPosition,c){if(i>=0&&n.instance.getPosition(c)>i){a=d,o=n.layoutPositions.length-2,l.breakLoop();return}l.continueLoop()}else a=d,o=u.pageAndPosition.position.pageIndex,n.complete=!0,l.breakLoop()})}).then(()=>{a=a||n.pages[o];let l=n.layoutPositions[o];if(a){e.finish(cl(a,o));return}this.renderSinglePage(n,l).then(c=>{c.nextLayoutPosition||(n.complete=!0),e.finish(c.pageAndPosition)})})}),e.result()}renderAllPages(){let t=A("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(e=>{t.loopWithFrame(n=>{this.spineItems.some(s=>s==null?void 0:s.pages.some(o=>o==null?void 0:o.fetchers.some(i=>!i.arrived)))?t.sleep(100).then(()=>{n.continueLoop()}):n.breakLoop()}).then(()=>{t.finish(e)})}),t.result()}renderPagesUpto(t,e){let n=A("renderPagesUpto");t||(t={spineIndex:0,pageIndex:0,offsetInItem:0});let s=t.spineIndex,o=t.pageIndex,i=0;e&&(i=s);let a;return n.loopWithFrame(l=>{let c={spineIndex:i,pageIndex:i===s?o:Number.POSITIVE_INFINITY,offsetInItem:i===s?t.offsetInItem:-1};this.renderPage(c).then(u=>{a=u,++i>s?l.breakLoop():l.continueLoop()})}).then(()=>{n.finish(a)}),n.result()}firstPage(t,e){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},e)}lastPage(t,e){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},e)}nextPage(t,e){let n=t.spineIndex,s=t.pageIndex,o=A("nextPage");return this.getPageViewItem(n).then(i=>{if(!i){o.finish(null);return}if(i.complete&&s==i.layoutPositions.length-1){if(n>=this.opf.spine.length-1){o.finish(null);return}n++,s=0;let a=this.spineItems[n],l=a&&a.pages[0],c=i.pages[i.pages.length-1];l&&c&&l.side==c.side&&(a.pages.forEach(u=>{u.container&&u.container.remove()}),this.spineItems[n]=null,this.spineItemLoadingContinuations[n]=null)}else s++;this.findPage({spineIndex:n,pageIndex:s,offsetInItem:-1},e).thenFinish(o)}),o.result()}previousPage(t,e){let n=t.spineIndex,s=t.pageIndex;if(s==0){if(n==0)return T(null);n--,s=Number.POSITIVE_INFINITY}else s--;return this.findPage({spineIndex:n,pageIndex:s,offsetInItem:-1},e)}isRectoPage(t,e){let n=t.side==="left",s=this.getCurrentPageProgression(e)==="ltr";return!n&&s||n&&!s}getSpread(t,e){let n=this.getPage(t);if(!n)return T({left:null,right:null});let s=A("getSpread"),o=n.side==="left",i;return this.isRectoPage(n,t)?i=this.previousPage(t,e):i=this.nextPage(t,e),i.then(a=>{let l=this.getPage(t),c=a&&a.page;c&&c.side===l.side&&(c=null),o?s.finish({left:l,right:c}):s.finish({left:c,right:l})}),s.result()}nextSpread(t,e){let n=this.getPage(t);if(!n)return T(null);let s=this.isRectoPage(n,t),o=this.nextPage(t,e);return s?o:o.thenAsync(i=>{if(i){if(i.page.side===n.side)return o;let a=this.nextPage(i.position,e);return a.thenAsync(l=>l?a:o)}else return T(null)})}previousSpread(t,e){let n=this.getPage(t);if(!n)return T(null);let s=this.isRectoPage(n,t),o=this.previousPage(t,e),i=n.container.previousElementSibling;return s?o.thenAsync(a=>a?a.page.side===n.side||a.page.container!==i?o:this.previousPage(a.position,e):T(null)):o}navigateToEPage(t,e,n){let s=A("navigateToEPage");return this.opf.resolveEPage(t).then(o=>{o?this.findPage(o,n).thenFinish(s):s.finish(null)}),s.result()}navigateToFragment(t,e,n){let s=A("navigateToCFI");return this.opf.resolveFragment(t).then(o=>{o?this.findPage(o,n).thenFinish(s):s.finish(null)}),s.result()}navigateTo(t,e,n){F.debug("Navigate to",t);let s=this.opf.getPathFromURL(At(t));if(!s){if(this.opf.opfXML&&t.match(/^#epubcfi\(/))s=this.opf.getPathFromURL(this.opf.opfXML.url);else if(t.charAt(0)==="#"){let a=this.opf.documentURLTransformer.restoreURL(t);this.opf.opfXML?(s=this.opf.getPathFromURL(a[0]),s==null&&(s=a[0])):s=a[0],t=a[0]+(a[1]?`#${a[1]}`:"")}if(s==null)return T(null)}let o=this.opf.itemMapByPath[s];if(!o){if(this.opf.opfXML&&s==this.opf.getPathFromURL(this.opf.opfXML.url)){let a=t.indexOf("#");if(a>=0)return this.navigateToFragment(t.substr(a+1),e,n)}return T(null)}let i=A("navigateTo");return this.getPageViewItem(o.spineIndex).then(a=>{if(!a){i.finish(null);return}let l=a.xmldoc.getElement(t);this.findPage({spineIndex:o.spineIndex,pageIndex:-1,offsetInItem:l?a.xmldoc.getElementOffset(l):0},n).thenFinish(i)}),i.result()}makePage(t,e){let n=t.instance.viewport,s=n.document.createElement("div");s.setAttribute("data-vivliostyle-page-container","true"),s.role="presentation",as||(s.style.visibility="hidden"),n.layoutBox.appendChild(s);let o=n.document.createElement("div");o.setAttribute("data-vivliostyle-bleed-box","true"),o.role="presentation",s.appendChild(o);let i=new mo(s,o);if(i.spineIndex=t.item.spineIndex,i.position=e,i.offset=t.instance.getPosition(e),i.offset===0&&!(t.instance.blankPageAtStart&&t.pages.length===0)){let a=this.opf.documentURLTransformer.transformFragment("",t.item.src);o.setAttribute("id",a),i.registerElementWithId(o,a)}if(n!==this.viewport){let a=_l(this.viewport.width,this.viewport.height,n.width,n.height),l=on(null,new Be(a,null),"");i.delayedItems.push(new zn(s,"transform",l))}return i}makeObjectView(t,e,n,s){let o=e.getAttribute("data"),i=null;if(o){o=Q(o,t.url);let a=e.getAttribute("media-type");if(!a){let l=this.opf.getPathFromURL(o);if(l){let c=this.opf.itemMapByPath[l];c&&(a=c.mediaType)}}if(a){let l=this.opf.bindings[a];if(l){i=this.viewport.document.createElement("iframe"),i.style.border="none";let c=Il(o),u=Il(a),d=new Ge;d.append(l),d.append("?src="),d.append(c),d.append("&type="),d.append(u);for(let g=e.firstChild;g;g=g.nextSibling)if(g.nodeType==1){let m=g;if(m.localName=="param"&&m.namespaceURI=="http://www.w3.org/1999/xhtml"){let x=m.getAttribute("name"),E=m.getAttribute("value");x&&E&&(d.append("&"),d.append(encodeURIComponent(x)),d.append("="),d.append(encodeURIComponent(E)))}}i.setAttribute("src",d.toString());let h=e.getAttribute("width");h&&i.setAttribute("width",h);let f=e.getAttribute("height");f&&i.setAttribute("height",f)}}}return i||(i=this.viewport.document.createElement("object"),o&&i.setAttribute("data",o),i.setAttribute("data-adapt-process-children","true")),T(i)}makeMathJaxView(t,e,n,s){let o=Mb();if(o){let i=n.ownerDocument,a=i.createElement("span");n.appendChild(a);let l=i.importNode(e,!0);this.resolveURLsInMathML(l,t),a.appendChild(l);let c=o.queue;c.Push(["Typeset",o,a]);let u=A("makeMathJaxView"),d=u.suspend();return c.Push(()=>{d.schedule(a)}),u.result()}return T(null)}resolveURLsInMathML(t,e){if(t!=null){if(t.nodeType===1&&t.tagName==="mglyph"){let n=Array.from(t.attributes);for(let s of n){if(s.name!=="src")continue;let o=Q(s.nodeValue,e.url);s.namespaceURI?t.setAttributeNS(s.namespaceURI,s.name,o):t.setAttribute(s.name,o)}}t.firstChild&&this.resolveURLsInMathML(t.firstChild,e),t.nextSibling&&this.resolveURLsInMathML(t.nextSibling,e)}}makeCustomRenderer(t){return(e,n,s)=>e.localName=="object"&&e.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(t,e,n,s):e.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(t,e,n,s):e.dataset&&e.dataset.mathTypeset=="true"?this.makeMathJaxView(t,e,n,s):T(null)}getPageViewItem(t){if(t===-1||t>=this.opf.spine.length)return T(null);let e=this.spineItems[t];if(e)return T(e);let n=A("getPageViewItem"),s=this.spineItemLoadingContinuations[t];if(s){let a=n.suspend();return s.push(a),n.result()}else s=this.spineItemLoadingContinuations[t]=[];let o=this.opf.spine[t],i=this.opf.store;return i.load(o.src).then(a=>{var y;let l=o.itemRefElement.getAttribute("properties");l&&a.root.setAttribute("data-vivliostyle-epub-spine-properties",l),o.title=a.document.title;let c=i.getStyleForDoc(a),u=this.makeCustomRenderer(a),d=this.viewport,h=c.sizeViewport(d.width,d.height,d.fontSize,this.pref);(h.width!=d.width||h.height!=d.height||h.fontSize!=d.fontSize)&&(d=new An(d.window,h.fontSize,d.pixelRatio,d.root,h.width,h.height));let f=(y=this.spineItems[0])==null?void 0:y.instance.isVersoFirstPage,g=this.spineItems[t-1],m,x;if(o.startPage!==null)m=o.startPage-1,x=m;else{if(t>0&&(!g||!g.complete))m=o.epage||t,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,x=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let N=this.counterStore.currentPageCounters.page;x=!N||!N.length?m:N[N.length-1]}o.skipPagesBefore!==null&&(m+=o.skipPagesBefore,x+=o.skipPagesBefore)}this.counterStore.forceSetPageCounter(x);let E=new ss(c,a,this.opf.lang,d,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,m,this.opf.documentURLTransformer,this.counterStore,this.opf.pageProgression,f);E.pref=this.pref;let C=this.opf.metadata&&this.opf.metadata[Ne.title];E.pubTitle=C&&C[0]&&C[0].v||"",E.docTitle=o.title||"",E.init().then(()=>{!this.opf.pageProgression&&E.pageProgression&&(this.opf.pageProgression=E.pageProgression),e={item:o,xmldoc:a,instance:E,layoutPositions:[null],pages:[],complete:!1},this.spineItems[t]=e,n.finish(e),s.forEach(N=>{N.schedule(e)})})}),n.result()}removeRenderedPages(){let t=this.spineItems;for(let e of t)e&&e.pages.splice(0);this.viewport.clear()}hasAutoSizedPages(){let t=this.spineItems;for(let e of t)if(e){let n=e.pages;for(let s of n)if(s.isAutoPageWidth&&s.isAutoPageHeight)return!0}return!1}hasPages(){return this.spineItems.some(t=>t&&t.pages.length>0)}showTOC(t){let e=this.opf,n=e.toc;if(this.tocAutohide=t,!n)return T(null);if(this.tocVisible=!0,this.tocView&&this.tocView.page)return this.tocView.page.container.style.visibility="visible",this.tocView.page.container.setAttribute("aria-hidden","false"),T(this.tocView.page);let s=A("showTOC");this.tocView||(this.tocView=new al(e.store,n.src,e.lang,this.clientLayout,this.fontMapper,this.pref,this,e.fallbackMap,e.documentURLTransformer,this.counterStore));let o=this.viewport,i=Math.min(344,Math.round(.67*o.width)-16),a=o.height-6,l=o.document.createElement("div");return o.root.appendChild(l),as||(l.style.visibility="hidden"),l.style.width=`${i+16}px`,l.style.maxHeight=`${a}px`,l.setAttribute("data-vivliostyle-toc-box","true"),l.setAttribute("role","navigation"),this.tocView.showTOC(l,o,i,a,this.viewport.fontSize).then(c=>{l.style.visibility="visible",l.setAttribute("aria-hidden","false"),s.finish(c)}),s.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}};var Vg="data-vivliostyle-viewer-status",Ub="data-vivliostyle-spread-view",kp=(n=>(n.SINGLE_PAGE="singlePage",n.SPREAD="spread",n.AUTO_SPREAD="autoSpread",n))(kp||{}),pl=class{constructor(t,e,n,s){this.window=t;this.viewportElement=e;this.instanceId=n;this.callbackFn=s;p(this,"fontMapper");p(this,"kick");p(this,"sendCommand");p(this,"resizeListener");p(this,"hyperlinkListener");p(this,"pageRuleStyleElement");p(this,"pageSheetSizeAlreadySet",!1);p(this,"renderTask",null);p(this,"actions");p(this,"readyState");p(this,"packageURL");p(this,"opf");p(this,"touchActive");p(this,"touchX");p(this,"touchY");p(this,"needResize");p(this,"resized");p(this,"needRefresh");p(this,"viewportSize");p(this,"currentPage");p(this,"currentSpread");p(this,"pagePosition");p(this,"fontSize");p(this,"zoom");p(this,"fitToScreen");p(this,"pageViewMode");p(this,"waitForLoading");p(this,"renderAllPages");p(this,"pref");p(this,"pageSizes");p(this,"pixelRatio");p(this,"pixelRatioLimit");p(this,"viewport");p(this,"opfView");let o=e.ownerDocument,i=(a,l)=>{let c=o.getElementById(a);return c||(c=o.createElement("style"),c.id=a,l&&(c.textContent=l),o.head.appendChild(c)),c};i("vivliostyle-viewport-screen-css",bc),i("vivliostyle-viewport-css",xc),i("vivliostyle-polyfill-css",Tc),e.setAttribute("data-vivliostyle-viewer-viewport",!0),as&&e.setAttribute("data-vivliostyle-debug",!0),e.setAttribute(Vg,"loading"),this.fontMapper=new za(o.head,e),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=a=>{},this.pageRuleStyleElement=i("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}init(){this.readyState="loading",this.packageURL=[],this.opf=null,this.touchActive=!1,this.touchX=0,this.touchY=0,this.needResize=!1,this.resized=!1,this.needRefresh=!1,this.viewportSize=null,this.currentPage=null,this.currentSpread=null,this.pagePosition=null,this.fontSize=16,this.zoom=1,this.fitToScreen=!1,this.pageViewMode="singlePage",this.waitForLoading=!1,this.renderAllPages=!0,this.pref=Ml(),this.pageSizes=[],this.pixelRatioLimit=ar==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let t=Tl;F.addListener(t.DEBUG,e=>{this.callback({t:"debug",content:e})}),F.addListener(t.INFO,e=>{this.callback({t:"info",content:e})}),F.addListener(t.WARN,e=>{this.callback({t:"warn",content:e})}),F.addListener(t.ERROR,e=>{this.callback({t:"error",content:e})})}callback(t){t.i=this.instanceId,this.callbackFn(t)}setReadyState(t){this.readyState!==t&&(this.readyState=t,this.viewportElement.setAttribute(Vg,t),this.callback({t:"readystatechange"}))}loadPublication(t){$e.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,n=t.fragment,s=t.authorStyleSheet,o=t.userStyleSheet;this.viewport=null;let i=A("loadPublication");return this.configure(t).then(()=>{let a=new Qi;a.init(s,o).then(()=>{let l=Q(Rn(e),this.window.location.href);this.packageURL=[l],a.loadPubDoc(l).then(c=>{c?(this.opf=c,this.render(n).then(()=>{i.finish(!0)})):i.finish(!1)})})}),i.result()}loadXML(t){$e.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,n=t.document,s=t.fragment,o=t.authorStyleSheet,i=t.userStyleSheet;this.viewport=null;let a=A("loadXML");return this.configure(t).then(()=>{let l=new Qi;l.init(o,i).then(()=>{let c=e.map((u,d)=>({url:Q(Rn(u.url),this.window.location.href),index:d,startPage:u.startPage,skipPagesBefore:u.skipPagesBefore}));this.packageURL=c.map(u=>u.url),this.opf=new Ws(l,""),this.opf.initWithChapters(c,n).then(()=>{this.render(s).then(()=>{a.finish(!0)})})})}),a.result()}render(t){this.cancelRenderingTask();let e;return t?e=this.opf.resolveFragment(t).thenAsync(n=>(this.pagePosition=n,T(!0))):e=T(!0),e.thenAsync(()=>($e.registerEndTiming("beforeRender"),this.resize()))}resolveLength(t){let e=parseFloat(t),n=/[a-z]+$/,s;if(typeof t=="string"&&(s=t.match(n))){let o=s[0];if(o==="em"||o==="rem")return e*this.fontSize;if(o==="ex")return e*K.ex*this.fontSize/K.em;let i=K[o];if(i)return e*i}return e}configure(t){if(typeof t.autoresize=="boolean"&&(t.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof t.fontSize=="number"){let e=t.fontSize;e>=5&&e<=72&&this.fontSize!=e&&(this.fontSize=e,this.needResize=!0)}if(typeof t.viewport=="object"&&t.viewport){let e=t.viewport,n={marginLeft:this.resolveLength(e["margin-left"])||0,marginRight:this.resolveLength(e["margin-right"])||0,marginTop:this.resolveLength(e["margin-top"])||0,marginBottom:this.resolveLength(e["margin-bottom"])||0,width:this.resolveLength(e.width)||0,height:this.resolveLength(e.height)||0};(n.width>=200||n.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=n,this.needResize=!0)}if(typeof t.hyphenate=="boolean"&&(this.pref.hyphenate=t.hyphenate,this.needResize=!0),typeof t.horizontal=="boolean"&&(this.pref.horizontal=t.horizontal,this.needResize=!0),typeof t.nightMode=="boolean"&&(this.pref.nightMode=t.nightMode,this.needResize=!0),typeof t.lineHeight=="number"&&(this.pref.lineHeight=t.lineHeight,this.needResize=!0),typeof t.columnWidth=="number"&&(this.pref.columnWidth=t.columnWidth,this.needResize=!0),typeof t.fontFamily=="string"&&(this.pref.fontFamily=t.fontFamily,this.needResize=!0),typeof t.load=="boolean"&&(this.waitForLoading=t.load),typeof t.renderAllPages=="boolean"&&(this.renderAllPages=t.renderAllPages),typeof t.userAgentRootURL=="string"&&(kl(t.userAgentRootURL.replace(/resources\/?$/,"")),Al(t.userAgentRootURL)),typeof t.rootURL=="string"&&(kl(t.rootURL),Al(`${hn}resources/`)),typeof t.pageViewMode=="string"&&t.pageViewMode!==this.pageViewMode&&(this.pageViewMode=t.pageViewMode,this.needResize=!0),typeof t.pageBorder=="number"&&t.pageBorder!==this.pref.pageBorder&&(this.viewport=null,this.pref.pageBorder=t.pageBorder,this.needResize=!0),typeof t.zoom=="number"&&t.zoom!==this.zoom&&(this.zoom=t.zoom,this.needRefresh=!0),typeof t.fitToScreen=="boolean"&&t.fitToScreen!==this.fitToScreen&&(this.fitToScreen=t.fitToScreen,this.needRefresh=!0),typeof t.defaultPaperSize=="object"&&typeof t.defaultPaperSize.width=="number"&&typeof t.defaultPaperSize.height=="number"&&(this.viewport=null,this.pref.defaultPaperSize=t.defaultPaperSize,this.needResize=!0),typeof t.allowScripts=="boolean"&&t.allowScripts!==Xt&&(Sg(t.allowScripts),this.needResize=!0),typeof t.pixelRatio=="number"){let e=Math.min(t.pixelRatio,this.pixelRatioLimit);e!==this.pixelRatio&&(this.pixelRatio=e,this.needResize=!0)}return this.configurePlugins(t),T(!0)}configurePlugins(t){He("CONFIGURATION").forEach(n=>{let s=n(t);this.needResize=s.needResize||this.needResize,this.needRefresh=s.needRefresh||this.needRefresh})}pageReplacedListener(t){let e=this.currentPage,n=this.currentSpread,s=t.target;n?(n.left===s||n.right===s)&&this.showCurrent(t.newPage):e===t.target&&this.showCurrent(t.newPage)}forCurrentPages(t){let e=[];this.currentPage&&e.push(this.currentPage),this.currentSpread&&(e.push(this.currentSpread.left),e.push(this.currentSpread.right)),e.forEach(n=>{n&&t(n)})}removePageListeners(){this.forCurrentPages(t=>{t.removeEventListener("hyperlink",this.hyperlinkListener,!1),t.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(t=>{w(t.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(t){t.addEventListener("hyperlink",this.hyperlinkListener,!1),t.addEventListener("replaced",this.pageReplacedListener,!1),w(t.container,"visibility","visible"),w(t.container,"display","block")}showPage(t){this.hidePages(),this.currentPage=t,t.container.style.marginLeft="",t.container.style.marginRight="",this.showSinglePage(t)}showSpread(t){if(this.hidePages(),this.currentSpread=t,t.left&&t.right){let e=parseFloat(t.left.container.style.width),n=parseFloat(t.right.container.style.width);e&&n&&e!==n&&(e<n?t.left.container.style.marginLeft=`${n-e}px`:t.right.container.style.marginRight=`${e-n}px`)}t.left&&(this.showSinglePage(t.left),t.right?t.left.container.removeAttribute("data-vivliostyle-unpaired-page"):t.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),t.right&&(this.showSinglePage(t.right),t.left?t.right.container.removeAttribute("data-vivliostyle-unpaired-page"):t.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let t=A("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(e=>{let n=this.currentPage;(this.waitForLoading&&n.fetchers.length>0?On(n.fetchers):T(!0)).then(()=>{this.sendLocationNotification(n,e).thenFinish(t)})}),t.result()}createViewport(){let t=this.viewportElement;if(this.viewportSize){let e=this.viewportSize;return t.style.marginLeft=`${e.marginLeft}px`,t.style.marginRight=`${e.marginRight}px`,t.style.marginTop=`${e.marginTop}px`,t.style.marginBottom=`${e.marginBottom}px`,new An(this.window,this.fontSize,this.pixelRatio,t,e.width,e.height)}else return new An(this.window,this.fontSize,this.pixelRatio,t)}resolveSpreadView(t,e){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;case"autoSpread":default:return t!=null&&(t.width-this.pref.pageBorder)/t.height>=(e?e.width*2/e.height:1.45)&&(!!e||t.width>800)}}updateSpreadView(t){this.pref.spreadView=t,this.viewportElement.setAttribute(Ub,t.toString())}sizeIsGood(){var i;let t=this.createViewport(),e=((i=this.opfView)==null?void 0:i.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&e?this.pageSizes[0]:null);this.resized=!1;let s=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!s&&t.width==this.viewport.width&&t.height==this.viewport.height||!s&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:e?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(t,e,n,s){this.pageSizes[s]=t,this.setPageSizePageRules(e,n,s),s===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,t))}setPageSizePageRules(t,e,n){var o,i;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[n].width!==((o=this.pageSizes[n-1])==null?void 0:o.width)||this.pageSizes[n].height!==((i=this.pageSizes[n-1])==null?void 0:i.height))){let c=function(m){let x=m*.75;return Math.ceil(x)};var s=c;let a=Math.max(...this.pageSizes.map(m=>m.width)),l=Math.max(...this.pageSizes.map(m=>m.height)),u=c(a),d=c(l),h=u*((this.pixelRatio||1)-1)+2,f=d*((this.pixelRatio||1)-1)+2,g=`@page {size: ${u}pt ${d}pt; margin: 0 ${-h}pt ${-f}pt 0;}`;this.pageRuleStyleElement.textContent=g,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}reset(){let t=!1,e=!1;this.opfView&&(t=this.opfView.tocVisible,e=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new dl(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this)),t&&this.sendCommand({a:"toc",v:"show",autohide:e})}showCurrent(t,e){this.needRefresh=!1,this.removePageListeners();let n=this.resolveSpreadView(this.viewport,t.dimensions);return n!==this.pref.spreadView&&this.updateSpreadView(n),n?this.opfView.getSpread(this.pagePosition,e).thenAsync(s=>!s.left&&!s.right?T(null):s.left&&s.right&&(!this.resolveSpreadView(this.viewport,s.left.dimensions)||!this.resolveSpreadView(this.viewport,s.right.dimensions))?(this.updateSpreadView(!1),this.showPage(t),this.setPageZoom(t),this.currentPage=t,T(null)):(this.showSpread(s),this.setSpreadZoom(s),this.currentPage=t.side==="left"?s.left:s.right,T(null))):(this.showPage(t),this.setPageZoom(t),this.currentPage=t,T(null))}setPageZoom(t){var n;let e=this.getAdjustedZoomFactor(t.dimensions);(n=this.viewport)==null||n.zoom(t.dimensions.width,t.dimensions.height,e)}setSpreadZoom(t){var n;let e=this.getSpreadDimensions(t);(n=this.viewport)==null||n.zoom(e.width,e.height,this.getAdjustedZoomFactor(e))}getAdjustedZoomFactor(t){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(t):this.zoom}getSpreadDimensions(t){let e=0,n=0;return t.left&&(e+=t.left.dimensions.width,n=t.left.dimensions.height),t.right&&(e+=t.right.dimensions.width,n=Math.max(n,t.right.dimensions.height)),t.left&&t.right&&(e+=this.pref.pageBorder*2,e+=Math.abs(t.left.dimensions.width-t.right.dimensions.width)),{width:e,height:n}}queryZoomFactor(t){if(!this.currentPage)throw new Error("no page exists.");switch(t){case"fit inside viewport":{let e;return this.pref.spreadView?(this.currentSpread,e=this.getSpreadDimensions(this.currentSpread)):e=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(e)}default:throw new Error(`unknown zoom type: ${t}`)}}calculateZoomFactorToFitInsideViewPort(t){if(!this.viewport)return this.zoom;let e=this.viewport.width/t.width,n=this.viewport.height/t.height;return Math.min(e,n)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new hl),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return T(!0);this.setReadyState("loading"),this.cancelRenderingTask();let t=ei().getScheduler().run(()=>Cn("resize",e=>{if(!this.opf){e.finish(!1);return}this.renderTask=t,$e.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(n=>{if(!n){e.finish(!1);return}this.pagePosition=n.position,this.showCurrent(n.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(s=>{let o={t:"nav",epageCount:s,first:this.currentPage.isFirstPage,last:this.currentPage.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(o.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(o)}).then(()=>{this.reportPosition().then(s=>{(this.renderAllPages?this.opfView.renderAllPages():T(null)).then(()=>{this.renderTask===t&&(this.renderTask=null),$e.registerEndTiming("render (resize)"),Xt&&xp(this.window)?Tg(this.window).then(()=>{this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),e.finish(s)}):(this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),e.finish(s))})})})})})},(e,n)=>{if(n instanceof hl)$e.registerEndTiming("render (resize)"),F.debug(n.message);else throw n}));return T(!0)}sendLocationNotification(t,e){let n=A("sendLocationNotification"),s={t:"nav",first:t.isFirstPage,last:t.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[t.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(o=>{s.epage=o,s.epageCount=this.opf.epageCount,e&&(s.cfi=e),this.callback(s),n.finish(!0)}),n.result()}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(t){var s;let e;if(this.readyState!=="complete"&&t.where!=="next"&&this.setReadyState("loading"),typeof t.where=="string"){let o;switch(t.where){case"next":o=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":o=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":o=this.opfView.lastPage;break;case"first":o=this.opfView.firstPage;break;default:return T(!0)}o&&(e=()=>o.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof t.epage=="number"){let o=t.epage;e=()=>this.opfView.navigateToEPage(o,this.pagePosition,!this.renderAllPages)}else if(typeof t.url=="string"){let o=t.url;e=()=>this.opfView.navigateTo(o,this.pagePosition,!this.renderAllPages)}else if(typeof((s=t.position)==null?void 0:s.spineIndex)=="number"){let o=t.position;e=()=>this.opfView.findPage(o,!this.renderAllPages)}else return T(!0);if(!this.opfView)return T(!0);let n=A("moveTo");return e.call(this.opfView).then(o=>{let i;if(o){this.pagePosition=o.position;let a=A("moveTo.showCurrent");i=a.result(),this.showCurrent(o.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(a)})}else i=T(!0);i.then(a=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(a)})}),n.result()}showTOC(t){let e=!!t.autohide,n=t.v,s=this.opfView.isTOCVisible(),o=e!=this.opfView.tocAutohide&&n!="hide";if(s){if(n=="show"&&!o)return T(!0)}else if(n=="hide")return T(!0);if(s&&n!="show")return this.opfView.hideTOC(),T(!0);{let i=A("showTOC");return this.opfView.showTOC(e).then(a=>{if(a){if(o&&(a.listeners={}),e){let l=()=>{this.opfView.hideTOC()};a.addEventListener("hyperlink",l,!1)}a.addEventListener("hyperlink",this.hyperlinkListener,!1)}i.finish(!0)}),i.result()}}runCommand(t){let e=t.a||"";return Cn("runCommand",n=>{let s=this.actions[e];s?s.call(this,t).then(()=>{this.callback({t:"done",a:e}),n.finish(!0)}):(F.error("No such action:",e),n.finish(!0))},(n,s)=>{F.error(s,"Error during action:",e),n.finish(!0)})}initEmbed(t){let e=Fg(t),n=null,s=this;yh(()=>{let o=A("commandLoop"),i=ei().getScheduler();return s.hyperlinkListener=a=>{let l=a,c=l.href.charAt(0)==="#"||s.packageURL.some(u=>l.href.substr(0,u.length)==u);if(c){a.preventDefault();let u={t:"hyperlink",href:l.href,internal:c};i.run(()=>(s.callback(u),T(!0)))}},o.loopWithFrame(a=>{if(s.needResize)s.resize().then(()=>{a.continueLoop()});else if(s.needRefresh)s.currentPage&&s.showCurrent(s.currentPage,!this.renderAllPages).then(()=>{a.continueLoop()});else if(e){let l=e;e=null,s.runCommand(l).then(()=>{a.continueLoop()})}else{let l=A("waitForCommand");n=l.suspend(this),l.result().then(()=>{a.continueLoop()})}}).thenFinish(o),o.result()}),s.kick=()=>{let o=n;o&&(n=null,o.schedule(!0))},s.sendCommand=o=>e?!1:(e=Fg(o),s.kick(),!0),this.window.adapt_command=s.sendCommand}},Ap=(t=>(t.FIT_INSIDE_VIEWPORT="fit inside viewport",t))(Ap||{}),hl=class r extends Error{constructor(){super();p(this,"name","RenderingCanceledError");p(this,"message","Page rendering has been canceled");p(this,"stack");Object.setPrototypeOf(this,r.prototype),this.stack=new Error().stack}};function Fg(r){return typeof r=="string"?js(r):r}var Bg=ls;function zb(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function Og(r){let t={};return Object.keys(r).forEach(e=>{let n=r[e];switch(e){case"autoResize":t.autoresize=n;break;case"pageBorderWidth":t.pageBorder=n;break;default:t[e]=n}}),t}var Ji=class{constructor(t,e){this.settings=t;p(this,"initialized",!1);p(this,"adaptViewer_");p(this,"options");p(this,"eventTarget");p(this,"readyState");El(t.debug),this.adaptViewer_=new pl(t.window||window,t.viewportElement,"main",this.dispatcher.bind(this)),this.options=zb(),e&&this.setOptions(e),this.eventTarget=new Ln,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(t){let e=Object.assign({a:"configure"},Og(t));this.adaptViewer_.sendCommand(e),Object.assign(this.options,t)}dispatcher(t){let e={type:t.t},n=t;Object.keys(n).forEach(s=>{s!=="t"&&(e[s]=n[s])}),this.eventTarget.dispatchEvent(e)}addListener(t,e){this.eventTarget.addEventListener(t,e,!1)}removeListener(t,e){this.eventTarget.removeEventListener(t,e,!1)}loadDocument(t,e,n){if(!t||(Array.isArray(t)?!t[0]||typeof t[0]!="string"&&!t[0].url:typeof t!="string"&&!t.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(t,null,e,n)}loadPublication(t,e,n){if(!t){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,t,e,n)}loadDocumentOrPublication(t,e,n,s){let o=n||{};function i(u){if(u)return u.map(d=>({url:d.url||null,text:d.text||null}))}let a=i(o.authorStyleSheet),l=i(o.userStyleSheet);s&&Object.assign(this.options,s);let c=Object.assign({a:t?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:Gb(t)||e,document:o.documentObject,fragment:o.fragment,authorStyleSheet:a,userStyleSheet:l},Og(this.options));this.initialized?this.adaptViewer_.sendCommand(c):(this.initialized=!0,this.adaptViewer_.initEmbed(c))}getCurrentPageProgression(){return this.adaptViewer_.getCurrentPageProgression()}resolveNavigation(t){switch(t){case"left":return this.getCurrentPageProgression()===Bg.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Bg.LTR?"next":"previous";default:return t}}navigateToPage(t,e){t==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:e}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(t)})}navigateToInternalUrl(t){this.adaptViewer_.sendCommand({a:"moveTo",url:t})}navigateToPosition(t){var e,n;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:t.spineIndex,pageIndex:(e=t.pageIndex)!=null?e:-1,offsetInItem:(n=t.offsetInItem)!=null?n:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(t,e){let n=t==null?"toggle":t?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:n,autohide:e})}queryZoomFactor(t){return this.adaptViewer_.queryZoomFactor(t)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var t,e;return(e=(t=this.adaptViewer_.opfView)==null?void 0:t.tocView)==null?void 0:e.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}};function Gb(r){function t(n){return typeof n=="number"?n:null}function e(n){return typeof n=="string"?{url:n,startPage:null,skipPagesBefore:null}:{url:n.url,startPage:t(n.startPage),skipPagesBefore:t(n.skipPagesBefore)}}return Array.isArray(r)?r.map(e):r?[e(r)]:null}var Dg=(a=>(a.PREVIOUS="previous",a.NEXT="next",a.LEFT="left",a.RIGHT="right",a.FIRST="first",a.LAST="last",a.EPAGE="epage",a))(Dg||{}),Wb=Ap,$b=kp;$e.forceRegisterEndTiming("load_vivliostyle");var Lp=class{constructor(t,{title:e="",printCallback:n=a=>a.print(),errorCallback:s=null,hideIframe:o=!0,removeIframe:i=!0}){p(this,"htmlDoc");p(this,"title");p(this,"printCallback");p(this,"errorCallback");p(this,"hideIframe");p(this,"removeIframe");p(this,"iframe");p(this,"iframeWin");p(this,"window");this.htmlDoc=t,this.title=e,this.printCallback=n,this.errorCallback=s,this.hideIframe=o,this.removeIframe=i}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
|
|
1517
|
+
`),n.toString()}},Ha=class{constructor(t){this.deobfuscator=t;p(this,"familyMap",{})}registerFamily(t,e){let n=t.family,s=this.familyMap[n],o=e.family;if(s){if(s!=o)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${t.family}`)}else this.familyMap[n]=o}filterFontFamily(t){if(t instanceof fe){let e=t.values,n=[];for(let s of e){let o=this.familyMap[s.stringValue()];o&&n.push(L(o)),n.push(s)}return new fe(n)}else{let e=this.familyMap[t.stringValue()];return e?new fe([L(e),t]):t}}},za=class{constructor(t,e,n){this.head=t;this.body=e;p(this,"srcURLMap",{});p(this,"familyPrefix");p(this,"familyCounter",0);this.familyPrefix=n||"Fnt_"}getViewFontFamily(t,e){let n=t.family,s=e.familyMap[n];return s||(s=this.familyPrefix+ ++this.familyCounter,e.familyMap[n]=s,s)}initFont(t,e,n){let s=A("initFont"),o=t.src,i={};for(let u of Kd(t.properties))i[u]=t.properties[u];let a=this.getViewFontFamily(t,n);i["font-family"]=L(a);let l=new Mi(i),c=this.head.ownerDocument.createElement("style");return c.textContent=l.makeAtRule(o,e),this.head.appendChild(c),F.debug("Load font:",o),s.finish(l),s.result()}loadFont(t,e){let n=t.src,s=t.family+";"+n,o=this.srcURLMap[s];return o?o.piggyback(i=>{let a=i;a.traitsEqual(t)?(e.registerFamily(t,a),F.debug("Found already-loaded font:",n)):F.warn("E_FONT_FACE_INCOMPATIBLE",t.src)}):(o=new nn(()=>{let i=A("loadFont"),a=n.replace(/^url\("([^"]+)"\).*$/,"$1"),l=e.deobfuscator?e.deobfuscator(a):null;return l?xs(a,"blob").then(c=>{if(!c.responseBlob){i.finish(null);return}l(c.responseBlob).then(u=>{this.initFont(t,u,e).thenFinish(i)})}):this.initFont(t,null,e).thenFinish(i),i.result()},`loadFont ${n}`),this.srcURLMap[s]=o,o.start()),o}findOrLoadFonts(t,e){let n=[];for(let s of t){if(!s.src||!s.family){F.warn("E_FONT_FACE_INVALID");continue}n.push(this.loadFont(s,e))}return On(n).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let t=this.head.ownerDocument.fonts,e=0;if(t.forEach(s=>{s.status==="unloaded"&&(e++,s.load().catch(o=>{}))}),e===0)return T(!0);let n=A("waitFontLoading");return n.loop(()=>n.sleep(20).thenAsync(()=>t.status==="loading"?T(!0):T(!1))).thenFinish(n),n.result()}};var lb=1,Io=class{constructor(t,e,n,s,o){this.name=e;this.pseudoName=n;this.classes=s;this.parent=o;p(this,"specified",{});p(this,"children",[]);p(this,"pageMaster",null);p(this,"index",0);p(this,"key");p(this,"_scope");this._scope=t,this.key=`p${lb++}`,o&&(this.index=o.children.length,o.children.push(this))}get scope(){return this._scope}createInstance(t){throw new Error("E_UNEXPECTED_CALL")}clone(t){throw new Error("E_UNEXPECTED_CALL")}copySpecified(t){let e=this.specified,n=t.specified;for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}cloneChildren(t){for(let e=0;e<this.children.length;e++)this.children[e].clone({parent:t})}},Ga=class extends Io{constructor(t){super(t,null,null,[],null),this.specified.width=new H(Fn,0),this.specified.height=new H(Bn,0)}},Wa=class extends ds{constructor(e,n){super(e,o);this.pageMaster=n;let s=this;function o(i,a){let l=i.match(/^([^.]+)\.([^.]+)$/);if(l){let c=s.pageMaster.keyMap[l[1]];if(c){let d=this.lookupInstance(c);if(d)return a?d.resolveFunc(l[2]):d.resolveName(l[2])}}return null}}},Vo=class r extends Io{constructor(e,n,s,o,i,a,l){super(e,n,s,o,i);this.condition=a;this.specificity=l;p(this,"keyMap",{});e instanceof Wa||(this._scope=new Wa(e,this)),this.pageMaster=this,this.specified.width=new H(Fn,0),this.specified.height=new H(Bn,0),this.specified["wrap-flow"]=new H(b.auto,0),this.specified.position=new H(b.relative,0),this.specified.overflow=new H(b.visible,0)}createInstance(e){return new zs(e,this)}clone(e){let n=new r(this.scope,this.name,e.pseudoName||this.pseudoName,this.classes,this.parent,this.condition,this.specificity);return this.copySpecified(n),this.cloneChildren(n),n}resetScope(){this.scope.pageMaster=this}},$a=class r extends Io{constructor(t,e,n,s,o){super(t,e,n,s,o),this.pageMaster=o.pageMaster,e&&(this.pageMaster.keyMap[e]=this.key),this.specified["wrap-flow"]=new H(b.auto,0)}createInstance(t){return new qd(t,this)}clone(t){let e=new r(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(e),this.cloneChildren(e),e}},ns=class r extends Io{constructor(t,e,n,s,o){super(t,e,n,s,o),this.pageMaster=o.pageMaster,e&&(this.pageMaster.keyMap[e]=this.key)}createInstance(t){return new dn(t,this)}clone(t){let e=new r(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(e),this.cloneChildren(e),e}};function cb(r,t,e){return!t||U(t)?new ie(r,e):t.toExpr(r,r.zero)}function ee(r,t,e){return!t||t===b.auto||U(t)?null:t.toExpr(r,e)}function ub(r,t,e){return!t||t===b.normal||U(t)?null:t.toExpr(r,e)}function nt(r,t,e){return!t||t===b.auto||U(t)?r.zero:t.toExpr(r,e)}function Qd(r,t,e){return!t||U(t)?r.zero:t===b.auto?null:t.toExpr(r,e)}function $t(r,t,e,n){return!t||e===b.none||U(t)?r.zero:t.toExpr(r,n)}function Cg(r,t,e){return!t||U(t)?e:t===b._true?r._true:t===b._false?r._false:t.toExpr(r,r.zero)}var Fo=class{constructor(t,e){this.parentInstance=t;this.pageBox=e;p(this,"cascaded",{});p(this,"style",{});p(this,"autoWidth",null);p(this,"autoHeight",null);p(this,"children",[]);p(this,"isAutoWidth",!1);p(this,"isAutoHeight",!1);p(this,"isTopDependentOnAutoHeight",!1);p(this,"isRightDependentOnAutoWidth",!1);p(this,"calculatedWidth",0);p(this,"calculatedHeight",0);p(this,"pageMasterInstance",null);p(this,"namedValues",{});p(this,"namedFuncs",{});p(this,"vertical",!1);p(this,"rtl",!1);p(this,"suppressEmptyBoxGeneration",!1);p(this,"borderBoxSizing",!1);t&&t.children.push(this)}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(t,e){let n=this.resolveName(t),s=this.resolveName(e);if(!n||!s)throw new Error("E_INTERNAL");return G(this.pageBox.scope,n,s)}resolveName(t){let e=this.namedValues[t];if(e)return e;let n=this.style[t];switch(n&&(e=n.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),t){case"margin-left-edge":e=this.resolveName("left");break;case"margin-top-edge":e=this.resolveName("top");break;case"margin-right-edge":e=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":e=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":e=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":e=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":e=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":e=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":e=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":e=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":e=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":e=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":e=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":e=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":e=this.addNamedValues("left-edge","width");break;case"bottom-edge":e=this.addNamedValues("top-edge","height");break}if(!e){let s;if(t=="extent")s=this.vertical?"width":"height";else if(t=="measure")s=this.vertical?"height":"width";else{let o=this.vertical?$u:Xu;s=t;for(let i in o)s=s.replace(i,o[i])}s!=t&&(e=this.resolveName(s))}return e&&(this.namedValues[t]=e),e}resolveFunc(t){let e=this.namedFuncs[t];if(e)return e;switch(t){case"columns":{let n=this.pageBox.scope,s=new Js(n,0),o=this.resolveName("column-count"),i=this.resolveName("column-width"),a=this.resolveName("column-gap");e=Y(n,eo(n,new gn(n,"min",[s,o]),G(n,i,a)),a);break}}return e&&(this.namedFuncs[t]=e),e}initEnabled(){let t=this.pageBox.scope,e=this.style,n=Cg(t,e.enabled,t._true),s=ee(t,e.page,t.zero);if(s){let a=new J(t,"page-number");n=Qe(t,n,new Vn(t,s,a))}let o=ee(t,e["min-page-width"],t.zero);o&&(n=Qe(t,n,new ps(t,new J(t,"page-width"),o)));let i=ee(t,e["min-page-height"],t.zero);i&&(n=Qe(t,n,new ps(t,new J(t,"page-height"),i))),n=this.boxSpecificEnabled(n),e.enabled=new B(n)}boxSpecificEnabled(t){return t}initHorizontal(){let t=this.pageBox.scope,e=this.style,n=this.parentInstance?this.parentInstance.style.width.toExpr(t,null):null,s=ee(t,e.left,n),o=ee(t,e["margin-left"],n),i=$t(t,e["border-left-width"],e["border-left-style"],n),a=nt(t,e["padding-left"],n),l=ee(t,e.width,n),c=ee(t,e["max-width"],n),u=nt(t,e["padding-right"],n),d=$t(t,e["border-right-width"],e["border-right-style"],n),h=ee(t,e["margin-right"],n),f=ee(t,e.right,n),g=G(t,i,a),m=G(t,i,u);if(s&&f&&l){let C=Y(t,n,G(t,l,G(t,G(t,s,g),m)));o?h?f=Y(t,C,h):h=Y(t,C,G(t,f,o)):(C=Y(t,C,f),h?o=Y(t,C,h):(o=eo(t,C,new ie(t,.5)),h=o))}else{o||(o=t.zero),h||(h=t.zero),!s&&!f&&!l&&(s=t.zero),!s&&!l?(l=this.autoWidth,this.isAutoWidth=!0):!s&&!f?s=t.zero:!l&&!f&&(l=this.autoWidth,this.isAutoWidth=!0);let C=Y(t,n,G(t,G(t,o,g),G(t,h,m)));this.isAutoWidth&&(c||(c=Y(t,C,s||f)),!this.vertical&&(ee(t,e["column-width"],null)||ee(t,e["column-count"],null))&&(l=c,this.isAutoWidth=!1)),s?l?f||(f=Y(t,C,G(t,s,l))):l=Y(t,C,G(t,s,f)):s=Y(t,C,G(t,f,l))}let x=e["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),E=nt(t,x,n);e.left=new B(s),e["margin-left"]=new B(o),e["border-left-width"]=new B(i),e["padding-left"]=new B(a),e.width=new B(l),e["max-width"]=new B(c||l),e["padding-right"]=new B(u),e["border-right-width"]=new B(d),e["margin-right"]=new B(h),e.right=new B(f),e["snap-width"]=new B(E)}initVertical(){let t=this.pageBox.scope,e=this.style,n=this.parentInstance?this.parentInstance.style.width.toExpr(t,null):null,s=this.parentInstance?this.parentInstance.style.height.toExpr(t,null):null,o=ee(t,e.top,s),i=ee(t,e["margin-top"],n),a=$t(t,e["border-top-width"],e["border-top-style"],n),l=nt(t,e["padding-top"],n),c=ee(t,e.height,s),u=ee(t,e["max-height"],s),d=nt(t,e["padding-bottom"],n),h=$t(t,e["border-bottom-width"],e["border-bottom-style"],n),f=ee(t,e["margin-bottom"],n),g=ee(t,e.bottom,s),m=G(t,a,l),x=G(t,h,d);if(o&&g&&c){let y=Y(t,s,G(t,c,G(t,G(t,o,m),x)));i?f?g=Y(t,y,i):f=Y(t,y,G(t,g,i)):(y=Y(t,y,g),f?i=Y(t,y,f):(i=eo(t,y,new ie(t,.5)),f=i))}else{i||(i=t.zero),f||(f=t.zero),!o&&!g&&!c&&(o=t.zero),!o&&!c?(c=this.autoHeight,this.isAutoHeight=!0):!o&&!g?o=t.zero:!c&&!g&&(c=this.autoHeight,this.isAutoHeight=!0);let y=Y(t,s,G(t,G(t,i,m),G(t,f,x)));this.isAutoHeight&&(u||(u=Y(t,y,o||g)),this.vertical&&(ee(t,e["column-width"],null)||ee(t,e["column-count"],null))&&(c=u,this.isAutoHeight=!1)),o?c?g||(g=Y(t,y,G(t,o,c))):c=Y(t,y,G(t,g,o)):o=Y(t,y,G(t,g,c))}let E=e["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),C=nt(t,E,n);e.top=new B(o),e["margin-top"]=new B(i),e["border-top-width"]=new B(a),e["padding-top"]=new B(l),e.height=new B(c),e["max-height"]=new B(u||c),e["padding-bottom"]=new B(d),e["border-bottom-width"]=new B(h),e["margin-bottom"]=new B(f),e.bottom=new B(g),e["snap-height"]=new B(C)}initColumns(){let t=this.pageBox.scope,e=this.style,n=ee(t,e[this.vertical?"height":"width"],null),s=ee(t,e["column-width"],n),o=ee(t,e["column-count"],null),i=ub(t,e["column-gap"],null);i||(i=new Dt(t,1,"em")),s&&!o&&(o=new gn(t,"floor",[Ko(t,G(t,n,i),G(t,s,i))]),o=new gn(t,"max",[t.one,o])),o||(o=t.one),s=Y(t,Ko(t,G(t,n,i),o),i),e["column-width"]=new B(s),e["column-count"]=new B(o),e["column-gap"]=new B(i)}depends(t,e,n){return this.style[t].toExpr(this.pageBox.scope,null).depend(e,n)}init(t){var l;t.registerInstance(this.pageBox.key,this);let n=this.pageBox.scope,s=this.style,o=this.parentInstance?this.parentInstance.getActiveRegions(t):null,i=Ta(this.cascaded,t,o,!1,null);this.vertical=Na(i,t,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=va(i,t,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((l=i["box-sizing"])==null?void 0:l.value)===b.border_box;let a=!!(t instanceof ss&&t.currentLayoutPosition&&new J(n,"left-page").evaluate(t));wa(i,s,this.vertical,this.rtl,a,(c,u)=>u.value),this.autoWidth=new q(n,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new q(n,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(t,e){var s,o;let n=this.style[e];return!n&&Zn(e)&&this.pageMasterInstance instanceof pn&&(e==="font-size"&&t.isRelativeRootFontSize&&t.rootFontSize?n=new P(t.rootFontSize,"px"):n=(o=((s=t.styler)==null?void 0:s.rootStyle)[e])==null?void 0:o.value),n&&(n=Ni(t,n,e)),n}getPropAsNumber(t,e){var s,o;let n=this.style[e];if(n){let i=/\b(height|top|bottom)\b/.test(e)?(s=t.pageAreaHeight)!=null?s:t.pageHeight():(o=t.pageAreaWidth)!=null?o:t.pageWidth();n=Ni(t,n,e,i)}return Pe(n,t)}getSpecial(t,e){let n=ju(this.cascaded,e);if(n){let s=[];for(let o=0;o<n.length;o++){let i=n[o].evaluate(t,"");i&&i!==D&&s.push(i)}if(s.length)return s}return null}getActiveRegions(t){let e=this.getSpecial(t,"region-id");if(e){let n=[];for(let s=0;s<e.length;s++)n[s]=e[s].toString();return n}return null}propagateProperty(t,e,n,s){this.propagatePropertyToElement(t,e.element,n,s)}propagatePropertyToElement(t,e,n,s){let o=this.getProp(t,n);o&&(o.isNumeric()&&Pr(o.unit)&&(o=Lr(o,t)),n==="font-family"&&(o=s.filterFontFamily(o)),(n.startsWith("background")||n==="z-index")&&e.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(e=e.parentElement),w(e,n,o.toString()))}propagateDelayedProperty(t,e,n,s){let o=this.getProp(t,n);o&&s.push(new zn(e.element,n,o))}assignLeftPosition(t,e){let n=this.getPropAsNumber(t,"left"),s=this.getPropAsNumber(t,"margin-left"),o=this.getPropAsNumber(t,"padding-left"),i=this.getPropAsNumber(t,"border-left-width"),a=this.getPropAsNumber(t,"width");e.setHorizontalPosition(n,a),w(e.element,"margin-left",`${s}px`),w(e.element,"padding-left",`${o}px`),w(e.element,"border-left-width",`${i}px`),e.marginLeft=s,e.borderLeft=i,e.paddingLeft=o}assignRightPosition(t,e){let n=this.getPropAsNumber(t,"right"),s=this.getPropAsNumber(t,"snap-height"),o=this.getPropAsNumber(t,"margin-right"),i=this.getPropAsNumber(t,"padding-right"),a=this.getPropAsNumber(t,"border-right-width");if(w(e.element,"margin-right",`${o}px`),w(e.element,"padding-right",`${i}px`),w(e.element,"border-right-width",`${a}px`),e.marginRight=o,e.borderRight=a,this.vertical&&s>0){let l=n+e.getInsetRight(),c=l-Math.floor(l/s)*s;c>0&&(e.snapOffsetX=s-c,i+=e.snapOffsetX)}e.paddingRight=i,e.snapWidth=s}assignTopPosition(t,e){let n=this.getPropAsNumber(t,"snap-height"),s=this.getPropAsNumber(t,"top"),o=this.getPropAsNumber(t,"margin-top"),i=this.getPropAsNumber(t,"padding-top"),a=this.getPropAsNumber(t,"border-top-width");if(e.top=s,e.marginTop=o,e.borderTop=a,e.snapHeight=n,!this.vertical&&n>0){let l=s+e.getInsetTop(),c=l-Math.floor(l/n)*n;c>0&&(e.snapOffsetY=n-c,i+=e.snapOffsetY)}e.paddingTop=i,w(e.element,"top",`${s}px`),w(e.element,"margin-top",`${o}px`),w(e.element,"padding-top",`${i}px`),w(e.element,"border-top-width",`${a}px`)}assignBottomPosition(t,e){let n=this.getPropAsNumber(t,"margin-bottom"),s=this.getPropAsNumber(t,"padding-bottom"),o=this.getPropAsNumber(t,"border-bottom-width"),i=this.getPropAsNumber(t,"height")-e.snapOffsetY;w(e.element,"height",`${i}px`),w(e.element,"margin-bottom",`${n}px`),w(e.element,"padding-bottom",`${s}px`),w(e.element,"border-bottom-width",`${o}px`),e.height=i-e.snapOffsetY,e.marginBottom=n,e.borderBottom=o,e.paddingBottom=s}assignBeforePosition(t,e){this.vertical?this.assignRightPosition(t,e):this.assignTopPosition(t,e)}assignAfterPosition(t,e){this.vertical?this.assignLeftPosition(t,e):this.assignBottomPosition(t,e)}assignStartEndPosition(t,e){this.vertical?(this.assignTopPosition(t,e),this.assignBottomPosition(t,e)):(this.assignRightPosition(t,e),this.assignLeftPosition(t,e))}sizeWithMaxHeight(t,e){w(e.element,"border-top-width","0px");let n=this.getPropAsNumber(t,"max-height");this.isTopDependentOnAutoHeight?e.setVerticalPosition(0,n):(this.assignTopPosition(t,e),n-=e.snapOffsetY,e.height=n,w(e.element,"height",`${n}px`))}sizeWithMaxWidth(t,e){w(e.element,"border-left-width","0px");let n=this.getPropAsNumber(t,"max-width");if(this.isRightDependentOnAutoWidth)e.setHorizontalPosition(0,n);else{this.assignRightPosition(t,e),n-=e.snapOffsetX,e.width=n;let s=this.getPropAsNumber(t,"right");w(e.element,"right",`${s}px`),w(e.element,"width",`${n}px`)}}prepareContainer(t,e,n,s,o){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&w(e.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&w(e.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(t,e):this.sizeWithMaxHeight(t,e):(this.assignBeforePosition(t,e),this.assignAfterPosition(t,e)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(t,e):this.sizeWithMaxWidth(t,e):this.assignStartEndPosition(t,e);for(let i=0;i<pg.length;i++)this.propagateProperty(t,e,pg[i],s)}transferContentProps(t,e,n,s){for(let o=0;o<fg.length;o++)this.propagateProperty(t,e,fg[o],s);if(this.style["text-overflow"]){let o=e.element.firstElementChild;w(o,"text-overflow","inherit"),w(o,"overflow","inherit")}}transferSingleUriContentProps(t,e,n){let s=()=>{var a,l;let i=(l=(a=this.cascaded.width)!=null?a:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:l.value;return!!i&&i!==b.auto&&!U(i)},o=()=>{var a,l;let i=(l=(a=this.cascaded.height)!=null?a:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:l.value;return!!i&&i!==b.auto&&!U(i)};for(let i=0;i<gg.length;i++){let a=gg[i];if(a==="width"||a==="height"){if(a==="width"&&!s()||a==="height"&&!o())continue;w(e,a,"100%");continue}this.propagatePropertyToElement(t,e,a,n)}}finishContainer(t,e,n,s,o,i,a){this.vertical?this.calculatedWidth=e.computedBlockSize+e.snapOffsetX:this.calculatedHeight=e.computedBlockSize+e.snapOffsetY;let l=(this.vertical||!s)&&this.isAutoHeight,c=(!this.vertical||!s)&&this.isAutoWidth,u=null;if(c||l){c&&w(e.element,"width","auto"),l&&w(e.element,"height","auto");let d=s&&Kc(s);d&&Yc(s),u=i.getElementClientRect(s?s.element:e.element),d&&pi(s),c&&(this.calculatedWidth=Math.ceil(u.right-u.left-e.paddingLeft-e.borderLeft-e.paddingRight-e.borderRight),this.vertical&&(this.calculatedWidth+=e.snapOffsetX)),l&&(this.calculatedHeight=u.bottom-u.top-e.paddingTop-e.borderTop-e.paddingBottom-e.borderBottom,this.vertical||(this.calculatedHeight+=e.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(t,e),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(t,e),this.assignAfterPosition(t,e)),o>1){let d=this.getPropAsNumber(t,"column-rule-width"),h=this.getProp(t,"column-rule-style"),f=this.getProp(t,"column-rule-color");if(d>0&&h&&h!=b.none&&f!=b.transparent){let g=this.getPropAsNumber(t,"column-gap"),m=this.vertical?e.height:e.width,x=this.vertical?"border-top":"border-left";for(let E=1;E<o;E++){let C=this.vertical?(m+g)*E/o-g/2+e.paddingTop-d/2:(m+g)*E/o-g/2+e.paddingLeft-d/2,y=this.vertical?e.width+e.paddingLeft+e.paddingRight:e.height+e.paddingTop+e.paddingBottom,N=e.element.ownerDocument.createElement("div");w(N,"position","absolute"),w(N,this.vertical?"left":"top","0px"),w(N,this.vertical?"top":"left",`${C}px`),w(N,this.vertical?"height":"width","0px"),w(N,this.vertical?"width":"height",`${y}px`),w(N,x,`${d}px ${h.toString()}${f?` ${f.toString()}`:""}`),e.element.insertBefore(N,e.element.firstChild)}}}for(let d=0;d<hg.length;d++)this.propagateProperty(t,e,hg[d],a);for(let d=0;d<mg.length;d++)this.propagateDelayedProperty(t,e,mg[d],n.delayedItems)}applyCascadeAndInit(t,e){let n=this.cascaded,s=this.pageBox.specified;for(let i in s)this instanceof pn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(i==="writing-mode"||i==="direction")||Rs(i)&&vn(n,i,pe(s,i));if(this.pageBox.pseudoName==Ui)for(let i in e)(i.match(/^background-/)||i=="writing-mode")&&(n[i]=e[i]);if(this.pageBox.pseudoName=="layout-host")for(let i in e)!i.match(/^background-/)&&i!="writing-mode"&&(n[i]=e[i]);t.pushRule(this.pageBox.classes,null,n);let o=n.content;o&&(n.content=o.filterValue(new To(t,null,t.counterResolver))),this.init(t.context);for(let i of this.pageBox.children)i.createInstance(this).applyCascadeAndInit(t,e);t.popRule()}resolveAutoSizing(t){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,t)||this.depends("margin-right",this.autoWidth,t)||this.depends("border-right-width",this.autoWidth,t)||this.depends("padding-right",this.autoWidth,t)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,t)||this.depends("margin-top",this.autoHeight,t)||this.depends("border-top-width",this.autoHeight,t)||this.depends("padding-top",this.autoHeight,t));for(let e of this.children)e.resolveAutoSizing(t)}},pg=["border-left-style","border-right-style","border-top-style","border-bottom-style","border-left-color","border-right-color","border-top-color","border-bottom-color","box-sizing","outline-style","outline-color","outline-width","overflow","visibility"],hg=["border-top-left-radius","border-top-right-radius","border-bottom-right-radius","border-bottom-left-radius","border-start-start-radius","border-start-end-radius","border-end-start-radius","border-end-end-radius","border-image-source","border-image-slice","border-image-width","border-image-outset","border-image-repeat","background-attachment","background-color","background-image","background-repeat","background-position","background-clip","background-origin","background-size","box-shadow","opacity","z-index","background-blend-mode","isolation","mix-blend-mode","filter"],fg=["color","font-family","font-size","font-style","font-weight","line-height","letter-spacing","text-align","text-align-last","text-decoration","text-indent","text-transform","white-space","text-wrap","text-wrap-mode","text-wrap-style","word-spacing","font-feature-settings","font-kerning","font-size-adjust","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian","font-stretch","text-combine-upright","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-fill-color","text-orientation","text-shadow","text-stroke-color","text-stroke-width","text-underline-offset","text-underline-position","text-overflow"],gg=["width","height","image-resolution","object-fit","object-position"],mg=["transform","transform-origin"],Ui="background-host",Xa=class extends Fo{constructor(t){super(null,t)}applyCascadeAndInit(t,e){super.applyCascadeAndInit(t,e),this.children.sort((s,o)=>o.pageBox.specificity-s.pageBox.specificity||s.pageBox.index-o.pageBox.index)}},zs=class extends Fo{constructor(t,e){super(t,e),this.pageMasterInstance=this}boxSpecificEnabled(t){let e=this.pageBox.pageMaster;return e.condition&&(t=Qe(e.scope,t,e.condition)),t}adjustPageLayout(t,e,n){}},qd=class extends Fo{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}},dn=class extends Fo{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}processPartitionList(t,e,n){let s=null;if(e instanceof Ce&&(s=[e]),e instanceof fe&&(s=e.values),s){let o=this.pageBox.scope;for(let i=0;i<s.length;i++)if(s[i]instanceof Ce){let a=Yo(s[i].name,"enabled"),l=new J(o,a);n&&(l=new bt(o,l)),t=Qe(o,t,l)}}return t}boxSpecificEnabled(t){let e=this.pageBox.scope,n=this.style,s=Cg(e,n.required,e._false)!==e._false;if(s||this.isAutoHeight){let o=cb(e,n["flow-from"],"body"),i=new gn(e,"has-content",[o]);t=Qe(e,t,i)}if(t=this.processPartitionList(t,n["required-partitions"],!1),t=this.processPartitionList(t,n["conflicting-partitions"],!0),s){let o=this.pageMasterInstance.style.enabled,i=o?o.toExpr(e,null):e._true;i=Qe(e,i,t),this.pageMasterInstance.style.enabled=new B(i)}return t}prepareContainer(t,e,n,s,o){var i;this.pageBox.pageMaster instanceof Hi||(w(e.element,"overflow","hidden"),e.element.setAttribute("data-vivliostyle-page-partition",(i=this.pageBox.name)!=null?i:"")),super.prepareContainer(t,e,n,s,o)}},_i=class extends sn{constructor(e,n,s,o){super(e,n,!1);this.target=s;this.validatorSet=o}property(e,n,s){this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}unknownProperty(e,n){this.report(`E_INVALID_PROPERTY ${e}: ${n.toString()}`)}invalidPropertyValue(e,n){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${n.toString()}`)}simpleProperty(e,n,s){this.target.specified[e]=new H(n,s?zr:Gr)}},ja=class extends _i{constructor(t,e,n,s){super(t,e,n,s)}},Zd=class r extends _i{constructor(t,e,n,s){super(t,e,n,s),n.specified.width=new H($l,0),n.specified.height=new H($l,0)}startPartitionRule(t,e,n){let s=new ns(this.scope,t,e,n,this.target),o=new ja(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,e,n){let s=new $a(this.scope,t,e,n,this.target),o=new r(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}},Ya=class extends _i{constructor(t,e,n,s){super(t,e,n,s)}startPartitionRule(t,e,n){let s=new ns(this.scope,t,e,n,this.target),o=new ja(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,e,n){let s=new $a(this.scope,t,e,n,this.target),o=new Zd(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}};function mp(r){var n,s;let t=(n=r["writing-mode"])==null?void 0:n.value,e=(s=r.direction)==null?void 0:s.value;return t===b.vertical_lr||t!==b.vertical_rl&&e!==b.rtl?"ltr":"rtl"}var db={a10:{width:new P(26,"mm"),height:new P(37,"mm")},a9:{width:new P(37,"mm"),height:new P(52,"mm")},a8:{width:new P(52,"mm"),height:new P(74,"mm")},a7:{width:new P(74,"mm"),height:new P(105,"mm")},a6:{width:new P(105,"mm"),height:new P(148,"mm")},a5:{width:new P(148,"mm"),height:new P(210,"mm")},a4:{width:new P(210,"mm"),height:new P(297,"mm")},a3:{width:new P(297,"mm"),height:new P(420,"mm")},a2:{width:new P(420,"mm"),height:new P(594,"mm")},a1:{width:new P(594,"mm"),height:new P(841,"mm")},a0:{width:new P(841,"mm"),height:new P(1189,"mm")},b10:{width:new P(31,"mm"),height:new P(44,"mm")},b9:{width:new P(44,"mm"),height:new P(62,"mm")},b8:{width:new P(62,"mm"),height:new P(88,"mm")},b7:{width:new P(88,"mm"),height:new P(125,"mm")},b6:{width:new P(125,"mm"),height:new P(176,"mm")},b5:{width:new P(176,"mm"),height:new P(250,"mm")},b4:{width:new P(250,"mm"),height:new P(353,"mm")},b3:{width:new P(353,"mm"),height:new P(500,"mm")},b2:{width:new P(500,"mm"),height:new P(707,"mm")},b1:{width:new P(707,"mm"),height:new P(1e3,"mm")},b0:{width:new P(1e3,"mm"),height:new P(1414,"mm")},c10:{width:new P(28,"mm"),height:new P(40,"mm")},c9:{width:new P(40,"mm"),height:new P(57,"mm")},c8:{width:new P(57,"mm"),height:new P(81,"mm")},c7:{width:new P(81,"mm"),height:new P(114,"mm")},c6:{width:new P(114,"mm"),height:new P(162,"mm")},c5:{width:new P(162,"mm"),height:new P(229,"mm")},c4:{width:new P(229,"mm"),height:new P(324,"mm")},c3:{width:new P(324,"mm"),height:new P(458,"mm")},c2:{width:new P(458,"mm"),height:new P(648,"mm")},c1:{width:new P(648,"mm"),height:new P(917,"mm")},c0:{width:new P(917,"mm"),height:new P(1297,"mm")},"jis-b10":{width:new P(32,"mm"),height:new P(45,"mm")},"jis-b9":{width:new P(45,"mm"),height:new P(64,"mm")},"jis-b8":{width:new P(64,"mm"),height:new P(91,"mm")},"jis-b7":{width:new P(91,"mm"),height:new P(128,"mm")},"jis-b6":{width:new P(128,"mm"),height:new P(182,"mm")},"jis-b5":{width:new P(182,"mm"),height:new P(257,"mm")},"jis-b4":{width:new P(257,"mm"),height:new P(364,"mm")},"jis-b3":{width:new P(364,"mm"),height:new P(515,"mm")},"jis-b2":{width:new P(515,"mm"),height:new P(728,"mm")},"jis-b1":{width:new P(728,"mm"),height:new P(1030,"mm")},"jis-b0":{width:new P(1030,"mm"),height:new P(1456,"mm")},letter:{width:new P(8.5,"in"),height:new P(11,"in")},legal:{width:new P(8.5,"in"),height:new P(14,"in")},ledger:{width:new P(11,"in"),height:new P(17,"in")}},pb=new P(.24,"pt"),my=new P(3,"mm"),hb=new P(10,"mm"),fb=new P(13,"mm");function ji(r){let t={width:Fn,height:Bn,bleed:ne,bleedOffset:ne,cropOffset:ne},e=r.size;if(!(!e||e.value===b.auto)){let c=e.value,u,d;if(c.isSpaceList()?(u=c.values[0],d=c.values[1]):(u=c,d=null),u.isNumeric())t.width=u,t.height=d||u;else{let h=u.name&&db[u.name.toLowerCase()];h&&(d&&d===b.landscape?(t.width=h.height,t.height=h.width):(t.width=h.width,t.height=h.height))}}let n=r.marks,s=r.bleed,o=n&&!U(n.value)?n.value:b.none,i=s&&!U(s.value)?s.value:b.auto;if(i===b.auto){if(o!==b.none){let c=!1;o.isSpaceList()?c=o.values.some(u=>u===b.crop):c=o===b.crop,c&&(t.bleed=new P(6,"pt"))}}else i.isNumeric()&&(t.bleed=i);let a=r["crop-offset"],l=a&&!U(a.value)?a.value:b.auto;return l===b.auto?o!==b.none&&(t.bleedOffset=fb):l.isNumeric()&&(t.cropOffset=l),t}function Cp(r,t){let e={},n=Math.max(0,r.bleed.num)*t.queryUnitSize(r.bleed.unit,!1),s=!r.cropOffset.num&&r.bleedOffset.num?r.bleedOffset.num*t.queryUnitSize(r.bleedOffset.unit,!1):Math.max(0,r.cropOffset.num*t.queryUnitSize(r.cropOffset.unit,!1)-n),o=n+s,i=r.width;i===Fn?t.pref.defaultPaperSize?e.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):e.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-o*2:e.pageWidth=i.num*t.queryUnitSize(i.unit,!1);let a=r.height;return a===Bn?t.pref.defaultPaperSize?e.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):e.pageHeight=t.viewportHeight-o*2:e.pageHeight=a.num*t.queryUnitSize(a.unit,!1),e.bleed=n,e.bleedOffset=s,e.cropOffset=o,e}function xg(r,t,e){let n=r.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("width",t),n.setAttribute("height",e),n.style.position="absolute",n}function zi(r,t,e,n){n=n||"polyline";let s=r.createElementNS("http://www.w3.org/2000/svg",n);return s.setAttribute("stroke",e===b.auto?"#010101":e.toString()),s.setAttribute("stroke-width",t),s.setAttribute("fill","none"),s}var Jd=(s=>(s.TOP_LEFT="top left",s.TOP_RIGHT="top right",s.BOTTOM_LEFT="bottom left",s.BOTTOM_RIGHT="bottom right",s))(Jd||{});function gb(r,t,e,n,s,o,i){let a=s;a<=o+2*K.mm&&(a=o+s/2);let l=Math.max(s,a),c=o+l+e/2,u=xg(r,c,c),d=[[0,o+s],[s,o+s],[s,o+s-a]],h=d.map(m=>[m[1],m[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(m=>[o+l-m[0],m[1]]),h=h.map(m=>[o+l-m[0],m[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(m=>[m[0],o+l-m[1]]),h=h.map(m=>[m[0],o+l-m[1]]));let f=zi(r,e,n);f.setAttribute("points",d.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=zi(r,e,n);return g.setAttribute("points",h.map(m=>m.join(",")).join(" ")),u.appendChild(g),t.split(" ").forEach(m=>{u.style[m]=`${i}px`}),u}var Gi=(s=>(s.TOP="top",s.BOTTOM="bottom",s.LEFT="left",s.RIGHT="right",s))(Gi||{});function mb(r,t,e,n,s,o){let i=s*2,a,l;t==="top"||t==="bottom"?(a=i,l=s):(a=s,l=i);let c=xg(r,a,l),u=zi(r,e,n);u.setAttribute("points",`0,${l/2} ${a},${l/2}`),c.appendChild(u);let d=zi(r,e,n);d.setAttribute("points",`${a/2},0 ${a/2},${l}`),c.appendChild(d);let h=zi(r,e,n,"circle");h.setAttribute("cx",a/2),h.setAttribute("cy",l/2),h.setAttribute("r",s/4),c.appendChild(h);let f;switch(t){case"top":f="bottom";break;case"bottom":f="top";break;case"left":f="right";break;case"right":f="left";break}return Object.keys(Gi).forEach(g=>{let m=Gi[g];m===t?c.style[m]=`${o}px`:m!==f&&(c.style[m]="0",c.style[`margin-${m}`]="auto")}),c}function yg(r,t,e,n){let s=!1,o=!1,i=r.marks;if(i){let m=i.value;m instanceof j?m.values.forEach(x=>{x===b.crop?s=!0:x===b.cross&&(o=!0)}):m===b.crop?s=!0:m===b.cross&&(o=!0)}let a=t.bleed;if(!s&&!o)return;let l=e.container,c=l.ownerDocument;let u=Pe(pb,n),d=Math.max(0,t.bleedOffset-Pe(hb,n)),h=t.bleedOffset-d,f=r["crop-marks-line-color"],g=f&&!U(f.value)?f.value:b.auto;s&&Object.keys(Jd).forEach(m=>{let x=Jd[m],E=gb(c,x,u,g,h,a,d);l.appendChild(E)}),o&&Object.keys(Gi).forEach(m=>{let x=Gi[m],E=mb(c,x,u,g,h,d);l.appendChild(E)})}var ep=(()=>{let r=["left","right","top","bottom","before","after","start","end","block-start","block-end","inline-start","inline-end","inside","outside"],t={width:!0,height:!0,"block-size":!0,"inline-size":!0,margin:!0,padding:!0,border:!0,outline:!0,"outline-width":!0,"outline-style":!0,"outline-color":!0,"border-radius":!0,"border-top-left-radius":!0,"border-top-right-radius":!0,"border-bottom-right-radius":!0,"border-bottom-left-radius":!0,"border-start-start-radius":!0,"border-start-end-radius":!0,"border-end-start-radius":!0,"border-end-end-radius":!0,"box-shadow":!0,"box-sizing":!0};return r.forEach(e=>{t[`margin-${e}`]=!0,t[`padding-${e}`]=!0,t[`border-${e}-width`]=!0,t[`border-${e}-style`]=!0,t[`border-${e}-color`]=!0}),t})();var bp={"top-left-corner":{order:1,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:null},"top-left":{order:2,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"start"},"top-center":{order:3,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"center"},"top-right":{order:4,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"end"},"top-right-corner":{order:5,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:null},"right-top":{order:6,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:"start"},"right-middle":{order:7,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:"center"},"right-bottom":{order:8,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:"end"},"bottom-right-corner":{order:9,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:null},"bottom-right":{order:10,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"end"},"bottom-center":{order:11,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"center"},"bottom-left":{order:12,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"start"},"bottom-left-corner":{order:13,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:null},"left-bottom":{order:14,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:"end"},"left-middle":{order:15,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:"center"},"left-top":{order:16,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:"start"}},Cb=(()=>{let r=bp;return Object.keys(r).sort((t,e)=>r[t].order-r[e].order)})(),Qa="vivliostyle-page-rule-master",Wi="_marginBoxes",Hi=class extends Vo{constructor(e,n,s){super(e,null,Qa,[],n,null,0);p(this,"pageMarginBoxes",{});let o=ji(s),i=new tp(this.scope,this,s,o);this.createPageMarginBoxes(s),this.applySpecified(s,o)}createPageMarginBoxes(e){let n=e[Wi];n&&Cb.forEach(s=>{n[s]&&(this.pageMarginBoxes[s]=new sp(this.scope,this,s,e))})}applySpecified(e,n){this.specified.position=new H(b.relative,0),this.specified.width=new H(n.width,0),this.specified.height=new H(n.height,0);for(let s in e)!ep[s]&&s!=="background-clip"&&(this.specified[s]=e[s])}createInstance(e){return new pn(e,this)}},tp=class extends ns{constructor(e,n,s,o){super(e,null,null,[],n);this.pageSize=o;let i=new np(this.scope,this);this.applySpecified(s)}applySpecified(e){this.specified["wrap-flow"]=new H(b.auto,0),this.specified["z-index"]=new H(new ct(0),0),this.specified.position=new H(b.absolute,0),this.specified.overflow=new H(b.visible,0);for(let n in ep)ep.hasOwnProperty(n)&&(this.specified[n]=e[n])}createInstance(e){return new ip(e,this)}},np=class extends ns{constructor(t,e){super(t,null,null,[],e),this.specified["flow-from"]=new H(L("body"),0)}createInstance(t){return new $i(t,this)}},sp=class extends ns{constructor(e,n,s,o){super(e,null,null,[],n);this.marginBoxName=s;this.applySpecified(o)}applySpecified(e){let n=e[Wi][this.marginBoxName];for(let s in e){let o=e[s],i=n[s];(Wu[s]||i&&i.value===b.inherit)&&(this.specified[s]=o)}for(let s in n)if(Object.prototype.hasOwnProperty.call(n,s)){let o=n[s];o&&o.value!==D&&o.value!==b.inherit&&o.value!==b.unset&&o.value!==b.revert&&(this.specified[s]=o)}}createInstance(e){return new Xi(e,this)}},pn=class extends zs{constructor(e,n){super(e,n);p(this,"pageAreaDimension",null);p(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,n){let s=this.cascaded;for(let o in n)if(Object.prototype.hasOwnProperty.call(n,o))switch(o){case"writing-mode":case"direction":s[o]=n[o]}super.applyCascadeAndInit(e,n)}initHorizontal(){let e=this.style;e.left=ne,e["margin-left"]=ne,e["border-left-width"]=ne,e["padding-left"]=ne,e["padding-right"]=ne,e["border-right-width"]=ne,e["margin-right"]=ne,e.right=ne}initVertical(){let e=this.style;e.top=ne,e["margin-top"]=ne,e["border-top-width"]=ne,e["padding-top"]=ne,e["padding-bottom"]=ne,e["border-bottom-width"]=ne,e["margin-bottom"]=ne,e.bottom=ne}setPageAreaDimension(e){this.pageAreaDimension=e;let n=this.style;n.width=new B(e.borderBoxWidth),n.height=new B(e.borderBoxHeight),n["padding-left"]=new B(e.marginLeft),n["padding-right"]=new B(e.marginRight),n["padding-top"]=new B(e.marginTop),n["padding-bottom"]=new B(e.marginBottom)}adjustPageLayout(e,n,s){let o=n.marginBoxes,i={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},a={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(o.top,!0,i,e,s),this.sizeMarginBoxesAlongVariableDimension(o.bottom,!0,i,e,s),this.sizeMarginBoxesAlongVariableDimension(o.left,!1,a,e,s),this.sizeMarginBoxesAlongVariableDimension(o.right,!1,a,e,s)}sizeMarginBoxesAlongVariableDimension(e,n,s,o,i){let a="start",l="center",c="end",u=this.pageBox.scope,d={},h={},f={};for(let S in e){let v=bp[S];if(v){let k=e[S],R=this.pageMarginBoxInstances[S],z=new Bo(k,R.style,n,u,i);d[v.positionAlongVariableDimension]=k,h[v.positionAlongVariableDimension]=R,f[v.positionAlongVariableDimension]=z}}let g={start:s.start.evaluate(o),end:s.end.evaluate(o),extent:s.extent.evaluate(o)},m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),x=!1,E={};Object.keys(d).forEach(S=>{let v=S,k=ee(u,h[v].style[n?"max-width":"max-height"],s.extent);if(k){let R=k.evaluate(o);if(m[v]>R){let z=f[v]=new Ka(d[v],h[v].style,n,u,i,R);E[v]=z.getOuterSize(),x=!0}}}),x&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),x=!1,[a,l,c].forEach(S=>{var v;m[S]=(v=E[S])!=null?v:m[S]}));let C={};Object.keys(d).forEach(S=>{let v=S,k=ee(u,h[v].style[n?"min-width":"min-height"],s.extent);if(k){let R=k.evaluate(o);if(m[v]<R){let z=f[v]=new Ka(d[v],h[v].style,n,u,i,R);C[v]=z.getOuterSize(),x=!0}}}),x&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),[a,l,c].forEach(S=>{m[S]=C[S]||m[S]}));let y=g.start+g.extent,N=g.start+(g.start+g.extent);[a,l,c].forEach(S=>{let v=m[S];if(v!=null){let k=d[S],R=0;switch(S){case a:R=n?k.left:k.top;break;case l:R=(N-v)/2;break;case c:R=y-v;break}n?k.setHorizontalPosition(R,v-k.getInsetLeft()-k.getInsetRight()):k.setVerticalPosition(R,v-k.getInsetTop()-k.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,n){var l;let s=e.start,o=e.center,i=e.end,a={};if(o){let c=[s,i],u=new op(c),d=this.distributeAutoMarginBoxSizes(o,u,n);d.xSize!=null&&(a.center=d.xSize);let h=(l=d.xSize)!=null?l:o.getOuterSize(),f=Math.max((n-h)/2,0);s&&(a.start=s.hasAutoSize()?f:s.getOuterSize()),i&&(a.end=i.hasAutoSize()?f:i.getOuterSize())}else{let c=this.distributeAutoMarginBoxSizes(s,i,n);c.xSize!=null&&(a.start=c.xSize),c.ySize!=null&&(a.end=c.ySize)}return a}distributeAutoMarginBoxSizes(e,n,s){let o={xSize:null,ySize:null};if(e instanceof Bo&&e.minMaxFitContent&&(o.xSize=e.getOuterSize()),n instanceof Bo&&n.minMaxFitContent&&(o.ySize=n.getOuterSize()),e&&n)if(e.hasAutoSize()&&n.hasAutoSize()){let i=e.getOuterMaxContentSize(),a=n.getOuterMaxContentSize();if(i>0&&a>0){let l=i+a;if(l<s)o.xSize=s*i/l;else{let c=e.getOuterMinContentSize(),u=n.getOuterMinContentSize(),d=c+u;d<s?o.xSize=c+(s-d)*(i-c)/(l-d):d>0&&(o.xSize=s*c/d)}o.xSize>0&&(o.ySize=s-o.xSize)}else i>0?o.xSize=s:a>0&&(o.ySize=s)}else e.hasAutoSize()?o.xSize=Math.max(s-n.getOuterSize(),0):n.hasAutoSize()&&(o.ySize=Math.max(s-e.getOuterSize(),0));else e?e.hasAutoSize()&&(o.xSize=s):n&&n.hasAutoSize()&&(o.ySize=s);return o}prepareContainer(e,n,s,o,i){n.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,n,s,o,i)}},Bo=class{constructor(t,e,n,s,o){this.container=t;this.isHorizontal=n;this.clientLayout=o;p(this,"hasAutoSize_");p(this,"size",null);p(this,"minMaxFitContent",null);let i=e[n?"width":"height"];if(this.hasAutoSize_=!i||i===b.auto||U(i),this.minMaxFitContent=i instanceof Ce&&(i.name==="min-content"||i.name==="max-content"||i.name==="fit-content")?i.name:null,this.minMaxFitContent){let a=this.getSize();if(this.isHorizontal){let l=a[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,l)}else{let l=a[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,l)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let t=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=ho(this.clientLayout,this.container.element,t)}return this.size}getOuterMaxContentSize(){let t=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+t["max-content width"]+this.container.getInsetRight():this.container.getInsetTop()+t["max-content height"]+this.container.getInsetBottom()}getOuterMinContentSize(){let t=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+t["min-content width"]+this.container.getInsetRight():this.container.getInsetTop()+t["min-content height"]+this.container.getInsetBottom()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.container.width+this.container.getInsetRight():this.container.getInsetTop()+this.container.height+this.container.getInsetBottom()}},op=class{constructor(t){this.params=t}hasAutoSize(){return this.params.some(t=>{var e;return(e=t==null?void 0:t.hasAutoSize())!=null?e:!1})}getOuterMaxContentSize(){let t=this.params.map(e=>{var n;return(n=e==null?void 0:e.getOuterMaxContentSize())!=null?n:0});return Math.max.apply(null,t)*t.length}getOuterMinContentSize(){let t=this.params.map(e=>{var n;return(n=e==null?void 0:e.getOuterMinContentSize())!=null?n:0});return Math.max.apply(null,t)*t.length}getOuterSize(){let t=this.params.map(e=>{var n;return(n=e==null?void 0:e.getOuterSize())!=null?n:0});return Math.max.apply(null,t)*t.length}},Ka=class extends Bo{constructor(e,n,s,o,i,a){super(e,n,s,o,i);p(this,"fixedSize");this.fixedSize=a}hasAutoSize(){return!1}getOuterMaxContentSize(){return this.getOuterSize()}getOuterMinContentSize(){return this.getOuterSize()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.fixedSize+this.container.getInsetRight():this.container.getInsetTop()+this.fixedSize+this.container.getInsetBottom()}},ip=class extends dn{constructor(e,n){super(e,n);p(this,"borderBoxWidth",null);p(this,"borderBoxHeight",null);p(this,"contentBoxWidth",null);p(this,"contentBoxHeight",null);p(this,"marginTop",null);p(this,"marginRight",null);p(this,"marginBottom",null);p(this,"marginLeft",null)}applyCascadeAndInit(e,n){for(let o in n)o.match(/^background-/)&&(this.cascaded[o]=n[o]);super.applyCascadeAndInit(e,n),this.parentInstance.setPageAreaDimension({borderBoxWidth:this.borderBoxWidth,borderBoxHeight:this.borderBoxHeight,marginTop:this.marginTop,marginRight:this.marginRight,marginBottom:this.marginBottom,marginLeft:this.marginLeft})}initHorizontal(){let e=this.resolvePageBoxDimensions({start:"left",end:"right",extent:"width"});this.borderBoxWidth=e.borderBoxExtent,this.contentBoxWidth=e.contentBoxExtent,this.marginLeft=e.marginStart,this.marginRight=e.marginEnd}initVertical(){let e=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.borderBoxHeight=e.borderBoxExtent,this.contentBoxHeight=e.contentBoxExtent,this.marginTop=e.marginStart,this.marginBottom=e.marginEnd}resolvePageBoxDimensions(e){let n=this.style,s=this.pageBox.pageSize,o=this.pageBox.scope,i=e.start,a=e.end,l=e.extent,c=s[l].toExpr(o,null),u=ee(o,n[l],c),d=ee(o,n[`margin-${i}`],c),h=ee(o,n[`margin-${a}`],c),f=nt(o,n[`padding-${i}`],c),g=nt(o,n[`padding-${a}`],c),m=$t(o,n[`border-${i}-width`],n[`border-${i}-style`],c),x=$t(o,n[`border-${a}-width`],n[`border-${a}-style`],c),E=G(o,G(o,m,f),G(o,x,g)),C,y,N;return u?(this.borderBoxSizing?(y=u,N=Y(o,y,E)):(N=u,y=G(o,N,E)),C=Y(o,c,y),!d&&!h?(d=eo(o,C,new ie(o,.5)),h=d):d?h=Y(o,C,d):d=Y(o,C,h)):(d||(d=o.zero),h||(h=o.zero),C=G(o,d,h),y=Y(o,c,C),N=Y(o,y,E),u=this.borderBoxSizing?y:N),n[i]=new B(d),n[a]=new B(h),n[`margin-${i}`]=ne,n[`margin-${a}`]=ne,n[`border-${i}-width`]=new B(m),n[`border-${a}-width`]=new B(x),n[`padding-${i}`]=new B(f),n[`padding-${a}`]=new B(g),n[l]=new B(u),n[`max-${l}`]=new B(u),{borderBoxExtent:y,contentBoxExtent:N,marginStart:d,marginEnd:h}}prepareContainer(e,n,s,o,i){n.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,n,s,o,i)}},$i=class extends dn{constructor(t,e){super(t,e)}applyCascadeAndInit(t,e){for(let n in e)n.match(/^column.*$/)&&(this.cascaded[n]=e[n]);super.applyCascadeAndInit(t,{})}initHorizontal(){let t=this.style,e=this.parentInstance.style,n=this.pageBox.scope;t.left=e["padding-left"],t.width=new B(this.parentInstance.contentBoxWidth),t["margin-left"]=new B(new Qt(n,e.left.toExpr(n,null))),t["margin-right"]=new B(new Qt(n,e.right.toExpr(n,null))),t["border-left-width"]=e.left,t["border-right-width"]=e.right,t["border-left-style"]=b.solid,t["border-right-style"]=b.solid,t["border-left-color"]=b.transparent,t["border-right-color"]=b.transparent}initVertical(){let t=this.style,e=this.parentInstance.style,n=this.pageBox.scope;t.top=e["padding-top"],t.height=new B(this.parentInstance.contentBoxHeight),t["margin-top"]=new B(new Qt(n,e.top.toExpr(n,null))),t["margin-bottom"]=new B(new Qt(n,e.bottom.toExpr(n,null))),t["border-top-width"]=e.top,t["border-bottom-width"]=e.bottom,t["border-top-style"]=b.solid,t["border-bottom-style"]=b.solid,t["border-top-color"]=b.transparent,t["border-bottom-color"]=b.transparent}prepareContainer(t,e,n,s,o){e.element.setAttribute("data-vivliostyle-page-area",!0),n.pageAreaElement=e.element,super.prepareContainer(t,e,n,s,o),t.pageAreaWidth=e.width,t.pageAreaHeight=e.height}},Xi=class extends dn{constructor(e,n){super(e,n);p(this,"boxInfo");p(this,"suppressEmptyBoxGeneration",!0);let s=n.marginBoxName;this.boxInfo=bp[s];let o=e;o.pageMarginBoxInstances[s]=this}prepareContainer(e,n,s,o,i){n.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,n.element),super.prepareContainer(e,n,s,o,i)}applyVerticalAlign(e,n){w(n,"display","flex"),w(n,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let s=this.getProp(e,"vertical-align"),o=null;s===L("middle")?o="center":s===L("top")?o="flex-start":s===L("bottom")&&(o="flex-end"),o&&w(n,"justify-content",o);let i=this.getProp(e,"content");if(this.vertical||i instanceof Fe||i instanceof B&&i.expr instanceof q&&i.expr.str.startsWith("running-element-")){let a="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?a=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(a=this.vertical||this.rtl?"end":"start")),w(n,"align-items",a)}}positionAlongVariableDimension(e,n){let s=this.style,o=this.pageBox.scope,i=e.start,a=e.end,l=e.extent,c=i==="left",u=c?n.borderBoxWidth:n.borderBoxHeight,d=ee(o,s[l],u),h=c?n.marginLeft:n.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")s[i]=new B(h);else if(d){let f=nt(o,s[`margin-${i}`],u),g=nt(o,s[`margin-${a}`],u),m=nt(o,s[`padding-${i}`],u),x=nt(o,s[`padding-${a}`],u),E=$t(o,s[`border-${i}-width`],s[`border-${i}-style`],u),C=$t(o,s[`border-${a}-width`],s[`border-${a}-style`],u),y=G(o,d,G(o,this.borderBoxSizing?o.zero:G(o,G(o,m,x),G(o,E,C)),G(o,f,g)));switch(this.boxInfo.positionAlongVariableDimension){case"center":s[i]=new B(G(o,h,Ko(o,Y(o,u,y),new ie(o,2))));break;case"end":s[i]=new B(Y(o,G(o,h,u),y));break}}}positionAndSizeAlongFixedDimension(e,n){let s=this.style,o=this.pageBox.scope,i=this.borderBoxSizing,a=e.inside,l=e.outside,c=e.extent,u=n[`margin${l.charAt(0).toUpperCase()}${l.substring(1)}`],d=Qd(o,s[`margin-${a}`],u),h=Qd(o,s[`margin-${l}`],u),f=nt(o,s[`padding-${a}`],u),g=nt(o,s[`padding-${l}`],u),m=$t(o,s[`border-${a}-width`],s[`border-${a}-style`],u),x=$t(o,s[`border-${l}-width`],s[`border-${l}-style`],u),E=ee(o,s[c],u),C=null;function y(N){if(C)return C;C={extent:E?E.evaluate(N):null,marginInside:d?d.evaluate(N):null,marginOutside:h?h.evaluate(N):null};let S=u.evaluate(N),v=0;return i||[m,f,g,x].forEach(k=>{k&&(v+=k.evaluate(N))}),(C.marginInside===null||C.marginOutside===null)&&v+C.extent+C.marginInside+C.marginOutside>S&&(C.marginInside===null&&(C.marginInside=0),C.marginOutside===null&&(C.marginOutside=0)),C.extent!==null&&C.marginInside!==null&&C.marginOutside!==null&&(C.marginOutside=null),C.extent===null?(C.extent=S-v-C.marginInside-C.marginOutside,C.marginInside===null&&(C.marginInside=0),C.marginOutside===null&&(C.marginOutside=0)):typeof C.extent=="number"&&(C.marginInside===null&&typeof C.marginOutside=="number"?C.marginInside=S-v-C.extent-C.marginOutside:typeof C.marginInside=="number"&&C.marginOutside===null?C.marginOutside=S-v-C.extent-C.marginInside:C.marginInside=C.marginOutside=(S-v-C.extent)/2),C}s[c]=new B(new q(o,function(){let N=y(this).extent;return N===null?"auto":N},c)),s[`margin-${a}`]=new B(new q(o,function(){let N=y(this).marginInside;return N===null?"auto":N},`margin-${a}`)),s[`margin-${l}`]=new B(new q(o,function(){let N=y(this).marginOutside;return N===null?"auto":N},`margin-${l}`)),a==="left"?s.left=new B(G(o,n.marginLeft,n.borderBoxWidth)):a==="top"&&(s.top=new B(G(o,n.marginTop,n.borderBoxHeight)))}initHorizontal(){let n=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},n):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},n):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},n)}initVertical(){let n=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},n):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},n):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},n)}finishContainer(e,n,s,o,i,a,l){super.finishContainer(e,n,s,o,i,a,l);let c=s.marginBoxes,u=this.pageBox.marginBoxName,d=this.boxInfo;!d.isInLeftColumn&&!d.isInRightColumn?d.isInTopRow?c.top[u]=n:d.isInBottomRow&&(c.bottom[u]=n):!d.isInTopRow&&!d.isInBottomRow&&(d.isInLeftColumn?c.left[u]=n:d.isInRightColumn&&(c.right[u]=n));let h=this.parentInstance.pageAreaDimension,f=this.getProp(e,"width"),g=f instanceof Ce&&(f.name==="min-content"||f.name==="max-content"||f.name==="fit-content")?f.name:null,m=this.getPropAsNumber(e,"min-width"),x=this.getPropAsNumber(e,"max-width");if(g||m||x){g&&w(n.element,"width",g),m&&w(n.element,"min-width",`${m}px`),x&&w(n.element,"max-width",`${x}px`);let S=this.getProp(e,"margin-left"),v=this.getProp(e,"margin-right");if(d.isInLeftColumn){let k=h.borderBoxWidth.evaluate(e)+h.marginRight.evaluate(e);w(n.element,"right",`${k}px`),(S===b.auto||v!==b.auto)&&w(n.element,"margin-left","auto"),v===b.auto&&w(n.element,"margin-right","auto")}else d.isInRightColumn&&(w(n.element,"right","0"),(v===b.auto||S!==b.auto)&&w(n.element,"margin-right","auto"),S===b.auto&&w(n.element,"margin-left","auto"))}let E=this.getProp(e,"height"),C=E instanceof Ce&&(E.name==="min-content"||E.name==="max-content"||E.name==="fit-content")?E.name:null,y=this.getPropAsNumber(e,"min-height"),N=this.getPropAsNumber(e,"max-height");if(C||y||N){C&&w(n.element,"height",C),y&&w(n.element,"min-height",`${y}px`),N&&w(n.element,"max-height",`${N}px`);let S=this.getProp(e,"margin-top"),v=this.getProp(e,"margin-bottom");if(d.isInTopRow){let k=h.borderBoxHeight.evaluate(e)+h.marginBottom.evaluate(e);w(n.element,"bottom",`${k}px`),(S===b.auto||v!==b.auto)&&w(n.element,"margin-top","auto"),v===b.auto&&w(n.element,"margin-bottom","auto")}else d.isInBottomRow&&(w(n.element,"bottom","0"),(v===b.auto||S!==b.auto)&&w(n.element,"margin-bottom","auto"),S===b.auto&&w(n.element,"margin-top","auto"))}}},qa=class{constructor(t,e,n,s,o){this.cascadeInstance=t;this.pageScope=e;this.rootPageBoxInstance=n;this.context=s;this.docElementStyle=o;p(this,"pageMasterCache",{});this.definePageProgression()}definePageProgression(){let t=this.pageScope,e=this.context,n=e.isVersoFirstPage,s=new J(t,"page-number"),o=new Vn(t,new Qs(t,s,new ie(t,2)),n?t.one:t.zero);t.defineName("recto-page",new bt(t,o)),t.defineName("verso-page",o),(e.pageProgression||mp(this.docElementStyle))==="ltr"?(t.defineName("left-page",o),t.defineName("right-page",new bt(t,o))):(t.defineName("left-page",new bt(t,o)),t.defineName("right-page",o))}getCascadedPageStyle(t){let e={};return this.cascadeInstance.pushRule([],t,e),this.cascadeInstance.popRule(),e}getPageRulePageMaster(t,e){let n=t.pageBox;if(Object.keys(e).length===0)return n.resetScope(),t;let s=this.makeCacheKey(e,n),o=this.pageMasterCache[s];return o||(n.pseudoName===Ui?o=this.generatePageRuleMaster(e):o=this.generateCascadedPageMaster(e,n),this.pageMasterCache[s]=o),o.pageBox.resetScope(),o}makeCacheKey(t,e){var o;let n=this.makeCascadeValueObjectKey(t),s=((o=this.context.currentLayoutPosition)==null?void 0:o.page)%2;return`${e.key}^${n}^${s}`}makeCascadeValueObjectKey(t){let e=[];for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n)){let s=t[n],o;s instanceof H?o=`${s.value}`:o=this.makeCascadeValueObjectKey(s),e.push(n+o+(s.priority||""))}return e.sort().join("^")}generatePageRuleMaster(t){let n=new Hi(this.pageScope,this.rootPageBoxInstance.pageBox,t).createInstance(this.rootPageBoxInstance);return n.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),n.resolveAutoSizing(this.context),n}generateCascadedPageMaster(t,e){let n=e.clone({pseudoName:Qa}),s=n.specified,o=t.size;if(o&&!U(o.value)){let a=ji(t),l=o.priority;un(s,"width",new H(a.width,l),this.context),un(s,"height",new H(a.height,l),this.context)}["counter-reset","counter-increment"].forEach(a=>{s[a]&&(t[a]=s[a])});let i=n.createInstance(this.rootPageBoxInstance);return i.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),i.resolveAutoSizing(this.context),i}},rp=class extends Z{constructor(e){super();this.pageType=e}apply(e){e.currentPageType===this.pageType&&this.chained.apply(e)}getPriority(){return 3}makePrimary(e){return this.chained&&e.insertInTable(e.pagetypes,this.pageType,this.chained),!0}},ap=class extends Z{constructor(e){super();this.scope=e}apply(e){new J(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},lp=class extends Z{constructor(e){super();this.scope=e}apply(e){new J(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},cp=class extends Z{constructor(e){super();this.scope=e}apply(e){new J(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},up=class extends Z{constructor(e){super();this.scope=e}apply(e){new J(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},dp=class extends Z{constructor(e){super();this.scope=e}apply(e){new J(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},pp=class extends Z{constructor(e){super();this.scope=e}apply(e){new J(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},hp=class extends qn{constructor(e,n,s){super(n,s);this.scope=e;this.a=n;this.b=s}apply(e){let n=e.context,s=n.layoutPositionAtPageStart.page;n.blankPageAtStart&&s--,s&&this.matchANPlusB(s)&&this.chained.apply(e)}getPriority(){return 2}},fp=class extends Is{constructor(t,e){super(t,e,null,null,null)}apply(t){bb(t.context,t.currentStyle,this.style,this.specificity,t)}};function bb(r,t,e,n,s){Si(r,t,e,n,null,null,null);let o=e[Wi];if(o){let i=Po(t,Wi);for(let a in o)if(o.hasOwnProperty(a)){let l=i[a];l||(l={},i[a]=l),Si(r,l,o[a],n,null,null,null)}}}var Za=class extends wn{constructor(e,n,s,o,i){super(e,n,s==null?void 0:s.condition,s,null,o,!1);this.pageProps=i;p(this,"currentPageSelectors",[]);p(this,"currentNamedPageSelector","");p(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,n){this.currentNamedPageSelector=n,n&&(this.chain.push(new rp(n)),this.specificity+=65536)}pseudoclassSelector(e,n){if(e=e.toLowerCase(),n)switch(e){case"nth":{let[s,o]=n;this.currentPseudoPageClassSelectors.push(`:${e}(${s}n${o<0?o:"+"+o})`),this.chain.push(new hp(this.scope,s,o)),this.specificity+=256}break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}(${n.join("")})`);break}else switch(this.currentPseudoPageClassSelectors.push(`:${e}`),e){case"first":this.chain.push(new ap(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new lp(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new cp(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new up(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new dp(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new pp(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}`);break}}finishSelector(){let e;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?e=null:e=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:e,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(e,n,s){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(a=>a.selectors===null))return;super.simpleProperty(e,n,s);let o=pe(this.elementStyle,e),i=this.pageProps;if(e==="bleed"||e==="marks")i[""]||(i[""]={}),Object.keys(i).forEach(a=>{vn(i[a],e,o)});else if(e==="size"){let a=i[""];this.currentPageSelectors.forEach(l=>{let c=new H(o.value,o.priority+l.specificity),u=l.selectors?l.selectors.join(""):"",d=i[u];d?un(d,e,c):(d=i[u]={},vn(d,e,c),a&&["bleed","marks"].forEach(h=>{a[h]&&vn(d,h,a[h])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new fp(this.elementStyle,e)}startPageMarginBoxRule(e){let n=Po(this.elementStyle,Wi),s=n[e];s||(s={},n[e]=s);let o=new gp(this.scope,this.owner,this.validatorSet,s);this.owner.pushHandler(o)}},gp=class extends sn{constructor(e,n,s,o){super(e,n,!1);this.validatorSet=s;this.boxStyle=o}property(e,n,s){this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}invalidPropertyValue(e,n){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${n.toString()}`)}unknownProperty(e,n){this.report(`E_INVALID_PROPERTY ${e}: ${n.toString()}`)}simpleProperty(e,n,s){let o=s?this.getImportantSpecificity():this.getBaseSpecificity(),i=new H(n,o);vn(this.boxStyle,e,i)}};var Xt=!0;function Sg(r){Xt=r}var Gs=[];function Eg(r,t){return r===t||(r.src||t.src?r.src===t.src:r.textContent===t.textContent)}function Ng(r){let t=Array.from(r.querySelectorAll("body > :not(script):not(link):not(style) ~ script"));return Array.from(r.querySelectorAll("head > script, body > script")).filter(e=>!t.includes(e))}function Ja(r,t,e){var u,d;if(!Xt)return T(!1);if(!(e!=null&&e.inHead)&&!(e!=null&&e.atEnd)&&Ng(r.ownerDocument).includes(r))return T(!1);let n=r.textContent,s=r.src,o=r.type==="module",i=(o||s)&&r.async,a=o&&!i||s&&r.defer,l=!(e!=null&&e.atEnd)&&((e==null?void 0:e.forceDefer)||a||i);if(xp(t)||(t.onload=null),l)return Gs.some(h=>Eg(h,r))||Gs.push(r),T(!0);if(s.includes("/mathjax")){let h=t.document.head.querySelector("script[src*='MathJax.js']:not([data-vivliostyle-scripting])");if(h){if(s.includes("/mathjax@3"))t.document.head.removeChild(h),(d=(u=t.MathJax)==null?void 0:u.version)!=null&&d.startsWith("2.")&&delete t.MathJax;else if(s.includes("/MathJax.js"))return T(!0)}}for(let h of t.document.head.getElementsByTagName("script"))h.hasAttribute("data-vivliostyle-scripting")&&Eg(h,r)&&t.document.head.removeChild(h);let c=t.document.createElement("script");c.textContent=n,s&&(c.src=s),c.async=i,c.defer=a,c.setAttribute("data-vivliostyle-scripting","true");for(let h of r.attributes)["src","async","defer"].includes(h.name)||c.setAttribute(h.name,h.value);if(F.debug("script:",s),s){let h=Dn(c);return t.document.head.appendChild(c),On([h])}else return t.document.head.appendChild(c),T(!0)}function yb(r,t){var o;let e={},n=i=>{var c;let a=(c=i["font-family"])==null?void 0:c.value;if(a)if(a.values)for(let u of a.values)e[u.stringValue()]=!0;else e[a.stringValue()]=!0;let l=i._marginBoxes;if(l)for(let u of Object.values(l))n(u)},s=i=>{if(i instanceof Is)n(i.style);else if(i instanceof Tn||Array.isArray(i))for(let a of Object.values(i))s(a)};for(let i of Object.values(t.cascade.code))for(let a of Object.values(i!=null?i:{}))s(a);for(let i of r.querySelectorAll("[style]"))(o=i.style)!=null&&o.fontFamily&&(e[i.style.fontFamily]=!0);return Object.keys(e).join(",")}function Eb(r,t,e){var s;let n=(s=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?s:t.document.createElement("div");return n.style.position="fixed",n.style.fontSize="0",n.setAttribute("data-vivliostyle-textcontent","true"),n.setAttribute("aria-hidden","true"),n.style.fontFamily=yb(r,e),n.textContent=r.documentElement.textContent,t.document.body.appendChild(n),n}function vg(r,t,e){if(!Xt)return T(!1);let n=Ng(r);if(n.length===0)return T(!1);let s=n.some(u=>!(u.async||u.defer||u.type==="module")),o=s?Eb(r,t,e):null,i=t.document.fonts,a=t.$,l=!1,c=A("loadScripts");return c.loop(()=>{if(n.length===0)return s?c.sleep(20).thenAsync(()=>{var d,h;return i.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(d=t.FontJSON)!=null&&d.Font&&((h=t.ret)!=null&&h.readyState)&&t.ret.readyState<4?T(!0):T(!1)}):T(!1);let u=n.shift();return Ja(u,t,{inHead:!0,forceDefer:l}).thenAsync(()=>(!l&&t.$!==a&&(Gs.push(u),l=!0),n.length===0&&s&&(F.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),T(!0)))}).then(()=>{o&&o.remove(),c.finish(!0)}),c.result()}function Tg(r){if(!Xt)return T(!1);let t=A("loadScripts");return t.loop(()=>Gs.length===0?T(!1):Ja(Gs.shift(),r,{atEnd:!0}).thenReturn(Gs.length>0)).then(()=>{F.debug("dispatchEvent: DOMContentLoaded (window)"),r.dispatchEvent(new Event("DOMContentLoaded")),F.debug("dispatchEvent: load (window)"),r.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function xp(r){return Xt?Gs.length>0||!!r.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var wg=(r,t,e)=>r.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,s)=>`url("${e.transformURL(s,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,s)=>`url('${e.transformURL(s,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,s)=>`url(${e.transformURL(s,t)}`);var Nb={};function vb(r){r.addEventListener("load",()=>{r.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(t,e){switch(t){case"mouse-events":return!0}return!1}}},!1)}var Yi=class Yi extends Ln{constructor(e,n,s,o,i,a,l,c,u,d,h,f,g){super();this.flowName=e;this.context=n;this.viewport=s;this.styler=o;this.regionIds=i;this.xmldoc=a;this.docFaces=l;this.footnoteStyle=c;this.stylerProducer=u;this.page=d;this.customRenderer=h;this.fallbackMap=f;this.documentURLTransformer=g;p(this,"document");p(this,"exprContentListener");p(this,"nodeContext",null);p(this,"viewRoot",null);p(this,"isFootnote",!1);p(this,"sourceNode",null);p(this,"offsetInNode",0);p(this,"viewNode",null);this.document=s.document,this.exprContentListener=o.counterListener.getExprContentListener()}clone(){return new Yi(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer)}createPseudoelementShadow(e,n,s,o,i,a,l,c){let u=this.getPseudoMap(s,this.regionIds,this.isFootnote,this.nodeContext,a);if(!u)return c;let d=[],h=Ao.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=h;for(let m of Uf){let x;if(m){if(!u[m]||m=="footnote-marker"&&!(n&&this.isFootnote))continue;if(m.match(/^first-/)){let E=o.display;if(!E||E===b.inline)continue;let C=e.firstElementChild;if(C&&de(C.previousSibling)){let y=i.getStyle(C,!1);if(y){let N=pe(y,"display");if(N!=null&&N.value&&N.value!==b.inline)continue}}}if(m==="before"||m==="after"){let E=u[m].content;if(!E||!vt(E.value))continue}d.push(m),x=Ao.createElementNS("http://www.w3.org/1999/xhtml","span"),Ti(x,m)}else x=Ao.createElementNS("http://www.pyroxy.com/ns/shadow","content");f.appendChild(x),m.match(/^first-/)&&(f=x)}if(!d.length)return c;let g=new vi(e,s,i,a,this.exprContentListener);return new vs(e,h,null,l,c,Nt.ROOTLESS,g)}getPseudoMap(e,n,s,o,i){let a=Pt(e,"_pseudos");if(!a)return null;let l={};for(let c in a){let u=l[c]={};ko(u,a[c],i),ba(u,i,a[c]),qu(a[c],n,s,(d,h)=>{ko(u,h,i),Ku(h,f=>{ko(u,f,i)})})}return l}createRefShadow(e,n,s,o,i){let a=A("createRefShadow");return this.xmldoc.store.load(e).then(l=>{let c=l;if(c){let u=c.getElement(e);if(u){let d=this.stylerProducer.getStylerForDoc(c);i=new vs(s,u,c,o,i,n,d)}}a.finish(i)}),a.result()}createShadows(e,n,s,o,i,a,l){let c=A("createShadows"),u=null,d=o.template,h;if(d instanceof Fe||d===b.footnote){let f=d instanceof Fe?d.url:Q("user-agent.xml#footnote",Kt);h=this.createRefShadow(f,Nt.ROOTLESS,e,l,u)}else h=T(u);return h.then(f=>{let g=null;if(e.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&e.localName=="include"){let x=e.getAttribute("href"),E=null;x?E=l?l.xmldoc:this.xmldoc:l&&(l.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?x=l.owner.getAttribute("href"):x=l.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),E=l.parentShadow?l.parentShadow.xmldoc:this.xmldoc),x&&(x=Q(x,E.url),g=this.createRefShadow(x,Nt.ROOTED,e,l,f))}g==null&&(g=T(f));let m=null;g.then(x=>{if(o.display===b.table_cell){let E=Q("user-agent.xml#table-cell",Kt);m=this.createRefShadow(E,Nt.ROOTLESS,e,l,x)}else m=T(x);m.then(E=>{E=this.createPseudoelementShadow(e,n,s,o,i,a,l,E),c.finish(E)})})}),c.result()}setViewRoot(e,n){this.viewRoot=e,this.isFootnote=n}computeStyle(e,n,s,o){var E;let i=this.context,a=Ta(s,i,this.regionIds,this.isFootnote,this.nodeContext),l=!((E=this.nodeContext)!=null&&E.parent);l&&(!a["writing-mode"]&&this.styler.rootStyle["writing-mode"]&&(a["writing-mode"]=this.styler.rootStyle["writing-mode"]),!a.direction&&this.styler.rootStyle.direction&&(a.direction=this.styler.rootStyle.direction));let c=e;e=Na(a,i,e);let u=!l&&e!==c;n=va(a,i,n);let d=(C,y)=>{let N;u&&(e?/^(min-|max-)?(height|inline-size)$/.test(C)&&(N=i.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(C)&&(N=i.pageAreaWidth));let S=y.evaluate(i,C,N,e);return C=="font-family"&&(S=this.docFaces.filterFontFamily(S)),S},h=!!new J(i.style.pageScope,"left-page").evaluate(i);if(wa(a,o,e,n,h,d),u){let C=o[e?"height":"width"];(!C||C===b.auto)&&(o[e?"height":"width"]=b.max_content)}if(ui(o.position))return o.position=b.fixed,o.visibility=b.hidden,e;let f=o.position,g=o.float,m=o.display||(this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?b.inline:void 0),x=Xc(m,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(C=>{x[C]&&(o[C]=x[C])}),e}inheritFromSourceParent(e){let n=this.nodeContext.sourceNode,s=[],o=null,i=this.nodeContext.shadowContext,a=-1;for(;n&&n.nodeType==1;){let h=i&&i.root==n;if(!h||i.type==Nt.ROOTLESS){let g=(i?i.styler:this.styler).getStyle(n,!1);s.push(g),o=o||Uo(n)}h?(n=i.owner,i=i.parentShadow):(n=n.parentNode,a++)}let l=a===0,c=this.context.queryUnitSize("em",l),u={"font-size":new H(new P(c,"px"),0)},d=new ha(u,this.context);for(let h=s.length-1;h>=0;--h){let f=s[h],g=[];for(let E in f)Zn(E)&&g.push(E);g.sort(Xl);let m,x;for(let E of g){d.setPropName(E);let C=pe(f,E),y=C;if(!U(C.value)){if(E==="font-size"&&h===s.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)y=new H(new P(this.context.rootFontSize,"px"),C.priority);else if(E==="line-height"&&h===s.length-1&&this.context.rootLineHeight&&C.value instanceof P&&(C.value.unit==="lh"||C.value.unit==="rlh"))y=new H(new P(this.context.rootLineHeight,"px"),C.priority);else if(h===0&&C.value instanceof P&&C.value.unit==="lh"){let N=this.getLineHeightUnitSize(E,m,x);N!=null&&(y=new H(new P(C.value.num*N,"px"),C.priority))}else yt(E)||(y=C.filterValue(d));E==="font-size"?m=y.value:E==="line-height"&&(x=y.value),u[E]=y}}}for(let h in e)Zn(h)||(u[h]=e[h]);return{lang:o,elementStyle:u}}resolveURL(e){return e=Q(e,this.xmldoc.url),this.fallbackMap[e]||e}inheritLangAttribute(){this.nodeContext.lang=Uo(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(e){let n=yf().filter(s=>e[s]);if(n.length){let s=this.nodeContext.inheritedProps;if(this.nodeContext.parent){s=this.nodeContext.inheritedProps={};for(let o in this.nodeContext.parent.inheritedProps)s[o]=this.nodeContext.parent.inheritedProps[o]}n.forEach(o=>{let i=e[o];if(i){if(U(i))i===b.initial&&(s[o]=void 0);else if(i instanceof ct)s[o]=i.num;else if(i instanceof Ce)s[o]=i.name;else if(i instanceof P){let a=i;switch(a.unit){case"dpi":case"dpcm":case"dppx":s[o]=a.num*K[a.unit];break;default:s[o]=i}}else s[o]=i;["widows","orphans"].includes(o)||delete e[o]}})}}resolveFormattingContext(e,n,s,o,i,a){let l=He("RESOLVE_FORMATTING_CONTEXT");for(let c=0;c<l.length;c++){let u=l[c](e,n,s,o,i,a);if(u){e.formattingContext=u;return}}}createElementView(e,n){var E,C,y,N;let s=!0,o=A("createElementView"),i=this.sourceNode,a=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,l=a.getStyle(i,!1);if(!this.nodeContext.shadowContext){let S=this.xmldoc.getElementOffset(i);Kn.registerFragmentIndex(S,this.nodeContext.fragmentIndex,0)}let c={};if(!this.nodeContext.parent){let S=this.inheritFromSourceParent(l);l=S.elementStyle,this.nodeContext.lang=S.lang}let u=l.position,d=l.float,h=l["float-reference"],f=d&&!U(d.value)&&d.value!==b.none&&h&&!U(h.value)?ef(h.value.toString()):null;if(this.nodeContext.parent&&(ui(u==null?void 0:u.value)||f&&Wn(f))){let S=this.inheritFromSourceParent(l);l=S.elementStyle,this.nodeContext.lang=S.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,c),f&&Wn(f)&&c.display===b.block&&(c.display=b.flow_root),a.processContent(i,c,(C=this.nodeContext.viewNode)!=null?C:(E=this.nodeContext.parent)==null?void 0:E.viewNode),this.transferPolyfilledInheritedProps(c),this.inheritLangAttribute(),c.direction&&(this.nodeContext.direction=c.direction.toString());let g=c["flow-into"];if(g&&g.toString()!=this.flowName)return o.finish(!1),o.result();if(Xt&&i.localName==="script"&&i.namespaceURI==="http://www.w3.org/1999/xhtml")return Ja(i,this.viewport.window).thenFinish(o),o.result();let m=c.display;if(U(m)&&(m===b.initial||m===b.unset?m=b.inline:m===b.inherit?m=((y=this.nodeContext.parent)==null?void 0:y.display)&&L((N=this.nodeContext.parent)==null?void 0:N.display):m=null),m===b.none)return o.finish(!1),o.result();let x=this.nodeContext.parent==null;return this.nodeContext.flexContainer=m===b.flex,this.createShadows(i,x,l,c,a,this.context,this.nodeContext.shadowContext).then(S=>{var Vp,Fp;this.nodeContext.nodeShadow=S;let v=c.position,k=c.float,R=c.clear,z=this.nodeContext.vertical?b.vertical_rl:b.horizontal_tb,te=this.nodeContext.parent?this.nodeContext.parent.vertical?b.vertical_rl:b.horizontal_tb:z,Ke=nf(i),ht=c["column-count"],Ue=c["column-width"],qe=ht&&ht!==b.auto&&!U(ht)||Ue&&Ue!==b.auto&&!U(Ue);this.nodeContext.establishesBFC=of(m,v,k,c.overflow,z,te,qe||Ke),this.nodeContext.containingBlockForAbsolute=rf(v),this.nodeContext.isInsideBFC()&&k!==b.footnote&&!(f&&Wn(f))&&(k=null,R=null);let st=k instanceof j||k===b.left||k===b.right||k===b.top||k===b.bottom||k===b.inline_start||k===b.inline_end||k===b.block_start||k===b.block_end||k===b.snap_block||k===b.snap_inline||k===b.inside||k===b.outside||k===b.footnote;k&&(delete c.float,k===b.footnote&&(this.isFootnote?(st=!1,c.display=b.block):c.display=b.inline)),R&&(R===b.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(R=L(this.nodeContext.parent.clearSide)),(R===b.left||R===b.right||R===b.top||R===b.bottom||R===b.inline_start||R===b.inline_end||R===b.block_start||R===b.block_end||R===b.inside||R===b.outside||R===b.both||R===b.all||R===b.same||R===b.column||R===b.region||R===b.page)&&(delete c.clear,c.display&&c.display!=b.inline&&(this.nodeContext.clearSide=R.toString())));let I=m===b.list_item&&c["ua-list-item-count"],O=c["break-inside"];(st||O&&!U(O)&&O!==b.auto)&&this.nodeContext.breakPenalty++,m&&m!==b.inline&&Gt(m)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!st&&!m||Gt(m)||aa(m),this.nodeContext.display=m?m.toString():"inline",this.nodeContext.floatSide=st?k.toString():null,this.nodeContext.floatReference=f||le.INLINE;let V=c["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=V&&!U(V)?V:null;let _=this.isInsideNonRootMultiColumn(),W=c["column-span"];if(this.nodeContext.columnSpan=!_&&W&&!U(W)?W:null,!this.nodeContext.inline){let M=c["break-after"];M&&!U(M)&&!(_&&M===b.column)&&(this.nodeContext.breakAfter=M.toString(),Xr[this.nodeContext.breakAfter]&&(c["break-after"]=b.column));let ot=c["break-before"];ot&&!U(ot)&&!(_&&ot===b.column)&&(this.nodeContext.breakBefore=ot.toString(),Xr[this.nodeContext.breakBefore]&&(c["break-before"]=b.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let kt=c.page,it=kt&&!U(kt)&&kt.toString();!it&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||m===b.table_header_group||m===b.table_footer_group)&&(it=this.styler.cascade.currentPageType),!it||it.toLowerCase()==="auto"?it=this.nodeContext.pageType:this.nodeContext.pageType=it,this.styler.cascade.currentPageType!==it&&!(!it&&c.position===b.fixed)&&(this.nodeContext.fragmentIndex===1&&!_n(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),it!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=it)}this.nodeContext.verticalAlign=c["vertical-align"]&&c["vertical-align"].toString()||"baseline",this.nodeContext.captionSide=c["caption-side"]&&c["caption-side"].toString()||"top";let ae=c["border-collapse"];if(!ae||ae===L("separate")){let M=c["border-spacing"],ot,kt;M&&(M instanceof j?(ot=M.values[0],kt=M.values[1]):ot=kt=M,ot.isNumeric()&&(this.nodeContext.inlineBorderSpacing=Pe(ot,this.context)),kt.isNumeric()&&(this.nodeContext.blockBorderSpacing=Pe(kt,this.context)))}let ft=c["footnote-policy"];this.nodeContext.footnotePolicy=ft&&!U(ft)?ft:null;let is=c["x-first-pseudo"];if(is){let M=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Qr(M,is.num)}this.nodeContext.inline||this.processAfterIfcontinues(i,l,a,this.context);let Rp=c["white-space"];if(Rp){let M=na(Rp.toString());M!==null&&(this.nodeContext.whitespace=M)}let fl=c["hyphenate-character"];fl&&fl instanceof ue&&(this.nodeContext.hyphenateCharacter=fl.str);let Mg=c["word-break"],_g=c["line-break"],Ip=c["overflow-wrap"];(Mg===b.break_all||_g===b.anywhere||Ip===b.break_word||Ip===b.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,e,m,v,k,x),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(e=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,e)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(c),this.findAndProcessRepeatingElements(i,a));let rs=!1,gl=null,Oo=[],Ft=i.namespaceURI,$=i.localName,er=$;if(Ft=="http://www.w3.org/1999/xhtml"?($=="html"||$=="body"||$=="script"||$=="link"||$=="meta"?$="div":$=="vide_"?$="video":$=="audi_"?$="audio":$=="object"&&(rs=!!this.customRenderer),i.getAttribute(Pa)&&(Fp=(Vp=l.content)==null?void 0:Vp.value)!=null&&Fp.url&&($="img")):Ft=="http://www.idpf.org/2007/ops"?($="span",Ft="http://www.w3.org/1999/xhtml"):Ft=="http://www.pyroxy.com/ns/shadow"?(Ft="http://www.w3.org/1999/xhtml",$=this.nodeContext.inline?"span":"div"):rs=!!this.customRenderer,I)e?$="li":($="div",m=b.block,c.display=m);else if($=="body"||$=="li")$="div";else if($=="q")$="span";else if($=="a"){let M=c["hyperlink-processing"];M&&M.toString()!="normal"&&($="span")}c.behavior&&c.behavior.toString()!="none"&&this.customRenderer&&(rs=!0),i.dataset&&i.getAttribute("data-math-typeset")==="true"&&(rs=!0);let ml;if(rs){let M=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;ml=this.customRenderer(i,M,c)}else ml=T(null);ml.then(M=>{var Dp,Mp,_p;if(M)rs&&(s=M.getAttribute("data-adapt-process-children")=="true");else if(c.display===b.none){o.finish(!1);return}else M=this.createElement(Ft,$);!x&&qe&&c["column-fill"]===b.auto&&(M.setAttribute("data-vivliostyle-column-fill","auto"),c["column-fill"]=b.balance),$!=er&&(M.setAttribute("data-vivliostyle-original-tag",er),(er==="html"||er==="body")&&(M.role="presentation")),$=="a"&&M.addEventListener("click",this.page.hrefHandler,!1),gl&&(this.applyPseudoelementStyle(this.nodeContext,"inner",gl),M.appendChild(gl)),M.localName=="iframe"&&M.namespaceURI=="http://www.w3.org/1999/xhtml"&&vb(M);let ot=this.nodeContext.inheritedProps["image-resolution"],kt=[],it=c.width,Cl=c.height,Ug=i.getAttribute("width"),Hg=i.getAttribute("height"),bl=it===b.auto||!it&&!Ug,xl=Cl===b.auto||!Cl&&!Hg,Bp=i.attributes,zg=Bp.length,tr=null,Op=null;m===b.table_cell&&((_p=(Mp=(Dp=this.nodeContext.parent)==null?void 0:Dp.viewNode)==null?void 0:Mp.lastElementChild)==null?void 0:_p.localName)==="a"&&M.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let Ze=0;Ze<zg;Ze++){let jt=Bp[Ze],rt=jt.namespaceURI,oe=jt.localName,he=jt.nodeValue;if(rt){if(rt=="http://www.w3.org/2000/xmlns/")continue;rt=="http://www.w3.org/1999/xlink"&&oe=="href"&&(he=this.documentURLTransformer.transformURL(this.resolveURL(he),this.xmldoc.url))}else{if(!Xt&&oe.match(/^on/)||oe=="style")continue;if((oe=="id"||oe=="name")&&e){let We=this.documentURLTransformer.transformFragment(he,this.xmldoc.url);M.setAttribute(oe,he),M.setAttribute("data-vivliostyle-id",We);let gt=M.ownerDocument.createElement("a");gt.setAttribute(oe,We),gt.setAttribute(an,"1"),gt.style.position="absolute",M.appendChild(gt),this.page.registerElementWithId(M,We);continue}if(oe=="src"||oe=="href"||oe=="poster")he=this.resolveURL(he),oe==="href"&&(he=this.documentURLTransformer.transformURL(he,this.xmldoc.url));else if(oe=="srcset")he=he.split(",").map(We=>this.resolveURL(We.trim())).join(",");else if(oe==="data"&&rs&&$==="object"&&M.hasAttribute("data"))continue;if(oe==="poster"&&$==="video"&&Ft==="http://www.w3.org/1999/xhtml"&&bl&&xl){let We=new Image,gt=Dn(We,he);Oo.push(gt),kt.push({image:We,element:M,fetcher:gt})}}if(Ft=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(oe)&&(oe=oe.toLowerCase()),this.isSVGUrlAttribute(oe)&&(he=wg(he,this.xmldoc.url,this.documentURLTransformer)),rt){let We=Nb[rt];We&&(oe=`${We}:${oe}`)}if(oe=="src"&&!rt&&($=="img"||$=="input")&&Ft=="http://www.w3.org/1999/xhtml")tr=he;else if(oe=="alt"&&!rt&&$=="img"&&Ft=="http://www.w3.org/1999/xhtml")Op=he;else if(oe=="href"&&$=="image"&&Ft=="http://www.w3.org/2000/svg"&&rt=="http://www.w3.org/1999/xlink")this.page.fetchers.push(Dn(M,he));else if(rt)M.setAttributeNS(rt,oe,he);else try{M.setAttribute(oe,he)}catch(We){F.warn(We)}}if(tr){let Ze=$==="input"?new Image:M,jt=Dn(Ze,tr,Op);Ze!==M&&(M.src=tr);let rt=()=>{var he,We;if(c.position===b.fixed)return!0;for(let gt=(he=this.nodeContext.parent)==null?void 0:he.viewNode;gt&>!==this.viewRoot;gt=gt.parentElement)if(((We=gt.style)==null?void 0:We.position)==="fixed")return!0;return!1};!bl&&!xl&&!(()=>{let he=this.nodeContext.vertical?it:Cl;return he instanceof P&&he.unit==="%"})()&&!rt()?this.page.fetchers.push(jt):(bl&&xl&&ot&&ot!==1&&kt.push({image:Ze,element:M,fetcher:jt}),Oo.push(jt))}delete c.content;let yl=c["list-style-image"];if(yl&&yl instanceof Fe){let Ze=yl.url;Oo.push(Dn(new Image,Ze))}if(this.preprocessElementStyle(c),this.applyComputedStyles(M,c),this.nodeContext.inline)e||(dt(M,"inline-start"),Ss(M)&&dt(M,"clone"));else if(e){if(!ia(c.position)){let Ze=c["margin-break"],jt=this.getBreakTypeAt(this.nodeContext),rt=jt!==null,oe=jt==="auto";(Ze===b.discard&&rt||Ze!==b.keep&&oe&&!this.nodeContext.floatSide)&&$r(M,"block-start")}}else{let Ze=this.nodeContext.vertical?"width":"height";Ot(M,Ze)&&w(M,Ze,this.nodeContext.display==="table-row"?"0.01px":""),dt(M,"block-start"),Ss(M)&&dt(M,"clone"),$r(M,"block-start")}I&&M.setAttribute("value",c["ua-list-item-count"].stringValue()),this.viewNode=M,Oo.length?On(Oo).then(()=>{ot>0&&this.modifyElemDimensionWithImageResolution(kt,ot,c,this.nodeContext.vertical),o.finish(s)}):o.timeSlice().then(()=>{o.finish(s)})})}),o.result()}isInsideNonRootMultiColumn(){var n;let e=(n=this.nodeContext.parent)==null?void 0:n.viewNode;return!!(e&&hi(e))}getBreakTypeAt(e){var s,o,i,a,l;if(this.isInsideTable(e))return null;for(let c=e;c&&!c.after;c=c.parent){if(Re(c.breakBefore))return c.breakBefore;if(c.fragmentIndex===1&&!c.parent)return c.sourceNode===c.sourceNode.ownerDocument.documentElement?"page":null;if((s=c.parent)!=null&&s.floatSide)return null;let u=(o=c.parent)==null?void 0:o.viewNode;if(u){let d=this.viewport.window.getComputedStyle(u),h=parseFloat(d.paddingBlockStart),f=parseFloat(d.borderBlockStartWidth);if(h||f)return null;let g=u==null?void 0:u.firstChild;for(;g&&(de(g,c.parent.whitespace)||!c.floatSide&&ws(g));)g=g.nextSibling;if(g&&g!==c.viewNode)return null}}let n=(l=(a=(i=this.context)==null?void 0:i.currentLayoutPosition)==null?void 0:a.flowPositions[this.flowName])==null?void 0:l.startBreakType;return Re(n)?n:"auto"}isInsideTable(e){for(let n=e;n&&!n.after;n=n.parent)if(n.display&&n.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(e,n,s,o){let i=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(i&&i["after-if-continues"]&&i["after-if-continues"].content){let a=new vi(e,n,s,o,this.exprContentListener);this.nodeContext.afterIfContinues=new ka(e,a)}}isSVGUrlAttribute(e){return Yi.SVG_URL_ATTRIBUTES.includes(e.toLowerCase())}modifyElemDimensionWithImageResolution(e,n,s,o){e.forEach(i=>{if(i.fetcher.get().get()==="load"){let a=i.image,l=a.width/n,c=a.height/n,u=i.element;if(l>0&&c>0){if(s["box-sizing"]===b.border_box&&(s["border-left-style"]!==b.none&&(l+=Pe(s["border-left-width"],this.context)),s["border-right-style"]!==b.none&&(l+=Pe(s["border-right-width"],this.context)),s["border-top-style"]!==b.none&&(c+=Pe(s["border-top-width"],this.context)),s["border-bottom-style"]!==b.none&&(c+=Pe(s["border-bottom-width"],this.context))),n>1){let d=s["max-width"]||b.none,h=s["max-height"]||b.none;if(d===b.none&&h===b.none)w(u,"max-width",`${l}px`);else if(d!==b.none&&h===b.none)w(u,"width",`${l}px`);else if(d===b.none&&h!==b.none)w(u,"height",`${c}px`);else{d.isNumeric(),h.isNumeric();let f=d,g=h;f.unit!=="%"?w(u,"max-width",`${Math.min(l,Pe(f,this.context))}px`):g.unit!=="%"?w(u,"max-height",`${Math.min(c,Pe(g,this.context))}px`):o?w(u,"height",`${c}px`):w(u,"width",`${l}px`)}}else if(n<1){let d=s["min-width"]||ne,h=s["min-height"]||ne;d.isNumeric(),d.isNumeric();let f=d,g=h;f.num===0&&g.num===0?w(u,"min-width",`${l}px`):f.num!==0&&g.num===0?w(u,"width",`${l}px`):f.num===0&&g.num!==0?w(u,"height",`${c}px`):f.unit!=="%"?w(u,"min-width",`${Math.max(l,Pe(f,this.context))}px`):g.unit!=="%"?w(u,"min-height",`${Math.max(c,Pe(g,this.context))}px`):o?w(u,"height",`${c}px`):w(u,"width",`${l}px`)}}}})}preprocessElementStyle(e){He("PREPROCESS_ELEMENT_STYLE").forEach(s=>{s(this.nodeContext,e)})}findAndProcessRepeatingElements(e,n){for(let s=e.firstChild;s;s=s.nextSibling){if(s.nodeType!==1)continue;let o={},i=n.getStyle(s,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",i,o),!this.processRepeatOnBreak(o))continue;if(this.nodeContext.formattingContext instanceof Wt&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let l=this.nodeContext.parent,c=l&&l.formattingContext;this.nodeContext.formattingContext=new Wt(c,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(e){let n=e["repeat-on-break"];return n!==b.none&&((n===b.auto||U(n))&&(e.display===b.table_header_group?n=b.header:e.display===b.table_footer_group?n=b.footer:n=b.none),n&&n!==b.none)?n.toString():null}createTextNodeView(){let e=A("createTextNodeView");return this.preprocessTextContent().then(()=>{let n=this.offsetInNode||0,s=Mc(this.nodeContext.preprocessedTextContent).substr(n);this.viewNode=document.createTextNode(s),e.finish(!0)}),e.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return T(!0);let e,n=e=this.sourceNode.textContent,s=A("preprocessTextContent"),o=He("PREPROCESS_TEXT_CONTENT"),i=0;return s.loop(()=>i>=o.length?T(!1):o[i++](this.nodeContext,n).thenAsync(a=>(n=a,T(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Gh(e,n),s.finish(!0)}),s.result()}createNodeView(e,n){let s=A("createNodeView"),o,i=!0;return this.sourceNode.nodeType==1?o=this.createElementView(e,n):this.sourceNode.nodeType==8?(this.viewNode=null,o=T(!0)):o=this.createTextNodeView(),o.then(a=>{var l;if(i=a,this.nodeContext.viewNode=this.viewNode,this.viewNode){let c=(h,f)=>(h==null?void 0:h.nodeType)===1&&Bs(h)===f,u=this.nodeContext.parent,d=u?c(this.viewNode,"after")&&c(u.viewNode,"first-letter")&&((l=u.viewNode)!=null&&l.hasChildNodes())?u.parent.viewNode:u.viewNode:this.viewRoot;d&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&de(this.viewNode))&&!d.hasChildNodes()&&Ic(d).includes("block-start")&&dt(d,"text-start"),d.appendChild(this.viewNode),uf(this.viewNode))}s.finish(i)}),s.result()}setCurrent(e,n,s){return this.nodeContext=e,e?(this.sourceNode=e.sourceNode,this.offsetInNode=e.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(n,!!s):T(!0)}processShadowContent(e){if(e.shadowContext==null||e.sourceNode.localName!="content"||e.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return e;let n=e.boxOffset,s=e.shadowContext,o=e.parent,i,a,l=s.subShadow||s.parentShadow;s.subShadow?(i=s.root,a=s.type,a==Nt.ROOTLESS&&(i=i.firstChild)):(i=s.owner.firstChild,a=Nt.ROOTLESS);let c=e.sourceNode.nextSibling;if(c?(e.sourceNode=c,e.resetView()):e.shadowSibling?e=e.shadowSibling:i?e=null:(e=e.parent.modify(),e.after=!0),i){let u=new Gn(i,o,n);return u.shadowContext=l,u.shadowType=a,u.shadowSibling=e,u}return e.boxOffset=n,e}nextPositionInTree(e){let n=e.boxOffset+1;if(e.after){if(!e.parent)return null;if(e.shadowType!=Nt.ROOTED){let s=e.sourceNode.nextSibling;if(s)return e=e.modify(),e.boxOffset=n,e.sourceNode=s,e.resetView(),this.processShadowContent(e)}return e.shadowSibling?(e=e.shadowSibling.modify(),e.boxOffset=n,e):(e=e.parent.modify(),e.boxOffset=n,e.after=!0,e)}else{if(e.nodeShadow){let o=e.nodeShadow.root;if(e.nodeShadow.type==Nt.ROOTLESS&&(o=o.firstChild),o){let i=new Gn(o,e,n);return i.shadowContext=e.nodeShadow,i.shadowType=e.nodeShadow.type,this.processShadowContent(i)}}let s=e.sourceNode.firstChild;if(s)return this.processShadowContent(new Gn(s,e,n));if(e.sourceNode.nodeType!=1){let o=Mc(e.preprocessedTextContent);n+=o.length-1-e.offsetInNode}return e=e.modify(),e.boxOffset=n,e.after=!0,e}}isTransclusion(e,n,s){let o=pe(n,"hyperlink-processing");if(!o)return!1;let i=o.evaluate(this.context,"hyperlink-processing");return i?i.toString()==s:!1}nextInTree(e,n){let s=this.nextPositionInTree(e);if(!s||s.after)return T(s);let o=A("nextInTree");return this.setCurrent(s,!0,n).then(i=>{(!s.viewNode||!i)&&(s=s.modify(),s.after=!0,s.viewNode||(s.inline=!0)),this.dispatchEvent({type:"nextInTree",nodeContext:s}),o.finish(s)}),o.result()}addImageFetchers(e){if(e instanceof fe){let n=e.values;for(let s=0;s<n.length;s++)this.addImageFetchers(n[s])}else if(e instanceof Fe){let n=e.url;this.page.fetchers.push(Dn(new Image,n))}}applyComputedStyles(e,n){var u,d,h;let s=n["background-image"];s&&this.addImageFetchers(s);let o=n.position===b.relative,i=((u=this.nodeContext)==null?void 0:u.parent)===null&&((d=this.sourceNode)==null?void 0:d.parentElement)===null&&!!((h=this.viewRoot)!=null&&h.parentElement),a=Object.keys(n);a.sort(Xl);let l,c;for(let f of a){if(Tb[f])continue;let g=n[f];if(!(!g||g===D&&!yt(f))){if(g=g.visit(new Fr(this.xmldoc.url,this.documentURLTransformer)),g instanceof P)if(g.unit==="em"){let m=this.getEmUnitSize(f,l);m!=null&&(g=new P(g.num*m,"px"))}else if(g.unit==="lh"){let m=this.getLineHeightUnitSize(f,l,c);m!=null&&(g=new P(g.num*m,"px"))}else Pr(g.unit)&&(g=Lr(g,this.context));if((f==="font-size"||f==="line-height")&&(f==="font-size"?l=g:c=g,this.viewport.layoutUnitAdj&&g instanceof P&&g.unit!=="%"&&g.unit!=="em"&&g.unit!=="lh"&&(g=new en(`calc(${g.toString()} - var(--viv-layoutUnitAdj))`))),jh[f]||o&&Yh[f]){this.page.delayedItems.push(new zn(e,f,g));continue}i&&this.page.pageAreaElement&&Zn(f)?w(this.page.pageAreaElement.parentElement.parentElement,f,g.toString()):w(e,f,g.toString())}}}parsePlusLayoutUnitAdj(e){if(e.endsWith("px")){let n=parseFloat(e);if(!isNaN(n))return Math.round((n+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getLineHeightUnitSize(e,n,s){var l,c,u,d,h,f;let o=((u=(c=(l=this.nodeContext)==null?void 0:l.parent)==null?void 0:c.viewNode)==null?void 0:u.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,i=o?this.parsePlusLayoutUnitAdj(o.lineHeight):this.context.rootLineHeight;if(e==="line-height"||e==="font-size")return i;let a=null;if(s)if(s instanceof Je||s instanceof P&&(s.unit==="em"||s.unit==="%"))a=s instanceof P&&s.unit==="%"?s.num/100:s.num;else{if(s instanceof P&&s.unit!=="lh"){let g=this.context.queryUnitSize(s.unit,!1);if(g!=null)return s.num*g}return null}if(a==null)for(let g=(h=(d=this.nodeContext)==null?void 0:d.parent)==null?void 0:h.viewNode;g&&g.nodeType===1;g=g.parentNode){let m=(f=g==null?void 0:g.style)==null?void 0:f.lineHeight;if(m){/^[0-9.]+$/.test(m)&&(a=parseFloat(m));break}}if(a!=null){if(n&&!(n instanceof P))return null;let g=o?this.parsePlusLayoutUnitAdj(o.fontSize):this.context.rootFontSize;if(n instanceof P){let m=Ea(n,g,this.context).num;return typeof m!="number"||isNaN(m)?null:a*m}else return g==null?null:a*g}return i}getEmUnitSize(e,n){var i,a,l;let s=((l=(a=(i=this.nodeContext)==null?void 0:i.parent)==null?void 0:a.viewNode)==null?void 0:l.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,o=s?this.parsePlusLayoutUnitAdj(s.fontSize):this.context.rootFontSize;if(e==="font-size"||n==null)return o;if(n instanceof P){let c=Ea(n,o,this.context).num;if(typeof c=="number"&&!isNaN(c))return c}return null}applyPseudoelementStyle(e,n,s){if(e.after)return;let o=this.sourceNode,a=(e.shadowContext?e.shadowContext.styler:this.styler).getStyle(o,!1),l=Pt(a,"_pseudos");if(!l||(a=l[n],!a))return;let c={};e.vertical=this.computeStyle(e.vertical,e.direction==="rtl",a,c);let u=c.content;vt(u)&&(u.visit(new bn(s,this.context,u,this.exprContentListener)),delete c.content),this.applyComputedStyles(s,c)}peelOff(e,n){let s=A("peelOff"),o=e.firstPseudo,i=e.offsetInNode,a=e.after;if(n>0){let h=e.viewNode.textContent;e.viewNode.textContent=h.substr(0,n),i+=n}else if(!a&&e.viewNode&&i==0){let h=e.viewNode.parentNode;h&&h.removeChild(e.viewNode)}let l=e.boxOffset+n,c=[];for(;e.firstPseudo===o;)c.push(e),e=e.parent;let u=c.pop(),d=u.shadowSibling;return s.loop(()=>{for(;c.length>0;){u=c.pop(),e=new Gn(u.sourceNode,e,l),c.length==0&&(e.offsetInNode=i,e.after=a),e.shadowType=u.shadowType,e.shadowContext=u.shadowContext,e.nodeShadow=u.nodeShadow,e.shadowSibling=u.shadowSibling?u.shadowSibling:d,d=null;let h=this.setCurrent(e,!1);if(h.isPending())return h}return T(!1)}).then(()=>{s.finish(e)}),s.result()}createElement(e,n){return e=="http://www.w3.org/1999/xhtml"?this.document.createElement(n):this.document.createElementNS(e,n)}applyFootnoteStyle(e,n,s){let o={},i=Pt(this.footnoteStyle,"_pseudos");if(e=this.computeStyle(e,n,this.footnoteStyle,o),i&&i.before){let a={},l=this.createElement("http://www.w3.org/1999/xhtml","span");Ti(l,"before"),s.appendChild(l),this.computeStyle(e,n,i.before,a),delete a.content,this.applyComputedStyles(l,a)}return delete o.content,this.applyComputedStyles(s,o),e}processFragmentedBlockEdge(e){var i,a,l;let n=!e.inline&&e.after?e.parent:e,s=!1;if(e.inline&&e.after&&!e.shadowContext&&((i=e.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let c=e.sourceNode.nextSibling,u=(a=pe(this.styler.getStyle(c,!1),"display"))==null?void 0:a.value.toString();s=u&&!Gt(u)||c.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(c.textContent)}let o=0;for(let c=n;c;c=c.parent){if(((l=c.viewNode)==null?void 0:l.nodeType)!==1)continue;let u=c.viewNode;if(u.style)if(c.inline){if(dt(u,"inline-end"),Ss(u)){let d=c.vertical?u.offsetWidth:u.offsetHeight;dt(u,"clone"),(c.vertical?u.offsetWidth:u.offsetHeight)>d&&this.fixClonedBoxDecorationOverflow(u)}}else{let d=this.nodeContext.vertical?"width":"height";if(Ot(u,d)&&w(u,d,""),dt(u,"block-end"),!o++&&c!==n){let{textAlign:h}=this.viewport.window.getComputedStyle(u);if(h==="justify"&&!s){let f=this.createChildAnonymousBlockIfNeeded(u);f?f!==u?Vc(f,["block-start","text-start","block-end","text-end","justify"]):(dt(u,"text-end"),dt(u,"justify")):dt(u,"text-end")}else dt(u,"text-end")}Ss(u)&&dt(u,"clone"),$r(u,"block-end")}}}fixClonedBoxDecorationOverflow(e){let n=this.viewport.window.getComputedStyle(e),s=parseFloat(n.paddingInlineEnd),o=parseFloat(n.borderInlineEndWidth),i=-(s+o);isNaN(i)||(e.style.marginInlineEnd=`${i}px`)}createChildAnonymousBlockIfNeeded(e){let n=i=>{let{display:a,position:l,float:c}=this.viewport.window.getComputedStyle(i);if(i.localName==="ruby"||Zt[i.localName])return!1;if(i.localName==="br")return!0;if((a==="inline"||a==="contents")&&i.hasChildNodes()){let u=i.lastElementChild;if(u&&(!u.nextSibling||u.nextSibling===i.lastChild&&de(u.nextSibling))){let d=n(u);if(d||d===null)return d}for(let d=u==null?void 0:u.previousElementSibling;d;d=d.previousElementSibling){let h=n(d);if(h||h===null)return null}return!1}if(a==="none"||l==="absolute"||l==="fixed"||c&&c!=="none"||i.hasAttribute(an)){let u=i.previousElementSibling;return u&&(u.nextSibling===i||u.nextSibling===i.previousSibling&&de(u.nextSibling))?n(u):!1}return!(!a||Gt(a))},s=null;for(let i=e.lastElementChild;i;i=i.previousElementSibling){let a=n(i);if(a){s=i;break}if(a===null)return null}if(!s)return e;if(s===e.lastElementChild&&(!s.nextSibling||s.nextSibling===e.lastChild&&de(s.nextSibling)))return null;let o=e.ownerDocument.createElement("span");o.className="viv-anonymous-block";for(let i=s.nextSibling,a=null;i;i=a)a=i.nextSibling,o.appendChild(i);return e.appendChild(o),o}convertLengthToPx(e,n,s){let o=e.num,i=e.unit;if(th(i)){let a=n;for(;a&&a.nodeType!==1;)a=a.parentNode;let l=parseFloat(s.getElementComputedStyle(a)["font-size"]);return this.context,ya(e,l,this.context).num}else{let a=this.context.queryUnitSize(i,!1);return a?o*a:e}}isSameNodePositionStep(e,n){if(e.shadowContext){if(!n.shadowContext)return!1;let s=e.node.nodeType===1?e.node:e.node.parentElement,o=n.node.nodeType===1?n.node:n.node.parentElement;return e.shadowContext.owner===n.shadowContext.owner&&Bs(s)===Bs(o)}else return e.node===n.node}isSameNodePosition(e,n){return e.offsetInNode===n.offsetInNode&&e.after==n.after&&e.steps.length===n.steps.length&&e.steps.every((s,o)=>{let i=n.steps[o];return this.isSameNodePositionStep(s,i)})}isPseudoelement(e){return!!Bs(e)}};p(Yi,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var el=Yi,Tb={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-policy":!0,"margin-break":!0,page:!0},tl=class{constructor(t){p(this,"layoutBox");p(this,"window");p(this,"scaleRatio");p(this,"layoutUnitPerPixel");this.layoutBox=t.layoutBox,this.window=t.window,this.scaleRatio=t.scaleRatio,this.layoutUnitPerPixel=t.layoutUnitPerPixel}subtractOffsets(t,e){let n=e.left,s=e.top;return{left:t.left-n,top:t.top-s,right:t.right-n,bottom:t.bottom-s,width:t.width,height:t.height}}getRangeClientRects(t){let e=t.getClientRects(),n=this.layoutBox.getBoundingClientRect();return Array.from(e).map(s=>this.subtractOffsets(s,n))}getElementClientRect(t){let n=t.getBoundingClientRect();if(n.left===0&&n.top===0&&n.right===0&&n.bottom===0)return n;let s=this.layoutBox.getBoundingClientRect();return this.subtractOffsets(n,s)}getElementComputedStyle(t){return this.window.getComputedStyle(t,null)}adjustLengthValue(t){return this.layoutUnitPerPixel?Math.floor(t*this.layoutUnitPerPixel)/this.layoutUnitPerPixel:t}},An=class{constructor(t,e,n,s,o,i){this.window=t;this.fontSize=e;this.pixelRatio=n;p(this,"document");p(this,"root");p(this,"outerZoomBox");p(this,"contentContainer");p(this,"layoutBox");p(this,"width");p(this,"height");p(this,"scaleRatio",1);p(this,"layoutUnitPerPixel");p(this,"layoutUnitAdj",0);this.document=t.document,this.root=s||this.document.body;let a=this.root.firstElementChild;a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-outer-zoom-box","true"),a.role="presentation",this.root.appendChild(a));let l=a.firstElementChild;switch(l||(l=this.document.createElement("div"),l.setAttribute("data-vivliostyle-spread-container","true"),l.role="presentation",a.appendChild(l)),n>0&&CSS.supports("zoom","8")&&(w(this.root,"--viv-outputPixelRatio",`${n}`),w(this.root,"--viv-devicePixelRatio",`${t.devicePixelRatio}`),this.scaleRatio=n/t.devicePixelRatio),ar){case"chromium":this.layoutUnitPerPixel=64*(this.pixelRatio||t.devicePixelRatio),this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"firefox":this.layoutUnitPerPixel=60,this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"webkit":default:this.layoutUnitPerPixel=64,this.layoutUnitAdj=0}this.layoutUnitAdj&&w(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let c=a.nextElementSibling;c||(c=this.document.createElement("div"),c.setAttribute("data-vivliostyle-layout-box","true"),c.role="presentation",this.root.appendChild(c)),this.outerZoomBox=a,this.contentContainer=l,this.layoutBox=c,this.width=o||parseFloat(t.getComputedStyle(this.root).width)||this.root.offsetWidth||t.innerWidth,this.height=i||parseFloat(t.getComputedStyle(this.root).height)||this.root.offsetHeight||t.innerHeight;let u={width:794,height:1056},d=!t.outerWidth&&!t.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&t.innerWidth===800&&t.innerHeight===600;(!this.width||!o&&d)&&(this.width=u.width),(!this.height||!i&&d)&&(this.height=u.height)}resetZoom(){w(this.outerZoomBox,"width",""),w(this.outerZoomBox,"height",""),w(this.contentContainer,"width",""),w(this.contentContainer,"height",""),w(this.contentContainer,"transform","")}zoom(t,e,n){w(this.root,"--viv-outputScale",`${n}`),w(this.outerZoomBox,"width",`${t*n}px`),w(this.outerZoomBox,"height",`${e*n}px`),w(this.contentContainer,"width",`${t}px`),w(this.contentContainer,"height",`${e}px`)}clear(){let t=this.root;for(;t.lastChild;)t.removeChild(t.lastChild)}};var Ki=class{constructor(t,e,n){this.store=t;this.url=e;this.document=n;p(this,"lang",null);p(this,"totalOffset",-1);p(this,"root");p(this,"body");p(this,"head");p(this,"last");p(this,"lastOffset",1);p(this,"idMap");this.root=n.documentElement;let s=null,o=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let i=this.root.firstChild;i;i=i.nextSibling){if(i.nodeType!=1)continue;let a=i;if(a.namespaceURI=="http://www.w3.org/1999/xhtml")switch(a.localName){case"head":o=a;break;case"body":s=a;break}}this.lang=this.root.getAttribute("lang")}this.body=s,this.head=o,this.last=this.root,this.last.setAttribute(Bt,"0")}doc(){return new ol([this.document])}getElementOffset(t){let e=t.getAttribute(Bt);if(e)return parseInt(e,10);let n=this.lastOffset,s=this.last;for(;s!=t;){let o=s.firstChild;if(!o){for(;o=s.nextSibling,!o;)if(s=s.parentNode,s==null)throw new Error("Internal error")}s=o,o.nodeType==1?(o.setAttribute(Bt,n.toString()),++n):n+=o.textContent.length}return this.lastOffset=n,this.last=t,n-1}getNodeOffset(t,e,n){let s=0,o=t,i=null;if(o.nodeType==1){if(!n)return this.getElementOffset(o)}else{if(s=e,i=o.previousSibling,!i)return o=o.parentNode,s+=1,this.getElementOffset(o)+s;o=i}for(;;){for(;o.lastChild;)o=o.lastChild;if(o.nodeType==1)break;if(s+=o.textContent.length,i=o.previousSibling,!i){o=o.parentNode;break}o=i}return s+=1,this.getElementOffset(o)+s}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(t){let e,n=this.root;for(;;){if(e=this.getElementOffset(n),e>=t)return n;let l=n.children;if(!l)break;let c=Ct(l.length,u=>{let d=l[u];return this.getElementOffset(d)>t});if(c==0)break;n=l[c-1]}let s=e+1,o=n,i=o.firstChild||o.nextSibling,a=null;for(;;){if(i){if(i.nodeType==1||(o=i,a=o,s+=i.textContent.length,s>t&&!/^\s*$/.test(i.textContent)))break}else if(o=o.parentNode,!o)break;i=o.nextSibling}return i&&a&&/^\s*$/.test(a.textContent)&&(a=i),a||n}buildIdMap(t){let e=t.getAttribute("id");e&&!this.idMap[e]&&(this.idMap[e]=t);let n=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");n&&!this.idMap[n]&&(this.idMap[n]=t);for(let s=t.firstElementChild;s;s=s.nextElementSibling)this.buildIdMap(s)}getElement(t){let e=t.match(/([^#]*)#(.+)$/);if(!e||e[1]&&e[1]!=this.url)return null;let n=e[2],s=this.document.getElementById(n);return!s&&this.document.getElementsByName&&(s=this.document.getElementsByName(n)[0]),s||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),s=this.idMap[n]),s}},Ep=(o=>(o.TEXT_HTML="text/html",o.TEXT_XML="text/xml",o.APPLICATION_XML="application/xml",o.APPLICATION_XHTML_XML="application/xhtml+xml",o.IMAGE_SVG_XML="image/svg+xml",o))(Ep||{});function sl(r,t,e){let n=e||new DOMParser,s;try{s=n.parseFromString(r,t)}catch(o){}if(s){let o=s.documentElement,i="parsererror";if(o.localName===i)return null;for(let a=o.firstElementChild;a;a=a.nextElementSibling)if(a.localName===i)return null}else return null;return s}function wb(r){let t=r.contentType;if(t){let n=Object.keys(Ep);for(let s=0;s<n.length;s++)if(Ep[n[s]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let e=r.url.match(/\.([^./#?]+)([#?]|$)/);if(e)switch(e[1]){case"html":case"htm":return"text/html";case"xhtml":case"xht":return"application/xhtml+xml";case"svg":case"svgz":return"image/svg+xml";case"opf":case"xml":return"application/xml"}return null}function Np(r,t){let e=r.responseXML;if(!e){let s=new DOMParser,o=r.responseText;if(o){let i=wb(r);if(e=sl(o,i||"application/xml",s),e&&!i){let a=e.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?e=sl(o,"text/html",s):a.localName.toLowerCase()==="svg"&&e.contentType!=="image/svg+xml"&&(e=sl(o,"image/svg+xml",s))}e||(e=sl(o,"text/html",s))}}let n=e?new Ki(t,r.url,e):null;return T(n)}function Pg(){return new bs(Np,"document")}var Sp=class r{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,e){return new r(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==e)}withChild(t,e){return new r(n=>{if(!this.check(n))return!1;let s=new ol([n]);return s=s.child(t),e&&(s=s.predicate(e)),s.size()>0})}},vp=new Sp(r=>!0),ol=class r{constructor(t){this.nodes=t}asArray(){return this.nodes}size(){return this.nodes.length}predicate(t){let e=[];for(let n of this.nodes)t.check(n)&&e.push(n);return new r(e)}forEachNode(t){let e=[],n=s=>{e.push(s)};for(let s=0;s<this.nodes.length;s++)t(this.nodes[s],n);return new r(e)}forEach(t){let e=[];for(let n=0;n<this.nodes.length;n++)e.push(t(this.nodes[n]));return e}forEachNonNull(t){let e=[];for(let n=0;n<this.nodes.length;n++){let s=t(this.nodes[n]);s!=null&&e.push(s)}return e}child(t){return this.forEachNode((e,n)=>{for(let s=e.firstChild;s;s=s.nextSibling)s.nodeType==1&&s.localName==t&&n(s)})}childElements(){return this.forEachNode((t,e)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&e(n)})}attribute(t){return this.forEachNonNull(e=>e.nodeType==1?e.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}};var Pb=new nn(()=>{let r=A("uaStylesheetBase"),t=Yd(),e=Q("user-agent-base.css",Kt),n=new wn(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),wf(n.cascade),Wr(Nc,n,e,null,null).thenFinish(r),r.result()},"uaStylesheetBaseFetcher");function kb(){return Pb.get()}var Tp=class{constructor(t,e,n,s,o,i,a,l,c,u){this.store=t;this.rootScope=e;this.pageScope=n;this.cascade=s;this.rootBox=o;this.fontFaces=i;this.footnoteProps=a;this.flowProps=l;this.viewportProps=c;this.pageProps=u;p(this,"fontDeobfuscator");p(this,"validatorSet");this.fontDeobfuscator=t.fontDeobfuscator,this.validatorSet=t.validatorSet,this.pageScope.defineBuiltIn("has-content",function(d){d=d;let h=this,f=h.currentLayoutPosition,g=f.firstFlowChunkOfFlow(d);return h.matchPageSide(f.startSideOfFlow(d))&&f.hasContent(d,h.lookupOffset)&&!!g&&!h.flowChunkIsAfterParentFlowForcedBreak(g)}),this.pageScope.defineName("page-number",new q(this.pageScope,function(){let d=this;return d.pageNumberOffset+d.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new q(this.pageScope,function(){let h=this.currentLayoutPosition;return h==null?void 0:h.isBlankPage},"blank-page"))}sizeViewport(t,e,n,s){if(this.viewportProps.length){let o=new Ys(this.rootScope,t,e,n),i=vf(o,this.viewportProps),a=i.width,l=i.height,c=i["text-zoom"],u=1;if(a&&l||c){let d=K.em;if((c?c.evaluate(o,"text-zoom"):null)===b.scale&&(u=d/n,n=d,t*=u,e*=u),a&&l){let f=Pe(a.evaluate(o,"width"),o),g=Pe(l.evaluate(o,"height"),o);if(f>0&&g>0)return{width:s&&s.spreadView?(f+s.pageBorder)*2:f,height:g,fontSize:n}}}}return{width:t,height:e,fontSize:n}}},ss=class extends Ys{constructor(e,n,s,o,i,a,l,c,u,d,h,f,g){super(e.rootScope,o.width,o.height,o.fontSize);this.style=e;this.xmldoc=n;this.viewport=o;this.clientLayout=i;this.fontMapper=a;this.customRenderer=l;this.fallbackMap=c;this.pageNumberOffset=u;this.documentURLTransformer=d;this.counterStore=h;p(this,"lang");p(this,"primaryFlows",{body:!0});p(this,"rootPageBoxInstance",null);p(this,"styler",null);p(this,"stylerMap",null);p(this,"currentLayoutPosition",null);p(this,"layoutPositionAtPageStart",null);p(this,"lookupOffset",0);p(this,"faces");p(this,"pageBoxInstances",{});p(this,"pageManager",null);p(this,"rootPageFloatLayoutContext");p(this,"pageBreaks",{});p(this,"pageProgression",null);p(this,"isVersoFirstPage",!1);p(this,"blankPageAtStart",!1);p(this,"pageSheetSize",{});p(this,"pageSheetHeight",0);p(this,"pageSheetWidth",0);this.lang=n.lang||s,this.faces=new Ha(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new xn(null,null,null,null,null,null,null),this.pageProgression=f||null,this.isVersoFirstPage=!!g;for(let m in e.flowProps){let x=e.flowProps[m],E=pe(x,"flow-consume");E&&(E.evaluate(this,"flow-consume")==b.all?this.primaryFlows[m]=!0:delete this.primaryFlows[m])}}init(){let e=A("StyleInstance.init"),n=this.counterStore.createCounterListener(this.xmldoc.url),s=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new Ii(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,n,s),s.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let o=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=mp(o)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let i=this.style.rootBox;this.rootPageBoxInstance=new Xa(i);let a=this.style.cascade.createInstance(this,n,s,this.lang);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(a,o),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new qa(a,this.style.pageScope,this.rootPageBoxInstance,this,o);let l=[];for(let u of this.style.fontFaces){if(u.condition&&!u.condition.evaluate(this))continue;let d=ug(u.properties,this),h=new Mi(d);l.push(h)}this.fontMapper.findOrLoadFonts(l,this.faces).then(()=>{vg(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let c=this.style.pageProps;return c[""]||(c[""]={}),Object.keys(c).forEach(u=>{let d=c[u];this.styler.cascade.applyVarFilter([d],this.styler,null),this.styler.cascade.applyCalcFilter(d,this.styler.context);let h=Cp(ji(d),this);this.pageSheetSize[u]={width:h.pageWidth+h.cropOffset*2,height:h.pageHeight+h.cropOffset*2}}),e.result()}matchStartPageSide(e){let n=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),s=this.pageProgression=="ltr";switch(e){case"left":return n!==s;case"right":return n===s;case"recto":return n;case"verso":return!n;default:return!0}}getStylerForDoc(e){let n=this.stylerMap[e.url];if(!n){let s=this.style.store.getStyleForDoc(e),o=new Ys(s.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),i=this.counterStore.createCounterListener(e.url),a=this.counterStore.createCounterResolver(e.url,s.rootScope,s.pageScope);n=new Ii(e,s.cascade,s.rootScope,o,this.primaryFlows,s.validatorSet,i,a),this.stylerMap[e.url]=n}return n}registerInstance(e,n){this.pageBoxInstances[e]=n}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,n){let s=this.currentLayoutPosition;if(s){s.flows[e.flowName]?n=s.flows[e.flowName]:s.flows[e.flowName]=n;let o=s.flowPositions[e.flowName];o||(o=new ea,s.flowPositions[e.flowName]=o);let i=Qh(e.element),a=new pt(i),l=new Jr(a,e);o.positions.push(l)}}evalSupportsTest(e,n,s){if(s)return e==="selector"?this.evalSupportsSelector(n):!1;if(!e)return!1;let o=!0;class i{unknownProperty(d,h){o=!1}invalidPropertyValue(d,h){o=!1}simpleProperty(d,h,f){}}let a=new i,l=on(this.style.rootScope,new Be(n,null),"");return l?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,l,!1,a),o):!1}evalSupportsSelector(e){let n=new il(null),s=new Be(e+"{}",n);return new Mn(ge,s,n,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!n.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let n=Number.POSITIVE_INFINITY;for(let s=0;s<e.positions.length;s++){let o=e.positions[s].chunkPosition.primary,i=o.steps[0].node,a=o.offsetInNode,l=o.after,c=0;for(;i.ownerDocument!=this.xmldoc.document;)c++,i=o.steps[c].node,l=!1,a=0;let u=this.xmldoc.getNodeOffset(i,a,l);u<n&&(n=u)}return n}getPosition(e,n){if(!e)return 0;let s=Number.POSITIVE_INFINITY;for(let o in this.primaryFlows){let i=e.flowPositions[o];if(!n&&(!i||i.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(o),i=this.currentLayoutPosition.flowPositions[o],e!=this.currentLayoutPosition&&i&&(i=i.clone(),e.flowPositions[o]=i)),i){let a=this.getConsumedOffset(i);a<s&&(s=a)}}return s}dumpLocation(e){F.debug("Location - page",this.currentLayoutPosition.page),F.debug(" current:",e),F.debug(" lookup:",this.lookupOffset);for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let o of s.positions)F.debug(" Chunk",`${n}:`,o.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new J(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let n in e.flowPositions){let s=e.flowPositions[n];if(s&&s.positions.length>0){let o=s.positions[0].flowChunk;if(this.getConsumedOffset(s)===o.startOffset){let i=s.positions[0].flowChunk.breakBefore,a=s.startBreakType;s.startBreakType=Fc(Ie(a,i))}}}}selectPageMaster(e){let n=this.currentLayoutPosition,s=this.getPosition(n);if(s==Number.POSITIVE_INFINITY)return null;let o=this.rootPageBoxInstance.children,i;for(let a=0;a<o.length;a++){if(i=o[a],i.pageBox.pseudoName===Qa)continue;let l=1;i.pageBox.pseudoName===Ui&&!(this.actualPageWidth&&this.actualPageHeight)&&(l=1/0);let c=i.getProp(this,"utilization");c&&c.isNum()&&(l=c.num);let u=this.queryUnitSize("em",!1),d=this.pageWidth()*this.pageHeight(),h=Math.ceil(l*d/(u*u)),f=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(s,h),this.styler.cascade.currentPageType=f,this.updateStartSide(n),this.layoutPositionAtPageStart=n.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let g=i.getProp(this,"enabled");if(!g||g===b._true){if(n.page===1&&this.blankPageAtStart){i.style={};let m=e.size;e={},m&&(e.size=m)}return this.pageManager.getPageRulePageMaster(i,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let n=this.layoutPositionAtPageStart.flows,s=n[e.flowName].parentFlowName;if(s){let o=e.startOffset,i=n[s].forcedBreakOffsets;if(!i.length||o<i[0])return!1;let a=Ct(i.length,d=>i[d]>o)-1,l=i[a],c=this.layoutPositionAtPageStart.flowPositions[s],u=this.getConsumedOffset(c);return l<u?!1:u<l?!0:!this.matchPageSide(c.startBreakType)}return!1}setFormattingContextToColumn(e,n){let s=this.currentLayoutPosition.flows[n];s.formattingContext||(s.formattingContext=new yo(null)),e.flowRootFormattingContext=s.formattingContext}layoutDeferredPageFloats(e){let n=e.pageFloatLayoutContext,s=n.getDeferredPageFloatContinuations(),o=c=>{if(c.floatReference!==le.PAGE)return!1;let u=this.layoutPositionAtPageStart.flowPositions.body,d=u&&this.getConsumedOffset(u),h=this.xmldoc.getNodeOffset(c.nodePosition.steps[0].node,0,!1);return h!=null&&d!=null&&h>d},i=A("layoutDeferredPageFloats"),a=!1,l=0;return i.loopWithFrame(c=>{if(l===s.length){c.breakLoop();return}let u=s[l++],d=u.float;if(o(d)){c.breakLoop();return}let h=new zt().findByFloat(d),f=h.findPageFloatFragment(d,n);if(f&&f.hasFloat(d)){c.continueLoop();return}else if(n.isForbidden(d)||n.hasPrecedingFloatsDeferredToNext(d)){n.deferPageFloat(u),c.breakLoop();return}e.layoutPageFloatInner(u,h,null,f).then(g=>{if(!g){c.breakLoop();return}let m=n.parent.isInvalidated();if(m){c.breakLoop();return}else n.isInvalidated()&&!m&&(a=!0,n.validate());c.continueLoop()})}).then(()=>{a&&n.invalidate(),i.finish(!0)}),i.result()}getLastAfterPositionIfDeferredFloatsExists(e,n){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return n?(i=n.clone(),i.primary=e.lastAfterPosition):i=new pt(e.lastAfterPosition),i}else return null;else return null}layoutColumn(e,n){let s=this.currentLayoutPosition.flowPositions[n];if(!s||!this.matchPageSide(s.startBreakType))return T(!0);this.setFormattingContextToColumn(e,n),e.init(),this.primaryFlows[n]&&e.bands.length>0&&(e.forceNonfitting=!1);let o=A("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){o.finish(!0);return}let i=[],a=[],l=!0;o.loopWithFrame(c=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(n)){c.breakLoop();return}for(;s.positions.length-a.length>0;){let u=0;for(;a.includes(u);)u++;let d=s.positions[u];if(d.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(d.flowChunk))break;for(let g=u+1;g<s.positions.length;g++){if(a.includes(g))continue;let m=s.positions[g];if(m.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(m.flowChunk))break;m.flowChunk.isBetter(d.flowChunk)&&(d=m,u=g)}let h=d.flowChunk,f=!0;if(e.layout(d.chunkPosition,l,s.breakAfter).then(g=>{if(e.pageFloatLayoutContext.isInvalidated()){c.breakLoop();return}if(l=!1,d.flowChunk.repeated&&(g===null||h.exclusive)&&i.push(u),h.exclusive){a.push(u),c.breakLoop();return}else{let m=!!g||!!e.pageBreakType,x=this.getLastAfterPositionIfDeferredFloatsExists(e,g);if(e.pageBreakType&&x?(d.chunkPosition=x,s.breakAfter=e.pageBreakType,e.pageBreakType=null):(a.push(u),(g||x)&&(d.chunkPosition=g||x,i.push(u)),s.startBreakType=Fc(e.pageBreakType)),m){c.breakLoop();return}}e.forceNonfitting=!1,f?f=!1:c.continueLoop()}),f){f=!1;return}}c.breakLoop()}).then(()=>{if(!e.pageFloatLayoutContext.isInvalidated()){s.positions=s.positions.filter((u,d)=>i.includes(d)||!a.includes(d)),s.breakAfter==="column"&&(s.breakAfter=null),e.saveDistanceToBlockEndFloats();let c=e.pageFloatLayoutContext.getMaxReachedAfterEdge();e.updateMaxReachedAfterEdge(c)}o.finish(!0)})}),o.result()}createLayoutConstraint(e){let n=this.currentLayoutPosition.page-1,s=this.counterStore.createLayoutConstraint(n);return new Aa([s].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,n,s,o,i,a,l,c,u,d,h,f,g,m){let x=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,E=i.element,C=new xn(c,le.COLUMN,null,l,null,null,null),y=this.currentLayoutPosition.clone(),N=A("createAndLayoutColumn"),S;return N.loopWithFrame(v=>{let k=this.createLayoutConstraint(C);if(u>1){let R=this.viewport.document.createElement("div");if(w(R,"position","absolute"),E.appendChild(R),S=new Ds(R,g,this.clientLayout,k,C),S.forceNonfitting=m,S.vertical=i.vertical,S.rtl=i.rtl,S.snapHeight=i.snapHeight,S.snapWidth=i.snapWidth,i.vertical){let z=(i.rtl?u-a-1:a)*(h+d)+i.paddingTop,te=parseFloat(E.style.width);S.setHorizontalPosition(i.paddingLeft+te-i.width,i.width),S.setVerticalPosition(z,h)}else{let z=(i.rtl?u-a-1:a)*(h+d)+i.paddingLeft;S.setVerticalPosition(i.paddingTop,i.height),S.setHorizontalPosition(z,h)}S.originX=n,S.originY=s}else S=new Ds(E,g,this.clientLayout,k,C),S.copyFrom(i);S.exclusions=x?[]:o.concat(),S.innerShape=f,C.setContainer(S),(S.vertical?S.height:S.width)>=0?this.layoutColumn(S,l).then(()=>{C.isInvalidated()||C.finish(),S.pageFloatLayoutContext.isInvalidated()&&!c.isInvalidated()?(S.pageFloatLayoutContext.validate(),this.currentLayoutPosition=y.clone(),S.element!==E&&E.removeChild(S.element),v.continueLoop()):v.breakLoop()}):(C.finish(),v.breakLoop())}).then(()=>{N.finish(S)}),N.result()}setPagePageFloatLayoutContextContainer(e,n,s){(n instanceof $i||n instanceof zs&&!(n instanceof pn))&&e.setContainer(s)}getRegionPageFloatLayoutContext(e,n,s,o){n instanceof dn;let i=n.getProp(this,"writing-mode")||null,a=n.getProp(this,"direction")||null;return new xn(e,le.REGION,s,o,null,i,a)}layoutFlowColumnsWithBalancing(e,n,s,o,i,a,l,c,u){let d=this.currentLayoutPosition.clone(),h=this.getRegionPageFloatLayoutContext(a,n,l,c),f=!0,g=()=>(this.currentLayoutPosition=d.clone(),this.layoutFlowColumns(e,n,s,o,i,a,h,l,c,u,f).thenAsync(m=>m?T({columns:m,position:this.currentLayoutPosition}):T(null)));return g().thenAsync(m=>{if(!m)return T(null);if(u<=1)return T(m.columns);let x=n.getProp(this,"column-fill")||b.balance,E=this.currentLayoutPosition.flowPositions[c];let C=Jf(u,x,g,h,l,m.columns,E);return C?(f=!1,a.lock(),h.lock(),C.balanceColumns(m).thenAsync(y=>(a.unlock(),a.validate(),h.unlock(),this.currentLayoutPosition=y.position,T(y.columns)))):T(m.columns)})}layoutFlowColumns(e,n,s,o,i,a,l,c,u,d,h){let f=A("layoutFlowColumns"),g=this.currentLayoutPosition.clone(),m=n.getPropAsNumber(this,"column-gap"),x=d>1?n.getPropAsNumber(this,"column-width"):c.vertical?c.height:c.width,E=n.getActiveRegions(this),C=n.getProp(this,"shape-inside"),y=Br(C,0,0,c.width,c.height,this),N=new el(u,this,this.viewport,this.styler,E,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer),S=0,v=null,k=[];return f.loopWithFrame(R=>{this.createAndLayoutColumn(n,s,o,i,c,S++,u,l,d,m,x,y,N,h).then(z=>{if(a.isInvalidated()){k=null,R.breakLoop();return}if((!!z.pageBreakType&&z.pageBreakType!=="column"||S===d)&&!l.isInvalidated()&&l.finish(),l.isInvalidated()){S=0,this.currentLayoutPosition=g.clone(),l.validate(),l.isLocked()?(k=null,R.breakLoop()):R.continueLoop();return}v=z,k[S-1]=v,v.pageBreakType&&v.pageBreakType!="column"&&(S=d,v.pageBreakType!="region"&&(this.pageBreaks[u]=!0)),S<d?R.continueLoop():R.breakLoop()})}).then(()=>{f.finish(k)}),f.result()}layoutContainer(e,n,s,o,i,a,l){n.reset();let c=n.getProp(this,"enabled");if(c&&c!==b._true)return T(!0);let u=A("layoutContainer"),h=n.getProp(this,"wrap-flow")===b.auto,f=n.getProp(this,"flow-from"),g=this.viewport.document.createElement("div");g.role=n instanceof Xi?"complementary":"presentation";let m=n.getProp(this,"position");w(g,"position",m?m.name:"absolute");let x=n instanceof pn;n instanceof dn?s.appendChild(g):s.insertBefore(g,s.firstChild);let C=new Co(g);C.vertical=n.vertical,C.rtl=n.rtl,C.borderBoxSizing=n.borderBoxSizing,C.exclusions=a,n.prepareContainer(this,C,e,this.faces,this.clientLayout),n instanceof pn&&(C.width<=0||C.height<=0)&&F.warn("Negative or zero page area size"),C.originX=o,C.originY=i,o+=C.left+C.marginLeft+C.borderLeft,i+=C.top+C.marginTop+C.borderTop,this.setPagePageFloatLayoutContextContainer(l,n,C);let y,N=!1;if(!f||!f.isIdent()){let S=n.getProp(this,"content");if(S instanceof B&&S.expr instanceof q&&S.expr.str.startsWith("running-element-"))S.visit(new bn(g,this,S,this.counterStore.getExprContentListener()));else if(S&&vt(S)){let v="span";S.url&&(v="img");let k=this.viewport.document.createElement(v);S.visit(new bn(k,this,S,this.counterStore.getExprContentListener())),g.appendChild(k),v=="img"&&n.transferSingleUriContentProps(this,k,this.faces),n.transferContentProps(this,C,e,this.faces),v=="span"&&Mf(k,n.getProp(this,"text-autospace"),n.getProp(this,"text-spacing-trim"),n.getProp(this,"hanging-punctuation"),this.lang,n.vertical)}else n.suppressEmptyBoxGeneration&&(s.removeChild(g),N=!0);N||n.finishContainer(this,C,e,null,1,this.clientLayout,this.faces),y=T(!0)}else if(this.pageBreaks[f.toString()])l.isInvalidated()||n.finishContainer(this,C,e,null,1,this.clientLayout,this.faces),y=T(!0);else{let S=A("layoutContainer.inner"),v=f.toString(),k=n.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,n,o,i,a,l,C,v,k).then(R=>{if(!l.isInvalidated()){let z=R[0];z.element===g&&(C=z),C.computedBlockSize=Math.max.apply(null,R.map(Ke=>Ke.computedBlockSize)),n.finishContainer(this,C,e,z,k,this.clientLayout,this.faces);let te=this.currentLayoutPosition.flowPositions[v];te&&te.breakAfter==="region"&&(te.breakAfter=null)}S.finish(!0)}),y=S.result()}return y.then(()=>{if(l.isInvalidated()){u.finish(!0);return}if(!n.isAutoHeight||Math.floor(C.computedBlockSize)>0){if(!N&&!h){let v=n.getProp(this,"shape-outside"),k=C.getOuterShape(v,this);a.push(k)}}else if(n.children.length==0){s.removeChild(g),u.finish(!0);return}let S=x?0:n.children.length-1;u.loop(()=>{for(;S>=0&&S<n.children.length;){let v=n.children[x?S++:S--],k=this.layoutContainer(e,v,g,o,i,a,l);if(k.isPending())return k.thenAsync(()=>T(!l.isInvalidated()));if(l.isInvalidated())break}return T(!1)}).then(()=>{u.finish(!0)})}),u.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let o=s.positions.length-1;o>=0;o--){let i=s.positions[o];i.flowChunk.startPage>=0&&i.flowChunk.startPage+i.flowChunk.linger-1<=e&&s.positions.splice(o,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let o=s.positions.length-1;o>=0;o--){let i=s.positions[o];i.flowChunk.startPage<0&&i.flowChunk.startOffset<this.lookupOffset&&(i.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let n in this.primaryFlows){let s=e.flowPositions[n];if(s&&s.positions.length>0)return!1}return!0}layoutNextPage(e,n){var g;let s=e.container===e.bleedBox;this.pageBreaks={},n?(this.currentLayoutPosition=n.clone(),this.styler.replayFlowElementsFromOffset(n.highestSeenOffset)):(this.currentLayoutPosition=new ta,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),n=this.currentLayoutPosition;let o=1e4;if(n.page>o)throw new Error(`Too many pages generated (over ${o} pages)`);let i=n.startSideOfFlow("body");n.isBlankPage=_n(i)&&this.matchPageSide(i),e.isBlankPage=n.isBlankPage,n.page++,e.pageType==null&&(e.pageType=(g=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?g:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=n.clone();let a=s?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.styler.cascade.applyVarFilter([a],this.styler,null),this.styler.cascade.applyCalcFilter(a,this.styler.context),!s){let m=new J(this.style.pageScope,"left-page");e.side=m.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let l=this.selectPageMaster(a);if(!l)return T(null);let c=0;if(!s){e.setAutoPageWidth(l.pageBox.specified.width.value===Fn),e.setAutoPageHeight(l.pageBox.specified.height.value===Bn),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(a,this);let m=Cp(ji(a),this);this.setPageSizeAndBleed(m,e),yg(a,m,e,this),c=m.bleedOffset+m.bleed}let u=!s&&l.getProp(this,"writing-mode")||b.horizontal_tb;this.pageVertical=u!=b.horizontal_tb;let d=l.getProp(this,"direction")||b.ltr,h=new xn(this.rootPageFloatLayoutContext,le.PAGE,null,null,null,u,d),f=A("layoutNextPage");return f.loopWithFrame(m=>{this.layoutContainer(e,l,e.bleedBox,c,c,[],h).then(()=>{h.isInvalidated()||h.finish(),h.isInvalidated()?(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),h.validate(),m.continueLoop()):m.breakLoop()})}).then(()=>{l.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),n=this.currentLayoutPosition,Object.keys(n.flowPositions).forEach(x=>{let E=n.flowPositions[x],C=E.breakAfter;C&&(C==="page"||!this.matchPageSide(C))&&(E.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,n.highestSeenOffset=this.styler.getReachedOffset();let m=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(m,this.clientLayout),this.noMorePrimaryFlows(n)&&(n=null),f.finish(n)}),f.result()}setPageSizeAndBleed(e,n){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,n.container.style.width=`${this.pageSheetWidth}px`,n.container.style.height=`${this.pageSheetHeight}px`,n.bleedBox.style.left=`${e.bleedOffset}px`,n.bleedBox.style.right=`${e.bleedOffset}px`,n.bleedBox.style.top=`${e.bleedOffset}px`,n.bleedBox.style.bottom=`${e.bleedOffset}px`,n.bleedBox.style.padding=`${e.bleed}px`}},wp=class r extends wn{constructor(e,n,s,o){super(e.rootScope,e,n,s,o,e.validatorSet,!s);this.masterHandler=e;p(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(e,n,s){let o=new Vo(this.masterHandler.pageScope,e,n,s,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new Ya(o.scope,this.masterHandler,o,this.validatorSet))}startWhenRule(e){let n=e.expr;this.condition!=null&&(n=Qe(this.scope,this.condition,n)),this.masterHandler.pushHandler(new r(this.masterHandler,n,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new Ca(this.scope,this.owner))}startFontFaceRule(){let e={};this.masterHandler.fontFaces.push({properties:e,condition:this.condition}),this.masterHandler.pushHandler(new Fs(this.scope,this.owner,null,e,this.masterHandler.validatorSet,"font-face"))}startFlowRule(e){let n=this.masterHandler.flowProps[e];n||(n={},this.masterHandler.flowProps[e]=n),this.masterHandler.pushHandler(new Fs(this.scope,this.owner,null,n,this.masterHandler.validatorSet))}startViewportRule(){let e={};this.masterHandler.viewportProps.push(e),this.masterHandler.pushHandler(new Fs(this.scope,this.owner,this.condition,e,this.masterHandler.validatorSet))}startFootnoteRule(e){let n=this.masterHandler.footnoteProps;if(e){let s=Po(n,"_pseudos");n=s[e],n||(n={},s[e]=n)}this.masterHandler.pushHandler(new Fs(this.scope,this.owner,null,n,this.masterHandler.validatorSet))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let e=new Za(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(e),e.startPageRule()}startRuleBody(){if(wn.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let e=`R${this.masterHandler.regionCount++}`;this.special("region-id",L(e)),this.endRule();let n=new r(this.masterHandler,this.condition,this,e);this.masterHandler.pushHandler(n),n.startRuleBody()}}},il=class extends _r{constructor(e){super();this.validatorSet=e;p(this,"rootScope");p(this,"pageScope");p(this,"rootBox");p(this,"cascadeParserHandler");p(this,"regionCount",0);p(this,"fontFaces",[]);p(this,"footnoteProps",{});p(this,"flowProps",{});p(this,"viewportProps",[]);p(this,"pageProps",{});this.rootScope=new ds(null),this.pageScope=new ds(this.rootScope),this.rootBox=new Ga(this.rootScope),this.cascadeParserHandler=new wp(this,null,null,null),this.slave=this.cascadeParserHandler}};function Ab(r,t){return t.parseOPSResource(r)}var rl=class extends bs{constructor(e){super(Ab,"document");this.fontDeobfuscator=e;p(this,"styleByKey",{});p(this,"styleFetcherByKey",{});p(this,"styleByDocURL",{});p(this,"triggersByDocURL",{});p(this,"validatorSet",null);p(this,"styleSheets",[]);p(this,"triggerSingleDocumentPreprocessing",!1)}init(e,n){this.setStyleSheets(e,n);let s=A("OPSDocStore.init");return this.validatorSet=Yd(),kb().then(()=>{this.triggerSingleDocumentPreprocessing=!0,s.finish(!0)}),s.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,n){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),n&&n.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let n=e.url;n&&(n=Q(Rn(n),hn)),this.styleSheets.push({url:n,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let n=e.url;n&&(n=Q(Rn(n),hn)),this.styleSheets.push({url:n,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let n=A("OPSDocStore.load"),s=e.url,o=s.endsWith("?viv-toc-box");return Np(e,this).then(i=>{var f;if(!i){n.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let g=He("PREPROCESS_SINGLE_DOCUMENT");for(let m=0;m<g.length;m++)try{g[m](i.document)}catch(x){F.warn("Error during single document preprocessing:",x)}}let a=[],l=i.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let g=0;g<l.length;g++){let m=l[g],x=m.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),E=m.getAttributeNS("http://www.w3.org/2001/xml-events","event"),C=m.getAttribute("action"),y=m.getAttribute("ref");x&&E&&C&&y&&a.push({observer:x,event:E,action:C,ref:y})}this.triggersByDocURL[s]=a;let c=[];if(c.push({url:Q("user-agent-page.css",Kt),text:Sc,flavor:"UA",classes:null,media:null}),o)c.push({url:Q("user-agent-toc.css",Kt),text:vc,flavor:"UA",classes:null,media:null});else{let g=i.document.querySelectorAll("style, link, meta");for(let m of g){let x=m.namespaceURI,E=m.localName;if(x=="http://www.w3.org/1999/xhtml")if(E=="style"){let C=m.getAttribute("class"),y=m.getAttribute("media"),N=m.getAttribute("title");c.push({url:s,text:m.textContent,flavor:"Author",classes:N?C:null,media:y})}else if(E=="link"){let C=m.getAttribute("href"),y=(f=m.getAttribute("rel"))==null?void 0:f.split(/\s+/),N=m.getAttribute("class"),S=m.getAttribute("media");if(C&&(y!=null&&y.includes("stylesheet"))&&(!y.includes("alternate")||N)){let v=Q(C,s),k=m.getAttribute("title");c.push({url:v,text:null,classes:k?N:null,media:S,flavor:"Author"})}}else E=="meta"&&m.getAttribute("name")=="viewport"&&c.push({url:s,text:this.processViewportMeta(m),flavor:"Author",classes:null,media:null})}for(let m=0;m<this.styleSheets.length;m++)c.push(this.styleSheets[m])}let u="";for(let g=0;g<c.length;g++)u+=c[g].url,u+="^",c[g].text&&(u+=c[g].text),u+="^";let d=this.styleByKey[u];if(d){this.styleByDocURL[s]=d,n.finish(i);return}let h=this.styleFetcherByKey[u];h||(h=new nn(()=>{let g=A("fetchStylesheet"),m=0,x=new il(this.validatorSet);return g.loop(()=>{if(m<c.length){let E=c[m++];return x.startStylesheet(E.flavor),E.text!==null?Wr(E.text,x,E.url,E.classes,E.media).thenReturn(!0):kc(E.url,x,E.classes,E.media)}return T(!1)}).then(()=>{let E=x.cascadeParserHandler.finish();d=new Tp(this,x.rootScope,x.pageScope,E,x.rootBox,x.fontFaces,x.footnoteProps,x.flowProps,x.viewportProps,x.pageProps),this.styleByKey[u]=d,delete this.styleFetcherByKey[u],g.finish(d)}),g.result()},`FetchStylesheet ${s}`),this.styleFetcherByKey[u]=h,h.start()),h.get().then(g=>{this.styleByDocURL[s]=g,n.finish(i)})}),n.result()}processViewportMeta(e){return""}};var qi="\u25B8",Lg="\u25BE",Lb="\u25B9";function ll(r){let t=Array.from(r.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(r.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let e="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of r.querySelectorAll(e)){if(t.find(o=>o.contains(n)))continue;let s=n;/^h[1-6]$/.test(s.localName)&&(s.previousElementSibling?s=s.nextElementSibling:s=s.parentElement),s&&s.querySelector("li a[href]")&&t.push(s)}return t}function Rg(r){let t=ll(r),e=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))e.push(s);return e}var al=class{constructor(t,e,n,s,o,i,a,l,c,u){this.store=t;this.url=e;this.lang=n;this.clientLayout=s;this.fontMapper=o;this.rendererFactory=a;this.fallbackMap=l;this.documentURLTransformer=c;this.counterStore=u;p(this,"pref");p(this,"page",null);p(this,"instance",null);this.pref=wr(i),this.pref.spreadView=!1}setAutoHeight(t,e){if(e--!=0){for(let n=t.firstChild;n;n=n.nextSibling)if(n.nodeType==1){let s=n;Ot(s,"height","auto")!="auto"&&(w(s,"height","auto"),this.setAutoHeight(s,e)),Ot(s,"position","static")=="absolute"&&(w(s,"position","relative"),this.setAutoHeight(s,e))}}}makeCustomRenderer(t){let e=this.rendererFactory.makeCustomRenderer(t);return(n,s,o)=>{let i=o.behavior;if(i)switch(i.toString()){case"toc-node-anchor":o.color=b.inherit,o["text-decoration"]=b.none;break;case"toc-node":o.display=b.block,o.margin=ne,o.padding=ne,o["padding-inline-start"]=new P(1.25,"em");break;case"toc-node-first-child":o.display=b.inline_block,o.margin=new P(.2,"em"),o["vertical-align"]=b.top,o.color=b.inherit,o["text-decoration"]=b.none;break;case"toc-container":o.padding=ne;break}if(!i||i.toString()!="toc-node"&&i.toString()!="toc-container")return e(n,s,o);let a=n.firstChild;a&&a.nodeType!==1&&de(a)&&n.replaceChild(n.ownerDocument.createComment(a.textContent),a);let l=s.getAttribute("data-adapt-class");if(l=="toc-node"){let u=s.firstChild;u.textContent!=qi&&(u.textContent=qi,w(u,"cursor","pointer"),u.addEventListener("click",Rb,!1),u.setAttribute("role","button"),u.setAttribute("aria-expanded","false"),s.setAttribute("aria-expanded","false"),s.style.height!=="0px"&&(u.tabIndex=0))}let c=s.ownerDocument.createElement("div");if(c.setAttribute("data-adapt-process-children","true"),i.toString()=="toc-node"){let u=s.ownerDocument.createElement("div");if(u.textContent=Lb,w(u,"margin","0.2em 0 0 -1em"),w(u,"margin-inline-start","-1em"),w(u,"margin-inline-end","0"),w(u,"display","inline-block"),w(u,"width","1em"),w(u,"text-align","center"),w(u,"vertical-align","top"),w(u,"cursor","default"),w(u,"font-family","Menlo,sans-serif"),c.appendChild(u),w(c,"overflow","hidden"),c.setAttribute("data-adapt-class","toc-node"),c.setAttribute("role","treeitem"),l=="toc-node"||l=="toc-container"){w(c,"height","0px");let d=n.firstElementChild;d&&d.localName==="a"&&(d.tabIndex=-1)}else s.setAttribute("role","tree")}else l=="toc-node"&&(c.setAttribute("data-adapt-class","toc-container"),c.setAttribute("role","group"),c.setAttribute("aria-hidden","true"));return T(c)}}showTOC(t,e,n,s,o){if(this.page)return T(this.page);let i=A("showTOC"),a=new mo(t,t);this.page=a;let l=At(this.url)+"?viv-toc-box";return this.store.load(l).then(c=>{for(let g of ll(c.document))g.setAttribute("data-vivliostyle-role","doc-toc");let u=this.store.getStyleForDoc(c),d=u.sizeViewport(n,1e5,o);e=new An(e.window,d.fontSize,0,e.root,d.width,d.height);let h=this.makeCustomRenderer(c),f=new ss(u,c,this.lang,e,this.clientLayout,this.fontMapper,h,this.fallbackMap,0,this.documentURLTransformer,this.counterStore);this.instance=f,f.pref=this.pref,f.init().then(()=>{f.layoutNextPage(a,null).then(()=>{this.setAutoHeight(t,2),i.finish(a)})})}),i.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function t(s){if(!s)return[];let o=s.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(o).map(e)}function e(s){let o=new URL(s.href),[,i]=o.hash.match(/^#?(.*)$/),a=s.innerText,l=s.parentElement.querySelector("[role=group]"),c=t(l);return{id:i,title:a,children:c}}let n=this.page.container.querySelector("[role=tree]");return t(n)}};function Rb(r){let t=r.target,e=t.textContent==qi;t.textContent=e?Lg:qi;let n=t.parentNode;t.setAttribute("aria-expanded",e?"true":"false"),n.setAttribute("aria-expanded",e?"true":"false");let s=n.firstChild;for(;s;){if(s.nodeType===1){let o=s,i=o.getAttribute("data-adapt-class");if(i==="toc-container"){if(o.setAttribute("aria-hidden",e?"false":"true"),o.firstChild){s=o.firstChild;continue}}else if(i==="toc-node"&&(o.style.height=e?"auto":"0px",o.children.length>=2&&(o.children[1].tabIndex=e?0:-1),o.children.length>=3&&(o.children[0].tabIndex=e?0:-1,!e))){let a=o.children[0];if(a.textContent==Lg){a.textContent=qi,a.setAttribute("aria-expanded","false"),o.setAttribute("aria-expanded","false"),s=o.children[2];continue}}}for(;!s.nextSibling&&s.parentNode!==n;)s=s.parentNode;s=s.nextSibling}r.stopPropagation()}var Qi=class extends rl{constructor(){super(null);p(this,"plainXMLStore");p(this,"jsonStore");p(this,"opfByURL",{});p(this,"primaryOPFByEPubURL",{});p(this,"deobfuscators",{});p(this,"documents",{});this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=Pg(),this.jsonStore=Nh()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,n,s){return this.plainXMLStore.load(e,n,s)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,n,s){return this.jsonStore.load(e,n,s)}loadPubDoc(e){let n=A("loadPubDoc");return xs(e,null,"HEAD").then(s=>{if(s.status>=400)this.loadEPUBDoc(e).then(o=>{if(o){n.finish(o);return}F.error(`Failed to fetch a source document from ${e} (${s.status}${s.statusText?" "+s.statusText:""})`),n.finish(null)});else if(!s.status&&!s.responseXML&&!s.responseText&&!s.responseBlob&&!s.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),s.contentType=="application/oebps-package+xml"||/\.opf(?:[#?]|$)/.test(e)){let[,o,i]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(o,i).thenFinish(n)}else s.contentType=="application/ld+json"||s.contentType=="application/webpub+json"||s.contentType=="application/audiobook+json"||s.contentType=="application/json"||/\.json(?:ld)?(?:[#?]|$)/.test(e)?this.loadAsJSON(e,!0).then(o=>{if(!o){this.reportLoadError(e),n.finish(null);return}let i=new Ws(this,e);i.initWithWebPubManifest(o,void 0,e).then(()=>{n.finish(i)})}):this.loadWebPub(e).then(o=>{if(o){n.finish(o);return}this.loadEPUBDoc(e).then(i=>{if(i){n.finish(i);return}F.error(`Failed to load ${e}.`),n.finish(null)})})}),n.result()}loadEPUBDoc(e){let n=A("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let s=e+"META-INF/container.xml";return this.loadAsPlainXML(s).then(o=>{if(o){let i=o.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let a of i)if(a){this.loadOPF(e,a).thenFinish(n);return}}n.finish(null)}),n.result()}loadOPF(e,n){let s=e+n,o=this.opfByURL[s];if(o)return T(o);let i=A("loadOPF");return this.loadAsPlainXML(s,!0,`Failed to fetch EPUB OPF ${s}`).then(a=>{a?(o=new Ws(this,e),this.opfByURL[s]=o,this.primaryOPFByEPubURL[e]=o,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(l=>{o.initWithXMLDoc(a,l).then(()=>{i.finish(o)})}):o.initWithXMLDoc(a,null).then(()=>{i.finish(o)})):this.reportLoadError(s)}),i.result()}loadWebPub(e){let n=A("loadWebPub");return this.load(e).then(s=>{if(!s)this.reportLoadError(e);else if(s.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))n.finish(null);else{let o=s.document,i=new Ws(this,e),a=o.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(a){let l=a.getAttribute("href");if(/^#/.test(l)){let c=js(o.getElementById(l.substr(1)).textContent);i.initWithWebPubManifest(c,o).then(()=>{n.finish(i)})}else{let c=Q(a.getAttribute("href"),e);this.loadAsJSON(c,!0,`Failed to fetch Publication Manifest ${c}`).then(u=>{i.initWithWebPubManifest(u,o,c).then(()=>{n.finish(i)})})}}else i.initWithWebPubManifest({},o).then(()=>{i.toc&&i.toc.src===s.url&&ll(o).length===0&&(i.toc=null),n.finish(i)})}}),n.result()}addDocument(e,n){let s=A("EPUBDocStore.load"),o=At(e);return(this.documents[o]=this.parseOPSResource({status:200,statusText:"",url:o,contentType:n.contentType,responseText:null,responseXML:n,responseBlob:null})).thenFinish(s),s.result()}reportLoadError(e){let n=o=>o.replace(/([^:/?#]|^)[/?#].*/,"$1"),s=()=>{let o=n(e);return!(o===n(hn)||Object.keys(this.resources).find(a=>this.resources[a]&&n(a)===o)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?F.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&hn.startsWith("https:")?F.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):s()?F.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):F.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let n=At(e),s=this.documents[n];if(s)return s.isPending()?s:T(s.get());{let o=A("EPUBDocStore.load");return s=super.load(n,!0,`Failed to fetch a source document from ${n}`),s.then(i=>{i?o.finish(i):this.reportLoadError(n)}),o.result()}}processViewportMeta(e){let n=e.getAttribute("content");if(!n)return"";let s={},o;for(;(o=n.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)n=n.substr(o[0].length),s[o[1]]=o[2];let i=s.width-0,a=s.height-0;if(i&&a){let l=!!Object.values(this.primaryOPFByEPubURL).find(c=>c.prePaginated);return`@-epubx-viewport{width:${i}px;height:${a}px;}`+(l?`@page{size:${i}px ${a}px;margin:0;}`:"@page{margin:0;}")}return""}},ul=class{constructor(){p(this,"id",null);p(this,"src","");p(this,"mediaType",null);p(this,"title",null);p(this,"itemRefElement",null);p(this,"spineIndex",-1);p(this,"compressedSize",0);p(this,"compressed",null);p(this,"epage",0);p(this,"epageCount",0);p(this,"startPage",null);p(this,"skipPagesBefore",null);p(this,"itemProperties");this.itemProperties=Wp}initWithElement(t,e){this.id=t.getAttribute("id"),this.src=Q(t.getAttribute("href"),e),this.mediaType=t.getAttribute("media-type");let n=t.getAttribute("properties");n&&(this.itemProperties=jp(n.split(/\s+/)))}initWithParam(t){this.spineIndex=t.index,this.id=`item${t.index+1}`,this.src=t.url,this.startPage=t.startPage,this.skipPagesBefore=t.skipPagesBefore}};function Vb(r){return r.id}function Fb(r){return t=>{let e=A("deobfuscator");return Bb("SHA-1",r).then(n=>{let s=t.slice(0,1040),o=t.slice(1040,t.size);Eh(s).then(i=>{let a=new DataView(i);for(let l=0;l<a.byteLength;l++){let c=a.getUint8(l);c^=n[l%20],a.setUint8(l,c)}e.finish(wc([a,o]))})}),e.result()}}function Bb(r,t){let e=A("makeDigest"),n=e.suspend();return window.crypto.subtle.digest(r,new TextEncoder().encode(t)).then(s=>{n.schedule(new Uint8Array(s))}),e.result()}var os={dcterms:"http://purl.org/dc/terms/",marc:"http://id.loc.gov/vocabulary/",media:"http://www.idpf.org/epub/vocab/overlays/#",rendition:"http://www.idpf.org/vocab/rendition/#",onix:"http://www.editeur.org/ONIX/book/codelists/current.html#",xsd:"http://www.w3.org/2001/XMLSchema#",opf:"http://www.idpf.org/2007/opf"},Zi="http://idpf.org/epub/vocab/package/meta/#",Ne={language:`${os.dcterms}language`,title:`${os.dcterms}title`,creator:`${os.dcterms}creator`,layout:`${os.rendition}layout`,titleType:`${Zi}title-type`,displaySeq:`${Zi}display-seq`,alternateScript:`${Zi}alternate-script`,role:`${Zi}role`};function Ob(r,t){let e={};return(n,s)=>{var d,h,f,g,m,x;let o,i,a=n.r||e,l=s.r||e;if(r==Ne.title&&(o=((d=a[Ne.titleType])==null?void 0:d[0].v)=="main",i=((h=l[Ne.titleType])==null?void 0:h[0].v)=="main",o!=i))return o?-1:1;let c=parseInt((f=a[Ne.displaySeq])==null?void 0:f[0].v,10);isNaN(c)&&(c=Number.MAX_VALUE);let u=parseInt((g=l[Ne.displaySeq])==null?void 0:g[0].v,10);return isNaN(u)&&(u=Number.MAX_VALUE),c!=u?c-u:r!=Ne.language&&t&&(o=((m=a[Ne.language]||a[Ne.alternateScript])==null?void 0:m[0].v)==t,i=((x=l[Ne.language]||l[Ne.alternateScript])==null?void 0:x[0].v)==t,o!=i)?o?-1:1:n.o-s.o}}function Db(r,t){let e;if(!t)e=os;else{e={};for(let h in os)e[h]=os[h];let d;for(;(d=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(d[0].length),e[d[1]]=d[2]}let n=d=>{if(d){let h=d.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(h){let f=h[2]?e[h[2]]:Zi;if(f)return f+h[3]}}return null},s=1,o=r.childElements().forEachNonNull(d=>{if(d.localName=="meta"){let h=n(d.getAttribute("property"));if(h)return{name:h,value:d.textContent,id:d.getAttribute("id"),order:s++,refines:d.getAttribute("refines"),lang:null,scheme:n(d.getAttribute("scheme")),role:null}}else if(d.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:os.dcterms+d.localName,order:s++,lang:d.getAttribute("xml:lang"),value:d.textContent,id:d.getAttribute("id"),refines:null,scheme:null,role:d.getAttribute("role")||d.getAttribute("opf:role")};return null}),i=cr(o,d=>d.refines),a=d=>Yp(d,(h,f)=>h.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let x=i[`#${g.id}`]||[];if(x.length||g.lang||g.role){g.lang&&x.push({name:Ne.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&x.push({name:Ne.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let E=cr(x,C=>C.name);m.r=a(E)}return m})),l=a(cr(o,d=>d.refines?null:d.name)),c=null;l[Ne.language]&&(c=l[Ne.language][0].v);let u=d=>{for(let h in d){let f=d[h];f.sort(Ob(h,c));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(l),l}function Mb(){let r=window.MathJax;return r?r.Hub:null}var Ig={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Pp="viv-id-",Ws=class{constructor(t,e){this.store=t;this.pubURL=e;p(this,"opfXML",null);p(this,"encXML",null);p(this,"items",null);p(this,"spine",null);p(this,"itemMap",null);p(this,"itemMapByPath",null);p(this,"uid",null);p(this,"bindings",{});p(this,"lang",null);p(this,"epageCount",0);p(this,"prePaginated",!1);p(this,"epageIsRenderedPage",!0);p(this,"epageCountCallback",null);p(this,"metadata",{});p(this,"toc",null);p(this,"cover",null);p(this,"fallbackMap",{});p(this,"pageProgression",null);p(this,"documentURLTransformer");this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let t=this;class e{transformFragment(s,o){let i=o+(s?`#${s}`:"");return Pp+Fl(i,":")}transformURL(s,o){let i=s.match(/^([^#]*)#?(.*)$/);if(i){let a=i[1]||o.replace(/\?viv-toc-box$/,""),l=decodeURIComponent(i[2]);if(a&&t.spine.some(c=>c.src===a))return`#${this.transformFragment(l,a)}`}return s}restoreURL(s){s.charAt(0)==="#"&&(s=s.substring(1)),s.indexOf(Pp)===0&&(s=s.substring(Pp.length));let i=Xp(s,":").match(/^([^#]*)#?(.*)$/);return i?[i[1],i[2]]:[]}}return new e}getMetadata(){return this.metadata}getPathFromURL(t){if(t.startsWith("data:"))return t===this.pubURL?"":t;if(this.pubURL){let e=Q("",this.pubURL);return t===e||t+"/"===e?"":(e.charAt(e.length-1)!="/"&&(e+="/"),t.substr(0,e.length)==e?decodeURIComponent(t.substr(e.length)):null)}else return t}initWithXMLDoc(t,e){this.opfXML=t,this.encXML=e;let n=t.doc().child("package"),s=n.attribute("unique-identifier")[0];if(s){let c=t.getElement(`${t.url}#${s}`);c&&(this.uid=c.textContent.replace(/[ \n\r\t]/g,""))}let o={};this.items=n.child("manifest").child("item").asArray().map(c=>{let u=new ul,d=c;u.initWithElement(d,t.url);let h=d.getAttribute("fallback");return h&&!Ig[u.mediaType]&&(o[u.src]=h),!this.toc&&u.itemProperties.nav&&(this.toc=u),!this.cover&&u.itemProperties["cover-image"]&&(this.cover=u),u}),this.itemMap=Bl(this.items,Vb),this.itemMapByPath=Bl(this.items,c=>this.getPathFromURL(c.src));for(let c in o){let u=c;for(;;){let d=this.itemMap[o[u]];if(!d)break;if(Ig[d.mediaType]){this.fallbackMap[c]=d.src;break}u=d.src}}this.spine=n.child("spine").child("itemref").asArray().map((c,u)=>{let d=c,h=d.getAttribute("idref"),f=this.itemMap[h];return f&&(f.itemRefElement=d,f.spineIndex=u),f});let i=n.child("spine").attribute("page-progression-direction")[0];i&&(this.pageProgression=Sl(i));let a=e?e.doc().child("encryption").child("EncryptedData").predicate(vp.withChild("EncryptionMethod",vp.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],l=n.child("bindings").child("mediaType").asArray();for(let c=0;c<l.length;c++){let u=l[c].getAttribute("handler"),d=l[c].getAttribute("media-type");d&&u&&this.itemMap[u]&&(this.bindings[d]=this.itemMap[u].src)}if(this.metadata=Db(n.child("metadata"),n.attribute("prefix")[0]),this.metadata[Ne.language]&&(this.lang=this.metadata[Ne.language][0].v),this.metadata[Ne.layout]&&(this.prePaginated=this.metadata[Ne.layout][0].v==="pre-paginated"),a.length>0&&this.uid){let c=Fb(this.uid);for(let u=0;u<a.length;u++)this.store.deobfuscators[this.pubURL+a[u]]=c}return this.prePaginated&&this.assignAutoPages(),T(!0)}assignAutoPages(){let t=0;for(let e of this.spine){let n=this.prePaginated?1:Math.ceil(e.compressedSize/1024);e.epage=t,e.epageCount=n,t+=n}this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(t){this.epageIsRenderedPage=t||this.prePaginated}countEPages(t){if(this.epageCountCallback=t,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),T(!0);let e=0,n=0,s=A("countEPages");return s.loopWithFrame(o=>{if(n===this.spine.length){o.breakLoop();return}let i=this.spine[n++];i.epage=e,this.store.load(i.src).then(a=>{let l=1800,c=a.lang||this.lang;c&&c.match(/^(ja|ko|zh)/)&&(l/=3),i.epageCount=Math.ceil(a.getTotalOffset()/l),e+=i.epageCount,this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount),o.continueLoop()})}).thenFinish(s),s.result()}initWithChapters(t,e){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let n=this.opfXML=new Ki(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return t.forEach(s=>{let o=new ul;o.initWithParam(s),o.id;let i=n.document.createElement("itemref");i.setAttribute("idref",o.id),n.root.appendChild(i),o.itemRefElement=i,this.itemMap[o.id]=o;let a=this.getPathFromURL(s.url);a==null&&(a=s.url),this.itemMapByPath[a]=o,this.items.push(o)}),e?this.store.addDocument(t[0].url,e):T(null)}initWithWebPubManifest(t,e,n){var h,f,g,m;t.readingProgression&&(this.pageProgression=t.readingProgression),this.metadata===void 0&&(this.metadata={});let s=t.name||((h=t.metadata)==null?void 0:h.title)||(e==null?void 0:e.title);s&&(this.metadata[Ne.title]=(Array.isArray(s)?s:[s]).map(x=>{var E;return{v:(E=x.value)!=null?E:x}}));let o=t.author||t.creator||((f=t.metadata)==null?void 0:f.author)||Array.from((g=e==null?void 0:e.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?g:[]).map(x=>x.content);o&&o.length!==0&&(this.metadata[Ne.creator]=(Array.isArray(o)?o:[o]).map(x=>{var E;return{v:(E=x.name)!=null?E:x}}));let i=t.inLanguage||((m=t.metadata)==null?void 0:m.language)||(e==null?void 0:e.documentElement.lang)||(e==null?void 0:e.documentElement.getAttribute("xml:lang"));i&&(this.metadata[Ne.language]=(Array.isArray(i)?i:[i]).map(x=>({v:x})));let a=this.getPathFromURL(this.pubURL);if(!t.readingOrder&&e&&a!==null){t.readingOrder=[encodeURI(a)];for(let x of Rg(e)){let E=x.getAttribute("href");if(/^(https?:)?\/\//.test(E)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(E))continue;let C=At(Q(E,this.pubURL)),y=this.getPathFromURL(C),N=y!==null?encodeURI(y):C;t.readingOrder.indexOf(N)==-1&&t.readingOrder.push(N)}}let l=[],c=0,u=-1;[t.readingOrder,t.resources].forEach(x=>{x instanceof Array&&x.forEach(E=>{let C=x===t.readingOrder,y=typeof E=="string"?E:E.url||E.href,N=typeof E=="string"?"":E.encodingFormat||E.href&&E.type||"";if(C||N==="text/html"||N==="application/xhtml+xml"||!N&&E.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(y)){let S=n?n.replace(/\/[^/]+$/,"/"):this.pubURL,v={url:Q(Rn(y),S),index:c++,startPage:null,skipPagesBefore:null};E.rel==="contents"&&u===-1&&(u=v.index),l.push(v)}})});let d=A("initWithWebPubManifest");return this.initWithChapters(l).then(()=>{var E,C;u!==-1&&(this.toc=this.items[u]),this.toc||(this.toc=n?(E=this.items)==null?void 0:E[0]:this.itemMapByPath[a]);let x=(C=t.readingOrder)==null?void 0:C.length;x&&x<this.items.length&&this.items.splice(x),d.finish(!0)}),d.result()}getCFI(t,e){let n=this.spine[t],s=A("getCFI");return this.store.load(n.src).then(o=>{let i=o.getNodeByOffset(e),a=null;if(i){let l=o.getNodeOffset(i,0,!1),c=e-l,u=new Ho;u.prependPathFromNode(i,c,!1,null),n.itemRefElement&&u.prependPathFromNode(n.itemRefElement,0,!1,null),a=u.toString()}s.finish(a)}),s.result()}resolveFragment(t){return Cn("resolveFragment",e=>{if(!t){e.finish(null);return}let n=new Ho;n.fromString(t);let s;if(this.opfXML){let o=n.navigate(this.opfXML.document);if(o.node.nodeType!=1||o.after||!o.ref){e.finish(null);return}let i=o.node,a=i.getAttribute("idref");if(i.localName!="itemref"||!a||!this.itemMap[a]){e.finish(null);return}s=this.itemMap[a],n=o.ref}else s=this.spine[0];this.store.load(s.src).then(o=>{let i=n.navigate(o.document),a=o.getNodeOffset(i.node,i.offset,i.after);e.finish({spineIndex:s.spineIndex,offsetInItem:a,pageIndex:-1})})},(e,n)=>{F.warn(n,"Cannot resolve fragment:",t),e.finish(null)})}resolveEPage(t){return Cn("resolveEPage",e=>{if(t<=0){e.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let o=this.spine.findIndex(l=>l.epage==0&&l.epageCount==0||l.epage<=t&&l.epage+l.epageCount>t);o==-1&&(o=this.spine.length-1);let i=this.spine[o];(!i||i.epageCount==0)&&(i=this.spine[--o]);let a=Math.floor(t-i.epage);e.finish({spineIndex:o,offsetInItem:-1,pageIndex:a});return}let n=Ct(this.spine.length,o=>{let i=this.spine[o];return i.epage+i.epageCount>t});n==this.spine.length&&n--;let s=this.spine[n];this.store.load(s.src).then(o=>{t-=s.epage,t>s.epageCount&&(t=s.epageCount);let i=0;if(t>0){let a=o.getTotalOffset();i=Math.round(a*t/s.epageCount),i==a&&i--}e.finish({spineIndex:n,offsetInItem:i,pageIndex:-1})})},(e,n)=>{F.warn(n,"Cannot resolve epage:",t),e.finish(null)})}getEPageFromPosition(t){let e=this.spine[t.spineIndex];if(this.epageIsRenderedPage){let s=e.epage+t.pageIndex;return T(s)}if(t.offsetInItem<=0)return T(e.epage);let n=A("getEPage");return this.store.load(e.src).then(s=>{let o=s.getTotalOffset(),i=Math.min(o,t.offsetInItem);n.finish(e.epage+i*e.epageCount/o)}),n.result()}},cl=(r,t)=>({page:r,position:{spineIndex:r.spineIndex,pageIndex:t,offsetInItem:r.offset}}),dl=class{constructor(t,e,n,s,o){this.opf=t;this.viewport=e;this.fontMapper=n;this.pageSheetSizeReporter=o;p(this,"spineItems",[]);p(this,"spineItemLoadingContinuations",[]);p(this,"pref");p(this,"clientLayout");p(this,"counterStore");p(this,"tocAutohide",!1);p(this,"tocVisible",!1);p(this,"tocView");this.pref=wr(s),this.clientLayout=new tl(e),this.counterStore=new Or(t.documentURLTransformer)}getPage(t){let e=this.spineItems[t.spineIndex];return e?e.pages[t.pageIndex]:null}getCurrentPageProgression(t){if(this.opf.pageProgression)return this.opf.pageProgression;{let e=this.spineItems[t?t.spineIndex:0];return e?e.instance.pageProgression:null}}finishPageContainer(t,e,n){e.container.style.display="none",e.container.style.visibility="visible",e.container.style.position="",e.container.style.top="",e.container.style.left="",e.container.setAttribute("data-vivliostyle-page-side",e.side);let s=t.pages[n];if(e.isFirstPage=t.item.spineIndex==0&&n==0,t.pages[n]=e,this.opf.epageIsRenderedPage){if(n==0&&t.item.spineIndex>0){let o=this.opf.spine[t.item.spineIndex-1];t.item.epage=o.epage+o.epageCount}t.item.epageCount=t.pages.length,this.opf.epageCount=this.opf.spine.reduce((o,i)=>o+i.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(s)t.instance.viewport.contentContainer.replaceChild(e.container,s.container),s.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:e});else{let o=null;if(n>0)o=t.pages[n-1].container.nextElementSibling;else for(let i=t.item.spineIndex+1;i<this.spineItems.length;i++){let a=this.spineItems[i];if(a&&a.pages[0]){o=a.pages[0].container;break}}t.instance.viewport.contentContainer.insertBefore(e.container,o)}this.pageSheetSizeReporter({width:t.instance.pageSheetWidth,height:t.instance.pageSheetHeight},t.instance.pageSheetSize,t.item.spineIndex,t.instance.pageNumberOffset+n)}renderSinglePage(t,e){let n=A("renderSinglePage"),s=t.pages[e?e.page:0],o=this.makePage(t,e);return s&&(o.pageType=s.pageType),t.instance.layoutNextPage(o,e).then(i=>{e=i;let a=e?e.page-1:t.layoutPositions.length-1;this.finishPageContainer(t,o,a),this.counterStore.finishPage(o.spineIndex,a);let l=null;if(e){let c=t.layoutPositions[e.page];t.layoutPositions[e.page]=e,c&&t.pages[e.page]&&(e.isSamePosition(c)||(l=this.renderSinglePage(t,e)))}l||(l=T(!0)),l.then(()=>{let c=this.counterStore.getUnresolvedRefsToPage(o),u=0;n.loopWithFrame(d=>{if(u++,u>c.length){d.breakLoop();return}let h=c[u-1];if(h.refs=h.refs.filter(f=>!f.isResolved()),h.refs.length===0){d.continueLoop();return}this.getPageViewItem(h.spineIndex).then(f=>{if(!f){d.continueLoop();return}let{currentPageType:g,previousPageType:m}=f.instance.styler.cascade,x=f.instance.scopes;f.instance.scopes={},this.counterStore.pushPageCounters(h.pageCounters),this.counterStore.pushReferencesToSolve(h.refs);let E=f.layoutPositions[h.pageIndex];this.renderSinglePage(f,E).then(C=>{f.instance.styler.cascade.currentPageType=g,f.instance.styler.cascade.previousPageType=m,f.instance.scopes=x,this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve();let y=C.pageAndPosition.position;y.spineIndex===o.spineIndex&&y.pageIndex===a&&(o=C.pageAndPosition.page),d.continueLoop()})})}).then(()=>{o.container.parentElement||(o=t.pages[a]),o.isLastPage=!e&&t.item.spineIndex===this.opf.spine.length-1,o.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),o.container.setAttribute("data-vivliostyle-page-index",a),o.container.setAttribute("data-vivliostyle-spine-index",o.spineIndex),n.finish({pageAndPosition:cl(o,a),nextLayoutPosition:e})})})}),n.result()}normalizeSeekPosition(t,e){let n=t.pageIndex,s=-1;if(n<0){s=t.offsetInItem;let o=Ct(e.layoutPositions.length,i=>e.instance.getPosition(e.layoutPositions[i],!0)>s);o===e.layoutPositions.length?e.complete?n=e.layoutPositions.length-1:n=Number.POSITIVE_INFINITY:n=o-1}else n===Number.POSITIVE_INFINITY&&t.offsetInItem!==-1&&(s=t.offsetInItem);return{spineIndex:t.spineIndex,pageIndex:n,offsetInItem:s}}findPage(t,e){let n=A("findPage");return this.getPageViewItem(t.spineIndex).then(s=>{if(!s){n.finish(null);return}let o=null,i;n.loopWithFrame(a=>{let l=this.normalizeSeekPosition(t,s);i=l.pageIndex,o=s.pages[i],o?a.breakLoop():s.complete?(i=s.layoutPositions.length-1,o=s.pages[i],a.breakLoop()):e?this.renderPage(l).then(c=>{c&&(o=c.page,i=c.position.pageIndex),a.breakLoop()}):n.sleep(100).then(()=>{a.continueLoop()})}).then(()=>{n.finish(cl(o,i))})}),n.result()}renderPage(t){let e=A("renderPage");return this.getPageViewItem(t.spineIndex).then(n=>{if(!n){e.finish(null);return}let s=this.normalizeSeekPosition(t,n),o=s.pageIndex,i=s.offsetInItem,a=n.pages[o];if(a){e.finish(cl(a,o));return}e.loopWithFrame(l=>{if(o<n.layoutPositions.length){l.breakLoop();return}if(n.complete){o=n.layoutPositions.length-1,l.breakLoop();return}let c=n.layoutPositions[n.layoutPositions.length-1];this.renderSinglePage(n,c).then(u=>{let d=u.pageAndPosition.page;if(c=u.nextLayoutPosition,c){if(i>=0&&n.instance.getPosition(c)>i){a=d,o=n.layoutPositions.length-2,l.breakLoop();return}l.continueLoop()}else a=d,o=u.pageAndPosition.position.pageIndex,n.complete=!0,l.breakLoop()})}).then(()=>{a=a||n.pages[o];let l=n.layoutPositions[o];if(a){e.finish(cl(a,o));return}this.renderSinglePage(n,l).then(c=>{c.nextLayoutPosition||(n.complete=!0),e.finish(c.pageAndPosition)})})}),e.result()}renderAllPages(){let t=A("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(e=>{t.loopWithFrame(n=>{this.spineItems.some(s=>s==null?void 0:s.pages.some(o=>o==null?void 0:o.fetchers.some(i=>!i.arrived)))?t.sleep(100).then(()=>{n.continueLoop()}):n.breakLoop()}).then(()=>{t.finish(e)})}),t.result()}renderPagesUpto(t,e){let n=A("renderPagesUpto");t||(t={spineIndex:0,pageIndex:0,offsetInItem:0});let s=t.spineIndex,o=t.pageIndex,i=0;e&&(i=s);let a;return n.loopWithFrame(l=>{let c={spineIndex:i,pageIndex:i===s?o:Number.POSITIVE_INFINITY,offsetInItem:i===s?t.offsetInItem:-1};this.renderPage(c).then(u=>{a=u,++i>s?l.breakLoop():l.continueLoop()})}).then(()=>{n.finish(a)}),n.result()}firstPage(t,e){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},e)}lastPage(t,e){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},e)}nextPage(t,e){let n=t.spineIndex,s=t.pageIndex,o=A("nextPage");return this.getPageViewItem(n).then(i=>{if(!i){o.finish(null);return}if(i.complete&&s==i.layoutPositions.length-1){if(n>=this.opf.spine.length-1){o.finish(null);return}n++,s=0;let a=this.spineItems[n],l=a&&a.pages[0],c=i.pages[i.pages.length-1];l&&c&&l.side==c.side&&(a.pages.forEach(u=>{u.container&&u.container.remove()}),this.spineItems[n]=null,this.spineItemLoadingContinuations[n]=null)}else s++;this.findPage({spineIndex:n,pageIndex:s,offsetInItem:-1},e).thenFinish(o)}),o.result()}previousPage(t,e){let n=t.spineIndex,s=t.pageIndex;if(s==0){if(n==0)return T(null);n--,s=Number.POSITIVE_INFINITY}else s--;return this.findPage({spineIndex:n,pageIndex:s,offsetInItem:-1},e)}isRectoPage(t,e){let n=t.side==="left",s=this.getCurrentPageProgression(e)==="ltr";return!n&&s||n&&!s}getSpread(t,e){let n=this.getPage(t);if(!n)return T({left:null,right:null});let s=A("getSpread"),o=n.side==="left",i;return this.isRectoPage(n,t)?i=this.previousPage(t,e):i=this.nextPage(t,e),i.then(a=>{let l=this.getPage(t),c=a&&a.page;c&&c.side===l.side&&(c=null),o?s.finish({left:l,right:c}):s.finish({left:c,right:l})}),s.result()}nextSpread(t,e){let n=this.getPage(t);if(!n)return T(null);let s=this.isRectoPage(n,t),o=this.nextPage(t,e);return s?o:o.thenAsync(i=>{if(i){if(i.page.side===n.side)return o;let a=this.nextPage(i.position,e);return a.thenAsync(l=>l?a:o)}else return T(null)})}previousSpread(t,e){let n=this.getPage(t);if(!n)return T(null);let s=this.isRectoPage(n,t),o=this.previousPage(t,e),i=n.container.previousElementSibling;return s?o.thenAsync(a=>a?a.page.side===n.side||a.page.container!==i?o:this.previousPage(a.position,e):T(null)):o}navigateToEPage(t,e,n){let s=A("navigateToEPage");return this.opf.resolveEPage(t).then(o=>{o?this.findPage(o,n).thenFinish(s):s.finish(null)}),s.result()}navigateToFragment(t,e,n){let s=A("navigateToCFI");return this.opf.resolveFragment(t).then(o=>{o?this.findPage(o,n).thenFinish(s):s.finish(null)}),s.result()}navigateTo(t,e,n){F.debug("Navigate to",t);let s=this.opf.getPathFromURL(At(t));if(!s){if(this.opf.opfXML&&t.match(/^#epubcfi\(/))s=this.opf.getPathFromURL(this.opf.opfXML.url);else if(t.charAt(0)==="#"){let a=this.opf.documentURLTransformer.restoreURL(t);this.opf.opfXML?(s=this.opf.getPathFromURL(a[0]),s==null&&(s=a[0])):s=a[0],t=a[0]+(a[1]?`#${a[1]}`:"")}if(s==null)return T(null)}let o=this.opf.itemMapByPath[s];if(!o){if(this.opf.opfXML&&s==this.opf.getPathFromURL(this.opf.opfXML.url)){let a=t.indexOf("#");if(a>=0)return this.navigateToFragment(t.substr(a+1),e,n)}return T(null)}let i=A("navigateTo");return this.getPageViewItem(o.spineIndex).then(a=>{if(!a){i.finish(null);return}let l=a.xmldoc.getElement(t);this.findPage({spineIndex:o.spineIndex,pageIndex:-1,offsetInItem:l?a.xmldoc.getElementOffset(l):0},n).thenFinish(i)}),i.result()}makePage(t,e){let n=t.instance.viewport,s=n.document.createElement("div");s.setAttribute("data-vivliostyle-page-container","true"),s.role="presentation",as||(s.style.visibility="hidden"),n.layoutBox.appendChild(s);let o=n.document.createElement("div");o.setAttribute("data-vivliostyle-bleed-box","true"),o.role="presentation",s.appendChild(o);let i=new mo(s,o);if(i.spineIndex=t.item.spineIndex,i.position=e,i.offset=t.instance.getPosition(e),i.offset===0&&!(t.instance.blankPageAtStart&&t.pages.length===0)){let a=this.opf.documentURLTransformer.transformFragment("",t.item.src);o.setAttribute("id",a),i.registerElementWithId(o,a)}if(n!==this.viewport){let a=_l(this.viewport.width,this.viewport.height,n.width,n.height),l=on(null,new Be(a,null),"");i.delayedItems.push(new zn(s,"transform",l))}return i}makeObjectView(t,e,n,s){let o=e.getAttribute("data"),i=null;if(o){o=Q(o,t.url);let a=e.getAttribute("media-type");if(!a){let l=this.opf.getPathFromURL(o);if(l){let c=this.opf.itemMapByPath[l];c&&(a=c.mediaType)}}if(a){let l=this.opf.bindings[a];if(l){i=this.viewport.document.createElement("iframe"),i.style.border="none";let c=Il(o),u=Il(a),d=new Ge;d.append(l),d.append("?src="),d.append(c),d.append("&type="),d.append(u);for(let g=e.firstChild;g;g=g.nextSibling)if(g.nodeType==1){let m=g;if(m.localName=="param"&&m.namespaceURI=="http://www.w3.org/1999/xhtml"){let x=m.getAttribute("name"),E=m.getAttribute("value");x&&E&&(d.append("&"),d.append(encodeURIComponent(x)),d.append("="),d.append(encodeURIComponent(E)))}}i.setAttribute("src",d.toString());let h=e.getAttribute("width");h&&i.setAttribute("width",h);let f=e.getAttribute("height");f&&i.setAttribute("height",f)}}}return i||(i=this.viewport.document.createElement("object"),o&&i.setAttribute("data",o),i.setAttribute("data-adapt-process-children","true")),T(i)}makeMathJaxView(t,e,n,s){let o=Mb();if(o){let i=n.ownerDocument,a=i.createElement("span");n.appendChild(a);let l=i.importNode(e,!0);this.resolveURLsInMathML(l,t),a.appendChild(l);let c=o.queue;c.Push(["Typeset",o,a]);let u=A("makeMathJaxView"),d=u.suspend();return c.Push(()=>{d.schedule(a)}),u.result()}return T(null)}resolveURLsInMathML(t,e){if(t!=null){if(t.nodeType===1&&t.tagName==="mglyph"){let n=Array.from(t.attributes);for(let s of n){if(s.name!=="src")continue;let o=Q(s.nodeValue,e.url);s.namespaceURI?t.setAttributeNS(s.namespaceURI,s.name,o):t.setAttribute(s.name,o)}}t.firstChild&&this.resolveURLsInMathML(t.firstChild,e),t.nextSibling&&this.resolveURLsInMathML(t.nextSibling,e)}}makeCustomRenderer(t){return(e,n,s)=>e.localName=="object"&&e.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(t,e,n,s):e.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(t,e,n,s):e.dataset&&e.dataset.mathTypeset=="true"?this.makeMathJaxView(t,e,n,s):T(null)}getPageViewItem(t){if(t===-1||t>=this.opf.spine.length)return T(null);let e=this.spineItems[t];if(e)return T(e);let n=A("getPageViewItem"),s=this.spineItemLoadingContinuations[t];if(s){let a=n.suspend();return s.push(a),n.result()}else s=this.spineItemLoadingContinuations[t]=[];let o=this.opf.spine[t],i=this.opf.store;return i.load(o.src).then(a=>{var y;let l=o.itemRefElement.getAttribute("properties");l&&a.root.setAttribute("data-vivliostyle-epub-spine-properties",l),o.title=a.document.title;let c=i.getStyleForDoc(a),u=this.makeCustomRenderer(a),d=this.viewport,h=c.sizeViewport(d.width,d.height,d.fontSize,this.pref);(h.width!=d.width||h.height!=d.height||h.fontSize!=d.fontSize)&&(d=new An(d.window,h.fontSize,d.pixelRatio,d.root,h.width,h.height));let f=(y=this.spineItems[0])==null?void 0:y.instance.isVersoFirstPage,g=this.spineItems[t-1],m,x;if(o.startPage!==null)m=o.startPage-1,x=m;else{if(t>0&&(!g||!g.complete))m=o.epage||t,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,x=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let N=this.counterStore.currentPageCounters.page;x=!N||!N.length?m:N[N.length-1]}o.skipPagesBefore!==null&&(m+=o.skipPagesBefore,x+=o.skipPagesBefore)}this.counterStore.forceSetPageCounter(x);let E=new ss(c,a,this.opf.lang,d,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,m,this.opf.documentURLTransformer,this.counterStore,this.opf.pageProgression,f);E.pref=this.pref;let C=this.opf.metadata&&this.opf.metadata[Ne.title];E.pubTitle=C&&C[0]&&C[0].v||"",E.docTitle=o.title||"",E.init().then(()=>{!this.opf.pageProgression&&E.pageProgression&&(this.opf.pageProgression=E.pageProgression),e={item:o,xmldoc:a,instance:E,layoutPositions:[null],pages:[],complete:!1},this.spineItems[t]=e,n.finish(e),s.forEach(N=>{N.schedule(e)})})}),n.result()}removeRenderedPages(){let t=this.spineItems;for(let e of t)e&&e.pages.splice(0);this.viewport.clear()}hasAutoSizedPages(){let t=this.spineItems;for(let e of t)if(e){let n=e.pages;for(let s of n)if(s.isAutoPageWidth&&s.isAutoPageHeight)return!0}return!1}hasPages(){return this.spineItems.some(t=>t&&t.pages.length>0)}showTOC(t){let e=this.opf,n=e.toc;if(this.tocAutohide=t,!n)return T(null);if(this.tocVisible=!0,this.tocView&&this.tocView.page)return this.tocView.page.container.style.visibility="visible",this.tocView.page.container.setAttribute("aria-hidden","false"),T(this.tocView.page);let s=A("showTOC");this.tocView||(this.tocView=new al(e.store,n.src,e.lang,this.clientLayout,this.fontMapper,this.pref,this,e.fallbackMap,e.documentURLTransformer,this.counterStore));let o=this.viewport,i=Math.min(344,Math.round(.67*o.width)-16),a=o.height-6,l=o.document.createElement("div");return o.root.appendChild(l),as||(l.style.visibility="hidden"),l.style.width=`${i+16}px`,l.style.maxHeight=`${a}px`,l.setAttribute("data-vivliostyle-toc-box","true"),l.setAttribute("role","navigation"),this.tocView.showTOC(l,o,i,a,this.viewport.fontSize).then(c=>{l.style.visibility="visible",l.setAttribute("aria-hidden","false"),s.finish(c)}),s.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}};var Vg="data-vivliostyle-viewer-status",Ub="data-vivliostyle-spread-view",kp=(n=>(n.SINGLE_PAGE="singlePage",n.SPREAD="spread",n.AUTO_SPREAD="autoSpread",n))(kp||{}),pl=class{constructor(t,e,n,s){this.window=t;this.viewportElement=e;this.instanceId=n;this.callbackFn=s;p(this,"fontMapper");p(this,"kick");p(this,"sendCommand");p(this,"resizeListener");p(this,"hyperlinkListener");p(this,"pageRuleStyleElement");p(this,"pageSheetSizeAlreadySet",!1);p(this,"renderTask",null);p(this,"actions");p(this,"readyState");p(this,"packageURL");p(this,"opf");p(this,"touchActive");p(this,"touchX");p(this,"touchY");p(this,"needResize");p(this,"resized");p(this,"needRefresh");p(this,"viewportSize");p(this,"currentPage");p(this,"currentSpread");p(this,"pagePosition");p(this,"fontSize");p(this,"zoom");p(this,"fitToScreen");p(this,"pageViewMode");p(this,"waitForLoading");p(this,"renderAllPages");p(this,"pref");p(this,"pageSizes");p(this,"pixelRatio");p(this,"pixelRatioLimit");p(this,"viewport");p(this,"opfView");let o=e.ownerDocument,i=(a,l)=>{let c=o.getElementById(a);return c||(c=o.createElement("style"),c.id=a,l&&(c.textContent=l),o.head.appendChild(c)),c};i("vivliostyle-viewport-screen-css",bc),i("vivliostyle-viewport-css",xc),i("vivliostyle-polyfill-css",Tc),e.setAttribute("data-vivliostyle-viewer-viewport",!0),as&&e.setAttribute("data-vivliostyle-debug",!0),e.setAttribute(Vg,"loading"),this.fontMapper=new za(o.head,e),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=a=>{},this.pageRuleStyleElement=i("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}init(){this.readyState="loading",this.packageURL=[],this.opf=null,this.touchActive=!1,this.touchX=0,this.touchY=0,this.needResize=!1,this.resized=!1,this.needRefresh=!1,this.viewportSize=null,this.currentPage=null,this.currentSpread=null,this.pagePosition=null,this.fontSize=16,this.zoom=1,this.fitToScreen=!1,this.pageViewMode="singlePage",this.waitForLoading=!1,this.renderAllPages=!0,this.pref=Ml(),this.pageSizes=[],this.pixelRatioLimit=ar==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let t=Tl;F.addListener(t.DEBUG,e=>{this.callback({t:"debug",content:e})}),F.addListener(t.INFO,e=>{this.callback({t:"info",content:e})}),F.addListener(t.WARN,e=>{this.callback({t:"warn",content:e})}),F.addListener(t.ERROR,e=>{this.callback({t:"error",content:e})})}callback(t){t.i=this.instanceId,this.callbackFn(t)}setReadyState(t){this.readyState!==t&&(this.readyState=t,this.viewportElement.setAttribute(Vg,t),this.callback({t:"readystatechange"}))}loadPublication(t){$e.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,n=t.fragment,s=t.authorStyleSheet,o=t.userStyleSheet;this.viewport=null;let i=A("loadPublication");return this.configure(t).then(()=>{let a=new Qi;a.init(s,o).then(()=>{let l=Q(Rn(e),this.window.location.href);this.packageURL=[l],a.loadPubDoc(l).then(c=>{c?(this.opf=c,this.render(n).then(()=>{i.finish(!0)})):i.finish(!1)})})}),i.result()}loadXML(t){$e.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,n=t.document,s=t.fragment,o=t.authorStyleSheet,i=t.userStyleSheet;this.viewport=null;let a=A("loadXML");return this.configure(t).then(()=>{let l=new Qi;l.init(o,i).then(()=>{let c=e.map((u,d)=>({url:Q(Rn(u.url),this.window.location.href),index:d,startPage:u.startPage,skipPagesBefore:u.skipPagesBefore}));this.packageURL=c.map(u=>u.url),this.opf=new Ws(l,""),this.opf.initWithChapters(c,n).then(()=>{this.render(s).then(()=>{a.finish(!0)})})})}),a.result()}render(t){this.cancelRenderingTask();let e;return t?e=this.opf.resolveFragment(t).thenAsync(n=>(this.pagePosition=n,T(!0))):e=T(!0),e.thenAsync(()=>($e.registerEndTiming("beforeRender"),this.resize()))}resolveLength(t){let e=parseFloat(t),n=/[a-z]+$/,s;if(typeof t=="string"&&(s=t.match(n))){let o=s[0];if(o==="em"||o==="rem")return e*this.fontSize;if(o==="ex")return e*K.ex*this.fontSize/K.em;let i=K[o];if(i)return e*i}return e}configure(t){if(typeof t.autoresize=="boolean"&&(t.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof t.fontSize=="number"){let e=t.fontSize;e>=5&&e<=72&&this.fontSize!=e&&(this.fontSize=e,this.needResize=!0)}if(typeof t.viewport=="object"&&t.viewport){let e=t.viewport,n={marginLeft:this.resolveLength(e["margin-left"])||0,marginRight:this.resolveLength(e["margin-right"])||0,marginTop:this.resolveLength(e["margin-top"])||0,marginBottom:this.resolveLength(e["margin-bottom"])||0,width:this.resolveLength(e.width)||0,height:this.resolveLength(e.height)||0};(n.width>=200||n.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=n,this.needResize=!0)}if(typeof t.hyphenate=="boolean"&&(this.pref.hyphenate=t.hyphenate,this.needResize=!0),typeof t.horizontal=="boolean"&&(this.pref.horizontal=t.horizontal,this.needResize=!0),typeof t.nightMode=="boolean"&&(this.pref.nightMode=t.nightMode,this.needResize=!0),typeof t.lineHeight=="number"&&(this.pref.lineHeight=t.lineHeight,this.needResize=!0),typeof t.columnWidth=="number"&&(this.pref.columnWidth=t.columnWidth,this.needResize=!0),typeof t.fontFamily=="string"&&(this.pref.fontFamily=t.fontFamily,this.needResize=!0),typeof t.load=="boolean"&&(this.waitForLoading=t.load),typeof t.renderAllPages=="boolean"&&(this.renderAllPages=t.renderAllPages),typeof t.userAgentRootURL=="string"&&(kl(t.userAgentRootURL.replace(/resources\/?$/,"")),Al(t.userAgentRootURL)),typeof t.rootURL=="string"&&(kl(t.rootURL),Al(`${hn}resources/`)),typeof t.pageViewMode=="string"&&t.pageViewMode!==this.pageViewMode&&(this.pageViewMode=t.pageViewMode,this.needResize=!0),typeof t.pageBorder=="number"&&t.pageBorder!==this.pref.pageBorder&&(this.viewport=null,this.pref.pageBorder=t.pageBorder,this.needResize=!0),typeof t.zoom=="number"&&t.zoom!==this.zoom&&(this.zoom=t.zoom,this.needRefresh=!0),typeof t.fitToScreen=="boolean"&&t.fitToScreen!==this.fitToScreen&&(this.fitToScreen=t.fitToScreen,this.needRefresh=!0),typeof t.defaultPaperSize=="object"&&typeof t.defaultPaperSize.width=="number"&&typeof t.defaultPaperSize.height=="number"&&(this.viewport=null,this.pref.defaultPaperSize=t.defaultPaperSize,this.needResize=!0),typeof t.allowScripts=="boolean"&&t.allowScripts!==Xt&&(Sg(t.allowScripts),this.needResize=!0),typeof t.pixelRatio=="number"){let e=Math.min(t.pixelRatio,this.pixelRatioLimit);e!==this.pixelRatio&&(this.pixelRatio=e,this.needResize=!0)}return this.configurePlugins(t),T(!0)}configurePlugins(t){He("CONFIGURATION").forEach(n=>{let s=n(t);this.needResize=s.needResize||this.needResize,this.needRefresh=s.needRefresh||this.needRefresh})}pageReplacedListener(t){let e=this.currentPage,n=this.currentSpread,s=t.target;n?(n.left===s||n.right===s)&&this.showCurrent(t.newPage):e===t.target&&this.showCurrent(t.newPage)}forCurrentPages(t){let e=[];this.currentPage&&e.push(this.currentPage),this.currentSpread&&(e.push(this.currentSpread.left),e.push(this.currentSpread.right)),e.forEach(n=>{n&&t(n)})}removePageListeners(){this.forCurrentPages(t=>{t.removeEventListener("hyperlink",this.hyperlinkListener,!1),t.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(t=>{w(t.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(t){t.addEventListener("hyperlink",this.hyperlinkListener,!1),t.addEventListener("replaced",this.pageReplacedListener,!1),w(t.container,"visibility","visible"),w(t.container,"display","block")}showPage(t){this.hidePages(),this.currentPage=t,t.container.style.marginLeft="",t.container.style.marginRight="",this.showSinglePage(t)}showSpread(t){if(this.hidePages(),this.currentSpread=t,t.left&&t.right){let e=parseFloat(t.left.container.style.width),n=parseFloat(t.right.container.style.width);e&&n&&e!==n&&(e<n?t.left.container.style.marginLeft=`${n-e}px`:t.right.container.style.marginRight=`${e-n}px`)}t.left&&(this.showSinglePage(t.left),t.right?t.left.container.removeAttribute("data-vivliostyle-unpaired-page"):t.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),t.right&&(this.showSinglePage(t.right),t.left?t.right.container.removeAttribute("data-vivliostyle-unpaired-page"):t.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let t=A("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(e=>{let n=this.currentPage;(this.waitForLoading&&n.fetchers.length>0?On(n.fetchers):T(!0)).then(()=>{this.sendLocationNotification(n,e).thenFinish(t)})}),t.result()}createViewport(){let t=this.viewportElement;if(this.viewportSize){let e=this.viewportSize;return t.style.marginLeft=`${e.marginLeft}px`,t.style.marginRight=`${e.marginRight}px`,t.style.marginTop=`${e.marginTop}px`,t.style.marginBottom=`${e.marginBottom}px`,new An(this.window,this.fontSize,this.pixelRatio,t,e.width,e.height)}else return new An(this.window,this.fontSize,this.pixelRatio,t)}resolveSpreadView(t,e){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;case"autoSpread":default:return t!=null&&(t.width-this.pref.pageBorder)/t.height>=(e?e.width*2/e.height:1.45)&&(!!e||t.width>800)}}updateSpreadView(t){this.pref.spreadView=t,this.viewportElement.setAttribute(Ub,t.toString())}sizeIsGood(){var i;let t=this.createViewport(),e=((i=this.opfView)==null?void 0:i.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&e?this.pageSizes[0]:null);this.resized=!1;let s=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!s&&t.width==this.viewport.width&&t.height==this.viewport.height||!s&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:e?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(t,e,n,s){this.pageSizes[s]=t,this.setPageSizePageRules(e,n,s),s===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,t))}setPageSizePageRules(t,e,n){var o,i;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[n].width!==((o=this.pageSizes[n-1])==null?void 0:o.width)||this.pageSizes[n].height!==((i=this.pageSizes[n-1])==null?void 0:i.height))){let c=function(m){let x=m*.75;return Math.ceil(x)};var s=c;let a=Math.max(...this.pageSizes.map(m=>m.width)),l=Math.max(...this.pageSizes.map(m=>m.height)),u=c(a),d=c(l),h=u*((this.pixelRatio||1)-1)+2,f=d*((this.pixelRatio||1)-1)+2,g=`@page {size: ${u}pt ${d}pt; margin: 0 ${-h}pt ${-f}pt 0;}`;this.pageRuleStyleElement.textContent=g,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}reset(){let t=!1,e=!1;this.opfView&&(t=this.opfView.tocVisible,e=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new dl(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this)),t&&this.sendCommand({a:"toc",v:"show",autohide:e})}showCurrent(t,e){this.needRefresh=!1,this.removePageListeners();let n=this.resolveSpreadView(this.viewport,t.dimensions);return n!==this.pref.spreadView&&this.updateSpreadView(n),n?this.opfView.getSpread(this.pagePosition,e).thenAsync(s=>!s.left&&!s.right?T(null):s.left&&s.right&&(!this.resolveSpreadView(this.viewport,s.left.dimensions)||!this.resolveSpreadView(this.viewport,s.right.dimensions))?(this.updateSpreadView(!1),this.showPage(t),this.setPageZoom(t),this.currentPage=t,T(null)):(this.showSpread(s),this.setSpreadZoom(s),this.currentPage=t.side==="left"?s.left:s.right,T(null))):(this.showPage(t),this.setPageZoom(t),this.currentPage=t,T(null))}setPageZoom(t){var n;let e=this.getAdjustedZoomFactor(t.dimensions);(n=this.viewport)==null||n.zoom(t.dimensions.width,t.dimensions.height,e)}setSpreadZoom(t){var n;let e=this.getSpreadDimensions(t);(n=this.viewport)==null||n.zoom(e.width,e.height,this.getAdjustedZoomFactor(e))}getAdjustedZoomFactor(t){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(t):this.zoom}getSpreadDimensions(t){let e=0,n=0;return t.left&&(e+=t.left.dimensions.width,n=t.left.dimensions.height),t.right&&(e+=t.right.dimensions.width,n=Math.max(n,t.right.dimensions.height)),t.left&&t.right&&(e+=this.pref.pageBorder*2,e+=Math.abs(t.left.dimensions.width-t.right.dimensions.width)),{width:e,height:n}}queryZoomFactor(t){if(!this.currentPage)throw new Error("no page exists.");switch(t){case"fit inside viewport":{let e;return this.pref.spreadView?(this.currentSpread,e=this.getSpreadDimensions(this.currentSpread)):e=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(e)}default:throw new Error(`unknown zoom type: ${t}`)}}calculateZoomFactorToFitInsideViewPort(t){if(!this.viewport)return this.zoom;let e=this.viewport.width/t.width,n=this.viewport.height/t.height;return Math.min(e,n)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new hl),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return T(!0);this.setReadyState("loading"),this.cancelRenderingTask();let t=ei().getScheduler().run(()=>Cn("resize",e=>{if(!this.opf){e.finish(!1);return}this.renderTask=t,$e.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(n=>{if(!n){e.finish(!1);return}this.pagePosition=n.position,this.showCurrent(n.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(s=>{let o={t:"nav",epageCount:s,first:this.currentPage.isFirstPage,last:this.currentPage.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(o.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(o)}).then(()=>{this.reportPosition().then(s=>{(this.renderAllPages?this.opfView.renderAllPages():T(null)).then(()=>{this.renderTask===t&&(this.renderTask=null),$e.registerEndTiming("render (resize)"),Xt&&xp(this.window)?Tg(this.window).then(()=>{this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),e.finish(s)}):(this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),e.finish(s))})})})})})},(e,n)=>{if(n instanceof hl)$e.registerEndTiming("render (resize)"),F.debug(n.message);else throw n}));return T(!0)}sendLocationNotification(t,e){let n=A("sendLocationNotification"),s={t:"nav",first:t.isFirstPage,last:t.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[t.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(o=>{s.epage=o,s.epageCount=this.opf.epageCount,e&&(s.cfi=e),this.callback(s),n.finish(!0)}),n.result()}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(t){var s;let e;if(this.readyState!=="complete"&&t.where!=="next"&&this.setReadyState("loading"),typeof t.where=="string"){let o;switch(t.where){case"next":o=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":o=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":o=this.opfView.lastPage;break;case"first":o=this.opfView.firstPage;break;default:return T(!0)}o&&(e=()=>o.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof t.epage=="number"){let o=t.epage;e=()=>this.opfView.navigateToEPage(o,this.pagePosition,!this.renderAllPages)}else if(typeof t.url=="string"){let o=t.url;e=()=>this.opfView.navigateTo(o,this.pagePosition,!this.renderAllPages)}else if(typeof((s=t.position)==null?void 0:s.spineIndex)=="number"){let o=t.position;e=()=>this.opfView.findPage(o,!this.renderAllPages)}else return T(!0);if(!this.opfView)return T(!0);let n=A("moveTo");return e.call(this.opfView).then(o=>{let i;if(o){this.pagePosition=o.position;let a=A("moveTo.showCurrent");i=a.result(),this.showCurrent(o.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(a)})}else i=T(!0);i.then(a=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(a)})}),n.result()}showTOC(t){let e=!!t.autohide,n=t.v,s=this.opfView.isTOCVisible(),o=e!=this.opfView.tocAutohide&&n!="hide";if(s){if(n=="show"&&!o)return T(!0)}else if(n=="hide")return T(!0);if(s&&n!="show")return this.opfView.hideTOC(),T(!0);{let i=A("showTOC");return this.opfView.showTOC(e).then(a=>{if(a){if(o&&(a.listeners={}),e){let l=()=>{this.opfView.hideTOC()};a.addEventListener("hyperlink",l,!1)}a.addEventListener("hyperlink",this.hyperlinkListener,!1)}i.finish(!0)}),i.result()}}runCommand(t){let e=t.a||"";return Cn("runCommand",n=>{let s=this.actions[e];s?s.call(this,t).then(()=>{this.callback({t:"done",a:e}),n.finish(!0)}):(F.error("No such action:",e),n.finish(!0))},(n,s)=>{F.error(s,"Error during action:",e),n.finish(!0)})}initEmbed(t){let e=Fg(t),n=null,s=this;yh(()=>{let o=A("commandLoop"),i=ei().getScheduler();return s.hyperlinkListener=a=>{let l=a,c=l.href.charAt(0)==="#"||s.packageURL.some(u=>l.href.substr(0,u.length)==u);if(c){a.preventDefault();let u={t:"hyperlink",href:l.href,internal:c};i.run(()=>(s.callback(u),T(!0)))}},o.loopWithFrame(a=>{if(s.needResize)s.resize().then(()=>{a.continueLoop()});else if(s.needRefresh)s.currentPage&&s.showCurrent(s.currentPage,!this.renderAllPages).then(()=>{a.continueLoop()});else if(e){let l=e;e=null,s.runCommand(l).then(()=>{a.continueLoop()})}else{let l=A("waitForCommand");n=l.suspend(this),l.result().then(()=>{a.continueLoop()})}}).thenFinish(o),o.result()}),s.kick=()=>{let o=n;o&&(n=null,o.schedule(!0))},s.sendCommand=o=>e?!1:(e=Fg(o),s.kick(),!0),this.window.adapt_command=s.sendCommand}},Ap=(t=>(t.FIT_INSIDE_VIEWPORT="fit inside viewport",t))(Ap||{}),hl=class r extends Error{constructor(){super();p(this,"name","RenderingCanceledError");p(this,"message","Page rendering has been canceled");p(this,"stack");Object.setPrototypeOf(this,r.prototype),this.stack=new Error().stack}};function Fg(r){return typeof r=="string"?js(r):r}var Bg=ls;function zb(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function Og(r){let t={};return Object.keys(r).forEach(e=>{let n=r[e];switch(e){case"autoResize":t.autoresize=n;break;case"pageBorderWidth":t.pageBorder=n;break;default:t[e]=n}}),t}var Ji=class{constructor(t,e){this.settings=t;p(this,"initialized",!1);p(this,"adaptViewer_");p(this,"options");p(this,"eventTarget");p(this,"readyState");El(t.debug),this.adaptViewer_=new pl(t.window||window,t.viewportElement,"main",this.dispatcher.bind(this)),this.options=zb(),e&&this.setOptions(e),this.eventTarget=new Ln,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(t){let e=Object.assign({a:"configure"},Og(t));this.adaptViewer_.sendCommand(e),Object.assign(this.options,t)}dispatcher(t){let e={type:t.t},n=t;Object.keys(n).forEach(s=>{s!=="t"&&(e[s]=n[s])}),this.eventTarget.dispatchEvent(e)}addListener(t,e){this.eventTarget.addEventListener(t,e,!1)}removeListener(t,e){this.eventTarget.removeEventListener(t,e,!1)}loadDocument(t,e,n){if(!t||(Array.isArray(t)?!t[0]||typeof t[0]!="string"&&!t[0].url:typeof t!="string"&&!t.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(t,null,e,n)}loadPublication(t,e,n){if(!t){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,t,e,n)}loadDocumentOrPublication(t,e,n,s){let o=n||{};function i(u){if(u)return u.map(d=>({url:d.url||null,text:d.text||null}))}let a=i(o.authorStyleSheet),l=i(o.userStyleSheet);s&&Object.assign(this.options,s);let c=Object.assign({a:t?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:Gb(t)||e,document:o.documentObject,fragment:o.fragment,authorStyleSheet:a,userStyleSheet:l},Og(this.options));this.initialized?this.adaptViewer_.sendCommand(c):(this.initialized=!0,this.adaptViewer_.initEmbed(c))}getCurrentPageProgression(){return this.adaptViewer_.getCurrentPageProgression()}resolveNavigation(t){switch(t){case"left":return this.getCurrentPageProgression()===Bg.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Bg.LTR?"next":"previous";default:return t}}navigateToPage(t,e){t==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:e}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(t)})}navigateToInternalUrl(t){this.adaptViewer_.sendCommand({a:"moveTo",url:t})}navigateToPosition(t){var e,n;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:t.spineIndex,pageIndex:(e=t.pageIndex)!=null?e:-1,offsetInItem:(n=t.offsetInItem)!=null?n:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(t,e){let n=t==null?"toggle":t?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:n,autohide:e})}queryZoomFactor(t){return this.adaptViewer_.queryZoomFactor(t)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var t,e;return(e=(t=this.adaptViewer_.opfView)==null?void 0:t.tocView)==null?void 0:e.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}};function Gb(r){function t(n){return typeof n=="number"?n:null}function e(n){return typeof n=="string"?{url:n,startPage:null,skipPagesBefore:null}:{url:n.url,startPage:t(n.startPage),skipPagesBefore:t(n.skipPagesBefore)}}return Array.isArray(r)?r.map(e):r?[e(r)]:null}var Dg=(a=>(a.PREVIOUS="previous",a.NEXT="next",a.LEFT="left",a.RIGHT="right",a.FIRST="first",a.LAST="last",a.EPAGE="epage",a))(Dg||{}),Wb=Ap,$b=kp;$e.forceRegisterEndTiming("load_vivliostyle");var Lp=class{constructor(t,{title:e="",printCallback:n=a=>a.print(),errorCallback:s=null,hideIframe:o=!0,removeIframe:i=!0}){p(this,"htmlDoc");p(this,"title");p(this,"printCallback");p(this,"errorCallback");p(this,"hideIframe");p(this,"removeIframe");p(this,"iframe");p(this,"iframeWin");p(this,"window");this.htmlDoc=t,this.title=e,this.printCallback=n,this.errorCallback=s,this.hideIframe=o,this.removeIframe=i}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
|
|
1518
1518
|
<!DOCTYPE html>
|
|
1519
1519
|
<html data-vivliostyle-paginated="true">
|
|
1520
1520
|
<head>
|