@vivliostyle/print 2.36.1 → 2.36.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +2 -2
- package/dist/index.es6.js +1 -1
- package/dist/index.es6.js.map +2 -2
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1514,7 +1514,7 @@ span[data-viv-leader] {
|
|
|
1514
1514
|
`);for(let n of xo(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
|
|
1515
1515
|
`);if(t){i.append('src: url("');let n=Cp(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
|
|
1516
1516
|
}
|
|
1517
|
-
`),i.toString()}},Xm=class{constructor(e){this.deobfuscator=e,u(this,"familyMap",{})}registerFamily(e,t){let i=e.family,n=this.familyMap[i],s=t.family;if(n){if(n!=s)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${e.family}`)}else this.familyMap[i]=s}filterFontFamily(e){if(e instanceof Ye){let t=e.values,i=[];for(let n of t){let s=this.familyMap[n.stringValue()];s&&i.push(B(s)),i.push(n)}return new Ye(i)}else{let t=this.familyMap[e.stringValue()];return t?new Ye([B(t),e]):e}}},qm=class{constructor(e,t,i){this.head=e,this.body=t,u(this,"srcURLMap",{}),u(this,"familyPrefix"),u(this,"familyCounter",0),this.familyPrefix=i||"Fnt_"}getViewFontFamily(e,t){let i=e.family,n=t.familyMap[i];return n||(n=this.familyPrefix+ ++this.familyCounter,t.familyMap[i]=n,n)}initFont(e,t,i){let n=F("initFont"),s=e.src,r={};for(let l of xo(e.properties))r[l]=e.properties[l];let o=this.getViewFontFamily(e,i);r["font-family"]=B(o);let a=new Wu(r),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(s,t),this.head.appendChild(h),H.debug("Load font:",s),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i,s=this.srcURLMap[n];return s?s.piggyback(r=>{let o=r;o.traitsEqual(e)?(t.registerFamily(e,o),H.debug("Found already-loaded font:",i)):H.warn("E_FONT_FACE_INCOMPATIBLE",e.src)}):(s=new Cn(()=>{let r=F("loadFont"),o=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(o):null;return a?bs(o,"blob").then(h=>{if(!h.responseBlob){r.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(e,l,t).thenFinish(r)})}):this.initFont(e,null,t).thenFinish(r),r.result()},`loadFont ${i}`),this.srcURLMap[n]=s,s.start()),s}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){H.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return ws(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(s=>{}))}),t===0)return N(!0);let i=F("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?N(!0):N(!1))).thenFinish(i),i.result()}},Ym=1,Cs=class{constructor(e,t,i,n,s){this.name=t,this.pseudoName=i,this.classes=n,this.parent=s,u(this,"specified",{}),u(this,"children",[]),u(this,"pageMaster",null),u(this,"index",0),u(this,"key"),u(this,"_scope"),this._scope=e,this.key=`p${Ym++}`,s&&(this.index=s.children.length,s.children.push(this))}get scope(){return this._scope}createInstance(e){throw new Error("E_UNEXPECTED_CALL")}clone(e){throw new Error("E_UNEXPECTED_CALL")}copySpecified(e){let t=this.specified,i=e.specified;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n])}cloneChildren(e){for(let t=0;t<this.children.length;t++)this.children[t].clone({parent:e})}},Zm=class extends Cs{constructor(e){super(e,null,null,[],null),this.specified.width=new Z(xn,0),this.specified.height=new Z(Sn,0)}},Ua=class extends Zs{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(s,r){let o=s.match(/^([^.]+)\.([^.]+)$/);if(o){let a=i.pageMaster.keyMap[o[1]];if(a){let h=this.lookupInstance(a);if(h)return r?h.resolveFunc(o[2]):h.resolveName(o[2])}}return null}}},ju=class Xu extends Cs{constructor(t,i,n,s,r,o,a){super(t,i,n,s,r),this.condition=o,this.specificity=a,u(this,"keyMap",{}),t instanceof Ua||(this._scope=new Ua(t,this)),this.pageMaster=this,this.specified.width=new Z(xn,0),this.specified.height=new Z(Sn,0),this.specified["wrap-flow"]=new Z(v.auto,0),this.specified.position=new Z(v.relative,0),this.specified.overflow=new Z(v.visible,0)}createInstance(t){return new Co(t,this)}clone(t){let i=new Xu(this.scope,this.name,t.pseudoName||this.pseudoName,this.classes,this.parent,this.condition,this.specificity);return this.copySpecified(i),this.cloneChildren(i),i}resetScope(){this.scope.pageMaster=this}},qu=class Yu extends Cs{constructor(t,i,n,s,r){super(t,i,n,s,r),this.pageMaster=r.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new Z(v.auto,0)}createInstance(t){return new ew(t,this)}clone(t){let i=new Yu(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},Tn=class Zu extends Cs{constructor(t,i,n,s,r){super(t,i,n,s,r),this.pageMaster=r.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new Ii(t,this)}clone(t){let i=new Zu(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function Km(e,t,i){return!t||K(t)?new Fe(e,i):t.toExpr(e,e.zero)}function ae(e,t,i){return!t||t===v.auto||K(t)?null:t.toExpr(e,i)}function Jm(e,t,i){return!t||t===v.normal||K(t)?null:t.toExpr(e,i)}function st(e,t,i){return!t||t===v.auto||K(t)?e.zero:t.toExpr(e,i)}function Ha(e,t,i){return!t||K(t)?e.zero:t===v.auto?null:t.toExpr(e,i)}function Ct(e,t,i,n){return!t||i===v.none||K(t)?e.zero:t.toExpr(e,n)}function Ku(e,t,i){return!t||K(t)?i:t===v._true?e._true:t===v._false?e._false:t.toExpr(e,e.zero)}var Es=class{constructor(e,t){this.parentInstance=e,this.pageBox=t,u(this,"cascaded",{}),u(this,"style",{}),u(this,"autoWidth",null),u(this,"autoHeight",null),u(this,"children",[]),u(this,"isAutoWidth",!1),u(this,"isAutoHeight",!1),u(this,"isTopDependentOnAutoHeight",!1),u(this,"isRightDependentOnAutoWidth",!1),u(this,"calculatedWidth",0),u(this,"calculatedHeight",0),u(this,"pageMasterInstance",null),u(this,"namedValues",{}),u(this,"namedFuncs",{}),u(this,"vertical",!1),u(this,"rtl",!1),u(this,"suppressEmptyBoxGeneration",!1),u(this,"borderBoxSizing",!1),e&&e.children.push(this)}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(e,t){let i=this.resolveName(e),n=this.resolveName(t);if(!i||!n)throw new Error("E_INTERNAL");return X(this.pageBox.scope,i,n)}resolveName(e){let t=this.namedValues[e];if(t)return t;let i=this.style[e];switch(i&&(t=i.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),e){case"margin-left-edge":t=this.resolveName("left");break;case"margin-top-edge":t=this.resolveName("top");break;case"margin-right-edge":t=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":t=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":t=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":t=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":t=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":t=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":t=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":t=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":t=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":t=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":t=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":t=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":t=this.addNamedValues("left-edge","width");break;case"bottom-edge":t=this.addNamedValues("top-edge","height");break}if(!t){let n;if(e=="extent")n=this.vertical?"width":"height";else if(e=="measure")n=this.vertical?"height":"width";else{let s=this.vertical?jh:Xh;n=e;for(let r in s)n=n.replace(r,s[r])}n!=e&&(t=this.resolveName(n))}return t&&(this.namedValues[e]=t),t}resolveFunc(e){let t=this.namedFuncs[e];if(t)return t;switch(e){case"columns":{let i=this.pageBox.scope,n=new zl(i,0),s=this.resolveName("column-count"),r=this.resolveName("column-width"),o=this.resolveName("column-gap");t=re(i,Un(i,new Zi(i,"min",[n,s]),X(i,r,o)),o);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=Ku(e,t.enabled,e._true),n=ae(e,t.page,e.zero);if(n){let o=new Ie(e,"page-number");i=pt(e,i,new Xr(e,n,o))}let s=ae(e,t["min-page-width"],e.zero);s&&(i=pt(e,i,new Js(e,new Ie(e,"page-width"),s)));let r=ae(e,t["min-page-height"],e.zero);r&&(i=pt(e,i,new Js(e,new Ie(e,"page-height"),r))),i=this.boxSpecificEnabled(i),t.enabled=new D(i)}boxSpecificEnabled(e){return e}initHorizontal(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=ae(e,t.left,i),s=ae(e,t["margin-left"],i),r=Ct(e,t["border-left-width"],t["border-left-style"],i),o=st(e,t["padding-left"],i),a=ae(e,t.width,i),h=ae(e,t["max-width"],i),l=st(e,t["padding-right"],i),c=Ct(e,t["border-right-width"],t["border-right-style"],i),p=ae(e,t["margin-right"],i),d=ae(e,t.right,i),f=X(e,r,o),m=X(e,r,l);if(n&&d&&a){let y=re(e,i,X(e,a,X(e,X(e,n,f),m)));s?p?d=re(e,y,p):p=re(e,y,X(e,d,s)):(y=re(e,y,d),p?s=re(e,y,p):(s=Un(e,y,new Fe(e,.5)),p=s))}else{s||(s=e.zero),p||(p=e.zero),!n&&!d&&!a&&(n=e.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!d?n=e.zero:!a&&!d&&(a=this.autoWidth,this.isAutoWidth=!0);let y=re(e,i,X(e,X(e,s,f),X(e,p,m)));this.isAutoWidth&&(h||(h=re(e,y,n||d)),!this.vertical&&(ae(e,t["column-width"],null)||ae(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?d||(d=re(e,y,X(e,n,a))):a=re(e,y,X(e,n,d)):n=re(e,y,X(e,d,a))}let g=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=st(e,g,i);t.left=new D(n),t["margin-left"]=new D(s),t["border-left-width"]=new D(r),t["padding-left"]=new D(o),t.width=new D(a),t["max-width"]=new D(h||a),t["padding-right"]=new D(l),t["border-right-width"]=new D(c),t["margin-right"]=new D(p),t.right=new D(d),t["snap-width"]=new D(w)}initVertical(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(e,null):null,s=ae(e,t.top,n),r=ae(e,t["margin-top"],i),o=Ct(e,t["border-top-width"],t["border-top-style"],i),a=st(e,t["padding-top"],i),h=ae(e,t.height,n),l=ae(e,t["max-height"],n),c=st(e,t["padding-bottom"],i),p=Ct(e,t["border-bottom-width"],t["border-bottom-style"],i),d=ae(e,t["margin-bottom"],i),f=ae(e,t.bottom,n),m=X(e,o,a),g=X(e,p,c);if(s&&f&&h){let b=re(e,n,X(e,h,X(e,X(e,s,m),g)));r?d?f=re(e,b,r):d=re(e,b,X(e,f,r)):(b=re(e,b,f),d?r=re(e,b,d):(r=Un(e,b,new Fe(e,.5)),d=r))}else{r||(r=e.zero),d||(d=e.zero),!s&&!f&&!h&&(s=e.zero),!s&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!s&&!f?s=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let b=re(e,n,X(e,X(e,r,m),X(e,d,g)));this.isAutoHeight&&(l||(l=re(e,b,s||f)),this.vertical&&(ae(e,t["column-width"],null)||ae(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),s?h?f||(f=re(e,b,X(e,s,h))):h=re(e,b,X(e,f,s)):s=re(e,b,X(e,f,h))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),y=st(e,w,i);t.top=new D(s),t["margin-top"]=new D(r),t["border-top-width"]=new D(o),t["padding-top"]=new D(a),t.height=new D(h),t["max-height"]=new D(l||h),t["padding-bottom"]=new D(c),t["border-bottom-width"]=new D(p),t["margin-bottom"]=new D(d),t.bottom=new D(f),t["snap-height"]=new D(y)}initColumns(){let e=this.pageBox.scope,t=this.style,i=ae(e,t[this.vertical?"height":"width"],null),n=ae(e,t["column-width"],i),s=ae(e,t["column-count"],null),r=Jm(e,t["column-gap"],null);r||(r=new yn(e,1,"em")),n&&!s&&(s=new Zi(e,"floor",[Qs(e,X(e,i,r),X(e,n,r))]),s=new Zi(e,"max",[e.one,s])),s||(s=e.one),n=re(e,Qs(e,X(e,i,r),s),r),t["column-width"]=new D(n),t["column-count"]=new D(s),t["column-gap"]=new D(r)}depends(e,t,i){return this.style[e].toExpr(this.pageBox.scope,null).depend(t,i)}init(e){var t;e.registerInstance(this.pageBox.key,this);let i=this.pageBox.scope,n=this.style,s=this.parentInstance?this.parentInstance.getActiveRegions(e):null,r=cu(this.cascaded,e,s,!1,null);this.vertical=hu(r,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=uu(r,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=r["box-sizing"])==null?void 0:t.value)===v.border_box;let o=!!(e instanceof To&&e.currentLayoutPosition&&new Ie(i,"left-page").evaluate(e));pu(r,n,this.vertical,this.rtl,o,(a,h)=>h.value),this.autoWidth=new Te(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new Te(i,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(e,t){var i,n;let s=this.style[t];return!s&&tn(t)&&this.pageMasterInstance instanceof Ei&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?s=new I(e.rootFontSize,"px"):s=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),s&&(s=as(e,s,t)),s}getPropAsNumber(e,t){var i,n;let s=this.style[t];if(s){let r=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();s=as(e,s,t,r)}return We(s,e)}getSpecial(e,t){let i=Zh(this.cascaded,t);if(i){let n=[];for(let s=0;s<i.length;s++){let r=i[s].evaluate(e,"");r&&r!==G&&n.push(r)}if(n.length)return n}return null}getActiveRegions(e){let t=this.getSpecial(e,"region-id");if(t){let i=[];for(let n=0;n<t.length;n++)i[n]=t[n].toString();return i}return null}propagateProperty(e,t,i,n){this.propagatePropertyToElement(e,t.element,i,n)}propagatePropertyToElement(e,t,i,n){let s=this.getProp(e,i);s&&(s.isNumeric()&&Pl(s.unit)&&(s=Wl(s,e)),i==="font-family"&&(s=n.filterFontFamily(s)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),P(t,i,s.toString()))}propagateDelayedProperty(e,t,i,n){let s=this.getProp(e,i);s&&n.push(new to(t.element,i,s))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),s=this.getPropAsNumber(e,"padding-left"),r=this.getPropAsNumber(e,"border-left-width"),o=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,o),P(t.element,"margin-left",`${n}px`),P(t.element,"padding-left",`${s}px`),P(t.element,"border-left-width",`${r}px`),t.marginLeft=n,t.borderLeft=r,t.paddingLeft=s}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),s=this.getPropAsNumber(e,"margin-right"),r=this.getPropAsNumber(e,"padding-right"),o=this.getPropAsNumber(e,"border-right-width");if(P(t.element,"margin-right",`${s}px`),P(t.element,"padding-right",`${r}px`),P(t.element,"border-right-width",`${o}px`),t.marginRight=s,t.borderRight=o,this.vertical&&n>0){let a=i+t.getInsetRight(),h=a-Math.floor(a/n)*n;h>0&&(t.snapOffsetX=n-h,r+=t.snapOffsetX)}t.paddingRight=r,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),s=this.getPropAsNumber(e,"margin-top"),r=this.getPropAsNumber(e,"padding-top"),o=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=s,t.borderTop=o,t.snapHeight=i,!this.vertical&&i>0){let a=n+t.getInsetTop(),h=a-Math.floor(a/i)*i;h>0&&(t.snapOffsetY=i-h,r+=t.snapOffsetY)}t.paddingTop=r,P(t.element,"top",`${n}px`),P(t.element,"margin-top",`${s}px`),P(t.element,"padding-top",`${r}px`),P(t.element,"border-top-width",`${o}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),s=this.getPropAsNumber(e,"border-bottom-width"),r=this.getPropAsNumber(e,"height")-t.snapOffsetY;P(t.element,"height",`${r}px`),P(t.element,"margin-bottom",`${i}px`),P(t.element,"padding-bottom",`${n}px`),P(t.element,"border-bottom-width",`${s}px`),t.height=r-t.snapOffsetY,t.marginBottom=i,t.borderBottom=s,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){P(t.element,"border-top-width","0px");let i=this.getPropAsNumber(e,"max-height");this.isTopDependentOnAutoHeight?t.setVerticalPosition(0,i):(this.assignTopPosition(e,t),i-=t.snapOffsetY,t.height=i,P(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){P(t.element,"border-left-width","0px");let i=this.getPropAsNumber(e,"max-width");if(this.isRightDependentOnAutoWidth)t.setHorizontalPosition(0,i);else{this.assignRightPosition(e,t),i-=t.snapOffsetX,t.width=i;let n=this.getPropAsNumber(e,"right");P(t.element,"right",`${n}px`),P(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,s){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&P(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&P(t.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(e,t):this.sizeWithMaxHeight(e,t):(this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(e,t):this.sizeWithMaxWidth(e,t):this.assignStartEndPosition(e,t);for(let r=0;r<$a.length;r++)this.propagateProperty(e,t,$a[r],n)}transferContentProps(e,t,i,n){for(let s=0;s<Wa.length;s++)this.propagateProperty(e,t,Wa[s],n);if(this.style["text-overflow"]){let s=t.element.firstElementChild;P(s,"text-overflow","inherit"),P(s,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var r,o;let a=(o=(r=this.cascaded.width)!=null?r:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:o.value;return!!a&&a!==v.auto&&!K(a)},s=()=>{var r,o;let a=(o=(r=this.cascaded.height)!=null?r:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:o.value;return!!a&&a!==v.auto&&!K(a)};for(let r=0;r<ja.length;r++){let o=ja[r];if(o==="width"||o==="height"){if(o==="width"&&!n()||o==="height"&&!s())continue;P(t,o,"100%");continue}this.propagatePropertyToElement(e,t,o,i)}}finishContainer(e,t,i,n,s,r,o){this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let a=(this.vertical||!n)&&this.isAutoHeight,h=(!this.vertical||!n)&&this.isAutoWidth,l=null;if(h||a){h&&P(t.element,"width","auto"),a&&P(t.element,"height","auto");let c=Dh(n);c&&zh(n),l=r.getElementClientRect(n?n.element:t.element),c&&no(n),h&&(this.calculatedWidth=Math.ceil(l.right-l.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),a&&(this.calculatedHeight=l.bottom-l.top-t.paddingTop-t.borderTop-t.paddingBottom-t.borderBottom,this.vertical||(this.calculatedHeight+=t.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(e,t),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),s>1){let c=this.getPropAsNumber(e,"column-rule-width"),p=this.getProp(e,"column-rule-style"),d=this.getProp(e,"column-rule-color");if(c>0&&p&&p!=v.none&&d!=v.transparent){let f=this.getPropAsNumber(e,"column-gap"),m=this.vertical?t.height:t.width,g=this.vertical?"border-top":"border-left";for(let w=1;w<s;w++){let y=this.vertical?(m+f)*w/s-f/2+t.paddingTop-c/2:(m+f)*w/s-f/2+t.paddingLeft-c/2,b=this.vertical?t.width+t.paddingLeft+t.paddingRight:t.height+t.paddingTop+t.paddingBottom,S=t.element.ownerDocument.createElement("div");P(S,"position","absolute"),P(S,this.vertical?"left":"top","0px"),P(S,this.vertical?"top":"left",`${y}px`),P(S,this.vertical?"height":"width","0px"),P(S,this.vertical?"width":"height",`${b}px`),P(S,g,`${c}px ${p.toString()}${d?` ${d.toString()}`:""}`),t.element.insertBefore(S,t.element.firstChild)}}}for(let c=0;c<Ga.length;c++)this.propagateProperty(e,t,Ga[c],o);for(let c=0;c<Xa.length;c++)this.propagateDelayedProperty(e,t,Xa[c],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let r in n)this instanceof Ei&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(r==="writing-mode"||r==="direction")||Si(r)&&ei(i,r,Ue(n,r));if(this.pageBox.pseudoName==So)for(let r in t)(r.match(/^background-/)||r=="writing-mode")&&(i[r]=t[r]);if(this.pageBox.pseudoName=="layout-host")for(let r in t)!r.match(/^background-/)&&r!="writing-mode"&&(i[r]=t[r]);e.pushRule(this.pageBox.classes,null,i);let s=i.content;s&&(i.content=s.filterValue(new Nr(e,null,e.counterResolver))),this.init(e.context);for(let r of this.pageBox.children)r.createInstance(this).applyCascadeAndInit(e,t);e.popRule()}resolveAutoSizing(e){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,e)||this.depends("margin-right",this.autoWidth,e)||this.depends("border-right-width",this.autoWidth,e)||this.depends("padding-right",this.autoWidth,e)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,e)||this.depends("margin-top",this.autoHeight,e)||this.depends("border-top-width",this.autoHeight,e)||this.depends("padding-top",this.autoHeight,e));for(let t of this.children)t.resolveAutoSizing(e)}},$a=["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"],Ga=["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"],Wa=["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"],ja=["width","height","image-resolution","object-fit","object-position"],Xa=["transform","transform-origin"],So="background-host",Qm=class extends Es{constructor(e){super(null,e)}applyCascadeAndInit(e,t){super.applyCascadeAndInit(e,t),this.children.sort((i,n)=>n.pageBox.specificity-i.pageBox.specificity||i.pageBox.index-n.pageBox.index)}},Co=class extends Es{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=pt(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},ew=class extends Es{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},Ii=class extends Es{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof rt&&(n=[t]),t instanceof Ye&&(n=t.values),n){let s=this.pageBox.scope;for(let r=0;r<n.length;r++)if(n[r]instanceof rt){let o=Ys(n[r].name,"enabled"),a=new Ie(s,o);i&&(a=new Ut(s,a)),e=pt(s,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=Ku(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let s=Km(t,i["flow-from"],"body"),r=new Zi(t,"has-content",[s]);e=pt(t,e,r)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let s=this.pageMasterInstance.style.enabled,r=s?s.toExpr(t,null):t._true;r=pt(t,r,e),this.pageMasterInstance.style.enabled=new D(r)}return e}prepareContainer(e,t,i,n,s){var r;this.pageBox.pageMaster instanceof ic||(P(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(r=this.pageBox.name)!=null?r:"")),super.prepareContainer(e,t,i,n,s)}},Eo=class extends En{constructor(e,t,i,n){super(e,t,!1),this.target=i,this.validatorSet=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}simpleProperty(e,t,i){this.target.specified[e]=new Z(t,i?ch:dh)}},Ju=class extends Eo{constructor(e,t,i,n){super(e,t,i,n)}},tw=class Qu extends Eo{constructor(t,i,n,s){super(t,i,n,s),n.specified.width=new Z(Yo,0),n.specified.height=new Z(Yo,0)}startPartitionRule(t,i,n){let s=new Tn(this.scope,t,i,n,this.target),r=new Ju(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(t,i,n){let s=new qu(this.scope,t,i,n,this.target),r=new Qu(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}},iw=class extends Eo{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new Tn(this.scope,e,t,i,this.target),s=new Ju(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(e,t,i){let n=new qu(this.scope,e,t,i,this.target),s=new tw(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}};function ec(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,s=(i=e.direction)==null?void 0:i.value;return n===v.vertical_lr||n!==v.vertical_rl&&s!==v.rtl?"ltr":"rtl"}var nw={a10:{width:new I(26,"mm"),height:new I(37,"mm")},a9:{width:new I(37,"mm"),height:new I(52,"mm")},a8:{width:new I(52,"mm"),height:new I(74,"mm")},a7:{width:new I(74,"mm"),height:new I(105,"mm")},a6:{width:new I(105,"mm"),height:new I(148,"mm")},a5:{width:new I(148,"mm"),height:new I(210,"mm")},a4:{width:new I(210,"mm"),height:new I(297,"mm")},a3:{width:new I(297,"mm"),height:new I(420,"mm")},a2:{width:new I(420,"mm"),height:new I(594,"mm")},a1:{width:new I(594,"mm"),height:new I(841,"mm")},a0:{width:new I(841,"mm"),height:new I(1189,"mm")},b10:{width:new I(31,"mm"),height:new I(44,"mm")},b9:{width:new I(44,"mm"),height:new I(62,"mm")},b8:{width:new I(62,"mm"),height:new I(88,"mm")},b7:{width:new I(88,"mm"),height:new I(125,"mm")},b6:{width:new I(125,"mm"),height:new I(176,"mm")},b5:{width:new I(176,"mm"),height:new I(250,"mm")},b4:{width:new I(250,"mm"),height:new I(353,"mm")},b3:{width:new I(353,"mm"),height:new I(500,"mm")},b2:{width:new I(500,"mm"),height:new I(707,"mm")},b1:{width:new I(707,"mm"),height:new I(1e3,"mm")},b0:{width:new I(1e3,"mm"),height:new I(1414,"mm")},c10:{width:new I(28,"mm"),height:new I(40,"mm")},c9:{width:new I(40,"mm"),height:new I(57,"mm")},c8:{width:new I(57,"mm"),height:new I(81,"mm")},c7:{width:new I(81,"mm"),height:new I(114,"mm")},c6:{width:new I(114,"mm"),height:new I(162,"mm")},c5:{width:new I(162,"mm"),height:new I(229,"mm")},c4:{width:new I(229,"mm"),height:new I(324,"mm")},c3:{width:new I(324,"mm"),height:new I(458,"mm")},c2:{width:new I(458,"mm"),height:new I(648,"mm")},c1:{width:new I(648,"mm"),height:new I(917,"mm")},c0:{width:new I(917,"mm"),height:new I(1297,"mm")},"jis-b10":{width:new I(32,"mm"),height:new I(45,"mm")},"jis-b9":{width:new I(45,"mm"),height:new I(64,"mm")},"jis-b8":{width:new I(64,"mm"),height:new I(91,"mm")},"jis-b7":{width:new I(91,"mm"),height:new I(128,"mm")},"jis-b6":{width:new I(128,"mm"),height:new I(182,"mm")},"jis-b5":{width:new I(182,"mm"),height:new I(257,"mm")},"jis-b4":{width:new I(257,"mm"),height:new I(364,"mm")},"jis-b3":{width:new I(364,"mm"),height:new I(515,"mm")},"jis-b2":{width:new I(515,"mm"),height:new I(728,"mm")},"jis-b1":{width:new I(728,"mm"),height:new I(1030,"mm")},"jis-b0":{width:new I(1030,"mm"),height:new I(1456,"mm")},letter:{width:new I(8.5,"in"),height:new I(11,"in")},legal:{width:new I(8.5,"in"),height:new I(14,"in")},ledger:{width:new I(11,"in"),height:new I(17,"in")}},sw=new I(.24,"pt"),yb=new I(3,"mm"),rw=new I(10,"mm"),ow=new I(13,"mm");function us(e){let t={width:xn,height:Sn,bleed:ge,bleedOffset:ge,cropOffset:ge},i=e.size;if(!(!i||i.value===v.auto)){let l=i.value,c,p;if(l.isSpaceList()?(c=l.values[0],p=l.values[1]):(c=l,p=null),c.isNumeric())t.width=c,t.height=p||c;else{let d=c.name&&nw[c.name.toLowerCase()];d&&(p&&p===v.landscape?(t.width=d.height,t.height=d.width):(t.width=d.width,t.height=d.height))}}let n=e.marks,s=e.bleed,r=n&&!K(n.value)?n.value:v.none,o=s&&!K(s.value)?s.value:v.auto;if(o===v.auto){if(r!==v.none){let l=!1;r.isSpaceList()?l=r.values.some(c=>c===v.crop):l=r===v.crop,l&&(t.bleed=new I(6,"pt"))}}else o.isNumeric()&&(t.bleed=o);let a=e["crop-offset"],h=a&&!K(a.value)?a.value:v.auto;return h===v.auto?r!==v.none&&(t.bleedOffset=ow):h.isNumeric()&&(t.cropOffset=h),t}function qa(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),s=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),r=n+s,o=e.width;o===xn?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-r*2:i.pageWidth=o.num*t.queryUnitSize(o.unit,!1);let a=e.height;return a===Sn?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-r*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=s,i.cropOffset=r,i}function tc(e,t,i){let n=e.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("width",t),n.setAttribute("height",i),n.style.position="absolute",n}function on(e,t,i,n){n=n||"polyline";let s=e.createElementNS("http://www.w3.org/2000/svg",n);return s.setAttribute("stroke",i===v.auto?"#010101":i.toString()),s.setAttribute("stroke-width",t),s.setAttribute("fill","none"),s}var Or=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(Or||{});function aw(e,t,i,n,s,r,o){let a=s;a<=r+2*pe.mm&&(a=r+s/2);let h=Math.max(s,a),l=r+h+i/2,c=tc(e,l,l),p=[[0,r+s],[s,r+s],[s,r+s-a]],d=p.map(g=>[g[1],g[0]]);(t==="top right"||t==="bottom right")&&(p=p.map(g=>[r+h-g[0],g[1]]),d=d.map(g=>[r+h-g[0],g[1]])),(t==="bottom left"||t==="bottom right")&&(p=p.map(g=>[g[0],r+h-g[1]]),d=d.map(g=>[g[0],r+h-g[1]]));let f=on(e,i,n);f.setAttribute("points",p.map(g=>g.join(",")).join(" ")),c.appendChild(f);let m=on(e,i,n);return m.setAttribute("points",d.map(g=>g.join(",")).join(" ")),c.appendChild(m),t.split(" ").forEach(g=>{c.style[g]=`${o}px`}),c}var mn=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(mn||{});function lw(e,t,i,n,s,r){let o=s*2,a,h;t==="top"||t==="bottom"?(a=o,h=s):(a=s,h=o);let l=tc(e,a,h),c=on(e,i,n);c.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(c);let p=on(e,i,n);p.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(p);let d=on(e,i,n,"circle");d.setAttribute("cx",a/2),d.setAttribute("cy",h/2),d.setAttribute("r",s/4),l.appendChild(d);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(mn).forEach(m=>{let g=mn[m];g===t?l.style[g]=`${r}px`:g!==f&&(l.style[g]="0",l.style[`margin-${g}`]="auto")}),l}function hw(e,t,i,n){let s=!1,r=!1,o=e.marks;if(o){let g=o.value;g instanceof me?g.values.forEach(w=>{w===v.crop?s=!0:w===v.cross&&(r=!0)}):g===v.crop?s=!0:g===v.cross&&(r=!0)}let a=t.bleed;if(!s&&!r)return;let h=i.container,l=h.ownerDocument,c=We(sw,n),p=Math.max(0,t.bleedOffset-We(rw,n)),d=t.bleedOffset-p,f=e["crop-marks-line-color"],m=f&&!K(f.value)?f.value:v.auto;s&&Object.keys(Or).forEach(g=>{let w=Or[g],y=aw(l,w,c,m,d,a,p);h.appendChild(y)}),r&&Object.keys(mn).forEach(g=>{let w=mn[g],y=lw(l,w,c,m,d,p);h.appendChild(y)})}var Br=(()=>{let e=["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 e.forEach(i=>{t[`margin-${i}`]=!0,t[`padding-${i}`]=!0,t[`border-${i}-width`]=!0,t[`border-${i}-style`]=!0,t[`border-${i}-color`]=!0}),t})(),ko={"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"}},uw=(()=>{let e=ko;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),No="vivliostyle-page-rule-master",wn="_marginBoxes",ic=class extends ju{constructor(e,t,i){super(e,null,No,[],t,null,0),u(this,"pageMarginBoxes",{});let n=us(i),s=new cw(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[wn];t&&uw.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new pw(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new Z(v.relative,0),this.specified.width=new Z(t.width,0),this.specified.height=new Z(t.height,0);for(let i in e)!Br[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new Ei(e,this)}},cw=class extends Tn{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let s=new dw(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new Z(v.auto,0),this.specified["z-index"]=new Z(new ni(0),0),this.specified.position=new Z(v.absolute,0),this.specified.overflow=new Z(v.visible,0);for(let t in Br)Br.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new gw(e,this)}},dw=class extends Tn{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new Z(B("body"),0)}createInstance(e){return new nc(e,this)}},pw=class extends Tn{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[wn][this.marginBoxName];for(let i in e){let n=e[i],s=t[i];(Wh[i]||s&&s.value===v.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==G&&n.value!==v.inherit&&n.value!==v.unset&&n.value!==v.revert&&(this.specified[i]=n)}}createInstance(e){return new sc(e,this)}},Ei=class extends Co{constructor(e,t){super(e,t),u(this,"pageAreaDimension",null),u(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,t){let i=this.cascaded;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n))switch(n){case"writing-mode":case"direction":i[n]=t[n]}super.applyCascadeAndInit(e,t)}initHorizontal(){let e=this.style;e.left=ge,e["margin-left"]=ge,e["border-left-width"]=ge,e["padding-left"]=ge,e["padding-right"]=ge,e["border-right-width"]=ge,e["margin-right"]=ge,e.right=ge}initVertical(){let e=this.style;e.top=ge,e["margin-top"]=ge,e["border-top-width"]=ge,e["padding-top"]=ge,e["padding-bottom"]=ge,e["border-bottom-width"]=ge,e["margin-bottom"]=ge,e.bottom=ge}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new D(e.borderBoxWidth),t.height=new D(e.borderBoxHeight),t["padding-left"]=new D(e.marginLeft),t["padding-right"]=new D(e.marginRight),t["padding-top"]=new D(e.marginTop),t["padding-bottom"]=new D(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,s={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},r={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,r,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,s){let r="start",o="center",a="end",h=this.pageBox.scope,l={},c={},p={};for(let S in e){let T=ko[S];if(T){let R=e[S],M=this.pageMarginBoxInstances[S],V=new Xn(R,M.style,t,h,s);l[T.positionAlongVariableDimension]=R,c[T.positionAlongVariableDimension]=M,p[T.positionAlongVariableDimension]=V}}let d={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),m=!1,g={};Object.keys(l).forEach(S=>{let T=S,R=ae(h,c[T].style[t?"max-width":"max-height"],i.extent);if(R){let M=R.evaluate(n);if(f[T]>M){let V=p[T]=new Ya(l[T],c[T].style,t,h,s,M);g[T]=V.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),m=!1,[r,o,a].forEach(S=>{var T;f[S]=(T=g[S])!=null?T:f[S]}));let w={};Object.keys(l).forEach(S=>{let T=S,R=ae(h,c[T].style[t?"min-width":"min-height"],i.extent);if(R){let M=R.evaluate(n);if(f[T]<M){let V=p[T]=new Ya(l[T],c[T].style,t,h,s,M);w[T]=V.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),[r,o,a].forEach(S=>{f[S]=w[S]||f[S]}));let y=d.start+d.extent,b=d.start+(d.start+d.extent);[r,o,a].forEach(S=>{let T=f[S];if(T!=null){let R=l[S],M=0;switch(S){case r:M=t?R.left:R.top;break;case o:M=(b-T)/2;break;case a:M=y-T;break}t?R.setHorizontalPosition(M,T-R.getInsetLeft()-R.getInsetRight()):R.setVerticalPosition(M,T-R.getInsetTop()-R.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,s=e.center,r=e.end,o={};if(s){let a=[n,r],h=new fw(a),l=this.distributeAutoMarginBoxSizes(s,h,t);l.xSize!=null&&(o.center=l.xSize);let c=(i=l.xSize)!=null?i:s.getOuterSize(),p=Math.max((t-c)/2,0);n&&(o.start=n.hasAutoSize()?p:n.getOuterSize()),r&&(o.end=r.hasAutoSize()?p:r.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,r,t);a.xSize!=null&&(o.start=a.xSize),a.ySize!=null&&(o.end=a.ySize)}return o}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e instanceof Xn&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof Xn&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let s=e.getOuterMaxContentSize(),r=t.getOuterMaxContentSize();if(s>0&&r>0){let o=s+r;if(o<i)n.xSize=i*s/o;else{let a=e.getOuterMinContentSize(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(s-a)/(o-l):l>0&&(n.xSize=i*a/l)}n.xSize>0&&(n.ySize=i-n.xSize)}else s>0?n.xSize=i:r>0&&(n.ySize=i)}else e.hasAutoSize()?n.xSize=Math.max(i-t.getOuterSize(),0):t.hasAutoSize()&&(n.ySize=Math.max(i-e.getOuterSize(),0));else e?e.hasAutoSize()&&(n.xSize=i):t&&t.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,s)}},Xn=class{constructor(e,t,i,n,s){this.container=e,this.isHorizontal=i,this.clientLayout=s,u(this,"hasAutoSize_"),u(this,"size",null),u(this,"minMaxFitContent",null);let r=t[i?"width":"height"];if(this.hasAutoSize_=!r||r===v.auto||K(r),this.minMaxFitContent=r instanceof rt&&(r.name==="min-content"||r.name==="max-content"||r.name==="fit-content")?r.name:null,this.minMaxFitContent){let o=this.getSize();if(this.isHorizontal){let a=o[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,a)}else{let a=o[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,a)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let e=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=eo(this.clientLayout,this.container.element,e)}return this.size}getOuterMaxContentSize(){let e=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+e["max-content width"]+this.container.getInsetRight():this.container.getInsetTop()+e["max-content height"]+this.container.getInsetBottom()}getOuterMinContentSize(){let e=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+e["min-content width"]+this.container.getInsetRight():this.container.getInsetTop()+e["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()}},fw=class{constructor(e){this.params=e}hasAutoSize(){return this.params.some(e=>{var t;return(t=e?.hasAutoSize())!=null?t:!1})}getOuterMaxContentSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterMaxContentSize())!=null?i:0});return Math.max.apply(null,e)*e.length}getOuterMinContentSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterMinContentSize())!=null?i:0});return Math.max.apply(null,e)*e.length}getOuterSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterSize())!=null?i:0});return Math.max.apply(null,e)*e.length}},Ya=class extends Xn{constructor(e,t,i,n,s,r){super(e,t,i,n,s),u(this,"fixedSize"),this.fixedSize=r}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()}},gw=class extends Ii{constructor(e,t){super(e,t),u(this,"borderBoxWidth",null),u(this,"borderBoxHeight",null),u(this,"contentBoxWidth",null),u(this,"contentBoxHeight",null),u(this,"marginTop",null),u(this,"marginRight",null),u(this,"marginBottom",null),u(this,"marginLeft",null)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^background-/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,t),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 t=this.style,i=this.pageBox.pageSize,n=this.pageBox.scope,s=e.start,r=e.end,o=e.extent,a=i[o].toExpr(n,null),h=ae(n,t[o],a),l=ae(n,t[`margin-${s}`],a),c=ae(n,t[`margin-${r}`],a),p=st(n,t[`padding-${s}`],a),d=st(n,t[`padding-${r}`],a),f=Ct(n,t[`border-${s}-width`],t[`border-${s}-style`],a),m=Ct(n,t[`border-${r}-width`],t[`border-${r}-style`],a),g=X(n,X(n,f,p),X(n,m,d)),w,y,b;return h?(this.borderBoxSizing?(y=h,b=re(n,y,g)):(b=h,y=X(n,b,g)),w=re(n,a,y),!l&&!c?(l=Un(n,w,new Fe(n,.5)),c=l):l?c=re(n,w,l):l=re(n,w,c)):(l||(l=n.zero),c||(c=n.zero),w=X(n,l,c),y=re(n,a,w),b=re(n,y,g),h=this.borderBoxSizing?y:b),t[s]=new D(l),t[r]=new D(c),t[`margin-${s}`]=ge,t[`margin-${r}`]=ge,t[`border-${s}-width`]=new D(f),t[`border-${r}-width`]=new D(m),t[`padding-${s}`]=new D(p),t[`padding-${r}`]=new D(d),t[o]=new D(h),t[`max-${o}`]=new D(h),{borderBoxExtent:y,contentBoxExtent:b,marginStart:l,marginEnd:c}}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,s),P(t.element,"position","relative"),P(t.element,"inset",""),P(t.element,"display","flow-root")}},nc=class extends Ii{constructor(e,t){super(e,t)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^column.*$/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,{})}initHorizontal(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.left=t["padding-left"],e.width=new D(this.parentInstance.contentBoxWidth),e["margin-left"]=new D(new pi(i,t.left.toExpr(i,null))),e["margin-right"]=new D(new pi(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=v.solid,e["border-right-style"]=v.solid,e["border-left-color"]=v.transparent,e["border-right-color"]=v.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new D(this.parentInstance.contentBoxHeight),e["margin-top"]=new D(new pi(i,t.top.toExpr(i,null))),e["margin-bottom"]=new D(new pi(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=v.solid,e["border-bottom-style"]=v.solid,e["border-top-color"]=v.transparent,e["border-bottom-color"]=v.transparent}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,s),e.pageAreaWidth=parseFloat(i.pageAreaElement.style.width),e.pageAreaHeight=parseFloat(i.pageAreaElement.style.height),P(t.element,"position","relative"),P(t.element,"inset",""),P(t.element,"display","flow-root")}},sc=class extends Ii{constructor(e,t){super(e,t),u(this,"boxInfo"),u(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=ko[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,s)}applyVerticalAlign(e,t){P(t,"display","flex"),P(t,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let i=this.getProp(e,"vertical-align"),n=null;i===B("middle")?n="center":i===B("top")?n="flex-start":i===B("bottom")&&(n="flex-end"),n&&P(t,"justify-content",n);let s=this.getProp(e,"content");if(this.vertical||s instanceof ft||s instanceof D&&s.expr instanceof Te&&s.expr.str.startsWith("running-element-")){let r="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?r=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(r=this.vertical||this.rtl?"end":"start")),P(t,"align-items",r)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,s=e.start,r=e.end,o=e.extent,a=s==="left",h=a?t.borderBoxWidth:t.borderBoxHeight,l=ae(n,i[o],h),c=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[s]=new D(c);else if(l){let p=st(n,i[`margin-${s}`],h),d=st(n,i[`margin-${r}`],h),f=st(n,i[`padding-${s}`],h),m=st(n,i[`padding-${r}`],h),g=Ct(n,i[`border-${s}-width`],i[`border-${s}-style`],h),w=Ct(n,i[`border-${r}-width`],i[`border-${r}-style`],h),y=X(n,l,X(n,this.borderBoxSizing?n.zero:X(n,X(n,f,m),X(n,g,w)),X(n,p,d)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[s]=new D(X(n,c,Qs(n,re(n,h,y),new Fe(n,2))));break;case"end":i[s]=new D(re(n,X(n,c,h),y));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,s=this.borderBoxSizing,r=e.inside,o=e.outside,a=e.extent,h=t[`margin${o.charAt(0).toUpperCase()}${o.substring(1)}`],l=Ha(n,i[`margin-${r}`],h),c=Ha(n,i[`margin-${o}`],h),p=st(n,i[`padding-${r}`],h),d=st(n,i[`padding-${o}`],h),f=Ct(n,i[`border-${r}-width`],i[`border-${r}-style`],h),m=Ct(n,i[`border-${o}-width`],i[`border-${o}-style`],h),g=ae(n,i[a],h),w=null;function y(b){if(w)return w;w={extent:g?g.evaluate(b):null,marginInside:l?l.evaluate(b):null,marginOutside:c?c.evaluate(b):null};let S=h.evaluate(b),T=0;return s||[f,p,d,m].forEach(R=>{R&&(T+=R.evaluate(b))}),(w.marginInside===null||w.marginOutside===null)&&T+w.extent+w.marginInside+w.marginOutside>S&&(w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)),w.extent!==null&&w.marginInside!==null&&w.marginOutside!==null&&(w.marginOutside=null),w.extent===null?(w.extent=S-T-w.marginInside-w.marginOutside,w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)):typeof w.extent=="number"&&(w.marginInside===null&&typeof w.marginOutside=="number"?w.marginInside=S-T-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=S-T-w.extent-w.marginInside:w.marginInside=w.marginOutside=(S-T-w.extent)/2),w}i[a]=new D(new Te(n,function(){let b=y(this).extent;return b===null?"auto":b},a)),i[`margin-${r}`]=new D(new Te(n,function(){let b=y(this).marginInside;return b===null?"auto":b},`margin-${r}`)),i[`margin-${o}`]=new D(new Te(n,function(){let b=y(this).marginOutside;return b===null?"auto":b},`margin-${o}`)),r==="left"?i.left=new D(X(n,t.marginLeft,t.borderBoxWidth)):r==="top"&&(i.top=new D(X(n,t.marginTop,t.borderBoxHeight)))}initHorizontal(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},e):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},e):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},e)}initVertical(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},e):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},e):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},e)}finishContainer(e,t,i,n,s,r,o){super.finishContainer(e,t,i,n,s,r,o);let a=i.marginBoxes,h=this.pageBox.marginBoxName,l=this.boxInfo;!l.isInLeftColumn&&!l.isInRightColumn?l.isInTopRow?a.top[h]=t:l.isInBottomRow&&(a.bottom[h]=t):!l.isInTopRow&&!l.isInBottomRow&&(l.isInLeftColumn?a.left[h]=t:l.isInRightColumn&&(a.right[h]=t));let c=this.parentInstance.pageAreaDimension,p=this.getProp(e,"width"),d=p instanceof rt&&(p.name==="min-content"||p.name==="max-content"||p.name==="fit-content")?p.name:null,f=this.getPropAsNumber(e,"min-width"),m=this.getPropAsNumber(e,"max-width");if(d||f||m){d&&P(t.element,"width",d),f&&P(t.element,"min-width",`${f}px`),m&&P(t.element,"max-width",`${m}px`);let S=this.getProp(e,"margin-left"),T=this.getProp(e,"margin-right");if(l.isInLeftColumn){let R=c.borderBoxWidth.evaluate(e)+c.marginRight.evaluate(e);P(t.element,"right",`${R}px`),(S===v.auto||T!==v.auto)&&P(t.element,"margin-left","auto"),T===v.auto&&P(t.element,"margin-right","auto")}else l.isInRightColumn&&(P(t.element,"right","0"),(T===v.auto||S!==v.auto)&&P(t.element,"margin-right","auto"),S===v.auto&&P(t.element,"margin-left","auto"))}let g=this.getProp(e,"height"),w=g instanceof rt&&(g.name==="min-content"||g.name==="max-content"||g.name==="fit-content")?g.name:null,y=this.getPropAsNumber(e,"min-height"),b=this.getPropAsNumber(e,"max-height");if(w||y||b){w&&P(t.element,"height",w),y&&P(t.element,"min-height",`${y}px`),b&&P(t.element,"max-height",`${b}px`);let S=this.getProp(e,"margin-top"),T=this.getProp(e,"margin-bottom");if(l.isInTopRow){let R=c.borderBoxHeight.evaluate(e)+c.marginBottom.evaluate(e);P(t.element,"bottom",`${R}px`),(S===v.auto||T!==v.auto)&&P(t.element,"margin-top","auto"),T===v.auto&&P(t.element,"margin-bottom","auto")}else l.isInBottomRow&&(P(t.element,"bottom","0"),(T===v.auto||S!==v.auto)&&P(t.element,"margin-bottom","auto"),S===v.auto&&P(t.element,"margin-top","auto"))}}},mw=class{constructor(e,t,i,n,s){this.cascadeInstance=e,this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=s,u(this,"pageMasterCache",{}),this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new Ie(e,"page-number"),s=new Xr(e,new Ol(e,n,new Fe(e,2)),i?e.one:e.zero);e.defineName("recto-page",new Ut(e,s)),e.defineName("verso-page",s),(t.pageProgression||ec(this.docElementStyle))==="ltr"?(e.defineName("left-page",s),e.defineName("right-page",new Ut(e,s))):(e.defineName("left-page",new Ut(e,s)),e.defineName("right-page",s))}getCascadedPageStyle(e){let t={};return this.cascadeInstance.pushRule([],e,t),this.cascadeInstance.popRule(),t}getPageRulePageMaster(e,t){let i=e.pageBox;if(Object.keys(t).length===0)return i.resetScope(),e;let n=this.makeCacheKey(t,i),s=this.pageMasterCache[n];return s||(i.pseudoName===So?s=this.generatePageRuleMaster(t):s=this.generateCascadedPageMaster(t,i),this.pageMasterCache[n]=s),s.pageBox.resetScope(),s}makeCacheKey(e,t){var i;let n=this.makeCascadeValueObjectKey(e),s=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${t.key}^${n}^${s}`}makeCascadeValueObjectKey(e){let t=[];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],s;n instanceof Z?s=`${n.value}`:s=this.makeCascadeValueObjectKey(n),t.push(i+s+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new ic(this.pageScope,this.rootPageBoxInstance.pageBox,e).createInstance(this.rootPageBoxInstance);return t.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),t.resolveAutoSizing(this.context),t}generateCascadedPageMaster(e,t){let i=t.clone({pseudoName:No}),n=i.specified,s=e.size;if(s&&!K(s.value)){let o=us(e),a=s.priority;Lt(n,"width",new Z(o.width,a),this.context),Lt(n,"height",new Z(o.height,a),this.context)}["counter-reset","counter-increment"].forEach(o=>{n[o]&&(e[o]=n[o])});let r=i.createInstance(this.rootPageBoxInstance);return r.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),r.resolveAutoSizing(this.context),r}},ww=class extends de{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}},bw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ie(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},vw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ie(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},yw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ie(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},xw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ie(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Sw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ie(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Cw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ie(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Ew=class extends Pn{constructor(e,t,i){super(t,i),this.scope=e,this.a=t,this.b=i}apply(e){let t=e.context,i=t.layoutPositionAtPageStart.page;t.blankPageAtStart&&i--,i&&this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 2}},kw=class extends uo{constructor(e,t){super(e,t,null,null,null)}apply(e){Nw(e.context,e.currentStyle,this.style,this.specificity,e)}};function Nw(e,t,i,n,s){os(e,t,i,n,null,null,null);let r=i[wn];if(r){let o=ys(t,wn);for(let a in r)if(r.hasOwnProperty(a)){let h=o[a];h||(h={},o[a]=h),os(e,h,r[a],n,null,null,null)}}}var Pw=class extends cn{constructor(e,t,i,n,s){super(e,t,i?.condition,i,null,n,!1),this.pageProps=s,u(this,"currentPageSelectors",[]),u(this,"currentNamedPageSelector",""),u(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new ww(t)),this.specificity+=65536)}pseudoclassSelector(e,t){if(e=e.toLowerCase(),t)switch(e){case"nth":{let[i,n]=t;this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new Ew(this.scope,i,n)),this.specificity+=256}break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}(${t.join("")})`);break}else switch(this.currentPseudoPageClassSelectors.push(`:${e}`),e){case"first":this.chain.push(new bw(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new vw(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new yw(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new xw(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new Sw(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Cw(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,t,i){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(r=>r.selectors===null))return;super.simpleProperty(e,t,i);let n=Ue(this.elementStyle,e),s=this.pageProps;if(e==="bleed"||e==="marks")s[""]||(s[""]={}),Object.keys(s).forEach(r=>{ei(s[r],e,n)});else if(e==="size"){let r=s[""];this.currentPageSelectors.forEach(o=>{let a=new Z(n.value,n.priority+o.specificity),h=o.selectors?o.selectors.join(""):"",l=s[h];l?Lt(l,e,a):(l=s[h]={},ei(l,e,a),r&&["bleed","marks"].forEach(c=>{r[c]&&ei(l,c,r[c])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new kw(this.elementStyle,e)}startPageMarginBoxRule(e){let t=ys(this.elementStyle,wn),i=t[e];i||(i={},t[e]=i);let n=new Tw(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},Tw=class extends En{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.boxStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),s=new Z(t,n);ei(this.boxStyle,e,s)}},Ft=!0;function Iw(e){Ft=e}var ti=[];function Za(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function rc(e){let t=Array.from(e.querySelectorAll("body > :not(script):not(link):not(style) ~ script"));return Array.from(e.querySelectorAll("head > script, body > script")).filter(i=>!t.includes(i))}function Po(e,t,i){var n,s;if(!Ft||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&rc(e.ownerDocument).includes(e))return N(!1);let r=e.textContent,o=e.src,a=e.type==="module",h=(a||o)&&e.async,l=a&&!h||o&&e.defer,c=!(i!=null&&i.atEnd)&&(i?.forceDefer||l||h);if(oc(t)||(t.onload=null),c)return ti.some(d=>Za(d,e))||ti.push(e),N(!0);if(o.includes("/mathjax")){let d=t.document.head.querySelector("script[src*='MathJax.js']:not([data-vivliostyle-scripting])");if(d){if(o.includes("/mathjax@3"))t.document.head.removeChild(d),(s=(n=t.MathJax)==null?void 0:n.version)!=null&&s.startsWith("2.")&&delete t.MathJax;else if(o.includes("/MathJax.js"))return N(!0)}}for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&Za(d,e)&&t.document.head.removeChild(d);let p=t.document.createElement("script");p.textContent=r,o&&(p.src=o),p.async=h,p.defer=l,p.setAttribute("data-vivliostyle-scripting","true");for(let d of e.attributes)["src","async","defer"].includes(d.name)||p.setAttribute(d.name,d.value);if(H.debug("script:",o),o){let d=hi(p);return t.document.head.appendChild(p),ws([d])}else return t.document.head.appendChild(p),N(!0)}function Rw(e,t){var i;let n={},s=o=>{var a;let h=(a=o["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let c of h.values)n[c.stringValue()]=!0;else n[h.stringValue()]=!0;let l=o._marginBoxes;if(l)for(let c of Object.values(l))s(c)},r=o=>{if(o instanceof uo)s(o.style);else if(o instanceof Bi||Array.isArray(o))for(let a of Object.values(o))r(a)};for(let o of Object.values(t.cascade.code))for(let a of Object.values(o??{}))r(a);for(let o of e.querySelectorAll("[style]"))(i=o.style)!=null&&i.fontFamily&&(n[o.style.fontFamily]=!0);return Object.keys(n).join(",")}function Aw(e,t,i){var n;let s=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return s.style.position="fixed",s.style.fontSize="0",s.setAttribute("data-vivliostyle-textcontent","true"),s.setAttribute("aria-hidden","true"),s.style.fontFamily=Rw(e,i),s.textContent=e.documentElement.textContent,t.document.body.appendChild(s),s}function Lw(e,t,i){if(!Ft)return N(!1);let n=rc(e);if(n.length===0)return N(!1);let s=n.some(c=>!(c.async||c.defer||c.type==="module")),r=s?Aw(e,t,i):null,o=t.document.fonts,a=t.$,h=!1,l=F("loadScripts");return l.loop(()=>{if(n.length===0)return s?l.sleep(20).thenAsync(()=>{var p,d;return o.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(p=t.FontJSON)!=null&&p.Font&&(d=t.ret)!=null&&d.readyState&&t.ret.readyState<4?N(!0):N(!1)}):N(!1);let c=n.shift();return Po(c,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(ti.push(c),h=!0),n.length===0&&s&&(H.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),N(!0)))}).then(()=>{r&&r.remove(),l.finish(!0)}),l.result()}function Fw(e){if(!Ft)return N(!1);let t=F("loadScripts");return t.loop(()=>ti.length===0?N(!1):Po(ti.shift(),e,{atEnd:!0}).thenReturn(ti.length>0)).then(()=>{H.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),H.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function oc(e){return Ft?ti.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var Ow=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,s)=>`url("${i.transformURL(s,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,s)=>`url('${i.transformURL(s,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,s)=>`url(${i.transformURL(s,t)}`),Bw={};function _w(e){e.addEventListener("load",()=>{e.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(t,i){switch(t){case"mouse-events":return!0}return!1}}},!1)}var ac=class _r extends $r{constructor(t,i,n,s,r,o,a,h,l,c,p,d,f){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=s,this.regionIds=r,this.xmldoc=o,this.docFaces=a,this.footnoteStyle=h,this.stylerProducer=l,this.page=c,this.customRenderer=p,this.fallbackMap=d,this.documentURLTransformer=f,u(this,"document"),u(this,"exprContentListener"),u(this,"nodeContext",null),u(this,"viewRoot",null),u(this,"isFootnote",!1),u(this,"sourceNode",null),u(this,"offsetInNode",0),u(this,"viewNode",null),this.document=n.document,this.exprContentListener=s.counterListener.getExprContentListener()}clone(){return new _r(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(t,i,n,s,r,o,a,h){let l=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(!l)return h;let c=[],p=$n.createElementNS("http://www.pyroxy.com/ns/shadow","root"),d=p;for(let m of Fg){let g;if(m){if(!l[m]||m=="footnote-marker"&&!(i&&this.isFootnote))continue;if(m.match(/^first-/)){let w=s.display;if(!w||w===v.inline)continue;let y=t.firstElementChild;if(y&&ze(y.previousSibling)){let b=r.getStyle(y,!1);if(b){let S=Ue(b,"display");if(S!=null&&S.value&&S.value!==v.inline)continue}}}if(m==="before"||m==="after"){let w=l[m].content;if(!w||!jt(w.value))continue}c.push(m),g=$n.createElementNS("http://www.w3.org/1999/xhtml","span"),Ir(g,m)}else g=$n.createElementNS("http://www.pyroxy.com/ns/shadow","content");d.appendChild(g),m.match(/^first-/)&&(d=g)}if(!c.length)return h;let f=new La(t,n,r,o,this.exprContentListener);return new hr(t,p,null,a,h,ut.ROOTLESS,f)}getPseudoMap(t,i,n,s,r){let o=bt(t,"_pseudos");if(!o)return null;let a={};for(let h in o){let l=a[h]={};sn(l,o[h],r),Tr(l,r,o[h]),du(o[h],i,n,(c,p)=>{sn(l,p,r),lu(p,d=>{sn(l,d,r)})})}return a}createRefShadow(t,i,n,s,r){let o=F("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let h=a;if(h){let l=h.getElement(t);if(l){let c=this.stylerProducer.getStylerForDoc(h);r=new hr(n,l,h,s,r,i,c)}}o.finish(r)}),o.result()}createShadows(t,i,n,s,r,o,a){let h=F("createShadows"),l=null,c=s.template,p;if(c instanceof ft||c===v.footnote){let d=c instanceof ft?c.url:Ce("user-agent.xml#footnote",ii);p=this.createRefShadow(d,ut.ROOTLESS,t,a,l)}else p=N(l);return p.then(d=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let g=t.getAttribute("href"),w=null;g?w=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?g=a.owner.getAttribute("href"):g=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),w=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),g&&(g=Ce(g,w.url),f=this.createRefShadow(g,ut.ROOTED,t,a,d))}f==null&&(f=N(d));let m=null;f.then(g=>{if(s.display===v.table_cell){let w=Ce("user-agent.xml#table-cell",ii);m=this.createRefShadow(w,ut.ROOTLESS,t,a,g)}else m=N(g);m.then(w=>{w=this.createPseudoelementShadow(t,i,n,s,r,o,a,w),h.finish(w)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,s){var r;let o=this.context,a=cu(n,o,this.regionIds,this.isFootnote,this.nodeContext),h=!((r=this.nodeContext)!=null&&r.parent);h&&(!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 l=t;t=hu(a,o,t);let c=!h&&t!==l;i=uu(a,o,i);let p=(y,b)=>{let S;c&&(t?/^(min-|max-)?(height|inline-size)$/.test(y)&&(S=o.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(y)&&(S=o.pageAreaWidth));let T=b.evaluate(o,y,S,t);return y=="font-family"&&(T=this.docFaces.filterFontFamily(T)),T},d=!!new Ie(o.style.pageScope,"left-page").evaluate(o);if(pu(a,s,t,i,d,p),c){let y=s[t?"height":"width"];(!y||y===v.auto)&&(s[t?"height":"width"]=v.max_content)}if(dr(s.position))return s.position=v.fixed,s.visibility=v.hidden,t;let f=s.position,m=s.float,g=s.display||(this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?v.inline:void 0),w=Bh(g,f,m,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(y=>{w[y]&&(s[y]=w[y])}),t}inheritFromSourceParent(t){let i=this.nodeContext.sourceNode,n=[],s=null,r=this.nodeContext.shadowContext,o=-1;for(;i&&i.nodeType==1;){let p=r&&r.root==i;if(!p||r.type==ut.ROOTLESS){let d=(r?r.styler:this.styler).getStyle(i,!1);n.push(d),s=s||Xs(i)}p?(i=r.owner,r=r.parentShadow):(i=i.parentNode,o++)}let a=o===0,h=this.context.queryUnitSize("em",a),l={"font-size":new Z(new I(h,"px"),0)},c=new Mf(l,this.context);for(let p=n.length-1;p>=0;--p){let d=n[p],f=[];for(let w in d)tn(w)&&f.push(w);f.sort(Ko);let m,g;for(let w of f){c.setPropName(w);let y=Ue(d,w),b=y;K(y.value)||(w==="font-size"&&p===n.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize?b=new Z(new I(this.context.rootFontSize,"px"),y.priority):w==="line-height"&&p===n.length-1&&this.context.rootLineHeight&&y.value instanceof I&&(y.value.unit==="lh"||y.value.unit==="rlh")?b=new Z(new I(this.context.rootLineHeight,"px"),y.priority):p===0&&y.value instanceof I&&y.value.unit==="lh"?b=new Z(new I(y.value.num*this.getLineHeightUnitSize(w,m,g),"px"),y.priority):Rt(w)||(b=y.filterValue(c)),w==="font-size"?m=b.value:w==="line-height"&&(g=b.value),l[w]=b)}}for(let p in t)tn(p)||(l[p]=t[p]);return{lang:s,elementStyle:l}}resolveURL(t){return t=Ce(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=Xs(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=Tf().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let s in this.nodeContext.parent.inheritedProps)n[s]=this.nodeContext.parent.inheritedProps[s]}i.forEach(s=>{let r=t[s];if(r){if(K(r))r===v.initial&&(n[s]=void 0);else if(r instanceof ni)n[s]=r.num;else if(r instanceof rt)n[s]=r.name;else if(r instanceof I){let o=r;switch(o.unit){case"dpi":case"dpcm":case"dppx":n[s]=o.num*pe[o.unit];break;default:n[s]=r}}else n[s]=r;["widows","orphans"].includes(s)||delete t[s]}})}}resolveFormattingContext(t,i,n,s,r,o){let a=vt("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,s,r,o);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,s,r,o;let a=!0,h=F("createElementView"),l=this.sourceNode,c=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,p=c.getStyle(l,!1);if(!this.nodeContext.shadowContext){let T=this.xmldoc.getElementOffset(l);vs.registerFragmentIndex(T,this.nodeContext.fragmentIndex,0)}let d={};if(!this.nodeContext.parent){let T=this.inheritFromSourceParent(p);p=T.elementStyle,this.nodeContext.lang=T.lang}let f=p.position,m=p.float,g=p["float-reference"],w=m&&!K(m.value)&&m.value!==v.none&&g&&!K(g.value)?lf(g.value.toString()):null;if(this.nodeContext.parent&&(dr(f?.value)||w&&yi(w))){let T=this.inheritFromSourceParent(p);p=T.elementStyle,this.nodeContext.lang=T.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",p,d),w&&yi(w)&&d.display===v.block&&(d.display=v.flow_root),c.processContent(l,d,(s=this.nodeContext.viewNode)!=null?s:(n=this.nodeContext.parent)==null?void 0:n.viewNode),this.transferPolyfilledInheritedProps(d),this.inheritLangAttribute(),d.direction&&(this.nodeContext.direction=d.direction.toString());let y=d["flow-into"];if(y&&y.toString()!=this.flowName)return h.finish(!1),h.result();if(Ft&&l.localName==="script"&&l.namespaceURI==="http://www.w3.org/1999/xhtml")return Po(l,this.viewport.window).thenFinish(h),h.result();let b=d.display;if(K(b)&&(b===v.initial||b===v.unset?b=v.inline:b===v.inherit?b=((r=this.nodeContext.parent)==null?void 0:r.display)&&B((o=this.nodeContext.parent)==null?void 0:o.display):b=null),b===v.none)return h.finish(!1),h.result();let S=this.nodeContext.parent==null;return this.nodeContext.flexContainer=b===v.flex,this.createShadows(l,S,p,d,c,this.context,this.nodeContext.shadowContext).then(T=>{var R,M;this.nodeContext.nodeShadow=T;let V=d.position,W=d.float,j=d.clear,Be=this.nodeContext.vertical?v.vertical_rl:v.horizontal_tb,Je=this.nodeContext.parent?this.nodeContext.parent.vertical?v.vertical_rl:v.horizontal_tb:Be,De=gf(l),C=d["column-count"],L=d["column-width"],x=C&&C!==v.auto&&!K(C)||L&&L!==v.auto&&!K(L);this.nodeContext.establishesBFC=wf(b,V,W,d.overflow,Be,Je,x||De),this.nodeContext.containingBlockForAbsolute=bf(V),this.nodeContext.isInsideBFC()&&W!==v.footnote&&!(w&&yi(w))&&(W=null,j=null);let k=W instanceof me||W===v.left||W===v.right||W===v.top||W===v.bottom||W===v.inline_start||W===v.inline_end||W===v.block_start||W===v.block_end||W===v.snap_block||W===v.snap_inline||W===v.inside||W===v.outside||W===v.footnote;W&&(delete d.float,W===v.footnote&&(this.isFootnote?(k=!1,d.display=v.block):d.display=v.inline)),j&&(j===v.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(j=B(this.nodeContext.parent.clearSide)),(j===v.left||j===v.right||j===v.top||j===v.bottom||j===v.inline_start||j===v.inline_end||j===v.block_start||j===v.block_end||j===v.inside||j===v.outside||j===v.both||j===v.all||j===v.same||j===v.column||j===v.region||j===v.page)&&(delete d.clear,d.display&&d.display!=v.inline&&(this.nodeContext.clearSide=j.toString())));let E=b===v.list_item&&d["ua-list-item-count"],A=d["break-inside"];(k||A&&!K(A)&&A!==v.auto)&&this.nodeContext.breakPenalty++,b&&b!==v.inline&&zt(b)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!k&&!b||zt(b)||Mh(b),this.nodeContext.display=b?b.toString():"inline",this.nodeContext.floatSide=k?W.toString():null,this.nodeContext.floatReference=w||Se.INLINE;let O=d["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=O&&!K(O)?O:null;let _=this.isInsideNonRootMultiColumn(),U=d["column-span"];if(this.nodeContext.columnSpan=!_&&U&&!K(U)?U:null,!this.nodeContext.inline){let z=d["break-after"];z&&!K(z)&&!(_&&z===v.column)&&(this.nodeContext.breakAfter=z.toString(),or[this.nodeContext.breakAfter]&&(d["break-after"]=v.column));let Qe=d["break-before"];Qe&&!K(Qe)&&!(_&&Qe===v.column)&&(this.nodeContext.breakBefore=Qe.toString(),or[this.nodeContext.breakBefore]&&(d["break-before"]=v.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let ht=d.page,et=ht&&!K(ht)&&ht.toString();!et&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||b===v.table_header_group||b===v.table_footer_group)&&(et=this.styler.cascade.currentPageType),!et||et.toLowerCase()==="auto"?et=this.nodeContext.pageType:this.nodeContext.pageType=et,this.styler.cascade.currentPageType!==et&&!(!et&&d.position===v.fixed)&&(this.nodeContext.fragmentIndex===1&&!un(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),et!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=et)}this.nodeContext.verticalAlign=d["vertical-align"]&&d["vertical-align"].toString()||"baseline",this.nodeContext.captionSide=d["caption-side"]&&d["caption-side"].toString()||"top";let q=d["border-collapse"];if(!q||q===B("separate")){let z=d["border-spacing"],Qe,ht;z&&(z instanceof me?(Qe=z.values[0],ht=z.values[1]):Qe=ht=z,Qe.isNumeric()&&(this.nodeContext.inlineBorderSpacing=We(Qe,this.context)),ht.isNumeric()&&(this.nodeContext.blockBorderSpacing=We(ht,this.context)))}let J=d["footnote-policy"];this.nodeContext.footnotePolicy=J&&!K(J)?J:null;let Y=d["x-first-pseudo"];if(Y){let z=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new sf(z,Y.num)}this.nodeContext.inline||this.processAfterIfcontinues(l,p,c,this.context);let he=d["white-space"];if(he){let z=Eh(he.toString());z!==null&&(this.nodeContext.whitespace=z)}let te=d["hyphenate-character"];te&&te instanceof Ae&&(this.nodeContext.hyphenateCharacter=te.str);let fe=d["word-break"],Ee=d["line-break"],we=d["overflow-wrap"];(fe===v.break_all||Ee===v.anywhere||we===v.break_word||we===v.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,b,V,W,S),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(t=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,t)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(d),this.findAndProcessRepeatingElements(l,c));let Q=!1,oe=null,se=[],ee=l.namespaceURI,$=l.localName,ue=$;if(ee=="http://www.w3.org/1999/xhtml"?($=="html"||$=="body"||$=="script"||$=="link"||$=="meta"?$="div":$=="vide_"?$="video":$=="audi_"?$="audio":$=="object"&&(Q=!!this.customRenderer),l.getAttribute(go)&&(M=(R=p.content)==null?void 0:R.value)!=null&&M.url&&($="img")):ee=="http://www.idpf.org/2007/ops"?($="span",ee="http://www.w3.org/1999/xhtml"):ee=="http://www.pyroxy.com/ns/shadow"?(ee="http://www.w3.org/1999/xhtml",$=this.nodeContext.inline?"span":"div"):Q=!!this.customRenderer,E)t?$="li":($="div",b=v.block,d.display=b);else if($=="body"||$=="li")$="div";else if($=="q")$="span";else if($=="a"){let z=d["hyperlink-processing"];z&&z.toString()!="normal"&&($="span")}d.behavior&&d.behavior.toString()!="none"&&this.customRenderer&&(Q=!0),l.dataset&&l.getAttribute("data-math-typeset")==="true"&&(Q=!0);let He;if(Q){let z=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;He=this.customRenderer(l,z,d)}else He=N(null);He.then(z=>{if(z)Q&&(a=z.getAttribute("data-adapt-process-children")=="true");else if(d.display===v.none){h.finish(!1);return}else z=this.createElement(ee,$);!S&&x&&d["column-fill"]===v.auto&&(z.setAttribute("data-vivliostyle-column-fill","auto"),d["column-fill"]=v.balance),$!=ue&&(z.setAttribute("data-vivliostyle-original-tag",ue),(ue==="html"||ue==="body")&&(z.role="presentation")),$=="a"&&z.addEventListener("click",this.page.hrefHandler,!1),oe&&(this.applyPseudoelementStyle(this.nodeContext,"inner",oe),z.appendChild(oe)),z.localName=="iframe"&&z.namespaceURI=="http://www.w3.org/1999/xhtml"&&_w(z);let Qe=this.nodeContext.inheritedProps["image-resolution"],ht=[],et=d.width,ks=d.height,yc=l.getAttribute("width"),xc=l.getAttribute("height"),Ns=et===v.auto||!et&&!yc,Ps=ks===v.auto||!ks&&!xc,Ro=l.attributes,Sc=Ro.length,In=null,Ao=null;for(let Ze=0;Ze<Sc;Ze++){let xt=Ro[Ze],tt=xt.namespaceURI,ne=xt.localName,Re=xt.nodeValue;if(tt){if(tt=="http://www.w3.org/2000/xmlns/")continue;tt=="http://www.w3.org/1999/xlink"&&ne=="href"&&(Re=this.documentURLTransformer.transformURL(this.resolveURL(Re),this.xmldoc.url))}else{if(!Ft&&ne.match(/^on/)||ne=="style")continue;if((ne=="id"||ne=="name")&&t){let Ve=this.documentURLTransformer.transformFragment(Re,this.xmldoc.url);z.setAttribute(ne,Re),z.setAttribute("data-vivliostyle-id",Ve);let ri=z.ownerDocument.createElement("a");ri.setAttribute(ne,Ve),ri.setAttribute(Pi,"1"),z.appendChild(ri),this.page.registerElementWithId(z,Ve);continue}if(ne=="src"||ne=="href"||ne=="poster")Re=this.resolveURL(Re),ne==="href"&&(Re=this.documentURLTransformer.transformURL(Re,this.xmldoc.url));else if(ne=="srcset")Re=Re.split(",").map(Ve=>this.resolveURL(Ve.trim())).join(",");else if(ne==="data"&&Q&&$==="object"&&z.hasAttribute("data"))continue;if(ne==="poster"&&$==="video"&&ee==="http://www.w3.org/1999/xhtml"&&Ns&&Ps){let Ve=new Image,ri=hi(Ve,Re);se.push(ri),ht.push({image:Ve,element:z,fetcher:ri})}}if(ee=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ne)&&(ne=ne.toLowerCase()),this.isSVGUrlAttribute(ne)&&(Re=Ow(Re,this.xmldoc.url,this.documentURLTransformer)),tt){let Ve=Bw[tt];Ve&&(ne=`${Ve}:${ne}`)}if(ne=="src"&&!tt&&($=="img"||$=="input")&&ee=="http://www.w3.org/1999/xhtml")In=Re;else if(ne=="alt"&&!tt&&$=="img"&&ee=="http://www.w3.org/1999/xhtml")Ao=Re;else if(ne=="href"&&$=="image"&&ee=="http://www.w3.org/2000/svg"&&tt=="http://www.w3.org/1999/xlink")this.page.fetchers.push(hi(z,Re));else if(tt)z.setAttributeNS(tt,ne,Re);else try{z.setAttribute(ne,Re)}catch(Ve){H.warn(Ve)}}if(In){let Ze=$==="input"?new Image:z,xt=hi(Ze,In,Ao);Ze!==z&&(z.src=In);let tt=()=>{var ne,Re;if(d.position===v.fixed)return!0;for(let Ve=(ne=this.nodeContext.parent)==null?void 0:ne.viewNode;Ve&&Ve!==this.viewRoot;Ve=Ve.parentElement)if(((Re=Ve.style)==null?void 0:Re.position)==="fixed")return!0;return!1};!Ns&&!Ps&&!(()=>{let ne=this.nodeContext.vertical?et:ks;return ne instanceof I&&ne.unit==="%"})()&&!tt()?this.page.fetchers.push(xt):(Ns&&Ps&&Qe&&Qe!==1&&ht.push({image:Ze,element:z,fetcher:xt}),se.push(xt))}delete d.content;let Ts=d["list-style-image"];if(Ts&&Ts instanceof ft){let Ze=Ts.url;se.push(hi(new Image,Ze))}if(this.preprocessElementStyle(d),this.applyComputedStyles(z,d),this.nodeContext.inline)t||(ot(z,"inline-start"),Hi(z)&&ot(z,"clone"));else if(t){if(!io(d.position)){let Ze=d["margin-break"],xt=this.getBreakTypeAt(this.nodeContext),tt=xt!==null,ne=xt==="auto";(Ze===v.discard&&tt||Ze!==v.keep&&ne&&!this.nodeContext.floatSide)&&Vs(z,"block-start")}}else{let Ze=this.nodeContext.vertical?"width":"height";_t(z,Ze)&&P(z,Ze,this.nodeContext.display==="table-row"?"0.01px":""),ot(z,"block-start"),Hi(z)&&ot(z,"clone"),Vs(z,"block-start")}E&&z.setAttribute("value",d["ua-list-item-count"].stringValue()),this.viewNode=z,se.length?ws(se).then(()=>{Qe>0&&this.modifyElemDimensionWithImageResolution(ht,Qe,d,this.nodeContext.vertical),h.finish(a)}):h.timeSlice().then(()=>{h.finish(a)})})}),h.result()}isInsideNonRootMultiColumn(){var t;let i=(t=this.nodeContext.parent)==null?void 0:t.viewNode;return!!(i&&Uh(i))}getBreakTypeAt(t){var i,n,s,r,o;if(this.isInsideTable(t))return null;for(let h=t;h&&!h.after;h=h.parent){if(Xe(h.breakBefore))return h.breakBefore;if(h.fragmentIndex===1&&!h.parent)return h.sourceNode===h.sourceNode.ownerDocument.documentElement?"page":null;if((i=h.parent)!=null&&i.floatSide)return null;let l=(n=h.parent)==null?void 0:n.viewNode;if(l){let c=this.viewport.window.getComputedStyle(l),p=parseFloat(c.paddingBlockStart),d=parseFloat(c.borderBlockStartWidth);if(p||d)return null;let f=l?.firstChild;for(;f&&(ze(f,h.parent.whitespace)||!h.floatSide&&ji(f));)f=f.nextSibling;if(f&&f!==h.viewNode)return null}}let a=(o=(r=(s=this.context)==null?void 0:s.currentLayoutPosition)==null?void 0:r.flowPositions[this.flowName])==null?void 0:o.startBreakType;return Xe(a)?a:"auto"}isInsideTable(t){for(let i=t;i&&!i.after;i=i.parent)if(i.display&&i.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(t,i,n,s){let r=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,s);if(r&&r["after-if-continues"]&&r["after-if-continues"].content){let o=new La(t,i,n,s,this.exprContentListener);this.nodeContext.afterIfContinues=new Bg(t,o)}}isSVGUrlAttribute(t){return _r.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,s){t.forEach(r=>{if(r.fetcher.get().get()==="load"){let o=r.image,a=o.width/i,h=o.height/i,l=r.element;if(a>0&&h>0){if(n["box-sizing"]===v.border_box&&(n["border-left-style"]!==v.none&&(a+=We(n["border-left-width"],this.context)),n["border-right-style"]!==v.none&&(a+=We(n["border-right-width"],this.context)),n["border-top-style"]!==v.none&&(h+=We(n["border-top-width"],this.context)),n["border-bottom-style"]!==v.none&&(h+=We(n["border-bottom-width"],this.context))),i>1){let c=n["max-width"]||v.none,p=n["max-height"]||v.none;if(c===v.none&&p===v.none)P(l,"max-width",`${a}px`);else if(c!==v.none&&p===v.none)P(l,"width",`${a}px`);else if(c===v.none&&p!==v.none)P(l,"height",`${h}px`);else{c.isNumeric(),p.isNumeric();let d=c,f=p;d.unit!=="%"?P(l,"max-width",`${Math.min(a,We(d,this.context))}px`):f.unit!=="%"?P(l,"max-height",`${Math.min(h,We(f,this.context))}px`):s?P(l,"height",`${h}px`):P(l,"width",`${a}px`)}}else if(i<1){let c=n["min-width"]||ge,p=n["min-height"]||ge;c.isNumeric(),c.isNumeric();let d=c,f=p;d.num===0&&f.num===0?P(l,"min-width",`${a}px`):d.num!==0&&f.num===0?P(l,"width",`${a}px`):d.num===0&&f.num!==0?P(l,"height",`${h}px`):d.unit!=="%"?P(l,"min-width",`${Math.max(a,We(d,this.context))}px`):f.unit!=="%"?P(l,"min-height",`${Math.max(h,We(f,this.context))}px`):s?P(l,"height",`${h}px`):P(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){vt("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let s={},r=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",r,s),!this.processRepeatOnBreak(s))continue;if(this.nodeContext.formattingContext instanceof si&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let o=this.nodeContext.parent,a=o&&o.formattingContext;this.nodeContext.formattingContext=new si(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==v.none&&((i===v.auto||K(i))&&(t.display===v.table_header_group?i=v.header:t.display===v.table_footer_group?i=v.footer:i=v.none),i&&i!==v.none)?i.toString():null}createTextNodeView(){let t=F("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=ua(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return N(!0);let t,i=t=this.sourceNode.textContent,n=F("preprocessTextContent"),s=vt("PREPROCESS_TEXT_CONTENT"),r=0;return n.loop(()=>r>=s.length?N(!1):s[r++](this.nodeContext,i).thenAsync(o=>(i=o,N(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Wp(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=F("createNodeView"),s,r=!0;return this.sourceNode.nodeType==1?s=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,s=N(!0)):s=this.createTextNodeView(),s.then(o=>{var a,h;if(r=o,this.nodeContext.viewNode=this.viewNode,this.viewNode){let l=(d,f)=>d?.nodeType===1&&wi(d)===f,c=this.nodeContext.parent,p=c?l(this.viewNode,"after")&&l(c.viewNode,"first-letter")&&(a=c.viewNode)!=null&&a.hasChildNodes()?c.parent.viewNode:c.viewNode:this.viewRoot;if(p&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&ze(this.viewNode))&&!p.hasChildNodes()&&yh(p).includes("block-start")&&ot(p,"text-start"),p.appendChild(this.viewNode),yf(this.viewNode),this.viewNode.nodeType===1&&this.viewNode.hasAttribute("data-vivliostyle-id"))){let d=this.viewNode,f=d.querySelector(":scope > a:empty[id^='viv-id-']");if(f&&(d.closest("[style*='position: absolute']")||/(table|flex|grid|ruby)/.test(d.style.display))){let m=f.getAttribute("id");f.ownerDocument.querySelectorAll(`a[id="${m}"]`).forEach(w=>{var y;(y=w.parentElement)==null||y.removeChild(w)});let g=p.closest("[data-vivliostyle-bleed-box]");(h=g?.parentElement)==null||h.insertBefore(f,g)}}}n.finish(r)}),n.result()}setCurrent(t,i,n){return this.nodeContext=t,t?(this.sourceNode=t.sourceNode,this.offsetInNode=t.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(i,!!n):N(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,s=t.parent,r,o,a=n.subShadow||n.parentShadow;n.subShadow?(r=n.root,o=n.type,o==ut.ROOTLESS&&(r=r.firstChild)):(r=n.owner.firstChild,o=ut.ROOTLESS);let h=t.sourceNode.nextSibling;if(h?(t.sourceNode=h,t.resetView()):t.shadowSibling?t=t.shadowSibling:r?t=null:(t=t.parent.modify(),t.after=!0),r){let l=new Gi(r,s,i);return l.shadowContext=a,l.shadowType=o,l.shadowSibling=t,l}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=ut.ROOTED){let n=t.sourceNode.nextSibling;if(n)return t=t.modify(),t.boxOffset=i,t.sourceNode=n,t.resetView(),this.processShadowContent(t)}return t.shadowSibling?(t=t.shadowSibling.modify(),t.boxOffset=i,t):(t=t.parent.modify(),t.boxOffset=i,t.after=!0,t)}else{if(t.nodeShadow){let s=t.nodeShadow.root;if(t.nodeShadow.type==ut.ROOTLESS&&(s=s.firstChild),s){let r=new Gi(s,t,i);return r.shadowContext=t.nodeShadow,r.shadowType=t.nodeShadow.type,this.processShadowContent(r)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new Gi(n,t,i));if(t.sourceNode.nodeType!=1){let s=ua(t.preprocessedTextContent);i+=s.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}isTransclusion(t,i,n){let s=Ue(i,"hyperlink-processing");if(!s)return!1;let r=s.evaluate(this.context,"hyperlink-processing");return r?r.toString()==n:!1}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return N(n);let s=F("nextInTree");return this.setCurrent(n,!0,i).then(r=>{(!n.viewNode||!r)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),this.dispatchEvent({type:"nextInTree",nodeContext:n}),s.finish(n)}),s.result()}addImageFetchers(t){if(t instanceof Ye){let i=t.values;for(let n=0;n<i.length;n++)this.addImageFetchers(i[n])}else if(t instanceof ft){let i=t.url;this.page.fetchers.push(hi(new Image,i))}}applyComputedStyles(t,i){var n,s,r;let o=i["background-image"];o&&this.addImageFetchers(o);let a=i.position===v.relative,h=((n=this.nodeContext)==null?void 0:n.parent)===null&&((s=this.sourceNode)==null?void 0:s.parentElement)===null&&!!((r=this.viewRoot)!=null&&r.parentElement),l=Object.keys(i);l.sort(Ko);let c,p;for(let d of l){if(zw[d])continue;let f=i[d];if(!(!f||f===G&&!Rt(d))){if(f=f.visit(new Ud(this.xmldoc.url,this.documentURLTransformer)),f instanceof I&&Pl(f.unit)&&(f.unit==="lh"?f=new I(f.num*this.getLineHeightUnitSize(d,c,p),"px"):f=Wl(f,this.context)),d==="font-size"?c=f:d==="line-height"&&(p=f),qp[d]||a&&Yp[d]){this.page.delayedItems.push(new to(t,d,f));continue}h&&this.page.pageAreaElement&&tn(d)?P(this.page.pageAreaElement.parentElement.parentElement,d,f.toString()):P(t,d,f.toString())}}}getLineHeightUnitSize(t,i,n){var s,r,o,a;let h=pe.lh/pe.em,l=((r=(s=this.nodeContext.parent)==null?void 0:s.viewNode)==null?void 0:r.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,c=l?parseFloat(l.fontSize):this.context.fontSize(),p=l?l.lineHeight==="normal"?c*h:parseFloat(l.lineHeight):this.context.rootLineHeight;if(t==="line-height"||t==="font-size")return p;let d=null;if(n){if(n instanceof Xt||n instanceof I&&(n.unit==="em"||n.unit==="%"))d=n instanceof I&&n.unit==="%"?n.num/100:n.num;else if(n instanceof I)return n.num*this.context.queryUnitSize(n.unit,!1)}else for(let f=(o=this.nodeContext.parent)==null?void 0:o.viewNode;;f=f.parentNode){if(!f||f.nodeType!==1){d=h;break}let m=(a=f?.style)==null?void 0:a.lineHeight;if(m){/^[0-9.]+$/.test(m)&&(d=parseFloat(m)),m==="normal"&&(d=h);break}}return d!==null?i instanceof I?d*Qh(i,c,this.context).num:d*c:p}applyPseudoelementStyle(t,i,n){if(t.after)return;let s=this.sourceNode,r=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(s,!1),o=bt(r,"_pseudos");if(!o||(r=o[i],!r))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",r,a);let h=a.content;jt(h)&&(h.visit(new ss(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=F("peelOff"),s=t.firstPseudo,r=t.offsetInNode,o=t.after;if(i>0){let p=t.viewNode.textContent;t.viewNode.textContent=p.substr(0,i),r+=i}else if(!o&&t.viewNode&&r==0){let p=t.viewNode.parentNode;p&&p.removeChild(t.viewNode)}let a=t.boxOffset+i,h=[];for(;t.firstPseudo===s;)h.push(t),t=t.parent;let l=h.pop(),c=l.shadowSibling;return n.loop(()=>{for(;h.length>0;){l=h.pop(),t=new Gi(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=r,t.after=o),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.shadowSibling:c,c=null;let p=this.setCurrent(t,!1);if(p.isPending())return p}return N(!1)}).then(()=>{n.finish(t)}),n.result()}createElement(t,i){return t=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(t,i)}applyFootnoteStyle(t,i,n){let s={},r=bt(this.footnoteStyle,"_pseudos");if(t=this.computeStyle(t,i,this.footnoteStyle,s),r&&r.before){let o={},a=this.createElement("http://www.w3.org/1999/xhtml","span");Ir(a,"before"),n.appendChild(a),this.computeStyle(t,i,r.before,o),delete o.content,this.applyComputedStyles(a,o)}return delete s.content,this.applyComputedStyles(n,s),t}processFragmentedBlockEdge(t){var i,n,s;let r=!t.inline&&t.after?t.parent:t,o=!1;if(t.inline&&t.after&&!t.shadowContext&&((i=t.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let h=t.sourceNode.nextSibling,l=(n=Ue(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();o=l&&!zt(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=r;h;h=h.parent){if(((s=h.viewNode)==null?void 0:s.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(ot(l,"inline-end"),Hi(l)){let c=h.vertical?l.offsetWidth:l.offsetHeight;ot(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>c&&this.fixClonedBoxDecorationOverflow(l)}}else{let c=this.nodeContext.vertical?"width":"height";if(_t(l,c)&&P(l,c,""),ot(l,"block-end"),!a++&&h!==r){let{textAlign:p}=this.viewport.window.getComputedStyle(l);if(p==="justify"&&!o){let d=this.createChildAnonymousBlockIfNeeded(l);d?d!==l?xh(d,["block-start","text-start","block-end","text-end","justify"]):(ot(l,"text-end"),ot(l,"justify")):ot(l,"text-end")}else ot(l,"text-end")}Hi(l)&&ot(l,"clone"),Vs(l,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),s=parseFloat(i.borderInlineEndWidth),r=-(n+s);isNaN(r)||(t.style.marginInlineEnd=`${r}px`)}createChildAnonymousBlockIfNeeded(t){let i=r=>{let{display:o,position:a,float:h}=this.viewport.window.getComputedStyle(r);if(r.localName==="ruby"||Jt[r.localName])return!1;if(r.localName==="br")return!0;if((o==="inline"||o==="contents")&&r.hasChildNodes()){let l=r.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===r.lastChild&&ze(l.nextSibling))){let c=i(l);if(c||c===null)return c}for(let c=l?.previousElementSibling;c;c=c.previousElementSibling){let p=i(c);if(p||p===null)return null}return!1}if(o==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||r.hasAttribute(Pi)){let l=r.previousElementSibling;return l&&(l.nextSibling===r||l.nextSibling===r.previousSibling&&ze(l.nextSibling))?i(l):!1}return!(!o||zt(o))},n=null;for(let r=t.lastElementChild;r;r=r.previousElementSibling){let o=i(r);if(o){n=r;break}if(o===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&ze(n.nextSibling)))return null;let s=t.ownerDocument.createElement("span");s.className="viv-anonymous-block";for(let r=n.nextSibling,o=null;r;r=o)o=r.nextSibling,s.appendChild(r);return t.appendChild(s),s}convertLengthToPx(t,i,n){let s=t.num,r=t.unit;if(ud(r)){let o=i;for(;o&&o.nodeType!==1;)o=o.parentNode;let a=parseFloat(n.getElementComputedStyle(o)["font-size"]);return this.context,ho(t,a,this.context).num}else{let o=this.context.queryUnitSize(r,!1);return o?s*o:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,s=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&wi(n)===wi(s)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,s)=>{let r=i.steps[s];return this.isSameNodePositionStep(n,r)})}isPseudoelement(t){return!!wi(t)}};u(ac,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var Mw=ac,zw={"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},qn=null,Dw=class{constructor(e){u(this,"layoutBox"),u(this,"window"),u(this,"scaleRatio"),this.layoutBox=e.layoutBox,this.window=e.window,this.scaleRatio=e.scaleRatio}scaleRect(e){return qn?{left:e.left*this.scaleRatio,top:e.top*this.scaleRatio,right:e.right*this.scaleRatio,bottom:e.bottom*this.scaleRatio,width:e.width*this.scaleRatio,height:e.height*this.scaleRatio}:e}subtractOffsets(e,t){let i=t.left,n=t.top;return{left:e.left-i,top:e.top-n,right:e.right-i,bottom:e.bottom-n,width:e.width,height:e.height}}getRangeClientRects(e){let t=e.getClientRects(),i=this.layoutBox.getBoundingClientRect();return Array.from(t).map(n=>this.scaleRect(this.subtractOffsets(n,i)))}getElementClientRect(e){let t=e.getBoundingClientRect();if(t.left===0&&t.top===0&&t.right===0&&t.bottom===0)return t;let i=this.layoutBox.getBoundingClientRect();return this.scaleRect(this.subtractOffsets(t,i))}getElementComputedStyle(e){return this.window.getComputedStyle(e,null)}adjustLengthValue(e){let t=64*(this.scaleRatio||1);return Math.floor(e*t)/t}},cs=class{constructor(e,t,i,n,s,r){this.window=e,this.fontSize=t,this.pixelRatio=i,u(this,"document"),u(this,"root"),u(this,"outerZoomBox"),u(this,"contentContainer"),u(this,"layoutBox"),u(this,"width"),u(this,"height"),u(this,"scaleRatio",1),this.document=e.document,this.root=n||this.document.body;let o=this.root.firstElementChild;o||(o=this.document.createElement("div"),o.setAttribute("data-vivliostyle-outer-zoom-box","true"),o.role="presentation",this.root.appendChild(o));let a=o.firstElementChild;a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),a.role="presentation",o.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(P(this.root,"--viv-outputPixelRatio",`${i}`),P(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio,qn===null&&(qn=!("currentCSSZoom"in a)),qn&&P(this.root,"--viv-scaleRectRatio",`${this.scaleRatio}`));let h=o.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),h.role="presentation",this.root.appendChild(h)),this.outerZoomBox=o,this.contentContainer=a,this.layoutBox=h,this.width=s||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=r||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let l={width:794,height:1056},c=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!s&&c)&&(this.width=l.width),(!this.height||!r&&c)&&(this.height=l.height)}resetZoom(){P(this.outerZoomBox,"width",""),P(this.outerZoomBox,"height",""),P(this.contentContainer,"width",""),P(this.contentContainer,"height",""),P(this.contentContainer,"transform","")}zoom(e,t,i){P(this.root,"--viv-outputScale",`${i}`),P(this.outerZoomBox,"width",`${e*i}px`),P(this.outerZoomBox,"height",`${t*i}px`),P(this.contentContainer,"width",`${e}px`),P(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}},lc=class{constructor(e,t,i){this.store=e,this.url=t,this.document=i,u(this,"lang",null),u(this,"totalOffset",-1),u(this,"root"),u(this,"body"),u(this,"head"),u(this,"last"),u(this,"lastOffset",1),u(this,"idMap"),this.root=i.documentElement;let n=null,s=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let r=this.root.firstChild;r;r=r.nextSibling){if(r.nodeType!=1)continue;let o=r;if(o.namespaceURI=="http://www.w3.org/1999/xhtml")switch(o.localName){case"head":s=o;break;case"body":n=o;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=s,this.last=this.root,this.last.setAttribute(kt,"0")}doc(){return new uc([this.document])}getElementOffset(e){let t=e.getAttribute(kt);if(t)return parseInt(t,10);let i=this.lastOffset,n=this.last;for(;n!=e;){let s=n.firstChild;if(!s){for(;s=n.nextSibling,!s;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=s,s.nodeType==1?(s.setAttribute(kt,i.toString()),++i):i+=s.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,s=e,r=null;if(s.nodeType==1){if(!i)return this.getElementOffset(s)}else{if(n=t,r=s.previousSibling,!r)return s=s.parentNode,n+=1,this.getElementOffset(s)+n;s=r}for(;;){for(;s.lastChild;)s=s.lastChild;if(s.nodeType==1)break;if(n+=s.textContent.length,r=s.previousSibling,!r){s=s.parentNode;break}s=r}return n+=1,this.getElementOffset(s)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let h=Ht(a.length,l=>{let c=a[l];return this.getElementOffset(c)>e});if(h==0)break;i=a[h-1]}let n=t+1,s=i,r=s.firstChild||s.nextSibling,o=null;for(;;){if(r){if(r.nodeType==1||(s=r,o=s,n+=r.textContent.length,n>e&&!/^\s*$/.test(r.textContent)))break}else if(s=s.parentNode,!s)break;r=s.nextSibling}return r&&o&&/^\s*$/.test(o.textContent)&&(o=r),o||i}buildIdMap(e){let t=e.getAttribute("id");t&&!this.idMap[t]&&(this.idMap[t]=e);let i=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=e);for(let n=e.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(e){let t=e.match(/([^#]*)#(.+)$/);if(!t||t[1]&&t[1]!=this.url)return null;let i=t[2],n=this.document.getElementById(i);return!n&&this.document.getElementsByName&&(n=this.document.getElementsByName(i)[0]),n||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),n=this.idMap[i]),n}},Mr=(e=>(e.TEXT_HTML="text/html",e.TEXT_XML="text/xml",e.APPLICATION_XML="application/xml",e.APPLICATION_XHTML_XML="application/xhtml+xml",e.IMAGE_SVG_XML="image/svg+xml",e))(Mr||{});function Dn(e,t,i){let n=i||new DOMParser,s;try{s=n.parseFromString(e,t)}catch{}if(s){let r=s.documentElement,o="parsererror";if(r.localName===o)return null;for(let a=r.firstElementChild;a;a=a.nextElementSibling)if(a.localName===o)return null}else return null;return s}function Vw(e){let t=e.contentType;if(t){let n=Object.keys(Mr);for(let s=0;s<n.length;s++)if(Mr[n[s]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let i=e.url.match(/\.([^./]+)$/);if(i)switch(i[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 hc(e,t){let i=e.responseXML;if(!i){let s=new DOMParser,r=e.responseText;if(r){let o=Vw(e);if(i=Dn(r,o||"application/xml",s),i&&!o){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Dn(r,"text/html",s):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Dn(r,"image/svg+xml",s))}i||(i=Dn(r,"text/html",s))}}let n=i?new lc(t,e.url,i):null;return N(n)}function Uw(){return new Kr(hc,"document")}var Hw=class zr{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new zr(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new zr(n=>{if(!this.check(n))return!1;let s=new uc([n]);return s=s.child(t),i&&(s=s.predicate(i)),s.size()>0})}},Ka=new Hw(e=>!0),uc=class Dr{constructor(t){this.nodes=t}asArray(){return this.nodes}size(){return this.nodes.length}predicate(t){let i=[];for(let n of this.nodes)t.check(n)&&i.push(n);return new Dr(i)}forEachNode(t){let i=[],n=s=>{i.push(s)};for(let s=0;s<this.nodes.length;s++)t(this.nodes[s],n);return new Dr(i)}forEach(t){let i=[];for(let n=0;n<this.nodes.length;n++)i.push(t(this.nodes[n]));return i}forEachNonNull(t){let i=[];for(let n=0;n<this.nodes.length;n++){let s=t(this.nodes[n]);s!=null&&i.push(s)}return i}child(t){return this.forEachNode((i,n)=>{for(let s=i.firstChild;s;s=s.nextSibling)s.nodeType==1&&s.localName==t&&n(s)})}childElements(){return this.forEachNode((t,i)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&i(n)})}attribute(t){return this.forEachNonNull(i=>i.nodeType==1?i.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}},$w=new Cn(()=>{let e=F("uaStylesheetBase"),t=Gu(),i=Ce("user-agent-base.css",ii),n=new cn(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),vg(n.cascade),Qr(oh,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function Gw(){return $w.get()}var Ww=class{constructor(e,t,i,n,s,r,o,a,h,l){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=s,this.fontFaces=r,this.footnoteProps=o,this.flowProps=a,this.viewportProps=h,this.pageProps=l,u(this,"fontDeobfuscator"),u(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(c){c=c;let p=this,d=p.currentLayoutPosition,f=d.firstFlowChunkOfFlow(c);return p.matchPageSide(d.startSideOfFlow(c))&&d.hasContent(c,p.lookupOffset)&&!!f&&!p.flowChunkIsAfterParentFlowForcedBreak(f)}),this.pageScope.defineName("page-number",new Te(this.pageScope,function(){let c=this;return c.pageNumberOffset+c.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new Te(this.pageScope,function(){let c=this.currentLayoutPosition;return c?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let s=new Ks(this.rootScope,e,t,i),r=_f(s,this.viewportProps),o=r.width,a=r.height,h=r["text-zoom"],l=1;if(o&&a||h){let c=pe.em;if((h?h.evaluate(s,"text-zoom"):null)===v.scale&&(l=c/i,i=c,e*=l,t*=l),o&&a){let p=We(o.evaluate(s,"width"),s),d=We(a.evaluate(s,"height"),s);if(p>0&&d>0)return{width:n&&n.spreadView?(p+n.pageBorder)*2:p,height:d,fontSize:i}}}}return{width:e,height:t,fontSize:i}}},To=class extends Ks{constructor(e,t,i,n,s,r,o,a,h,l,c,p,d){super(e.rootScope,n.width,n.height,n.fontSize),this.style=e,this.xmldoc=t,this.viewport=n,this.clientLayout=s,this.fontMapper=r,this.customRenderer=o,this.fallbackMap=a,this.pageNumberOffset=h,this.documentURLTransformer=l,this.counterStore=c,u(this,"lang"),u(this,"primaryFlows",{body:!0}),u(this,"rootPageBoxInstance",null),u(this,"styler",null),u(this,"stylerMap",null),u(this,"currentLayoutPosition",null),u(this,"layoutPositionAtPageStart",null),u(this,"lookupOffset",0),u(this,"faces"),u(this,"pageBoxInstances",{}),u(this,"pageManager",null),u(this,"rootPageFloatLayoutContext"),u(this,"pageBreaks",{}),u(this,"pageProgression",null),u(this,"isVersoFirstPage",!1),u(this,"blankPageAtStart",!1),u(this,"pageSheetSize",{}),u(this,"pageSheetHeight",0),u(this,"pageSheetWidth",0),this.lang=t.lang||i,this.faces=new Xm(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new Wi(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!d;for(let f in e.flowProps){let m=e.flowProps[f],g=Ue(m,"flow-consume");g&&(g.evaluate(this,"flow-consume")==v.all?this.primaryFlows[f]=!0:delete this.primaryFlows[f])}}init(){let e=F("StyleInstance.init"),t=this.counterStore.createCounterListener(this.xmldoc.url),i=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new Ma(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,t,i),i.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let n=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=ec(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let s=this.style.rootBox;this.rootPageBoxInstance=new Qm(s);let r=this.style.cascade.createInstance(this,t,i,this.lang);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(r,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new mw(r,this.style.pageScope,this.rootPageBoxInstance,this,n);let o=[];for(let h of this.style.fontFaces){if(h.condition&&!h.condition.evaluate(this))continue;let l=jm(h.properties,this),c=new Wu(l);o.push(c)}this.fontMapper.findOrLoadFonts(o,this.faces).then(()=>{Lw(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let a=this.style.pageProps;return a[""]||(a[""]={}),Object.keys(a).forEach(h=>{let l=a[h];this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context);let c=qa(us(l),this);this.pageSheetSize[h]={width:c.pageWidth+c.cropOffset*2,height:c.pageHeight+c.cropOffset*2}}),e.result()}matchStartPageSide(e){let t=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),i=this.pageProgression=="ltr";switch(e){case"left":return t!==i;case"right":return t===i;case"recto":return t;case"verso":return!t;default:return!0}}getStylerForDoc(e){let t=this.stylerMap[e.url];if(!t){let i=this.style.store.getStyleForDoc(e),n=new Ks(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),s=this.counterStore.createCounterListener(e.url),r=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new Ma(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,s,r),this.stylerMap[e.url]=t}return t}registerInstance(e,t){this.pageBoxInstances[e]=t}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,t){let i=this.currentLayoutPosition;if(i){i.flows[e.flowName]?t=i.flows[e.flowName]:i.flows[e.flowName]=t;let n=i.flowPositions[e.flowName];n||(n=new of,i.flowPositions[e.flowName]=n);let s=nf(e.element),r=new Wt(s),o=new rf(r,e);n.positions.push(o)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;let n=!0;class s{unknownProperty(h,l){n=!1}invalidPropertyValue(h,l){n=!1}simpleProperty(h,l,c){}}let r=new s,o=Fi(this.style.rootScope,new yt(t,null),"");return o?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,o,!1,r),n):!1}evalSupportsSelector(e){let t=new cc(null),i=new yt(e+"{}",t);return new kn(xe,i,t,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!t.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let t=Number.POSITIVE_INFINITY;for(let i=0;i<e.positions.length;i++){let n=e.positions[i].chunkPosition.primary,s=n.steps[0].node,r=n.offsetInNode,o=n.after,a=0;for(;s.ownerDocument!=this.xmldoc.document;)a++,s=n.steps[a].node,o=!1,r=0;let h=this.xmldoc.getNodeOffset(s,r,o);h<t&&(t=h)}return t}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let s=e.flowPositions[n];if(!t&&(!s||s.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),s=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&s&&(s=s.clone(),e.flowPositions[n]=s)),s){let r=this.getConsumedOffset(s);r<i&&(i=r)}}return i}dumpLocation(e){H.debug("Location - page",this.currentLayoutPosition.page),H.debug(" current:",e),H.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)H.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new Ie(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let t in e.flowPositions){let i=e.flowPositions[t];if(i&&i.positions.length>0){let n=i.positions[0].flowChunk;if(this.getConsumedOffset(i)===n.startOffset){let s=i.positions[0].flowChunk.breakBefore,r=i.startBreakType;i.startBreakType=ha(qe(r,s))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,s;for(let r=0;r<n.length;r++){if(s=n[r],s.pageBox.pseudoName===No)continue;let o=1;s.pageBox.pseudoName===So&&!(this.actualPageWidth&&this.actualPageHeight)&&(o=1/0);let a=s.getProp(this,"utilization");a&&a.isNum()&&(o=a.num);let h=this.queryUnitSize("em",!1),l=this.pageWidth()*this.pageHeight(),c=Math.ceil(o*l/(h*h)),p=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,c),this.styler.cascade.currentPageType=p,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let d=s.getProp(this,"enabled");if(!d||d===v._true){if(t.page===1&&this.blankPageAtStart){s.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(s,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,s=t[i].forcedBreakOffsets;if(!s.length||n<s[0])return!1;let r=Ht(s.length,l=>s[l]>n)-1,o=s[r],a=this.layoutPositionAtPageStart.flowPositions[i],h=this.getConsumedOffset(a);return o<h?!1:h<o?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new oo(null)),e.flowRootFormattingContext=i.formattingContext}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=a=>{if(a.floatReference!==Se.PAGE)return!1;let h=this.layoutPositionAtPageStart.flowPositions.body,l=h&&this.getConsumedOffset(h),c=this.xmldoc.getNodeOffset(a.nodePosition.steps[0].node,0,!1);return c!=null&&l!=null&&c>l},s=F("layoutDeferredPageFloats"),r=!1,o=0;return s.loopWithFrame(a=>{if(o===i.length){a.breakLoop();return}let h=i[o++],l=h.float;if(n(l)){a.breakLoop();return}let c=new Ti().findByFloat(l),p=c.findPageFloatFragment(l,t);if(p&&p.hasFloat(l)){a.continueLoop();return}else if(t.isForbidden(l)||t.hasPrecedingFloatsDeferredToNext(l)){t.deferPageFloat(h),a.breakLoop();return}e.layoutPageFloatInner(h,c,null,p).then(d=>{if(!d){a.breakLoop();return}let f=t.parent.isInvalidated();if(f){a.breakLoop();return}else t.isInvalidated()&&!f&&(r=!0,t.validate());a.continueLoop()})}).then(()=>{r&&t.invalidate(),s.finish(!0)}),s.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new Wt(e.lastAfterPosition),i}else return null;else return null}layoutColumn(e,t){let i=this.currentLayoutPosition.flowPositions[t];if(!i||!this.matchPageSide(i.startBreakType))return N(!0);this.setFormattingContextToColumn(e,t),e.init(),this.primaryFlows[t]&&e.bands.length>0&&(e.forceNonfitting=!1);let n=F("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let s=[],r=[],o=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-r.length>0;){let h=0;for(;r.includes(h);)h++;let l=i.positions[h];if(l.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(l.flowChunk))break;for(let d=h+1;d<i.positions.length;d++){if(r.includes(d))continue;let f=i.positions[d];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(l.flowChunk)&&(l=f,h=d)}let c=l.flowChunk,p=!0;if(e.layout(l.chunkPosition,o,i.breakAfter).then(d=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(o=!1,l.flowChunk.repeated&&(d===null||c.exclusive)&&s.push(h),c.exclusive){r.push(h),a.breakLoop();return}else{let f=!!d||!!e.pageBreakType,m=this.getLastAfterPositionIfDeferredFloatsExists(e,d);if(e.pageBreakType&&m?(l.chunkPosition=m,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(r.push(h),(d||m)&&(l.chunkPosition=d||m,s.push(h)),i.startBreakType=ha(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,p?p=!1:a.continueLoop()}),p){p=!1;return}}a.breakLoop()}).then(()=>{if(!e.pageFloatLayoutContext.isInvalidated()){i.positions=i.positions.filter((h,l)=>s.includes(l)||!r.includes(l)),i.breakAfter==="column"&&(i.breakAfter=null),e.saveDistanceToBlockEndFloats();let a=e.pageFloatLayoutContext.getMaxReachedAfterEdge();e.updateMaxReachedAfterEdge(a)}n.finish(!0)})}),n.result()}createLayoutConstraint(e){let t=this.currentLayoutPosition.page-1,i=this.counterStore.createLayoutConstraint(t);return new Vg([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,s,r,o,a,h,l,c,p,d,f){let m=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,g=s.element,w=new Wi(a,Se.COLUMN,null,o,null,null,null),y=this.currentLayoutPosition.clone(),b=F("createAndLayoutColumn"),S;return b.loopWithFrame(T=>{let R=this.createLayoutConstraint(w);if(h>1){let M=this.viewport.document.createElement("div");if(P(M,"position","absolute"),g.appendChild(M),S=new ls(M,d,this.clientLayout,R,w),S.forceNonfitting=f,S.vertical=s.vertical,S.rtl=s.rtl,S.snapHeight=s.snapHeight,S.snapWidth=s.snapWidth,s.vertical){let V=(s.rtl?h-r-1:r)*(c+l)+s.paddingTop,W=parseFloat(g.style.width);S.setHorizontalPosition(s.paddingLeft+W-s.width,s.width),S.setVerticalPosition(V,c)}else{let V=(s.rtl?h-r-1:r)*(c+l)+s.paddingLeft;S.setVerticalPosition(s.paddingTop,s.height),S.setHorizontalPosition(V,c)}S.originX=t,S.originY=i}else S=new ls(g,d,this.clientLayout,R,w),S.copyFrom(s);S.exclusions=m?[]:n.concat(),S.innerShape=p,w.setContainer(S),(S.vertical?S.height:S.width)>=0?this.layoutColumn(S,o).then(()=>{w.isInvalidated()||w.finish(),S.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(S.pageFloatLayoutContext.validate(),this.currentLayoutPosition=y.clone(),S.element!==g&&g.removeChild(S.element),T.continueLoop()):T.breakLoop()}):(w.finish(),T.breakLoop())}).then(()=>{b.finish(S)}),b.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof nc||t instanceof Co&&!(t instanceof Ei))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof Ii;let s=t.getProp(this,"writing-mode")||null,r=t.getProp(this,"direction")||null;return new Wi(e,Se.REGION,i,n,null,s,r)}layoutFlowColumnsWithBalancing(e,t,i,n,s,r,o,a,h){let l=this.currentLayoutPosition.clone(),c=this.getRegionPageFloatLayoutContext(r,t,o,a),p=!0,d=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,s,r,c,o,a,h,p).thenAsync(f=>N(f?{columns:f,position:this.currentLayoutPosition}:null)));return d().thenAsync(f=>{if(!f)return N(null);if(h<=1)return N(f.columns);let m=t.getProp(this,"column-fill")||v.balance,g=this.currentLayoutPosition.flowPositions[a],w=Tm(h,m,d,c,o,f.columns,g);return w?(p=!1,r.lock(),c.lock(),w.balanceColumns(f).thenAsync(y=>(r.unlock(),r.validate(),c.unlock(),this.currentLayoutPosition=y.position,N(y.columns)))):N(f.columns)})}layoutFlowColumns(e,t,i,n,s,r,o,a,h,l,c){let p=F("layoutFlowColumns"),d=this.currentLayoutPosition.clone(),f=t.getPropAsNumber(this,"column-gap"),m=l>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,g=t.getActiveRegions(this),w=t.getProp(this,"shape-inside"),y=Zl(w,0,0,a.width,a.height,this),b=new Mw(h,this,this.viewport,this.styler,g,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer),S=0,T=null,R=[];return p.loopWithFrame(M=>{this.createAndLayoutColumn(t,i,n,s,a,S++,h,o,l,f,m,y,b,c).then(V=>{if(r.isInvalidated()){R=null,M.breakLoop();return}if((V.pageBreakType&&V.pageBreakType!=="column"||S===l)&&!o.isInvalidated()&&o.finish(),o.isInvalidated()){S=0,this.currentLayoutPosition=d.clone(),o.validate(),o.isLocked()?(R=null,M.breakLoop()):M.continueLoop();return}T=V,R[S-1]=T,T.pageBreakType&&T.pageBreakType!="column"&&(S=l,T.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),S<l?M.continueLoop():M.breakLoop()})}).then(()=>{p.finish(R)}),p.result()}layoutContainer(e,t,i,n,s,r,o){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==v._true)return N(!0);let h=F("layoutContainer"),l=t.getProp(this,"wrap-flow")===v.auto,c=t.getProp(this,"flow-from"),p=this.viewport.document.createElement("div");p.role=t instanceof sc?"complementary":"presentation";let d=t.getProp(this,"position");P(p,"position",d?d.name:"absolute");let f=t instanceof Ei;t instanceof Ii?i.appendChild(p):i.insertBefore(p,i.firstChild);let m=new Ah(p);m.vertical=t.vertical,m.rtl=t.rtl,m.borderBoxSizing=t.borderBoxSizing,m.exclusions=r,t.prepareContainer(this,m,e,this.faces,this.clientLayout),t instanceof Ei&&(m.width<=0||m.height<=0)&&H.warn("Negative or zero page area size"),m.originX=n,m.originY=s,n+=m.left+m.marginLeft+m.borderLeft,s+=m.top+m.marginTop+m.borderTop,this.setPagePageFloatLayoutContextContainer(o,t,m);let g,w=!1;if(!c||!c.isIdent()){let y=t.getProp(this,"content");if(y instanceof D&&y.expr instanceof Te&&y.expr.str.startsWith("running-element-"))y.visit(new ss(p,this,y,this.counterStore.getExprContentListener()));else if(y&&jt(y)){let b="span";y.url&&(b="img");let S=this.viewport.document.createElement(b);y.visit(new ss(S,this,y,this.counterStore.getExprContentListener())),p.appendChild(S),b=="img"&&t.transferSingleUriContentProps(this,S,this.faces),t.transferContentProps(this,m,e,this.faces),b=="span"&&Lg(S,t.getProp(this,"text-autospace"),t.getProp(this,"text-spacing-trim"),t.getProp(this,"hanging-punctuation"),this.lang,t.vertical)}else t.suppressEmptyBoxGeneration&&(i.removeChild(p),w=!0);w||t.finishContainer(this,m,e,null,1,this.clientLayout,this.faces),g=N(!0)}else if(this.pageBreaks[c.toString()])o.isInvalidated()||t.finishContainer(this,m,e,null,1,this.clientLayout,this.faces),g=N(!0);else{let y=F("layoutContainer.inner"),b=c.toString(),S=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,s,r,o,m,b,S).then(T=>{if(!o.isInvalidated()){let R=T[0];R.element===p&&(m=R),m.computedBlockSize=Math.max.apply(null,T.map(V=>V.computedBlockSize)),t.finishContainer(this,m,e,R,S,this.clientLayout,this.faces);let M=this.currentLayoutPosition.flowPositions[b];M&&M.breakAfter==="region"&&(M.breakAfter=null)}y.finish(!0)}),g=y.result()}return g.then(()=>{if(o.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(m.computedBlockSize)>0){if(!w&&!l){let b=t.getProp(this,"shape-outside"),S=m.getOuterShape(b,this);r.push(S)}}else if(t.children.length==0){i.removeChild(p),h.finish(!0);return}let y=f?0:t.children.length-1;h.loop(()=>{for(;y>=0&&y<t.children.length;){let b=t.children[f?y++:y--],S=this.layoutContainer(e,b,p,n,s,r,o);if(S.isPending())return S.thenAsync(()=>N(!o.isInvalidated()));if(o.isInvalidated())break}return N(!1)}).then(()=>{h.finish(!0)})}),h.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let s=i.positions[n];s.flowChunk.startPage>=0&&s.flowChunk.startPage+s.flowChunk.linger-1<=e&&i.positions.splice(n,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let s=i.positions[n];s.flowChunk.startPage<0&&s.flowChunk.startOffset<this.lookupOffset&&(s.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let t in this.primaryFlows){let i=e.flowPositions[t];if(i&&i.positions.length>0)return!1}return!0}layoutNextPage(e,t){var i;let n=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new af,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let s=1e4;if(t.page>s)throw new Error(`Too many pages generated (over ${s} pages)`);let r=t.startSideOfFlow("body");t.isBlankPage=un(r)&&this.matchPageSide(r),e.isBlankPage=t.isBlankPage,t.page++,e.pageType==null&&(e.pageType=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let o=n?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.styler.cascade.applyVarFilter([o],this.styler,null),this.styler.cascade.applyCalcFilter(o,this.styler.context),!n){let f=new Ie(this.style.pageScope,"left-page");e.side=f.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let a=this.selectPageMaster(o);if(!a)return N(null);let h=0;if(!n){e.setAutoPageWidth(a.pageBox.specified.width.value===xn),e.setAutoPageHeight(a.pageBox.specified.height.value===Sn),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(o,this);let f=qa(us(o),this);this.setPageSizeAndBleed(f,e),hw(o,f,e,this),h=f.bleedOffset+f.bleed}let l=!n&&a.getProp(this,"writing-mode")||v.horizontal_tb;this.pageVertical=l!=v.horizontal_tb;let c=a.getProp(this,"direction")||v.ltr,p=new Wi(this.rootPageFloatLayoutContext,Se.PAGE,null,null,null,l,c),d=F("layoutNextPage");return d.loopWithFrame(f=>{this.layoutContainer(e,a,e.bleedBox,h,h,[],p).then(()=>{p.isInvalidated()||p.finish(),p.isInvalidated()?(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),p.validate(),f.continueLoop()):f.breakLoop()})}).then(()=>{a.adjustPageLayout(this,e,this.clientLayout),n||(this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(m=>{let g=t.flowPositions[m],w=g.breakAfter;w&&(w==="page"||!this.matchPageSide(w))&&(g.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let f=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(f,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),d.finish(t)}),d.result()}setPageSizeAndBleed(e,t){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,t.container.style.width=`${this.pageSheetWidth}px`,t.container.style.height=`${this.pageSheetHeight}px`,t.bleedBox.style.left=`${e.bleedOffset}px`,t.bleedBox.style.width=`${e.pageWidth}px`,t.bleedBox.style.top=`${e.bleedOffset}px`,t.bleedBox.style.height=`${e.pageHeight}px`,t.bleedBox.style.padding=`${e.bleed}px`}},jw=class Vr extends cn{constructor(t,i,n,s){super(t.rootScope,t,i,n,s,t.validatorSet,!n),this.masterHandler=t,u(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let s=new ju(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new iw(s.scope,this.masterHandler,s,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=pt(this.scope,this.condition,i)),this.masterHandler.pushHandler(new Vr(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new Eg(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new zn(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startFlowRule(t){let i=this.masterHandler.flowProps[t];i||(i={},this.masterHandler.flowProps[t]=i),this.masterHandler.pushHandler(new zn(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new zn(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=ys(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new zn(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new Pw(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(cn.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let t=`R${this.masterHandler.regionCount++}`;this.special("region-id",B(t)),this.endRule();let i=new Vr(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},cc=class extends Ip{constructor(e){super(),this.validatorSet=e,u(this,"rootScope"),u(this,"pageScope"),u(this,"rootBox"),u(this,"cascadeParserHandler"),u(this,"regionCount",0),u(this,"fontFaces",[]),u(this,"footnoteProps",{}),u(this,"flowProps",{}),u(this,"viewportProps",[]),u(this,"pageProps",{}),this.rootScope=new Zs(null),this.pageScope=new Zs(this.rootScope),this.rootBox=new Zm(this.rootScope),this.cascadeParserHandler=new jw(this,null,null,null),this.slave=this.cascadeParserHandler}};function Xw(e,t){return t.parseOPSResource(e)}var qw=class extends Kr{constructor(e){super(Xw,"document"),this.fontDeobfuscator=e,u(this,"styleByKey",{}),u(this,"styleFetcherByKey",{}),u(this,"styleByDocURL",{}),u(this,"triggersByDocURL",{}),u(this,"validatorSet",null),u(this,"styleSheets",[]),u(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=F("OPSDocStore.init");return this.validatorSet=Gu(),Gw().then(()=>{this.triggerSingleDocumentPreprocessing=!0,i.finish(!0)}),i.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,t){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),t&&t.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let t=e.url;t&&(t=Ce(hn(t),ki)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ce(hn(t),ki)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=F("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return hc(e,this).then(s=>{var r;if(!s){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let d=vt("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<d.length;f++)try{d[f](s.document)}catch(m){H.warn("Error during single document preprocessing:",m)}}let o=[],a=s.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let d=0;d<a.length;d++){let f=a[d],m=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),g=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),w=f.getAttribute("action"),y=f.getAttribute("ref");m&&g&&w&&y&&o.push({observer:m,event:g,action:w,ref:y})}this.triggersByDocURL[i]=o;let h=[];if(h.push({url:Ce("user-agent-page.css",ii),text:rh,flavor:"UA",classes:null,media:null}),n)h.push({url:Ce("user-agent-toc.css",ii),text:ah,flavor:"UA",classes:null,media:null});else{let d=s.document.querySelectorAll("style, link, meta");for(let f of d){let m=f.namespaceURI,g=f.localName;if(m=="http://www.w3.org/1999/xhtml")if(g=="style"){let w=f.getAttribute("class"),y=f.getAttribute("media"),b=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:b?w:null,media:y})}else if(g=="link"){let w=f.getAttribute("href"),y=(r=f.getAttribute("rel"))==null?void 0:r.split(/\s+/),b=f.getAttribute("class"),S=f.getAttribute("media");if(w&&y!=null&&y.includes("stylesheet")&&(!y.includes("alternate")||b)){let T=Ce(w,i),R=f.getAttribute("title");h.push({url:T,text:null,classes:R?b:null,media:S,flavor:"Author"})}}else g=="meta"&&f.getAttribute("name")=="viewport"&&h.push({url:i,text:this.processViewportMeta(f),flavor:"Author",classes:null,media:null})}for(let f=0;f<this.styleSheets.length;f++)h.push(this.styleSheets[f])}let l="";for(let d=0;d<h.length;d++)l+=h[d].url,l+="^",h[d].text&&(l+=h[d].text),l+="^";let c=this.styleByKey[l];if(c){this.styleByDocURL[i]=c,t.finish(s);return}let p=this.styleFetcherByKey[l];p||(p=new Cn(()=>{let d=F("fetchStylesheet"),f=0,m=new cc(this.validatorSet);return d.loop(()=>{if(f<h.length){let g=h[f++];return m.startStylesheet(g.flavor),g.text!==null?Qr(g.text,m,g.url,g.classes,g.media).thenReturn(!0):fh(g.url,m,g.classes,g.media)}return N(!1)}).then(()=>{let g=m.cascadeParserHandler.finish();c=new Ww(this,m.rootScope,m.pageScope,g,m.rootBox,m.fontFaces,m.footnoteProps,m.flowProps,m.viewportProps,m.pageProps),this.styleByKey[l]=c,delete this.styleFetcherByKey[l],d.finish(c)}),d.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[l]=p,p.start()),p.get().then(d=>{this.styleByDocURL[i]=d,t.finish(s)})}),t.result()}processViewportMeta(e){return""}},an="\u25B8",Ja="\u25BE",Yw="\u25B9";function Io(e){let t=Array.from(e.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(e.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of e.querySelectorAll(i)){if(t.find(r=>r.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 Zw(e){let t=Io(e),i=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))i.push(s);return i}var Kw=class{constructor(e,t,i,n,s,r,o,a,h,l){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=s,this.rendererFactory=o,this.fallbackMap=a,this.documentURLTransformer=h,this.counterStore=l,u(this,"pref"),u(this,"page",null),u(this,"instance",null),this.pref=Cl(r),this.pref.spreadView=!1}setAutoHeight(e,t){if(t--!=0){for(let i=e.firstChild;i;i=i.nextSibling)if(i.nodeType==1){let n=i;_t(n,"height","auto")!="auto"&&(P(n,"height","auto"),this.setAutoHeight(n,t)),_t(n,"position","static")=="absolute"&&(P(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,s)=>{let r=s.behavior;if(r)switch(r.toString()){case"toc-node-anchor":s.color=v.inherit,s["text-decoration"]=v.none;break;case"toc-node":s.display=v.block,s.margin=ge,s.padding=ge,s["padding-inline-start"]=new I(1.25,"em");break;case"toc-node-first-child":s.display=v.inline_block,s.margin=new I(.2,"em"),s["vertical-align"]=v.top,s.color=v.inherit,s["text-decoration"]=v.none;break;case"toc-container":s.padding=ge;break}if(!r||r.toString()!="toc-node"&&r.toString()!="toc-container")return t(i,n,s);let o=i.firstChild;o&&o.nodeType!==1&&ze(o)&&i.replaceChild(i.ownerDocument.createComment(o.textContent),o);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=an&&(l.textContent=an,P(l,"cursor","pointer"),l.addEventListener("click",Jw,!1),l.setAttribute("role","button"),l.setAttribute("aria-expanded","false"),n.setAttribute("aria-expanded","false"),n.style.height!=="0px"&&(l.tabIndex=0))}let h=n.ownerDocument.createElement("div");if(h.setAttribute("data-adapt-process-children","true"),r.toString()=="toc-node"){let l=n.ownerDocument.createElement("div");if(l.textContent=Yw,P(l,"margin","0.2em 0 0 -1em"),P(l,"margin-inline-start","-1em"),P(l,"margin-inline-end","0"),P(l,"display","inline-block"),P(l,"width","1em"),P(l,"text-align","center"),P(l,"vertical-align","top"),P(l,"cursor","default"),P(l,"font-family","Menlo,sans-serif"),h.appendChild(l),P(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){P(h,"height","0px");let c=i.firstElementChild;c&&c.localName==="a"&&(c.tabIndex=-1)}else n.setAttribute("role","tree")}else a=="toc-node"&&(h.setAttribute("data-adapt-class","toc-container"),h.setAttribute("role","group"),h.setAttribute("aria-hidden","true"));return N(h)}}showTOC(e,t,i,n,s){if(this.page)return N(this.page);let r=F("showTOC"),o=new Ch(e,e);this.page=o;let a=Pt(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of Io(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),c=l.sizeViewport(i,1e5,s);t=new cs(t.window,c.fontSize,0,t.root,c.width,c.height);let p=this.makeCustomRenderer(h),d=new To(l,h,this.lang,t,this.clientLayout,this.fontMapper,p,this.fallbackMap,0,this.documentURLTransformer,this.counterStore);this.instance=d,d.pref=this.pref,d.init().then(()=>{d.layoutNextPage(o,null).then(()=>{this.setAutoHeight(e,2),r.finish(o)})})}),r.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 e(n){if(!n)return[];let s=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(s).map(t)}function t(n){let s=new URL(n.href),[,r]=s.hash.match(/^#?(.*)$/),o=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=e(a);return{id:r,title:o,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function Jw(e){let t=e.target,i=t.textContent==an;t.textContent=i?Ja:an;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let s=n.firstChild;for(;s;){if(s.nodeType===1){let r=s,o=r.getAttribute("data-adapt-class");if(o==="toc-container"){if(r.setAttribute("aria-hidden",i?"false":"true"),r.firstChild){s=r.firstChild;continue}}else if(o==="toc-node"&&(r.style.height=i?"auto":"0px",r.children.length>=2&&(r.children[1].tabIndex=i?0:-1),r.children.length>=3&&(r.children[0].tabIndex=i?0:-1,!i))){let a=r.children[0];if(a.textContent==Ja){a.textContent=an,a.setAttribute("aria-expanded","false"),r.setAttribute("aria-expanded","false"),s=r.children[2];continue}}}for(;!s.nextSibling&&s.parentNode!==n;)s=s.parentNode;s=s.nextSibling}e.stopPropagation()}var Qa=class extends qw{constructor(){super(null),u(this,"plainXMLStore"),u(this,"jsonStore"),u(this,"opfByURL",{}),u(this,"primaryOPFByEPubURL",{}),u(this,"deobfuscators",{}),u(this,"documents",{}),this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=Uw(),this.jsonStore=kp()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,t,i){return this.plainXMLStore.load(e,t,i)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,t,i){return this.jsonStore.load(e,t,i)}loadPubDoc(e){let t=F("loadPubDoc");return bs(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}H.error(`Failed to fetch a source document from ${e} (${i.status}${i.statusText?" "+i.statusText:""})`),t.finish(null)});else if(!i.status&&!i.responseXML&&!i.responseText&&!i.responseBlob&&!i.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),i.contentType=="application/oebps-package+xml"||/\.opf(?:[#?]|$)/.test(e)){let[,n,s]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,s).thenFinish(t)}else i.contentType=="application/ld+json"||i.contentType=="application/webpub+json"||i.contentType=="application/audiobook+json"||i.contentType=="application/json"||/\.json(?:ld)?(?:[#?]|$)/.test(e)?this.loadAsJSON(e,!0).then(n=>{if(!n){this.reportLoadError(e),t.finish(null);return}let s=new Yn(this,e);s.initWithWebPubManifest(n,void 0,e).then(()=>{t.finish(s)})}):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(s=>{if(s){t.finish(s);return}H.error(`Failed to load ${e}.`),t.finish(null)})})}),t.result()}loadEPUBDoc(e){let t=F("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let i=e+"META-INF/container.xml";return this.loadAsPlainXML(i).then(n=>{if(n){let s=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let r of s)if(r){this.loadOPF(e,r).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return N(n);let s=F("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(r=>{r?(n=new Yn(this,e),this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(o=>{n.initWithXMLDoc(r,o).then(()=>{s.finish(n)})}):n.initWithXMLDoc(r,null).then(()=>{s.finish(n)})):this.reportLoadError(i)}),s.result()}loadWebPub(e){let t=F("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,s=new Yn(this,e),r=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(r){let o=r.getAttribute("href");if(/^#/.test(o)){let a=Hr(n.getElementById(o.substr(1)).textContent);s.initWithWebPubManifest(a,n).then(()=>{t.finish(s)})}else{let a=Ce(r.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{s.initWithWebPubManifest(h,n,a).then(()=>{t.finish(s)})})}}else s.initWithWebPubManifest({},n).then(()=>{s.toc&&s.toc.src===i.url&&Io(n).length===0&&(s.toc=null),t.finish(s)})}}),t.result()}addDocument(e,t){let i=F("EPUBDocStore.load"),n=Pt(e);return(this.documents[n]=this.parseOPSResource({status:200,statusText:"",url:n,contentType:t.contentType,responseText:null,responseXML:t,responseBlob:null})).thenFinish(i),i.result()}reportLoadError(e){let t=n=>n.replace(/([^:/?#]|^)[/?#].*/,"$1"),i=()=>{let n=t(e);return!(n===t(ki)||Object.keys(this.resources).find(s=>this.resources[s]&&t(s)===n)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?H.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&ki.startsWith("https:")?H.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?H.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):H.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Pt(e),i=this.documents[t];if(i)return i.isPending()?i:N(i.get());{let n=F("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(s=>{s?n.finish(s):this.reportLoadError(t)}),n.result()}}processViewportMeta(e){let t=e.getAttribute("content");if(!t)return"";let i={},n;for(;(n=t.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)t=t.substr(n[0].length),i[n[1]]=n[2];let s=i.width-0,r=i.height-0;if(s&&r){let o=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${s}px;height:${r}px;}`+(o?`@page{size:${s}px ${r}px;margin:0;}`:"@page{margin:0;}")}return""}},el=class{constructor(){u(this,"id",null),u(this,"src",""),u(this,"mediaType",null),u(this,"title",null),u(this,"itemRefElement",null),u(this,"spineIndex",-1),u(this,"compressedSize",0),u(this,"compressed",null),u(this,"epage",0),u(this,"epageCount",0),u(this,"startPage",null),u(this,"skipPagesBefore",null),u(this,"itemProperties"),this.itemProperties=Yc}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Ce(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=id(i.split(/\s+/)))}initWithParam(e){this.spineIndex=e.index,this.id=`item${e.index+1}`,this.src=e.url,this.startPage=e.startPage,this.skipPagesBefore=e.skipPagesBefore}};function Qw(e){return e.id}function eb(e){return t=>{let i=F("deobfuscator");return tb("SHA-1",e).then(n=>{let s=t.slice(0,1040),r=t.slice(1040,t.size);Sp(s).then(o=>{let a=new DataView(o);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(hh([a,r]))})}),i.result()}}function tb(e,t){let i=F("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(s=>{n.schedule(new Uint8Array(s))}),i.result()}var Dt={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"},Yi="http://idpf.org/epub/vocab/package/meta/#",Ne={language:`${Dt.dcterms}language`,title:`${Dt.dcterms}title`,creator:`${Dt.dcterms}creator`,layout:`${Dt.rendition}layout`,titleType:`${Yi}title-type`,displaySeq:`${Yi}display-seq`,alternateScript:`${Yi}alternate-script`,role:`${Yi}role`};function ib(e,t){let i={};return(n,s)=>{var r,o,a,h,l,c;let p,d,f=n.r||i,m=s.r||i;if(e==Ne.title&&(p=((r=f[Ne.titleType])==null?void 0:r[0].v)=="main",d=((o=m[Ne.titleType])==null?void 0:o[0].v)=="main",p!=d))return p?-1:1;let g=parseInt((a=f[Ne.displaySeq])==null?void 0:a[0].v,10);isNaN(g)&&(g=Number.MAX_VALUE);let w=parseInt((h=m[Ne.displaySeq])==null?void 0:h[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),g!=w?g-w:e!=Ne.language&&t&&(p=((l=f[Ne.language]||f[Ne.alternateScript])==null?void 0:l[0].v)==t,d=((c=m[Ne.language]||m[Ne.alternateScript])==null?void 0:c[0].v)==t,p!=d)?p?-1:1:n.o-s.o}}function nb(e,t){let i;if(!t)i=Dt;else{i={};for(let d in Dt)i[d]=Dt[d];let p;for(;(p=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(p[0].length),i[p[1]]=p[2]}let n=p=>{if(p){let d=p.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(d){let f=d[2]?i[d[2]]:Yi;if(f)return f+d[3]}}return null},s=1,r=e.childElements().forEachNonNull(p=>{if(p.localName=="meta"){let d=n(p.getAttribute("property"));if(d)return{name:d,value:p.textContent,id:p.getAttribute("id"),order:s++,refines:p.getAttribute("refines"),lang:null,scheme:n(p.getAttribute("scheme")),role:null}}else if(p.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:Dt.dcterms+p.localName,order:s++,lang:p.getAttribute("xml:lang"),value:p.textContent,id:p.getAttribute("id"),refines:null,scheme:null,role:p.getAttribute("role")||p.getAttribute("opf:role")};return null}),o=As(r,p=>p.refines),a=p=>nd(p,(d,f)=>d.map(m=>{let g={v:m.value,o:m.order};m.scheme&&(g.s=m.scheme);let w=o[`#${m.id}`]||[];if(w.length||m.lang||m.role){m.lang&&w.push({name:Ne.language,value:m.lang,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null}),m.role&&w.push({name:Ne.role,value:m.role,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null});let y=As(w,b=>b.name);g.r=a(y)}return g})),h=a(As(r,p=>p.refines?null:p.name)),l=null;h[Ne.language]&&(l=h[Ne.language][0].v);let c=p=>{for(let d in p){let f=p[d];f.sort(ib(d,l));for(let m=0;m<f.length;m++){let g=f[m].r;g&&c(g)}}};return c(h),h}function sb(){let e=window.MathJax;return e?e.Hub:null}var tl={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},js="viv-id-",Yn=class{constructor(e,t){this.store=e,this.pubURL=t,u(this,"opfXML",null),u(this,"encXML",null),u(this,"items",null),u(this,"spine",null),u(this,"itemMap",null),u(this,"itemMapByPath",null),u(this,"uid",null),u(this,"bindings",{}),u(this,"lang",null),u(this,"epageCount",0),u(this,"prePaginated",!1),u(this,"epageIsRenderedPage",!0),u(this,"epageCountCallback",null),u(this,"metadata",{}),u(this,"toc",null),u(this,"cover",null),u(this,"fallbackMap",{}),u(this,"pageProgression",null),u(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,s){let r=s+(n?`#${n}`:"");return js+bl(r,":")}transformURL(n,s){let r=n.match(/^([^#]*)#?(.*)$/);if(r){let o=r[1]||s.replace(/\?viv-toc-box$/,""),a=decodeURIComponent(r[2]);if(o&&e.spine.some(h=>h.src===o))return`#${this.transformFragment(a,o)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(js)===0&&(n=n.substring(js.length));let s=td(n,":").match(/^([^#]*)#?(.*)$/);return s?[s[1],s[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=Ce("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let h=e.getElement(`${e.url}#${n}`);h&&(this.uid=h.textContent.replace(/[ \n\r\t]/g,""))}let s={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new el,c=h;l.initWithElement(c,e.url);let p=c.getAttribute("fallback");return p&&!tl[l.mediaType]&&(s[l.src]=p),!this.toc&&l.itemProperties.nav&&(this.toc=l),!this.cover&&l.itemProperties["cover-image"]&&(this.cover=l),l}),this.itemMap=Do(this.items,Qw),this.itemMapByPath=Do(this.items,h=>this.getPathFromURL(h.src));for(let h in s){let l=h;for(;;){let c=this.itemMap[s[l]];if(!c)break;if(tl[c.mediaType]){this.fallbackMap[h]=c.src;break}l=c.src}}this.spine=i.child("spine").child("itemref").asArray().map((h,l)=>{let c=h,p=c.getAttribute("idref"),d=this.itemMap[p];return d&&(d.itemRefElement=c,d.spineIndex=l),d});let r=i.child("spine").attribute("page-progression-direction")[0];r&&(this.pageProgression=ul(r));let o=t?t.doc().child("encryption").child("EncryptedData").predicate(Ka.withChild("EncryptionMethod",Ka.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],a=i.child("bindings").child("mediaType").asArray();for(let h=0;h<a.length;h++){let l=a[h].getAttribute("handler"),c=a[h].getAttribute("media-type");c&&l&&this.itemMap[l]&&(this.bindings[c]=this.itemMap[l].src)}if(this.metadata=nb(i.child("metadata"),i.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"),o.length>0&&this.uid){let h=eb(this.uid);for(let l=0;l<o.length;l++)this.store.deobfuscators[this.pubURL+o[l]]=h}return this.prePaginated&&this.assignAutoPages(),N(!0)}assignAutoPages(){let e=0;for(let t of this.spine){let i=this.prePaginated?1:Math.ceil(t.compressedSize/1024);t.epage=e,t.epageCount=i,e+=i}this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(e){this.epageIsRenderedPage=e||this.prePaginated}countEPages(e){if(this.epageCountCallback=e,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),N(!0);let t=0,i=0,n=F("countEPages");return n.loopWithFrame(s=>{if(i===this.spine.length){s.breakLoop();return}let r=this.spine[i++];r.epage=t,this.store.load(r.src).then(o=>{let a=1800,h=o.lang||this.lang;h&&h.match(/^(ja|ko|zh)/)&&(a/=3),r.epageCount=Math.ceil(o.getTotalOffset()/a),t+=r.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),s.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new lc(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let s=new el;s.initWithParam(n),s.id;let r=i.document.createElement("itemref");r.setAttribute("idref",s.id),i.root.appendChild(r),s.itemRefElement=r,this.itemMap[s.id]=s;let o=this.getPathFromURL(n.url);o==null&&(o=n.url),this.itemMapByPath[o]=s,this.items.push(s)}),t?this.store.addDocument(e[0].url,t):N(null)}initWithWebPubManifest(e,t,i){var n,s,r,o;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[Ne.title]=(Array.isArray(a)?a:[a]).map(g=>{var w;return{v:(w=g.value)!=null?w:g}}));let h=e.author||e.creator||((s=e.metadata)==null?void 0:s.author)||Array.from((r=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?r:[]).map(g=>g.content);h&&h.length!==0&&(this.metadata[Ne.creator]=(Array.isArray(h)?h:[h]).map(g=>{var w;return{v:(w=g.name)!=null?w:g}}));let l=e.inLanguage||((o=e.metadata)==null?void 0:o.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[Ne.language]=(Array.isArray(l)?l:[l]).map(g=>({v:g})));let c=this.getPathFromURL(this.pubURL);if(!e.readingOrder&&t&&c!==null){e.readingOrder=[encodeURI(c)];for(let g of Zw(t)){let w=g.getAttribute("href");if(/^(https?:)?\/\//.test(w)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(w))continue;let y=Pt(Ce(w,this.pubURL)),b=this.getPathFromURL(y),S=b!==null?encodeURI(b):y;e.readingOrder.indexOf(S)==-1&&e.readingOrder.push(S)}}let p=[],d=0,f=-1;[e.readingOrder,e.resources].forEach(g=>{g instanceof Array&&g.forEach(w=>{let y=g===e.readingOrder,b=typeof w=="string"?w:w.url||w.href,S=typeof w=="string"?"":w.encodingFormat||w.href&&w.type||"";if(y||S==="text/html"||S==="application/xhtml+xml"||!S&&w.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(b)){let T=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,R={url:Ce(hn(b),T),index:d++,startPage:null,skipPagesBefore:null};w.rel==="contents"&&f===-1&&(f=R.index),p.push(R)}})});let m=F("initWithWebPubManifest");return this.initWithChapters(p).then(()=>{var g,w;f!==-1&&(this.toc=this.items[f]),this.toc||(this.toc=i?(g=this.items)==null?void 0:g[0]:this.itemMapByPath[c]);let y=(w=e.readingOrder)==null?void 0:w.length;y&&y<this.items.length&&this.items.splice(y),m.finish(!0)}),m.result()}getCFI(e,t){let i=this.spine[e],n=F("getCFI");return this.store.load(i.src).then(s=>{let r=s.getNodeByOffset(t),o=null;if(r){let a=s.getNodeOffset(r,0,!1),h=t-a,l=new Wo;l.prependPathFromNode(r,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),o=l.toString()}n.finish(o)}),n.result()}resolveFragment(e){return Ni("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Wo;i.fromString(e);let n;if(this.opfXML){let s=i.navigate(this.opfXML.document);if(s.node.nodeType!=1||s.after||!s.ref){t.finish(null);return}let r=s.node,o=r.getAttribute("idref");if(r.localName!="itemref"||!o||!this.itemMap[o]){t.finish(null);return}n=this.itemMap[o],i=s.ref}else n=this.spine[0];this.store.load(n.src).then(s=>{let r=i.navigate(s.document),o=s.getNodeOffset(r.node,r.offset,r.after);t.finish({spineIndex:n.spineIndex,offsetInItem:o,pageIndex:-1})})},(t,i)=>{H.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return Ni("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let s=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);s==-1&&(s=this.spine.length-1);let r=this.spine[s];(!r||r.epageCount==0)&&(r=this.spine[--s]);let o=Math.floor(e-r.epage);t.finish({spineIndex:s,offsetInItem:-1,pageIndex:o});return}let i=Ht(this.spine.length,s=>{let r=this.spine[s];return r.epage+r.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(s=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let r=0;if(e>0){let o=s.getTotalOffset();r=Math.round(o*e/n.epageCount),r==o&&r--}t.finish({spineIndex:i,offsetInItem:r,pageIndex:-1})})},(t,i)=>{H.warn(i,"Cannot resolve epage:",e),t.finish(null)})}getEPageFromPosition(e){let t=this.spine[e.spineIndex];if(this.epageIsRenderedPage){let n=t.epage+e.pageIndex;return N(n)}if(e.offsetInItem<=0)return N(t.epage);let i=F("getEPage");return this.store.load(t.src).then(n=>{let s=n.getTotalOffset(),r=Math.min(s,e.offsetInItem);i.finish(t.epage+r*t.epageCount/s)}),i.result()}},Vn=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),rb=class{constructor(e,t,i,n,s){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=s,u(this,"spineItems",[]),u(this,"spineItemLoadingContinuations",[]),u(this,"pref"),u(this,"clientLayout"),u(this,"counterStore"),u(this,"tocAutohide",!1),u(this,"tocVisible",!1),u(this,"tocView"),this.pref=Cl(n),this.clientLayout=new Dw(t),this.counterStore=new Wd(e.documentURLTransformer)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let s=this.opf.spine[e.item.spineIndex-1];e.item.epage=s.epage+s.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((s,r)=>s+r.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)e.instance.viewport.contentContainer.replaceChild(t.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:t});else{let s=null;if(i>0)s=e.pages[i-1].container.nextElementSibling;else for(let r=e.item.spineIndex+1;r<this.spineItems.length;r++){let o=this.spineItems[r];if(o&&o.pages[0]){s=o.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,s)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}renderSinglePage(e,t){let i=F("renderSinglePage"),n=e.pages[t?t.page:0],s=this.makePage(e,t);return n&&(s.pageType=n.pageType),e.instance.layoutNextPage(s,t).then(r=>{t=r;let o=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,s,o),this.counterStore.finishPage(s.spineIndex,o);let a=null;if(t){let h=e.layoutPositions[t.page];e.layoutPositions[t.page]=t,h&&e.pages[t.page]&&(t.isSamePosition(h)||(a=this.renderSinglePage(e,t)))}a||(a=N(!0)),a.then(()=>{let h=this.counterStore.getUnresolvedRefsToPage(s),l=0;i.loopWithFrame(c=>{if(l++,l>h.length){c.breakLoop();return}let p=h[l-1];if(p.refs=p.refs.filter(d=>!d.isResolved()),p.refs.length===0){c.continueLoop();return}this.getPageViewItem(p.spineIndex).then(d=>{if(!d){c.continueLoop();return}let{currentPageType:f,previousPageType:m}=d.instance.styler.cascade,g=d.instance.scopes;d.instance.scopes={},this.counterStore.pushPageCounters(p.pageCounters),this.counterStore.pushReferencesToSolve(p.refs);let w=d.layoutPositions[p.pageIndex];this.renderSinglePage(d,w).then(y=>{d.instance.styler.cascade.currentPageType=f,d.instance.styler.cascade.previousPageType=m,d.instance.scopes=g,this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve();let b=y.pageAndPosition.position;b.spineIndex===s.spineIndex&&b.pageIndex===o&&(s=y.pageAndPosition.page),c.continueLoop()})})}).then(()=>{s.container.parentElement||(s=e.pages[o]),s.isLastPage=!t&&e.item.spineIndex===this.opf.spine.length-1,s.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),s.container.setAttribute("data-vivliostyle-page-index",o),s.container.setAttribute("data-vivliostyle-spine-index",s.spineIndex),i.finish({pageAndPosition:Vn(s,o),nextLayoutPosition:t})})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let s=Ht(t.layoutPositions.length,r=>t.instance.getPosition(t.layoutPositions[r],!0)>n);s===t.layoutPositions.length?t.complete?i=t.layoutPositions.length-1:i=Number.POSITIVE_INFINITY:i=s-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=F("findPage");return this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let s=null,r;i.loopWithFrame(o=>{let a=this.normalizeSeekPosition(e,n);r=a.pageIndex,s=n.pages[r],s?o.breakLoop():n.complete?(r=n.layoutPositions.length-1,s=n.pages[r],o.breakLoop()):t?this.renderPage(a).then(h=>{h&&(s=h.page,r=h.position.pageIndex),o.breakLoop()}):i.sleep(100).then(()=>{o.continueLoop()})}).then(()=>{i.finish(Vn(s,r))})}),i.result()}renderPage(e){let t=F("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),s=n.pageIndex,r=n.offsetInItem,o=i.pages[s];if(o){t.finish(Vn(o,s));return}t.loopWithFrame(a=>{if(s<i.layoutPositions.length){a.breakLoop();return}if(i.complete){s=i.layoutPositions.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let c=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(r>=0&&i.instance.getPosition(h)>r){o=c,s=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else o=c,s=l.pageAndPosition.position.pageIndex,i.complete=!0,a.breakLoop()})}).then(()=>{o=o||i.pages[s];let a=i.layoutPositions[s];if(o){t.finish(Vn(o,s));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||(i.complete=!0),t.finish(h.pageAndPosition)})})}),t.result()}renderAllPages(){let e=F("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(t=>{e.loopWithFrame(i=>{this.spineItems.some(n=>n?.pages.some(s=>s?.fetchers.some(r=>!r.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=F("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,s=e.pageIndex,r=0;t&&(r=n);let o;return i.loopWithFrame(a=>{let h={spineIndex:r,pageIndex:r===n?s:Number.POSITIVE_INFINITY,offsetInItem:r===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{o=l,++r>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(o)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,s=F("nextPage");return this.getPageViewItem(i).then(r=>{if(!r){s.finish(null);return}if(r.complete&&n==r.layoutPositions.length-1){if(i>=this.opf.spine.length-1){s.finish(null);return}i++,n=0;let o=this.spineItems[i],a=o&&o.pages[0],h=r.pages[r.pages.length-1];a&&h&&a.side==h.side&&(o.pages.forEach(l=>{l.container&&l.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(s)}),s.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return N(null);i--,n=Number.POSITIVE_INFINITY}else n--;return this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t)}isRectoPage(e,t){let i=e.side==="left",n=this.getCurrentPageProgression(t)==="ltr";return!i&&n||i&&!n}getSpread(e,t){let i=this.getPage(e);if(!i)return N({left:null,right:null});let n=F("getSpread"),s=i.side==="left",r;return this.isRectoPage(i,e)?r=this.previousPage(e,t):r=this.nextPage(e,t),r.then(o=>{let a=this.getPage(e),h=o&&o.page;h&&h.side===a.side&&(h=null),s?n.finish({left:a,right:h}):n.finish({left:h,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),s=this.nextPage(e,t);return n?s:s.thenAsync(r=>{if(r){if(r.page.side===i.side)return s;let o=this.nextPage(r.position,t);return o.thenAsync(a=>a?o:s)}else return N(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),s=this.previousPage(e,t),r=i.container.previousElementSibling;return n?s.thenAsync(o=>o?o.page.side===i.side||o.page.container!==r?s:this.previousPage(o.position,t):N(null)):s}navigateToEPage(e,t,i){let n=F("navigateToEPage");return this.opf.resolveEPage(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(e,t,i){let n=F("navigateToCFI");return this.opf.resolveFragment(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateTo(e,t,i){H.debug("Navigate to",e);let n=this.opf.getPathFromURL(Pt(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let o=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(o[0]),n==null&&(n=o[0])):n=o[0],e=o[0]+(o[1]?`#${o[1]}`:"")}if(n==null)return N(null)}let s=this.opf.itemMapByPath[n];if(!s){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let o=e.indexOf("#");if(o>=0)return this.navigateToFragment(e.substr(o+1),t,i)}return N(null)}let r=F("navigateTo");return this.getPageViewItem(s.spineIndex).then(o=>{if(!o){r.finish(null);return}let a=o.xmldoc.getElement(e);this.findPage({spineIndex:s.spineIndex,pageIndex:-1,offsetInItem:a?o.xmldoc.getElementOffset(a):0},i).thenFinish(r)}),r.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",ln||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let s=i.document.createElement("div");s.setAttribute("data-vivliostyle-bleed-box","true"),s.role="presentation",n.appendChild(s);let r=new Ch(n,s);if(r.spineIndex=e.item.spineIndex,r.position=t,r.offset=e.instance.getPosition(t),r.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let o=this.opf.documentURLTransformer.transformFragment("",e.item.src);s.setAttribute("id",o),r.registerElementWithId(s,o)}if(i!==this.viewport){let o=El(this.viewport.width,this.viewport.height,i.width,i.height),a=Fi(null,new yt(o,null),"");r.delayedItems.push(new to(n,"transform",a))}return r}makeObjectView(e,t,i,n){let s=t.getAttribute("data"),r=null;if(s){s=Ce(s,e.url);let o=t.getAttribute("media-type");if(!o){let a=this.opf.getPathFromURL(s);if(a){let h=this.opf.itemMapByPath[a];h&&(o=h.mediaType)}}if(o){let a=this.opf.bindings[o];if(a){r=this.viewport.document.createElement("iframe"),r.style.border="none";let h=Mo(s),l=Mo(o),c=new It;c.append(a),c.append("?src="),c.append(h),c.append("&type="),c.append(l);for(let f=t.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let m=f;if(m.localName=="param"&&m.namespaceURI=="http://www.w3.org/1999/xhtml"){let g=m.getAttribute("name"),w=m.getAttribute("value");g&&w&&(c.append("&"),c.append(encodeURIComponent(g)),c.append("="),c.append(encodeURIComponent(w)))}}r.setAttribute("src",c.toString());let p=t.getAttribute("width");p&&r.setAttribute("width",p);let d=t.getAttribute("height");d&&r.setAttribute("height",d)}}}return r||(r=this.viewport.document.createElement("object"),s&&r.setAttribute("data",s),r.setAttribute("data-adapt-process-children","true")),N(r)}makeMathJaxView(e,t,i,n){let s=sb();if(s){let r=i.ownerDocument,o=r.createElement("span");i.appendChild(o);let a=r.importNode(t,!0);this.resolveURLsInMathML(a,e),o.appendChild(a);let h=s.queue;h.Push(["Typeset",s,o]);let l=F("makeMathJaxView"),c=l.suspend();return h.Push(()=>{c.schedule(o)}),l.result()}return N(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let s=Ce(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,s):e.setAttribute(n.name,s)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):N(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return N(null);let t=this.spineItems[e];if(t)return N(t);let i=F("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let o=i.suspend();return n.push(o),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let s=this.opf.spine[e],r=this.opf.store;return r.load(s.src).then(o=>{var a;let h=s.itemRefElement.getAttribute("properties");h&&o.root.setAttribute("data-vivliostyle-epub-spine-properties",h),s.title=o.document.title;let l=r.getStyleForDoc(o),c=this.makeCustomRenderer(o),p=this.viewport,d=l.sizeViewport(p.width,p.height,p.fontSize,this.pref);(d.width!=p.width||d.height!=p.height||d.fontSize!=p.fontSize)&&(p=new cs(p.window,d.fontSize,p.pixelRatio,p.root,d.width,d.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,m=this.spineItems[e-1],g,w;if(s.startPage!==null)g=s.startPage-1,w=g;else{if(e>0&&(!m||!m.complete))g=s.epage||e,!this.opf.prePaginated&&g%2==(f?1:0)&&g++,w=g;else{g=m?m.instance.pageNumberOffset+m.pages.length:0;let S=this.counterStore.currentPageCounters.page;w=!S||!S.length?g:S[S.length-1]}s.skipPagesBefore!==null&&(g+=s.skipPagesBefore,w+=s.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let y=new To(l,o,this.opf.lang,p,this.clientLayout,this.fontMapper,c,this.opf.fallbackMap,g,this.opf.documentURLTransformer,this.counterStore,this.opf.pageProgression,f);y.pref=this.pref;let b=this.opf.metadata&&this.opf.metadata[Ne.title];y.pubTitle=b&&b[0]&&b[0].v||"",y.docTitle=s.title||"",y.init().then(()=>{!this.opf.pageProgression&&y.pageProgression&&(this.opf.pageProgression=y.pageProgression),t={item:s,xmldoc:o,instance:y,layoutPositions:[null],pages:[],complete:!1},this.spineItems[e]=t,i.finish(t),n.forEach(S=>{S.schedule(t)})})}),i.result()}removeRenderedPages(){let e=this.spineItems;for(let t of e)t&&t.pages.splice(0);this.viewport.clear()}hasAutoSizedPages(){let e=this.spineItems;for(let t of e)if(t){let i=t.pages;for(let n of i)if(n.isAutoPageWidth&&n.isAutoPageHeight)return!0}return!1}hasPages(){return this.spineItems.some(e=>e&&e.pages.length>0)}showTOC(e){let t=this.opf,i=t.toc;if(this.tocAutohide=e,!i)return N(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"),N(this.tocView.page);let n=F("showTOC");this.tocView||(this.tocView=new Kw(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore));let s=this.viewport,r=Math.min(344,Math.round(.67*s.width)-16),o=s.height-6,a=s.document.createElement("div");return s.root.appendChild(a),ln||(a.style.visibility="hidden"),a.style.width=`${r+16}px`,a.style.maxHeight=`${o}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,s,r,o,this.viewport.fontSize).then(h=>{a.style.visibility="visible",a.setAttribute("aria-hidden","false"),n.finish(h)}),n.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}},il="data-vivliostyle-viewer-status",ob="data-vivliostyle-spread-view",dc=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(dc||{}),ab=class{constructor(e,t,i,n){this.window=e,this.viewportElement=t,this.instanceId=i,this.callbackFn=n,u(this,"fontMapper"),u(this,"kick"),u(this,"sendCommand"),u(this,"resizeListener"),u(this,"hyperlinkListener"),u(this,"pageRuleStyleElement"),u(this,"pageSheetSizeAlreadySet",!1),u(this,"renderTask",null),u(this,"actions"),u(this,"readyState"),u(this,"packageURL"),u(this,"opf"),u(this,"touchActive"),u(this,"touchX"),u(this,"touchY"),u(this,"needResize"),u(this,"resized"),u(this,"needRefresh"),u(this,"viewportSize"),u(this,"currentPage"),u(this,"currentSpread"),u(this,"pagePosition"),u(this,"fontSize"),u(this,"zoom"),u(this,"fitToScreen"),u(this,"pageViewMode"),u(this,"waitForLoading"),u(this,"renderAllPages"),u(this,"pref"),u(this,"pageSizes"),u(this,"pixelRatio"),u(this,"pixelRatioLimit"),u(this,"viewport"),u(this,"opfView");let s=t.ownerDocument,r=(o,a)=>{let h=s.getElementById(o);return h||(h=s.createElement("style"),h.id=o,a&&(h.textContent=a),s.head.appendChild(h)),h};r("vivliostyle-viewport-screen-css",th),r("vivliostyle-viewport-css",ih),r("vivliostyle-polyfill-css",lh),t.setAttribute("data-vivliostyle-viewer-viewport",!0),ln&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(il,"loading"),this.fontMapper=new qm(s.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=o=>{},this.pageRuleStyleElement=r("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=Sl(),this.pageSizes=[],this.pixelRatioLimit=/Chrome/.test(navigator.userAgent)?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=pl;H.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),H.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),H.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),H.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){this.readyState!==e&&(this.readyState=e,this.viewportElement.setAttribute(il,e),this.callback({t:"readystatechange"}))}loadPublication(e){nt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,s=e.userStyleSheet;this.viewport=null;let r=F("loadPublication");return this.configure(e).then(()=>{let o=new Qa;o.init(n,s).then(()=>{let a=Ce(hn(t),this.window.location.href);this.packageURL=[a],o.loadPubDoc(a).then(h=>{h?(this.opf=h,this.render(i).then(()=>{r.finish(!0)})):r.finish(!1)})})}),r.result()}loadXML(e){nt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,s=e.authorStyleSheet,r=e.userStyleSheet;this.viewport=null;let o=F("loadXML");return this.configure(e).then(()=>{let a=new Qa;a.init(s,r).then(()=>{let h=t.map((l,c)=>({url:Ce(hn(l.url),this.window.location.href),index:c,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new Yn(a,""),this.opf.initWithChapters(h,i).then(()=>{this.render(n).then(()=>{o.finish(!0)})})})}),o.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,N(!0))):t=N(!0),t.thenAsync(()=>(nt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let s=n[0];if(s==="em"||s==="rem")return t*this.fontSize;if(s==="ex")return t*pe.ex*this.fontSize/pe.em;let r=pe[s];if(r)return t*r}return t}configure(e){if(typeof e.autoresize=="boolean"&&(e.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof e.fontSize=="number"){let t=e.fontSize;t>=5&&t<=72&&this.fontSize!=t&&(this.fontSize=t,this.needResize=!0)}if(typeof e.viewport=="object"&&e.viewport){let t=e.viewport,i={marginLeft:this.resolveLength(t["margin-left"])||0,marginRight:this.resolveLength(t["margin-right"])||0,marginTop:this.resolveLength(t["margin-top"])||0,marginBottom:this.resolveLength(t["margin-bottom"])||0,width:this.resolveLength(t.width)||0,height:this.resolveLength(t.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof e.hyphenate=="boolean"&&(this.pref.hyphenate=e.hyphenate,this.needResize=!0),typeof e.horizontal=="boolean"&&(this.pref.horizontal=e.horizontal,this.needResize=!0),typeof e.nightMode=="boolean"&&(this.pref.nightMode=e.nightMode,this.needResize=!0),typeof e.lineHeight=="number"&&(this.pref.lineHeight=e.lineHeight,this.needResize=!0),typeof e.columnWidth=="number"&&(this.pref.columnWidth=e.columnWidth,this.needResize=!0),typeof e.fontFamily=="string"&&(this.pref.fontFamily=e.fontFamily,this.needResize=!0),typeof e.load=="boolean"&&(this.waitForLoading=e.load),typeof e.renderAllPages=="boolean"&&(this.renderAllPages=e.renderAllPages),typeof e.userAgentRootURL=="string"&&(Oo(e.userAgentRootURL.replace(/resources\/?$/,"")),Bo(e.userAgentRootURL)),typeof e.rootURL=="string"&&(Oo(e.rootURL),Bo(`${ki}resources/`)),typeof e.pageViewMode=="string"&&e.pageViewMode!==this.pageViewMode&&(this.pageViewMode=e.pageViewMode,this.needResize=!0),typeof e.pageBorder=="number"&&e.pageBorder!==this.pref.pageBorder&&(this.viewport=null,this.pref.pageBorder=e.pageBorder,this.needResize=!0),typeof e.zoom=="number"&&e.zoom!==this.zoom&&(this.zoom=e.zoom,this.needRefresh=!0),typeof e.fitToScreen=="boolean"&&e.fitToScreen!==this.fitToScreen&&(this.fitToScreen=e.fitToScreen,this.needRefresh=!0),typeof e.defaultPaperSize=="object"&&typeof e.defaultPaperSize.width=="number"&&typeof e.defaultPaperSize.height=="number"&&(this.viewport=null,this.pref.defaultPaperSize=e.defaultPaperSize,this.needResize=!0),typeof e.allowScripts=="boolean"&&e.allowScripts!==Ft&&(Iw(e.allowScripts),this.needResize=!0),typeof e.pixelRatio=="number"){let t=Math.min(e.pixelRatio,this.pixelRatioLimit);t!==this.pixelRatio&&(this.pixelRatio=t,this.needResize=!0)}return this.configurePlugins(e),N(!0)}configurePlugins(e){vt("CONFIGURATION").forEach(t=>{let i=t(e);this.needResize=i.needResize||this.needResize,this.needRefresh=i.needRefresh||this.needRefresh})}pageReplacedListener(e){let t=this.currentPage,i=this.currentSpread,n=e.target;i?(i.left===n||i.right===n)&&this.showCurrent(e.newPage):t===e.target&&this.showCurrent(e.newPage)}forCurrentPages(e){let t=[];this.currentPage&&t.push(this.currentPage),this.currentSpread&&(t.push(this.currentSpread.left),t.push(this.currentSpread.right)),t.forEach(i=>{i&&e(i)})}removePageListeners(){this.forCurrentPages(e=>{e.removeEventListener("hyperlink",this.hyperlinkListener,!1),e.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(e=>{P(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),P(e.container,"visibility","visible"),P(e.container,"display","block")}showPage(e){this.hidePages(),this.currentPage=e,e.container.style.marginLeft="",e.container.style.marginRight="",this.showSinglePage(e)}showSpread(e){if(this.hidePages(),this.currentSpread=e,e.left&&e.right){let t=parseFloat(e.left.container.style.width),i=parseFloat(e.right.container.style.width);t&&i&&t!==i&&(t<i?e.left.container.style.marginLeft=`${i-t}px`:e.right.container.style.marginRight=`${t-i}px`)}e.left&&(this.showSinglePage(e.left),e.right?e.left.container.removeAttribute("data-vivliostyle-unpaired-page"):e.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),e.right&&(this.showSinglePage(e.right),e.left?e.right.container.removeAttribute("data-vivliostyle-unpaired-page"):e.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let e=F("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(t=>{let i=this.currentPage;(this.waitForLoading&&i.fetchers.length>0?ws(i.fetchers):N(!0)).then(()=>{this.sendLocationNotification(i,t).thenFinish(e)})}),e.result()}createViewport(){let e=this.viewportElement;if(this.viewportSize){let t=this.viewportSize;return e.style.marginLeft=`${t.marginLeft}px`,e.style.marginRight=`${t.marginRight}px`,e.style.marginTop=`${t.marginTop}px`,e.style.marginBottom=`${t.marginBottom}px`,new cs(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new cs(this.window,this.fontSize,this.pixelRatio,e)}resolveSpreadView(e,t){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;case"autoSpread":default:return(e.width-this.pref.pageBorder)/e.height>=(t?t.width*2/t.height:1.45)&&(!!t||e.width>800)}}updateSpreadView(e){this.pref.spreadView=e,this.viewportElement.setAttribute(ob,e.toString())}sizeIsGood(){var e;let t=this.createViewport(),i=((e=this.opfView)==null?void 0:e.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&i?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:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,s;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((s=this.pageSizes[i-1])==null?void 0:s.height))){let o=function(m){let g=m*.75;return Math.ceil(g)};var r=o;let a=Math.max(...this.pageSizes.map(m=>m.width)),h=Math.max(...this.pageSizes.map(m=>m.height)),l=o(a),c=o(h),p=l*((this.pixelRatio||1)-1)+2,d=c*((this.pixelRatio||1)-1)+2,f=`@page {size: ${l}pt ${c}pt; margin: 0 ${-p}pt ${-d}pt 0;}`;this.pageRuleStyleElement.textContent=f,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}reset(){let e=!1,t=!1;this.opfView&&(e=this.opfView.tocVisible,t=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new rb(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this)),e&&this.sendCommand({a:"toc",v:"show",autohide:t})}showCurrent(e,t){this.needRefresh=!1,this.removePageListeners();let i=this.resolveSpreadView(this.viewport,e.dimensions);return i!==this.pref.spreadView&&this.updateSpreadView(i),i?this.opfView.getSpread(this.pagePosition,t).thenAsync(n=>!n.left&&!n.right?N(null):n.left&&n.right&&(!this.resolveSpreadView(this.viewport,n.left.dimensions)||!this.resolveSpreadView(this.viewport,n.right.dimensions))?(this.updateSpreadView(!1),this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,N(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null))}setPageZoom(e){let t=this.getAdjustedZoomFactor(e.dimensions);this.viewport.zoom(e.dimensions.width,e.dimensions.height,t)}setSpreadZoom(e){let t=this.getSpreadDimensions(e);this.viewport.zoom(t.width,t.height,this.getAdjustedZoomFactor(t))}getAdjustedZoomFactor(e){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(e):this.zoom}getSpreadDimensions(e){let t=0,i=0;return e.left&&(t+=e.left.dimensions.width,i=e.left.dimensions.height),e.right&&(t+=e.right.dimensions.width,i=Math.max(i,e.right.dimensions.height)),e.left&&e.right&&(t+=this.pref.pageBorder*2,t+=Math.abs(e.left.dimensions.width-e.right.dimensions.width)),{width:t,height:i}}queryZoomFactor(e){if(!this.currentPage)throw new Error("no page exists.");switch(e){case"fit inside viewport":{let t;return this.pref.spreadView?(this.currentSpread,t=this.getSpreadDimensions(this.currentSpread)):t=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(t)}default:throw new Error(`unknown zoom type: ${e}`)}}calculateZoomFactorToFitInsideViewPort(e){if(!this.viewport)return this.zoom;let t=this.viewport.width/e.width,i=this.viewport.height/e.height;return Math.min(t,i)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new nl),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return N(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=sr().getScheduler().run(()=>Ni("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,nt.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(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let s={t:"nav",epageCount:n,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)&&(s.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(s)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():N(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),nt.registerEndTiming("render (resize)"),Ft&&oc(this.window)?Fw(this.window).then(()=>{this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),t.finish(n)}):(this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),t.finish(n))})})})})})},(t,i)=>{if(i instanceof nl)nt.registerEndTiming("render (resize)"),H.debug(i.message);else throw i}));return N(!0)}sendLocationNotification(e,t){let i=F("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:e.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(s=>{n.epage=s,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(e){var t;let i;if(this.readyState!=="complete"&&e.where!=="next"&&this.setReadyState("loading"),typeof e.where=="string"){let s;switch(e.where){case"next":s=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":s=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":s=this.opfView.lastPage;break;case"first":s=this.opfView.firstPage;break;default:return N(!0)}s&&(i=()=>s.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let s=e.epage;i=()=>this.opfView.navigateToEPage(s,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let s=e.url;i=()=>this.opfView.navigateTo(s,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let s=e.position;i=()=>this.opfView.findPage(s,!this.renderAllPages)}else return N(!0);if(!this.opfView)return N(!0);let n=F("moveTo");return i.call(this.opfView).then(s=>{let r;if(s){this.pagePosition=s.position;let o=F("moveTo.showCurrent");r=o.result(),this.showCurrent(s.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(o)})}else r=N(!0);r.then(o=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(o)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),s=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!s)return N(!0)}else if(i=="hide")return N(!0);if(n&&i!="show")return this.opfView.hideTOC(),N(!0);{let r=F("showTOC");return this.opfView.showTOC(t).then(o=>{if(o){if(s&&(o.listeners={}),t){let a=()=>{this.opfView.hideTOC()};o.addEventListener("hyperlink",a,!1)}o.addEventListener("hyperlink",this.hyperlinkListener,!1)}r.finish(!0)}),r.result()}}runCommand(e){let t=e.a||"";return Ni("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(H.error("No such action:",t),i.finish(!0))},(i,n)=>{H.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=sl(e),i=null,n=this;mp(()=>{let s=F("commandLoop"),r=sr().getScheduler();return n.hyperlinkListener=o=>{let a=o,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){o.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};r.run(()=>(n.callback(l),N(!0)))}},s.loopWithFrame(o=>{if(n.needResize)n.resize().then(()=>{o.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{o.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{o.continueLoop()})}else{let a=F("waitForCommand");i=a.suspend(this),a.result().then(()=>{o.continueLoop()})}}).thenFinish(s),s.result()}),n.kick=()=>{let s=i;s&&(i=null,s.schedule(!0))},n.sendCommand=s=>t?!1:(t=sl(s),n.kick(),!0),this.window.adapt_command=n.sendCommand}},pc=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(pc||{}),nl=class fc extends Error{constructor(){super(),u(this,"name","RenderingCanceledError"),u(this,"message","Page rendering has been canceled"),u(this,"stack"),Object.setPrototypeOf(this,fc.prototype),this.stack=new Error().stack}};function sl(e){return typeof e=="string"?Hr(e):e}var rl=Ur;function lb(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function ol(e){let t={};return Object.keys(e).forEach(i=>{let n=e[i];switch(i){case"autoResize":t.autoresize=n;break;case"pageBorderWidth":t.pageBorder=n;break;default:t[i]=n}}),t}var gc=class{constructor(e,t){this.settings=e,u(this,"initialized",!1),u(this,"adaptViewer_"),u(this,"options"),u(this,"eventTarget"),u(this,"readyState"),hl(e.debug),this.adaptViewer_=new ab(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=lb(),t&&this.setOptions(t),this.eventTarget=new $r,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},ol(e));this.adaptViewer_.sendCommand(t),Object.assign(this.options,e)}dispatcher(e){let t={type:e.t},i=e;Object.keys(i).forEach(n=>{n!=="t"&&(t[n]=i[n])}),this.eventTarget.dispatchEvent(t)}addListener(e,t){this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){this.eventTarget.removeEventListener(e,t,!1)}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let s=i||{};function r(l){if(l)return l.map(c=>({url:c.url||null,text:c.text||null}))}let o=r(s.authorStyleSheet),a=r(s.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:hb(e)||t,document:s.documentObject,fragment:s.fragment,authorStyleSheet:o,userStyleSheet:a},ol(this.options));this.initialized?this.adaptViewer_.sendCommand(h):(this.initialized=!0,this.adaptViewer_.initEmbed(h))}getCurrentPageProgression(){return this.adaptViewer_.getCurrentPageProgression()}resolveNavigation(e){switch(e){case"left":return this.getCurrentPageProgression()===rl.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===rl.LTR?"next":"previous";default:return e}}navigateToPage(e,t){e==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:t}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(e)})}navigateToInternalUrl(e){this.adaptViewer_.sendCommand({a:"moveTo",url:e})}navigateToPosition(e){var t,i;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:e.spineIndex,pageIndex:(t=e.pageIndex)!=null?t:-1,offsetInItem:(i=e.offsetInItem)!=null?i:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(e,t){let i=e==null?"toggle":e?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:i,autohide:t})}queryZoomFactor(e){return this.adaptViewer_.queryZoomFactor(e)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var e,t;return(t=(e=this.adaptViewer_.opfView)==null?void 0:e.tocView)==null?void 0:t.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}};function hb(e){function t(n){return typeof n=="number"?n:null}function i(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(e)?e.map(i):e?[i(e)]:null}var mc=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(mc||{}),ub=pc,cb=dc;nt.forceRegisterEndTiming("load_vivliostyle");var db=class{constructor(e,{title:t="",printCallback:i=o=>o.print(),errorCallback:n=null,hideIframe:s=!0,removeIframe:r=!0}){u(this,"htmlDoc"),u(this,"title"),u(this,"printCallback"),u(this,"errorCallback"),u(this,"hideIframe"),u(this,"removeIframe"),u(this,"iframe"),u(this,"iframeWin"),u(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=s,this.removeIframe=r}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
|
+
`),i.toString()}},Xm=class{constructor(e){this.deobfuscator=e,u(this,"familyMap",{})}registerFamily(e,t){let i=e.family,n=this.familyMap[i],s=t.family;if(n){if(n!=s)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${e.family}`)}else this.familyMap[i]=s}filterFontFamily(e){if(e instanceof Ye){let t=e.values,i=[];for(let n of t){let s=this.familyMap[n.stringValue()];s&&i.push(B(s)),i.push(n)}return new Ye(i)}else{let t=this.familyMap[e.stringValue()];return t?new Ye([B(t),e]):e}}},qm=class{constructor(e,t,i){this.head=e,this.body=t,u(this,"srcURLMap",{}),u(this,"familyPrefix"),u(this,"familyCounter",0),this.familyPrefix=i||"Fnt_"}getViewFontFamily(e,t){let i=e.family,n=t.familyMap[i];return n||(n=this.familyPrefix+ ++this.familyCounter,t.familyMap[i]=n,n)}initFont(e,t,i){let n=F("initFont"),s=e.src,r={};for(let l of xo(e.properties))r[l]=e.properties[l];let o=this.getViewFontFamily(e,i);r["font-family"]=B(o);let a=new Wu(r),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(s,t),this.head.appendChild(h),H.debug("Load font:",s),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i,s=this.srcURLMap[n];return s?s.piggyback(r=>{let o=r;o.traitsEqual(e)?(t.registerFamily(e,o),H.debug("Found already-loaded font:",i)):H.warn("E_FONT_FACE_INCOMPATIBLE",e.src)}):(s=new Cn(()=>{let r=F("loadFont"),o=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(o):null;return a?bs(o,"blob").then(h=>{if(!h.responseBlob){r.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(e,l,t).thenFinish(r)})}):this.initFont(e,null,t).thenFinish(r),r.result()},`loadFont ${i}`),this.srcURLMap[n]=s,s.start()),s}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){H.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return ws(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(s=>{}))}),t===0)return N(!0);let i=F("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?N(!0):N(!1))).thenFinish(i),i.result()}},Ym=1,Cs=class{constructor(e,t,i,n,s){this.name=t,this.pseudoName=i,this.classes=n,this.parent=s,u(this,"specified",{}),u(this,"children",[]),u(this,"pageMaster",null),u(this,"index",0),u(this,"key"),u(this,"_scope"),this._scope=e,this.key=`p${Ym++}`,s&&(this.index=s.children.length,s.children.push(this))}get scope(){return this._scope}createInstance(e){throw new Error("E_UNEXPECTED_CALL")}clone(e){throw new Error("E_UNEXPECTED_CALL")}copySpecified(e){let t=this.specified,i=e.specified;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n])}cloneChildren(e){for(let t=0;t<this.children.length;t++)this.children[t].clone({parent:e})}},Zm=class extends Cs{constructor(e){super(e,null,null,[],null),this.specified.width=new Z(xn,0),this.specified.height=new Z(Sn,0)}},Ua=class extends Zs{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(s,r){let o=s.match(/^([^.]+)\.([^.]+)$/);if(o){let a=i.pageMaster.keyMap[o[1]];if(a){let h=this.lookupInstance(a);if(h)return r?h.resolveFunc(o[2]):h.resolveName(o[2])}}return null}}},ju=class Xu extends Cs{constructor(t,i,n,s,r,o,a){super(t,i,n,s,r),this.condition=o,this.specificity=a,u(this,"keyMap",{}),t instanceof Ua||(this._scope=new Ua(t,this)),this.pageMaster=this,this.specified.width=new Z(xn,0),this.specified.height=new Z(Sn,0),this.specified["wrap-flow"]=new Z(v.auto,0),this.specified.position=new Z(v.relative,0),this.specified.overflow=new Z(v.visible,0)}createInstance(t){return new Co(t,this)}clone(t){let i=new Xu(this.scope,this.name,t.pseudoName||this.pseudoName,this.classes,this.parent,this.condition,this.specificity);return this.copySpecified(i),this.cloneChildren(i),i}resetScope(){this.scope.pageMaster=this}},qu=class Yu extends Cs{constructor(t,i,n,s,r){super(t,i,n,s,r),this.pageMaster=r.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new Z(v.auto,0)}createInstance(t){return new ew(t,this)}clone(t){let i=new Yu(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},Tn=class Zu extends Cs{constructor(t,i,n,s,r){super(t,i,n,s,r),this.pageMaster=r.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new Ii(t,this)}clone(t){let i=new Zu(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function Km(e,t,i){return!t||K(t)?new Fe(e,i):t.toExpr(e,e.zero)}function ae(e,t,i){return!t||t===v.auto||K(t)?null:t.toExpr(e,i)}function Jm(e,t,i){return!t||t===v.normal||K(t)?null:t.toExpr(e,i)}function st(e,t,i){return!t||t===v.auto||K(t)?e.zero:t.toExpr(e,i)}function Ha(e,t,i){return!t||K(t)?e.zero:t===v.auto?null:t.toExpr(e,i)}function Ct(e,t,i,n){return!t||i===v.none||K(t)?e.zero:t.toExpr(e,n)}function Ku(e,t,i){return!t||K(t)?i:t===v._true?e._true:t===v._false?e._false:t.toExpr(e,e.zero)}var Es=class{constructor(e,t){this.parentInstance=e,this.pageBox=t,u(this,"cascaded",{}),u(this,"style",{}),u(this,"autoWidth",null),u(this,"autoHeight",null),u(this,"children",[]),u(this,"isAutoWidth",!1),u(this,"isAutoHeight",!1),u(this,"isTopDependentOnAutoHeight",!1),u(this,"isRightDependentOnAutoWidth",!1),u(this,"calculatedWidth",0),u(this,"calculatedHeight",0),u(this,"pageMasterInstance",null),u(this,"namedValues",{}),u(this,"namedFuncs",{}),u(this,"vertical",!1),u(this,"rtl",!1),u(this,"suppressEmptyBoxGeneration",!1),u(this,"borderBoxSizing",!1),e&&e.children.push(this)}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(e,t){let i=this.resolveName(e),n=this.resolveName(t);if(!i||!n)throw new Error("E_INTERNAL");return X(this.pageBox.scope,i,n)}resolveName(e){let t=this.namedValues[e];if(t)return t;let i=this.style[e];switch(i&&(t=i.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),e){case"margin-left-edge":t=this.resolveName("left");break;case"margin-top-edge":t=this.resolveName("top");break;case"margin-right-edge":t=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":t=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":t=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":t=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":t=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":t=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":t=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":t=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":t=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":t=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":t=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":t=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":t=this.addNamedValues("left-edge","width");break;case"bottom-edge":t=this.addNamedValues("top-edge","height");break}if(!t){let n;if(e=="extent")n=this.vertical?"width":"height";else if(e=="measure")n=this.vertical?"height":"width";else{let s=this.vertical?jh:Xh;n=e;for(let r in s)n=n.replace(r,s[r])}n!=e&&(t=this.resolveName(n))}return t&&(this.namedValues[e]=t),t}resolveFunc(e){let t=this.namedFuncs[e];if(t)return t;switch(e){case"columns":{let i=this.pageBox.scope,n=new zl(i,0),s=this.resolveName("column-count"),r=this.resolveName("column-width"),o=this.resolveName("column-gap");t=re(i,Un(i,new Zi(i,"min",[n,s]),X(i,r,o)),o);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=Ku(e,t.enabled,e._true),n=ae(e,t.page,e.zero);if(n){let o=new Ie(e,"page-number");i=pt(e,i,new Xr(e,n,o))}let s=ae(e,t["min-page-width"],e.zero);s&&(i=pt(e,i,new Js(e,new Ie(e,"page-width"),s)));let r=ae(e,t["min-page-height"],e.zero);r&&(i=pt(e,i,new Js(e,new Ie(e,"page-height"),r))),i=this.boxSpecificEnabled(i),t.enabled=new D(i)}boxSpecificEnabled(e){return e}initHorizontal(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=ae(e,t.left,i),s=ae(e,t["margin-left"],i),r=Ct(e,t["border-left-width"],t["border-left-style"],i),o=st(e,t["padding-left"],i),a=ae(e,t.width,i),h=ae(e,t["max-width"],i),l=st(e,t["padding-right"],i),c=Ct(e,t["border-right-width"],t["border-right-style"],i),p=ae(e,t["margin-right"],i),d=ae(e,t.right,i),f=X(e,r,o),m=X(e,r,l);if(n&&d&&a){let y=re(e,i,X(e,a,X(e,X(e,n,f),m)));s?p?d=re(e,y,p):p=re(e,y,X(e,d,s)):(y=re(e,y,d),p?s=re(e,y,p):(s=Un(e,y,new Fe(e,.5)),p=s))}else{s||(s=e.zero),p||(p=e.zero),!n&&!d&&!a&&(n=e.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!d?n=e.zero:!a&&!d&&(a=this.autoWidth,this.isAutoWidth=!0);let y=re(e,i,X(e,X(e,s,f),X(e,p,m)));this.isAutoWidth&&(h||(h=re(e,y,n||d)),!this.vertical&&(ae(e,t["column-width"],null)||ae(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?d||(d=re(e,y,X(e,n,a))):a=re(e,y,X(e,n,d)):n=re(e,y,X(e,d,a))}let g=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=st(e,g,i);t.left=new D(n),t["margin-left"]=new D(s),t["border-left-width"]=new D(r),t["padding-left"]=new D(o),t.width=new D(a),t["max-width"]=new D(h||a),t["padding-right"]=new D(l),t["border-right-width"]=new D(c),t["margin-right"]=new D(p),t.right=new D(d),t["snap-width"]=new D(w)}initVertical(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(e,null):null,s=ae(e,t.top,n),r=ae(e,t["margin-top"],i),o=Ct(e,t["border-top-width"],t["border-top-style"],i),a=st(e,t["padding-top"],i),h=ae(e,t.height,n),l=ae(e,t["max-height"],n),c=st(e,t["padding-bottom"],i),p=Ct(e,t["border-bottom-width"],t["border-bottom-style"],i),d=ae(e,t["margin-bottom"],i),f=ae(e,t.bottom,n),m=X(e,o,a),g=X(e,p,c);if(s&&f&&h){let b=re(e,n,X(e,h,X(e,X(e,s,m),g)));r?d?f=re(e,b,r):d=re(e,b,X(e,f,r)):(b=re(e,b,f),d?r=re(e,b,d):(r=Un(e,b,new Fe(e,.5)),d=r))}else{r||(r=e.zero),d||(d=e.zero),!s&&!f&&!h&&(s=e.zero),!s&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!s&&!f?s=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let b=re(e,n,X(e,X(e,r,m),X(e,d,g)));this.isAutoHeight&&(l||(l=re(e,b,s||f)),this.vertical&&(ae(e,t["column-width"],null)||ae(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),s?h?f||(f=re(e,b,X(e,s,h))):h=re(e,b,X(e,f,s)):s=re(e,b,X(e,f,h))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),y=st(e,w,i);t.top=new D(s),t["margin-top"]=new D(r),t["border-top-width"]=new D(o),t["padding-top"]=new D(a),t.height=new D(h),t["max-height"]=new D(l||h),t["padding-bottom"]=new D(c),t["border-bottom-width"]=new D(p),t["margin-bottom"]=new D(d),t.bottom=new D(f),t["snap-height"]=new D(y)}initColumns(){let e=this.pageBox.scope,t=this.style,i=ae(e,t[this.vertical?"height":"width"],null),n=ae(e,t["column-width"],i),s=ae(e,t["column-count"],null),r=Jm(e,t["column-gap"],null);r||(r=new yn(e,1,"em")),n&&!s&&(s=new Zi(e,"floor",[Qs(e,X(e,i,r),X(e,n,r))]),s=new Zi(e,"max",[e.one,s])),s||(s=e.one),n=re(e,Qs(e,X(e,i,r),s),r),t["column-width"]=new D(n),t["column-count"]=new D(s),t["column-gap"]=new D(r)}depends(e,t,i){return this.style[e].toExpr(this.pageBox.scope,null).depend(t,i)}init(e){var t;e.registerInstance(this.pageBox.key,this);let i=this.pageBox.scope,n=this.style,s=this.parentInstance?this.parentInstance.getActiveRegions(e):null,r=cu(this.cascaded,e,s,!1,null);this.vertical=hu(r,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=uu(r,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=r["box-sizing"])==null?void 0:t.value)===v.border_box;let o=!!(e instanceof To&&e.currentLayoutPosition&&new Ie(i,"left-page").evaluate(e));pu(r,n,this.vertical,this.rtl,o,(a,h)=>h.value),this.autoWidth=new Te(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new Te(i,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(e,t){var i,n;let s=this.style[t];return!s&&tn(t)&&this.pageMasterInstance instanceof Ei&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?s=new I(e.rootFontSize,"px"):s=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),s&&(s=as(e,s,t)),s}getPropAsNumber(e,t){var i,n;let s=this.style[t];if(s){let r=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();s=as(e,s,t,r)}return We(s,e)}getSpecial(e,t){let i=Zh(this.cascaded,t);if(i){let n=[];for(let s=0;s<i.length;s++){let r=i[s].evaluate(e,"");r&&r!==G&&n.push(r)}if(n.length)return n}return null}getActiveRegions(e){let t=this.getSpecial(e,"region-id");if(t){let i=[];for(let n=0;n<t.length;n++)i[n]=t[n].toString();return i}return null}propagateProperty(e,t,i,n){this.propagatePropertyToElement(e,t.element,i,n)}propagatePropertyToElement(e,t,i,n){let s=this.getProp(e,i);s&&(s.isNumeric()&&Pl(s.unit)&&(s=Wl(s,e)),i==="font-family"&&(s=n.filterFontFamily(s)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),P(t,i,s.toString()))}propagateDelayedProperty(e,t,i,n){let s=this.getProp(e,i);s&&n.push(new to(t.element,i,s))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),s=this.getPropAsNumber(e,"padding-left"),r=this.getPropAsNumber(e,"border-left-width"),o=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,o),P(t.element,"margin-left",`${n}px`),P(t.element,"padding-left",`${s}px`),P(t.element,"border-left-width",`${r}px`),t.marginLeft=n,t.borderLeft=r,t.paddingLeft=s}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),s=this.getPropAsNumber(e,"margin-right"),r=this.getPropAsNumber(e,"padding-right"),o=this.getPropAsNumber(e,"border-right-width");if(P(t.element,"margin-right",`${s}px`),P(t.element,"padding-right",`${r}px`),P(t.element,"border-right-width",`${o}px`),t.marginRight=s,t.borderRight=o,this.vertical&&n>0){let a=i+t.getInsetRight(),h=a-Math.floor(a/n)*n;h>0&&(t.snapOffsetX=n-h,r+=t.snapOffsetX)}t.paddingRight=r,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),s=this.getPropAsNumber(e,"margin-top"),r=this.getPropAsNumber(e,"padding-top"),o=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=s,t.borderTop=o,t.snapHeight=i,!this.vertical&&i>0){let a=n+t.getInsetTop(),h=a-Math.floor(a/i)*i;h>0&&(t.snapOffsetY=i-h,r+=t.snapOffsetY)}t.paddingTop=r,P(t.element,"top",`${n}px`),P(t.element,"margin-top",`${s}px`),P(t.element,"padding-top",`${r}px`),P(t.element,"border-top-width",`${o}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),s=this.getPropAsNumber(e,"border-bottom-width"),r=this.getPropAsNumber(e,"height")-t.snapOffsetY;P(t.element,"height",`${r}px`),P(t.element,"margin-bottom",`${i}px`),P(t.element,"padding-bottom",`${n}px`),P(t.element,"border-bottom-width",`${s}px`),t.height=r-t.snapOffsetY,t.marginBottom=i,t.borderBottom=s,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){P(t.element,"border-top-width","0px");let i=this.getPropAsNumber(e,"max-height");this.isTopDependentOnAutoHeight?t.setVerticalPosition(0,i):(this.assignTopPosition(e,t),i-=t.snapOffsetY,t.height=i,P(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){P(t.element,"border-left-width","0px");let i=this.getPropAsNumber(e,"max-width");if(this.isRightDependentOnAutoWidth)t.setHorizontalPosition(0,i);else{this.assignRightPosition(e,t),i-=t.snapOffsetX,t.width=i;let n=this.getPropAsNumber(e,"right");P(t.element,"right",`${n}px`),P(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,s){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&P(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&P(t.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(e,t):this.sizeWithMaxHeight(e,t):(this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(e,t):this.sizeWithMaxWidth(e,t):this.assignStartEndPosition(e,t);for(let r=0;r<$a.length;r++)this.propagateProperty(e,t,$a[r],n)}transferContentProps(e,t,i,n){for(let s=0;s<Wa.length;s++)this.propagateProperty(e,t,Wa[s],n);if(this.style["text-overflow"]){let s=t.element.firstElementChild;P(s,"text-overflow","inherit"),P(s,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var r,o;let a=(o=(r=this.cascaded.width)!=null?r:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:o.value;return!!a&&a!==v.auto&&!K(a)},s=()=>{var r,o;let a=(o=(r=this.cascaded.height)!=null?r:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:o.value;return!!a&&a!==v.auto&&!K(a)};for(let r=0;r<ja.length;r++){let o=ja[r];if(o==="width"||o==="height"){if(o==="width"&&!n()||o==="height"&&!s())continue;P(t,o,"100%");continue}this.propagatePropertyToElement(e,t,o,i)}}finishContainer(e,t,i,n,s,r,o){this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let a=(this.vertical||!n)&&this.isAutoHeight,h=(!this.vertical||!n)&&this.isAutoWidth,l=null;if(h||a){h&&P(t.element,"width","auto"),a&&P(t.element,"height","auto");let c=n&&Dh(n);c&&zh(n),l=r.getElementClientRect(n?n.element:t.element),c&&no(n),h&&(this.calculatedWidth=Math.ceil(l.right-l.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),a&&(this.calculatedHeight=l.bottom-l.top-t.paddingTop-t.borderTop-t.paddingBottom-t.borderBottom,this.vertical||(this.calculatedHeight+=t.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(e,t),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),s>1){let c=this.getPropAsNumber(e,"column-rule-width"),p=this.getProp(e,"column-rule-style"),d=this.getProp(e,"column-rule-color");if(c>0&&p&&p!=v.none&&d!=v.transparent){let f=this.getPropAsNumber(e,"column-gap"),m=this.vertical?t.height:t.width,g=this.vertical?"border-top":"border-left";for(let w=1;w<s;w++){let y=this.vertical?(m+f)*w/s-f/2+t.paddingTop-c/2:(m+f)*w/s-f/2+t.paddingLeft-c/2,b=this.vertical?t.width+t.paddingLeft+t.paddingRight:t.height+t.paddingTop+t.paddingBottom,S=t.element.ownerDocument.createElement("div");P(S,"position","absolute"),P(S,this.vertical?"left":"top","0px"),P(S,this.vertical?"top":"left",`${y}px`),P(S,this.vertical?"height":"width","0px"),P(S,this.vertical?"width":"height",`${b}px`),P(S,g,`${c}px ${p.toString()}${d?` ${d.toString()}`:""}`),t.element.insertBefore(S,t.element.firstChild)}}}for(let c=0;c<Ga.length;c++)this.propagateProperty(e,t,Ga[c],o);for(let c=0;c<Xa.length;c++)this.propagateDelayedProperty(e,t,Xa[c],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let r in n)this instanceof Ei&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(r==="writing-mode"||r==="direction")||Si(r)&&ei(i,r,Ue(n,r));if(this.pageBox.pseudoName==So)for(let r in t)(r.match(/^background-/)||r=="writing-mode")&&(i[r]=t[r]);if(this.pageBox.pseudoName=="layout-host")for(let r in t)!r.match(/^background-/)&&r!="writing-mode"&&(i[r]=t[r]);e.pushRule(this.pageBox.classes,null,i);let s=i.content;s&&(i.content=s.filterValue(new Nr(e,null,e.counterResolver))),this.init(e.context);for(let r of this.pageBox.children)r.createInstance(this).applyCascadeAndInit(e,t);e.popRule()}resolveAutoSizing(e){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,e)||this.depends("margin-right",this.autoWidth,e)||this.depends("border-right-width",this.autoWidth,e)||this.depends("padding-right",this.autoWidth,e)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,e)||this.depends("margin-top",this.autoHeight,e)||this.depends("border-top-width",this.autoHeight,e)||this.depends("padding-top",this.autoHeight,e));for(let t of this.children)t.resolveAutoSizing(e)}},$a=["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"],Ga=["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"],Wa=["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"],ja=["width","height","image-resolution","object-fit","object-position"],Xa=["transform","transform-origin"],So="background-host",Qm=class extends Es{constructor(e){super(null,e)}applyCascadeAndInit(e,t){super.applyCascadeAndInit(e,t),this.children.sort((i,n)=>n.pageBox.specificity-i.pageBox.specificity||i.pageBox.index-n.pageBox.index)}},Co=class extends Es{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=pt(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},ew=class extends Es{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},Ii=class extends Es{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof rt&&(n=[t]),t instanceof Ye&&(n=t.values),n){let s=this.pageBox.scope;for(let r=0;r<n.length;r++)if(n[r]instanceof rt){let o=Ys(n[r].name,"enabled"),a=new Ie(s,o);i&&(a=new Ut(s,a)),e=pt(s,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=Ku(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let s=Km(t,i["flow-from"],"body"),r=new Zi(t,"has-content",[s]);e=pt(t,e,r)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let s=this.pageMasterInstance.style.enabled,r=s?s.toExpr(t,null):t._true;r=pt(t,r,e),this.pageMasterInstance.style.enabled=new D(r)}return e}prepareContainer(e,t,i,n,s){var r;this.pageBox.pageMaster instanceof ic||(P(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(r=this.pageBox.name)!=null?r:"")),super.prepareContainer(e,t,i,n,s)}},Eo=class extends En{constructor(e,t,i,n){super(e,t,!1),this.target=i,this.validatorSet=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}simpleProperty(e,t,i){this.target.specified[e]=new Z(t,i?ch:dh)}},Ju=class extends Eo{constructor(e,t,i,n){super(e,t,i,n)}},tw=class Qu extends Eo{constructor(t,i,n,s){super(t,i,n,s),n.specified.width=new Z(Yo,0),n.specified.height=new Z(Yo,0)}startPartitionRule(t,i,n){let s=new Tn(this.scope,t,i,n,this.target),r=new Ju(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(t,i,n){let s=new qu(this.scope,t,i,n,this.target),r=new Qu(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}},iw=class extends Eo{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new Tn(this.scope,e,t,i,this.target),s=new Ju(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(e,t,i){let n=new qu(this.scope,e,t,i,this.target),s=new tw(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}};function ec(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,s=(i=e.direction)==null?void 0:i.value;return n===v.vertical_lr||n!==v.vertical_rl&&s!==v.rtl?"ltr":"rtl"}var nw={a10:{width:new I(26,"mm"),height:new I(37,"mm")},a9:{width:new I(37,"mm"),height:new I(52,"mm")},a8:{width:new I(52,"mm"),height:new I(74,"mm")},a7:{width:new I(74,"mm"),height:new I(105,"mm")},a6:{width:new I(105,"mm"),height:new I(148,"mm")},a5:{width:new I(148,"mm"),height:new I(210,"mm")},a4:{width:new I(210,"mm"),height:new I(297,"mm")},a3:{width:new I(297,"mm"),height:new I(420,"mm")},a2:{width:new I(420,"mm"),height:new I(594,"mm")},a1:{width:new I(594,"mm"),height:new I(841,"mm")},a0:{width:new I(841,"mm"),height:new I(1189,"mm")},b10:{width:new I(31,"mm"),height:new I(44,"mm")},b9:{width:new I(44,"mm"),height:new I(62,"mm")},b8:{width:new I(62,"mm"),height:new I(88,"mm")},b7:{width:new I(88,"mm"),height:new I(125,"mm")},b6:{width:new I(125,"mm"),height:new I(176,"mm")},b5:{width:new I(176,"mm"),height:new I(250,"mm")},b4:{width:new I(250,"mm"),height:new I(353,"mm")},b3:{width:new I(353,"mm"),height:new I(500,"mm")},b2:{width:new I(500,"mm"),height:new I(707,"mm")},b1:{width:new I(707,"mm"),height:new I(1e3,"mm")},b0:{width:new I(1e3,"mm"),height:new I(1414,"mm")},c10:{width:new I(28,"mm"),height:new I(40,"mm")},c9:{width:new I(40,"mm"),height:new I(57,"mm")},c8:{width:new I(57,"mm"),height:new I(81,"mm")},c7:{width:new I(81,"mm"),height:new I(114,"mm")},c6:{width:new I(114,"mm"),height:new I(162,"mm")},c5:{width:new I(162,"mm"),height:new I(229,"mm")},c4:{width:new I(229,"mm"),height:new I(324,"mm")},c3:{width:new I(324,"mm"),height:new I(458,"mm")},c2:{width:new I(458,"mm"),height:new I(648,"mm")},c1:{width:new I(648,"mm"),height:new I(917,"mm")},c0:{width:new I(917,"mm"),height:new I(1297,"mm")},"jis-b10":{width:new I(32,"mm"),height:new I(45,"mm")},"jis-b9":{width:new I(45,"mm"),height:new I(64,"mm")},"jis-b8":{width:new I(64,"mm"),height:new I(91,"mm")},"jis-b7":{width:new I(91,"mm"),height:new I(128,"mm")},"jis-b6":{width:new I(128,"mm"),height:new I(182,"mm")},"jis-b5":{width:new I(182,"mm"),height:new I(257,"mm")},"jis-b4":{width:new I(257,"mm"),height:new I(364,"mm")},"jis-b3":{width:new I(364,"mm"),height:new I(515,"mm")},"jis-b2":{width:new I(515,"mm"),height:new I(728,"mm")},"jis-b1":{width:new I(728,"mm"),height:new I(1030,"mm")},"jis-b0":{width:new I(1030,"mm"),height:new I(1456,"mm")},letter:{width:new I(8.5,"in"),height:new I(11,"in")},legal:{width:new I(8.5,"in"),height:new I(14,"in")},ledger:{width:new I(11,"in"),height:new I(17,"in")}},sw=new I(.24,"pt"),yb=new I(3,"mm"),rw=new I(10,"mm"),ow=new I(13,"mm");function us(e){let t={width:xn,height:Sn,bleed:ge,bleedOffset:ge,cropOffset:ge},i=e.size;if(!(!i||i.value===v.auto)){let l=i.value,c,p;if(l.isSpaceList()?(c=l.values[0],p=l.values[1]):(c=l,p=null),c.isNumeric())t.width=c,t.height=p||c;else{let d=c.name&&nw[c.name.toLowerCase()];d&&(p&&p===v.landscape?(t.width=d.height,t.height=d.width):(t.width=d.width,t.height=d.height))}}let n=e.marks,s=e.bleed,r=n&&!K(n.value)?n.value:v.none,o=s&&!K(s.value)?s.value:v.auto;if(o===v.auto){if(r!==v.none){let l=!1;r.isSpaceList()?l=r.values.some(c=>c===v.crop):l=r===v.crop,l&&(t.bleed=new I(6,"pt"))}}else o.isNumeric()&&(t.bleed=o);let a=e["crop-offset"],h=a&&!K(a.value)?a.value:v.auto;return h===v.auto?r!==v.none&&(t.bleedOffset=ow):h.isNumeric()&&(t.cropOffset=h),t}function qa(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),s=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),r=n+s,o=e.width;o===xn?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-r*2:i.pageWidth=o.num*t.queryUnitSize(o.unit,!1);let a=e.height;return a===Sn?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-r*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=s,i.cropOffset=r,i}function tc(e,t,i){let n=e.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("width",t),n.setAttribute("height",i),n.style.position="absolute",n}function on(e,t,i,n){n=n||"polyline";let s=e.createElementNS("http://www.w3.org/2000/svg",n);return s.setAttribute("stroke",i===v.auto?"#010101":i.toString()),s.setAttribute("stroke-width",t),s.setAttribute("fill","none"),s}var Or=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(Or||{});function aw(e,t,i,n,s,r,o){let a=s;a<=r+2*pe.mm&&(a=r+s/2);let h=Math.max(s,a),l=r+h+i/2,c=tc(e,l,l),p=[[0,r+s],[s,r+s],[s,r+s-a]],d=p.map(g=>[g[1],g[0]]);(t==="top right"||t==="bottom right")&&(p=p.map(g=>[r+h-g[0],g[1]]),d=d.map(g=>[r+h-g[0],g[1]])),(t==="bottom left"||t==="bottom right")&&(p=p.map(g=>[g[0],r+h-g[1]]),d=d.map(g=>[g[0],r+h-g[1]]));let f=on(e,i,n);f.setAttribute("points",p.map(g=>g.join(",")).join(" ")),c.appendChild(f);let m=on(e,i,n);return m.setAttribute("points",d.map(g=>g.join(",")).join(" ")),c.appendChild(m),t.split(" ").forEach(g=>{c.style[g]=`${o}px`}),c}var mn=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(mn||{});function lw(e,t,i,n,s,r){let o=s*2,a,h;t==="top"||t==="bottom"?(a=o,h=s):(a=s,h=o);let l=tc(e,a,h),c=on(e,i,n);c.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(c);let p=on(e,i,n);p.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(p);let d=on(e,i,n,"circle");d.setAttribute("cx",a/2),d.setAttribute("cy",h/2),d.setAttribute("r",s/4),l.appendChild(d);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(mn).forEach(m=>{let g=mn[m];g===t?l.style[g]=`${r}px`:g!==f&&(l.style[g]="0",l.style[`margin-${g}`]="auto")}),l}function hw(e,t,i,n){let s=!1,r=!1,o=e.marks;if(o){let g=o.value;g instanceof me?g.values.forEach(w=>{w===v.crop?s=!0:w===v.cross&&(r=!0)}):g===v.crop?s=!0:g===v.cross&&(r=!0)}let a=t.bleed;if(!s&&!r)return;let h=i.container,l=h.ownerDocument,c=We(sw,n),p=Math.max(0,t.bleedOffset-We(rw,n)),d=t.bleedOffset-p,f=e["crop-marks-line-color"],m=f&&!K(f.value)?f.value:v.auto;s&&Object.keys(Or).forEach(g=>{let w=Or[g],y=aw(l,w,c,m,d,a,p);h.appendChild(y)}),r&&Object.keys(mn).forEach(g=>{let w=mn[g],y=lw(l,w,c,m,d,p);h.appendChild(y)})}var Br=(()=>{let e=["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 e.forEach(i=>{t[`margin-${i}`]=!0,t[`padding-${i}`]=!0,t[`border-${i}-width`]=!0,t[`border-${i}-style`]=!0,t[`border-${i}-color`]=!0}),t})(),ko={"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"}},uw=(()=>{let e=ko;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),No="vivliostyle-page-rule-master",wn="_marginBoxes",ic=class extends ju{constructor(e,t,i){super(e,null,No,[],t,null,0),u(this,"pageMarginBoxes",{});let n=us(i),s=new cw(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[wn];t&&uw.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new pw(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new Z(v.relative,0),this.specified.width=new Z(t.width,0),this.specified.height=new Z(t.height,0);for(let i in e)!Br[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new Ei(e,this)}},cw=class extends Tn{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let s=new dw(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new Z(v.auto,0),this.specified["z-index"]=new Z(new ni(0),0),this.specified.position=new Z(v.absolute,0),this.specified.overflow=new Z(v.visible,0);for(let t in Br)Br.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new gw(e,this)}},dw=class extends Tn{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new Z(B("body"),0)}createInstance(e){return new nc(e,this)}},pw=class extends Tn{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[wn][this.marginBoxName];for(let i in e){let n=e[i],s=t[i];(Wh[i]||s&&s.value===v.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==G&&n.value!==v.inherit&&n.value!==v.unset&&n.value!==v.revert&&(this.specified[i]=n)}}createInstance(e){return new sc(e,this)}},Ei=class extends Co{constructor(e,t){super(e,t),u(this,"pageAreaDimension",null),u(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,t){let i=this.cascaded;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n))switch(n){case"writing-mode":case"direction":i[n]=t[n]}super.applyCascadeAndInit(e,t)}initHorizontal(){let e=this.style;e.left=ge,e["margin-left"]=ge,e["border-left-width"]=ge,e["padding-left"]=ge,e["padding-right"]=ge,e["border-right-width"]=ge,e["margin-right"]=ge,e.right=ge}initVertical(){let e=this.style;e.top=ge,e["margin-top"]=ge,e["border-top-width"]=ge,e["padding-top"]=ge,e["padding-bottom"]=ge,e["border-bottom-width"]=ge,e["margin-bottom"]=ge,e.bottom=ge}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new D(e.borderBoxWidth),t.height=new D(e.borderBoxHeight),t["padding-left"]=new D(e.marginLeft),t["padding-right"]=new D(e.marginRight),t["padding-top"]=new D(e.marginTop),t["padding-bottom"]=new D(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,s={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},r={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,r,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,s){let r="start",o="center",a="end",h=this.pageBox.scope,l={},c={},p={};for(let S in e){let T=ko[S];if(T){let R=e[S],M=this.pageMarginBoxInstances[S],V=new Xn(R,M.style,t,h,s);l[T.positionAlongVariableDimension]=R,c[T.positionAlongVariableDimension]=M,p[T.positionAlongVariableDimension]=V}}let d={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),m=!1,g={};Object.keys(l).forEach(S=>{let T=S,R=ae(h,c[T].style[t?"max-width":"max-height"],i.extent);if(R){let M=R.evaluate(n);if(f[T]>M){let V=p[T]=new Ya(l[T],c[T].style,t,h,s,M);g[T]=V.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),m=!1,[r,o,a].forEach(S=>{var T;f[S]=(T=g[S])!=null?T:f[S]}));let w={};Object.keys(l).forEach(S=>{let T=S,R=ae(h,c[T].style[t?"min-width":"min-height"],i.extent);if(R){let M=R.evaluate(n);if(f[T]<M){let V=p[T]=new Ya(l[T],c[T].style,t,h,s,M);w[T]=V.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),[r,o,a].forEach(S=>{f[S]=w[S]||f[S]}));let y=d.start+d.extent,b=d.start+(d.start+d.extent);[r,o,a].forEach(S=>{let T=f[S];if(T!=null){let R=l[S],M=0;switch(S){case r:M=t?R.left:R.top;break;case o:M=(b-T)/2;break;case a:M=y-T;break}t?R.setHorizontalPosition(M,T-R.getInsetLeft()-R.getInsetRight()):R.setVerticalPosition(M,T-R.getInsetTop()-R.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,s=e.center,r=e.end,o={};if(s){let a=[n,r],h=new fw(a),l=this.distributeAutoMarginBoxSizes(s,h,t);l.xSize!=null&&(o.center=l.xSize);let c=(i=l.xSize)!=null?i:s.getOuterSize(),p=Math.max((t-c)/2,0);n&&(o.start=n.hasAutoSize()?p:n.getOuterSize()),r&&(o.end=r.hasAutoSize()?p:r.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,r,t);a.xSize!=null&&(o.start=a.xSize),a.ySize!=null&&(o.end=a.ySize)}return o}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e instanceof Xn&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof Xn&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let s=e.getOuterMaxContentSize(),r=t.getOuterMaxContentSize();if(s>0&&r>0){let o=s+r;if(o<i)n.xSize=i*s/o;else{let a=e.getOuterMinContentSize(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(s-a)/(o-l):l>0&&(n.xSize=i*a/l)}n.xSize>0&&(n.ySize=i-n.xSize)}else s>0?n.xSize=i:r>0&&(n.ySize=i)}else e.hasAutoSize()?n.xSize=Math.max(i-t.getOuterSize(),0):t.hasAutoSize()&&(n.ySize=Math.max(i-e.getOuterSize(),0));else e?e.hasAutoSize()&&(n.xSize=i):t&&t.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,s)}},Xn=class{constructor(e,t,i,n,s){this.container=e,this.isHorizontal=i,this.clientLayout=s,u(this,"hasAutoSize_"),u(this,"size",null),u(this,"minMaxFitContent",null);let r=t[i?"width":"height"];if(this.hasAutoSize_=!r||r===v.auto||K(r),this.minMaxFitContent=r instanceof rt&&(r.name==="min-content"||r.name==="max-content"||r.name==="fit-content")?r.name:null,this.minMaxFitContent){let o=this.getSize();if(this.isHorizontal){let a=o[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,a)}else{let a=o[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,a)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let e=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=eo(this.clientLayout,this.container.element,e)}return this.size}getOuterMaxContentSize(){let e=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+e["max-content width"]+this.container.getInsetRight():this.container.getInsetTop()+e["max-content height"]+this.container.getInsetBottom()}getOuterMinContentSize(){let e=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+e["min-content width"]+this.container.getInsetRight():this.container.getInsetTop()+e["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()}},fw=class{constructor(e){this.params=e}hasAutoSize(){return this.params.some(e=>{var t;return(t=e?.hasAutoSize())!=null?t:!1})}getOuterMaxContentSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterMaxContentSize())!=null?i:0});return Math.max.apply(null,e)*e.length}getOuterMinContentSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterMinContentSize())!=null?i:0});return Math.max.apply(null,e)*e.length}getOuterSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterSize())!=null?i:0});return Math.max.apply(null,e)*e.length}},Ya=class extends Xn{constructor(e,t,i,n,s,r){super(e,t,i,n,s),u(this,"fixedSize"),this.fixedSize=r}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()}},gw=class extends Ii{constructor(e,t){super(e,t),u(this,"borderBoxWidth",null),u(this,"borderBoxHeight",null),u(this,"contentBoxWidth",null),u(this,"contentBoxHeight",null),u(this,"marginTop",null),u(this,"marginRight",null),u(this,"marginBottom",null),u(this,"marginLeft",null)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^background-/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,t),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 t=this.style,i=this.pageBox.pageSize,n=this.pageBox.scope,s=e.start,r=e.end,o=e.extent,a=i[o].toExpr(n,null),h=ae(n,t[o],a),l=ae(n,t[`margin-${s}`],a),c=ae(n,t[`margin-${r}`],a),p=st(n,t[`padding-${s}`],a),d=st(n,t[`padding-${r}`],a),f=Ct(n,t[`border-${s}-width`],t[`border-${s}-style`],a),m=Ct(n,t[`border-${r}-width`],t[`border-${r}-style`],a),g=X(n,X(n,f,p),X(n,m,d)),w,y,b;return h?(this.borderBoxSizing?(y=h,b=re(n,y,g)):(b=h,y=X(n,b,g)),w=re(n,a,y),!l&&!c?(l=Un(n,w,new Fe(n,.5)),c=l):l?c=re(n,w,l):l=re(n,w,c)):(l||(l=n.zero),c||(c=n.zero),w=X(n,l,c),y=re(n,a,w),b=re(n,y,g),h=this.borderBoxSizing?y:b),t[s]=new D(l),t[r]=new D(c),t[`margin-${s}`]=ge,t[`margin-${r}`]=ge,t[`border-${s}-width`]=new D(f),t[`border-${r}-width`]=new D(m),t[`padding-${s}`]=new D(p),t[`padding-${r}`]=new D(d),t[o]=new D(h),t[`max-${o}`]=new D(h),{borderBoxExtent:y,contentBoxExtent:b,marginStart:l,marginEnd:c}}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,s),P(t.element,"position","relative"),P(t.element,"inset",""),P(t.element,"display","flow-root")}},nc=class extends Ii{constructor(e,t){super(e,t)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^column.*$/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,{})}initHorizontal(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.left=t["padding-left"],e.width=new D(this.parentInstance.contentBoxWidth),e["margin-left"]=new D(new pi(i,t.left.toExpr(i,null))),e["margin-right"]=new D(new pi(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=v.solid,e["border-right-style"]=v.solid,e["border-left-color"]=v.transparent,e["border-right-color"]=v.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new D(this.parentInstance.contentBoxHeight),e["margin-top"]=new D(new pi(i,t.top.toExpr(i,null))),e["margin-bottom"]=new D(new pi(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=v.solid,e["border-bottom-style"]=v.solid,e["border-top-color"]=v.transparent,e["border-bottom-color"]=v.transparent}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,s),e.pageAreaWidth=parseFloat(i.pageAreaElement.style.width),e.pageAreaHeight=parseFloat(i.pageAreaElement.style.height),P(t.element,"position","relative"),P(t.element,"inset",""),P(t.element,"display","flow-root")}},sc=class extends Ii{constructor(e,t){super(e,t),u(this,"boxInfo"),u(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=ko[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,s)}applyVerticalAlign(e,t){P(t,"display","flex"),P(t,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let i=this.getProp(e,"vertical-align"),n=null;i===B("middle")?n="center":i===B("top")?n="flex-start":i===B("bottom")&&(n="flex-end"),n&&P(t,"justify-content",n);let s=this.getProp(e,"content");if(this.vertical||s instanceof ft||s instanceof D&&s.expr instanceof Te&&s.expr.str.startsWith("running-element-")){let r="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?r=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(r=this.vertical||this.rtl?"end":"start")),P(t,"align-items",r)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,s=e.start,r=e.end,o=e.extent,a=s==="left",h=a?t.borderBoxWidth:t.borderBoxHeight,l=ae(n,i[o],h),c=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[s]=new D(c);else if(l){let p=st(n,i[`margin-${s}`],h),d=st(n,i[`margin-${r}`],h),f=st(n,i[`padding-${s}`],h),m=st(n,i[`padding-${r}`],h),g=Ct(n,i[`border-${s}-width`],i[`border-${s}-style`],h),w=Ct(n,i[`border-${r}-width`],i[`border-${r}-style`],h),y=X(n,l,X(n,this.borderBoxSizing?n.zero:X(n,X(n,f,m),X(n,g,w)),X(n,p,d)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[s]=new D(X(n,c,Qs(n,re(n,h,y),new Fe(n,2))));break;case"end":i[s]=new D(re(n,X(n,c,h),y));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,s=this.borderBoxSizing,r=e.inside,o=e.outside,a=e.extent,h=t[`margin${o.charAt(0).toUpperCase()}${o.substring(1)}`],l=Ha(n,i[`margin-${r}`],h),c=Ha(n,i[`margin-${o}`],h),p=st(n,i[`padding-${r}`],h),d=st(n,i[`padding-${o}`],h),f=Ct(n,i[`border-${r}-width`],i[`border-${r}-style`],h),m=Ct(n,i[`border-${o}-width`],i[`border-${o}-style`],h),g=ae(n,i[a],h),w=null;function y(b){if(w)return w;w={extent:g?g.evaluate(b):null,marginInside:l?l.evaluate(b):null,marginOutside:c?c.evaluate(b):null};let S=h.evaluate(b),T=0;return s||[f,p,d,m].forEach(R=>{R&&(T+=R.evaluate(b))}),(w.marginInside===null||w.marginOutside===null)&&T+w.extent+w.marginInside+w.marginOutside>S&&(w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)),w.extent!==null&&w.marginInside!==null&&w.marginOutside!==null&&(w.marginOutside=null),w.extent===null?(w.extent=S-T-w.marginInside-w.marginOutside,w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)):typeof w.extent=="number"&&(w.marginInside===null&&typeof w.marginOutside=="number"?w.marginInside=S-T-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=S-T-w.extent-w.marginInside:w.marginInside=w.marginOutside=(S-T-w.extent)/2),w}i[a]=new D(new Te(n,function(){let b=y(this).extent;return b===null?"auto":b},a)),i[`margin-${r}`]=new D(new Te(n,function(){let b=y(this).marginInside;return b===null?"auto":b},`margin-${r}`)),i[`margin-${o}`]=new D(new Te(n,function(){let b=y(this).marginOutside;return b===null?"auto":b},`margin-${o}`)),r==="left"?i.left=new D(X(n,t.marginLeft,t.borderBoxWidth)):r==="top"&&(i.top=new D(X(n,t.marginTop,t.borderBoxHeight)))}initHorizontal(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},e):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},e):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},e)}initVertical(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},e):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},e):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},e)}finishContainer(e,t,i,n,s,r,o){super.finishContainer(e,t,i,n,s,r,o);let a=i.marginBoxes,h=this.pageBox.marginBoxName,l=this.boxInfo;!l.isInLeftColumn&&!l.isInRightColumn?l.isInTopRow?a.top[h]=t:l.isInBottomRow&&(a.bottom[h]=t):!l.isInTopRow&&!l.isInBottomRow&&(l.isInLeftColumn?a.left[h]=t:l.isInRightColumn&&(a.right[h]=t));let c=this.parentInstance.pageAreaDimension,p=this.getProp(e,"width"),d=p instanceof rt&&(p.name==="min-content"||p.name==="max-content"||p.name==="fit-content")?p.name:null,f=this.getPropAsNumber(e,"min-width"),m=this.getPropAsNumber(e,"max-width");if(d||f||m){d&&P(t.element,"width",d),f&&P(t.element,"min-width",`${f}px`),m&&P(t.element,"max-width",`${m}px`);let S=this.getProp(e,"margin-left"),T=this.getProp(e,"margin-right");if(l.isInLeftColumn){let R=c.borderBoxWidth.evaluate(e)+c.marginRight.evaluate(e);P(t.element,"right",`${R}px`),(S===v.auto||T!==v.auto)&&P(t.element,"margin-left","auto"),T===v.auto&&P(t.element,"margin-right","auto")}else l.isInRightColumn&&(P(t.element,"right","0"),(T===v.auto||S!==v.auto)&&P(t.element,"margin-right","auto"),S===v.auto&&P(t.element,"margin-left","auto"))}let g=this.getProp(e,"height"),w=g instanceof rt&&(g.name==="min-content"||g.name==="max-content"||g.name==="fit-content")?g.name:null,y=this.getPropAsNumber(e,"min-height"),b=this.getPropAsNumber(e,"max-height");if(w||y||b){w&&P(t.element,"height",w),y&&P(t.element,"min-height",`${y}px`),b&&P(t.element,"max-height",`${b}px`);let S=this.getProp(e,"margin-top"),T=this.getProp(e,"margin-bottom");if(l.isInTopRow){let R=c.borderBoxHeight.evaluate(e)+c.marginBottom.evaluate(e);P(t.element,"bottom",`${R}px`),(S===v.auto||T!==v.auto)&&P(t.element,"margin-top","auto"),T===v.auto&&P(t.element,"margin-bottom","auto")}else l.isInBottomRow&&(P(t.element,"bottom","0"),(T===v.auto||S!==v.auto)&&P(t.element,"margin-bottom","auto"),S===v.auto&&P(t.element,"margin-top","auto"))}}},mw=class{constructor(e,t,i,n,s){this.cascadeInstance=e,this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=s,u(this,"pageMasterCache",{}),this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new Ie(e,"page-number"),s=new Xr(e,new Ol(e,n,new Fe(e,2)),i?e.one:e.zero);e.defineName("recto-page",new Ut(e,s)),e.defineName("verso-page",s),(t.pageProgression||ec(this.docElementStyle))==="ltr"?(e.defineName("left-page",s),e.defineName("right-page",new Ut(e,s))):(e.defineName("left-page",new Ut(e,s)),e.defineName("right-page",s))}getCascadedPageStyle(e){let t={};return this.cascadeInstance.pushRule([],e,t),this.cascadeInstance.popRule(),t}getPageRulePageMaster(e,t){let i=e.pageBox;if(Object.keys(t).length===0)return i.resetScope(),e;let n=this.makeCacheKey(t,i),s=this.pageMasterCache[n];return s||(i.pseudoName===So?s=this.generatePageRuleMaster(t):s=this.generateCascadedPageMaster(t,i),this.pageMasterCache[n]=s),s.pageBox.resetScope(),s}makeCacheKey(e,t){var i;let n=this.makeCascadeValueObjectKey(e),s=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${t.key}^${n}^${s}`}makeCascadeValueObjectKey(e){let t=[];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],s;n instanceof Z?s=`${n.value}`:s=this.makeCascadeValueObjectKey(n),t.push(i+s+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new ic(this.pageScope,this.rootPageBoxInstance.pageBox,e).createInstance(this.rootPageBoxInstance);return t.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),t.resolveAutoSizing(this.context),t}generateCascadedPageMaster(e,t){let i=t.clone({pseudoName:No}),n=i.specified,s=e.size;if(s&&!K(s.value)){let o=us(e),a=s.priority;Lt(n,"width",new Z(o.width,a),this.context),Lt(n,"height",new Z(o.height,a),this.context)}["counter-reset","counter-increment"].forEach(o=>{n[o]&&(e[o]=n[o])});let r=i.createInstance(this.rootPageBoxInstance);return r.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),r.resolveAutoSizing(this.context),r}},ww=class extends de{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}},bw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ie(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},vw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ie(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},yw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ie(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},xw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ie(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Sw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ie(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Cw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ie(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Ew=class extends Pn{constructor(e,t,i){super(t,i),this.scope=e,this.a=t,this.b=i}apply(e){let t=e.context,i=t.layoutPositionAtPageStart.page;t.blankPageAtStart&&i--,i&&this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 2}},kw=class extends uo{constructor(e,t){super(e,t,null,null,null)}apply(e){Nw(e.context,e.currentStyle,this.style,this.specificity,e)}};function Nw(e,t,i,n,s){os(e,t,i,n,null,null,null);let r=i[wn];if(r){let o=ys(t,wn);for(let a in r)if(r.hasOwnProperty(a)){let h=o[a];h||(h={},o[a]=h),os(e,h,r[a],n,null,null,null)}}}var Pw=class extends cn{constructor(e,t,i,n,s){super(e,t,i?.condition,i,null,n,!1),this.pageProps=s,u(this,"currentPageSelectors",[]),u(this,"currentNamedPageSelector",""),u(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new ww(t)),this.specificity+=65536)}pseudoclassSelector(e,t){if(e=e.toLowerCase(),t)switch(e){case"nth":{let[i,n]=t;this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new Ew(this.scope,i,n)),this.specificity+=256}break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}(${t.join("")})`);break}else switch(this.currentPseudoPageClassSelectors.push(`:${e}`),e){case"first":this.chain.push(new bw(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new vw(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new yw(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new xw(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new Sw(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Cw(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,t,i){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(r=>r.selectors===null))return;super.simpleProperty(e,t,i);let n=Ue(this.elementStyle,e),s=this.pageProps;if(e==="bleed"||e==="marks")s[""]||(s[""]={}),Object.keys(s).forEach(r=>{ei(s[r],e,n)});else if(e==="size"){let r=s[""];this.currentPageSelectors.forEach(o=>{let a=new Z(n.value,n.priority+o.specificity),h=o.selectors?o.selectors.join(""):"",l=s[h];l?Lt(l,e,a):(l=s[h]={},ei(l,e,a),r&&["bleed","marks"].forEach(c=>{r[c]&&ei(l,c,r[c])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new kw(this.elementStyle,e)}startPageMarginBoxRule(e){let t=ys(this.elementStyle,wn),i=t[e];i||(i={},t[e]=i);let n=new Tw(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},Tw=class extends En{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.boxStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),s=new Z(t,n);ei(this.boxStyle,e,s)}},Ft=!0;function Iw(e){Ft=e}var ti=[];function Za(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function rc(e){let t=Array.from(e.querySelectorAll("body > :not(script):not(link):not(style) ~ script"));return Array.from(e.querySelectorAll("head > script, body > script")).filter(i=>!t.includes(i))}function Po(e,t,i){var n,s;if(!Ft||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&rc(e.ownerDocument).includes(e))return N(!1);let r=e.textContent,o=e.src,a=e.type==="module",h=(a||o)&&e.async,l=a&&!h||o&&e.defer,c=!(i!=null&&i.atEnd)&&(i?.forceDefer||l||h);if(oc(t)||(t.onload=null),c)return ti.some(d=>Za(d,e))||ti.push(e),N(!0);if(o.includes("/mathjax")){let d=t.document.head.querySelector("script[src*='MathJax.js']:not([data-vivliostyle-scripting])");if(d){if(o.includes("/mathjax@3"))t.document.head.removeChild(d),(s=(n=t.MathJax)==null?void 0:n.version)!=null&&s.startsWith("2.")&&delete t.MathJax;else if(o.includes("/MathJax.js"))return N(!0)}}for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&Za(d,e)&&t.document.head.removeChild(d);let p=t.document.createElement("script");p.textContent=r,o&&(p.src=o),p.async=h,p.defer=l,p.setAttribute("data-vivliostyle-scripting","true");for(let d of e.attributes)["src","async","defer"].includes(d.name)||p.setAttribute(d.name,d.value);if(H.debug("script:",o),o){let d=hi(p);return t.document.head.appendChild(p),ws([d])}else return t.document.head.appendChild(p),N(!0)}function Rw(e,t){var i;let n={},s=o=>{var a;let h=(a=o["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let c of h.values)n[c.stringValue()]=!0;else n[h.stringValue()]=!0;let l=o._marginBoxes;if(l)for(let c of Object.values(l))s(c)},r=o=>{if(o instanceof uo)s(o.style);else if(o instanceof Bi||Array.isArray(o))for(let a of Object.values(o))r(a)};for(let o of Object.values(t.cascade.code))for(let a of Object.values(o??{}))r(a);for(let o of e.querySelectorAll("[style]"))(i=o.style)!=null&&i.fontFamily&&(n[o.style.fontFamily]=!0);return Object.keys(n).join(",")}function Aw(e,t,i){var n;let s=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return s.style.position="fixed",s.style.fontSize="0",s.setAttribute("data-vivliostyle-textcontent","true"),s.setAttribute("aria-hidden","true"),s.style.fontFamily=Rw(e,i),s.textContent=e.documentElement.textContent,t.document.body.appendChild(s),s}function Lw(e,t,i){if(!Ft)return N(!1);let n=rc(e);if(n.length===0)return N(!1);let s=n.some(c=>!(c.async||c.defer||c.type==="module")),r=s?Aw(e,t,i):null,o=t.document.fonts,a=t.$,h=!1,l=F("loadScripts");return l.loop(()=>{if(n.length===0)return s?l.sleep(20).thenAsync(()=>{var p,d;return o.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(p=t.FontJSON)!=null&&p.Font&&(d=t.ret)!=null&&d.readyState&&t.ret.readyState<4?N(!0):N(!1)}):N(!1);let c=n.shift();return Po(c,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(ti.push(c),h=!0),n.length===0&&s&&(H.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),N(!0)))}).then(()=>{r&&r.remove(),l.finish(!0)}),l.result()}function Fw(e){if(!Ft)return N(!1);let t=F("loadScripts");return t.loop(()=>ti.length===0?N(!1):Po(ti.shift(),e,{atEnd:!0}).thenReturn(ti.length>0)).then(()=>{H.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),H.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function oc(e){return Ft?ti.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var Ow=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,s)=>`url("${i.transformURL(s,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,s)=>`url('${i.transformURL(s,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,s)=>`url(${i.transformURL(s,t)}`),Bw={};function _w(e){e.addEventListener("load",()=>{e.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(t,i){switch(t){case"mouse-events":return!0}return!1}}},!1)}var ac=class _r extends $r{constructor(t,i,n,s,r,o,a,h,l,c,p,d,f){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=s,this.regionIds=r,this.xmldoc=o,this.docFaces=a,this.footnoteStyle=h,this.stylerProducer=l,this.page=c,this.customRenderer=p,this.fallbackMap=d,this.documentURLTransformer=f,u(this,"document"),u(this,"exprContentListener"),u(this,"nodeContext",null),u(this,"viewRoot",null),u(this,"isFootnote",!1),u(this,"sourceNode",null),u(this,"offsetInNode",0),u(this,"viewNode",null),this.document=n.document,this.exprContentListener=s.counterListener.getExprContentListener()}clone(){return new _r(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(t,i,n,s,r,o,a,h){let l=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(!l)return h;let c=[],p=$n.createElementNS("http://www.pyroxy.com/ns/shadow","root"),d=p;for(let m of Fg){let g;if(m){if(!l[m]||m=="footnote-marker"&&!(i&&this.isFootnote))continue;if(m.match(/^first-/)){let w=s.display;if(!w||w===v.inline)continue;let y=t.firstElementChild;if(y&&ze(y.previousSibling)){let b=r.getStyle(y,!1);if(b){let S=Ue(b,"display");if(S!=null&&S.value&&S.value!==v.inline)continue}}}if(m==="before"||m==="after"){let w=l[m].content;if(!w||!jt(w.value))continue}c.push(m),g=$n.createElementNS("http://www.w3.org/1999/xhtml","span"),Ir(g,m)}else g=$n.createElementNS("http://www.pyroxy.com/ns/shadow","content");d.appendChild(g),m.match(/^first-/)&&(d=g)}if(!c.length)return h;let f=new La(t,n,r,o,this.exprContentListener);return new hr(t,p,null,a,h,ut.ROOTLESS,f)}getPseudoMap(t,i,n,s,r){let o=bt(t,"_pseudos");if(!o)return null;let a={};for(let h in o){let l=a[h]={};sn(l,o[h],r),Tr(l,r,o[h]),du(o[h],i,n,(c,p)=>{sn(l,p,r),lu(p,d=>{sn(l,d,r)})})}return a}createRefShadow(t,i,n,s,r){let o=F("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let h=a;if(h){let l=h.getElement(t);if(l){let c=this.stylerProducer.getStylerForDoc(h);r=new hr(n,l,h,s,r,i,c)}}o.finish(r)}),o.result()}createShadows(t,i,n,s,r,o,a){let h=F("createShadows"),l=null,c=s.template,p;if(c instanceof ft||c===v.footnote){let d=c instanceof ft?c.url:Ce("user-agent.xml#footnote",ii);p=this.createRefShadow(d,ut.ROOTLESS,t,a,l)}else p=N(l);return p.then(d=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let g=t.getAttribute("href"),w=null;g?w=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?g=a.owner.getAttribute("href"):g=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),w=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),g&&(g=Ce(g,w.url),f=this.createRefShadow(g,ut.ROOTED,t,a,d))}f==null&&(f=N(d));let m=null;f.then(g=>{if(s.display===v.table_cell){let w=Ce("user-agent.xml#table-cell",ii);m=this.createRefShadow(w,ut.ROOTLESS,t,a,g)}else m=N(g);m.then(w=>{w=this.createPseudoelementShadow(t,i,n,s,r,o,a,w),h.finish(w)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,s){var r;let o=this.context,a=cu(n,o,this.regionIds,this.isFootnote,this.nodeContext),h=!((r=this.nodeContext)!=null&&r.parent);h&&(!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 l=t;t=hu(a,o,t);let c=!h&&t!==l;i=uu(a,o,i);let p=(y,b)=>{let S;c&&(t?/^(min-|max-)?(height|inline-size)$/.test(y)&&(S=o.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(y)&&(S=o.pageAreaWidth));let T=b.evaluate(o,y,S,t);return y=="font-family"&&(T=this.docFaces.filterFontFamily(T)),T},d=!!new Ie(o.style.pageScope,"left-page").evaluate(o);if(pu(a,s,t,i,d,p),c){let y=s[t?"height":"width"];(!y||y===v.auto)&&(s[t?"height":"width"]=v.max_content)}if(dr(s.position))return s.position=v.fixed,s.visibility=v.hidden,t;let f=s.position,m=s.float,g=s.display||(this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?v.inline:void 0),w=Bh(g,f,m,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(y=>{w[y]&&(s[y]=w[y])}),t}inheritFromSourceParent(t){let i=this.nodeContext.sourceNode,n=[],s=null,r=this.nodeContext.shadowContext,o=-1;for(;i&&i.nodeType==1;){let p=r&&r.root==i;if(!p||r.type==ut.ROOTLESS){let d=(r?r.styler:this.styler).getStyle(i,!1);n.push(d),s=s||Xs(i)}p?(i=r.owner,r=r.parentShadow):(i=i.parentNode,o++)}let a=o===0,h=this.context.queryUnitSize("em",a),l={"font-size":new Z(new I(h,"px"),0)},c=new Mf(l,this.context);for(let p=n.length-1;p>=0;--p){let d=n[p],f=[];for(let w in d)tn(w)&&f.push(w);f.sort(Ko);let m,g;for(let w of f){c.setPropName(w);let y=Ue(d,w),b=y;K(y.value)||(w==="font-size"&&p===n.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize?b=new Z(new I(this.context.rootFontSize,"px"),y.priority):w==="line-height"&&p===n.length-1&&this.context.rootLineHeight&&y.value instanceof I&&(y.value.unit==="lh"||y.value.unit==="rlh")?b=new Z(new I(this.context.rootLineHeight,"px"),y.priority):p===0&&y.value instanceof I&&y.value.unit==="lh"?b=new Z(new I(y.value.num*this.getLineHeightUnitSize(w,m,g),"px"),y.priority):Rt(w)||(b=y.filterValue(c)),w==="font-size"?m=b.value:w==="line-height"&&(g=b.value),l[w]=b)}}for(let p in t)tn(p)||(l[p]=t[p]);return{lang:s,elementStyle:l}}resolveURL(t){return t=Ce(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=Xs(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=Tf().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let s in this.nodeContext.parent.inheritedProps)n[s]=this.nodeContext.parent.inheritedProps[s]}i.forEach(s=>{let r=t[s];if(r){if(K(r))r===v.initial&&(n[s]=void 0);else if(r instanceof ni)n[s]=r.num;else if(r instanceof rt)n[s]=r.name;else if(r instanceof I){let o=r;switch(o.unit){case"dpi":case"dpcm":case"dppx":n[s]=o.num*pe[o.unit];break;default:n[s]=r}}else n[s]=r;["widows","orphans"].includes(s)||delete t[s]}})}}resolveFormattingContext(t,i,n,s,r,o){let a=vt("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,s,r,o);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,s,r,o;let a=!0,h=F("createElementView"),l=this.sourceNode,c=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,p=c.getStyle(l,!1);if(!this.nodeContext.shadowContext){let T=this.xmldoc.getElementOffset(l);vs.registerFragmentIndex(T,this.nodeContext.fragmentIndex,0)}let d={};if(!this.nodeContext.parent){let T=this.inheritFromSourceParent(p);p=T.elementStyle,this.nodeContext.lang=T.lang}let f=p.position,m=p.float,g=p["float-reference"],w=m&&!K(m.value)&&m.value!==v.none&&g&&!K(g.value)?lf(g.value.toString()):null;if(this.nodeContext.parent&&(dr(f?.value)||w&&yi(w))){let T=this.inheritFromSourceParent(p);p=T.elementStyle,this.nodeContext.lang=T.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",p,d),w&&yi(w)&&d.display===v.block&&(d.display=v.flow_root),c.processContent(l,d,(s=this.nodeContext.viewNode)!=null?s:(n=this.nodeContext.parent)==null?void 0:n.viewNode),this.transferPolyfilledInheritedProps(d),this.inheritLangAttribute(),d.direction&&(this.nodeContext.direction=d.direction.toString());let y=d["flow-into"];if(y&&y.toString()!=this.flowName)return h.finish(!1),h.result();if(Ft&&l.localName==="script"&&l.namespaceURI==="http://www.w3.org/1999/xhtml")return Po(l,this.viewport.window).thenFinish(h),h.result();let b=d.display;if(K(b)&&(b===v.initial||b===v.unset?b=v.inline:b===v.inherit?b=((r=this.nodeContext.parent)==null?void 0:r.display)&&B((o=this.nodeContext.parent)==null?void 0:o.display):b=null),b===v.none)return h.finish(!1),h.result();let S=this.nodeContext.parent==null;return this.nodeContext.flexContainer=b===v.flex,this.createShadows(l,S,p,d,c,this.context,this.nodeContext.shadowContext).then(T=>{var R,M;this.nodeContext.nodeShadow=T;let V=d.position,W=d.float,j=d.clear,Be=this.nodeContext.vertical?v.vertical_rl:v.horizontal_tb,Je=this.nodeContext.parent?this.nodeContext.parent.vertical?v.vertical_rl:v.horizontal_tb:Be,De=gf(l),C=d["column-count"],L=d["column-width"],x=C&&C!==v.auto&&!K(C)||L&&L!==v.auto&&!K(L);this.nodeContext.establishesBFC=wf(b,V,W,d.overflow,Be,Je,x||De),this.nodeContext.containingBlockForAbsolute=bf(V),this.nodeContext.isInsideBFC()&&W!==v.footnote&&!(w&&yi(w))&&(W=null,j=null);let k=W instanceof me||W===v.left||W===v.right||W===v.top||W===v.bottom||W===v.inline_start||W===v.inline_end||W===v.block_start||W===v.block_end||W===v.snap_block||W===v.snap_inline||W===v.inside||W===v.outside||W===v.footnote;W&&(delete d.float,W===v.footnote&&(this.isFootnote?(k=!1,d.display=v.block):d.display=v.inline)),j&&(j===v.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(j=B(this.nodeContext.parent.clearSide)),(j===v.left||j===v.right||j===v.top||j===v.bottom||j===v.inline_start||j===v.inline_end||j===v.block_start||j===v.block_end||j===v.inside||j===v.outside||j===v.both||j===v.all||j===v.same||j===v.column||j===v.region||j===v.page)&&(delete d.clear,d.display&&d.display!=v.inline&&(this.nodeContext.clearSide=j.toString())));let E=b===v.list_item&&d["ua-list-item-count"],A=d["break-inside"];(k||A&&!K(A)&&A!==v.auto)&&this.nodeContext.breakPenalty++,b&&b!==v.inline&&zt(b)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!k&&!b||zt(b)||Mh(b),this.nodeContext.display=b?b.toString():"inline",this.nodeContext.floatSide=k?W.toString():null,this.nodeContext.floatReference=w||Se.INLINE;let O=d["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=O&&!K(O)?O:null;let _=this.isInsideNonRootMultiColumn(),U=d["column-span"];if(this.nodeContext.columnSpan=!_&&U&&!K(U)?U:null,!this.nodeContext.inline){let z=d["break-after"];z&&!K(z)&&!(_&&z===v.column)&&(this.nodeContext.breakAfter=z.toString(),or[this.nodeContext.breakAfter]&&(d["break-after"]=v.column));let Qe=d["break-before"];Qe&&!K(Qe)&&!(_&&Qe===v.column)&&(this.nodeContext.breakBefore=Qe.toString(),or[this.nodeContext.breakBefore]&&(d["break-before"]=v.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let ht=d.page,et=ht&&!K(ht)&&ht.toString();!et&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||b===v.table_header_group||b===v.table_footer_group)&&(et=this.styler.cascade.currentPageType),!et||et.toLowerCase()==="auto"?et=this.nodeContext.pageType:this.nodeContext.pageType=et,this.styler.cascade.currentPageType!==et&&!(!et&&d.position===v.fixed)&&(this.nodeContext.fragmentIndex===1&&!un(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),et!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=et)}this.nodeContext.verticalAlign=d["vertical-align"]&&d["vertical-align"].toString()||"baseline",this.nodeContext.captionSide=d["caption-side"]&&d["caption-side"].toString()||"top";let q=d["border-collapse"];if(!q||q===B("separate")){let z=d["border-spacing"],Qe,ht;z&&(z instanceof me?(Qe=z.values[0],ht=z.values[1]):Qe=ht=z,Qe.isNumeric()&&(this.nodeContext.inlineBorderSpacing=We(Qe,this.context)),ht.isNumeric()&&(this.nodeContext.blockBorderSpacing=We(ht,this.context)))}let J=d["footnote-policy"];this.nodeContext.footnotePolicy=J&&!K(J)?J:null;let Y=d["x-first-pseudo"];if(Y){let z=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new sf(z,Y.num)}this.nodeContext.inline||this.processAfterIfcontinues(l,p,c,this.context);let he=d["white-space"];if(he){let z=Eh(he.toString());z!==null&&(this.nodeContext.whitespace=z)}let te=d["hyphenate-character"];te&&te instanceof Ae&&(this.nodeContext.hyphenateCharacter=te.str);let fe=d["word-break"],Ee=d["line-break"],we=d["overflow-wrap"];(fe===v.break_all||Ee===v.anywhere||we===v.break_word||we===v.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,b,V,W,S),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(t=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,t)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(d),this.findAndProcessRepeatingElements(l,c));let Q=!1,oe=null,se=[],ee=l.namespaceURI,$=l.localName,ue=$;if(ee=="http://www.w3.org/1999/xhtml"?($=="html"||$=="body"||$=="script"||$=="link"||$=="meta"?$="div":$=="vide_"?$="video":$=="audi_"?$="audio":$=="object"&&(Q=!!this.customRenderer),l.getAttribute(go)&&(M=(R=p.content)==null?void 0:R.value)!=null&&M.url&&($="img")):ee=="http://www.idpf.org/2007/ops"?($="span",ee="http://www.w3.org/1999/xhtml"):ee=="http://www.pyroxy.com/ns/shadow"?(ee="http://www.w3.org/1999/xhtml",$=this.nodeContext.inline?"span":"div"):Q=!!this.customRenderer,E)t?$="li":($="div",b=v.block,d.display=b);else if($=="body"||$=="li")$="div";else if($=="q")$="span";else if($=="a"){let z=d["hyperlink-processing"];z&&z.toString()!="normal"&&($="span")}d.behavior&&d.behavior.toString()!="none"&&this.customRenderer&&(Q=!0),l.dataset&&l.getAttribute("data-math-typeset")==="true"&&(Q=!0);let He;if(Q){let z=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;He=this.customRenderer(l,z,d)}else He=N(null);He.then(z=>{if(z)Q&&(a=z.getAttribute("data-adapt-process-children")=="true");else if(d.display===v.none){h.finish(!1);return}else z=this.createElement(ee,$);!S&&x&&d["column-fill"]===v.auto&&(z.setAttribute("data-vivliostyle-column-fill","auto"),d["column-fill"]=v.balance),$!=ue&&(z.setAttribute("data-vivliostyle-original-tag",ue),(ue==="html"||ue==="body")&&(z.role="presentation")),$=="a"&&z.addEventListener("click",this.page.hrefHandler,!1),oe&&(this.applyPseudoelementStyle(this.nodeContext,"inner",oe),z.appendChild(oe)),z.localName=="iframe"&&z.namespaceURI=="http://www.w3.org/1999/xhtml"&&_w(z);let Qe=this.nodeContext.inheritedProps["image-resolution"],ht=[],et=d.width,ks=d.height,yc=l.getAttribute("width"),xc=l.getAttribute("height"),Ns=et===v.auto||!et&&!yc,Ps=ks===v.auto||!ks&&!xc,Ro=l.attributes,Sc=Ro.length,In=null,Ao=null;for(let Ze=0;Ze<Sc;Ze++){let xt=Ro[Ze],tt=xt.namespaceURI,ne=xt.localName,Re=xt.nodeValue;if(tt){if(tt=="http://www.w3.org/2000/xmlns/")continue;tt=="http://www.w3.org/1999/xlink"&&ne=="href"&&(Re=this.documentURLTransformer.transformURL(this.resolveURL(Re),this.xmldoc.url))}else{if(!Ft&&ne.match(/^on/)||ne=="style")continue;if((ne=="id"||ne=="name")&&t){let Ve=this.documentURLTransformer.transformFragment(Re,this.xmldoc.url);z.setAttribute(ne,Re),z.setAttribute("data-vivliostyle-id",Ve);let ri=z.ownerDocument.createElement("a");ri.setAttribute(ne,Ve),ri.setAttribute(Pi,"1"),z.appendChild(ri),this.page.registerElementWithId(z,Ve);continue}if(ne=="src"||ne=="href"||ne=="poster")Re=this.resolveURL(Re),ne==="href"&&(Re=this.documentURLTransformer.transformURL(Re,this.xmldoc.url));else if(ne=="srcset")Re=Re.split(",").map(Ve=>this.resolveURL(Ve.trim())).join(",");else if(ne==="data"&&Q&&$==="object"&&z.hasAttribute("data"))continue;if(ne==="poster"&&$==="video"&&ee==="http://www.w3.org/1999/xhtml"&&Ns&&Ps){let Ve=new Image,ri=hi(Ve,Re);se.push(ri),ht.push({image:Ve,element:z,fetcher:ri})}}if(ee=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ne)&&(ne=ne.toLowerCase()),this.isSVGUrlAttribute(ne)&&(Re=Ow(Re,this.xmldoc.url,this.documentURLTransformer)),tt){let Ve=Bw[tt];Ve&&(ne=`${Ve}:${ne}`)}if(ne=="src"&&!tt&&($=="img"||$=="input")&&ee=="http://www.w3.org/1999/xhtml")In=Re;else if(ne=="alt"&&!tt&&$=="img"&&ee=="http://www.w3.org/1999/xhtml")Ao=Re;else if(ne=="href"&&$=="image"&&ee=="http://www.w3.org/2000/svg"&&tt=="http://www.w3.org/1999/xlink")this.page.fetchers.push(hi(z,Re));else if(tt)z.setAttributeNS(tt,ne,Re);else try{z.setAttribute(ne,Re)}catch(Ve){H.warn(Ve)}}if(In){let Ze=$==="input"?new Image:z,xt=hi(Ze,In,Ao);Ze!==z&&(z.src=In);let tt=()=>{var ne,Re;if(d.position===v.fixed)return!0;for(let Ve=(ne=this.nodeContext.parent)==null?void 0:ne.viewNode;Ve&&Ve!==this.viewRoot;Ve=Ve.parentElement)if(((Re=Ve.style)==null?void 0:Re.position)==="fixed")return!0;return!1};!Ns&&!Ps&&!(()=>{let ne=this.nodeContext.vertical?et:ks;return ne instanceof I&&ne.unit==="%"})()&&!tt()?this.page.fetchers.push(xt):(Ns&&Ps&&Qe&&Qe!==1&&ht.push({image:Ze,element:z,fetcher:xt}),se.push(xt))}delete d.content;let Ts=d["list-style-image"];if(Ts&&Ts instanceof ft){let Ze=Ts.url;se.push(hi(new Image,Ze))}if(this.preprocessElementStyle(d),this.applyComputedStyles(z,d),this.nodeContext.inline)t||(ot(z,"inline-start"),Hi(z)&&ot(z,"clone"));else if(t){if(!io(d.position)){let Ze=d["margin-break"],xt=this.getBreakTypeAt(this.nodeContext),tt=xt!==null,ne=xt==="auto";(Ze===v.discard&&tt||Ze!==v.keep&&ne&&!this.nodeContext.floatSide)&&Vs(z,"block-start")}}else{let Ze=this.nodeContext.vertical?"width":"height";_t(z,Ze)&&P(z,Ze,this.nodeContext.display==="table-row"?"0.01px":""),ot(z,"block-start"),Hi(z)&&ot(z,"clone"),Vs(z,"block-start")}E&&z.setAttribute("value",d["ua-list-item-count"].stringValue()),this.viewNode=z,se.length?ws(se).then(()=>{Qe>0&&this.modifyElemDimensionWithImageResolution(ht,Qe,d,this.nodeContext.vertical),h.finish(a)}):h.timeSlice().then(()=>{h.finish(a)})})}),h.result()}isInsideNonRootMultiColumn(){var t;let i=(t=this.nodeContext.parent)==null?void 0:t.viewNode;return!!(i&&Uh(i))}getBreakTypeAt(t){var i,n,s,r,o;if(this.isInsideTable(t))return null;for(let h=t;h&&!h.after;h=h.parent){if(Xe(h.breakBefore))return h.breakBefore;if(h.fragmentIndex===1&&!h.parent)return h.sourceNode===h.sourceNode.ownerDocument.documentElement?"page":null;if((i=h.parent)!=null&&i.floatSide)return null;let l=(n=h.parent)==null?void 0:n.viewNode;if(l){let c=this.viewport.window.getComputedStyle(l),p=parseFloat(c.paddingBlockStart),d=parseFloat(c.borderBlockStartWidth);if(p||d)return null;let f=l?.firstChild;for(;f&&(ze(f,h.parent.whitespace)||!h.floatSide&&ji(f));)f=f.nextSibling;if(f&&f!==h.viewNode)return null}}let a=(o=(r=(s=this.context)==null?void 0:s.currentLayoutPosition)==null?void 0:r.flowPositions[this.flowName])==null?void 0:o.startBreakType;return Xe(a)?a:"auto"}isInsideTable(t){for(let i=t;i&&!i.after;i=i.parent)if(i.display&&i.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(t,i,n,s){let r=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,s);if(r&&r["after-if-continues"]&&r["after-if-continues"].content){let o=new La(t,i,n,s,this.exprContentListener);this.nodeContext.afterIfContinues=new Bg(t,o)}}isSVGUrlAttribute(t){return _r.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,s){t.forEach(r=>{if(r.fetcher.get().get()==="load"){let o=r.image,a=o.width/i,h=o.height/i,l=r.element;if(a>0&&h>0){if(n["box-sizing"]===v.border_box&&(n["border-left-style"]!==v.none&&(a+=We(n["border-left-width"],this.context)),n["border-right-style"]!==v.none&&(a+=We(n["border-right-width"],this.context)),n["border-top-style"]!==v.none&&(h+=We(n["border-top-width"],this.context)),n["border-bottom-style"]!==v.none&&(h+=We(n["border-bottom-width"],this.context))),i>1){let c=n["max-width"]||v.none,p=n["max-height"]||v.none;if(c===v.none&&p===v.none)P(l,"max-width",`${a}px`);else if(c!==v.none&&p===v.none)P(l,"width",`${a}px`);else if(c===v.none&&p!==v.none)P(l,"height",`${h}px`);else{c.isNumeric(),p.isNumeric();let d=c,f=p;d.unit!=="%"?P(l,"max-width",`${Math.min(a,We(d,this.context))}px`):f.unit!=="%"?P(l,"max-height",`${Math.min(h,We(f,this.context))}px`):s?P(l,"height",`${h}px`):P(l,"width",`${a}px`)}}else if(i<1){let c=n["min-width"]||ge,p=n["min-height"]||ge;c.isNumeric(),c.isNumeric();let d=c,f=p;d.num===0&&f.num===0?P(l,"min-width",`${a}px`):d.num!==0&&f.num===0?P(l,"width",`${a}px`):d.num===0&&f.num!==0?P(l,"height",`${h}px`):d.unit!=="%"?P(l,"min-width",`${Math.max(a,We(d,this.context))}px`):f.unit!=="%"?P(l,"min-height",`${Math.max(h,We(f,this.context))}px`):s?P(l,"height",`${h}px`):P(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){vt("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let s={},r=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",r,s),!this.processRepeatOnBreak(s))continue;if(this.nodeContext.formattingContext instanceof si&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let o=this.nodeContext.parent,a=o&&o.formattingContext;this.nodeContext.formattingContext=new si(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==v.none&&((i===v.auto||K(i))&&(t.display===v.table_header_group?i=v.header:t.display===v.table_footer_group?i=v.footer:i=v.none),i&&i!==v.none)?i.toString():null}createTextNodeView(){let t=F("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=ua(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return N(!0);let t,i=t=this.sourceNode.textContent,n=F("preprocessTextContent"),s=vt("PREPROCESS_TEXT_CONTENT"),r=0;return n.loop(()=>r>=s.length?N(!1):s[r++](this.nodeContext,i).thenAsync(o=>(i=o,N(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Wp(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=F("createNodeView"),s,r=!0;return this.sourceNode.nodeType==1?s=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,s=N(!0)):s=this.createTextNodeView(),s.then(o=>{var a,h;if(r=o,this.nodeContext.viewNode=this.viewNode,this.viewNode){let l=(d,f)=>d?.nodeType===1&&wi(d)===f,c=this.nodeContext.parent,p=c?l(this.viewNode,"after")&&l(c.viewNode,"first-letter")&&(a=c.viewNode)!=null&&a.hasChildNodes()?c.parent.viewNode:c.viewNode:this.viewRoot;if(p&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&ze(this.viewNode))&&!p.hasChildNodes()&&yh(p).includes("block-start")&&ot(p,"text-start"),p.appendChild(this.viewNode),yf(this.viewNode),this.viewNode.nodeType===1&&this.viewNode.hasAttribute("data-vivliostyle-id"))){let d=this.viewNode,f=d.querySelector(":scope > a:empty[id^='viv-id-']");if(f&&(d.closest("[style*='position: absolute']")||/(table|flex|grid|ruby)/.test(d.style.display))){let m=f.getAttribute("id");f.ownerDocument.querySelectorAll(`a[id="${m}"]`).forEach(w=>{var y;(y=w.parentElement)==null||y.removeChild(w)});let g=p.closest("[data-vivliostyle-bleed-box]");(h=g?.parentElement)==null||h.insertBefore(f,g)}}}n.finish(r)}),n.result()}setCurrent(t,i,n){return this.nodeContext=t,t?(this.sourceNode=t.sourceNode,this.offsetInNode=t.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(i,!!n):N(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,s=t.parent,r,o,a=n.subShadow||n.parentShadow;n.subShadow?(r=n.root,o=n.type,o==ut.ROOTLESS&&(r=r.firstChild)):(r=n.owner.firstChild,o=ut.ROOTLESS);let h=t.sourceNode.nextSibling;if(h?(t.sourceNode=h,t.resetView()):t.shadowSibling?t=t.shadowSibling:r?t=null:(t=t.parent.modify(),t.after=!0),r){let l=new Gi(r,s,i);return l.shadowContext=a,l.shadowType=o,l.shadowSibling=t,l}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=ut.ROOTED){let n=t.sourceNode.nextSibling;if(n)return t=t.modify(),t.boxOffset=i,t.sourceNode=n,t.resetView(),this.processShadowContent(t)}return t.shadowSibling?(t=t.shadowSibling.modify(),t.boxOffset=i,t):(t=t.parent.modify(),t.boxOffset=i,t.after=!0,t)}else{if(t.nodeShadow){let s=t.nodeShadow.root;if(t.nodeShadow.type==ut.ROOTLESS&&(s=s.firstChild),s){let r=new Gi(s,t,i);return r.shadowContext=t.nodeShadow,r.shadowType=t.nodeShadow.type,this.processShadowContent(r)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new Gi(n,t,i));if(t.sourceNode.nodeType!=1){let s=ua(t.preprocessedTextContent);i+=s.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}isTransclusion(t,i,n){let s=Ue(i,"hyperlink-processing");if(!s)return!1;let r=s.evaluate(this.context,"hyperlink-processing");return r?r.toString()==n:!1}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return N(n);let s=F("nextInTree");return this.setCurrent(n,!0,i).then(r=>{(!n.viewNode||!r)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),this.dispatchEvent({type:"nextInTree",nodeContext:n}),s.finish(n)}),s.result()}addImageFetchers(t){if(t instanceof Ye){let i=t.values;for(let n=0;n<i.length;n++)this.addImageFetchers(i[n])}else if(t instanceof ft){let i=t.url;this.page.fetchers.push(hi(new Image,i))}}applyComputedStyles(t,i){var n,s,r;let o=i["background-image"];o&&this.addImageFetchers(o);let a=i.position===v.relative,h=((n=this.nodeContext)==null?void 0:n.parent)===null&&((s=this.sourceNode)==null?void 0:s.parentElement)===null&&!!((r=this.viewRoot)!=null&&r.parentElement),l=Object.keys(i);l.sort(Ko);let c,p;for(let d of l){if(zw[d])continue;let f=i[d];if(!(!f||f===G&&!Rt(d))){if(f=f.visit(new Ud(this.xmldoc.url,this.documentURLTransformer)),f instanceof I&&Pl(f.unit)&&(f.unit==="lh"?f=new I(f.num*this.getLineHeightUnitSize(d,c,p),"px"):f=Wl(f,this.context)),d==="font-size"?c=f:d==="line-height"&&(p=f),qp[d]||a&&Yp[d]){this.page.delayedItems.push(new to(t,d,f));continue}h&&this.page.pageAreaElement&&tn(d)?P(this.page.pageAreaElement.parentElement.parentElement,d,f.toString()):P(t,d,f.toString())}}}getLineHeightUnitSize(t,i,n){var s,r,o,a;let h=pe.lh/pe.em,l=((r=(s=this.nodeContext.parent)==null?void 0:s.viewNode)==null?void 0:r.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,c=l?parseFloat(l.fontSize):this.context.fontSize(),p=l?l.lineHeight==="normal"?c*h:parseFloat(l.lineHeight):this.context.rootLineHeight;if(t==="line-height"||t==="font-size")return p;let d=null;if(n){if(n instanceof Xt||n instanceof I&&(n.unit==="em"||n.unit==="%"))d=n instanceof I&&n.unit==="%"?n.num/100:n.num;else if(n instanceof I)return n.num*this.context.queryUnitSize(n.unit,!1)}else for(let f=(o=this.nodeContext.parent)==null?void 0:o.viewNode;;f=f.parentNode){if(!f||f.nodeType!==1){d=h;break}let m=(a=f?.style)==null?void 0:a.lineHeight;if(m){/^[0-9.]+$/.test(m)&&(d=parseFloat(m)),m==="normal"&&(d=h);break}}return d!==null?i instanceof I?d*Qh(i,c,this.context).num:d*c:p}applyPseudoelementStyle(t,i,n){if(t.after)return;let s=this.sourceNode,r=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(s,!1),o=bt(r,"_pseudos");if(!o||(r=o[i],!r))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",r,a);let h=a.content;jt(h)&&(h.visit(new ss(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=F("peelOff"),s=t.firstPseudo,r=t.offsetInNode,o=t.after;if(i>0){let p=t.viewNode.textContent;t.viewNode.textContent=p.substr(0,i),r+=i}else if(!o&&t.viewNode&&r==0){let p=t.viewNode.parentNode;p&&p.removeChild(t.viewNode)}let a=t.boxOffset+i,h=[];for(;t.firstPseudo===s;)h.push(t),t=t.parent;let l=h.pop(),c=l.shadowSibling;return n.loop(()=>{for(;h.length>0;){l=h.pop(),t=new Gi(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=r,t.after=o),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.shadowSibling:c,c=null;let p=this.setCurrent(t,!1);if(p.isPending())return p}return N(!1)}).then(()=>{n.finish(t)}),n.result()}createElement(t,i){return t=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(t,i)}applyFootnoteStyle(t,i,n){let s={},r=bt(this.footnoteStyle,"_pseudos");if(t=this.computeStyle(t,i,this.footnoteStyle,s),r&&r.before){let o={},a=this.createElement("http://www.w3.org/1999/xhtml","span");Ir(a,"before"),n.appendChild(a),this.computeStyle(t,i,r.before,o),delete o.content,this.applyComputedStyles(a,o)}return delete s.content,this.applyComputedStyles(n,s),t}processFragmentedBlockEdge(t){var i,n,s;let r=!t.inline&&t.after?t.parent:t,o=!1;if(t.inline&&t.after&&!t.shadowContext&&((i=t.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let h=t.sourceNode.nextSibling,l=(n=Ue(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();o=l&&!zt(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=r;h;h=h.parent){if(((s=h.viewNode)==null?void 0:s.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(ot(l,"inline-end"),Hi(l)){let c=h.vertical?l.offsetWidth:l.offsetHeight;ot(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>c&&this.fixClonedBoxDecorationOverflow(l)}}else{let c=this.nodeContext.vertical?"width":"height";if(_t(l,c)&&P(l,c,""),ot(l,"block-end"),!a++&&h!==r){let{textAlign:p}=this.viewport.window.getComputedStyle(l);if(p==="justify"&&!o){let d=this.createChildAnonymousBlockIfNeeded(l);d?d!==l?xh(d,["block-start","text-start","block-end","text-end","justify"]):(ot(l,"text-end"),ot(l,"justify")):ot(l,"text-end")}else ot(l,"text-end")}Hi(l)&&ot(l,"clone"),Vs(l,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),s=parseFloat(i.borderInlineEndWidth),r=-(n+s);isNaN(r)||(t.style.marginInlineEnd=`${r}px`)}createChildAnonymousBlockIfNeeded(t){let i=r=>{let{display:o,position:a,float:h}=this.viewport.window.getComputedStyle(r);if(r.localName==="ruby"||Jt[r.localName])return!1;if(r.localName==="br")return!0;if((o==="inline"||o==="contents")&&r.hasChildNodes()){let l=r.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===r.lastChild&&ze(l.nextSibling))){let c=i(l);if(c||c===null)return c}for(let c=l?.previousElementSibling;c;c=c.previousElementSibling){let p=i(c);if(p||p===null)return null}return!1}if(o==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||r.hasAttribute(Pi)){let l=r.previousElementSibling;return l&&(l.nextSibling===r||l.nextSibling===r.previousSibling&&ze(l.nextSibling))?i(l):!1}return!(!o||zt(o))},n=null;for(let r=t.lastElementChild;r;r=r.previousElementSibling){let o=i(r);if(o){n=r;break}if(o===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&ze(n.nextSibling)))return null;let s=t.ownerDocument.createElement("span");s.className="viv-anonymous-block";for(let r=n.nextSibling,o=null;r;r=o)o=r.nextSibling,s.appendChild(r);return t.appendChild(s),s}convertLengthToPx(t,i,n){let s=t.num,r=t.unit;if(ud(r)){let o=i;for(;o&&o.nodeType!==1;)o=o.parentNode;let a=parseFloat(n.getElementComputedStyle(o)["font-size"]);return this.context,ho(t,a,this.context).num}else{let o=this.context.queryUnitSize(r,!1);return o?s*o:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,s=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&wi(n)===wi(s)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,s)=>{let r=i.steps[s];return this.isSameNodePositionStep(n,r)})}isPseudoelement(t){return!!wi(t)}};u(ac,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var Mw=ac,zw={"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},qn=null,Dw=class{constructor(e){u(this,"layoutBox"),u(this,"window"),u(this,"scaleRatio"),this.layoutBox=e.layoutBox,this.window=e.window,this.scaleRatio=e.scaleRatio}scaleRect(e){return qn?{left:e.left*this.scaleRatio,top:e.top*this.scaleRatio,right:e.right*this.scaleRatio,bottom:e.bottom*this.scaleRatio,width:e.width*this.scaleRatio,height:e.height*this.scaleRatio}:e}subtractOffsets(e,t){let i=t.left,n=t.top;return{left:e.left-i,top:e.top-n,right:e.right-i,bottom:e.bottom-n,width:e.width,height:e.height}}getRangeClientRects(e){let t=e.getClientRects(),i=this.layoutBox.getBoundingClientRect();return Array.from(t).map(n=>this.scaleRect(this.subtractOffsets(n,i)))}getElementClientRect(e){let t=e.getBoundingClientRect();if(t.left===0&&t.top===0&&t.right===0&&t.bottom===0)return t;let i=this.layoutBox.getBoundingClientRect();return this.scaleRect(this.subtractOffsets(t,i))}getElementComputedStyle(e){return this.window.getComputedStyle(e,null)}adjustLengthValue(e){let t=64*(this.scaleRatio||1);return Math.floor(e*t)/t}},cs=class{constructor(e,t,i,n,s,r){this.window=e,this.fontSize=t,this.pixelRatio=i,u(this,"document"),u(this,"root"),u(this,"outerZoomBox"),u(this,"contentContainer"),u(this,"layoutBox"),u(this,"width"),u(this,"height"),u(this,"scaleRatio",1),this.document=e.document,this.root=n||this.document.body;let o=this.root.firstElementChild;o||(o=this.document.createElement("div"),o.setAttribute("data-vivliostyle-outer-zoom-box","true"),o.role="presentation",this.root.appendChild(o));let a=o.firstElementChild;a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),a.role="presentation",o.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(P(this.root,"--viv-outputPixelRatio",`${i}`),P(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio,qn===null&&(qn=!("currentCSSZoom"in a)),qn&&P(this.root,"--viv-scaleRectRatio",`${this.scaleRatio}`));let h=o.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),h.role="presentation",this.root.appendChild(h)),this.outerZoomBox=o,this.contentContainer=a,this.layoutBox=h,this.width=s||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=r||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let l={width:794,height:1056},c=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!s&&c)&&(this.width=l.width),(!this.height||!r&&c)&&(this.height=l.height)}resetZoom(){P(this.outerZoomBox,"width",""),P(this.outerZoomBox,"height",""),P(this.contentContainer,"width",""),P(this.contentContainer,"height",""),P(this.contentContainer,"transform","")}zoom(e,t,i){P(this.root,"--viv-outputScale",`${i}`),P(this.outerZoomBox,"width",`${e*i}px`),P(this.outerZoomBox,"height",`${t*i}px`),P(this.contentContainer,"width",`${e}px`),P(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}},lc=class{constructor(e,t,i){this.store=e,this.url=t,this.document=i,u(this,"lang",null),u(this,"totalOffset",-1),u(this,"root"),u(this,"body"),u(this,"head"),u(this,"last"),u(this,"lastOffset",1),u(this,"idMap"),this.root=i.documentElement;let n=null,s=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let r=this.root.firstChild;r;r=r.nextSibling){if(r.nodeType!=1)continue;let o=r;if(o.namespaceURI=="http://www.w3.org/1999/xhtml")switch(o.localName){case"head":s=o;break;case"body":n=o;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=s,this.last=this.root,this.last.setAttribute(kt,"0")}doc(){return new uc([this.document])}getElementOffset(e){let t=e.getAttribute(kt);if(t)return parseInt(t,10);let i=this.lastOffset,n=this.last;for(;n!=e;){let s=n.firstChild;if(!s){for(;s=n.nextSibling,!s;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=s,s.nodeType==1?(s.setAttribute(kt,i.toString()),++i):i+=s.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,s=e,r=null;if(s.nodeType==1){if(!i)return this.getElementOffset(s)}else{if(n=t,r=s.previousSibling,!r)return s=s.parentNode,n+=1,this.getElementOffset(s)+n;s=r}for(;;){for(;s.lastChild;)s=s.lastChild;if(s.nodeType==1)break;if(n+=s.textContent.length,r=s.previousSibling,!r){s=s.parentNode;break}s=r}return n+=1,this.getElementOffset(s)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let h=Ht(a.length,l=>{let c=a[l];return this.getElementOffset(c)>e});if(h==0)break;i=a[h-1]}let n=t+1,s=i,r=s.firstChild||s.nextSibling,o=null;for(;;){if(r){if(r.nodeType==1||(s=r,o=s,n+=r.textContent.length,n>e&&!/^\s*$/.test(r.textContent)))break}else if(s=s.parentNode,!s)break;r=s.nextSibling}return r&&o&&/^\s*$/.test(o.textContent)&&(o=r),o||i}buildIdMap(e){let t=e.getAttribute("id");t&&!this.idMap[t]&&(this.idMap[t]=e);let i=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=e);for(let n=e.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(e){let t=e.match(/([^#]*)#(.+)$/);if(!t||t[1]&&t[1]!=this.url)return null;let i=t[2],n=this.document.getElementById(i);return!n&&this.document.getElementsByName&&(n=this.document.getElementsByName(i)[0]),n||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),n=this.idMap[i]),n}},Mr=(e=>(e.TEXT_HTML="text/html",e.TEXT_XML="text/xml",e.APPLICATION_XML="application/xml",e.APPLICATION_XHTML_XML="application/xhtml+xml",e.IMAGE_SVG_XML="image/svg+xml",e))(Mr||{});function Dn(e,t,i){let n=i||new DOMParser,s;try{s=n.parseFromString(e,t)}catch{}if(s){let r=s.documentElement,o="parsererror";if(r.localName===o)return null;for(let a=r.firstElementChild;a;a=a.nextElementSibling)if(a.localName===o)return null}else return null;return s}function Vw(e){let t=e.contentType;if(t){let n=Object.keys(Mr);for(let s=0;s<n.length;s++)if(Mr[n[s]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let i=e.url.match(/\.([^./]+)$/);if(i)switch(i[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 hc(e,t){let i=e.responseXML;if(!i){let s=new DOMParser,r=e.responseText;if(r){let o=Vw(e);if(i=Dn(r,o||"application/xml",s),i&&!o){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Dn(r,"text/html",s):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Dn(r,"image/svg+xml",s))}i||(i=Dn(r,"text/html",s))}}let n=i?new lc(t,e.url,i):null;return N(n)}function Uw(){return new Kr(hc,"document")}var Hw=class zr{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new zr(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new zr(n=>{if(!this.check(n))return!1;let s=new uc([n]);return s=s.child(t),i&&(s=s.predicate(i)),s.size()>0})}},Ka=new Hw(e=>!0),uc=class Dr{constructor(t){this.nodes=t}asArray(){return this.nodes}size(){return this.nodes.length}predicate(t){let i=[];for(let n of this.nodes)t.check(n)&&i.push(n);return new Dr(i)}forEachNode(t){let i=[],n=s=>{i.push(s)};for(let s=0;s<this.nodes.length;s++)t(this.nodes[s],n);return new Dr(i)}forEach(t){let i=[];for(let n=0;n<this.nodes.length;n++)i.push(t(this.nodes[n]));return i}forEachNonNull(t){let i=[];for(let n=0;n<this.nodes.length;n++){let s=t(this.nodes[n]);s!=null&&i.push(s)}return i}child(t){return this.forEachNode((i,n)=>{for(let s=i.firstChild;s;s=s.nextSibling)s.nodeType==1&&s.localName==t&&n(s)})}childElements(){return this.forEachNode((t,i)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&i(n)})}attribute(t){return this.forEachNonNull(i=>i.nodeType==1?i.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}},$w=new Cn(()=>{let e=F("uaStylesheetBase"),t=Gu(),i=Ce("user-agent-base.css",ii),n=new cn(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),vg(n.cascade),Qr(oh,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function Gw(){return $w.get()}var Ww=class{constructor(e,t,i,n,s,r,o,a,h,l){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=s,this.fontFaces=r,this.footnoteProps=o,this.flowProps=a,this.viewportProps=h,this.pageProps=l,u(this,"fontDeobfuscator"),u(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(c){c=c;let p=this,d=p.currentLayoutPosition,f=d.firstFlowChunkOfFlow(c);return p.matchPageSide(d.startSideOfFlow(c))&&d.hasContent(c,p.lookupOffset)&&!!f&&!p.flowChunkIsAfterParentFlowForcedBreak(f)}),this.pageScope.defineName("page-number",new Te(this.pageScope,function(){let c=this;return c.pageNumberOffset+c.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new Te(this.pageScope,function(){let c=this.currentLayoutPosition;return c?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let s=new Ks(this.rootScope,e,t,i),r=_f(s,this.viewportProps),o=r.width,a=r.height,h=r["text-zoom"],l=1;if(o&&a||h){let c=pe.em;if((h?h.evaluate(s,"text-zoom"):null)===v.scale&&(l=c/i,i=c,e*=l,t*=l),o&&a){let p=We(o.evaluate(s,"width"),s),d=We(a.evaluate(s,"height"),s);if(p>0&&d>0)return{width:n&&n.spreadView?(p+n.pageBorder)*2:p,height:d,fontSize:i}}}}return{width:e,height:t,fontSize:i}}},To=class extends Ks{constructor(e,t,i,n,s,r,o,a,h,l,c,p,d){super(e.rootScope,n.width,n.height,n.fontSize),this.style=e,this.xmldoc=t,this.viewport=n,this.clientLayout=s,this.fontMapper=r,this.customRenderer=o,this.fallbackMap=a,this.pageNumberOffset=h,this.documentURLTransformer=l,this.counterStore=c,u(this,"lang"),u(this,"primaryFlows",{body:!0}),u(this,"rootPageBoxInstance",null),u(this,"styler",null),u(this,"stylerMap",null),u(this,"currentLayoutPosition",null),u(this,"layoutPositionAtPageStart",null),u(this,"lookupOffset",0),u(this,"faces"),u(this,"pageBoxInstances",{}),u(this,"pageManager",null),u(this,"rootPageFloatLayoutContext"),u(this,"pageBreaks",{}),u(this,"pageProgression",null),u(this,"isVersoFirstPage",!1),u(this,"blankPageAtStart",!1),u(this,"pageSheetSize",{}),u(this,"pageSheetHeight",0),u(this,"pageSheetWidth",0),this.lang=t.lang||i,this.faces=new Xm(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new Wi(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!d;for(let f in e.flowProps){let m=e.flowProps[f],g=Ue(m,"flow-consume");g&&(g.evaluate(this,"flow-consume")==v.all?this.primaryFlows[f]=!0:delete this.primaryFlows[f])}}init(){let e=F("StyleInstance.init"),t=this.counterStore.createCounterListener(this.xmldoc.url),i=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new Ma(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,t,i),i.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let n=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=ec(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let s=this.style.rootBox;this.rootPageBoxInstance=new Qm(s);let r=this.style.cascade.createInstance(this,t,i,this.lang);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(r,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new mw(r,this.style.pageScope,this.rootPageBoxInstance,this,n);let o=[];for(let h of this.style.fontFaces){if(h.condition&&!h.condition.evaluate(this))continue;let l=jm(h.properties,this),c=new Wu(l);o.push(c)}this.fontMapper.findOrLoadFonts(o,this.faces).then(()=>{Lw(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let a=this.style.pageProps;return a[""]||(a[""]={}),Object.keys(a).forEach(h=>{let l=a[h];this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context);let c=qa(us(l),this);this.pageSheetSize[h]={width:c.pageWidth+c.cropOffset*2,height:c.pageHeight+c.cropOffset*2}}),e.result()}matchStartPageSide(e){let t=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),i=this.pageProgression=="ltr";switch(e){case"left":return t!==i;case"right":return t===i;case"recto":return t;case"verso":return!t;default:return!0}}getStylerForDoc(e){let t=this.stylerMap[e.url];if(!t){let i=this.style.store.getStyleForDoc(e),n=new Ks(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),s=this.counterStore.createCounterListener(e.url),r=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new Ma(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,s,r),this.stylerMap[e.url]=t}return t}registerInstance(e,t){this.pageBoxInstances[e]=t}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,t){let i=this.currentLayoutPosition;if(i){i.flows[e.flowName]?t=i.flows[e.flowName]:i.flows[e.flowName]=t;let n=i.flowPositions[e.flowName];n||(n=new of,i.flowPositions[e.flowName]=n);let s=nf(e.element),r=new Wt(s),o=new rf(r,e);n.positions.push(o)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;let n=!0;class s{unknownProperty(h,l){n=!1}invalidPropertyValue(h,l){n=!1}simpleProperty(h,l,c){}}let r=new s,o=Fi(this.style.rootScope,new yt(t,null),"");return o?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,o,!1,r),n):!1}evalSupportsSelector(e){let t=new cc(null),i=new yt(e+"{}",t);return new kn(xe,i,t,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!t.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let t=Number.POSITIVE_INFINITY;for(let i=0;i<e.positions.length;i++){let n=e.positions[i].chunkPosition.primary,s=n.steps[0].node,r=n.offsetInNode,o=n.after,a=0;for(;s.ownerDocument!=this.xmldoc.document;)a++,s=n.steps[a].node,o=!1,r=0;let h=this.xmldoc.getNodeOffset(s,r,o);h<t&&(t=h)}return t}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let s=e.flowPositions[n];if(!t&&(!s||s.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),s=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&s&&(s=s.clone(),e.flowPositions[n]=s)),s){let r=this.getConsumedOffset(s);r<i&&(i=r)}}return i}dumpLocation(e){H.debug("Location - page",this.currentLayoutPosition.page),H.debug(" current:",e),H.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)H.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new Ie(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let t in e.flowPositions){let i=e.flowPositions[t];if(i&&i.positions.length>0){let n=i.positions[0].flowChunk;if(this.getConsumedOffset(i)===n.startOffset){let s=i.positions[0].flowChunk.breakBefore,r=i.startBreakType;i.startBreakType=ha(qe(r,s))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,s;for(let r=0;r<n.length;r++){if(s=n[r],s.pageBox.pseudoName===No)continue;let o=1;s.pageBox.pseudoName===So&&!(this.actualPageWidth&&this.actualPageHeight)&&(o=1/0);let a=s.getProp(this,"utilization");a&&a.isNum()&&(o=a.num);let h=this.queryUnitSize("em",!1),l=this.pageWidth()*this.pageHeight(),c=Math.ceil(o*l/(h*h)),p=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,c),this.styler.cascade.currentPageType=p,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let d=s.getProp(this,"enabled");if(!d||d===v._true){if(t.page===1&&this.blankPageAtStart){s.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(s,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,s=t[i].forcedBreakOffsets;if(!s.length||n<s[0])return!1;let r=Ht(s.length,l=>s[l]>n)-1,o=s[r],a=this.layoutPositionAtPageStart.flowPositions[i],h=this.getConsumedOffset(a);return o<h?!1:h<o?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new oo(null)),e.flowRootFormattingContext=i.formattingContext}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=a=>{if(a.floatReference!==Se.PAGE)return!1;let h=this.layoutPositionAtPageStart.flowPositions.body,l=h&&this.getConsumedOffset(h),c=this.xmldoc.getNodeOffset(a.nodePosition.steps[0].node,0,!1);return c!=null&&l!=null&&c>l},s=F("layoutDeferredPageFloats"),r=!1,o=0;return s.loopWithFrame(a=>{if(o===i.length){a.breakLoop();return}let h=i[o++],l=h.float;if(n(l)){a.breakLoop();return}let c=new Ti().findByFloat(l),p=c.findPageFloatFragment(l,t);if(p&&p.hasFloat(l)){a.continueLoop();return}else if(t.isForbidden(l)||t.hasPrecedingFloatsDeferredToNext(l)){t.deferPageFloat(h),a.breakLoop();return}e.layoutPageFloatInner(h,c,null,p).then(d=>{if(!d){a.breakLoop();return}let f=t.parent.isInvalidated();if(f){a.breakLoop();return}else t.isInvalidated()&&!f&&(r=!0,t.validate());a.continueLoop()})}).then(()=>{r&&t.invalidate(),s.finish(!0)}),s.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new Wt(e.lastAfterPosition),i}else return null;else return null}layoutColumn(e,t){let i=this.currentLayoutPosition.flowPositions[t];if(!i||!this.matchPageSide(i.startBreakType))return N(!0);this.setFormattingContextToColumn(e,t),e.init(),this.primaryFlows[t]&&e.bands.length>0&&(e.forceNonfitting=!1);let n=F("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let s=[],r=[],o=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-r.length>0;){let h=0;for(;r.includes(h);)h++;let l=i.positions[h];if(l.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(l.flowChunk))break;for(let d=h+1;d<i.positions.length;d++){if(r.includes(d))continue;let f=i.positions[d];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(l.flowChunk)&&(l=f,h=d)}let c=l.flowChunk,p=!0;if(e.layout(l.chunkPosition,o,i.breakAfter).then(d=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(o=!1,l.flowChunk.repeated&&(d===null||c.exclusive)&&s.push(h),c.exclusive){r.push(h),a.breakLoop();return}else{let f=!!d||!!e.pageBreakType,m=this.getLastAfterPositionIfDeferredFloatsExists(e,d);if(e.pageBreakType&&m?(l.chunkPosition=m,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(r.push(h),(d||m)&&(l.chunkPosition=d||m,s.push(h)),i.startBreakType=ha(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,p?p=!1:a.continueLoop()}),p){p=!1;return}}a.breakLoop()}).then(()=>{if(!e.pageFloatLayoutContext.isInvalidated()){i.positions=i.positions.filter((h,l)=>s.includes(l)||!r.includes(l)),i.breakAfter==="column"&&(i.breakAfter=null),e.saveDistanceToBlockEndFloats();let a=e.pageFloatLayoutContext.getMaxReachedAfterEdge();e.updateMaxReachedAfterEdge(a)}n.finish(!0)})}),n.result()}createLayoutConstraint(e){let t=this.currentLayoutPosition.page-1,i=this.counterStore.createLayoutConstraint(t);return new Vg([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,s,r,o,a,h,l,c,p,d,f){let m=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,g=s.element,w=new Wi(a,Se.COLUMN,null,o,null,null,null),y=this.currentLayoutPosition.clone(),b=F("createAndLayoutColumn"),S;return b.loopWithFrame(T=>{let R=this.createLayoutConstraint(w);if(h>1){let M=this.viewport.document.createElement("div");if(P(M,"position","absolute"),g.appendChild(M),S=new ls(M,d,this.clientLayout,R,w),S.forceNonfitting=f,S.vertical=s.vertical,S.rtl=s.rtl,S.snapHeight=s.snapHeight,S.snapWidth=s.snapWidth,s.vertical){let V=(s.rtl?h-r-1:r)*(c+l)+s.paddingTop,W=parseFloat(g.style.width);S.setHorizontalPosition(s.paddingLeft+W-s.width,s.width),S.setVerticalPosition(V,c)}else{let V=(s.rtl?h-r-1:r)*(c+l)+s.paddingLeft;S.setVerticalPosition(s.paddingTop,s.height),S.setHorizontalPosition(V,c)}S.originX=t,S.originY=i}else S=new ls(g,d,this.clientLayout,R,w),S.copyFrom(s);S.exclusions=m?[]:n.concat(),S.innerShape=p,w.setContainer(S),(S.vertical?S.height:S.width)>=0?this.layoutColumn(S,o).then(()=>{w.isInvalidated()||w.finish(),S.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(S.pageFloatLayoutContext.validate(),this.currentLayoutPosition=y.clone(),S.element!==g&&g.removeChild(S.element),T.continueLoop()):T.breakLoop()}):(w.finish(),T.breakLoop())}).then(()=>{b.finish(S)}),b.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof nc||t instanceof Co&&!(t instanceof Ei))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof Ii;let s=t.getProp(this,"writing-mode")||null,r=t.getProp(this,"direction")||null;return new Wi(e,Se.REGION,i,n,null,s,r)}layoutFlowColumnsWithBalancing(e,t,i,n,s,r,o,a,h){let l=this.currentLayoutPosition.clone(),c=this.getRegionPageFloatLayoutContext(r,t,o,a),p=!0,d=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,s,r,c,o,a,h,p).thenAsync(f=>N(f?{columns:f,position:this.currentLayoutPosition}:null)));return d().thenAsync(f=>{if(!f)return N(null);if(h<=1)return N(f.columns);let m=t.getProp(this,"column-fill")||v.balance,g=this.currentLayoutPosition.flowPositions[a],w=Tm(h,m,d,c,o,f.columns,g);return w?(p=!1,r.lock(),c.lock(),w.balanceColumns(f).thenAsync(y=>(r.unlock(),r.validate(),c.unlock(),this.currentLayoutPosition=y.position,N(y.columns)))):N(f.columns)})}layoutFlowColumns(e,t,i,n,s,r,o,a,h,l,c){let p=F("layoutFlowColumns"),d=this.currentLayoutPosition.clone(),f=t.getPropAsNumber(this,"column-gap"),m=l>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,g=t.getActiveRegions(this),w=t.getProp(this,"shape-inside"),y=Zl(w,0,0,a.width,a.height,this),b=new Mw(h,this,this.viewport,this.styler,g,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer),S=0,T=null,R=[];return p.loopWithFrame(M=>{this.createAndLayoutColumn(t,i,n,s,a,S++,h,o,l,f,m,y,b,c).then(V=>{if(r.isInvalidated()){R=null,M.breakLoop();return}if((V.pageBreakType&&V.pageBreakType!=="column"||S===l)&&!o.isInvalidated()&&o.finish(),o.isInvalidated()){S=0,this.currentLayoutPosition=d.clone(),o.validate(),o.isLocked()?(R=null,M.breakLoop()):M.continueLoop();return}T=V,R[S-1]=T,T.pageBreakType&&T.pageBreakType!="column"&&(S=l,T.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),S<l?M.continueLoop():M.breakLoop()})}).then(()=>{p.finish(R)}),p.result()}layoutContainer(e,t,i,n,s,r,o){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==v._true)return N(!0);let h=F("layoutContainer"),l=t.getProp(this,"wrap-flow")===v.auto,c=t.getProp(this,"flow-from"),p=this.viewport.document.createElement("div");p.role=t instanceof sc?"complementary":"presentation";let d=t.getProp(this,"position");P(p,"position",d?d.name:"absolute");let f=t instanceof Ei;t instanceof Ii?i.appendChild(p):i.insertBefore(p,i.firstChild);let m=new Ah(p);m.vertical=t.vertical,m.rtl=t.rtl,m.borderBoxSizing=t.borderBoxSizing,m.exclusions=r,t.prepareContainer(this,m,e,this.faces,this.clientLayout),t instanceof Ei&&(m.width<=0||m.height<=0)&&H.warn("Negative or zero page area size"),m.originX=n,m.originY=s,n+=m.left+m.marginLeft+m.borderLeft,s+=m.top+m.marginTop+m.borderTop,this.setPagePageFloatLayoutContextContainer(o,t,m);let g,w=!1;if(!c||!c.isIdent()){let y=t.getProp(this,"content");if(y instanceof D&&y.expr instanceof Te&&y.expr.str.startsWith("running-element-"))y.visit(new ss(p,this,y,this.counterStore.getExprContentListener()));else if(y&&jt(y)){let b="span";y.url&&(b="img");let S=this.viewport.document.createElement(b);y.visit(new ss(S,this,y,this.counterStore.getExprContentListener())),p.appendChild(S),b=="img"&&t.transferSingleUriContentProps(this,S,this.faces),t.transferContentProps(this,m,e,this.faces),b=="span"&&Lg(S,t.getProp(this,"text-autospace"),t.getProp(this,"text-spacing-trim"),t.getProp(this,"hanging-punctuation"),this.lang,t.vertical)}else t.suppressEmptyBoxGeneration&&(i.removeChild(p),w=!0);w||t.finishContainer(this,m,e,null,1,this.clientLayout,this.faces),g=N(!0)}else if(this.pageBreaks[c.toString()])o.isInvalidated()||t.finishContainer(this,m,e,null,1,this.clientLayout,this.faces),g=N(!0);else{let y=F("layoutContainer.inner"),b=c.toString(),S=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,s,r,o,m,b,S).then(T=>{if(!o.isInvalidated()){let R=T[0];R.element===p&&(m=R),m.computedBlockSize=Math.max.apply(null,T.map(V=>V.computedBlockSize)),t.finishContainer(this,m,e,R,S,this.clientLayout,this.faces);let M=this.currentLayoutPosition.flowPositions[b];M&&M.breakAfter==="region"&&(M.breakAfter=null)}y.finish(!0)}),g=y.result()}return g.then(()=>{if(o.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(m.computedBlockSize)>0){if(!w&&!l){let b=t.getProp(this,"shape-outside"),S=m.getOuterShape(b,this);r.push(S)}}else if(t.children.length==0){i.removeChild(p),h.finish(!0);return}let y=f?0:t.children.length-1;h.loop(()=>{for(;y>=0&&y<t.children.length;){let b=t.children[f?y++:y--],S=this.layoutContainer(e,b,p,n,s,r,o);if(S.isPending())return S.thenAsync(()=>N(!o.isInvalidated()));if(o.isInvalidated())break}return N(!1)}).then(()=>{h.finish(!0)})}),h.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let s=i.positions[n];s.flowChunk.startPage>=0&&s.flowChunk.startPage+s.flowChunk.linger-1<=e&&i.positions.splice(n,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let s=i.positions[n];s.flowChunk.startPage<0&&s.flowChunk.startOffset<this.lookupOffset&&(s.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let t in this.primaryFlows){let i=e.flowPositions[t];if(i&&i.positions.length>0)return!1}return!0}layoutNextPage(e,t){var i;let n=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new af,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let s=1e4;if(t.page>s)throw new Error(`Too many pages generated (over ${s} pages)`);let r=t.startSideOfFlow("body");t.isBlankPage=un(r)&&this.matchPageSide(r),e.isBlankPage=t.isBlankPage,t.page++,e.pageType==null&&(e.pageType=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let o=n?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.styler.cascade.applyVarFilter([o],this.styler,null),this.styler.cascade.applyCalcFilter(o,this.styler.context),!n){let f=new Ie(this.style.pageScope,"left-page");e.side=f.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let a=this.selectPageMaster(o);if(!a)return N(null);let h=0;if(!n){e.setAutoPageWidth(a.pageBox.specified.width.value===xn),e.setAutoPageHeight(a.pageBox.specified.height.value===Sn),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(o,this);let f=qa(us(o),this);this.setPageSizeAndBleed(f,e),hw(o,f,e,this),h=f.bleedOffset+f.bleed}let l=!n&&a.getProp(this,"writing-mode")||v.horizontal_tb;this.pageVertical=l!=v.horizontal_tb;let c=a.getProp(this,"direction")||v.ltr,p=new Wi(this.rootPageFloatLayoutContext,Se.PAGE,null,null,null,l,c),d=F("layoutNextPage");return d.loopWithFrame(f=>{this.layoutContainer(e,a,e.bleedBox,h,h,[],p).then(()=>{p.isInvalidated()||p.finish(),p.isInvalidated()?(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),p.validate(),f.continueLoop()):f.breakLoop()})}).then(()=>{a.adjustPageLayout(this,e,this.clientLayout),n||(this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(m=>{let g=t.flowPositions[m],w=g.breakAfter;w&&(w==="page"||!this.matchPageSide(w))&&(g.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let f=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(f,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),d.finish(t)}),d.result()}setPageSizeAndBleed(e,t){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,t.container.style.width=`${this.pageSheetWidth}px`,t.container.style.height=`${this.pageSheetHeight}px`,t.bleedBox.style.left=`${e.bleedOffset}px`,t.bleedBox.style.width=`${e.pageWidth}px`,t.bleedBox.style.top=`${e.bleedOffset}px`,t.bleedBox.style.height=`${e.pageHeight}px`,t.bleedBox.style.padding=`${e.bleed}px`}},jw=class Vr extends cn{constructor(t,i,n,s){super(t.rootScope,t,i,n,s,t.validatorSet,!n),this.masterHandler=t,u(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let s=new ju(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new iw(s.scope,this.masterHandler,s,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=pt(this.scope,this.condition,i)),this.masterHandler.pushHandler(new Vr(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new Eg(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new zn(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startFlowRule(t){let i=this.masterHandler.flowProps[t];i||(i={},this.masterHandler.flowProps[t]=i),this.masterHandler.pushHandler(new zn(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new zn(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=ys(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new zn(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new Pw(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(cn.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let t=`R${this.masterHandler.regionCount++}`;this.special("region-id",B(t)),this.endRule();let i=new Vr(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},cc=class extends Ip{constructor(e){super(),this.validatorSet=e,u(this,"rootScope"),u(this,"pageScope"),u(this,"rootBox"),u(this,"cascadeParserHandler"),u(this,"regionCount",0),u(this,"fontFaces",[]),u(this,"footnoteProps",{}),u(this,"flowProps",{}),u(this,"viewportProps",[]),u(this,"pageProps",{}),this.rootScope=new Zs(null),this.pageScope=new Zs(this.rootScope),this.rootBox=new Zm(this.rootScope),this.cascadeParserHandler=new jw(this,null,null,null),this.slave=this.cascadeParserHandler}};function Xw(e,t){return t.parseOPSResource(e)}var qw=class extends Kr{constructor(e){super(Xw,"document"),this.fontDeobfuscator=e,u(this,"styleByKey",{}),u(this,"styleFetcherByKey",{}),u(this,"styleByDocURL",{}),u(this,"triggersByDocURL",{}),u(this,"validatorSet",null),u(this,"styleSheets",[]),u(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=F("OPSDocStore.init");return this.validatorSet=Gu(),Gw().then(()=>{this.triggerSingleDocumentPreprocessing=!0,i.finish(!0)}),i.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,t){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),t&&t.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let t=e.url;t&&(t=Ce(hn(t),ki)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ce(hn(t),ki)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=F("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return hc(e,this).then(s=>{var r;if(!s){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let d=vt("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<d.length;f++)try{d[f](s.document)}catch(m){H.warn("Error during single document preprocessing:",m)}}let o=[],a=s.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let d=0;d<a.length;d++){let f=a[d],m=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),g=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),w=f.getAttribute("action"),y=f.getAttribute("ref");m&&g&&w&&y&&o.push({observer:m,event:g,action:w,ref:y})}this.triggersByDocURL[i]=o;let h=[];if(h.push({url:Ce("user-agent-page.css",ii),text:rh,flavor:"UA",classes:null,media:null}),n)h.push({url:Ce("user-agent-toc.css",ii),text:ah,flavor:"UA",classes:null,media:null});else{let d=s.document.querySelectorAll("style, link, meta");for(let f of d){let m=f.namespaceURI,g=f.localName;if(m=="http://www.w3.org/1999/xhtml")if(g=="style"){let w=f.getAttribute("class"),y=f.getAttribute("media"),b=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:b?w:null,media:y})}else if(g=="link"){let w=f.getAttribute("href"),y=(r=f.getAttribute("rel"))==null?void 0:r.split(/\s+/),b=f.getAttribute("class"),S=f.getAttribute("media");if(w&&y!=null&&y.includes("stylesheet")&&(!y.includes("alternate")||b)){let T=Ce(w,i),R=f.getAttribute("title");h.push({url:T,text:null,classes:R?b:null,media:S,flavor:"Author"})}}else g=="meta"&&f.getAttribute("name")=="viewport"&&h.push({url:i,text:this.processViewportMeta(f),flavor:"Author",classes:null,media:null})}for(let f=0;f<this.styleSheets.length;f++)h.push(this.styleSheets[f])}let l="";for(let d=0;d<h.length;d++)l+=h[d].url,l+="^",h[d].text&&(l+=h[d].text),l+="^";let c=this.styleByKey[l];if(c){this.styleByDocURL[i]=c,t.finish(s);return}let p=this.styleFetcherByKey[l];p||(p=new Cn(()=>{let d=F("fetchStylesheet"),f=0,m=new cc(this.validatorSet);return d.loop(()=>{if(f<h.length){let g=h[f++];return m.startStylesheet(g.flavor),g.text!==null?Qr(g.text,m,g.url,g.classes,g.media).thenReturn(!0):fh(g.url,m,g.classes,g.media)}return N(!1)}).then(()=>{let g=m.cascadeParserHandler.finish();c=new Ww(this,m.rootScope,m.pageScope,g,m.rootBox,m.fontFaces,m.footnoteProps,m.flowProps,m.viewportProps,m.pageProps),this.styleByKey[l]=c,delete this.styleFetcherByKey[l],d.finish(c)}),d.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[l]=p,p.start()),p.get().then(d=>{this.styleByDocURL[i]=d,t.finish(s)})}),t.result()}processViewportMeta(e){return""}},an="\u25B8",Ja="\u25BE",Yw="\u25B9";function Io(e){let t=Array.from(e.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(e.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of e.querySelectorAll(i)){if(t.find(r=>r.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 Zw(e){let t=Io(e),i=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))i.push(s);return i}var Kw=class{constructor(e,t,i,n,s,r,o,a,h,l){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=s,this.rendererFactory=o,this.fallbackMap=a,this.documentURLTransformer=h,this.counterStore=l,u(this,"pref"),u(this,"page",null),u(this,"instance",null),this.pref=Cl(r),this.pref.spreadView=!1}setAutoHeight(e,t){if(t--!=0){for(let i=e.firstChild;i;i=i.nextSibling)if(i.nodeType==1){let n=i;_t(n,"height","auto")!="auto"&&(P(n,"height","auto"),this.setAutoHeight(n,t)),_t(n,"position","static")=="absolute"&&(P(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,s)=>{let r=s.behavior;if(r)switch(r.toString()){case"toc-node-anchor":s.color=v.inherit,s["text-decoration"]=v.none;break;case"toc-node":s.display=v.block,s.margin=ge,s.padding=ge,s["padding-inline-start"]=new I(1.25,"em");break;case"toc-node-first-child":s.display=v.inline_block,s.margin=new I(.2,"em"),s["vertical-align"]=v.top,s.color=v.inherit,s["text-decoration"]=v.none;break;case"toc-container":s.padding=ge;break}if(!r||r.toString()!="toc-node"&&r.toString()!="toc-container")return t(i,n,s);let o=i.firstChild;o&&o.nodeType!==1&&ze(o)&&i.replaceChild(i.ownerDocument.createComment(o.textContent),o);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=an&&(l.textContent=an,P(l,"cursor","pointer"),l.addEventListener("click",Jw,!1),l.setAttribute("role","button"),l.setAttribute("aria-expanded","false"),n.setAttribute("aria-expanded","false"),n.style.height!=="0px"&&(l.tabIndex=0))}let h=n.ownerDocument.createElement("div");if(h.setAttribute("data-adapt-process-children","true"),r.toString()=="toc-node"){let l=n.ownerDocument.createElement("div");if(l.textContent=Yw,P(l,"margin","0.2em 0 0 -1em"),P(l,"margin-inline-start","-1em"),P(l,"margin-inline-end","0"),P(l,"display","inline-block"),P(l,"width","1em"),P(l,"text-align","center"),P(l,"vertical-align","top"),P(l,"cursor","default"),P(l,"font-family","Menlo,sans-serif"),h.appendChild(l),P(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){P(h,"height","0px");let c=i.firstElementChild;c&&c.localName==="a"&&(c.tabIndex=-1)}else n.setAttribute("role","tree")}else a=="toc-node"&&(h.setAttribute("data-adapt-class","toc-container"),h.setAttribute("role","group"),h.setAttribute("aria-hidden","true"));return N(h)}}showTOC(e,t,i,n,s){if(this.page)return N(this.page);let r=F("showTOC"),o=new Ch(e,e);this.page=o;let a=Pt(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of Io(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),c=l.sizeViewport(i,1e5,s);t=new cs(t.window,c.fontSize,0,t.root,c.width,c.height);let p=this.makeCustomRenderer(h),d=new To(l,h,this.lang,t,this.clientLayout,this.fontMapper,p,this.fallbackMap,0,this.documentURLTransformer,this.counterStore);this.instance=d,d.pref=this.pref,d.init().then(()=>{d.layoutNextPage(o,null).then(()=>{this.setAutoHeight(e,2),r.finish(o)})})}),r.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 e(n){if(!n)return[];let s=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(s).map(t)}function t(n){let s=new URL(n.href),[,r]=s.hash.match(/^#?(.*)$/),o=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=e(a);return{id:r,title:o,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function Jw(e){let t=e.target,i=t.textContent==an;t.textContent=i?Ja:an;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let s=n.firstChild;for(;s;){if(s.nodeType===1){let r=s,o=r.getAttribute("data-adapt-class");if(o==="toc-container"){if(r.setAttribute("aria-hidden",i?"false":"true"),r.firstChild){s=r.firstChild;continue}}else if(o==="toc-node"&&(r.style.height=i?"auto":"0px",r.children.length>=2&&(r.children[1].tabIndex=i?0:-1),r.children.length>=3&&(r.children[0].tabIndex=i?0:-1,!i))){let a=r.children[0];if(a.textContent==Ja){a.textContent=an,a.setAttribute("aria-expanded","false"),r.setAttribute("aria-expanded","false"),s=r.children[2];continue}}}for(;!s.nextSibling&&s.parentNode!==n;)s=s.parentNode;s=s.nextSibling}e.stopPropagation()}var Qa=class extends qw{constructor(){super(null),u(this,"plainXMLStore"),u(this,"jsonStore"),u(this,"opfByURL",{}),u(this,"primaryOPFByEPubURL",{}),u(this,"deobfuscators",{}),u(this,"documents",{}),this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=Uw(),this.jsonStore=kp()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,t,i){return this.plainXMLStore.load(e,t,i)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,t,i){return this.jsonStore.load(e,t,i)}loadPubDoc(e){let t=F("loadPubDoc");return bs(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}H.error(`Failed to fetch a source document from ${e} (${i.status}${i.statusText?" "+i.statusText:""})`),t.finish(null)});else if(!i.status&&!i.responseXML&&!i.responseText&&!i.responseBlob&&!i.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),i.contentType=="application/oebps-package+xml"||/\.opf(?:[#?]|$)/.test(e)){let[,n,s]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,s).thenFinish(t)}else i.contentType=="application/ld+json"||i.contentType=="application/webpub+json"||i.contentType=="application/audiobook+json"||i.contentType=="application/json"||/\.json(?:ld)?(?:[#?]|$)/.test(e)?this.loadAsJSON(e,!0).then(n=>{if(!n){this.reportLoadError(e),t.finish(null);return}let s=new Yn(this,e);s.initWithWebPubManifest(n,void 0,e).then(()=>{t.finish(s)})}):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(s=>{if(s){t.finish(s);return}H.error(`Failed to load ${e}.`),t.finish(null)})})}),t.result()}loadEPUBDoc(e){let t=F("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let i=e+"META-INF/container.xml";return this.loadAsPlainXML(i).then(n=>{if(n){let s=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let r of s)if(r){this.loadOPF(e,r).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return N(n);let s=F("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(r=>{r?(n=new Yn(this,e),this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(o=>{n.initWithXMLDoc(r,o).then(()=>{s.finish(n)})}):n.initWithXMLDoc(r,null).then(()=>{s.finish(n)})):this.reportLoadError(i)}),s.result()}loadWebPub(e){let t=F("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,s=new Yn(this,e),r=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(r){let o=r.getAttribute("href");if(/^#/.test(o)){let a=Hr(n.getElementById(o.substr(1)).textContent);s.initWithWebPubManifest(a,n).then(()=>{t.finish(s)})}else{let a=Ce(r.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{s.initWithWebPubManifest(h,n,a).then(()=>{t.finish(s)})})}}else s.initWithWebPubManifest({},n).then(()=>{s.toc&&s.toc.src===i.url&&Io(n).length===0&&(s.toc=null),t.finish(s)})}}),t.result()}addDocument(e,t){let i=F("EPUBDocStore.load"),n=Pt(e);return(this.documents[n]=this.parseOPSResource({status:200,statusText:"",url:n,contentType:t.contentType,responseText:null,responseXML:t,responseBlob:null})).thenFinish(i),i.result()}reportLoadError(e){let t=n=>n.replace(/([^:/?#]|^)[/?#].*/,"$1"),i=()=>{let n=t(e);return!(n===t(ki)||Object.keys(this.resources).find(s=>this.resources[s]&&t(s)===n)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?H.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&ki.startsWith("https:")?H.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?H.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):H.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Pt(e),i=this.documents[t];if(i)return i.isPending()?i:N(i.get());{let n=F("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(s=>{s?n.finish(s):this.reportLoadError(t)}),n.result()}}processViewportMeta(e){let t=e.getAttribute("content");if(!t)return"";let i={},n;for(;(n=t.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)t=t.substr(n[0].length),i[n[1]]=n[2];let s=i.width-0,r=i.height-0;if(s&&r){let o=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${s}px;height:${r}px;}`+(o?`@page{size:${s}px ${r}px;margin:0;}`:"@page{margin:0;}")}return""}},el=class{constructor(){u(this,"id",null),u(this,"src",""),u(this,"mediaType",null),u(this,"title",null),u(this,"itemRefElement",null),u(this,"spineIndex",-1),u(this,"compressedSize",0),u(this,"compressed",null),u(this,"epage",0),u(this,"epageCount",0),u(this,"startPage",null),u(this,"skipPagesBefore",null),u(this,"itemProperties"),this.itemProperties=Yc}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Ce(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=id(i.split(/\s+/)))}initWithParam(e){this.spineIndex=e.index,this.id=`item${e.index+1}`,this.src=e.url,this.startPage=e.startPage,this.skipPagesBefore=e.skipPagesBefore}};function Qw(e){return e.id}function eb(e){return t=>{let i=F("deobfuscator");return tb("SHA-1",e).then(n=>{let s=t.slice(0,1040),r=t.slice(1040,t.size);Sp(s).then(o=>{let a=new DataView(o);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(hh([a,r]))})}),i.result()}}function tb(e,t){let i=F("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(s=>{n.schedule(new Uint8Array(s))}),i.result()}var Dt={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"},Yi="http://idpf.org/epub/vocab/package/meta/#",Ne={language:`${Dt.dcterms}language`,title:`${Dt.dcterms}title`,creator:`${Dt.dcterms}creator`,layout:`${Dt.rendition}layout`,titleType:`${Yi}title-type`,displaySeq:`${Yi}display-seq`,alternateScript:`${Yi}alternate-script`,role:`${Yi}role`};function ib(e,t){let i={};return(n,s)=>{var r,o,a,h,l,c;let p,d,f=n.r||i,m=s.r||i;if(e==Ne.title&&(p=((r=f[Ne.titleType])==null?void 0:r[0].v)=="main",d=((o=m[Ne.titleType])==null?void 0:o[0].v)=="main",p!=d))return p?-1:1;let g=parseInt((a=f[Ne.displaySeq])==null?void 0:a[0].v,10);isNaN(g)&&(g=Number.MAX_VALUE);let w=parseInt((h=m[Ne.displaySeq])==null?void 0:h[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),g!=w?g-w:e!=Ne.language&&t&&(p=((l=f[Ne.language]||f[Ne.alternateScript])==null?void 0:l[0].v)==t,d=((c=m[Ne.language]||m[Ne.alternateScript])==null?void 0:c[0].v)==t,p!=d)?p?-1:1:n.o-s.o}}function nb(e,t){let i;if(!t)i=Dt;else{i={};for(let d in Dt)i[d]=Dt[d];let p;for(;(p=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(p[0].length),i[p[1]]=p[2]}let n=p=>{if(p){let d=p.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(d){let f=d[2]?i[d[2]]:Yi;if(f)return f+d[3]}}return null},s=1,r=e.childElements().forEachNonNull(p=>{if(p.localName=="meta"){let d=n(p.getAttribute("property"));if(d)return{name:d,value:p.textContent,id:p.getAttribute("id"),order:s++,refines:p.getAttribute("refines"),lang:null,scheme:n(p.getAttribute("scheme")),role:null}}else if(p.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:Dt.dcterms+p.localName,order:s++,lang:p.getAttribute("xml:lang"),value:p.textContent,id:p.getAttribute("id"),refines:null,scheme:null,role:p.getAttribute("role")||p.getAttribute("opf:role")};return null}),o=As(r,p=>p.refines),a=p=>nd(p,(d,f)=>d.map(m=>{let g={v:m.value,o:m.order};m.scheme&&(g.s=m.scheme);let w=o[`#${m.id}`]||[];if(w.length||m.lang||m.role){m.lang&&w.push({name:Ne.language,value:m.lang,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null}),m.role&&w.push({name:Ne.role,value:m.role,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null});let y=As(w,b=>b.name);g.r=a(y)}return g})),h=a(As(r,p=>p.refines?null:p.name)),l=null;h[Ne.language]&&(l=h[Ne.language][0].v);let c=p=>{for(let d in p){let f=p[d];f.sort(ib(d,l));for(let m=0;m<f.length;m++){let g=f[m].r;g&&c(g)}}};return c(h),h}function sb(){let e=window.MathJax;return e?e.Hub:null}var tl={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},js="viv-id-",Yn=class{constructor(e,t){this.store=e,this.pubURL=t,u(this,"opfXML",null),u(this,"encXML",null),u(this,"items",null),u(this,"spine",null),u(this,"itemMap",null),u(this,"itemMapByPath",null),u(this,"uid",null),u(this,"bindings",{}),u(this,"lang",null),u(this,"epageCount",0),u(this,"prePaginated",!1),u(this,"epageIsRenderedPage",!0),u(this,"epageCountCallback",null),u(this,"metadata",{}),u(this,"toc",null),u(this,"cover",null),u(this,"fallbackMap",{}),u(this,"pageProgression",null),u(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,s){let r=s+(n?`#${n}`:"");return js+bl(r,":")}transformURL(n,s){let r=n.match(/^([^#]*)#?(.*)$/);if(r){let o=r[1]||s.replace(/\?viv-toc-box$/,""),a=decodeURIComponent(r[2]);if(o&&e.spine.some(h=>h.src===o))return`#${this.transformFragment(a,o)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(js)===0&&(n=n.substring(js.length));let s=td(n,":").match(/^([^#]*)#?(.*)$/);return s?[s[1],s[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=Ce("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let h=e.getElement(`${e.url}#${n}`);h&&(this.uid=h.textContent.replace(/[ \n\r\t]/g,""))}let s={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new el,c=h;l.initWithElement(c,e.url);let p=c.getAttribute("fallback");return p&&!tl[l.mediaType]&&(s[l.src]=p),!this.toc&&l.itemProperties.nav&&(this.toc=l),!this.cover&&l.itemProperties["cover-image"]&&(this.cover=l),l}),this.itemMap=Do(this.items,Qw),this.itemMapByPath=Do(this.items,h=>this.getPathFromURL(h.src));for(let h in s){let l=h;for(;;){let c=this.itemMap[s[l]];if(!c)break;if(tl[c.mediaType]){this.fallbackMap[h]=c.src;break}l=c.src}}this.spine=i.child("spine").child("itemref").asArray().map((h,l)=>{let c=h,p=c.getAttribute("idref"),d=this.itemMap[p];return d&&(d.itemRefElement=c,d.spineIndex=l),d});let r=i.child("spine").attribute("page-progression-direction")[0];r&&(this.pageProgression=ul(r));let o=t?t.doc().child("encryption").child("EncryptedData").predicate(Ka.withChild("EncryptionMethod",Ka.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],a=i.child("bindings").child("mediaType").asArray();for(let h=0;h<a.length;h++){let l=a[h].getAttribute("handler"),c=a[h].getAttribute("media-type");c&&l&&this.itemMap[l]&&(this.bindings[c]=this.itemMap[l].src)}if(this.metadata=nb(i.child("metadata"),i.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"),o.length>0&&this.uid){let h=eb(this.uid);for(let l=0;l<o.length;l++)this.store.deobfuscators[this.pubURL+o[l]]=h}return this.prePaginated&&this.assignAutoPages(),N(!0)}assignAutoPages(){let e=0;for(let t of this.spine){let i=this.prePaginated?1:Math.ceil(t.compressedSize/1024);t.epage=e,t.epageCount=i,e+=i}this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(e){this.epageIsRenderedPage=e||this.prePaginated}countEPages(e){if(this.epageCountCallback=e,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),N(!0);let t=0,i=0,n=F("countEPages");return n.loopWithFrame(s=>{if(i===this.spine.length){s.breakLoop();return}let r=this.spine[i++];r.epage=t,this.store.load(r.src).then(o=>{let a=1800,h=o.lang||this.lang;h&&h.match(/^(ja|ko|zh)/)&&(a/=3),r.epageCount=Math.ceil(o.getTotalOffset()/a),t+=r.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),s.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new lc(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let s=new el;s.initWithParam(n),s.id;let r=i.document.createElement("itemref");r.setAttribute("idref",s.id),i.root.appendChild(r),s.itemRefElement=r,this.itemMap[s.id]=s;let o=this.getPathFromURL(n.url);o==null&&(o=n.url),this.itemMapByPath[o]=s,this.items.push(s)}),t?this.store.addDocument(e[0].url,t):N(null)}initWithWebPubManifest(e,t,i){var n,s,r,o;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[Ne.title]=(Array.isArray(a)?a:[a]).map(g=>{var w;return{v:(w=g.value)!=null?w:g}}));let h=e.author||e.creator||((s=e.metadata)==null?void 0:s.author)||Array.from((r=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?r:[]).map(g=>g.content);h&&h.length!==0&&(this.metadata[Ne.creator]=(Array.isArray(h)?h:[h]).map(g=>{var w;return{v:(w=g.name)!=null?w:g}}));let l=e.inLanguage||((o=e.metadata)==null?void 0:o.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[Ne.language]=(Array.isArray(l)?l:[l]).map(g=>({v:g})));let c=this.getPathFromURL(this.pubURL);if(!e.readingOrder&&t&&c!==null){e.readingOrder=[encodeURI(c)];for(let g of Zw(t)){let w=g.getAttribute("href");if(/^(https?:)?\/\//.test(w)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(w))continue;let y=Pt(Ce(w,this.pubURL)),b=this.getPathFromURL(y),S=b!==null?encodeURI(b):y;e.readingOrder.indexOf(S)==-1&&e.readingOrder.push(S)}}let p=[],d=0,f=-1;[e.readingOrder,e.resources].forEach(g=>{g instanceof Array&&g.forEach(w=>{let y=g===e.readingOrder,b=typeof w=="string"?w:w.url||w.href,S=typeof w=="string"?"":w.encodingFormat||w.href&&w.type||"";if(y||S==="text/html"||S==="application/xhtml+xml"||!S&&w.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(b)){let T=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,R={url:Ce(hn(b),T),index:d++,startPage:null,skipPagesBefore:null};w.rel==="contents"&&f===-1&&(f=R.index),p.push(R)}})});let m=F("initWithWebPubManifest");return this.initWithChapters(p).then(()=>{var g,w;f!==-1&&(this.toc=this.items[f]),this.toc||(this.toc=i?(g=this.items)==null?void 0:g[0]:this.itemMapByPath[c]);let y=(w=e.readingOrder)==null?void 0:w.length;y&&y<this.items.length&&this.items.splice(y),m.finish(!0)}),m.result()}getCFI(e,t){let i=this.spine[e],n=F("getCFI");return this.store.load(i.src).then(s=>{let r=s.getNodeByOffset(t),o=null;if(r){let a=s.getNodeOffset(r,0,!1),h=t-a,l=new Wo;l.prependPathFromNode(r,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),o=l.toString()}n.finish(o)}),n.result()}resolveFragment(e){return Ni("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Wo;i.fromString(e);let n;if(this.opfXML){let s=i.navigate(this.opfXML.document);if(s.node.nodeType!=1||s.after||!s.ref){t.finish(null);return}let r=s.node,o=r.getAttribute("idref");if(r.localName!="itemref"||!o||!this.itemMap[o]){t.finish(null);return}n=this.itemMap[o],i=s.ref}else n=this.spine[0];this.store.load(n.src).then(s=>{let r=i.navigate(s.document),o=s.getNodeOffset(r.node,r.offset,r.after);t.finish({spineIndex:n.spineIndex,offsetInItem:o,pageIndex:-1})})},(t,i)=>{H.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return Ni("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let s=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);s==-1&&(s=this.spine.length-1);let r=this.spine[s];(!r||r.epageCount==0)&&(r=this.spine[--s]);let o=Math.floor(e-r.epage);t.finish({spineIndex:s,offsetInItem:-1,pageIndex:o});return}let i=Ht(this.spine.length,s=>{let r=this.spine[s];return r.epage+r.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(s=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let r=0;if(e>0){let o=s.getTotalOffset();r=Math.round(o*e/n.epageCount),r==o&&r--}t.finish({spineIndex:i,offsetInItem:r,pageIndex:-1})})},(t,i)=>{H.warn(i,"Cannot resolve epage:",e),t.finish(null)})}getEPageFromPosition(e){let t=this.spine[e.spineIndex];if(this.epageIsRenderedPage){let n=t.epage+e.pageIndex;return N(n)}if(e.offsetInItem<=0)return N(t.epage);let i=F("getEPage");return this.store.load(t.src).then(n=>{let s=n.getTotalOffset(),r=Math.min(s,e.offsetInItem);i.finish(t.epage+r*t.epageCount/s)}),i.result()}},Vn=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),rb=class{constructor(e,t,i,n,s){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=s,u(this,"spineItems",[]),u(this,"spineItemLoadingContinuations",[]),u(this,"pref"),u(this,"clientLayout"),u(this,"counterStore"),u(this,"tocAutohide",!1),u(this,"tocVisible",!1),u(this,"tocView"),this.pref=Cl(n),this.clientLayout=new Dw(t),this.counterStore=new Wd(e.documentURLTransformer)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let s=this.opf.spine[e.item.spineIndex-1];e.item.epage=s.epage+s.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((s,r)=>s+r.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)e.instance.viewport.contentContainer.replaceChild(t.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:t});else{let s=null;if(i>0)s=e.pages[i-1].container.nextElementSibling;else for(let r=e.item.spineIndex+1;r<this.spineItems.length;r++){let o=this.spineItems[r];if(o&&o.pages[0]){s=o.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,s)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}renderSinglePage(e,t){let i=F("renderSinglePage"),n=e.pages[t?t.page:0],s=this.makePage(e,t);return n&&(s.pageType=n.pageType),e.instance.layoutNextPage(s,t).then(r=>{t=r;let o=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,s,o),this.counterStore.finishPage(s.spineIndex,o);let a=null;if(t){let h=e.layoutPositions[t.page];e.layoutPositions[t.page]=t,h&&e.pages[t.page]&&(t.isSamePosition(h)||(a=this.renderSinglePage(e,t)))}a||(a=N(!0)),a.then(()=>{let h=this.counterStore.getUnresolvedRefsToPage(s),l=0;i.loopWithFrame(c=>{if(l++,l>h.length){c.breakLoop();return}let p=h[l-1];if(p.refs=p.refs.filter(d=>!d.isResolved()),p.refs.length===0){c.continueLoop();return}this.getPageViewItem(p.spineIndex).then(d=>{if(!d){c.continueLoop();return}let{currentPageType:f,previousPageType:m}=d.instance.styler.cascade,g=d.instance.scopes;d.instance.scopes={},this.counterStore.pushPageCounters(p.pageCounters),this.counterStore.pushReferencesToSolve(p.refs);let w=d.layoutPositions[p.pageIndex];this.renderSinglePage(d,w).then(y=>{d.instance.styler.cascade.currentPageType=f,d.instance.styler.cascade.previousPageType=m,d.instance.scopes=g,this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve();let b=y.pageAndPosition.position;b.spineIndex===s.spineIndex&&b.pageIndex===o&&(s=y.pageAndPosition.page),c.continueLoop()})})}).then(()=>{s.container.parentElement||(s=e.pages[o]),s.isLastPage=!t&&e.item.spineIndex===this.opf.spine.length-1,s.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),s.container.setAttribute("data-vivliostyle-page-index",o),s.container.setAttribute("data-vivliostyle-spine-index",s.spineIndex),i.finish({pageAndPosition:Vn(s,o),nextLayoutPosition:t})})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let s=Ht(t.layoutPositions.length,r=>t.instance.getPosition(t.layoutPositions[r],!0)>n);s===t.layoutPositions.length?t.complete?i=t.layoutPositions.length-1:i=Number.POSITIVE_INFINITY:i=s-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=F("findPage");return this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let s=null,r;i.loopWithFrame(o=>{let a=this.normalizeSeekPosition(e,n);r=a.pageIndex,s=n.pages[r],s?o.breakLoop():n.complete?(r=n.layoutPositions.length-1,s=n.pages[r],o.breakLoop()):t?this.renderPage(a).then(h=>{h&&(s=h.page,r=h.position.pageIndex),o.breakLoop()}):i.sleep(100).then(()=>{o.continueLoop()})}).then(()=>{i.finish(Vn(s,r))})}),i.result()}renderPage(e){let t=F("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),s=n.pageIndex,r=n.offsetInItem,o=i.pages[s];if(o){t.finish(Vn(o,s));return}t.loopWithFrame(a=>{if(s<i.layoutPositions.length){a.breakLoop();return}if(i.complete){s=i.layoutPositions.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let c=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(r>=0&&i.instance.getPosition(h)>r){o=c,s=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else o=c,s=l.pageAndPosition.position.pageIndex,i.complete=!0,a.breakLoop()})}).then(()=>{o=o||i.pages[s];let a=i.layoutPositions[s];if(o){t.finish(Vn(o,s));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||(i.complete=!0),t.finish(h.pageAndPosition)})})}),t.result()}renderAllPages(){let e=F("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(t=>{e.loopWithFrame(i=>{this.spineItems.some(n=>n?.pages.some(s=>s?.fetchers.some(r=>!r.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=F("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,s=e.pageIndex,r=0;t&&(r=n);let o;return i.loopWithFrame(a=>{let h={spineIndex:r,pageIndex:r===n?s:Number.POSITIVE_INFINITY,offsetInItem:r===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{o=l,++r>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(o)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,s=F("nextPage");return this.getPageViewItem(i).then(r=>{if(!r){s.finish(null);return}if(r.complete&&n==r.layoutPositions.length-1){if(i>=this.opf.spine.length-1){s.finish(null);return}i++,n=0;let o=this.spineItems[i],a=o&&o.pages[0],h=r.pages[r.pages.length-1];a&&h&&a.side==h.side&&(o.pages.forEach(l=>{l.container&&l.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(s)}),s.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return N(null);i--,n=Number.POSITIVE_INFINITY}else n--;return this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t)}isRectoPage(e,t){let i=e.side==="left",n=this.getCurrentPageProgression(t)==="ltr";return!i&&n||i&&!n}getSpread(e,t){let i=this.getPage(e);if(!i)return N({left:null,right:null});let n=F("getSpread"),s=i.side==="left",r;return this.isRectoPage(i,e)?r=this.previousPage(e,t):r=this.nextPage(e,t),r.then(o=>{let a=this.getPage(e),h=o&&o.page;h&&h.side===a.side&&(h=null),s?n.finish({left:a,right:h}):n.finish({left:h,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),s=this.nextPage(e,t);return n?s:s.thenAsync(r=>{if(r){if(r.page.side===i.side)return s;let o=this.nextPage(r.position,t);return o.thenAsync(a=>a?o:s)}else return N(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),s=this.previousPage(e,t),r=i.container.previousElementSibling;return n?s.thenAsync(o=>o?o.page.side===i.side||o.page.container!==r?s:this.previousPage(o.position,t):N(null)):s}navigateToEPage(e,t,i){let n=F("navigateToEPage");return this.opf.resolveEPage(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(e,t,i){let n=F("navigateToCFI");return this.opf.resolveFragment(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateTo(e,t,i){H.debug("Navigate to",e);let n=this.opf.getPathFromURL(Pt(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let o=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(o[0]),n==null&&(n=o[0])):n=o[0],e=o[0]+(o[1]?`#${o[1]}`:"")}if(n==null)return N(null)}let s=this.opf.itemMapByPath[n];if(!s){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let o=e.indexOf("#");if(o>=0)return this.navigateToFragment(e.substr(o+1),t,i)}return N(null)}let r=F("navigateTo");return this.getPageViewItem(s.spineIndex).then(o=>{if(!o){r.finish(null);return}let a=o.xmldoc.getElement(e);this.findPage({spineIndex:s.spineIndex,pageIndex:-1,offsetInItem:a?o.xmldoc.getElementOffset(a):0},i).thenFinish(r)}),r.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",ln||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let s=i.document.createElement("div");s.setAttribute("data-vivliostyle-bleed-box","true"),s.role="presentation",n.appendChild(s);let r=new Ch(n,s);if(r.spineIndex=e.item.spineIndex,r.position=t,r.offset=e.instance.getPosition(t),r.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let o=this.opf.documentURLTransformer.transformFragment("",e.item.src);s.setAttribute("id",o),r.registerElementWithId(s,o)}if(i!==this.viewport){let o=El(this.viewport.width,this.viewport.height,i.width,i.height),a=Fi(null,new yt(o,null),"");r.delayedItems.push(new to(n,"transform",a))}return r}makeObjectView(e,t,i,n){let s=t.getAttribute("data"),r=null;if(s){s=Ce(s,e.url);let o=t.getAttribute("media-type");if(!o){let a=this.opf.getPathFromURL(s);if(a){let h=this.opf.itemMapByPath[a];h&&(o=h.mediaType)}}if(o){let a=this.opf.bindings[o];if(a){r=this.viewport.document.createElement("iframe"),r.style.border="none";let h=Mo(s),l=Mo(o),c=new It;c.append(a),c.append("?src="),c.append(h),c.append("&type="),c.append(l);for(let f=t.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let m=f;if(m.localName=="param"&&m.namespaceURI=="http://www.w3.org/1999/xhtml"){let g=m.getAttribute("name"),w=m.getAttribute("value");g&&w&&(c.append("&"),c.append(encodeURIComponent(g)),c.append("="),c.append(encodeURIComponent(w)))}}r.setAttribute("src",c.toString());let p=t.getAttribute("width");p&&r.setAttribute("width",p);let d=t.getAttribute("height");d&&r.setAttribute("height",d)}}}return r||(r=this.viewport.document.createElement("object"),s&&r.setAttribute("data",s),r.setAttribute("data-adapt-process-children","true")),N(r)}makeMathJaxView(e,t,i,n){let s=sb();if(s){let r=i.ownerDocument,o=r.createElement("span");i.appendChild(o);let a=r.importNode(t,!0);this.resolveURLsInMathML(a,e),o.appendChild(a);let h=s.queue;h.Push(["Typeset",s,o]);let l=F("makeMathJaxView"),c=l.suspend();return h.Push(()=>{c.schedule(o)}),l.result()}return N(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let s=Ce(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,s):e.setAttribute(n.name,s)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):N(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return N(null);let t=this.spineItems[e];if(t)return N(t);let i=F("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let o=i.suspend();return n.push(o),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let s=this.opf.spine[e],r=this.opf.store;return r.load(s.src).then(o=>{var a;let h=s.itemRefElement.getAttribute("properties");h&&o.root.setAttribute("data-vivliostyle-epub-spine-properties",h),s.title=o.document.title;let l=r.getStyleForDoc(o),c=this.makeCustomRenderer(o),p=this.viewport,d=l.sizeViewport(p.width,p.height,p.fontSize,this.pref);(d.width!=p.width||d.height!=p.height||d.fontSize!=p.fontSize)&&(p=new cs(p.window,d.fontSize,p.pixelRatio,p.root,d.width,d.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,m=this.spineItems[e-1],g,w;if(s.startPage!==null)g=s.startPage-1,w=g;else{if(e>0&&(!m||!m.complete))g=s.epage||e,!this.opf.prePaginated&&g%2==(f?1:0)&&g++,w=g;else{g=m?m.instance.pageNumberOffset+m.pages.length:0;let S=this.counterStore.currentPageCounters.page;w=!S||!S.length?g:S[S.length-1]}s.skipPagesBefore!==null&&(g+=s.skipPagesBefore,w+=s.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let y=new To(l,o,this.opf.lang,p,this.clientLayout,this.fontMapper,c,this.opf.fallbackMap,g,this.opf.documentURLTransformer,this.counterStore,this.opf.pageProgression,f);y.pref=this.pref;let b=this.opf.metadata&&this.opf.metadata[Ne.title];y.pubTitle=b&&b[0]&&b[0].v||"",y.docTitle=s.title||"",y.init().then(()=>{!this.opf.pageProgression&&y.pageProgression&&(this.opf.pageProgression=y.pageProgression),t={item:s,xmldoc:o,instance:y,layoutPositions:[null],pages:[],complete:!1},this.spineItems[e]=t,i.finish(t),n.forEach(S=>{S.schedule(t)})})}),i.result()}removeRenderedPages(){let e=this.spineItems;for(let t of e)t&&t.pages.splice(0);this.viewport.clear()}hasAutoSizedPages(){let e=this.spineItems;for(let t of e)if(t){let i=t.pages;for(let n of i)if(n.isAutoPageWidth&&n.isAutoPageHeight)return!0}return!1}hasPages(){return this.spineItems.some(e=>e&&e.pages.length>0)}showTOC(e){let t=this.opf,i=t.toc;if(this.tocAutohide=e,!i)return N(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"),N(this.tocView.page);let n=F("showTOC");this.tocView||(this.tocView=new Kw(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore));let s=this.viewport,r=Math.min(344,Math.round(.67*s.width)-16),o=s.height-6,a=s.document.createElement("div");return s.root.appendChild(a),ln||(a.style.visibility="hidden"),a.style.width=`${r+16}px`,a.style.maxHeight=`${o}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,s,r,o,this.viewport.fontSize).then(h=>{a.style.visibility="visible",a.setAttribute("aria-hidden","false"),n.finish(h)}),n.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}},il="data-vivliostyle-viewer-status",ob="data-vivliostyle-spread-view",dc=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(dc||{}),ab=class{constructor(e,t,i,n){this.window=e,this.viewportElement=t,this.instanceId=i,this.callbackFn=n,u(this,"fontMapper"),u(this,"kick"),u(this,"sendCommand"),u(this,"resizeListener"),u(this,"hyperlinkListener"),u(this,"pageRuleStyleElement"),u(this,"pageSheetSizeAlreadySet",!1),u(this,"renderTask",null),u(this,"actions"),u(this,"readyState"),u(this,"packageURL"),u(this,"opf"),u(this,"touchActive"),u(this,"touchX"),u(this,"touchY"),u(this,"needResize"),u(this,"resized"),u(this,"needRefresh"),u(this,"viewportSize"),u(this,"currentPage"),u(this,"currentSpread"),u(this,"pagePosition"),u(this,"fontSize"),u(this,"zoom"),u(this,"fitToScreen"),u(this,"pageViewMode"),u(this,"waitForLoading"),u(this,"renderAllPages"),u(this,"pref"),u(this,"pageSizes"),u(this,"pixelRatio"),u(this,"pixelRatioLimit"),u(this,"viewport"),u(this,"opfView");let s=t.ownerDocument,r=(o,a)=>{let h=s.getElementById(o);return h||(h=s.createElement("style"),h.id=o,a&&(h.textContent=a),s.head.appendChild(h)),h};r("vivliostyle-viewport-screen-css",th),r("vivliostyle-viewport-css",ih),r("vivliostyle-polyfill-css",lh),t.setAttribute("data-vivliostyle-viewer-viewport",!0),ln&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(il,"loading"),this.fontMapper=new qm(s.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=o=>{},this.pageRuleStyleElement=r("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=Sl(),this.pageSizes=[],this.pixelRatioLimit=/Chrome/.test(navigator.userAgent)?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=pl;H.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),H.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),H.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),H.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){this.readyState!==e&&(this.readyState=e,this.viewportElement.setAttribute(il,e),this.callback({t:"readystatechange"}))}loadPublication(e){nt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,s=e.userStyleSheet;this.viewport=null;let r=F("loadPublication");return this.configure(e).then(()=>{let o=new Qa;o.init(n,s).then(()=>{let a=Ce(hn(t),this.window.location.href);this.packageURL=[a],o.loadPubDoc(a).then(h=>{h?(this.opf=h,this.render(i).then(()=>{r.finish(!0)})):r.finish(!1)})})}),r.result()}loadXML(e){nt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,s=e.authorStyleSheet,r=e.userStyleSheet;this.viewport=null;let o=F("loadXML");return this.configure(e).then(()=>{let a=new Qa;a.init(s,r).then(()=>{let h=t.map((l,c)=>({url:Ce(hn(l.url),this.window.location.href),index:c,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new Yn(a,""),this.opf.initWithChapters(h,i).then(()=>{this.render(n).then(()=>{o.finish(!0)})})})}),o.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,N(!0))):t=N(!0),t.thenAsync(()=>(nt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let s=n[0];if(s==="em"||s==="rem")return t*this.fontSize;if(s==="ex")return t*pe.ex*this.fontSize/pe.em;let r=pe[s];if(r)return t*r}return t}configure(e){if(typeof e.autoresize=="boolean"&&(e.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof e.fontSize=="number"){let t=e.fontSize;t>=5&&t<=72&&this.fontSize!=t&&(this.fontSize=t,this.needResize=!0)}if(typeof e.viewport=="object"&&e.viewport){let t=e.viewport,i={marginLeft:this.resolveLength(t["margin-left"])||0,marginRight:this.resolveLength(t["margin-right"])||0,marginTop:this.resolveLength(t["margin-top"])||0,marginBottom:this.resolveLength(t["margin-bottom"])||0,width:this.resolveLength(t.width)||0,height:this.resolveLength(t.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof e.hyphenate=="boolean"&&(this.pref.hyphenate=e.hyphenate,this.needResize=!0),typeof e.horizontal=="boolean"&&(this.pref.horizontal=e.horizontal,this.needResize=!0),typeof e.nightMode=="boolean"&&(this.pref.nightMode=e.nightMode,this.needResize=!0),typeof e.lineHeight=="number"&&(this.pref.lineHeight=e.lineHeight,this.needResize=!0),typeof e.columnWidth=="number"&&(this.pref.columnWidth=e.columnWidth,this.needResize=!0),typeof e.fontFamily=="string"&&(this.pref.fontFamily=e.fontFamily,this.needResize=!0),typeof e.load=="boolean"&&(this.waitForLoading=e.load),typeof e.renderAllPages=="boolean"&&(this.renderAllPages=e.renderAllPages),typeof e.userAgentRootURL=="string"&&(Oo(e.userAgentRootURL.replace(/resources\/?$/,"")),Bo(e.userAgentRootURL)),typeof e.rootURL=="string"&&(Oo(e.rootURL),Bo(`${ki}resources/`)),typeof e.pageViewMode=="string"&&e.pageViewMode!==this.pageViewMode&&(this.pageViewMode=e.pageViewMode,this.needResize=!0),typeof e.pageBorder=="number"&&e.pageBorder!==this.pref.pageBorder&&(this.viewport=null,this.pref.pageBorder=e.pageBorder,this.needResize=!0),typeof e.zoom=="number"&&e.zoom!==this.zoom&&(this.zoom=e.zoom,this.needRefresh=!0),typeof e.fitToScreen=="boolean"&&e.fitToScreen!==this.fitToScreen&&(this.fitToScreen=e.fitToScreen,this.needRefresh=!0),typeof e.defaultPaperSize=="object"&&typeof e.defaultPaperSize.width=="number"&&typeof e.defaultPaperSize.height=="number"&&(this.viewport=null,this.pref.defaultPaperSize=e.defaultPaperSize,this.needResize=!0),typeof e.allowScripts=="boolean"&&e.allowScripts!==Ft&&(Iw(e.allowScripts),this.needResize=!0),typeof e.pixelRatio=="number"){let t=Math.min(e.pixelRatio,this.pixelRatioLimit);t!==this.pixelRatio&&(this.pixelRatio=t,this.needResize=!0)}return this.configurePlugins(e),N(!0)}configurePlugins(e){vt("CONFIGURATION").forEach(t=>{let i=t(e);this.needResize=i.needResize||this.needResize,this.needRefresh=i.needRefresh||this.needRefresh})}pageReplacedListener(e){let t=this.currentPage,i=this.currentSpread,n=e.target;i?(i.left===n||i.right===n)&&this.showCurrent(e.newPage):t===e.target&&this.showCurrent(e.newPage)}forCurrentPages(e){let t=[];this.currentPage&&t.push(this.currentPage),this.currentSpread&&(t.push(this.currentSpread.left),t.push(this.currentSpread.right)),t.forEach(i=>{i&&e(i)})}removePageListeners(){this.forCurrentPages(e=>{e.removeEventListener("hyperlink",this.hyperlinkListener,!1),e.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(e=>{P(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),P(e.container,"visibility","visible"),P(e.container,"display","block")}showPage(e){this.hidePages(),this.currentPage=e,e.container.style.marginLeft="",e.container.style.marginRight="",this.showSinglePage(e)}showSpread(e){if(this.hidePages(),this.currentSpread=e,e.left&&e.right){let t=parseFloat(e.left.container.style.width),i=parseFloat(e.right.container.style.width);t&&i&&t!==i&&(t<i?e.left.container.style.marginLeft=`${i-t}px`:e.right.container.style.marginRight=`${t-i}px`)}e.left&&(this.showSinglePage(e.left),e.right?e.left.container.removeAttribute("data-vivliostyle-unpaired-page"):e.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),e.right&&(this.showSinglePage(e.right),e.left?e.right.container.removeAttribute("data-vivliostyle-unpaired-page"):e.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let e=F("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(t=>{let i=this.currentPage;(this.waitForLoading&&i.fetchers.length>0?ws(i.fetchers):N(!0)).then(()=>{this.sendLocationNotification(i,t).thenFinish(e)})}),e.result()}createViewport(){let e=this.viewportElement;if(this.viewportSize){let t=this.viewportSize;return e.style.marginLeft=`${t.marginLeft}px`,e.style.marginRight=`${t.marginRight}px`,e.style.marginTop=`${t.marginTop}px`,e.style.marginBottom=`${t.marginBottom}px`,new cs(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new cs(this.window,this.fontSize,this.pixelRatio,e)}resolveSpreadView(e,t){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;case"autoSpread":default:return(e.width-this.pref.pageBorder)/e.height>=(t?t.width*2/t.height:1.45)&&(!!t||e.width>800)}}updateSpreadView(e){this.pref.spreadView=e,this.viewportElement.setAttribute(ob,e.toString())}sizeIsGood(){var e;let t=this.createViewport(),i=((e=this.opfView)==null?void 0:e.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&i?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:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,s;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((s=this.pageSizes[i-1])==null?void 0:s.height))){let o=function(m){let g=m*.75;return Math.ceil(g)};var r=o;let a=Math.max(...this.pageSizes.map(m=>m.width)),h=Math.max(...this.pageSizes.map(m=>m.height)),l=o(a),c=o(h),p=l*((this.pixelRatio||1)-1)+2,d=c*((this.pixelRatio||1)-1)+2,f=`@page {size: ${l}pt ${c}pt; margin: 0 ${-p}pt ${-d}pt 0;}`;this.pageRuleStyleElement.textContent=f,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}reset(){let e=!1,t=!1;this.opfView&&(e=this.opfView.tocVisible,t=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new rb(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this)),e&&this.sendCommand({a:"toc",v:"show",autohide:t})}showCurrent(e,t){this.needRefresh=!1,this.removePageListeners();let i=this.resolveSpreadView(this.viewport,e.dimensions);return i!==this.pref.spreadView&&this.updateSpreadView(i),i?this.opfView.getSpread(this.pagePosition,t).thenAsync(n=>!n.left&&!n.right?N(null):n.left&&n.right&&(!this.resolveSpreadView(this.viewport,n.left.dimensions)||!this.resolveSpreadView(this.viewport,n.right.dimensions))?(this.updateSpreadView(!1),this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,N(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null))}setPageZoom(e){let t=this.getAdjustedZoomFactor(e.dimensions);this.viewport.zoom(e.dimensions.width,e.dimensions.height,t)}setSpreadZoom(e){let t=this.getSpreadDimensions(e);this.viewport.zoom(t.width,t.height,this.getAdjustedZoomFactor(t))}getAdjustedZoomFactor(e){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(e):this.zoom}getSpreadDimensions(e){let t=0,i=0;return e.left&&(t+=e.left.dimensions.width,i=e.left.dimensions.height),e.right&&(t+=e.right.dimensions.width,i=Math.max(i,e.right.dimensions.height)),e.left&&e.right&&(t+=this.pref.pageBorder*2,t+=Math.abs(e.left.dimensions.width-e.right.dimensions.width)),{width:t,height:i}}queryZoomFactor(e){if(!this.currentPage)throw new Error("no page exists.");switch(e){case"fit inside viewport":{let t;return this.pref.spreadView?(this.currentSpread,t=this.getSpreadDimensions(this.currentSpread)):t=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(t)}default:throw new Error(`unknown zoom type: ${e}`)}}calculateZoomFactorToFitInsideViewPort(e){if(!this.viewport)return this.zoom;let t=this.viewport.width/e.width,i=this.viewport.height/e.height;return Math.min(t,i)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new nl),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return N(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=sr().getScheduler().run(()=>Ni("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,nt.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(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let s={t:"nav",epageCount:n,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)&&(s.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(s)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():N(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),nt.registerEndTiming("render (resize)"),Ft&&oc(this.window)?Fw(this.window).then(()=>{this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),t.finish(n)}):(this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),t.finish(n))})})})})})},(t,i)=>{if(i instanceof nl)nt.registerEndTiming("render (resize)"),H.debug(i.message);else throw i}));return N(!0)}sendLocationNotification(e,t){let i=F("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:e.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(s=>{n.epage=s,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(e){var t;let i;if(this.readyState!=="complete"&&e.where!=="next"&&this.setReadyState("loading"),typeof e.where=="string"){let s;switch(e.where){case"next":s=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":s=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":s=this.opfView.lastPage;break;case"first":s=this.opfView.firstPage;break;default:return N(!0)}s&&(i=()=>s.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let s=e.epage;i=()=>this.opfView.navigateToEPage(s,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let s=e.url;i=()=>this.opfView.navigateTo(s,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let s=e.position;i=()=>this.opfView.findPage(s,!this.renderAllPages)}else return N(!0);if(!this.opfView)return N(!0);let n=F("moveTo");return i.call(this.opfView).then(s=>{let r;if(s){this.pagePosition=s.position;let o=F("moveTo.showCurrent");r=o.result(),this.showCurrent(s.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(o)})}else r=N(!0);r.then(o=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(o)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),s=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!s)return N(!0)}else if(i=="hide")return N(!0);if(n&&i!="show")return this.opfView.hideTOC(),N(!0);{let r=F("showTOC");return this.opfView.showTOC(t).then(o=>{if(o){if(s&&(o.listeners={}),t){let a=()=>{this.opfView.hideTOC()};o.addEventListener("hyperlink",a,!1)}o.addEventListener("hyperlink",this.hyperlinkListener,!1)}r.finish(!0)}),r.result()}}runCommand(e){let t=e.a||"";return Ni("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(H.error("No such action:",t),i.finish(!0))},(i,n)=>{H.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=sl(e),i=null,n=this;mp(()=>{let s=F("commandLoop"),r=sr().getScheduler();return n.hyperlinkListener=o=>{let a=o,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){o.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};r.run(()=>(n.callback(l),N(!0)))}},s.loopWithFrame(o=>{if(n.needResize)n.resize().then(()=>{o.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{o.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{o.continueLoop()})}else{let a=F("waitForCommand");i=a.suspend(this),a.result().then(()=>{o.continueLoop()})}}).thenFinish(s),s.result()}),n.kick=()=>{let s=i;s&&(i=null,s.schedule(!0))},n.sendCommand=s=>t?!1:(t=sl(s),n.kick(),!0),this.window.adapt_command=n.sendCommand}},pc=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(pc||{}),nl=class fc extends Error{constructor(){super(),u(this,"name","RenderingCanceledError"),u(this,"message","Page rendering has been canceled"),u(this,"stack"),Object.setPrototypeOf(this,fc.prototype),this.stack=new Error().stack}};function sl(e){return typeof e=="string"?Hr(e):e}var rl=Ur;function lb(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function ol(e){let t={};return Object.keys(e).forEach(i=>{let n=e[i];switch(i){case"autoResize":t.autoresize=n;break;case"pageBorderWidth":t.pageBorder=n;break;default:t[i]=n}}),t}var gc=class{constructor(e,t){this.settings=e,u(this,"initialized",!1),u(this,"adaptViewer_"),u(this,"options"),u(this,"eventTarget"),u(this,"readyState"),hl(e.debug),this.adaptViewer_=new ab(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=lb(),t&&this.setOptions(t),this.eventTarget=new $r,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},ol(e));this.adaptViewer_.sendCommand(t),Object.assign(this.options,e)}dispatcher(e){let t={type:e.t},i=e;Object.keys(i).forEach(n=>{n!=="t"&&(t[n]=i[n])}),this.eventTarget.dispatchEvent(t)}addListener(e,t){this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){this.eventTarget.removeEventListener(e,t,!1)}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let s=i||{};function r(l){if(l)return l.map(c=>({url:c.url||null,text:c.text||null}))}let o=r(s.authorStyleSheet),a=r(s.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:hb(e)||t,document:s.documentObject,fragment:s.fragment,authorStyleSheet:o,userStyleSheet:a},ol(this.options));this.initialized?this.adaptViewer_.sendCommand(h):(this.initialized=!0,this.adaptViewer_.initEmbed(h))}getCurrentPageProgression(){return this.adaptViewer_.getCurrentPageProgression()}resolveNavigation(e){switch(e){case"left":return this.getCurrentPageProgression()===rl.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===rl.LTR?"next":"previous";default:return e}}navigateToPage(e,t){e==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:t}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(e)})}navigateToInternalUrl(e){this.adaptViewer_.sendCommand({a:"moveTo",url:e})}navigateToPosition(e){var t,i;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:e.spineIndex,pageIndex:(t=e.pageIndex)!=null?t:-1,offsetInItem:(i=e.offsetInItem)!=null?i:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(e,t){let i=e==null?"toggle":e?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:i,autohide:t})}queryZoomFactor(e){return this.adaptViewer_.queryZoomFactor(e)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var e,t;return(t=(e=this.adaptViewer_.opfView)==null?void 0:e.tocView)==null?void 0:t.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}};function hb(e){function t(n){return typeof n=="number"?n:null}function i(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(e)?e.map(i):e?[i(e)]:null}var mc=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(mc||{}),ub=pc,cb=dc;nt.forceRegisterEndTiming("load_vivliostyle");var db=class{constructor(e,{title:t="",printCallback:i=o=>o.print(),errorCallback:n=null,hideIframe:s=!0,removeIframe:r=!0}){u(this,"htmlDoc"),u(this,"title"),u(this,"printCallback"),u(this,"errorCallback"),u(this,"hideIframe"),u(this,"removeIframe"),u(this,"iframe"),u(this,"iframeWin"),u(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=s,this.removeIframe=r}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>
|