@vivliostyle/print 2.41.0 → 2.42.1

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 CHANGED
@@ -1,10 +1,12 @@
1
- var Dp=Object.create;var Nr=Object.defineProperty;var zp=Object.getOwnPropertyDescriptor;var Vp=Object.getOwnPropertyNames;var Up=Object.getPrototypeOf,Hp=Object.prototype.hasOwnProperty;var $p=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Wp=(e,t)=>{for(var i in t)Nr(e,i,{get:t[i],enumerable:!0})},wl=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Vp(t))!Hp.call(e,r)&&r!==i&&Nr(e,r,{get:()=>t[r],enumerable:!(n=zp(t,r))||n.enumerable});return e};var Gp=(e,t,i)=>(i=e!=null?Dp(Up(e)):{},wl(t||!e||!e.__esModule?Nr(i,"default",{value:e,enumerable:!0}):i,e)),jp=e=>wl(Nr({},"__esModule",{value:!0}),e);var Lp=$p((F0,Fp)=>{"use strict";var Xp=Object.create,pr=Object.defineProperty,qp=Object.getOwnPropertyDescriptor,Yp=Object.getOwnPropertyNames,Zp=Object.getPrototypeOf,Kp=Object.prototype.hasOwnProperty,Jh=e=>{throw TypeError(e)},Jp=(e,t,i)=>t in e?pr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Qp=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ef=(e,t)=>{for(var i in t)pr(e,i,{get:t[i],enumerable:!0})},Qh=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Yp(t))!Kp.call(e,r)&&r!==i&&pr(e,r,{get:()=>t[r],enumerable:!(n=qp(t,r))||n.enumerable});return e},tf=(e,t,i)=>(i=e!=null?Xp(Zp(e)):{},Qh(t||!e||!e.__esModule?pr(i,"default",{value:e,enumerable:!0}):i,e)),nf=e=>Qh(pr({},"__esModule",{value:!0}),e),c=(e,t,i)=>Jp(e,typeof t!="symbol"?t+"":t,i),Ea=(e,t,i)=>t.has(e)||Jh("Cannot "+i),V=(e,t,i)=>(Ea(e,t,"read from private field"),i?i.call(e):t.get(e)),ne=(e,t,i)=>t.has(e)?Jh("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),Oe=(e,t,i,n)=>(Ea(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),Ce=(e,t,i)=>(Ea(e,t,"access private method"),i),rf=Qp((e,t)=>{var i=-1,n=1,r=0;function s(C,_,k,O,E){if(C===_)return C?[[r,C]]:[];if(k!=null){var T=fe(C,_,k);if(T)return T}var L=l(C,_),z=C.substring(0,L);C=C.substring(L),_=_.substring(L),L=d(C,_);var H=C.substring(C.length-L);C=C.substring(0,C.length-L),_=_.substring(0,_.length-L);var K=o(C,_);return z&&K.unshift([r,z]),H&&K.push([r,H]),P(K,E),O&&f(K),K}function o(C,_){var k;if(!C)return[[n,_]];if(!_)return[[i,C]];var O=C.length>_.length?C:_,E=C.length>_.length?_:C,T=O.indexOf(E);if(T!==-1)return k=[[n,O.substring(0,T)],[r,E],[n,O.substring(T+E.length)]],C.length>_.length&&(k[0][0]=k[2][0]=i),k;if(E.length===1)return[[i,C],[n,_]];var L=p(C,_);if(L){var z=L[0],H=L[1],K=L[2],ee=L[3],Q=L[4],ge=s(z,K),re=s(H,ee);return ge.concat([[r,Q]],re)}return a(C,_)}function a(C,_){for(var k=C.length,O=_.length,E=Math.ceil((k+O)/2),T=E,L=2*E,z=new Array(L),H=new Array(L),K=0;K<L;K++)z[K]=-1,H[K]=-1;z[T+1]=0,H[T+1]=0;for(var ee=k-O,Q=ee%2!==0,ge=0,re=0,se=0,_e=0,De=0;De<E;De++){for(var pe=-De+ge;pe<=De-re;pe+=2){var le=T+pe,me;pe===-De||pe!==De&&z[le-1]<z[le+1]?me=z[le+1]:me=z[le-1]+1;for(var we=me-pe;me<k&&we<O&&C.charAt(me)===_.charAt(we);)me++,we++;if(z[le]=me,me>k)re+=2;else if(we>O)ge+=2;else if(Q){var oe=T+ee-pe;if(oe>=0&&oe<L&&H[oe]!==-1){var q=k-H[oe];if(me>=q)return h(C,_,me,we)}}}for(var Ze=-De+se;Ze<=De-_e;Ze+=2){var oe=T+Ze,q;Ze===-De||Ze!==De&&H[oe-1]<H[oe+1]?q=H[oe+1]:q=H[oe-1]+1;for(var at=q-Ze;q<k&&at<O&&C.charAt(k-q-1)===_.charAt(O-at-1);)q++,at++;if(H[oe]=q,q>k)_e+=2;else if(at>O)se+=2;else if(!Q){var le=T+ee-Ze;if(le>=0&&le<L&&z[le]!==-1){var me=z[le],we=T+me-le;if(q=k-q,me>=q)return h(C,_,me,we)}}}}return[[i,C],[n,_]]}function h(C,_,k,O){var E=C.substring(0,k),T=_.substring(0,O),L=C.substring(k),z=_.substring(O),H=s(E,T),K=s(L,z);return H.concat(K)}function l(C,_){if(!C||!_||C.charAt(0)!==_.charAt(0))return 0;for(var k=0,O=Math.min(C.length,_.length),E=O,T=0;k<E;)C.substring(T,E)==_.substring(T,E)?(k=E,T=k):O=E,E=Math.floor((O-k)/2+k);return S(C.charCodeAt(E-1))&&E--,E}function u(C,_){var k=C.length,O=_.length;if(k==0||O==0)return 0;k>O?C=C.substring(k-O):k<O&&(_=_.substring(0,k));var E=Math.min(k,O);if(C==_)return E;for(var T=0,L=1;;){var z=C.substring(E-L),H=_.indexOf(z);if(H==-1)return T;L+=H,(H==0||C.substring(E-L)==_.substring(0,L))&&(T=L,L++)}}function d(C,_){if(!C||!_||C.slice(-1)!==_.slice(-1))return 0;for(var k=0,O=Math.min(C.length,_.length),E=O,T=0;k<E;)C.substring(C.length-E,C.length-T)==_.substring(_.length-E,_.length-T)?(k=E,T=k):O=E,E=Math.floor((O-k)/2+k);return R(C.charCodeAt(C.length-E))&&E--,E}function p(C,_){var k=C.length>_.length?C:_,O=C.length>_.length?_:C;if(k.length<4||O.length*2<k.length)return null;function E(re,se,_e){for(var De=re.substring(_e,_e+Math.floor(re.length/4)),pe=-1,le="",me,we,oe,q;(pe=se.indexOf(De,pe+1))!==-1;){var Ze=l(re.substring(_e),se.substring(pe)),at=d(re.substring(0,_e),se.substring(0,pe));le.length<at+Ze&&(le=se.substring(pe-at,pe)+se.substring(pe,pe+Ze),me=re.substring(0,_e-at),we=re.substring(_e+Ze),oe=se.substring(0,pe-at),q=se.substring(pe+Ze))}return le.length*2>=re.length?[me,we,oe,q,le]:null}var T=E(k,O,Math.ceil(k.length/4)),L=E(k,O,Math.ceil(k.length/2)),z;if(!T&&!L)return null;L?T?z=T[4].length>L[4].length?T:L:z=L:z=T;var H,K,ee,Q;C.length>_.length?(H=z[0],K=z[1],ee=z[2],Q=z[3]):(ee=z[0],Q=z[1],H=z[2],K=z[3]);var ge=z[4];return[H,K,ee,Q,ge]}function f(C){for(var _=!1,k=[],O=0,E=null,T=0,L=0,z=0,H=0,K=0;T<C.length;)C[T][0]==r?(k[O++]=T,L=H,z=K,H=0,K=0,E=C[T][1]):(C[T][0]==n?H+=C[T][1].length:K+=C[T][1].length,E&&E.length<=Math.max(L,z)&&E.length<=Math.max(H,K)&&(C.splice(k[O-1],0,[i,E]),C[k[O-1]+1][0]=n,O--,O--,T=O>0?k[O-1]:-1,L=0,z=0,H=0,K=0,E=null,_=!0)),T++;for(_&&P(C),y(C),T=1;T<C.length;){if(C[T-1][0]==i&&C[T][0]==n){var ee=C[T-1][1],Q=C[T][1],ge=u(ee,Q),re=u(Q,ee);ge>=re?(ge>=ee.length/2||ge>=Q.length/2)&&(C.splice(T,0,[r,Q.substring(0,ge)]),C[T-1][1]=ee.substring(0,ee.length-ge),C[T+1][1]=Q.substring(ge),T++):(re>=ee.length/2||re>=Q.length/2)&&(C.splice(T,0,[r,ee.substring(0,re)]),C[T-1][0]=n,C[T-1][1]=Q.substring(0,Q.length-re),C[T+1][0]=i,C[T+1][1]=ee.substring(re),T++),T++}T++}}var g=/[^a-zA-Z0-9]/,m=/\s/,w=/[\r\n]/,b=/\n\r?\n$/,x=/^\r?\n\r?\n/;function y(C){function _(re,se){if(!re||!se)return 6;var _e=re.charAt(re.length-1),De=se.charAt(0),pe=_e.match(g),le=De.match(g),me=pe&&_e.match(m),we=le&&De.match(m),oe=me&&_e.match(w),q=we&&De.match(w),Ze=oe&&re.match(b),at=q&&se.match(x);return Ze||at?5:oe||q?4:pe&&!me&&we?3:me||we?2:pe||le?1:0}for(var k=1;k<C.length-1;){if(C[k-1][0]==r&&C[k+1][0]==r){var O=C[k-1][1],E=C[k][1],T=C[k+1][1],L=d(O,E);if(L){var z=E.substring(E.length-L);O=O.substring(0,O.length-L),E=z+E.substring(0,E.length-L),T=z+T}for(var H=O,K=E,ee=T,Q=_(O,E)+_(E,T);E.charAt(0)===T.charAt(0);){O+=E.charAt(0),E=E.substring(1)+T.charAt(0),T=T.substring(1);var ge=_(O,E)+_(E,T);ge>=Q&&(Q=ge,H=O,K=E,ee=T)}C[k-1][1]!=H&&(H?C[k-1][1]=H:(C.splice(k-1,1),k--),C[k][1]=K,ee?C[k+1][1]=ee:(C.splice(k+1,1),k--))}k++}}function P(C,_){C.push([r,""]);for(var k=0,O=0,E=0,T="",L="",z;k<C.length;){if(k<C.length-1&&!C[k][1]){C.splice(k,1);continue}switch(C[k][0]){case n:E++,L+=C[k][1],k++;break;case i:O++,T+=C[k][1],k++;break;case r:var H=k-E-O-1;if(_){if(H>=0&&U(C[H][1])){var K=C[H][1].slice(-1);if(C[H][1]=C[H][1].slice(0,-1),T=K+T,L=K+L,!C[H][1]){C.splice(H,1),k--;var ee=H-1;C[ee]&&C[ee][0]===n&&(E++,L=C[ee][1]+L,ee--),C[ee]&&C[ee][0]===i&&(O++,T=C[ee][1]+T,ee--),H=ee}}if(A(C[k][1])){var K=C[k][1].charAt(0);C[k][1]=C[k][1].slice(1),T+=K,L+=K}}if(k<C.length-1&&!C[k][1]){C.splice(k,1);break}if(T.length>0||L.length>0){T.length>0&&L.length>0&&(z=l(L,T),z!==0&&(H>=0?C[H][1]+=L.substring(0,z):(C.splice(0,0,[r,L.substring(0,z)]),k++),L=L.substring(z),T=T.substring(z)),z=d(L,T),z!==0&&(C[k][1]=L.substring(L.length-z)+C[k][1],L=L.substring(0,L.length-z),T=T.substring(0,T.length-z)));var Q=E+O;T.length===0&&L.length===0?(C.splice(k-Q,Q),k=k-Q):T.length===0?(C.splice(k-Q,Q,[n,L]),k=k-Q+1):L.length===0?(C.splice(k-Q,Q,[i,T]),k=k-Q+1):(C.splice(k-Q,Q,[i,T],[n,L]),k=k-Q+2)}k!==0&&C[k-1][0]===r?(C[k-1][1]+=C[k][1],C.splice(k,1)):k++,E=0,O=0,T="",L="";break}}C[C.length-1][1]===""&&C.pop();var ge=!1;for(k=1;k<C.length-1;)C[k-1][0]===r&&C[k+1][0]===r&&(C[k][1].substring(C[k][1].length-C[k-1][1].length)===C[k-1][1]?(C[k][1]=C[k-1][1]+C[k][1].substring(0,C[k][1].length-C[k-1][1].length),C[k+1][1]=C[k-1][1]+C[k+1][1],C.splice(k-1,1),ge=!0):C[k][1].substring(0,C[k+1][1].length)==C[k+1][1]&&(C[k-1][1]+=C[k+1][1],C[k][1]=C[k][1].substring(C[k+1][1].length)+C[k+1][1],C.splice(k+1,1),ge=!0)),k++;ge&&P(C,_)}function S(C){return C>=55296&&C<=56319}function R(C){return C>=56320&&C<=57343}function A(C){return R(C.charCodeAt(0))}function U(C){return S(C.charCodeAt(C.length-1))}function G(C){for(var _=[],k=0;k<C.length;k++)C[k][1].length>0&&_.push(C[k]);return _}function Z(C,_,k,O){return U(C)||A(O)?null:G([[r,C],[i,_],[n,k],[r,O]])}function fe(C,_,k){var O=typeof k=="number"?{index:k,length:0}:k.oldRange,E=typeof k=="number"?null:k.newRange,T=C.length,L=_.length;if(O.length===0&&(E===null||E.length===0)){var z=O.index,H=C.slice(0,z),K=C.slice(z),ee=E?E.index:null;e:{var Q=z+L-T;if(ee!==null&&ee!==Q||Q<0||Q>L)break e;var ge=_.slice(0,Q),re=_.slice(Q);if(re!==K)break e;var se=Math.min(z,Q),_e=H.slice(0,se),De=ge.slice(0,se);if(_e!==De)break e;var pe=H.slice(se),le=ge.slice(se);return Z(_e,pe,le,K)}e:{if(ee!==null&&ee!==z)break e;var me=z,ge=_.slice(0,me),re=_.slice(me);if(ge!==H)break e;var we=Math.min(T-me,L-me),oe=K.slice(K.length-we),q=re.slice(re.length-we);if(oe!==q)break e;var pe=K.slice(0,K.length-we),le=re.slice(0,re.length-we);return Z(H,pe,le,oe)}}if(O.length>0&&E&&E.length===0)e:{var _e=C.slice(0,O.index),oe=C.slice(O.index+O.length),se=_e.length,we=oe.length;if(L<se+we)break e;var De=_.slice(0,se),q=_.slice(L-we);if(_e!==De||oe!==q)break e;var pe=C.slice(se,T-we),le=_.slice(se,L-we);return Z(_e,pe,le,oe)}return null}function ue(C,_,k,O){return s(C,_,k,O,!0)}ue.INSERT=n,ue.DELETE=i,ue.EQUAL=r,t.exports=ue}),eu={};ef(eu,{CoreViewer:()=>Ap,HOOKS:()=>Bs,Navigation:()=>Rp,PageProgression:()=>Pa,PageSide:()=>nu,PageViewMode:()=>w0,Profiler:()=>au,ReadyState:()=>ru,UserAgentBaseCss:()=>sc,UserAgentCounterStylesCss:()=>lc,UserAgentPageCss:()=>rc,UserAgentTocCss:()=>oc,UserAgentXml:()=>nc,ValidationTxt:()=>ic,VivliostylePolyfillCss:()=>ac,VivliostyleViewportCss:()=>tc,VivliostyleViewportScreenCss:()=>ec,ZoomType:()=>m0,getHooksForName:()=>Ft,isDebug:()=>rr,pageProgressionOf:()=>iu,plugin:()=>of,printHTML:()=>b0,profile:()=>uf,profiler:()=>wt,registerHook:()=>kt,removeHook:()=>ou,setDebug:()=>tu});Fp.exports=nf(eu);var rr=!1;function tu(e){rr=e}var Pa=(e=>(e.LTR="ltr",e.RTL="rtl",e))(Pa||{});function iu(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var nu=(e=>(e.LEFT="left",e.RIGHT="right",e))(nu||{}),ru=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(ru||{}),su=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(su||{}),sf=class{constructor(e){this.opt_console=e,c(this,"listeners",{})}consoleDebug(e){this.opt_console?this.opt_console.debug?this.opt_console.debug(...e):this.opt_console.log(...e):console.debug(...e)}consoleInfo(e){this.opt_console?this.opt_console.info?this.opt_console.info(...e):this.opt_console.log(...e):console.info(...e)}consoleWarn(e){this.opt_console?this.opt_console.warn?this.opt_console.warn(...e):this.opt_console.log(...e):console.warn(...e)}consoleError(e){this.opt_console?this.opt_console.error?this.opt_console.error(...e):this.opt_console.log(...e):console.error(...e)}triggerListeners(e,t){let i=this.listeners[e];i&&i(t)}addListener(e,t){this.listeners[e]=t}debug(...e){let t=Tr(arguments);this.consoleDebug(Ir(t)),this.triggerListeners(1,t)}info(...e){let t=Tr(arguments);this.consoleInfo(Ir(t)),this.triggerListeners(2,t)}warn(...e){let t=Tr(arguments);this.consoleWarn(Ir(t)),this.triggerListeners(3,t)}error(...e){let t=Tr(arguments);this.consoleError(Ir(t)),this.triggerListeners(4,t)}};function Tr(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function Ir(e){let t=e.error,i=t&&(t.frameTrace||t.stack),n=[].concat(e.messages);return t&&(n.length>0&&(n=n.concat([`
1
+ var Tf=Object.create;var Ur=Object.defineProperty;var If=Object.getOwnPropertyDescriptor;var Af=Object.getOwnPropertyNames;var Ff=Object.getPrototypeOf,Rf=Object.prototype.hasOwnProperty;var Lf=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Of=(e,t)=>{for(var i in t)Ur(e,i,{get:t[i],enumerable:!0})},Vl=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Af(t))!Rf.call(e,r)&&r!==i&&Ur(e,r,{get:()=>t[r],enumerable:!(n=If(t,r))||n.enumerable});return e};var Bf=(e,t,i)=>(i=e!=null?Tf(Ff(e)):{},Vl(t||!e||!e.__esModule?Ur(i,"default",{value:e,enumerable:!0}):i,e)),Mf=e=>Vl(Ur({},"__esModule",{value:!0}),e);var Cf=Lf((tS,Sf)=>{"use strict";var _f=Object.create,Cr=Object.defineProperty,Df=Object.getOwnPropertyDescriptor,zf=Object.getOwnPropertyNames,Vf=Object.getPrototypeOf,Uf=Object.prototype.hasOwnProperty,ku=e=>{throw TypeError(e)},$f=(e,t,i)=>t in e?Cr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Hf=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Wf=(e,t)=>{for(var i in t)Cr(e,i,{get:t[i],enumerable:!0})},Eu=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of zf(t))!Uf.call(e,r)&&r!==i&&Cr(e,r,{get:()=>t[r],enumerable:!(n=Df(t,r))||n.enumerable});return e},Gf=(e,t,i)=>(i=e!=null?_f(Vf(e)):{},Eu(t||!e||!e.__esModule?Cr(i,"default",{value:e,enumerable:!0}):i,e)),jf=e=>Eu(Cr({},"__esModule",{value:!0}),e),c=(e,t,i)=>$f(e,typeof t!="symbol"?t+"":t,i),Ha=(e,t,i)=>t.has(e)||ku("Cannot "+i),$=(e,t,i)=>(Ha(e,t,"read from private field"),i?i.call(e):t.get(e)),ie=(e,t,i)=>t.has(e)?ku("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),Ve=(e,t,i,n)=>(Ha(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),Ne=(e,t,i)=>(Ha(e,t,"access private method"),i),Xf=Hf((e,t)=>{var i=-1,n=1,r=0;function o(k,_,E,L,P){if(k===_)return k?[[r,k]]:[];if(E!=null){var A=he(k,_,E);if(A)return A}var O=l(k,_),z=k.substring(0,O);k=k.substring(O),_=_.substring(O),O=d(k,_);var W=k.substring(k.length-O);k=k.substring(0,k.length-O),_=_.substring(0,_.length-O);var K=s(k,_);return z&&K.unshift([r,z]),W&&K.push([r,W]),S(K,P),L&&f(K),K}function s(k,_){var E;if(!k)return[[n,_]];if(!_)return[[i,k]];var L=k.length>_.length?k:_,P=k.length>_.length?_:k,A=L.indexOf(P);if(A!==-1)return E=[[n,L.substring(0,A)],[r,P],[n,L.substring(A+P.length)]],k.length>_.length&&(E[0][0]=E[2][0]=i),E;if(P.length===1)return[[i,k],[n,_]];var O=p(k,_);if(O){var z=O[0],W=O[1],K=O[2],Q=O[3],ee=O[4],pe=o(z,K),re=o(W,Q);return pe.concat([[r,ee]],re)}return a(k,_)}function a(k,_){for(var E=k.length,L=_.length,P=Math.ceil((E+L)/2),A=P,O=2*P,z=new Array(O),W=new Array(O),K=0;K<O;K++)z[K]=-1,W[K]=-1;z[A+1]=0,W[A+1]=0;for(var Q=E-L,ee=Q%2!==0,pe=0,re=0,se=0,Me=0,Oe=0;Oe<P;Oe++){for(var fe=-Oe+pe;fe<=Oe-re;fe+=2){var Ee=A+fe,we;fe===-Oe||fe!==Oe&&z[Ee-1]<z[Ee+1]?we=z[Ee+1]:we=z[Ee-1]+1;for(var ue=we-fe;we<E&&ue<L&&k.charAt(we)===_.charAt(ue);)we++,ue++;if(z[Ee]=we,we>E)re+=2;else if(ue>L)pe+=2;else if(ee){var Pe=A+Q-fe;if(Pe>=0&&Pe<O&&W[Pe]!==-1){var ye=E-W[Pe];if(we>=ye)return h(k,_,we,ue)}}}for(var Se=-Oe+se;Se<=Oe-Me;Se+=2){var Pe=A+Se,ye;Se===-Oe||Se!==Oe&&W[Pe-1]<W[Pe+1]?ye=W[Pe+1]:ye=W[Pe-1]+1;for(var ne=ye-Se;ye<E&&ne<L&&k.charAt(E-ye-1)===_.charAt(L-ne-1);)ye++,ne++;if(W[Pe]=ye,ye>E)Me+=2;else if(ne>L)se+=2;else if(!ee){var Ee=A+Q-Se;if(Ee>=0&&Ee<O&&z[Ee]!==-1){var we=z[Ee],ue=A+we-Ee;if(ye=E-ye,we>=ye)return h(k,_,we,ue)}}}}return[[i,k],[n,_]]}function h(k,_,E,L){var P=k.substring(0,E),A=_.substring(0,L),O=k.substring(E),z=_.substring(L),W=o(P,A),K=o(O,z);return W.concat(K)}function l(k,_){if(!k||!_||k.charAt(0)!==_.charAt(0))return 0;for(var E=0,L=Math.min(k.length,_.length),P=L,A=0;E<P;)k.substring(A,P)==_.substring(A,P)?(E=P,A=E):L=P,P=Math.floor((L-E)/2+E);return C(k.charCodeAt(P-1))&&P--,P}function u(k,_){var E=k.length,L=_.length;if(E==0||L==0)return 0;E>L?k=k.substring(E-L):E<L&&(_=_.substring(0,E));var P=Math.min(E,L);if(k==_)return P;for(var A=0,O=1;;){var z=k.substring(P-O),W=_.indexOf(z);if(W==-1)return A;O+=W,(W==0||k.substring(P-O)==_.substring(0,O))&&(A=O,O++)}}function d(k,_){if(!k||!_||k.slice(-1)!==_.slice(-1))return 0;for(var E=0,L=Math.min(k.length,_.length),P=L,A=0;E<P;)k.substring(k.length-P,k.length-A)==_.substring(_.length-P,_.length-A)?(E=P,A=E):L=P,P=Math.floor((L-E)/2+E);return N(k.charCodeAt(k.length-P))&&P--,P}function p(k,_){var E=k.length>_.length?k:_,L=k.length>_.length?_:k;if(E.length<4||L.length*2<E.length)return null;function P(re,se,Me){for(var Oe=re.substring(Me,Me+Math.floor(re.length/4)),fe=-1,Ee="",we,ue,Pe,ye;(fe=se.indexOf(Oe,fe+1))!==-1;){var Se=l(re.substring(Me),se.substring(fe)),ne=d(re.substring(0,Me),se.substring(0,fe));Ee.length<ne+Se&&(Ee=se.substring(fe-ne,fe)+se.substring(fe,fe+Se),we=re.substring(0,Me-ne),ue=re.substring(Me+Se),Pe=se.substring(0,fe-ne),ye=se.substring(fe+Se))}return Ee.length*2>=re.length?[we,ue,Pe,ye,Ee]:null}var A=P(E,L,Math.ceil(E.length/4)),O=P(E,L,Math.ceil(E.length/2)),z;if(!A&&!O)return null;O?A?z=A[4].length>O[4].length?A:O:z=O:z=A;var W,K,Q,ee;k.length>_.length?(W=z[0],K=z[1],Q=z[2],ee=z[3]):(Q=z[0],ee=z[1],W=z[2],K=z[3]);var pe=z[4];return[W,K,Q,ee,pe]}function f(k){for(var _=!1,E=[],L=0,P=null,A=0,O=0,z=0,W=0,K=0;A<k.length;)k[A][0]==r?(E[L++]=A,O=W,z=K,W=0,K=0,P=k[A][1]):(k[A][0]==n?W+=k[A][1].length:K+=k[A][1].length,P&&P.length<=Math.max(O,z)&&P.length<=Math.max(W,K)&&(k.splice(E[L-1],0,[i,P]),k[E[L-1]+1][0]=n,L--,L--,A=L>0?E[L-1]:-1,O=0,z=0,W=0,K=0,P=null,_=!0)),A++;for(_&&S(k),b(k),A=1;A<k.length;){if(k[A-1][0]==i&&k[A][0]==n){var Q=k[A-1][1],ee=k[A][1],pe=u(Q,ee),re=u(ee,Q);pe>=re?(pe>=Q.length/2||pe>=ee.length/2)&&(k.splice(A,0,[r,ee.substring(0,pe)]),k[A-1][1]=Q.substring(0,Q.length-pe),k[A+1][1]=ee.substring(pe),A++):(re>=Q.length/2||re>=ee.length/2)&&(k.splice(A,0,[r,Q.substring(0,re)]),k[A-1][0]=n,k[A-1][1]=ee.substring(0,ee.length-re),k[A+1][0]=i,k[A+1][1]=Q.substring(re),A++),A++}A++}}var g=/[^a-zA-Z0-9]/,m=/\s/,w=/[\r\n]/,x=/\n\r?\n$/,y=/^\r?\n\r?\n/;function b(k){function _(re,se){if(!re||!se)return 6;var Me=re.charAt(re.length-1),Oe=se.charAt(0),fe=Me.match(g),Ee=Oe.match(g),we=fe&&Me.match(m),ue=Ee&&Oe.match(m),Pe=we&&Me.match(w),ye=ue&&Oe.match(w),Se=Pe&&re.match(x),ne=ye&&se.match(y);return Se||ne?5:Pe||ye?4:fe&&!we&&ue?3:we||ue?2:fe||Ee?1:0}for(var E=1;E<k.length-1;){if(k[E-1][0]==r&&k[E+1][0]==r){var L=k[E-1][1],P=k[E][1],A=k[E+1][1],O=d(L,P);if(O){var z=P.substring(P.length-O);L=L.substring(0,L.length-O),P=z+P.substring(0,P.length-O),A=z+A}for(var W=L,K=P,Q=A,ee=_(L,P)+_(P,A);P.charAt(0)===A.charAt(0);){L+=P.charAt(0),P=P.substring(1)+A.charAt(0),A=A.substring(1);var pe=_(L,P)+_(P,A);pe>=ee&&(ee=pe,W=L,K=P,Q=A)}k[E-1][1]!=W&&(W?k[E-1][1]=W:(k.splice(E-1,1),E--),k[E][1]=K,Q?k[E+1][1]=Q:(k.splice(E+1,1),E--))}E++}}function S(k,_){k.push([r,""]);for(var E=0,L=0,P=0,A="",O="",z;E<k.length;){if(E<k.length-1&&!k[E][1]){k.splice(E,1);continue}switch(k[E][0]){case n:P++,O+=k[E][1],E++;break;case i:L++,A+=k[E][1],E++;break;case r:var W=E-P-L-1;if(_){if(W>=0&&B(k[W][1])){var K=k[W][1].slice(-1);if(k[W][1]=k[W][1].slice(0,-1),A=K+A,O=K+O,!k[W][1]){k.splice(W,1),E--;var Q=W-1;k[Q]&&k[Q][0]===n&&(P++,O=k[Q][1]+O,Q--),k[Q]&&k[Q][0]===i&&(L++,A=k[Q][1]+A,Q--),W=Q}}if(F(k[E][1])){var K=k[E][1].charAt(0);k[E][1]=k[E][1].slice(1),A+=K,O+=K}}if(E<k.length-1&&!k[E][1]){k.splice(E,1);break}if(A.length>0||O.length>0){A.length>0&&O.length>0&&(z=l(O,A),z!==0&&(W>=0?k[W][1]+=O.substring(0,z):(k.splice(0,0,[r,O.substring(0,z)]),E++),O=O.substring(z),A=A.substring(z)),z=d(O,A),z!==0&&(k[E][1]=O.substring(O.length-z)+k[E][1],O=O.substring(0,O.length-z),A=A.substring(0,A.length-z)));var ee=P+L;A.length===0&&O.length===0?(k.splice(E-ee,ee),E=E-ee):A.length===0?(k.splice(E-ee,ee,[n,O]),E=E-ee+1):O.length===0?(k.splice(E-ee,ee,[i,A]),E=E-ee+1):(k.splice(E-ee,ee,[i,A],[n,O]),E=E-ee+2)}E!==0&&k[E-1][0]===r?(k[E-1][1]+=k[E][1],k.splice(E,1)):E++,P=0,L=0,A="",O="";break}}k[k.length-1][1]===""&&k.pop();var pe=!1;for(E=1;E<k.length-1;)k[E-1][0]===r&&k[E+1][0]===r&&(k[E][1].substring(k[E][1].length-k[E-1][1].length)===k[E-1][1]?(k[E][1]=k[E-1][1]+k[E][1].substring(0,k[E][1].length-k[E-1][1].length),k[E+1][1]=k[E-1][1]+k[E+1][1],k.splice(E-1,1),pe=!0):k[E][1].substring(0,k[E+1][1].length)==k[E+1][1]&&(k[E-1][1]+=k[E+1][1],k[E][1]=k[E][1].substring(k[E+1][1].length)+k[E+1][1],k.splice(E+1,1),pe=!0)),E++;pe&&S(k,_)}function C(k){return k>=55296&&k<=56319}function N(k){return k>=56320&&k<=57343}function F(k){return N(k.charCodeAt(0))}function B(k){return C(k.charCodeAt(k.length-1))}function U(k){for(var _=[],E=0;E<k.length;E++)k[E][1].length>0&&_.push(k[E]);return _}function q(k,_,E,L){return B(k)||F(L)?null:U([[r,k],[i,_],[n,E],[r,L]])}function he(k,_,E){var L=typeof E=="number"?{index:E,length:0}:E.oldRange,P=typeof E=="number"?null:E.newRange,A=k.length,O=_.length;if(L.length===0&&(P===null||P.length===0)){var z=L.index,W=k.slice(0,z),K=k.slice(z),Q=P?P.index:null;e:{var ee=z+O-A;if(Q!==null&&Q!==ee||ee<0||ee>O)break e;var pe=_.slice(0,ee),re=_.slice(ee);if(re!==K)break e;var se=Math.min(z,ee),Me=W.slice(0,se),Oe=pe.slice(0,se);if(Me!==Oe)break e;var fe=W.slice(se),Ee=pe.slice(se);return q(Me,fe,Ee,K)}e:{if(Q!==null&&Q!==z)break e;var we=z,pe=_.slice(0,we),re=_.slice(we);if(pe!==W)break e;var ue=Math.min(A-we,O-we),Pe=K.slice(K.length-ue),ye=re.slice(re.length-ue);if(Pe!==ye)break e;var fe=K.slice(0,K.length-ue),Ee=re.slice(0,re.length-ue);return q(W,fe,Ee,Pe)}}if(L.length>0&&P&&P.length===0)e:{var Me=k.slice(0,L.index),Pe=k.slice(L.index+L.length),se=Me.length,ue=Pe.length;if(O<se+ue)break e;var Oe=_.slice(0,se),ye=_.slice(O-ue);if(Me!==Oe||Pe!==ye)break e;var fe=k.slice(se,A-ue),Ee=_.slice(se,O-ue);return q(Me,fe,Ee,Pe)}return null}function ae(k,_,E,L){return o(k,_,E,L,!0)}ae.INSERT=n,ae.DELETE=i,ae.EQUAL=r,t.exports=ae}),Pu={};Wf(Pu,{CoreViewer:()=>bf,HOOKS:()=>Yo,Navigation:()=>xf,PageProgression:()=>Wa,PageSide:()=>Iu,PageViewMode:()=>Vx,Profiler:()=>Lu,ReadyState:()=>Au,UserAgentBaseCss:()=>Uc,UserAgentCounterStylesCss:()=>Wc,UserAgentPageCss:()=>Vc,UserAgentTocCss:()=>$c,UserAgentXml:()=>zc,ValidationTxt:()=>Dc,VivliostylePolyfillCss:()=>Hc,VivliostyleViewportCss:()=>_c,VivliostyleViewportScreenCss:()=>Mc,ZoomType:()=>zx,getHooksForName:()=>Dt,isDebug:()=>dr,pageProgressionOf:()=>Tu,plugin:()=>Yf,printHTML:()=>$x,profile:()=>Qf,profiler:()=>xt,registerHook:()=>At,removeHook:()=>Ru,setDebug:()=>Nu});Sf.exports=jf(Pu);var dr=!1;function Nu(e){dr=e}var Wa=(e=>(e.LTR="ltr",e.RTL="rtl",e))(Wa||{});function Tu(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var Iu=(e=>(e.LEFT="left",e.RIGHT="right",e))(Iu||{}),Au=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(Au||{}),Fu=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(Fu||{}),qf=class{constructor(e){this.opt_console=e,c(this,"listeners",{})}consoleDebug(e){this.opt_console?this.opt_console.debug?this.opt_console.debug(...e):this.opt_console.log(...e):console.debug(...e)}consoleInfo(e){this.opt_console?this.opt_console.info?this.opt_console.info(...e):this.opt_console.log(...e):console.info(...e)}consoleWarn(e){this.opt_console?this.opt_console.warn?this.opt_console.warn(...e):this.opt_console.log(...e):console.warn(...e)}consoleError(e){this.opt_console?this.opt_console.error?this.opt_console.error(...e):this.opt_console.log(...e):console.error(...e)}triggerListeners(e,t){let i=this.listeners[e];i&&i(t)}addListener(e,t){this.listeners[e]=t}debug(...e){let t=$r(arguments);this.consoleDebug(Hr(t)),this.triggerListeners(1,t)}info(...e){let t=$r(arguments);this.consoleInfo(Hr(t)),this.triggerListeners(2,t)}warn(...e){let t=$r(arguments);this.consoleWarn(Hr(t)),this.triggerListeners(3,t)}error(...e){let t=$r(arguments);this.consoleError(Hr(t)),this.triggerListeners(4,t)}};function $r(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function Hr(e){let t=e.error,i=t&&(t.frameTrace||t.stack),n=[].concat(e.messages);return t&&(n.length>0&&(n=n.concat([`
2
2
  `])),n=n.concat([t.toString()]),i&&(n=n.concat([`
3
- `]).concat(i))),n}var W=new sf,Bs=(e=>(e.SIMPLE_PROPERTY="SIMPLE_PROPERTY",e.PREPROCESS_SINGLE_DOCUMENT="PREPROCESS_SINGLE_DOCUMENT",e.PREPROCESS_TEXT_CONTENT="PREPROCESS_TEXT_CONTENT",e.PREPROCESS_ELEMENT_STYLE="PREPROCESS_ELEMENT_STYLE",e.POLYFILLED_INHERITED_PROPS="POLYFILLED_INHERITED_PROPS",e.CONFIGURATION="CONFIGURATION",e.RESOLVE_TEXT_NODE_BREAKER="RESOLVE_TEXT_NODE_BREAKER",e.RESOLVE_FORMATTING_CONTEXT="RESOLVE_FORMATTING_CONTEXT",e.RESOLVE_LAYOUT_PROCESSOR="RESOLVE_LAYOUT_PROCESSOR",e.POST_LAYOUT_BLOCK="POST_LAYOUT_BLOCK",e.PAGINATION_PROGRESS="PAGINATION_PROGRESS",e))(Bs||{}),us={};function kt(e,t,i){if(!Bs[e])W.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=us[e];n||(n=us[e]=[]),i?n.unshift(t):n.push(t)}}function ou(e,t){if(!Bs[e])W.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=us[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function Ft(e){return us[e]||[]}var of={registerHook:kt,removeHook:ou},au=class{constructor(e){this.performanceInstance=e,c(this,"timestamps",{}),c(this,"registerTiming"),c(this,"registerStartTiming"),c(this,"registerEndTiming"),this.registerTiming=$i,this.registerStartTiming=this.registerStartTiming=$i,this.registerEndTiming=this.registerEndTiming=$i}forceRegisterStartTiming(e,t){eo.call(this,e,"start",t)}forceRegisterEndTiming(e,t){eo.call(this,e,"end",t)}printTimings(){let e=this.timestamps,t="";Object.keys(e).forEach(i=>{let n=e[i],r=n.length;for(let s=0;s<r;s++){let o=n[s];t+=i,r>1&&(t+=`(${s})`),t+=` => start: ${o.start}, end: ${o.end}, duration: ${o.end-o.start}
4
- `}}),W.info(t)}disable(){this.registerTiming=$i,this.registerStartTiming=this.registerStartTiming=$i,this.registerEndTiming=this.registerEndTiming=$i}enable(){this.registerTiming=eo,this.registerStartTiming=this.registerStartTiming=yl,this.registerEndTiming=this.registerEndTiming=af}isEnabled(){return this.registerStartTiming===yl}};function $i(){}function eo(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let r,s=n.length;for(let o=s-1;o>=0&&(r=n[o],!(r&&!r[t]));o--)r=null;r||(r={},n.push(r)),r[t]=i}function yl(e,t){this.registerTiming(e,"start",t)}function af(e,t){this.registerTiming(e,"end",t)}var lf={now:Date.now},hf=window&&window.performance,wt=new au(hf||lf);wt.forceRegisterStartTiming("load_vivliostyle");var uf={profiler:{registerStartTiming:wt.registerStartTiming,registerEndTiming:wt.registerEndTiming,printTimings:wt.printTimings,disable:wt.disable,enable:wt.enable}},Na=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",cs=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,$t="data-adapt-eloff",cf={};function Ta(e){return JSON.parse(e)}function Wt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function df(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var Di=window.location.href;function bl(e){Di=e}var fi=window.location.href;function vl(e){fi=e}function Ee(e,t){if(/^data:/i.test(t))return e||t;if(!t||e.match(/^\w{2,}:/))return e.toLowerCase().match("^javascript:")?"#":(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`),e);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let i;if(e.match(/^\/\//))return i=t.match(/^(\w{2,}:)\/\//),i?i[1]+e:e;if(e.match(/^\//))return i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e;if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=df(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let r=t.substr(0,n+1)+e,s="";for(i=r.match(/^([^?#]*)([?#].*)$/),i&&(r=i[1],s=i[2]);n=r.indexOf("/../"),!(n<=0);){let o=r.lastIndexOf("/",n-1);if(o<=0)break;r=r.substr(0,o)+r.substr(n+3)}return r.replace(/\/(\.\/)+/g,"/")+s}function Ar(e,t){return e.match(/^#/)&&t?Wt(t)+e:Ee(e,t)}function pn(e){let t;return(t=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/${t[2]}/${t[3]?"":"master/"}${t[4]}`:(t=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${t[2]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[6]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(?:#|%23)file-(.*)-(\w+)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[3]}.${t[4]}`:(t=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(e))&&(e=`${t[1]}//output.jsbin.com/${t[2]}${t[3]}/`),e}function xl(e){return e==null?e:e.toString()}var pf=class{constructor(){c(this,"queue",[null])}length(){return this.queue.length-1}add(e){let t=this.queue.length;for(;t>1;){let i=Math.floor(t/2),n=this.queue[i];if(n.compare(e)>0){this.queue[t]=e;return}this.queue[t]=n,t=i}this.queue[1]=e}peek(){return this.queue[1]}remove(){let e=this.queue[1],t=this.queue.pop(),i=this.queue.length;if(i>1){let n=1;for(;;){let r=n*2;if(r>=i)break;if(this.queue[r].compare(t)>0)r+1<i&&this.queue[r+1].compare(this.queue[r])>0&&r++;else if(r+1<i&&this.queue[r+1].compare(t)>0)r++;else break;this.queue[n]=this.queue[r],n=r}this.queue[n]=t}return e}},lu=["","-webkit-","-moz-"],ji={};function Ur(e,t){return CSS.supports(e+t,"unset")}function ff(e){let t=ji[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return ji[e]=null,null;case"text-combine-upright":if(Ur("-webkit-","text-combine")&&!Ur("","text-combine-upright"))return ji[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of lu)if(Ur(i,e))return t=[i+e],ji[e]=t,t;return W.warn("Property not supported by the browser: ",e),ji[e]=null,null}function I(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let r=ff(t);if(r)for(let s of r){switch(s){case"-webkit-text-combine":switch(i){case"all":i="horizontal";break}break;case"text-combine-upright":switch(i){case"all":n.setProperty("text-indent","0");break}break}n.setProperty(s,i)}}function ci(e,t,i){try{let n=ji[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function xo(e){let t=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!t&&e.namespaceURI=="http://www.w3.org/1999/xhtml"&&(t=e.getAttribute("lang")),t}var ii=class{constructor(){c(this,"list",[])}append(e){return this.list.push(e),this}clear(){this.list=[]}toString(){let e=this.list.join("");return this.list=[e],e}};function hu(e){return`\\${e.charCodeAt(0).toString(16)} `}function gi(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,hu)}function fr(e){return e.replace(/[\u0000-\u001F"\\]/g,hu)}function Sl(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Cl(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function gf(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function uu(e,t){function i(n){return gf(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function ai(e){return uu(e)}function mf(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function wf(e,t){t=typeof t=="string"?t:"\\u";function i(r){return mf(r,t)}let n=new RegExp(`${ai(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function ni(e,t){let i=0,n=e;for(;;){if(i<=n,i==0||t(i-1),n==e||t(n),i==n)return i;let r=i+n>>1;t(r)?n=r:i=r+1}}function cu(e,t){return e-t}function kl(e,t){let i={};for(let n of e){let r=t(n);r&&!i[r]&&(i[r]=n)}return i}function yf(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function to(e,t){let i={};for(let n of e){let r=t(n);r&&(i[r]?i[r].push(n):i[r]=[n])}return i}function bf(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var Ia=class{constructor(){c(this,"listeners",{})}dispatchEvent(e){let t=this.listeners[e.type];if(t){e.target=this,e.currentTarget=this;for(let i=0;i<t.length;i++)t[i](e)}}addEventListener(e,t,i){if(i)return;let n=this.listeners[e];n?n.includes(t)||n.push(t):this.listeners[e]=[t]}removeEventListener(e,t,i){if(i)return;let n=this.listeners[e];if(n){let r=n.indexOf(t);r>=0&&n.splice(r,1)}}},Oi={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function du(){return{fontFamily:"serif",lineHeight:1.25,margin:8,hyphenate:!1,columnWidth:25,horizontal:!1,nightMode:!1,spreadView:!1,pageBorder:1,enabledMediaTypes:{vivliostyle:!0,print:!0},defaultPaperSize:void 0}}function pu(e){return{fontFamily:e.fontFamily,lineHeight:e.lineHeight,margin:e.margin,hyphenate:e.hyphenate,columnWidth:e.columnWidth,horizontal:e.horizontal,nightMode:e.nightMode,spreadView:e.spreadView,pageBorder:e.pageBorder,enabledMediaTypes:Object.assign({},e.enabledMediaTypes),defaultPaperSize:e.defaultPaperSize?Object.assign({},e.defaultPaperSize):void 0}}var vf=du(),El={PENDING:{}};function fu(e,t,i,n){let r=Math.min((e-0)/i,(t-0)/n);return`matrix(${r},0,0,${r},0,0)`}function xf(e){return`"${fr(`${e}`)}"`}function Sf(e){return gi(`${e}`)}function So(e,t){return e?`${gi(e)}.${gi(t)}`:gi(t)}var gu=0,Co=class{constructor(e,t){if(this.parent=e,this.resolver=t,c(this,"scopeKey"),c(this,"children",[]),c(this,"zero"),c(this,"one"),c(this,"_true"),c(this,"_false"),c(this,"values",{}),c(this,"funcs",{}),c(this,"builtIns",{}),this.scopeKey=`S${gu++}`,this.zero=new Ye(this,0),this.one=new Ye(this,1),this._true=new Ye(this,!0),this._false=new Ye(this,!1),e&&e.children.push(this),!e){let i=this.builtIns;i.floor=Math.floor,i.ceil=Math.ceil,i.round=Math.round,i.sqrt=Math.sqrt,i.min=Math.min,i.max=Math.max,i.letterbox=fu,i["css-string"]=xf,i["css-name"]=Sf,i.typeof=n=>typeof n,this.defineBuiltInName("page-width",function(){return this.pageWidth()}),this.defineBuiltInName("page-height",function(){return this.pageHeight()}),this.defineBuiltInName("pref-font-family",function(){return this.pref.fontFamily}),this.defineBuiltInName("pref-night-mode",function(){return this.pref.nightMode}),this.defineBuiltInName("pref-hyphenate",function(){return this.pref.hyphenate}),this.defineBuiltInName("pref-margin",function(){return this.pref.margin}),this.defineBuiltInName("pref-line-height",function(){return this.pref.lineHeight}),this.defineBuiltInName("pref-column-width",function(){return this.pref.columnWidth*this.fontSize}),this.defineBuiltInName("pref-horizontal",function(){return this.pref.horizontal}),this.defineBuiltInName("pref-spread-view",function(){return this.pref.spreadView}),this.defineBuiltInName("pub-title",function(){return this.pubTitle?this.pubTitle:""}),this.defineBuiltInName("doc-title",function(){return this.docTitle?this.docTitle:""})}}defineBuiltInName(e,t){this.values[e]=new Ie(this,t,e)}defineName(e,t){this.values[e]=t}defineFunc(e,t){this.funcs[e]=t}defineBuiltIn(e,t){this.builtIns[e]=t}};function Cf(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function mu(e){switch(e?.toLowerCase()){case"vw":case"vh":case"vi":case"vb":case"vmin":case"vmax":case"pvw":case"pvh":case"pvi":case"pvb":case"pvmin":case"pvmax":return!0;default:return!1}}function kf(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function Ef(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var _t={px:1,in:96,pt:4/3,pc:96/6,cm:96/2.54,mm:96/25.4,q:96/2.54/40,em:16,rem:16,lh:20,rlh:20,dppx:1,dpi:1/96,dpcm:2.54/96};function wu(e){switch(e){case"q":return!CSS.supports("font-size","1q");case"lh":return!CSS.supports("line-height","1lh");case"rem":case"rlh":return!0;default:return!1}}var ko=class{constructor(e,t,i,n){this.rootScope=e,this.viewportWidth=t,this.viewportHeight=i,c(this,"actualPageWidth",null),c(this,"pageWidth"),c(this,"actualPageHeight",null),c(this,"pageHeight"),c(this,"initialFontSize"),c(this,"rootFontSize",null),c(this,"isRelativeRootFontSize",null),c(this,"fontSize"),c(this,"rootLineHeight",null),c(this,"pref"),c(this,"scopes",{}),c(this,"pageAreaWidth",null),c(this,"pageAreaHeight",null),c(this,"pageVertical",null),c(this,"pubTitle",null),c(this,"docTitle",null),this.pageWidth=function(){return this.actualPageWidth?this.actualPageWidth:this.pref.spreadView?Math.floor(t/2)-this.pref.pageBorder:t},this.pageHeight=function(){return this.actualPageHeight?this.actualPageHeight:i},this.initialFontSize=n,this.fontSize=function(){return this.rootFontSize?this.rootFontSize:n},this.pref=vf}getScopeContext(e){let t=this.scopes[e.scopeKey];return t||(t={},this.scopes[e.scopeKey]=t),t}clearScope(e){this.scopes[e.scopeKey]={};for(let t=0;t<e.children.length;t++)this.clearScope(e.children[t])}queryUnitSize(e,t,i){if(mu(e)){let n=this.pageWidth()/100,r=this.pageHeight()/100,s=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,o=this.pageAreaHeight!=null?this.pageAreaHeight/100:r,a=i??this.pageVertical;switch(e){case"vw":return s;case"vh":return o;case"vi":return a?o:s;case"vb":return a?s:o;case"vmin":return s<o?s:o;case"vmax":return s>o?s:o;case"pvw":return n;case"pvh":return r;case"pvi":return a?r:n;case"pvb":return a?n:r;case"pvmin":return n<r?n:r;case"pvmax":return n>r?n:r}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="lh"||e=="rlh"?this.rootLineHeight:_t[e]}evalName(e,t){do{let i=e.values[t];if(i||e.resolver&&(i=e.resolver.call(this,t,!1),i))return i;e=e.parent}while(e);throw new Error(`Name '${t}' is undefined`)}evalCall(e,t,i,n){do{let r=e.funcs[t];if(r||e.resolver&&(r=e.resolver.call(this,t,!0),r))return r;let s=e.builtIns[t];if(s){if(n)return e.zero;let o=Array(i.length);for(let a=0;a<i.length;a++)o[a]=i[a].evaluate(this);return new Ye(e,s.apply(this,o))}e=e.parent}while(e);throw new Error(`Function '${t}' is undefined`)}evalMediaName(e,t){let i=e==="all"||!!this.pref.enabledMediaTypes[e];return t?!i:i}evalMediaTest(e,t){let i="",n=e.match(/^(min|max)-(.*)$/);n&&(i=n[1],e=n[2]);let r=null,s=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(r=t.evaluate(this));break}switch(e){case"width":s=this.pageWidth();break;case"height":s=this.pageHeight();break;case"device-width":s=window.screen.availWidth;break;case"device-height":s=window.screen.availHeight;break;case"color":s=window.screen.pixelDepth;break}if(s!=null&&r!=null)switch(i){case"min":return s>=Number(r);case"max":return s<=Number(r);default:return s==r}else if(s!=null&&t==null)return s!==0;return!1}evalSupportsTest(e,t,i){return!1}queryVal(e,t){let i=e&&this.scopes[e.scopeKey];return i?i[t]:void 0}storeVal(e,t,i){this.getScopeContext(e)[t]=i}},Ot=class{constructor(e){this.scope=e,c(this,"key"),this.scope=e,this.key=`_${gu++}`}toString(){let e=new ii;return this.appendTo(e,0),e.toString()}appendTo(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){throw new Error("F_ABSTRACT")}expand(e,t){return this}dependCore(e,t,i){return e===this}dependOuter(e,t,i){let n=i[this.key];if(n!=null)return n===El.PENDING?!1:n;{i[this.key]=El.PENDING;let r=this.dependCore(e,t,i);return i[this.key]=r,r}}depend(e,t){return this.dependOuter(e,t,{})}evaluate(e){let t=e.queryVal(this.scope,this.key);return typeof t<"u"||(t=this.evaluateCore(e),this.scope&&e.storeVal(this.scope,this.key,t)),t}isMediaName(){return!1}},yu=class extends Ot{constructor(e,t){super(e),this.val=t}getOp(){throw new Error("F_ABSTRACT")}evalPrefix(e){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.val.evaluate(e);return this.evalPrefix(t)}dependCore(e,t,i){return e===this||this.val.dependOuter(e,t,i)}appendTo(e,t){10<t&&e.append("("),e.append(this.getOp()),this.val.appendTo(e,10),10<t&&e.append(")")}expand(e,t){let i=this.val.expand(e,t);return i===this.val?this:new this.constructor(this.scope,i)}},Ms=class extends Ot{constructor(e,t,i){super(e),this.lhs=t,this.rhs=i}getPriority(){throw new Error("F_ABSTRACT")}getOp(){throw new Error("F_ABSTRACT")}evalInfix(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.lhs.evaluate(e),i=this.rhs.evaluate(e);return this.evalInfix(t,i)}dependCore(e,t,i){return e===this||this.lhs.dependOuter(e,t,i)||this.rhs.dependOuter(e,t,i)}appendTo(e,t){let i=this.getPriority();i<=t&&e.append("("),this.lhs.appendTo(e,i),e.append(this.getOp()),this.rhs.appendTo(e,i),i<=t&&e.append(")")}expand(e,t){let i=this.lhs.expand(e,t),n=this.rhs.expand(e,t);return i===this.lhs&&n===this.rhs?this:new this.constructor(this.scope,i,n)}},bu=class extends Ms{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Nn=class extends Ms{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},vu=class extends Ms{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},Aa=class extends Ms{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},mi=class extends yu{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},Pf=class extends mi{constructor(e,t){super(e,t)}getOp(){return"not "}},rn=class extends yu{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},Ra=class extends bu{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},Nf=class extends Ra{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},Fa=class extends bu{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},Tf=class extends Fa{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},If=class extends Fa{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},Af=class extends Nn{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},Rf=class extends Nn{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},Ff=class extends Nn{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},Eo=class extends Nn{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},La=class extends Nn{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},Lf=class extends Nn{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},xu=class extends vu{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},Su=class extends vu{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},Oa=class extends Aa{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},Cu=class extends Aa{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},ku=class extends Aa{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},gr=class extends Ot{constructor(e,t,i){var n;super(e),this.num=t,c(this,"unit"),this.unit=(n=i?.toLowerCase())!=null?n:""}appendTo(e,t){e.append(this.num.toString()),e.append(gi(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},je=class extends Ot{constructor(e,t){super(e),this.qualifiedName=t}appendTo(e,t){e.append(this.qualifiedName)}evaluateCore(e){return e.evalName(this.scope,this.qualifiedName).evaluate(e)}dependCore(e,t,i){return e===this||t.evalName(this.scope,this.qualifiedName).dependOuter(e,t,i)}},Pl=class extends Ot{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(gi(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},Ie=class extends Ot{constructor(e,t,i){super(e),this.fn=t,this.str=i}appendTo(e,t){e.append(this.str)}evaluateCore(e){return this.fn.call(e)}};function Of(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function Bf(e,t,i){let n=t;for(let r=0;r<t.length;r++){let s=t[r].expand(e,i);if(t!==n)n[r]=s;else if(s!==t[r]){n=Array(t.length);for(let o=0;o<r;o++)n[o]=t[o];n[r]=s}}return n}var Yn=class Eu extends Ot{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),Of(t,this.params)}evaluateCore(t){return t.evalCall(this.scope,this.qualifiedName,this.params,!1).expand(t,this.params).evaluate(t)}dependCore(t,i,n){if(t===this)return!0;for(let r=0;r<this.params.length;r++)if(this.params[r].dependOuter(t,i,n))return!0;return i.evalCall(this.scope,this.qualifiedName,this.params,!0).dependOuter(t,i,n)}expand(t,i){let n=Bf(t,this.params,i);return n===this.params?this:new Eu(this.scope,this.qualifiedName,n)}},Mf=class Pu extends Ot{constructor(t,i,n,r){super(t),this.cond=i,this.ifTrue=n,this.ifFalse=r}appendTo(t,i){i>0&&t.append("("),this.cond.appendTo(t,0),t.append("?"),this.ifTrue.appendTo(t,0),t.append(":"),this.ifFalse.appendTo(t,0),i>0&&t.append(")")}evaluateCore(t){return this.cond.evaluate(t)?this.ifTrue.evaluate(t):this.ifFalse.evaluate(t)}dependCore(t,i,n){return t===this||this.cond.dependOuter(t,i,n)||this.ifTrue.dependOuter(t,i,n)||this.ifFalse.dependOuter(t,i,n)}expand(t,i){let n=this.cond.expand(t,i),r=this.ifTrue.expand(t,i),s=this.ifFalse.expand(t,i);return n===this.cond&&r===this.ifTrue&&s===this.ifFalse?this:new Pu(this.scope,n,r,s)}},Ye=class extends Ot{constructor(e,t){super(e),this.val=t}appendTo(e,t){switch(typeof this.val){case"number":case"boolean":e.append(this.val.toString());break;case"string":e.append('"'),e.append(fr(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Nl=class Nu extends Ot{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(fr(this.name.name)),t.append(":"),this.value.appendTo(t,0),t.append(")")}evaluateCore(t){return t.evalMediaTest(this.name.name,this.value)}dependCore(t,i,n){return t===this||this.value.dependOuter(t,i,n)}expand(t,i){let n=this.value.expand(t,i);return n===this.value?this:new Nu(this.scope,this.name,n)}},_f=class extends Ot{constructor(e,t,i,n){super(e),this.name=t,this.value=i,this.isFunc=n}appendTo(e,t){this.isFunc&&e.append(this.name),e.append("("),!this.isFunc&&this.name&&(e.append(this.name),e.append(":")),e.append(this.value),e.append(")")}evaluateCore(e){return e.evalSupportsTest(this.name,this.value,this.isFunc)}},Tu=class extends Ot{constructor(e,t){super(e),this.index=t}appendTo(e,t){e.append("$"),e.append(this.index.toString())}expand(e,t){let i=t[this.index];if(!i)throw new Error(`Parameter missing: ${this.index}`);return i}};function At(e,t,i){return t===e._false||t===e.zero||i==e._false||i==e.zero?e._false:t===e._true||t===e.one?i:i===e._true||i===e.one?t:new Ra(e,t,i)}function ie(e,t,i){return t===e.zero?i:i===e.zero?t:new xu(e,t,i)}function ye(e,t,i){return t===e.zero?new rn(e,i):i===e.zero?t:new Su(e,t,i)}function Hr(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new Oa(e,t,i)}function Po(e,t,i){return t===e.zero?e.zero:i===e.one?t:new Cu(e,t,i)}var oi=class{visitValues(e){for(let t=0;t<e.length;t++)e[t].visit(this);return null}visitEmpty(e){return null}visitSlash(e){return null}visitStr(e){return null}visitIdent(e){return null}visitNumeric(e){return null}visitNum(e){return null}visitInt(e){return this.visitNum(e)}visitHexColor(e){return null}visitURL(e){return null}visitURange(e){return null}visitSpaceList(e){return this.visitValues(e.values),null}visitCommaList(e){return this.visitValues(e.values),null}visitFunc(e){return this.visitValues(e.values),null}visitExpr(e){return null}},Vi=class extends oi{constructor(){super(),c(this,"error",!1)}visitValues(e){let t=null;for(let i=0;i<e.length;i++){let n=e[i],r=n.visit(this);if(this.error)return[];if(t)t[i]=r;else if(n!==r){t=new Array(e.length);for(let s=0;s<i;s++)t[s]=e[s];t[i]=r}}return t||e}visitEmpty(e){return e}visitStr(e){return e}visitIdent(e){return e}visitSlash(e){return e}visitNumeric(e){return e}visitNum(e){return e}visitInt(e){return e}visitHexColor(e){return e}visitURL(e){return e}visitURange(e){return e}visitSpaceList(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new te(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new tt(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new Ui(e.name,t)}visitExpr(e){return e}},it=class{toString(){let e=new ii;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new ii;return this.appendTo(e,!1),e.toString()}toExpr(e,t){return null}appendTo(e,t){e.append("[error]")}isExpr(){return!1}isNumeric(){return!1}isNum(){return!1}isIdent(){return!1}isSpaceList(){return!1}visit(e){return this}},Iu=class Au extends it{static get instance(){return this.empty||(this.empty=new Au),this.empty}constructor(){super()}toExpr(t,i){return new Ye(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};c(Iu,"empty");var Df=Iu,Y=Df.instance,Ru=class Fu extends it{static get instance(){return this.slash||(this.slash=new Fu),this.slash}constructor(){super()}toExpr(t,i){return new Ye(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};c(Ru,"slash");var zf=Ru,Tn=zf.instance,j=class extends it{constructor(e){super(),this.str=e}toExpr(e,t){return new Ye(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(fr(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},No=Object.create(null),de=class extends it{constructor(e){if(super(),this.name=e,No[e])throw new Error("E_INVALID_CALL");No[e]=this}toExpr(e,t){return new Ye(e,this.name)}appendTo(e,t){t?e.append(gi(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function B(e){let t=No[e];return t||(t=new de(e)),t}var F=class extends it{constructor(e,t){var i;super(),this.num=e,c(this,"unit"),this.unit=(i=t?.toLowerCase())!=null?i:""}toExpr(e,t){return this.num==0?e.zero:t&&this.unit=="%"?this.num==100?t:new Oa(e,t,new Ye(e,this.num/100)):new gr(e,this.num,this.unit)}appendTo(e,t){e.append(this.num.toString()),e.append(this.unit)}visit(e){return e.visitNumeric(this)}isNumeric(){return!0}},vt=class extends it{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new Ye(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},Be=class extends vt{constructor(e){super(e)}visit(e){return e.visitInt(this)}},Lu=class extends it{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},ot=class extends it{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(fr(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},Ou=class extends it{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function Ba(e,t,i,n){var r,s;let o=t.length;if(o>0){(r=t[0])==null||r.appendTo(e,n);for(let a=1;a<o;a++)e.append(i),(s=t[a])==null||s.appendTo(e,n)}}var te=class extends it{constructor(e){super(),this.values=e}appendTo(e,t){Ba(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},tt=class extends it{constructor(e){super(),this.values=e}appendTo(e,t){Ba(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},Ui=class extends it{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(gi(this.name)),e.append("("),Ba(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},$=class extends it{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof Ye||this.expr instanceof gr?this.expr.appendTo(e,0):(e.append("-epubx-expr("),this.expr.appendTo(e,0),e.append(")"))}visit(e){return e.visitExpr(this)}isExpr(){return!0}},Xi=class extends it{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function nt(e,t){if(e){if(e.isNumeric()){let i=e;return t.queryUnitSize(i.unit,!1)*i.num}if(e.isNum())return e.num}return 0}function Bu(e,t){return new F(nt(e,t),"px")}var v={absolute:B("absolute"),all:B("all"),always:B("always"),anywhere:B("anywhere"),auto:B("auto"),avoid:B("avoid"),balance:B("balance"),balance_all:B("balance-all"),block:B("block"),block_end:B("block-end"),block_start:B("block-start"),both:B("both"),bottom:B("bottom"),border_box:B("border-box"),break_all:B("break-all"),break_word:B("break-word"),clip:B("clip"),crop:B("crop"),cross:B("cross"),column:B("column"),discard:B("discard"),exclusive:B("exclusive"),_false:B("false"),fixed:B("fixed"),flex:B("flex"),flow_root:B("flow-root"),footnote:B("footnote"),footer:B("footer"),grid:B("grid"),header:B("header"),hidden:B("hidden"),horizontal_tb:B("horizontal-tb"),inherit:B("inherit"),initial:B("initial"),inline:B("inline"),inline_block:B("inline-block"),inline_end:B("inline-end"),inline_start:B("inline-start"),inside:B("inside"),keep:B("keep"),landscape:B("landscape"),left:B("left"),line:B("line"),list_item:B("list-item"),ltr:B("ltr"),manual:B("manual"),max_content:B("max-content"),min_content:B("min-content"),none:B("none"),normal:B("normal"),oeb_page_foot:B("oeb-page-foot"),oeb_page_head:B("oeb-page-head"),outside:B("outside"),padding_box:B("padding-box"),page:B("page"),relative:B("relative"),revert:B("revert"),right:B("right"),same:B("same"),scale:B("scale"),snap_block:B("snap-block"),snap_inline:B("snap-inline"),solid:B("solid"),spread:B("spread"),_static:B("static"),rtl:B("rtl"),table:B("table"),table_caption:B("table-caption"),table_cell:B("table-cell"),table_footer_group:B("table-footer-group"),table_header_group:B("table-header-group"),table_row:B("table-row"),top:B("top"),transparent:B("transparent"),unset:B("unset"),vertical_lr:B("vertical-lr"),vertical_rl:B("vertical-rl"),visible:B("visible"),_true:B("true")},Tl=new F(100,"%"),mr=new F(100,"pvw"),wr=new F(100,"pvh"),Ne=new F(0,"px"),S0=new Ou("U+0-10FFFF"),Il={"font-size":1,"line-height":2,color:3};function J(e){return e===v.inherit||e===v.initial||e===v.revert||e===v.unset}function Al(e,t){let i=Il[e]||Number.MAX_VALUE,n=Il[t]||Number.MAX_VALUE;return i-n}function jt(e){return e?.length>2&&e.startsWith("--")}var qi,Yi,Zi,Mu=class qt{constructor(t,i,n){ne(this,qi),ne(this,Yi),ne(this,Zi),Oe(this,qi,Math.round(Math.max(0,Math.min(t,qt.MAX)))),Oe(this,Yi,Math.round(Math.max(0,Math.min(i,qt.MAX)))),Oe(this,Zi,Math.round(Math.max(0,Math.min(n,qt.MAX))))}static fromInt(t,i,n){return new qt(t,i,n)}offset(t,i,n){return new qt(V(this,qi)+t,V(this,Yi)+i,V(this,Zi)+n)}toKey(){return JSON.stringify([V(this,qi),V(this,Yi),V(this,Zi)])}toColorFunc(t){return new Ui("color",[new te([B("srgb"),new vt(V(this,qi)/qt.MAX),new vt(V(this,Yi)/qt.MAX),new vt(V(this,Zi)/qt.MAX),...t!==null?[Tn,new vt(t)]:[]])])}};qi=new WeakMap,Yi=new WeakMap,Zi=new WeakMap,c(Mu,"MAX",1e4);var Zt=Mu;function Vf(e){return Array.isArray(e)?e.every(t=>{if(!Array.isArray(t)||t.length!==2)return!1;let[i,n]=t;if(!i||typeof i!="object"||Array.isArray(i)||!n||typeof n!="object"||Array.isArray(n))return!1;let r=i,s=n;return Number.isFinite(r.r)&&Number.isFinite(r.g)&&Number.isFinite(r.b)&&Number.isFinite(s.c)&&Number.isFinite(s.m)&&Number.isFinite(s.y)&&Number.isFinite(s.k)}):!1}var Ti,Ii,Ai,zt,_u=class lt{constructor(t,i,n,r){ne(this,Ti),ne(this,Ii),ne(this,Ai),ne(this,zt),Oe(this,Ti,Math.round(Math.max(0,Math.min(t,lt.MAX)))),Oe(this,Ii,Math.round(Math.max(0,Math.min(i,lt.MAX)))),Oe(this,Ai,Math.round(Math.max(0,Math.min(n,lt.MAX)))),Oe(this,zt,Math.round(Math.max(0,Math.min(r,lt.MAX))))}static fromInt(t,i,n,r){return new lt(t,i,n,r)}static fromNumber(t,i,n,r){return new lt(t*lt.MAX,i*lt.MAX,n*lt.MAX,r*lt.MAX)}toSRGB(){let t=lt.MAX-V(this,zt);return Zt.fromInt(Zt.MAX-Math.min(Zt.MAX,Math.round(V(this,Ti)*t/lt.MAX)+V(this,zt)),Zt.MAX-Math.min(Zt.MAX,Math.round(V(this,Ii)*t/lt.MAX)+V(this,zt)),Zt.MAX-Math.min(Zt.MAX,Math.round(V(this,Ai)*t/lt.MAX)+V(this,zt)))}equals(t){return V(this,Ti)===V(t,Ti)&&V(this,Ii)===V(t,Ii)&&V(this,Ai)===V(t,Ai)&&V(this,zt)===V(t,zt)}toJSON(){return{c:V(this,Ti),m:V(this,Ii),y:V(this,Ai),k:V(this,zt)}}};Ti=new WeakMap,Ii=new WeakMap,Ai=new WeakMap,zt=new WeakMap,c(_u,"MAX",1e4);var Du=_u;function Wi(e){return e instanceof vt?Math.max(0,Math.min(1,e.num)):e instanceof F&&e.unit==="%"?Math.max(0,Math.min(1,e.num/100)):null}function zu(e){if(e.name!=="device-cmyk"&&e.name!=="cmyk")return null;let t=e.values.length===1&&e.values[0]instanceof te?e.values[0].values:e.values;if(t.length<4||t.length>6)return null;let i=Wi(t[0]),n=Wi(t[1]),r=Wi(t[2]),s=Wi(t[3]);if(i===null||n===null||r===null||s===null)return null;let o=null;if(t.length>=5){if(t[4]===Tn){if(t.length!==6)return null;o=Wi(t[5])}else{if(t.length!==5)return null;o=Wi(t[4])}if(o===null)return null}return{cmyk:Du.fromNumber(i,n,r,s),alpha:o}}function*Uf(e){for(let t=-e;t<=e;t++)for(let i=-e;i<=e;i++)for(let n=-e;n<=e;n++)Math.abs(t)+Math.abs(i)+Math.abs(n)===e&&(yield[t,i,n])}var ui,ds,Vu,Rl,Uu=class{constructor(){ne(this,ds),ne(this,ui,new Map)}registerDeviceCmyk(e){let t=zu(e);return t?Ce(this,ds,Vu).call(this,t.cmyk).toColorFunc(t.alpha):null}registerCmykReserveMap(e){for(let[t,i]of e){let n=Zt.fromInt(t.r,t.g,t.b),r=Du.fromInt(i.c,i.m,i.y,i.k);V(this,ui).set(n.toKey(),r)}}toJSON(){let e={};return V(this,ui).forEach((t,i)=>{e[i]=t.toJSON()}),e}};ui=new WeakMap,ds=new WeakSet,Vu=function(e){let t=e.toSRGB(),i=t.toKey(),n=V(this,ui).get(i);return n?n.equals(e)?t:Ce(this,ds,Rl).call(this,e,t):(V(this,ui).set(i,e),t)},Rl=function(e,t){for(let i=1;i<=Zt.MAX;i++)for(let[n,r,s]of Uf(i)){let o=t.offset(n,r,s),a=o.toKey();if(!V(this,ui).has(a))return V(this,ui).set(a,e),o}return W.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(e.toJSON())}`),t};var $r,zn,Vn,Hu=class extends Vi{constructor(e){super(),ne(this,$r),ne(this,zn,new Map),ne(this,Vn,!1),Oe(this,$r,e??new Uu)}reset(){Oe(this,Vn,!1)}hadDeviceCmyk(){return V(this,Vn)}recordConversion(e,t){V(this,zn).set(e,t)}getConversions(){if(V(this,zn).size===0)return null;let e={};return V(this,zn).forEach((t,i)=>{e[i]=t}),e}visitFunc(e){let t=V(this,$r).registerDeviceCmyk(e);return t?(Oe(this,Vn,!0),t):super.visitFunc(e)}};$r=new WeakMap,zn=new WeakMap,Vn=new WeakMap;function $u(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function Hf(e){return`^${e}`}function Fl(e){return e.replace(/[\[\]\(\),=;^]/g,Hf)}function $f(e){return e.substr(1)}function To(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,$f)}function Wf(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=To(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function Ll(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=Wf(i[2]),e=e.substr(i[0].length)}return t}var Ol=class{appendTo(e){e.append("!")}applyTo(e){return!1}},Bl=class{constructor(e,t,i){this.index=e,this.id=t,this.sideBias=i}appendTo(e){e.append("/"),e.append(this.index.toString()),(this.id||this.sideBias)&&(e.append("["),this.id&&e.append(this.id),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}applyTo(e){if(e.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let t=e.node,i=t.children,n=i.length,r,s=Math.floor(this.index/2)-1;if(s<0||n==0)r=t.firstChild,e.node=r||t;else{if(r=i[Math.min(s,n-1)],this.index&1){let o=r.nextSibling;!o||o.nodeType==1?e.after=!0:r=o}e.node=r}if(this.id&&(e.after||this.id!=$u(e.node))){let o=t.ownerDocument.getElementById(this.id);o?e.node=o:W.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},Ml=class{constructor(e,t,i,n){this.offset=e,this.textBefore=t,this.textAfter=i,this.sideBias=n}applyTo(e){if(this.offset>0&&!e.after){let t=this.offset,i=e.node;for(;;){let n=i.nodeType;if(n==1)break;let r=i.nextSibling;if(3<=n&&n<=5){let s=i.textContent.length;if(t<=s)break;if(!r){t=s;break}t-=s}if(!r){t=0;break}i=r}e.node=i,e.offset=t}return e.sideBias=this.sideBias,!0}appendTo(e){e.append(":"),e.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(e.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&e.append(Fl(this.textBefore)),e.append(","),this.textAfter&&e.append(Fl(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},_l=class Wu{constructor(){c(this,"steps",null)}fromString(t){let i=t.match(/^#?epubcfi\((.*)\)$/);if(!i)throw new Error("E_CFI_NOT_CFI");let n=decodeURIComponent(i[1]),r=0,s=[];for(;;){let o;switch(n.charAt(r)){case"/":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[3];o=Ll(i[4]),s.push(new Bl(a,h,xl(o.s)));break}case":":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[4];h&&(h=To(h));let l=i[7];l&&(l=To(l)),o=Ll(i[10]),s.push(new Ml(a,h,l,xl(o.s)));break}case"!":r++,s.push(new Ol);break;case"~":case"@":case"":this.steps=s;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let i={node:t.documentElement,offset:0,after:!1,sideBias:null,ref:null};for(let n=0;n<this.steps.length;n++)if(!this.steps[n].applyTo(i)){i.ref=new Wu,i.ref.steps=this.steps.slice(n+1);break}return i}trim(t,i){return t.replace(/\s+/g," ").match(i?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,i,n,r){let s=[],o=t.parentNode,a="",h="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let l=t.textContent,u=l.length;n?(i+=u,a||(a=l)):(i>u&&(i=u),n=!0,a=l.substr(0,i),h=l.substr(i)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((i>0||a||h)&&(a=this.trim(a,!1),h=this.trim(h,!0),s.push(new Ml(i,a,h,r)),r=null);o&&!(!o||o.nodeType==9);){let l=n?null:$u(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;s.push(new Bl(u,l,r)),r=null,t=o,o=o.parentNode,n=!1}s.reverse(),this.steps?(s.push(new Ol),this.steps=s.concat(this.steps)):this.steps=s}toString(){if(!this.steps)return"";let t=new ii;t.append("epubcfi(");for(let i=0;i<this.steps.length;i++)this.steps[i].appendTo(t);return t.append(")"),t.toString().replace(/%/g,"%25")}},Ct=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},di=class{constructor(e,t){this.x=e,this.y=t}},io=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},Dl=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},Qt=class{constructor(e,t,i,n){this.y1=e,this.y2=t,this.x1=i,this.x2=n,c(this,"left",null),c(this,"right",null)}};function Gf(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var _s=class Gu{constructor(t){this.points=t}addSegments(t,i){let n=this.points,r=n.length,s=n[r-1];for(let o=0;o<r;o++){let a=n[o],h;s.y<a.y?h=new Dl(s,a,1,i):h=new Dl(a,s,-1,i),t.push(h),s=a}}withOffset(t,i){let n=[];for(let r of this.points)n.push(new di(r.x+t,r.y+i));return new Gu(n)}};function zl(e,t,i,n){let r=[];for(let s=0;s<20;s++){let o=s*2*Math.PI/20;r.push(new di(e+i*Math.sin(o),t+n*Math.cos(o)))}return new _s(r)}function Ma(e,t,i,n){return new _s([new di(e,t),new di(i,t),new di(i,n),new di(e,n)])}var Rr=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function Vl(e,t){let i=e.low.x+(e.high.x-e.low.x)*(t-e.low.y)/(e.high.y-e.low.y);if(isNaN(i))throw new Error("Bad intersection");return i}function jf(e,t,i,n){let r,s,o,a;t.high.y<i&&W.warn("Error: inconsistent segment (1)"),t.low.y<=i?(r=Vl(t,i),s=t.winding):(r=t.low.x,s=0),t.high.y>=n?(o=Vl(t,n),a=t.winding):(o=t.high.x,a=0),r<o?(e.push(new Rr(r,s,t.shapeId,-1)),e.push(new Rr(o,a,t.shapeId,1))):(e.push(new Rr(o,a,t.shapeId,-1)),e.push(new Rr(r,s,t.shapeId,1)))}function Xf(e,t,i){let n=t+i,r=Array(n),s=Array(n),o;for(o=0;o<=n;o++)r[o]=0,s[o]=0;let a=[],h=!1,l=e.length;for(let u=0;u<l;u++){let d=e[u];r[d.shapeId]+=d.winding,s[d.shapeId]+=d.lowOrHigh;let p=!1;for(o=0;o<t;o++)if(r[o]&&!s[o]){p=!0;break}if(p){for(o=t;o<=n;o++)if(r[o]||s[o]){p=!1;break}}h!=p&&(a.push(d.x),h=p)}return a}function qf(e,t){return t?Math.ceil(e/t)*t:e}function Ul(e,t){return t?Math.floor(e/t)*t:e}function Yf(e){return new di(e.y,-e.x)}function ps(e){return new Ct(e.y1,-e.x2,e.y2,-e.x1)}function ju(e){return new Ct(-e.y2,e.x1,-e.y1,e.x2)}function Hl(e){return new _s(e.points.map(t=>Yf(t)))}function Zf(e,t,i,n,r,s){s&&(e=ps(e),t=t.map(x=>Hl(x)),i=i.map(x=>Hl(x)));let o=t.length,a=i?i.length:0,h=[],l=[],u,d,p;for(u=0;u<o;u++)t[u].addSegments(l,u);for(u=0;u<a;u++)i[u].addSegments(l,u+o);let f=l.length;l.sort(Gf);let g=0;for(;l[g].shapeId>=o;)g++;let m=l[g].low.y;m>e.y1&&h.push(new Qt(e.y1,m,e.x2,e.x2));let w=0,b=[];for(;w<f&&(p=l[w]).low.y<m;)p.high.y>m&&b.push(p),w++;for(;w<f||b.length>0;){let x=e.y2,y=Math.min(qf(Math.ceil(m+n),r),e.y2);for(d=0;d<b.length&&x>y;d++)p=b[d],p.low.x==p.high.x?p.high.y<x&&(x=Math.max(Ul(p.high.y,r),y)):p.low.x!=p.high.x&&(x=y);for(x>e.y2&&(x=e.y2);w<f&&(p=l[w]).low.y<x;){if(p.high.y<m){w++;continue}if(p.low.y<y)p.low.y==p.high.y&&p.low.y==m||(b.push(p),x=y),w++;else{let R=Ul(p.low.y,r);R<x&&(x=R);break}}let P=[];for(d=0;d<b.length;d++)jf(P,b[d],m,x);P.sort((R,A)=>R.x-A.x||R.lowOrHigh-A.lowOrHigh);let S=Xf(P,o,a);if(S.length==0)h.push(new Qt(m,x,e.x2,e.x2));else{let R=0,A=e.x1;for(d=0;d<S.length;d+=2){let U=Math.max(e.x1,S[d]),G=Math.min(e.x2,S[d+1])-U;G>R&&(R=G,A=U)}R==0?h.push(new Qt(m,x,e.x2,e.x2)):h.push(new Qt(m,x,Math.max(A,e.x1),Math.min(A+R,e.x2)))}if(x==e.y2)break;for(m=x,d=b.length-1;d>=0;d--)b[d].high.y<=x&&b.splice(d,1)}return Xu(e,h),h}function Xu(e,t){let i=t.length-1,n=new Qt(e.y2,e.y2,e.x1,e.x2);for(;i>=0;){let r=n;n=t[i],(n.y2-n.y1<1||n.x1==r.x1&&n.x2==r.x2)&&(r.y1=n.y1,t.splice(i,1),n=r),i--}}function qu(e,t){let i=0,n=e.length;for(;i<n;){let r=Math.floor((i+n)/2);t>=e[r].y2?i=r+1:n=r}return i}function Kf(e,t){if(!e.length)return t;let i=t.y1,n,r;for(r=0;r<e.length&&(n=e[r],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));r++)i=Math.max(i,n.y2);let s=i;for(;r<e.length&&(n=e[r],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));r++)s=n.y2;return r===e.length?s=t.y2:s=Math.min(s,t.y2),s<=i?null:new Ct(t.x1,i,t.x2,s)}function Jf(e,t){if(!e.length)return t;let i=t.y2,n,r;for(r=e.length-1;r>=0&&(n=e[r],!(r===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);r--)i=Math.min(i,n.y1);let s=Math.min(i,n.y2);for(;r>=0&&(n=e[r],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));r--)s=n.y1;return s=Math.max(s,t.y1),i<=s?null:new Ct(t.x1,s,t.x2,i)}function Qf(e,t,i,n){let r=i.y1,s=i.x2-i.x1,o=i.y2-i.y1,a=qu(t,r);for(;;){let h=r+o;if(h>e.y2)return!1;let l=e.x1,u=e.x2;for(let d=a;d<t.length&&t[d].y1<h;d++){let p=t[d];p.x1>l&&(l=p.x1),p.x2<u&&(u=p.x2)}if(l+s<=u||a>=t.length)return n=="left"?(i.x1=l,i.x2=l+s):(i.x1=u-s,i.x2=u),i.y2+=r-i.y1,i.y1=r,!0;r=t[a].y2,a++}}function eg(e,t,i,n,r){for(n||(n=[new Qt(i.y1,i.y2,i.x1,i.x2)]);n.length>0&&n[0].y2<=e.y1;)n.shift();if(n.length==0)return;n[0].y1<e.y1&&(n[0].y1=e.y1);let s,o=t.length==0?e.y1:t[t.length-1].y2;o<e.y2&&t.push(new Qt(o,e.y2,e.x1,e.x2));let a=qu(t,n[0].y1);for(let h of n){if(a==t.length)break;for(t[a].y1<h.y1&&(s=t[a],a++,t.splice(a,0,new Qt(h.y1,s.y2,s.x1,s.x2)),s.y2=h.y1);a<t.length&&(s=t[a++],s.y2>h.y2&&(t.splice(a,0,new Qt(h.y2,s.y2,s.x1,s.x2)),s.y2=h.y2),h.x1!=h.x2&&(r=="left"?s.x1=Math.min(h.x2,e.x2):s.x2=Math.max(h.x1,e.x1)),s.y2!=h.y2););}Xu(e,t)}var tg=class extends oi{constructor(){super(),c(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function ig(e){if(e){let t=new tg;try{return e.visit(t),t.propSet}catch(i){W.warn(i,"toSet:")}}return{}}var ng=class extends oi{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function $l(e,t){if(e){let i=new ng(t);try{return e.visit(i),i.value}catch(n){W.warn(n,"toInt: ")}}return t}var rg=class extends oi{constructor(){super(),c(this,"collect",!1),c(this,"coords",[]),c(this,"name",null)}visitNumeric(e){return this.collect&&this.coords.push(e),null}visitNum(e){return this.collect&&e.num==0&&this.coords.push(new F(0,"px")),null}visitSpaceList(e){return this.visitValues(e.values),null}visitFunc(e){return this.collect||(this.collect=!0,this.visitValues(e.values),this.collect=!1,this.name=e.name.toLowerCase()),null}getShape(e,t,i,n,r){if(this.coords.length>0){let s=[];switch(this.coords.forEach((o,a)=>{if(o.unit=="%"){let h=a%2==0?i:n;a==3&&this.name=="circle"&&(h=Math.sqrt((i*i+n*n)/2)),s.push(o.num*h/100)}else s.push(o.num*r.queryUnitSize(o.unit,!1))}),this.name){case"polygon":if(s.length%2==0){let o=[];for(let a=0;a<s.length;a+=2)o.push(new di(e+s[a],t+s[a+1]));return new _s(o)}break;case"rectangle":if(s.length==4)return Ma(e+s[0],t+s[1],e+s[0]+s[2],t+s[1]+s[3]);break;case"ellipse":if(s.length==4)return zl(e+s[0],t+s[1],s[2],s[3]);break;case"circle":if(s.length==3)return zl(e+s[0],t+s[1],s[2],s[2]);break}}return null}};function Yu(e,t,i,n,r,s){if(e){let o=new rg;try{return e.visit(o),o.getShape(t,i,n,r,s)}catch(a){W.warn(a,"toShape:")}}return Ma(t,i,t+n,i+r)}var sg=class extends oi{constructor(e,t){super(),this.reset=e,this.defaultValue=t,c(this,"counters",Object.create(null)),c(this,"name",null)}visitIdent(e){return this.name=e.toString(),this.reset?this.counters[this.name]=0:this.counters[this.name]=(this.counters[this.name]||0)+this.defaultValue,e}visitInt(e){return this.name&&(this.counters[this.name]+=e.num-(this.reset?0:this.defaultValue)),e}visitSpaceList(e){return this.visitValues(e.values),e}};function fn(e,t){var i,n;let r=(i=t?.reset)!=null?i:!1,s=(n=t?.defaultValue)!=null?n:r?0:1,o=new sg(r,s);try{e.visit(o)}catch(a){W.warn(a,"toCounters:")}return o.counters}var og=class extends Vi{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new ot(this.transformer.transformURL(e.url,this.baseUrl))}};function Ci(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function ag(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(t,i,n)=>i?String.fromCodePoint(parseInt(i,16)):n)}function sn(e,t){var i,n;if(t==="content"){let r=e.cloneNode(!0);return r.querySelectorAll("[data-adapt-pseudo]").forEach(s=>s.remove()),r.textContent||""}else if(t==="marker"){let r=e.querySelector('[data-adapt-pseudo="marker"], [data-adapt-pseudo="footnote-marker"]');if(r)return r.textContent||"";let s=(n=(i=e.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(e))==null?void 0:n.getPropertyValue("--viv-marker-content");if(s){let o=s.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(o&&o.length>0)return o.map(a=>ag(a.substring(1,a.length-1))).join("")}return""}else{let r=e.querySelector(`[data-adapt-pseudo="${t}"]`);return r&&r.textContent||""}}var lg=class{constructor(e,t){this.targetId=e,this.resolved=t,c(this,"pageCounters",null),c(this,"spineIndex",-1),c(this,"pageIndex",-1)}equals(e){return this===e?!0:e?this.targetId===e.targetId&&this.resolved===e.resolved&&this.spineIndex===e.spineIndex&&this.pageIndex===e.pageIndex:!1}isResolved(){return this.resolved}resolve(){this.resolved=!0}unresolve(){this.resolved=!1}},hg=class{constructor(e,t){this.counterStore=e,this.baseURL=t}countersOfId(e,t){e=this.counterStore.documentURLTransformer.transformFragment(e,this.baseURL),this.counterStore.countersById[e]=t}getExprContentListener(){return this.counterStore.getExprContentListener()}},ug=class{constructor(e,t,i,n){this.counterStore=e,this.baseURL=t,this.rootScope=i,this.pageScope=n,c(this,"styler",null),c(this,"namedStringValues",Object.create(null)),c(this,"runningElements",Object.create(null))}setStyler(e){this.styler=e}getFragment(e){let t=e.match(/^[^#]*#(.*)$/);return t?t[1]:null}getTransformedId(e){let t=this.counterStore.documentURLTransformer.transformURL(Ee(e,this.baseURL),this.baseURL);return t.charAt(0)==="#"&&(t=t.substring(1)),t}getPageCounterVal(e,t){let i=()=>{let s=this.counterStore.currentPageCounters[e];return s&&s.length?s[s.length-1]:null},n=new Ie(this.pageScope,()=>t(i()),`page-counter-${e}`),r=s=>t(s[s.length-1]);return this.counterStore.registerPageCounterExpr(e,r,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new Ie(this.pageScope,()=>t(i()),`page-counters-${e}`);return this.counterStore.registerPageCounterExpr(e,t,n),n}getTargetCounters(e,t,i){let n=this.counterStore.countersById[t];return!n&&i&&e&&(this.styler.styleUntilIdIsReached(e),n=this.counterStore.countersById[t]),n||null}getTargetPageCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageCounters:this.counterStore.pageCountersById[e]||null}getTargetPageDocCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageDocCounters:this.counterStore.pageDocCountersById[e]||null}adjustCountersForCrossScope(e,t,i,n){if(!this.counterStore.isPageControlledCounter(e)||!i)return t;let r=i[e]||[],s=r.length?r[r.length-1]:0,o=n?.[e]||[],a=o.length?o[0]:0;return t.length?[s+(t[0]-a),...t.slice(1)]:[s]}getTargetPageText(e,t){if(this.counterStore.currentPage.elementsById[e]){let i=this.counterStore.currentPage.elementsById[e];if(i&&i.length>0){let n=i[0];return t==="before"||t==="after"||t==="marker"?sn(n,t):sn(n,"content")}return""}else{if(e in this.counterStore.pageTextById){let i=this.counterStore.pageTextById[e];return i[t]!==void 0?i[t]:i.content||""}return null}}getTargetCounterVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e),s=new Ie(this.pageScope,()=>{let o=this.getTargetCounters(n,r,!0);if(o)if(o[t]){let a=o[t],h=this.getTargetPageCounters(r),l=this.getTargetPageDocCounters(r),u=this.adjustCountersForCrossScope(t,a,h,l);return h&&this.counterStore.resolveReference(r),i(u[u.length-1]||null)}else{let a=this.getTargetPageCounters(r);if(a)if(this.counterStore.resolveReference(r),a[t]){let h=a[t];return i(h[h.length-1]||null)}else return i(0);else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counter-${t}-of-${e}`);return this.counterStore.registerTargetCounterExpr(t,i,s,r),s}getTargetCountersVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e);return new Ie(this.pageScope,()=>{let s=this.getTargetPageCounters(r);if(s){this.counterStore.resolveReference(r);let o=this.getTargetCounters(n,r,!0),a=o?.[t]||[],h=this.getTargetPageDocCounters(r),l=this.adjustCountersForCrossScope(t,a,s,h);if(l.length)return i(l);let u=s[t]||[];return i(u)}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counters-${t}-of-${e}`)}getTargetTextVal(e,t){let i=this.getTransformedId(e),n=new Ie(this.pageScope,()=>{if(t==="first-letter"){let s=this.getTargetPageText(i,"before"),o=this.getTargetPageText(i,"content"),a=this.getTargetPageText(i,"after");if(s===null&&o===null&&a===null)return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??";let h=(s??"")+(o??"")+(a??"");this.counterStore.resolveReference(i);let l=h.match(cs);return l?l[0]:""}let r=this.getTargetPageText(i,t);return r!==null?(this.counterStore.resolveReference(i),r):(this.counterStore.saveReferenceOfCurrentPage(i,!1),"??")},`target-text-${t}-of-${e}`);return this.counterStore.registerTargetTextExpr(t,n,i),n}getNamedStringVal(e,t){return new Ie(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new Ie(this.pageScope,()=>this.getRunningValue(this.runningElements,e,t),`running-element-${t}-${e}`)}getRunningValue(e,t,i){let n=e[t];if(!n)return"";let r=Object.keys(n).map(p=>parseInt(p,10)).sort(cu),s=this.counterStore.currentPage;if(!s)return"";let o=s.isBlankPage?s.offset-1:s.offset,a=s.isBlankPage?o:Math.max(o,...Array.from(s.container.querySelectorAll(`[${$t}]`)).map(p=>parseInt(p.getAttribute($t),10))),h=-1,l=-1,u=-1,d=-1;for(let p=0;p<r.length;p++){let f=r[p],g=p>0?r[p-1]:-1,m=p<r.length-1?r[p+1]:-1;if(f>a)break;if(f>=o){if(h<0&&(h=f,d=-1),l<0)if(f===o)l=f;else{g<h&&(l=g);let w=s.container.querySelector(`[${$t}="${f}"]`);if(!w)l<0&&(l=f);else{let b=s.container.querySelector(`[${$t}="${o}"]`);if(b||(b=s.container.querySelector(`[${$t}="0"]`)),b){for(let x=b;x;x=x.firstElementChild)if(x===w){l=f;break}}}}u=f}else(m>a||m<0)&&(h=l=u=d=f)}return n[{first:h,start:l,last:u,"first-except":d}[i]]||""}setNamedString(e,t,i){let n=this.namedStringValues[e]||(this.namedStringValues[e]=Object.create(null));n[i]=t}setRunningElement(e,t){let i=this.runningElements[e]||(this.runningElements[e]=Object.create(null));i[t]=String(t)}},cg=class{constructor(e){this.documentURLTransformer=e,c(this,"countersById",Object.create(null)),c(this,"pageCountersById",Object.create(null)),c(this,"pageDocCountersById",Object.create(null)),c(this,"pageTextById",Object.create(null)),c(this,"currentPageDocCounters",null),c(this,"previousPageDocCounters",null),c(this,"currentPageDocCounterChanges",Object.create(null)),c(this,"currentPageDocCounterChangeTypes",Object.create(null)),c(this,"currentPageCounters",Object.create(null)),c(this,"previousPageCounters",Object.create(null)),c(this,"currentPageCountersStack",[]),c(this,"pageIndicesById",Object.create(null)),c(this,"currentPage",null),c(this,"newReferencesOfCurrentPage",[]),c(this,"referencesToSolve",[]),c(this,"referencesToSolveStack",[]),c(this,"unresolvedReferences",Object.create(null)),c(this,"resolvedReferences",Object.create(null)),c(this,"pageControlledCounterNames",Object.assign(Object.create(null),{page:!0})),c(this,"pagesCounterExprs",[]),c(this,"pageCounterExprs",[]),c(this,"targetCounterExprs",[]),c(this,"targetTextExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new hg(this,e)}createCounterResolver(e,t,i){return new ug(this,e,t,i)}setCurrentPage(e){this.currentPage=e}setCurrentPageDocCounters(e,t,i){this.previousPageDocCounters=this.currentPageDocCounters?Ci(this.currentPageDocCounters):null,this.currentPageDocCounters=e?Ci(e):null,this.currentPageDocCounterChanges=Object.create(null),this.currentPageDocCounterChangeTypes=i?{...i}:Object.create(null),t&&t.forEach(n=>{this.currentPageDocCounterChanges[n]=!0})}setPageControlledCounterNames(e){let t=Object.assign(Object.create(null),{page:!0});e.forEach(i=>{t[i]=!0}),this.pageControlledCounterNames=t}isPageControlledCounter(e){return!!this.pageControlledCounterNames[e]}definePageCounter(e,t){this.currentPageCounters[e]?this.currentPageCounters[e].push(t):this.currentPageCounters[e]=[t]}forceSetPageCounter(e){let t=this.currentPageCounters.page;!t||!t.length?this.currentPageCounters.page=[e]:t[t.length-1]=e}updatePageCounters(e,t){this.previousPageCounters=Ci(this.currentPageCounters);let i=this.currentPageDocCounterChanges||{},n=this.currentPageDocCounterChangeTypes||{},r=Object.create(null);if(this.currentPageDocCounters){let g=this.previousPageDocCounters||{};for(let m in this.currentPageDocCounters){if(!i[m])continue;let w=this.currentPageDocCounters[m],b=w.length?w[w.length-1]:0,x=g[m]||[],y=x.length?x[x.length-1]:0,P=b-y,S=n[m],R=S==="reset"||S==="set";r[m]={delta:P,reset:R,value:b}}}let s=Object.create(null),o,a=e["counter-reset"];if(a){let g=a.evaluate(t);g&&(o=fn(g,{reset:!0}))}o&&"pages"in o&&delete o.pages;let h,l=e["counter-set"];if(l){let g=l.evaluate(t);g&&(h=fn(g,{defaultValue:0}))}h&&"pages"in h&&delete h.pages;let u=[];if(o)for(let g in o)u.push(g);if(h)for(let g in h)u.push(g);let d,p=e["counter-increment"];if(p){let g=p.evaluate(t);g&&(d=fn(g))}d&&"pages"in d&&delete d.pages,d?!("page"in d)&&!(r.page&&r.page.reset)&&(d.page=1):(d=Object.create(null),r.page&&r.page.reset||(d.page=1));for(let g in d)u.push(g);this.setPageControlledCounterNames(u);let f=Ci(this.previousPageCounters);if(this.currentPageDocCounters)for(let g in this.currentPageDocCounters){if(this.isPageControlledCounter(g)){let m=r[g];if(m){if(m.reset)f[g]=[m.value],s[g]=!0;else if(m.delta!==0){f[g]||(f[g]=[0]);let w=f[g];w[w.length-1]+=m.delta}}continue}f[g]=Array.from(this.currentPageDocCounters[g])}if(this.currentPageCounters=f,o)for(let g in o)this.definePageCounter(g,o[g]);if(h)for(let g in h)if(!this.currentPageCounters[g])this.definePageCounter(g,h[g]);else{let m=this.currentPageCounters[g];m[m.length-1]=h[g]}for(let g in d){if(s[g])continue;this.currentPageCounters[g]||this.definePageCounter(g,0);let m=this.currentPageCounters[g];m[m.length-1]+=d[g]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=Ci(e)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(e){let t=this.unresolvedReferences[e],i=this.resolvedReferences[e];i||(i=this.resolvedReferences[e]=[]);let n=!1;for(let r=0;r<this.referencesToSolve.length;){let s=this.referencesToSolve[r];if(s.targetId===e){if(s.resolve(),this.referencesToSolve.splice(r,1),t){let o=t.indexOf(s);o>=0&&t.splice(o,1)}i.push(s),n=!0}else r++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new lg(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let s=Ci(this.currentPageCounters),o=this.currentPageDocCounters?Ci(this.currentPageDocCounters):null;i.forEach(a=>{this.pageCountersById[a]=s,o&&(this.pageDocCountersById[a]=o);let h=this.currentPage.elementsById[a];if(h&&h.length>0){let u=h[0];this.pageTextById[a]={content:sn(u,"content"),before:sn(u,"before"),after:sn(u,"after"),marker:sn(u,"marker")}}let l=this.pageIndicesById[a];if(l&&l.pageIndex<t){let u=this.resolvedReferences[a];if(u){let d=this.unresolvedReferences[a];d||(d=this.unresolvedReferences[a]=[]);let p;for(;p=u.shift();)p.unresolve(),d.push(p)}}this.pageIndicesById[a]={spineIndex:e,pageIndex:t}})}let n=this.previousPageCounters,r;for(;r=this.newReferencesOfCurrentPage.shift();){r.pageCounters=n,r.spineIndex=e,r.pageIndex=t;let s;r.isResolved()?(s=this.resolvedReferences[r.targetId],s||(s=this.resolvedReferences[r.targetId]=[])):(s=this.unresolvedReferences[r.targetId],s||(s=this.unresolvedReferences[r.targetId]=[])),s.every(o=>!r.equals(o))&&s.push(r)}this.currentPage=null}adjustPageCountersOfLaterSpines(e,t){if(t<=0)return;let i=new Set;for(let n of Object.keys(this.pageIndicesById))if(this.pageIndicesById[n].spineIndex>e){let r=this.pageCountersById[n];r&&r.page&&!i.has(r)&&(i.add(r),r.page=r.page.map(s=>s+t))}}updateTargetCounterNodesInPages(e){for(let t of e){if(!t||!t.container)continue;let i=t.container.querySelectorAll(`[${On}]`);for(let n of i){let r=n.getAttribute(On),s=this.targetCounterExprs.find(o=>o.expr.key===r);if(s&&s.transformedId){let o=this.pageCountersById[s.transformedId];if(o){let a=o[s.name];a&&(n.textContent=s.format(a[a.length-1]))}}}}}getPageCountersForPage(e,t){let i=Object.keys(e.elementsById);for(let n of i){let r=this.pageCountersById[n];if(r)return r}return t||null}updatePageCounterNodesInPages(e,t){var i;for(let n=0;n<e.length;n++){let r=e[n];if(!(r!=null&&r.container))continue;let s=this.getPageCountersForPage(r,t?.[n]);if(!s)continue;let o=r.container.querySelectorAll(`[${Ln}]`);for(let a of o){let h=a.getAttribute(Ln),l=this.pageCounterExprs.find(f=>f.expr.key===h);if(!l)continue;let u=(i=l.expr)==null?void 0:i.str,d=u?.replace(/^page-counters?-/,""),p=s[d];p&&(a.textContent=l.format(p))}}}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(r=>{let s=this.unresolvedReferences[r];s&&(t=t.concat(s))}),t.sort((r,s)=>r.spineIndex-s.spineIndex||r.pageIndex-s.pageIndex);let i=[],n=null;return t.forEach(r=>{!n||n.spineIndex!==r.spineIndex||n.pageIndex!==r.pageIndex?(n={spineIndex:r.spineIndex,pageIndex:r.pageIndex,pageCounters:r.pageCounters,refs:[r]},i.push(n)):n.refs.push(r)}),i}pushReferencesToSolve(e){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=e}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(e,t,i){e==="pages"?this.pagesCounterExprs.push({expr:i,format:t}):this.pageCounterExprs.push({expr:i,format:t})}registerTargetCounterExpr(e,t,i,n){this.targetCounterExprs.push({name:e,expr:i,format:t,transformedId:n})}registerTargetTextExpr(e,t,i){this.targetTextExprs.push({pseudoElement:e,expr:t,transformedId:i})}getExprContentListener(){return this.exprContentListener.bind(this)}exprContentListener(e,t,i){if(e instanceof Ie){if(e.str=="viv-leader"){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute("data-viv-leader",e.key),s.setAttribute("data-viv-leader-value",t),s}else if(e.str.startsWith("running-element-")){let s=t&&i.querySelectorAll(`[${$t}="${t}"]`);if(!s||s.length===0)return null;let o=s[s.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(o),o.style.position="",o.style.visibility="",o}else if(e.str.startsWith("target-counter-")){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(On,e.key),s}else if(e.str.startsWith("target-text-")){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(ro,e.key),s}}let n=this.pagesCounterExprs.findIndex(s=>s.expr===e)>=0,r=!n&&this.pageCounterExprs.findIndex(s=>s.expr===e)>=0;if(n||r){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(n?no:Ln,e.key),s}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${Ln}]`);for(let r of t){let s=r.getAttribute(Ln),o=this.pageCounterExprs.find(u=>u.expr.key===s),a=(o?.expr).str,h=a?.replace(/^page-counters?-/,""),l=this.currentPageCounters[h];l&&(r.textContent=o.format(l))}let i=e.querySelectorAll(`[${On}]`);for(let r of i)r.setAttribute(Wl,!0);let n=e.querySelectorAll(`[${ro}]`);for(let r of n)r.setAttribute(Gl,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${no}]`),n=e.contentContainer.childElementCount;for(let o of i){let a=o.getAttribute(no),h=this.pagesCounterExprs.findIndex(l=>l.expr.key===a);h>=0,o.textContent=this.pagesCounterExprs[h].format([n])}let r=e.root.querySelectorAll(`[${Wl}]`);for(let o of r){let a=o.getAttribute(On),h=this.targetCounterExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageCountersById[h.transformedId];if(l){let u=l[h.name];u&&(o.textContent=h.format(u[u.length-1]))}}}let s=e.root.querySelectorAll(`[${Gl}]`);for(let o of s){let a=o.getAttribute(ro),h=this.targetTextExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageTextById[h.transformedId];l&&(o.textContent=(t=l[h.pseudoElement])!=null?t:"")}}}createLayoutConstraint(e){return new dg(this,e)}},no="data-vivliostyle-pages-counter",Ln="data-vivliostyle-page-counter",On="data-vivliostyle-target-counter",ro="data-vivliostyle-target-text",Wl="data-vivliostyle-target-counter-in-running",Gl="data-vivliostyle-target-text-in-running",dg=class{constructor(e,t){this.counterStore=e,this.pageIndex=t}allowLayout(e){if(!e||e.after)return!0;let t=e.viewNode;if(!t||t.nodeType!==1)return!0;let i=t.getAttribute("data-vivliostyle-id")||t.getAttribute("id")||t.getAttribute("name");if(!i||!this.counterStore.resolvedReferences[i]&&!this.counterStore.unresolvedReferences[i])return!0;let n=this.counterStore.pageIndicesById[i];return n?this.pageIndex>=n.pageIndex:!0}};function pg(e){if(e=e.substr(1),e.match(/^[^0-9a-fA-F\n\r]$/))return e;let t=parseInt(e,16);return isNaN(t)?"":t===0||t>=55296&&t<=57343||t>1114111?"\uFFFD":String.fromCodePoint(t)}function ki(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,pg)}var fg=class{constructor(){c(this,"type"),c(this,"precededBySpace",!1),c(this,"num",0),c(this,"text",""),c(this,"position",0),this.type=0}toString(){switch(this.type){case 10:return"(";case 11:return")";case 12:return"{";case 13:return"}";case 14:return"[";case 15:return"]";case 16:return",";case 17:return";";case 18:return":";case 19:return"/";case 21:return"%";case 22:return"?";case 23:return"+";case 24:return"-";case 25:return"||";case 26:return"&&";case 31:return"!";case 32:return"$";case 33:return"^";case 34:return"|";case 35:return"~";case 36:return"*";case 37:return">";case 38:return"<";case 39:return"=";case 41:return"!=";case 42:return"$=";case 43:return"^=";case 44:return"|=";case 45:return"~=";case 46:return"*=";case 47:return">=";case 48:return"<=";case 49:return"==";case 50:return"::";case 51:return"<!--";case 52:return"-->";case 3:return this.num.toString()+this.text;case 4:case 5:return this.num.toString();case 20:return"@"+this.text;case 7:return"#"+this.text;case 6:return this.text+"(";case 9:return"."+this.text;case 0:return"/*EOF*/";default:return this.text}}};function Xe(e,t){let i=Array(128),n;for(n=0;n<128;n++)i[n]=e;for(i[NaN]=e==35?35:72,n=0;n<t.length;n+=2)i[t[n]]=t[n+1];return i}var Yt=[72,72,72,72,72,72,72,72,72,1,1,72,1,1,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,1,4,34,6,7,8,9,33,10,11,12,13,14,15,16,17,2,2,2,2,2,2,2,2,2,2,18,19,20,21,22,23,24,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,25,29,26,30,3,72,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,27,31,28,32,72];Yt[NaN]=80;var Vt=[43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,52,43,43,43,43,39,43,43,39,39,39,39,39,39,39,39,39,39,43,43,43,43,43,43,43,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,43,44,43,43,39,43,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,43,43,43,43,43];Vt[NaN]=43;var gg=[72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,78,59,72,59,59,59,59,59,59,59,59,59,59,72,72,72,72,72,72,72,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,72,61,72,72,78,72,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,72,72,72,72,72];Vt[NaN]=43;var Zu=[35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,57,59,35,58,58,58,58,58,58,58,58,58,58,35,35,35,35,35,35,35,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,35,61,35,35,60,35,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,35,35,35,35,35];Zu[NaN]=35;var Ku=[45,45,45,45,45,45,45,45,45,73,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,73,45,45,45,45,45,45,45,53,45,45,45,45,45,45,45,39,39,39,39,39,39,39,39,39,39,45,45,45,45,45,45,45,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,45,44,45,45,39,45,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,45,45,45,45,45];Ku[NaN]=45;var Io=[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,41,37,37,37,37,37,37,37,37,42,37,39,39,39,39,39,39,39,39,39,39,37,37,37,37,37,37,37,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,37,37,37,37,40,37,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,37,37,37,37,37];Io[NaN]=37;var Ao=[38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,41,38,38,38,38,38,38,38,38,38,38,39,39,39,39,39,39,39,39,39,39,38,38,38,38,38,38,38,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,38,38,38,38,40,38,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,38,38,38,38,38];Ao[NaN]=38;var Ei=Xe(35,[61,36]),mg=Xe(35,[58,77]),wg=Xe(35,[61,36,124,50]),yg=Xe(35,[38,51]),bg=Xe(35,[42,54]),vg=Xe(39,[42,55]),xg=Xe(54,[42,55,47,56]),Sg=Xe(62,[62,82]),Cg=Xe(35,[61,36,33,70]),kg=Xe(62,[45,71]),Eg=Xe(63,[45,81]),so=Xe(76,[10,72,13,72]),Pg=Xe(39,[39,46,10,72,13,72,92,48]),Ng=Xe(39,[34,46,10,72,13,72,92,49]),Tg=Xe(39,[39,47,10,74,13,74,92,48]),Ig=Xe(39,[34,47,10,74,13,74,92,49]),jl=Xe(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),Ag=Xe(39,[41,67,9,79,10,79,13,79,32,79,92,75,40,72,91,72,93,72,123,72,125,72,NaN,67]),Rg=Xe(39,[39,68,10,74,13,74,92,75,NaN,67]),Fg=Xe(39,[34,68,10,74,13,74,92,75,NaN,67]),Lg=Xe(72,[9,39,10,39,13,39,32,39,41,69]),Og=15,Xt=class{constructor(e,t){this.input=e,this.handler=t,c(this,"indexMask"),c(this,"buffer"),c(this,"tail",0),c(this,"curr",0),c(this,"position",0),this.indexMask=Og,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new fg}token(){return this.tail==this.curr&&this.fillBuffer(),this.buffer[this.curr]}nthToken(e){return(this.tail-this.curr&this.indexMask)<=e&&this.fillBuffer(),this.buffer[this.curr+e&this.indexMask]}consume(){this.curr=this.curr+1&this.indexMask}fillBuffer(){let e=this.tail,t=this.curr,i=this.indexMask;if(e>=t?t+=i:t--,t==e)throw new Error("F_CSSTOK_INTERNAL");let n=Yt,r=this.input,s=this.position,o=this.buffer,a=0,h=0,l="",u=0,d=!1,p=o[e],f=-9;for(;;){let g=r.charCodeAt(s);switch(n[g]||n[65]){case 72:l=r.substring(h,s),isNaN(g)?a=0:a=54,n=Yt;break;case 1:s++,d=!0;continue;case 2:h=s++,n=Io;continue;case 3:a=1,h=s++,n=Vt;continue;case 4:h=s++,a=31,n=Ei;continue;case 33:a=2,h=++s,n=Pg;continue;case 34:a=2,h=++s,n=Ng;continue;case 6:h=++s,a=7,n=Vt;continue;case 7:h=s++,a=32,n=Ei;continue;case 8:h=s++,a=21;break;case 9:h=s++,a=32,n=yg;continue;case 10:h=s++,a=10;break;case 11:h=s++,a=11;break;case 12:h=s++,a=36,n=Ei;continue;case 13:h=s++,a=23;break;case 14:h=s++,a=16;break;case 15:a=24,h=s++,n=Zu;continue;case 16:h=s++,n=gg;continue;case 78:h=s++,a=9,n=Vt;continue;case 17:h=s++,a=19,n=bg;continue;case 18:h=s++,a=18,n=mg;continue;case 77:s++,a=50;break;case 19:h=s++,a=17;break;case 20:h=s++,a=38,n=Cg;continue;case 21:h=s++,a=39,n=Ei;continue;case 22:h=s++,a=37,n=Ei;continue;case 23:h=s++,a=22;break;case 24:h=++s,a=20,n=Vt;continue;case 25:h=s++,a=14;break;case 26:h=s++,a=15;break;case 27:h=s++,a=12;break;case 28:h=s++,a=13;break;case 29:h=s++,f=h,a=1,n=so;continue;case 30:h=s++,a=33,n=Ei;continue;case 31:h=s++,a=34,n=wg;continue;case 32:h=s++,a=35,n=Ei;continue;case 35:break;case 36:s++,a=a+41-31;break;case 37:a=5,u=parseInt(r.substring(h,s),10);break;case 38:a=4,u=parseFloat(r.substring(h,s));break;case 39:s++;continue;case 40:a=3,u=parseFloat(r.substring(h,s)),h=s++,n=Vt;continue;case 41:a=3,u=parseFloat(r.substring(h,s)),l="%",h=s++;break;case 42:s++,n=Ao;continue;case 43:if(l=ki(r.substring(h,s)),a===27&&g===63||a===1&&l.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(r.substring(s-1))){a=27,s++;continue}break;case 44:f=s++,n=so;continue;case 45:l=ki(r.substring(h,s));break;case 46:l=r.substring(h,s),s++;break;case 47:l=ki(r.substring(h,s)),s++;break;case 48:f=s,s+=2,n=Tg;continue;case 49:f=s,s+=2,n=Ig;continue;case 50:s++,a=25;break;case 51:s++,a=26;break;case 52:if(l=r.substring(h,s),a==1){if(s++,l.toLowerCase()=="url"){n=jl;continue}a=6}break;case 53:if(l=ki(r.substring(h,s)),a==1){if(s++,l.toLowerCase()=="url"){n=jl;continue}a=6}break;case 54:n=vg,s++;continue;case 55:n=xg,s++;continue;case 56:n=Yt,s++;continue;case 57:n=Sg,s++,r[s]!==">"&&(a=1,n=Vt);continue;case 81:a=51,l=r.substring(h,++s),n=Yt;break;case 82:a=52,l=r.substring(h,++s),n=Yt;break;case 58:a=5,n=Io,s++;continue;case 59:a=4,n=Ao,s++;continue;case 60:a=1,n=Vt,s++;continue;case 61:a=1,n=so,f=s++;continue;case 62:s--;break;case 63:s-=2;break;case 64:h=s++,n=Ag;continue;case 65:h=++s,n=Rg;continue;case 66:h=++s,n=Fg;continue;case 67:a=8,l=ki(r.substring(h,s)),s++;break;case 69:s++;break;case 70:n=kg,s++;continue;case 71:n=Eg,s++;continue;case 79:if(s-f<8&&r.substring(f+1,s+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){s++;continue}case 68:a=8,l=ki(r.substring(h,s)),s++,n=Lg;continue;case 74:if(s++,s-f<9&&r.substring(f+1,s).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,l="E_CSS_UNEXPECTED_NEWLINE",n=Yt;break;case 73:if(s-f<9&&r.substring(f+1,s+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){s++,n=Vt;continue}l=ki(r.substring(h,s));break;case 75:f=s++;continue;case 76:s++,n=Ku;continue;default:if(n!==Yt){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=s,a=0}if(p.type=a,p.precededBySpace=d,p.num=u,p.text=l,p.position=h,e++,e>=t)break;n=Yt,d=!1,p=o[e&i]}this.position=s,this.tail=e&i}},Ue=null,Ro=null;function Fo(){return Ue}function M(e){if(!Ue)throw new Error("E_TASK_NO_CONTEXT");Ue.name||(Ue.name=e);let t=Ue,i=new Ds(t,t.top,e);return t.top=i,i.state=1,i}function Bg(e){return new Dg(e||new _g)}function N(e){return new Lo(e)}function bn(e,t,i){let n=M(e);n.handler=i;try{t(n)}catch(r){n.task.raise(r,n)}return n.result()}function Mg(e,t){return(Ue?Ue.getScheduler():Ro||Bg()).run(e,t)}var _g=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Dg=class{constructor(e){this.timer=e,c(this,"timeout",1),c(this,"slice",25),c(this,"sliceOverTime",0),c(this,"queue"),c(this,"wakeupTime",null),c(this,"timeoutToken",null),c(this,"inTimeSlice",!1),c(this,"order",0),this.queue=new pf,Ro||(Ro=this)}setSlice(e){this.slice=e}setTimeout(e){this.timeout=e}isTimeSliceOver(){return this.timer.currentTime()>=this.sliceOverTime}arm(){if(this.inTimeSlice)return;let e=this.queue.peek().scheduledTime,t=this.timer.currentTime();if(this.timeoutToken!=null){if(t+this.timeout>this.wakeupTime)return;this.timer.clearTimeout(this.timeoutToken)}let i=e-t;i<=this.timeout&&(i=this.timeout),this.wakeupTime=t+i,this.timeoutToken=this.timer.setTimeout(()=>{this.timeoutToken=null,this.doTimeSlice()},i)}schedule(e,t){let i=e,n=this.timer.currentTime();i.order=this.order++,i.scheduledTime=n+(t||0),this.queue.add(i),this.arm()}doTimeSlice(){this.timeoutToken!=null&&(this.timer.clearTimeout(this.timeoutToken),this.timeoutToken=null),this.inTimeSlice=!0;try{let e=this.timer.currentTime();for(this.sliceOverTime=e+this.slice;this.queue.length();){let t=this.queue.peek();if(t.scheduledTime>e||(this.queue.remove(),t.canceled||t.resumeInternal(),e=this.timer.currentTime(),e>=this.sliceOverTime))break}}catch(e){W.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new zg(this,t||"");i.top=new Ds(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let r=()=>{i.running=!1;for(let s of i.callbacks)try{s()}catch(o){W.error(o)}};try{e().then(s=>{i.result=s,r()})}catch(s){i.raise(s),r()}});let n=Ue;return Ue=i,this.schedule(i.top.suspend("bootstrap")),Ue=n,i}},Ju=class{constructor(e){this.task=e,c(this,"scheduledTime",0),c(this,"order",0),c(this,"result",null),c(this,"canceled",!1)}compare(e){let t=e;return t.scheduledTime-this.scheduledTime||t.order-this.order}getTask(){return this.task}schedule(e,t){this.result=e,this.task.scheduler.schedule(this,t)}resumeInternal(){let e=this.task;if(this.task=null,e&&e.continuation==this){e.continuation=null;let t=Ue;return Ue=e,e.top.finish(this.result),Ue=t,!0}return!1}cancel(){this.canceled=!0}},zg=class{constructor(e,t){this.scheduler=e,this.name=t,c(this,"callbacks",[]),c(this,"exception",null),c(this,"running",!0),c(this,"result",null),c(this,"waitTarget",null),c(this,"top",null),c(this,"continuation",null)}getName(){return this.name}interrupt(e){if(this.raise(e||new Error("E_TASK_INTERRUPT")),this!==Ue&&this.continuation){this.continuation.cancel();let t=new Ju(this);this.waitTarget="interrupt",this.continuation=t,this.scheduler.schedule(t)}}getScheduler(){return this.scheduler}isRunning(){return this.running}whenDone(e){this.callbacks.push(e)}join(){let e=M("Task.join");if(!this.running)e.finish(this.result);else{let t=e.suspend(this);this.whenDone(()=>{t.schedule(this.result)})}return e.result()}unwind(){for(;this.top&&!this.top.handler;)this.top=this.top.parent;if(this.top&&this.top.handler&&this.exception){let e=this.exception;this.exception=null,this.top.handler(this.top,e)}else this.exception&&W.error(this.exception,"Unhandled exception in task",this.name)}raise(e,t){if(this.fillStack(e),t){let i=this.top;for(;i&&i!=t;)i=i.parent;i==t&&(this.top=i)}this.exception=e,this.unwind()}fillStack(e){let t=e.frameTrace;if(!t){t=e.stack?`${e.stack}
3
+ `]).concat(i))),n}var j=new qf,Yo=(e=>(e.SIMPLE_PROPERTY="SIMPLE_PROPERTY",e.PREPROCESS_SINGLE_DOCUMENT="PREPROCESS_SINGLE_DOCUMENT",e.PREPROCESS_TEXT_CONTENT="PREPROCESS_TEXT_CONTENT",e.PREPROCESS_ELEMENT_STYLE="PREPROCESS_ELEMENT_STYLE",e.POLYFILLED_INHERITED_PROPS="POLYFILLED_INHERITED_PROPS",e.CONFIGURATION="CONFIGURATION",e.RESOLVE_TEXT_NODE_BREAKER="RESOLVE_TEXT_NODE_BREAKER",e.RESOLVE_FORMATTING_CONTEXT="RESOLVE_FORMATTING_CONTEXT",e.RESOLVE_LAYOUT_PROCESSOR="RESOLVE_LAYOUT_PROCESSOR",e.POST_LAYOUT_BLOCK="POST_LAYOUT_BLOCK",e.PAGINATION_PROGRESS="PAGINATION_PROGRESS",e))(Yo||{}),So={};function At(e,t,i){if(!Yo[e])j.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=So[e];n||(n=So[e]=[]),i?n.unshift(t):n.push(t)}}function Ru(e,t){if(!Yo[e])j.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=So[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function Dt(e){return So[e]||[]}var Yf={registerHook:At,removeHook:Ru},Lu=class{constructor(e){this.performanceInstance=e,c(this,"timestamps",{}),c(this,"registerTiming"),c(this,"registerStartTiming"),c(this,"registerEndTiming"),this.registerTiming=Yi,this.registerStartTiming=this.registerStartTiming=Yi,this.registerEndTiming=this.registerEndTiming=Yi}forceRegisterStartTiming(e,t){ms.call(this,e,"start",t)}forceRegisterEndTiming(e,t){ms.call(this,e,"end",t)}printTimings(){let e=this.timestamps,t="";Object.keys(e).forEach(i=>{let n=e[i],r=n.length;for(let o=0;o<r;o++){let s=n[o];t+=i,r>1&&(t+=`(${o})`),t+=` => start: ${s.start}, end: ${s.end}, duration: ${s.end-s.start}
4
+ `}}),j.info(t)}disable(){this.registerTiming=Yi,this.registerStartTiming=this.registerStartTiming=Yi,this.registerEndTiming=this.registerEndTiming=Yi}enable(){this.registerTiming=ms,this.registerStartTiming=this.registerStartTiming=Ul,this.registerEndTiming=this.registerEndTiming=Zf}isEnabled(){return this.registerStartTiming===Ul}};function Yi(){}function ms(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let r,o=n.length;for(let s=o-1;s>=0&&(r=n[s],!(r&&!r[t]));s--)r=null;r||(r={},n.push(r)),r[t]=i}function Ul(e,t){this.registerTiming(e,"start",t)}function Zf(e,t){this.registerTiming(e,"end",t)}var Kf={now:Date.now},Jf=window&&window.performance,xt=new Lu(Jf||Kf);xt.forceRegisterStartTiming("load_vivliostyle");var Qf={profiler:{registerStartTiming:xt.registerStartTiming,registerEndTiming:xt.registerEndTiming,printTimings:xt.printTimings,disable:xt.disable,enable:xt.enable}},Ga=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",Co=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,Zt="data-adapt-eloff",eg={};function ja(e){return JSON.parse(e)}function Bt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function Ou(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var Ui=window.location.href;function $l(e){Ui=e}var vi=window.location.href;function Hl(e){vi=e}function tg(e){let t=Ou(e).match(/^(https?:\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+)(?:\/|$)/);return t?t[1]:null}function pr(e){return e.replace(/^(https?:)\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+\//,"$1//wpt.live/")}function Ie(e,t){if(/^data:/i.test(t))return e||t;if(!t||e.match(/^\w{2,}:/))return e.toLowerCase().match("^javascript:")?"#":(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`),e);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let i;if(e.match(/^\/\//))return i=t.match(/^(\w{2,}:)\/\//),i?i[1]+e:e;if(e.match(/^\//)){let s=tg(t);return s?s+e:(i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e)}if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=Ou(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let r=t.substr(0,n+1)+e,o="";for(i=r.match(/^([^?#]*)([?#].*)$/),i&&(r=i[1],o=i[2]);n=r.indexOf("/../"),!(n<=0);){let s=r.lastIndexOf("/",n-1);if(s<=0)break;r=r.substr(0,s)+r.substr(n+3)}return r.replace(/\/(\.\/)+/g,"/")+o}function ko(e,t){return e.match(/^#/)&&t?Bt(t)+e:Ie(e,t)}function Bu(e){return/^about:blank($|[?#])/i.test(e)?"data:text/html,":e}function yn(e){let t;return(e=Bu(e))!==e||((t=/^(https?:)\/\/github\.com\/web-platform-tests\/wpt\/(blob\/|tree\/|raw\/)?(.*)$/.exec(e))?e=`${t[1]}//raw.githack.com/web-platform-tests/wpt/${t[2]?"":"master/"}${t[3]}`:(t=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/${t[2]}/${t[3]?"":"master/"}${t[4]}`:(t=/^(https?:)\/\/wpt\.live\/(.*)$/.exec(e))?/\.sub\.[^/]+(?:[?#].*)?$/.test(t[2])||(e=`${t[1]}//raw.githack.com/web-platform-tests/wpt/master/${t[2]}`):(t=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${t[2]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[6]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(?:#|%23)file-(.*)-(\w+)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[3]}.${t[4]}`:(t=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(e))&&(e=`${t[1]}//output.jsbin.com/${t[2]}${t[3]}/`)),e}function Wl(e){return e==null?e:e.toString()}var ig=class{constructor(){c(this,"queue",[null])}length(){return this.queue.length-1}add(e){let t=this.queue.length;for(;t>1;){let i=Math.floor(t/2),n=this.queue[i];if(n.compare(e)>0){this.queue[t]=e;return}this.queue[t]=n,t=i}this.queue[1]=e}peek(){return this.queue[1]}remove(){let e=this.queue[1],t=this.queue.pop(),i=this.queue.length;if(i>1){let n=1;for(;;){let r=n*2;if(r>=i)break;if(this.queue[r].compare(t)>0)r+1<i&&this.queue[r+1].compare(this.queue[r])>0&&r++;else if(r+1<i&&this.queue[r+1].compare(t)>0)r++;else break;this.queue[n]=this.queue[r],n=r}this.queue[n]=t}return e}},Mu=["","-webkit-","-moz-"],Ji={};function eo(e,t){return CSS.supports(e+t,"unset")}function ng(e){let t=Ji[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return Ji[e]=null,null;case"text-combine-upright":if(eo("-webkit-","text-combine")&&!eo("","text-combine-upright"))return Ji[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of Mu)if(eo(i,e))return t=[i+e],Ji[e]=t,t;return j.warn("Property not supported by the browser: ",e),Ji[e]=null,null}function I(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let r=ng(t);if(r)for(let o of r){switch(o){case"-webkit-text-combine":switch(i){case"all":i="horizontal";break}break;case"text-combine-upright":switch(i){case"all":n.setProperty("text-indent","0");break}break}n.setProperty(o,i)}}function mi(e,t,i){try{let n=Ji[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function _s(e){let t=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!t&&e.namespaceURI=="http://www.w3.org/1999/xhtml"&&(t=e.getAttribute("lang")),t}var si=class{constructor(){c(this,"list",[])}append(e){return this.list.push(e),this}clear(){this.list=[]}toString(){let e=this.list.join("");return this.list=[e],e}};function Xa(e){return`\\${e.charCodeAt(0).toString(16)} `}function bi(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Xa)}function kr(e){return e.replace(/[\u0000-\u001F"\\]/g,Xa)}function Gl(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function jl(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function rg(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function _u(e,t){function i(n){return rg(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function di(e){return _u(e)}function og(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function sg(e,t){t=typeof t=="string"?t:"\\u";function i(r){return og(r,t)}let n=new RegExp(`${di(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function ai(e,t){let i=0,n=e;for(;;){if(i<=n,i==0||t(i-1),n==e||t(n),i==n)return i;let r=i+n>>1;t(r)?n=r:i=r+1}}function Du(e,t){return e-t}function Xl(e,t){let i={};for(let n of e){let r=t(n);r&&!i[r]&&(i[r]=n)}return i}function ag(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function ws(e,t){let i={};for(let n of e){let r=t(n);r&&(i[r]?i[r].push(n):i[r]=[n])}return i}function lg(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var qa=class{constructor(){c(this,"listeners",{})}dispatchEvent(e){let t=this.listeners[e.type];if(t){e.target=this,e.currentTarget=this;for(let i=0;i<t.length;i++)t[i](e)}}addEventListener(e,t,i){if(i)return;let n=this.listeners[e];n?n.includes(t)||n.push(t):this.listeners[e]=[t]}removeEventListener(e,t,i){if(i)return;let n=this.listeners[e];if(n){let r=n.indexOf(t);r>=0&&n.splice(r,1)}}},_i={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function zu(){return{fontFamily:"serif",lineHeight:1.25,margin:8,hyphenate:!1,columnWidth:25,horizontal:!1,nightMode:!1,spreadView:!1,pageBorder:1,enabledMediaTypes:{vivliostyle:!0,print:!0},defaultPaperSize:void 0}}function Vu(e){return{fontFamily:e.fontFamily,lineHeight:e.lineHeight,margin:e.margin,hyphenate:e.hyphenate,columnWidth:e.columnWidth,horizontal:e.horizontal,nightMode:e.nightMode,spreadView:e.spreadView,pageBorder:e.pageBorder,enabledMediaTypes:Object.assign({},e.enabledMediaTypes),defaultPaperSize:e.defaultPaperSize?Object.assign({},e.defaultPaperSize):void 0}}var hg=zu(),ql={PENDING:{}};function Uu(e,t,i,n){let r=Math.min((e-0)/i,(t-0)/n);return`matrix(${r},0,0,${r},0,0)`}function ug(e){return`"${kr(`${e}`)}"`}function cg(e){return bi(`${e}`)}function Ds(e,t){return e?`${bi(e)}.${bi(t)}`:bi(t)}var $u=0,zs=class{constructor(e,t){if(this.parent=e,this.resolver=t,c(this,"scopeKey"),c(this,"children",[]),c(this,"zero"),c(this,"one"),c(this,"_true"),c(this,"_false"),c(this,"values",{}),c(this,"funcs",{}),c(this,"builtIns",{}),this.scopeKey=`S${$u++}`,this.zero=new Qe(this,0),this.one=new Qe(this,1),this._true=new Qe(this,!0),this._false=new Qe(this,!1),e&&e.children.push(this),!e){let i=this.builtIns;i.floor=Math.floor,i.ceil=Math.ceil,i.round=Math.round,i.sqrt=Math.sqrt,i.min=Math.min,i.max=Math.max,i.letterbox=Uu,i["css-string"]=ug,i["css-name"]=cg,i.typeof=n=>typeof n,this.defineBuiltInName("page-width",function(){return this.pageWidth()}),this.defineBuiltInName("page-height",function(){return this.pageHeight()}),this.defineBuiltInName("pref-font-family",function(){return this.pref.fontFamily}),this.defineBuiltInName("pref-night-mode",function(){return this.pref.nightMode}),this.defineBuiltInName("pref-hyphenate",function(){return this.pref.hyphenate}),this.defineBuiltInName("pref-margin",function(){return this.pref.margin}),this.defineBuiltInName("pref-line-height",function(){return this.pref.lineHeight}),this.defineBuiltInName("pref-column-width",function(){return this.pref.columnWidth*this.fontSize}),this.defineBuiltInName("pref-horizontal",function(){return this.pref.horizontal}),this.defineBuiltInName("pref-spread-view",function(){return this.pref.spreadView}),this.defineBuiltInName("pub-title",function(){return this.pubTitle?this.pubTitle:""}),this.defineBuiltInName("doc-title",function(){return this.docTitle?this.docTitle:""})}}defineBuiltInName(e,t){this.values[e]=new Re(this,t,e)}defineName(e,t){this.values[e]=t}defineFunc(e,t){this.funcs[e]=t}defineBuiltIn(e,t){this.builtIns[e]=t}};function dg(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function Hu(e){switch(e?.toLowerCase()){case"vw":case"vh":case"vi":case"vb":case"vmin":case"vmax":case"pvw":case"pvh":case"pvi":case"pvb":case"pvmin":case"pvmax":return!0;default:return!1}}function pg(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function fg(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var Wt={px:1,in:96,pt:4/3,pc:96/6,cm:96/2.54,mm:96/25.4,q:96/2.54/40,em:16,rem:16,lh:20,rlh:20,dppx:1,dpi:1/96,dpcm:2.54/96};function Wu(e){switch(e){case"q":return!CSS.supports("font-size","1q");case"lh":return!CSS.supports("line-height","1lh");case"rem":case"rlh":return!0;default:return!1}}var Vs=class{constructor(e,t,i,n){this.rootScope=e,this.viewportWidth=t,this.viewportHeight=i,c(this,"actualPageWidth",null),c(this,"pageWidth"),c(this,"actualPageHeight",null),c(this,"pageHeight"),c(this,"initialFontSize"),c(this,"rootFontSize",null),c(this,"isRelativeRootFontSize",null),c(this,"fontSize"),c(this,"rootLineHeight",null),c(this,"pref"),c(this,"scopes",{}),c(this,"pageAreaWidth",null),c(this,"pageAreaHeight",null),c(this,"pageVertical",null),c(this,"pubTitle",null),c(this,"docTitle",null),this.pageWidth=function(){return this.actualPageWidth?this.actualPageWidth:this.pref.spreadView?Math.floor(t/2)-this.pref.pageBorder:t},this.pageHeight=function(){return this.actualPageHeight?this.actualPageHeight:i},this.initialFontSize=n,this.fontSize=function(){return this.rootFontSize?this.rootFontSize:n},this.pref=hg}getScopeContext(e){let t=this.scopes[e.scopeKey];return t||(t={},this.scopes[e.scopeKey]=t),t}clearScope(e){this.scopes[e.scopeKey]={};for(let t=0;t<e.children.length;t++)this.clearScope(e.children[t])}queryUnitSize(e,t,i){if(Hu(e)){let n=this.pageWidth()/100,r=this.pageHeight()/100,o=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,s=this.pageAreaHeight!=null?this.pageAreaHeight/100:r,a=i??this.pageVertical;switch(e){case"vw":return o;case"vh":return s;case"vi":return a?s:o;case"vb":return a?o:s;case"vmin":return o<s?o:s;case"vmax":return o>s?o:s;case"pvw":return n;case"pvh":return r;case"pvi":return a?r:n;case"pvb":return a?n:r;case"pvmin":return n<r?n:r;case"pvmax":return n>r?n:r}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="lh"||e=="rlh"?this.rootLineHeight:Wt[e]}evalName(e,t){do{let i=e.values[t];if(i||e.resolver&&(i=e.resolver.call(this,t,!1),i))return i;e=e.parent}while(e);throw new Error(`Name '${t}' is undefined`)}evalCall(e,t,i,n){do{let r=e.funcs[t];if(r||e.resolver&&(r=e.resolver.call(this,t,!0),r))return r;let o=e.builtIns[t];if(o){if(n)return e.zero;let s=Array(i.length);for(let a=0;a<i.length;a++)s[a]=i[a].evaluate(this);return new Qe(e,o.apply(this,s))}e=e.parent}while(e);throw new Error(`Function '${t}' is undefined`)}evalMediaName(e,t){let i=e==="all"||!!this.pref.enabledMediaTypes[e];return t?!i:i}evalMediaTest(e,t){let i="",n=e.match(/^(min|max)-(.*)$/);n&&(i=n[1],e=n[2]);let r=null,o=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(r=t.evaluate(this));break}switch(e){case"width":o=this.pageWidth();break;case"height":o=this.pageHeight();break;case"device-width":o=window.screen.availWidth;break;case"device-height":o=window.screen.availHeight;break;case"color":o=window.screen.pixelDepth;break}if(o!=null&&r!=null)switch(i){case"min":return o>=Number(r);case"max":return o<=Number(r);default:return o==r}else if(o!=null&&t==null)return o!==0;return!1}evalSupportsTest(e,t,i){return!1}queryVal(e,t){let i=e&&this.scopes[e.scopeKey];return i?i[t]:void 0}storeVal(e,t,i){this.getScopeContext(e)[t]=i}},Ut=class{constructor(e){this.scope=e,c(this,"key"),this.scope=e,this.key=`_${$u++}`}toString(){let e=new si;return this.appendTo(e,0),e.toString()}appendTo(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){throw new Error("F_ABSTRACT")}expand(e,t){return this}dependCore(e,t,i){return e===this}dependOuter(e,t,i){let n=i[this.key];if(n!=null)return n===ql.PENDING?!1:n;{i[this.key]=ql.PENDING;let r=this.dependCore(e,t,i);return i[this.key]=r,r}}depend(e,t){return this.dependOuter(e,t,{})}evaluate(e){let t=e.queryVal(this.scope,this.key);return typeof t<"u"||(t=this.evaluateCore(e),this.scope&&e.storeVal(this.scope,this.key,t)),t}isMediaName(){return!1}},Gu=class extends Ut{constructor(e,t){super(e),this.val=t}getOp(){throw new Error("F_ABSTRACT")}evalPrefix(e){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.val.evaluate(e);return this.evalPrefix(t)}dependCore(e,t,i){return e===this||this.val.dependOuter(e,t,i)}appendTo(e,t){10<t&&e.append("("),e.append(this.getOp()),this.val.appendTo(e,10),10<t&&e.append(")")}expand(e,t){let i=this.val.expand(e,t);return i===this.val?this:new this.constructor(this.scope,i)}},Zo=class extends Ut{constructor(e,t,i){super(e),this.lhs=t,this.rhs=i}getPriority(){throw new Error("F_ABSTRACT")}getOp(){throw new Error("F_ABSTRACT")}evalInfix(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.lhs.evaluate(e),i=this.rhs.evaluate(e);return this.evalInfix(t,i)}dependCore(e,t,i){return e===this||this.lhs.dependOuter(e,t,i)||this.rhs.dependOuter(e,t,i)}appendTo(e,t){let i=this.getPriority();i<=t&&e.append("("),this.lhs.appendTo(e,i),e.append(this.getOp()),this.rhs.appendTo(e,i),i<=t&&e.append(")")}expand(e,t){let i=this.lhs.expand(e,t),n=this.rhs.expand(e,t);return i===this.lhs&&n===this.rhs?this:new this.constructor(this.scope,i,n)}},ju=class extends Zo{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Rn=class extends Zo{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},Xu=class extends Zo{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},Ya=class extends Zo{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},xi=class extends Gu{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},gg=class extends xi{constructor(e,t){super(e,t)}getOp(){return"not "}},un=class extends Gu{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},Za=class extends ju{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},mg=class extends Za{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},Ka=class extends ju{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},wg=class extends Ka{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},yg=class extends Ka{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},vg=class extends Rn{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},bg=class extends Rn{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},xg=class extends Rn{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},Us=class extends Rn{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Ja=class extends Rn{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},Sg=class extends Rn{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},qu=class extends Xu{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},Yu=class extends Xu{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},Qa=class extends Ya{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},Zu=class extends Ya{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},Ku=class extends Ya{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},Er=class extends Ut{constructor(e,t,i){var n;super(e),this.num=t,c(this,"unit"),this.unit=(n=i?.toLowerCase())!=null?n:""}appendTo(e,t){e.append(this.num.toString()),e.append(bi(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},Ze=class extends Ut{constructor(e,t){super(e),this.qualifiedName=t}appendTo(e,t){e.append(this.qualifiedName)}evaluateCore(e){return e.evalName(this.scope,this.qualifiedName).evaluate(e)}dependCore(e,t,i){return e===this||t.evalName(this.scope,this.qualifiedName).dependOuter(e,t,i)}},Yl=class extends Ut{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(bi(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},Re=class extends Ut{constructor(e,t,i){super(e),this.fn=t,this.str=i}appendTo(e,t){e.append(this.str)}evaluateCore(e){return this.fn.call(e)}};function Cg(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function kg(e,t,i){let n=t;for(let r=0;r<t.length;r++){let o=t[r].expand(e,i);if(t!==n)n[r]=o;else if(o!==t[r]){n=Array(t.length);for(let s=0;s<r;s++)n[s]=t[s];n[r]=o}}return n}var tr=class Ju extends Ut{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),Cg(t,this.params)}evaluateCore(t){return t.evalCall(this.scope,this.qualifiedName,this.params,!1).expand(t,this.params).evaluate(t)}dependCore(t,i,n){if(t===this)return!0;for(let r=0;r<this.params.length;r++)if(this.params[r].dependOuter(t,i,n))return!0;return i.evalCall(this.scope,this.qualifiedName,this.params,!0).dependOuter(t,i,n)}expand(t,i){let n=kg(t,this.params,i);return n===this.params?this:new Ju(this.scope,this.qualifiedName,n)}},Eg=class Qu extends Ut{constructor(t,i,n,r){super(t),this.cond=i,this.ifTrue=n,this.ifFalse=r}appendTo(t,i){i>0&&t.append("("),this.cond.appendTo(t,0),t.append("?"),this.ifTrue.appendTo(t,0),t.append(":"),this.ifFalse.appendTo(t,0),i>0&&t.append(")")}evaluateCore(t){return this.cond.evaluate(t)?this.ifTrue.evaluate(t):this.ifFalse.evaluate(t)}dependCore(t,i,n){return t===this||this.cond.dependOuter(t,i,n)||this.ifTrue.dependOuter(t,i,n)||this.ifFalse.dependOuter(t,i,n)}expand(t,i){let n=this.cond.expand(t,i),r=this.ifTrue.expand(t,i),o=this.ifFalse.expand(t,i);return n===this.cond&&r===this.ifTrue&&o===this.ifFalse?this:new Qu(this.scope,n,r,o)}},Qe=class extends Ut{constructor(e,t){super(e),this.val=t}appendTo(e,t){switch(typeof this.val){case"number":case"boolean":e.append(this.val.toString());break;case"string":e.append('"'),e.append(kr(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Zl=class ec extends Ut{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(kr(this.name.name)),t.append(":"),this.value.appendTo(t,0),t.append(")")}evaluateCore(t){return t.evalMediaTest(this.name.name,this.value)}dependCore(t,i,n){return t===this||this.value.dependOuter(t,i,n)}expand(t,i){let n=this.value.expand(t,i);return n===this.value?this:new ec(this.scope,this.name,n)}},Pg=class extends Ut{constructor(e,t,i,n){super(e),this.name=t,this.value=i,this.isFunc=n}appendTo(e,t){this.isFunc&&e.append(this.name),e.append("("),!this.isFunc&&this.name&&(e.append(this.name),e.append(":")),e.append(this.value),e.append(")")}evaluateCore(e){return e.evalSupportsTest(this.name,this.value,this.isFunc)}},tc=class extends Ut{constructor(e,t){super(e),this.index=t}appendTo(e,t){e.append("$"),e.append(this.index.toString())}expand(e,t){let i=t[this.index];if(!i)throw new Error(`Parameter missing: ${this.index}`);return i}};function Mt(e,t,i){return t===e._false||t===e.zero||i==e._false||i==e.zero?e._false:t===e._true||t===e.one?i:i===e._true||i===e.one?t:new Za(e,t,i)}function te(e,t,i){return t===e.zero?i:i===e.zero?t:new qu(e,t,i)}function ge(e,t,i){return t===e.zero?new un(e,i):i===e.zero?t:new Yu(e,t,i)}function to(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new Qa(e,t,i)}function $s(e,t,i){return t===e.zero?e.zero:i===e.one?t:new Zu(e,t,i)}var ui=class{visitValues(e){for(let t=0;t<e.length;t++)e[t].visit(this);return null}visitEmpty(e){return null}visitSlash(e){return null}visitStr(e){return null}visitIdent(e){return null}visitNumeric(e){return null}visitNum(e){return null}visitInt(e){return this.visitNum(e)}visitHexColor(e){return null}visitURL(e){return null}visitURange(e){return null}visitSpaceList(e){return this.visitValues(e.values),null}visitCommaList(e){return this.visitValues(e.values),null}visitFunc(e){return this.visitValues(e.values),null}visitExpr(e){return null}},Gi=class extends ui{constructor(){super(),c(this,"error",!1)}visitValues(e){let t=null;for(let i=0;i<e.length;i++){let n=e[i],r=n.visit(this);if(this.error)return[];if(t)t[i]=r;else if(n!==r){t=new Array(e.length);for(let o=0;o<i;o++)t[o]=e[o];t[i]=r}}return t||e}visitEmpty(e){return e}visitStr(e){return e}visitIdent(e){return e}visitSlash(e){return e}visitNumeric(e){return e}visitNum(e){return e}visitInt(e){return e}visitHexColor(e){return e}visitURL(e){return e}visitURange(e){return e}visitSpaceList(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new J(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new it(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new ci(e.name,t)}visitExpr(e){return e}},nt=class{toString(){let e=new si;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new si;return this.appendTo(e,!1),e.toString()}toExpr(e,t){return null}appendTo(e,t){e.append("[error]")}isExpr(){return!1}isNumeric(){return!1}isNum(){return!1}isIdent(){return!1}isSpaceList(){return!1}visit(e){return this}},ic=class nc extends nt{static get instance(){return this.empty||(this.empty=new nc),this.empty}constructor(){super()}toExpr(t,i){return new Qe(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};c(ic,"empty");var Ng=ic,Y=Ng.instance,rc=class oc extends nt{static get instance(){return this.slash||(this.slash=new oc),this.slash}constructor(){super()}toExpr(t,i){return new Qe(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};c(rc,"slash");var Tg=rc,Ln=Tg.instance,X=class extends nt{constructor(e){super(),this.str=e}toExpr(e,t){return new Qe(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(kr(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},Hs=Object.create(null),de=class extends nt{constructor(e){if(super(),this.name=e,Hs[e])throw new Error("E_INVALID_CALL");Hs[e]=this}toExpr(e,t){return new Qe(e,this.name)}appendTo(e,t){t?e.append(bi(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function M(e){let t=Hs[e];return t||(t=new de(e)),t}var R=class extends nt{constructor(e,t){var i;super(),this.num=e,c(this,"unit"),this.unit=(i=t?.toLowerCase())!=null?i:""}toExpr(e,t){return this.num==0?e.zero:t&&this.unit=="%"?this.num==100?t:new Qa(e,t,new Qe(e,this.num/100)):new Er(e,this.num,this.unit)}appendTo(e,t){e.append(this.num.toString()),e.append(this.unit)}visit(e){return e.visitNumeric(this)}isNumeric(){return!0}},Ct=class extends nt{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new Qe(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},Ue=class extends Ct{constructor(e){super(e)}visit(e){return e.visitInt(this)}},sc=class extends nt{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},ut=class extends nt{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(kr(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},ac=class extends nt{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function el(e,t,i,n){var r,o;let s=t.length;if(s>0){(r=t[0])==null||r.appendTo(e,n);for(let a=1;a<s;a++)e.append(i),(o=t[a])==null||o.appendTo(e,n)}}var J=class extends nt{constructor(e){super(),this.values=e}appendTo(e,t){el(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},it=class extends nt{constructor(e){super(),this.values=e}appendTo(e,t){el(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},ci=class extends nt{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(bi(this.name)),e.append("("),el(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},G=class extends nt{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof Qe||this.expr instanceof Er?this.expr.appendTo(e,0):(e.append("-epubx-expr("),this.expr.appendTo(e,0),e.append(")"))}visit(e){return e.visitExpr(this)}isExpr(){return!0}},Qi=class extends nt{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function at(e,t){if(e){if(e.isNumeric()){let i=e;return t.queryUnitSize(i.unit,!1)*i.num}if(e.isNum())return e.num}return 0}function lc(e,t){return new R(at(e,t),"px")}var v={absolute:M("absolute"),all:M("all"),always:M("always"),anywhere:M("anywhere"),auto:M("auto"),avoid:M("avoid"),balance:M("balance"),balance_all:M("balance-all"),block:M("block"),block_end:M("block-end"),block_start:M("block-start"),both:M("both"),bottom:M("bottom"),border_box:M("border-box"),break_all:M("break-all"),break_word:M("break-word"),clip:M("clip"),crop:M("crop"),cross:M("cross"),column:M("column"),discard:M("discard"),exclusive:M("exclusive"),_false:M("false"),fixed:M("fixed"),flex:M("flex"),flow_root:M("flow-root"),footnote:M("footnote"),footer:M("footer"),grid:M("grid"),header:M("header"),hidden:M("hidden"),horizontal_tb:M("horizontal-tb"),inherit:M("inherit"),initial:M("initial"),inline:M("inline"),inline_block:M("inline-block"),inline_end:M("inline-end"),inline_start:M("inline-start"),inside:M("inside"),keep:M("keep"),landscape:M("landscape"),left:M("left"),line:M("line"),list_item:M("list-item"),ltr:M("ltr"),manual:M("manual"),max_content:M("max-content"),min_content:M("min-content"),none:M("none"),normal:M("normal"),oeb_page_foot:M("oeb-page-foot"),oeb_page_head:M("oeb-page-head"),outside:M("outside"),padding_box:M("padding-box"),page:M("page"),relative:M("relative"),revert:M("revert"),right:M("right"),same:M("same"),scale:M("scale"),snap_block:M("snap-block"),snap_inline:M("snap-inline"),solid:M("solid"),spread:M("spread"),_static:M("static"),rtl:M("rtl"),table:M("table"),table_caption:M("table-caption"),table_cell:M("table-cell"),table_footer_group:M("table-footer-group"),table_header_group:M("table-header-group"),table_row:M("table-row"),top:M("top"),transparent:M("transparent"),unset:M("unset"),vertical_lr:M("vertical-lr"),vertical_rl:M("vertical-rl"),visible:M("visible"),_true:M("true")},Kl=new R(100,"%"),Pr=new R(100,"pvw"),Nr=new R(100,"pvh"),Fe=new R(0,"px"),Gx=new ac("U+0-10FFFF"),Jl={"font-size":1,"line-height":2,color:3};function Z(e){return e===v.inherit||e===v.initial||e===v.revert||e===v.unset}function Ql(e,t){let i=Jl[e]||Number.MAX_VALUE,n=Jl[t]||Number.MAX_VALUE;return i-n}function Qt(e){return e?.length>2&&e.startsWith("--")}var en,tn,nn,hc=class ti{constructor(t,i,n){ie(this,en),ie(this,tn),ie(this,nn),Ve(this,en,Math.round(Math.max(0,Math.min(t,ti.MAX)))),Ve(this,tn,Math.round(Math.max(0,Math.min(i,ti.MAX)))),Ve(this,nn,Math.round(Math.max(0,Math.min(n,ti.MAX))))}static fromInt(t,i,n){return new ti(t,i,n)}offset(t,i,n){return new ti($(this,en)+t,$(this,tn)+i,$(this,nn)+n)}toKey(){return JSON.stringify([$(this,en),$(this,tn),$(this,nn)])}toColorFunc(t){return new ci("color",[new J([M("srgb"),new Ct($(this,en)/ti.MAX),new Ct($(this,tn)/ti.MAX),new Ct($(this,nn)/ti.MAX),...t!==null?[Ln,new Ct(t)]:[]])])}};en=new WeakMap,tn=new WeakMap,nn=new WeakMap,c(hc,"MAX",1e4);var ii=hc;function Ig(e){return Array.isArray(e)?e.every(t=>{if(!Array.isArray(t)||t.length!==2)return!1;let[i,n]=t;if(!i||typeof i!="object"||Array.isArray(i)||!n||typeof n!="object"||Array.isArray(n))return!1;let r=i,o=n;return Number.isFinite(r.r)&&Number.isFinite(r.g)&&Number.isFinite(r.b)&&Number.isFinite(o.c)&&Number.isFinite(o.m)&&Number.isFinite(o.y)&&Number.isFinite(o.k)}):!1}var Ai,Fi,Ri,jt,uc=class dt{constructor(t,i,n,r){ie(this,Ai),ie(this,Fi),ie(this,Ri),ie(this,jt),Ve(this,Ai,Math.round(Math.max(0,Math.min(t,dt.MAX)))),Ve(this,Fi,Math.round(Math.max(0,Math.min(i,dt.MAX)))),Ve(this,Ri,Math.round(Math.max(0,Math.min(n,dt.MAX)))),Ve(this,jt,Math.round(Math.max(0,Math.min(r,dt.MAX))))}static fromInt(t,i,n,r){return new dt(t,i,n,r)}static fromNumber(t,i,n,r){return new dt(t*dt.MAX,i*dt.MAX,n*dt.MAX,r*dt.MAX)}toSRGB(){let t=dt.MAX-$(this,jt);return ii.fromInt(ii.MAX-Math.min(ii.MAX,Math.round($(this,Ai)*t/dt.MAX)+$(this,jt)),ii.MAX-Math.min(ii.MAX,Math.round($(this,Fi)*t/dt.MAX)+$(this,jt)),ii.MAX-Math.min(ii.MAX,Math.round($(this,Ri)*t/dt.MAX)+$(this,jt)))}equals(t){return $(this,Ai)===$(t,Ai)&&$(this,Fi)===$(t,Fi)&&$(this,Ri)===$(t,Ri)&&$(this,jt)===$(t,jt)}toJSON(){return{c:$(this,Ai),m:$(this,Fi),y:$(this,Ri),k:$(this,jt)}}};Ai=new WeakMap,Fi=new WeakMap,Ri=new WeakMap,jt=new WeakMap,c(uc,"MAX",1e4);var cc=uc;function Zi(e){return e instanceof Ct?Math.max(0,Math.min(1,e.num)):e instanceof R&&e.unit==="%"?Math.max(0,Math.min(1,e.num/100)):null}function dc(e){if(e.name!=="device-cmyk"&&e.name!=="cmyk")return null;let t=e.values.length===1&&e.values[0]instanceof J?e.values[0].values:e.values;if(t.length<4||t.length>6)return null;let i=Zi(t[0]),n=Zi(t[1]),r=Zi(t[2]),o=Zi(t[3]);if(i===null||n===null||r===null||o===null)return null;let s=null;if(t.length>=5){if(t[4]===Ln){if(t.length!==6)return null;s=Zi(t[5])}else{if(t.length!==5)return null;s=Zi(t[4])}if(s===null)return null}return{cmyk:cc.fromNumber(i,n,r,o),alpha:s}}function*Ag(e){for(let t=-e;t<=e;t++)for(let i=-e;i<=e;i++)for(let n=-e;n<=e;n++)Math.abs(t)+Math.abs(i)+Math.abs(n)===e&&(yield[t,i,n])}var gi,Eo,pc,eh,fc=class{constructor(){ie(this,Eo),ie(this,gi,new Map)}registerDeviceCmyk(e){let t=dc(e);return t?Ne(this,Eo,pc).call(this,t.cmyk).toColorFunc(t.alpha):null}registerCmykReserveMap(e){for(let[t,i]of e){let n=ii.fromInt(t.r,t.g,t.b),r=cc.fromInt(i.c,i.m,i.y,i.k);$(this,gi).set(n.toKey(),r)}}toJSON(){let e={};return $(this,gi).forEach((t,i)=>{e[i]=t.toJSON()}),e}};gi=new WeakMap,Eo=new WeakSet,pc=function(e){let t=e.toSRGB(),i=t.toKey(),n=$(this,gi).get(i);return n?n.equals(e)?t:Ne(this,Eo,eh).call(this,e,t):($(this,gi).set(i,e),t)},eh=function(e,t){for(let i=1;i<=ii.MAX;i++)for(let[n,r,o]of Ag(i)){let s=t.offset(n,r,o),a=s.toKey();if(!$(this,gi).has(a))return $(this,gi).set(a,e),s}return j.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(e.toJSON())}`),t};var io,Wn,Gn,gc=class extends Gi{constructor(e){super(),ie(this,io),ie(this,Wn,new Map),ie(this,Gn,!1),Ve(this,io,e??new fc)}reset(){Ve(this,Gn,!1)}hadDeviceCmyk(){return $(this,Gn)}recordConversion(e,t){$(this,Wn).set(e,t)}getConversions(){if($(this,Wn).size===0)return null;let e={};return $(this,Wn).forEach((t,i)=>{e[i]=t}),e}visitFunc(e){let t=$(this,io).registerDeviceCmyk(e);return t?(Ve(this,Gn,!0),t):super.visitFunc(e)}};io=new WeakMap,Wn=new WeakMap,Gn=new WeakMap;function mc(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function Fg(e){return`^${e}`}function th(e){return e.replace(/[\[\]\(\),=;^]/g,Fg)}function Rg(e){return e.substr(1)}function Ws(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,Rg)}function Lg(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=Ws(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function ih(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=Lg(i[2]),e=e.substr(i[0].length)}return t}var nh=class{appendTo(e){e.append("!")}applyTo(e){return!1}},rh=class{constructor(e,t,i){this.index=e,this.id=t,this.sideBias=i}appendTo(e){e.append("/"),e.append(this.index.toString()),(this.id||this.sideBias)&&(e.append("["),this.id&&e.append(this.id),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}applyTo(e){if(e.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let t=e.node,i=t.children,n=i.length,r,o=Math.floor(this.index/2)-1;if(o<0||n==0)r=t.firstChild,e.node=r||t;else{if(r=i[Math.min(o,n-1)],this.index&1){let s=r.nextSibling;!s||s.nodeType==1?e.after=!0:r=s}e.node=r}if(this.id&&(e.after||this.id!=mc(e.node))){let s=t.ownerDocument.getElementById(this.id);s?e.node=s:j.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},oh=class{constructor(e,t,i,n){this.offset=e,this.textBefore=t,this.textAfter=i,this.sideBias=n}applyTo(e){if(this.offset>0&&!e.after){let t=this.offset,i=e.node;for(;;){let n=i.nodeType;if(n==1)break;let r=i.nextSibling;if(3<=n&&n<=5){let o=i.textContent.length;if(t<=o)break;if(!r){t=o;break}t-=o}if(!r){t=0;break}i=r}e.node=i,e.offset=t}return e.sideBias=this.sideBias,!0}appendTo(e){e.append(":"),e.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(e.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&e.append(th(this.textBefore)),e.append(","),this.textAfter&&e.append(th(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},sh=class wc{constructor(){c(this,"steps",null)}fromString(t){let i=t.match(/^#?epubcfi\((.*)\)$/);if(!i)throw new Error("E_CFI_NOT_CFI");let n=decodeURIComponent(i[1]),r=0,o=[];for(;;){let s;switch(n.charAt(r)){case"/":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[3];s=ih(i[4]),o.push(new rh(a,h,Wl(s.s)));break}case":":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[4];h&&(h=Ws(h));let l=i[7];l&&(l=Ws(l)),s=ih(i[10]),o.push(new oh(a,h,l,Wl(s.s)));break}case"!":r++,o.push(new nh);break;case"~":case"@":case"":this.steps=o;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let i={node:t.documentElement,offset:0,after:!1,sideBias:null,ref:null};for(let n=0;n<this.steps.length;n++)if(!this.steps[n].applyTo(i)){i.ref=new wc,i.ref.steps=this.steps.slice(n+1);break}return i}trim(t,i){return t.replace(/\s+/g," ").match(i?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,i,n,r){let o=[],s=t.parentNode,a="",h="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let l=t.textContent,u=l.length;n?(i+=u,a||(a=l)):(i>u&&(i=u),n=!0,a=l.substr(0,i),h=l.substr(i)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((i>0||a||h)&&(a=this.trim(a,!1),h=this.trim(h,!0),o.push(new oh(i,a,h,r)),r=null);s&&!(!s||s.nodeType==9);){let l=n?null:mc(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;o.push(new rh(u,l,r)),r=null,t=s,s=s.parentNode,n=!1}o.reverse(),this.steps?(o.push(new nh),this.steps=o.concat(this.steps)):this.steps=o}toString(){if(!this.steps)return"";let t=new si;t.append("epubcfi(");for(let i=0;i<this.steps.length;i++)this.steps[i].appendTo(t);return t.append(")"),t.toString().replace(/%/g,"%25")}},It=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},wi=class{constructor(e,t){this.x=e,this.y=t}},ys=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},ah=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},ri=class{constructor(e,t,i,n){this.y1=e,this.y2=t,this.x1=i,this.x2=n,c(this,"left",null),c(this,"right",null)}};function Og(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var Ko=class yc{constructor(t){this.points=t}addSegments(t,i){let n=this.points,r=n.length,o=n[r-1];for(let s=0;s<r;s++){let a=n[s],h;o.y<a.y?h=new ah(o,a,1,i):h=new ah(a,o,-1,i),t.push(h),o=a}}withOffset(t,i){let n=[];for(let r of this.points)n.push(new wi(r.x+t,r.y+i));return new yc(n)}};function lh(e,t,i,n){let r=[];for(let o=0;o<20;o++){let s=o*2*Math.PI/20;r.push(new wi(e+i*Math.sin(s),t+n*Math.cos(s)))}return new Ko(r)}function tl(e,t,i,n){return new Ko([new wi(e,t),new wi(i,t),new wi(i,n),new wi(e,n)])}var Wr=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function hh(e,t){let i=e.low.x+(e.high.x-e.low.x)*(t-e.low.y)/(e.high.y-e.low.y);if(isNaN(i))throw new Error("Bad intersection");return i}function Bg(e,t,i,n){let r,o,s,a;t.high.y<i&&j.warn("Error: inconsistent segment (1)"),t.low.y<=i?(r=hh(t,i),o=t.winding):(r=t.low.x,o=0),t.high.y>=n?(s=hh(t,n),a=t.winding):(s=t.high.x,a=0),r<s?(e.push(new Wr(r,o,t.shapeId,-1)),e.push(new Wr(s,a,t.shapeId,1))):(e.push(new Wr(s,a,t.shapeId,-1)),e.push(new Wr(r,o,t.shapeId,1)))}function Mg(e,t,i){let n=t+i,r=Array(n),o=Array(n),s;for(s=0;s<=n;s++)r[s]=0,o[s]=0;let a=[],h=!1,l=e.length;for(let u=0;u<l;u++){let d=e[u];r[d.shapeId]+=d.winding,o[d.shapeId]+=d.lowOrHigh;let p=!1;for(s=0;s<t;s++)if(r[s]&&!o[s]){p=!0;break}if(p){for(s=t;s<=n;s++)if(r[s]||o[s]){p=!1;break}}h!=p&&(a.push(d.x),h=p)}return a}function _g(e,t){return t?Math.ceil(e/t)*t:e}function uh(e,t){return t?Math.floor(e/t)*t:e}function Dg(e){return new wi(e.y,-e.x)}function Po(e){return new It(e.y1,-e.x2,e.y2,-e.x1)}function vc(e){return new It(-e.y2,e.x1,-e.y1,e.x2)}function ch(e){return new Ko(e.points.map(t=>Dg(t)))}function zg(e,t,i,n,r,o){o&&(e=Po(e),t=t.map(y=>ch(y)),i=i.map(y=>ch(y)));let s=t.length,a=i?i.length:0,h=[],l=[],u,d,p;for(u=0;u<s;u++)t[u].addSegments(l,u);for(u=0;u<a;u++)i[u].addSegments(l,u+s);let f=l.length;l.sort(Og);let g=0;for(;l[g].shapeId>=s;)g++;let m=l[g].low.y;m>e.y1&&h.push(new ri(e.y1,m,e.x2,e.x2));let w=0,x=[];for(;w<f&&(p=l[w]).low.y<m;)p.high.y>m&&x.push(p),w++;for(;w<f||x.length>0;){let y=e.y2,b=Math.min(_g(Math.ceil(m+n),r),e.y2);for(d=0;d<x.length&&y>b;d++)p=x[d],p.low.x==p.high.x?p.high.y<y&&(y=Math.max(uh(p.high.y,r),b)):p.low.x!=p.high.x&&(y=b);for(y>e.y2&&(y=e.y2);w<f&&(p=l[w]).low.y<y;){if(p.high.y<m){w++;continue}if(p.low.y<b)p.low.y==p.high.y&&p.low.y==m||(x.push(p),y=b),w++;else{let N=uh(p.low.y,r);N<y&&(y=N);break}}let S=[];for(d=0;d<x.length;d++)Bg(S,x[d],m,y);S.sort((N,F)=>N.x-F.x||N.lowOrHigh-F.lowOrHigh);let C=Mg(S,s,a);if(C.length==0)h.push(new ri(m,y,e.x2,e.x2));else{let N=0,F=e.x1;for(d=0;d<C.length;d+=2){let B=Math.max(e.x1,C[d]),U=Math.min(e.x2,C[d+1])-B;U>N&&(N=U,F=B)}N==0?h.push(new ri(m,y,e.x2,e.x2)):h.push(new ri(m,y,Math.max(F,e.x1),Math.min(F+N,e.x2)))}if(y==e.y2)break;for(m=y,d=x.length-1;d>=0;d--)x[d].high.y<=y&&x.splice(d,1)}return bc(e,h),h}function bc(e,t){let i=t.length-1,n=new ri(e.y2,e.y2,e.x1,e.x2);for(;i>=0;){let r=n;n=t[i],(n.y2-n.y1<1||n.x1==r.x1&&n.x2==r.x2)&&(r.y1=n.y1,t.splice(i,1),n=r),i--}}function xc(e,t){let i=0,n=e.length;for(;i<n;){let r=Math.floor((i+n)/2);t>=e[r].y2?i=r+1:n=r}return i}function Vg(e,t){if(!e.length)return t;let i=t.y1,n,r;for(r=0;r<e.length&&(n=e[r],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));r++)i=Math.max(i,n.y2);let o=i;for(;r<e.length&&(n=e[r],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));r++)o=n.y2;return r===e.length?o=t.y2:o=Math.min(o,t.y2),o<=i?null:new It(t.x1,i,t.x2,o)}function Ug(e,t){if(!e.length)return t;let i=t.y2,n,r;for(r=e.length-1;r>=0&&(n=e[r],!(r===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);r--)i=Math.min(i,n.y1);let o=Math.min(i,n.y2);for(;r>=0&&(n=e[r],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));r--)o=n.y1;return o=Math.max(o,t.y1),i<=o?null:new It(t.x1,o,t.x2,i)}function $g(e,t,i,n){let r=i.y1,o=i.x2-i.x1,s=i.y2-i.y1,a=xc(t,r);for(;;){let h=r+s;if(h>e.y2)return!1;let l=e.x1,u=e.x2;for(let d=a;d<t.length&&t[d].y1<h;d++){let p=t[d];p.x1>l&&(l=p.x1),p.x2<u&&(u=p.x2)}if(l+o<=u||a>=t.length)return n=="left"?(i.x1=l,i.x2=l+o):(i.x1=u-o,i.x2=u),i.y2+=r-i.y1,i.y1=r,!0;r=t[a].y2,a++}}function Hg(e,t,i,n,r){for(n||(n=[new ri(i.y1,i.y2,i.x1,i.x2)]);n.length>0&&n[0].y2<=e.y1;)n.shift();if(n.length==0)return;n[0].y1<e.y1&&(n[0].y1=e.y1);let o,s=t.length==0?e.y1:t[t.length-1].y2;s<e.y2&&t.push(new ri(s,e.y2,e.x1,e.x2));let a=xc(t,n[0].y1);for(let h of n){if(a==t.length)break;for(t[a].y1<h.y1&&(o=t[a],a++,t.splice(a,0,new ri(h.y1,o.y2,o.x1,o.x2)),o.y2=h.y1);a<t.length&&(o=t[a++],o.y2>h.y2&&(t.splice(a,0,new ri(h.y2,o.y2,o.x1,o.x2)),o.y2=h.y2),h.x1!=h.x2&&(r=="left"?o.x1=Math.min(h.x2,e.x2):o.x2=Math.max(h.x1,e.x1)),o.y2!=h.y2););}bc(e,t)}var Wg=class extends ui{constructor(){super(),c(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Gg(e){if(e){let t=new Wg;try{return e.visit(t),t.propSet}catch(i){j.warn(i,"toSet:")}}return{}}var jg=class extends ui{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function dh(e,t){if(e){let i=new jg(t);try{return e.visit(i),i.value}catch(n){j.warn(n,"toInt: ")}}return t}var Xg=class extends ui{constructor(){super(),c(this,"collect",!1),c(this,"coords",[]),c(this,"name",null)}visitNumeric(e){return this.collect&&this.coords.push(e),null}visitNum(e){return this.collect&&e.num==0&&this.coords.push(new R(0,"px")),null}visitSpaceList(e){return this.visitValues(e.values),null}visitFunc(e){return this.collect||(this.collect=!0,this.visitValues(e.values),this.collect=!1,this.name=e.name.toLowerCase()),null}getShape(e,t,i,n,r){if(this.coords.length>0){let o=[];switch(this.coords.forEach((s,a)=>{if(s.unit=="%"){let h=a%2==0?i:n;a==3&&this.name=="circle"&&(h=Math.sqrt((i*i+n*n)/2)),o.push(s.num*h/100)}else o.push(s.num*r.queryUnitSize(s.unit,!1))}),this.name){case"polygon":if(o.length%2==0){let s=[];for(let a=0;a<o.length;a+=2)s.push(new wi(e+o[a],t+o[a+1]));return new Ko(s)}break;case"rectangle":if(o.length==4)return tl(e+o[0],t+o[1],e+o[0]+o[2],t+o[1]+o[3]);break;case"ellipse":if(o.length==4)return lh(e+o[0],t+o[1],o[2],o[3]);break;case"circle":if(o.length==3)return lh(e+o[0],t+o[1],o[2],o[2]);break}}return null}};function Sc(e,t,i,n,r,o){if(e){let s=new Xg;try{return e.visit(s),s.getShape(t,i,n,r,o)}catch(a){j.warn(a,"toShape:")}}return tl(t,i,t+n,i+r)}var qg=class extends ui{constructor(e,t){super(),this.reset=e,this.defaultValue=t,c(this,"counters",Object.create(null)),c(this,"name",null)}visitIdent(e){return this.name=e.toString(),this.reset?this.counters[this.name]=0:this.counters[this.name]=(this.counters[this.name]||0)+this.defaultValue,e}visitInt(e){return this.name&&(this.counters[this.name]+=e.num-(this.reset?0:this.defaultValue)),e}visitSpaceList(e){return this.visitValues(e.values),e}};function vn(e,t){var i,n;let r=(i=t?.reset)!=null?i:!1,o=(n=t?.defaultValue)!=null?n:r?0:1,s=new qg(r,o);try{e.visit(s)}catch(a){j.warn(a,"toCounters:")}return s.counters}var Yg=class extends Gi{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new ut(pr(this.transformer.transformURL(e.url,this.baseUrl)))}};function Pi(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function Zg(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(t,i,n)=>i?String.fromCodePoint(parseInt(i,16)):n)}function cn(e,t){var i;if(t==="content"){let n=e.cloneNode(!0);return n.querySelectorAll("[data-adapt-pseudo]").forEach(r=>r.remove()),n.textContent||""}else if(t==="marker"){let n=e.querySelector('[data-adapt-pseudo="marker"], [data-adapt-pseudo="footnote-marker"]');if(n)return n.textContent||"";let r=(i=e.style)==null?void 0:i.getPropertyValue("--viv-marker-content");if(r){let o=r.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(o&&o.length>0)return o.map(s=>Zg(s.substring(1,s.length-1))).join("")}return""}else{let n=e.querySelector(`[data-adapt-pseudo="${t}"]`);return n&&n.textContent||""}}var Kg=class{constructor(e,t){this.targetId=e,this.resolved=t,c(this,"pageCounters",null),c(this,"spineIndex",-1),c(this,"pageIndex",-1)}equals(e){return this===e?!0:e?this.targetId===e.targetId&&this.resolved===e.resolved&&this.spineIndex===e.spineIndex&&this.pageIndex===e.pageIndex:!1}isResolved(){return this.resolved}resolve(){this.resolved=!0}unresolve(){this.resolved=!1}},Jg=class{constructor(e,t){this.counterStore=e,this.baseURL=t}countersOfId(e,t){e=this.counterStore.documentURLTransformer.transformFragment(e,this.baseURL),this.counterStore.countersById[e]=t}getExprContentListener(){return this.counterStore.getExprContentListener()}},Qg=class{constructor(e,t,i,n){this.counterStore=e,this.baseURL=t,this.rootScope=i,this.pageScope=n,c(this,"styler",null),c(this,"namedStringValues",Object.create(null)),c(this,"runningElements",Object.create(null))}setStyler(e){this.styler=e}getFragment(e){let t=e.match(/^[^#]*#(.*)$/);return t?t[1]:null}getTransformedId(e){let t=this.counterStore.documentURLTransformer.transformURL(Ie(e,this.baseURL),this.baseURL);return t.charAt(0)==="#"&&(t=t.substring(1)),t}getPageCounterVal(e,t){let i=()=>{let o=this.counterStore.currentPageCounters[e];return o&&o.length?o[o.length-1]:null},n=new Re(this.pageScope,()=>t(i()),`page-counter-${e}`),r=o=>t(o[o.length-1]);return this.counterStore.registerPageCounterExpr(e,r,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new Re(this.pageScope,()=>t(i()),`page-counters-${e}`);return this.counterStore.registerPageCounterExpr(e,t,n),n}getTargetCounters(e,t,i){let n=this.counterStore.countersById[t];return!n&&i&&e&&(this.styler.styleUntilIdIsReached(e),n=this.counterStore.countersById[t]),n||null}getTargetPageCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageCounters:this.counterStore.pageCountersById[e]||null}getTargetPageDocCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageDocCounters:this.counterStore.pageDocCountersById[e]||null}adjustCountersForCrossScope(e,t,i,n){if(!this.counterStore.isPageControlledCounter(e)||!i)return t;let r=i[e]||[],o=r.length?r[r.length-1]:0,s=n?.[e]||[],a=s.length?s[0]:0;return t.length?[o+(t[0]-a),...t.slice(1)]:[o]}getTargetPageText(e,t){if(this.counterStore.currentPage.elementsById[e]){let i=this.counterStore.currentPage.elementsById[e];if(i&&i.length>0){let n=i[0];return t==="before"||t==="after"||t==="marker"?cn(n,t):cn(n,"content")}return""}else{if(e in this.counterStore.pageTextById){let i=this.counterStore.pageTextById[e];return i[t]!==void 0?i[t]:i.content||""}return null}}getTargetCounterVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e),o=new Re(this.pageScope,()=>{let s=this.getTargetCounters(n,r,!0);if(s)if(s[t]){let a=s[t],h=this.getTargetPageCounters(r),l=this.getTargetPageDocCounters(r),u=this.adjustCountersForCrossScope(t,a,h,l);return h&&this.counterStore.resolveReference(r),i(u[u.length-1]||null)}else{let a=this.getTargetPageCounters(r);if(a)if(this.counterStore.resolveReference(r),a[t]){let h=a[t];return i(h[h.length-1]||null)}else return i(0);else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counter-${t}-of-${e}`);return this.counterStore.registerTargetCounterExpr(t,i,o,r),o}getTargetCountersVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e);return new Re(this.pageScope,()=>{let o=this.getTargetPageCounters(r);if(o){this.counterStore.resolveReference(r);let s=this.getTargetCounters(n,r,!0),a=s?.[t]||[],h=this.getTargetPageDocCounters(r),l=this.adjustCountersForCrossScope(t,a,o,h);if(l.length)return i(l);let u=o[t]||[];return i(u)}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counters-${t}-of-${e}`)}getTargetTextVal(e,t){let i=this.getTransformedId(e),n=new Re(this.pageScope,()=>{if(t==="first-letter"){let o=this.getTargetPageText(i,"before"),s=this.getTargetPageText(i,"content"),a=this.getTargetPageText(i,"after");if(o===null&&s===null&&a===null)return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??";let h=(o??"")+(s??"")+(a??"");this.counterStore.resolveReference(i);let l=h.match(Co);return l?l[0]:""}let r=this.getTargetPageText(i,t);return r!==null?(this.counterStore.resolveReference(i),r):(this.counterStore.saveReferenceOfCurrentPage(i,!1),"??")},`target-text-${t}-of-${e}`);return this.counterStore.registerTargetTextExpr(t,n,i),n}getNamedStringVal(e,t){return new Re(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new Re(this.pageScope,()=>this.getRunningValue(this.runningElements,e,t),`running-element-${t}-${e}`)}getRunningValue(e,t,i){let n=e[t];if(!n)return"";let r=Object.keys(n).map(p=>parseInt(p,10)).sort(Du),o=this.counterStore.currentPage;if(!o)return"";let s=o.isBlankPage?o.offset-1:o.offset,a=o.isBlankPage?s:Math.max(s,...Array.from(o.container.querySelectorAll(`[${Zt}]`)).map(p=>parseInt(p.getAttribute(Zt),10))),h=-1,l=-1,u=-1,d=-1;for(let p=0;p<r.length;p++){let f=r[p],g=p>0?r[p-1]:-1,m=p<r.length-1?r[p+1]:-1;if(f>a)break;if(f>=s){if(h<0&&(h=f,d=-1),l<0)if(f===s)l=f;else{g<h&&(l=g);let w=o.container.querySelector(`[${Zt}="${f}"]`);if(!w)l<0&&(l=f);else{let x=o.container.querySelector(`[${Zt}="${s}"]`);if(x||(x=o.container.querySelector(`[${Zt}="0"]`)),x){for(let y=x;y;y=y.firstElementChild)if(y===w){l=f;break}}}}u=f}else(m>a||m<0)&&(h=l=u=d=f)}return n[{first:h,start:l,last:u,"first-except":d}[i]]||""}setNamedString(e,t,i){let n=this.namedStringValues[e]||(this.namedStringValues[e]=Object.create(null));n[i]=t}setRunningElement(e,t){let i=this.runningElements[e]||(this.runningElements[e]=Object.create(null));i[t]=String(t)}},em=class{constructor(e){this.documentURLTransformer=e,c(this,"countersById",Object.create(null)),c(this,"pageCountersById",Object.create(null)),c(this,"pageDocCountersById",Object.create(null)),c(this,"pageTextById",Object.create(null)),c(this,"currentPageDocCounters",null),c(this,"previousPageDocCounters",null),c(this,"currentPageDocCounterChanges",Object.create(null)),c(this,"currentPageDocCounterChangeTypes",Object.create(null)),c(this,"currentPageCounters",Object.create(null)),c(this,"previousPageCounters",Object.create(null)),c(this,"currentPageCountersStack",[]),c(this,"pageIndicesById",Object.create(null)),c(this,"currentPage",null),c(this,"newReferencesOfCurrentPage",[]),c(this,"referencesToSolve",[]),c(this,"referencesToSolveStack",[]),c(this,"unresolvedReferences",Object.create(null)),c(this,"resolvedReferences",Object.create(null)),c(this,"pageControlledCounterNames",Object.assign(Object.create(null),{page:!0})),c(this,"pagesCounterExprs",[]),c(this,"pageCounterExprs",[]),c(this,"targetCounterExprs",[]),c(this,"targetTextExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new Jg(this,e)}createCounterResolver(e,t,i){return new Qg(this,e,t,i)}setCurrentPage(e){this.currentPage=e}setCurrentPageDocCounters(e,t,i){this.previousPageDocCounters=this.currentPageDocCounters?Pi(this.currentPageDocCounters):null,this.currentPageDocCounters=e?Pi(e):null,this.currentPageDocCounterChanges=Object.create(null),this.currentPageDocCounterChangeTypes=i?{...i}:Object.create(null),t&&t.forEach(n=>{this.currentPageDocCounterChanges[n]=!0})}setPageControlledCounterNames(e){let t=Object.assign(Object.create(null),{page:!0});e.forEach(i=>{t[i]=!0}),this.pageControlledCounterNames=t}isPageControlledCounter(e){return!!this.pageControlledCounterNames[e]}definePageCounter(e,t){this.currentPageCounters[e]?this.currentPageCounters[e].push(t):this.currentPageCounters[e]=[t]}forceSetPageCounter(e){let t=this.currentPageCounters.page;!t||!t.length?this.currentPageCounters.page=[e]:t[t.length-1]=e}updatePageCounters(e,t){this.previousPageCounters=Pi(this.currentPageCounters);let i=this.currentPageDocCounterChanges||{},n=this.currentPageDocCounterChangeTypes||{},r=Object.create(null);if(this.currentPageDocCounters){let g=this.previousPageDocCounters||{};for(let m in this.currentPageDocCounters){if(!i[m])continue;let w=this.currentPageDocCounters[m],x=w.length?w[w.length-1]:0,y=g[m]||[],b=y.length?y[y.length-1]:0,S=x-b,C=n[m],N=C==="reset"||C==="set";r[m]={delta:S,reset:N,value:x}}}let o=Object.create(null),s,a=e["counter-reset"];if(a){let g=a.evaluate(t);g&&(s=vn(g,{reset:!0}))}s&&"pages"in s&&delete s.pages;let h,l=e["counter-set"];if(l){let g=l.evaluate(t);g&&(h=vn(g,{defaultValue:0}))}h&&"pages"in h&&delete h.pages;let u=[];if(s)for(let g in s)u.push(g);if(h)for(let g in h)u.push(g);let d,p=e["counter-increment"];if(p){let g=p.evaluate(t);g&&(d=vn(g))}d&&"pages"in d&&delete d.pages,d?!("page"in d)&&!(r.page&&r.page.reset)&&(d.page=1):(d=Object.create(null),r.page&&r.page.reset||(d.page=1));for(let g in d)u.push(g);this.setPageControlledCounterNames(u);let f=Pi(this.previousPageCounters);if(this.currentPageDocCounters)for(let g in this.currentPageDocCounters){if(this.isPageControlledCounter(g)){let m=r[g];if(m){if(m.reset)f[g]=[m.value],o[g]=!0;else if(m.delta!==0){f[g]||(f[g]=[0]);let w=f[g];w[w.length-1]+=m.delta}}continue}f[g]=Array.from(this.currentPageDocCounters[g])}if(this.currentPageCounters=f,s)for(let g in s)this.definePageCounter(g,s[g]);if(h)for(let g in h)if(!this.currentPageCounters[g])this.definePageCounter(g,h[g]);else{let m=this.currentPageCounters[g];m[m.length-1]=h[g]}for(let g in d){if(o[g])continue;this.currentPageCounters[g]||this.definePageCounter(g,0);let m=this.currentPageCounters[g];m[m.length-1]+=d[g]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=Pi(e)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(e){let t=this.unresolvedReferences[e],i=this.resolvedReferences[e];i||(i=this.resolvedReferences[e]=[]);let n=!1;for(let r=0;r<this.referencesToSolve.length;){let o=this.referencesToSolve[r];if(o.targetId===e){if(o.resolve(),this.referencesToSolve.splice(r,1),t){let s=t.indexOf(o);s>=0&&t.splice(s,1)}i.push(o),n=!0}else r++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new Kg(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let o=Pi(this.currentPageCounters),s=this.currentPageDocCounters?Pi(this.currentPageDocCounters):null;i.forEach(a=>{this.pageCountersById[a]=o,s&&(this.pageDocCountersById[a]=s);let h=this.currentPage.elementsById[a];if(h&&h.length>0){let u=h[0];this.pageTextById[a]={content:cn(u,"content"),before:cn(u,"before"),after:cn(u,"after"),marker:cn(u,"marker")}}let l=this.pageIndicesById[a];if(l&&l.pageIndex<t){let u=this.resolvedReferences[a];if(u){let d=this.unresolvedReferences[a];d||(d=this.unresolvedReferences[a]=[]);let p;for(;p=u.shift();)p.unresolve(),d.push(p)}}this.pageIndicesById[a]={spineIndex:e,pageIndex:t}})}let n=this.previousPageCounters,r;for(;r=this.newReferencesOfCurrentPage.shift();){r.pageCounters=n,r.spineIndex=e,r.pageIndex=t;let o;r.isResolved()?(o=this.resolvedReferences[r.targetId],o||(o=this.resolvedReferences[r.targetId]=[])):(o=this.unresolvedReferences[r.targetId],o||(o=this.unresolvedReferences[r.targetId]=[])),o.every(s=>!r.equals(s))&&o.push(r)}this.currentPage=null}adjustPageCountersOfLaterSpines(e,t){if(t<=0)return;let i=new Set;for(let n of Object.keys(this.pageIndicesById))if(this.pageIndicesById[n].spineIndex>e){let r=this.pageCountersById[n];r&&r.page&&!i.has(r)&&(i.add(r),r.page=r.page.map(o=>o+t))}}updateTargetCounterNodesInPages(e){for(let t of e){if(!t||!t.container)continue;let i=t.container.querySelectorAll(`[${zn}]`);for(let n of i){let r=n.getAttribute(zn),o=this.targetCounterExprs.find(s=>s.expr.key===r);if(o&&o.transformedId){let s=this.pageCountersById[o.transformedId];if(s){let a=s[o.name];a&&(n.textContent=o.format(a[a.length-1]))}}}}}getPageCountersForPage(e,t){let i=Object.keys(e.elementsById);for(let n of i){let r=this.pageCountersById[n];if(r)return r}return t||null}updatePageCounterNodesInPages(e,t){var i;for(let n=0;n<e.length;n++){let r=e[n];if(!(r!=null&&r.container))continue;let o=this.getPageCountersForPage(r,t?.[n]);if(!o)continue;let s=r.container.querySelectorAll(`[${Dn}]`);for(let a of s){let h=a.getAttribute(Dn),l=this.pageCounterExprs.find(f=>f.expr.key===h);if(!l)continue;let u=(i=l.expr)==null?void 0:i.str,d=u?.replace(/^page-counters?-/,""),p=o[d];p&&(a.textContent=l.format(p))}}}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(r=>{let o=this.unresolvedReferences[r];o&&(t=t.concat(o))}),t.sort((r,o)=>r.spineIndex-o.spineIndex||r.pageIndex-o.pageIndex);let i=[],n=null;return t.forEach(r=>{!n||n.spineIndex!==r.spineIndex||n.pageIndex!==r.pageIndex?(n={spineIndex:r.spineIndex,pageIndex:r.pageIndex,pageCounters:r.pageCounters,refs:[r]},i.push(n)):n.refs.push(r)}),i}pushReferencesToSolve(e){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=e}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(e,t,i){e==="pages"?this.pagesCounterExprs.push({expr:i,format:t}):this.pageCounterExprs.push({expr:i,format:t})}registerTargetCounterExpr(e,t,i,n){this.targetCounterExprs.push({name:e,expr:i,format:t,transformedId:n})}registerTargetTextExpr(e,t,i){this.targetTextExprs.push({pseudoElement:e,expr:t,transformedId:i})}getExprContentListener(){return this.exprContentListener.bind(this)}exprContentListener(e,t,i){if(e instanceof Re){if(e.str=="viv-leader"){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute("data-viv-leader",e.key),o.setAttribute("data-viv-leader-value",t),o}else if(e.str.startsWith("running-element-")){let o=t&&i.querySelectorAll(`[${Zt}="${t}"]`);if(!o||o.length===0)return null;let s=o[o.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(s),s.style.position="",s.style.visibility="",s}else if(e.str.startsWith("target-counter-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(zn,e.key),o}else if(e.str.startsWith("target-text-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(bs,e.key),o}}let n=this.pagesCounterExprs.findIndex(o=>o.expr===e)>=0,r=!n&&this.pageCounterExprs.findIndex(o=>o.expr===e)>=0;if(n||r){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(n?vs:Dn,e.key),o}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${Dn}]`);for(let r of t){let o=r.getAttribute(Dn),s=this.pageCounterExprs.find(u=>u.expr.key===o),a=(s?.expr).str,h=a?.replace(/^page-counters?-/,""),l=this.currentPageCounters[h];l&&(r.textContent=s.format(l))}let i=e.querySelectorAll(`[${zn}]`);for(let r of i)r.setAttribute(ph,!0);let n=e.querySelectorAll(`[${bs}]`);for(let r of n)r.setAttribute(fh,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${vs}]`),n=e.contentContainer.childElementCount;for(let s of i){let a=s.getAttribute(vs),h=this.pagesCounterExprs.findIndex(l=>l.expr.key===a);h>=0,s.textContent=this.pagesCounterExprs[h].format([n])}let r=e.root.querySelectorAll(`[${ph}]`);for(let s of r){let a=s.getAttribute(zn),h=this.targetCounterExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageCountersById[h.transformedId];if(l){let u=l[h.name];u&&(s.textContent=h.format(u[u.length-1]))}}}let o=e.root.querySelectorAll(`[${fh}]`);for(let s of o){let a=s.getAttribute(bs),h=this.targetTextExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageTextById[h.transformedId];l&&(s.textContent=(t=l[h.pseudoElement])!=null?t:"")}}}createLayoutConstraint(e){return new tm(this,e)}},vs="data-vivliostyle-pages-counter",Dn="data-vivliostyle-page-counter",zn="data-vivliostyle-target-counter",bs="data-vivliostyle-target-text",ph="data-vivliostyle-target-counter-in-running",fh="data-vivliostyle-target-text-in-running",tm=class{constructor(e,t){this.counterStore=e,this.pageIndex=t}allowLayout(e){if(!e||e.after)return!0;let t=e.viewNode;if(!t||t.nodeType!==1)return!0;let i=t.getAttribute("data-vivliostyle-id")||t.getAttribute("id")||t.getAttribute("name");if(!i||!this.counterStore.resolvedReferences[i]&&!this.counterStore.unresolvedReferences[i])return!0;let n=this.counterStore.pageIndicesById[i];return n?this.pageIndex>=n.pageIndex:!0}},im=new Set(["before","after","first-line","first-letter"]),gh=new Set(["media","supports","-epubx-when"]),Cc=new Set([";","}"]),kc=new Set(["{",";","}"]),nm=new Set([";","{","}"]),rm=":where(:scope)",om=":where(:not(*))";function sm(e){let{statements:t,changed:i}=Gs(e,0,e.length,null);return i?t.join(`
5
+ `):e}function Gs(e,t,i,n){let r=[],o=[],s=!1,a=t,h=()=>{o.length!==0&&(n?r.push(am(n,o)):r.push(Ec(o)),o.length=0)};for(;a<i&&(a=$i(e,a,i),!(a>=i||e[a]==="}"));){if(e[a]==="@"){let d=xm(e,a,i);if(!d)break;if(n&&!gh.has(d.name)){o.push(Mi(e.slice(a,d.end))),a=d.end;continue}if(h(),d.hasBlock&&gh.has(d.name)){let p=Gs(e,d.blockStart,d.blockEnd,n);s||(s=p.changed||n!=null),r.push(`${d.header} {${lm(p.statements)}}`)}else r.push(Mi(e.slice(a,d.end)));a=d.end;continue}if(n&&pm(e,a,i)){let d=mm(e,a,i);if(!d)break;o.push(Mi(d.text)),a=d.end;continue}h();let l=wm(e,a,i);if(!l){let d=Sm(e,a,i);r.push(Mi(d.text)),a=d.end;continue}if(n&&ym(e,a,l)){let d=bm(e,a,l.end,i);o.push(Mi(d.text)),a=d.end;continue}let u=n?hm(n,l.prelude):Pc(l.prelude);if(u){s||(s=n!=null);let d=Gs(e,l.blockStart,l.blockEnd,u);s||(s=d.changed),d.statements.length===0?r.push(`${u} {}`):r.push(...d.statements)}a=l.end}return h(),{statements:r,changed:s}}function am(e,t){return`${e} { ${Ec(t)} }`}function Ec(e){return e.map(t=>t.endsWith(";")?t:`${t};`).join(" ")}function lm(e){return e.length===0?"":` ${e.join(" ")} `}function hm(e,t){let i=um(e);if(!i)return null;let n=Tc(t,",").map(r=>r.trim()).filter(Boolean).map(r=>{let o=Nc(r,i);return o.found?o.text:`${i} ${r}`}).filter(Boolean);return n.length===0?null:n.join(", ")}function Pc(e){return Nc(e.trim(),rm).text}function um(e){let t=Tc(e,",").map(i=>i.trim()).filter(Boolean).filter(i=>!cm(i));return t.length===0?null:`:is(${t.join(", ")})`}function cm(e){let t=0;for(;t<e.length;){let i=Jo(e,t);if(i!=null){t=i;continue}let n=ji(e,t,e.length);if(n!=null){t=n;continue}if(e[t]===":"){if(e[t+1]===":")return!0;let r=t+1,o=Tr(e,r,e.length),s=e.slice(r,o).toLowerCase();if(im.has(s))return!0;t=o;continue}t++}return!1}function Nc(e,t){let i=0,n=!1,r="",o=[],s=dm(t);for(;i<e.length;){let a=Jo(e,i);if(a!=null){r+=e.slice(i,a),i=a;continue}let h=ji(e,i,e.length);if(h!=null){r+=e.slice(i,h),i=h;continue}let l=e[i];if(l===":"&&e[i+1]!==":"){let u=i+1,d=Tr(e,u,e.length);if(d>u&&e[d]==="("){o.push(e.slice(u,d).toLowerCase()),r+=e.slice(i,d+1),i=d+1;continue}}if(l==="("){o.push(""),r+=l,i++;continue}if(l===")"){o.pop(),r+=l,i++;continue}if(l==="&"){r+=s&&o.includes("has")?om:t,n=!0,i++;continue}r+=l,i++}return{text:r,found:n}}function dm(e){let t=0;for(;t<e.length;){let i=Jo(e,t);if(i!=null){t=i;continue}let n=ji(e,t,e.length);if(n!=null){t=n;continue}if(e[t]===":"&&e[t+1]!==":"){let r=t+1,o=Tr(e,r,e.length);if(o>r&&e.slice(r,o).toLowerCase()==="has"&&e[o]==="(")return!0;t=o;continue}t++}return!1}function Tc(e,t){let i=[],n=0,r=0,o=0,s=0;for(;r<e.length;){let a=Jo(e,r);if(a!=null){r=a;continue}let h=ji(e,r,e.length);if(h!=null){r=h;continue}let l=e[r];switch(l){case"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":s++;break;case"]":s=Math.max(0,s-1);break;default:o===0&&s===0&&l===t&&(i.push(e.slice(n,r)),n=r+1);break}r++}return i.push(e.slice(n)),i}function pm(e,t,i){let n=t,r=gm(e,n,i);if(r<=n)return!1;let o=$i(e,r,i);if(o>=i||e[o]!==":")return!1;let s=Ir(e,o+1,i,nm);return s?.char==="{"?!fm(e,t,r,o,s.index):!0}function fm(e,t,i,n,r){if($i(e,i,r)!==n)return!1;let o=$i(e,n+1,r);if(o!==n+1||o>=r)return!1;let s=e[o];return s===":"||s==="\\"||/[A-Za-z_-]/.test(s)}function gm(e,t,i){let n=t;return e[n]==="-"&&(n++,n<i&&e[n]==="-"&&n++),Tr(e,n,i)}function Tr(e,t,i){let n=t;for(;n<i;){let r=e[n];if(r==="\\"){n+=2;continue}if(!/[0-9A-Za-z_-]/.test(r))break;n++}return n}function mm(e,t,i){let n=Ir(e,t,i,Cc);if(!n){let o=e.slice(t,i).trim();return o?{text:o,end:i}:null}let r=n.char===";"?n.index+1:n.index;return{text:e.slice(t,r).trim(),end:r}}function wm(e,t,i){let n=Ir(e,t,i,kc);if(!n||n.char!=="{")return null;let r=Ic(e,n.index,i);return r<0?null:{prelude:Mi(e.slice(t,n.index)),blockStart:n.index+1,blockEnd:r,end:r+1}}function ym(e,t,i){if(!vm(e,t,i.blockStart-1))return!0;let n=$i(e,i.blockStart,i.blockEnd);return n<i.blockEnd&&e[n]===";"}function vm(e,t,i){let n=$i(e,t,i);if(n>=i)return!1;let r=e[n];return r==="&"||r==="."||r==="#"||r===":"||r==="["||r==="|"||r==="*"||r===">"||r==="+"||r==="~"||r==="\\"||/[A-Za-z_-]/.test(r)}function bm(e,t,i,n){let r=$i(e,i,n),o=r<n&&e[r]===";"?r+1:i;return{text:e.slice(t,o),end:o}}function xm(e,t,i){let n=Ir(e,t,i,kc);if(!n)return null;let r=Tr(e,t+1,i),o=e.slice(t+1,r).toLowerCase(),s=Mi(e.slice(t,n.index));if(n.char!=="{")return{name:o,header:s,hasBlock:!1,blockStart:-1,blockEnd:-1,end:n.index+(n.char===";"?1:0)};let a=Ic(e,n.index,i);return a<0?null:{name:o,header:s,hasBlock:!0,blockStart:n.index+1,blockEnd:a,end:a+1}}function Sm(e,t,i){let n=Ir(e,t,i,Cc);if(!n)return{text:e.slice(t,i),end:i};let r=n.char===";"?n.index+1:n.index;return{text:e.slice(t,r),end:r}}function Ir(e,t,i,n){let r=t,o=0,s=0,a=0;for(;r<i;){let h=ji(e,r,i);if(h!=null){r=h;continue}let l=e[r];switch(l){case"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":s++;break;case"]":s=Math.max(0,s-1);break;case"{":if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};a++;break;case"}":if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};a=Math.max(0,a-1);break;default:if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};break}r++}return null}function Ic(e,t,i){let n=t+1,r=1;for(;n<i;){let o=ji(e,n,i);if(o!=null){n=o;continue}let s=e[n];if(s==="{")r++;else if(s==="}"&&(r--,r===0))return n;n++}return-1}function $i(e,t,i){let n=t;for(;n<i;){let r=e[n];if(Fc(r)){n++;continue}if(r==="/"&&e[n+1]==="*"){n=Ac(e,n,i);continue}break}return n}function Ac(e,t,i){let n=e.indexOf("*/",t+2);return n<0||n+2>i?i:n+2}function ji(e,t,i){let n=e[t];return n==='"'||n==="'"?Cm(e,t):n==="/"&&e[t+1]==="*"?Ac(e,t,i):null}function Jo(e,t){return e[t]!=="\\"?null:t+1>=e.length?e.length:t+2}function Cm(e,t){let i=e[t],n=t+1;for(;n<e.length;){let r=e[n];if(r==="\\"){n+=2;continue}if(r===i)return n+1;n++}return e.length}function Fc(e){return e===" "||e===`
6
+ `||e==="\r"||e===" "||e==="\f"}function Mi(e){let t="",i=0,n=!1;for(;i<e.length;){let r=ji(e,i,e.length);if(r!=null&&e[i]!=="/"){n&&t.length>0&&(t+=" ",n=!1),t+=e.slice(i,r),i=r;continue}if(r!=null){n=t.length>0,i=r;continue}let o=e[i];if(Fc(o)){n=t.length>0,i++;continue}n&&t.length>0&&(t+=" ",n=!1),t+=o,i++}return t}function km(e){if(e=e.substr(1),e.match(/^[^0-9a-fA-F\n\r]$/))return e;let t=parseInt(e,16);return isNaN(t)?"":t===0||t>=55296&&t<=57343||t>1114111?"\uFFFD":String.fromCodePoint(t)}function pi(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,km)}var Em=class{constructor(){c(this,"type"),c(this,"precededBySpace",!1),c(this,"num",0),c(this,"text",""),c(this,"position",0),this.type=0}toString(){switch(this.type){case 10:return"(";case 11:return")";case 12:return"{";case 13:return"}";case 14:return"[";case 15:return"]";case 16:return",";case 17:return";";case 18:return":";case 19:return"/";case 21:return"%";case 22:return"?";case 23:return"+";case 24:return"-";case 25:return"||";case 26:return"&&";case 31:return"!";case 32:return"$";case 33:return"^";case 34:return"|";case 35:return"~";case 36:return"*";case 37:return">";case 38:return"<";case 39:return"=";case 41:return"!=";case 42:return"$=";case 43:return"^=";case 44:return"|=";case 45:return"~=";case 46:return"*=";case 47:return">=";case 48:return"<=";case 49:return"==";case 50:return"::";case 51:return"<!--";case 52:return"-->";case 3:return this.num.toString()+this.text;case 4:case 5:return this.num.toString();case 20:return"@"+this.text;case 7:return"#"+this.text;case 6:return this.text+"(";case 9:return"."+this.text;case 0:return"/*EOF*/";default:return this.text}}};function Ke(e,t){let i=Array(128),n;for(n=0;n<128;n++)i[n]=e;for(i[NaN]=e==35?35:72,n=0;n<t.length;n+=2)i[t[n]]=t[n+1];return i}var Xt=[72,72,72,72,72,72,72,72,72,1,1,72,1,1,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,1,4,34,6,7,8,9,33,10,11,12,13,14,15,16,17,2,2,2,2,2,2,2,2,2,2,18,19,20,21,22,23,24,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,25,29,26,30,3,72,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,27,31,28,32,72];Xt[NaN]=80;var qt=[43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,52,43,43,43,43,39,43,43,39,39,39,39,39,39,39,39,39,39,43,43,43,43,43,43,43,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,43,44,43,43,39,43,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,43,43,43,43,43];qt[NaN]=43;var Pm=[72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,78,59,72,59,59,59,59,59,59,59,59,59,59,72,72,72,72,72,72,72,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,72,61,72,72,78,72,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,72,72,72,72,72];qt[NaN]=43;var Rc=[35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,57,59,35,58,58,58,58,58,58,58,58,58,58,35,35,35,35,35,35,35,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,35,61,35,35,60,35,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,35,35,35,35,35];Rc[NaN]=35;var Lc=[45,45,45,45,45,45,45,45,45,73,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,73,45,45,45,45,45,45,45,53,45,45,45,45,45,45,45,39,39,39,39,39,39,39,39,39,39,45,45,45,45,45,45,45,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,45,44,45,45,39,45,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,45,45,45,45,45];Lc[NaN]=45;var js=[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,41,37,37,37,37,37,37,37,37,42,37,39,39,39,39,39,39,39,39,39,39,37,37,37,37,37,37,37,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,37,37,37,37,40,37,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,37,37,37,37,37];js[NaN]=37;var Xs=[38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,41,38,38,38,38,38,38,38,38,38,38,39,39,39,39,39,39,39,39,39,39,38,38,38,38,38,38,38,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,38,38,38,38,40,38,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,38,38,38,38,38];Xs[NaN]=38;var Ni=Ke(35,[61,36]),Nm=Ke(35,[58,77]),Tm=Ke(35,[61,36,124,50]),Im=Ke(35,[38,51]),Am=Ke(35,[42,54]),Fm=Ke(39,[42,55]),Rm=Ke(54,[42,55,47,56]),Lm=Ke(62,[62,82]),Om=Ke(35,[61,36,33,70]),Bm=Ke(62,[45,71]),Mm=Ke(63,[45,81]),xs=Ke(76,[10,72,13,72]),_m=Ke(39,[39,46,10,72,13,72,92,48]),Dm=Ke(39,[34,46,10,72,13,72,92,49]),zm=Ke(39,[39,47,10,74,13,74,92,48]),Vm=Ke(39,[34,47,10,74,13,74,92,49]),mh=Ke(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),Um=Ke(39,[41,67,9,79,10,79,13,79,32,79,92,75,40,72,91,72,93,72,123,72,125,72,NaN,67]),$m=Ke(39,[39,68,10,74,13,74,92,75,NaN,67]),Hm=Ke(39,[34,68,10,74,13,74,92,75,NaN,67]),Wm=Ke(72,[9,39,10,39,13,39,32,39,41,69]),Gm=15,Vt=class{constructor(e,t){this.input=e,this.handler=t,c(this,"indexMask"),c(this,"buffer"),c(this,"tail",0),c(this,"curr",0),c(this,"position",0),this.indexMask=Gm,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new Em}token(){return this.tail==this.curr&&this.fillBuffer(),this.buffer[this.curr]}nthToken(e){return(this.tail-this.curr&this.indexMask)<=e&&this.fillBuffer(),this.buffer[this.curr+e&this.indexMask]}consume(){this.curr=this.curr+1&this.indexMask}fillBuffer(){let e=this.tail,t=this.curr,i=this.indexMask;if(e>=t?t+=i:t--,t==e)throw new Error("F_CSSTOK_INTERNAL");let n=Xt,r=this.input,o=this.position,s=this.buffer,a=0,h=0,l="",u=0,d=!1,p=s[e],f=-9;for(;;){let g=r.charCodeAt(o);switch(n[g]||n[65]){case 72:isNaN(g)?(l=r.substring(h,o),a=0):n===Xt&&a===0?(a=54,h=o,l=r.substring(o,o+1),o++):(l=r.substring(h,o),a=54),n=Xt;break;case 1:o++,d=!0;continue;case 2:h=o++,n=js;continue;case 3:a=1,h=o++,n=qt;continue;case 4:h=o++,a=31,n=Ni;continue;case 33:a=2,h=++o,n=_m;continue;case 34:a=2,h=++o,n=Dm;continue;case 6:h=++o,a=7,n=qt;continue;case 7:h=o++,a=32,n=Ni;continue;case 8:h=o++,a=21;break;case 9:h=o++,a=32,n=Im;continue;case 10:h=o++,a=10;break;case 11:h=o++,a=11;break;case 12:h=o++,a=36,n=Ni;continue;case 13:h=o++,a=23;break;case 14:h=o++,a=16;break;case 15:a=24,h=o++,n=Rc;continue;case 16:h=o++,n=Pm;continue;case 78:h=o++,a=9,n=qt;continue;case 17:h=o++,a=19,n=Am;continue;case 18:h=o++,a=18,n=Nm;continue;case 77:o++,a=50;break;case 19:h=o++,a=17;break;case 20:h=o++,a=38,n=Om;continue;case 21:h=o++,a=39,n=Ni;continue;case 22:h=o++,a=37,n=Ni;continue;case 23:h=o++,a=22;break;case 24:h=++o,a=20,n=qt;continue;case 25:h=o++,a=14;break;case 26:h=o++,a=15;break;case 27:h=o++,a=12;break;case 28:h=o++,a=13;break;case 29:h=o++,f=h,a=1,n=xs;continue;case 30:h=o++,a=33,n=Ni;continue;case 31:h=o++,a=34,n=Tm;continue;case 32:h=o++,a=35,n=Ni;continue;case 35:break;case 36:o++,a=a+41-31;break;case 37:a=5,u=parseInt(r.substring(h,o),10);break;case 38:a=4,u=parseFloat(r.substring(h,o));break;case 39:o++;continue;case 40:a=3,u=parseFloat(r.substring(h,o)),h=o++,n=qt;continue;case 41:a=3,u=parseFloat(r.substring(h,o)),l="%",h=o++;break;case 42:o++,n=Xs;continue;case 43:if(l=pi(r.substring(h,o)),a===27&&g===63||a===1&&l.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(r.substring(o-1))){a=27,o++;continue}break;case 44:f=o++,n=xs;continue;case 45:l=pi(r.substring(h,o));break;case 46:l=r.substring(h,o),o++;break;case 47:l=pi(r.substring(h,o)),o++;break;case 48:f=o,o+=2,n=zm;continue;case 49:f=o,o+=2,n=Vm;continue;case 50:o++,a=25;break;case 51:o++,a=26;break;case 52:if(l=r.substring(h,o),a==1){if(o++,l.toLowerCase()=="url"){n=mh;continue}a=6}break;case 53:if(l=pi(r.substring(h,o)),a==1){if(o++,l.toLowerCase()=="url"){n=mh;continue}a=6}break;case 54:n=Fm,o++;continue;case 55:n=Rm,o++;continue;case 56:n=Xt,o++;continue;case 57:n=Lm,o++,r[o]!==">"&&(a=1,n=qt);continue;case 81:a=51,l=r.substring(h,++o),n=Xt;break;case 82:a=52,l=r.substring(h,++o),n=Xt;break;case 58:a=5,n=js,o++;continue;case 59:a=4,n=Xs,o++;continue;case 60:a=1,n=qt,o++;continue;case 61:a=1,n=xs,f=o++;continue;case 62:o--;break;case 63:o-=2;break;case 64:h=o++,n=Um;continue;case 65:h=++o,n=$m;continue;case 66:h=++o,n=Hm;continue;case 67:a=8,l=pi(r.substring(h,o)),o++;break;case 69:o++;break;case 70:n=Bm,o++;continue;case 71:n=Mm,o++;continue;case 79:if(o-f<8&&r.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){o++;continue}case 68:a=8,l=pi(r.substring(h,o)),o++,n=Wm;continue;case 74:if(o++,o-f<9&&r.substring(f+1,o).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,l="E_CSS_UNEXPECTED_NEWLINE",n=Xt;break;case 73:if(o-f<9&&r.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){o++,n=qt;continue}l=pi(r.substring(h,o));break;case 75:f=o++;continue;case 76:o++,n=Lc;continue;default:if(n!==Xt){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=o,a=0}if(p.type=a,p.precededBySpace=d,p.num=u,p.text=l,p.position=h,e++,e>=t)break;n=Xt,d=!1,a=0,h=o,l="",u=0,p=s[e&i]}this.position=o,this.tail=e&i}},Xe=null,qs=null;function Ys(){return Xe}function D(e){if(!Xe)throw new Error("E_TASK_NO_CONTEXT");Xe.name||(Xe.name=e);let t=Xe,i=new Qo(t,t.top,e);return t.top=i,i.state=1,i}function jm(e){return new Ym(e||new qm)}function T(e){return new Zs(e)}function kn(e,t,i){let n=D(e);n.handler=i;try{t(n)}catch(r){n.task.raise(r,n)}return n.result()}function Xm(e,t){return(Xe?Xe.getScheduler():qs||jm()).run(e,t)}var qm=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Ym=class{constructor(e){this.timer=e,c(this,"timeout",1),c(this,"slice",25),c(this,"sliceOverTime",0),c(this,"queue"),c(this,"wakeupTime",null),c(this,"timeoutToken",null),c(this,"inTimeSlice",!1),c(this,"order",0),this.queue=new ig,qs||(qs=this)}setSlice(e){this.slice=e}setTimeout(e){this.timeout=e}isTimeSliceOver(){return this.timer.currentTime()>=this.sliceOverTime}arm(){if(this.inTimeSlice)return;let e=this.queue.peek().scheduledTime,t=this.timer.currentTime();if(this.timeoutToken!=null){if(t+this.timeout>this.wakeupTime)return;this.timer.clearTimeout(this.timeoutToken)}let i=e-t;i<=this.timeout&&(i=this.timeout),this.wakeupTime=t+i,this.timeoutToken=this.timer.setTimeout(()=>{this.timeoutToken=null,this.doTimeSlice()},i)}schedule(e,t){let i=e,n=this.timer.currentTime();i.order=this.order++,i.scheduledTime=n+(t||0),this.queue.add(i),this.arm()}doTimeSlice(){this.timeoutToken!=null&&(this.timer.clearTimeout(this.timeoutToken),this.timeoutToken=null),this.inTimeSlice=!0;try{let e=this.timer.currentTime();for(this.sliceOverTime=e+this.slice;this.queue.length();){let t=this.queue.peek();if(t.scheduledTime>e||(this.queue.remove(),t.canceled||t.resumeInternal(),e=this.timer.currentTime(),e>=this.sliceOverTime))break}}catch(e){j.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new Zm(this,t||"");i.top=new Qo(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let r=()=>{i.running=!1;for(let o of i.callbacks)try{o()}catch(s){j.error(s)}};try{e().then(o=>{i.result=o,r()})}catch(o){i.raise(o),r()}});let n=Xe;return Xe=i,this.schedule(i.top.suspend("bootstrap")),Xe=n,i}},Oc=class{constructor(e){this.task=e,c(this,"scheduledTime",0),c(this,"order",0),c(this,"result",null),c(this,"canceled",!1)}compare(e){let t=e;return t.scheduledTime-this.scheduledTime||t.order-this.order}getTask(){return this.task}schedule(e,t){this.result=e,this.task.scheduler.schedule(this,t)}resumeInternal(){let e=this.task;if(this.task=null,e&&e.continuation==this){e.continuation=null;let t=Xe;return Xe=e,e.top.finish(this.result),Xe=t,!0}return!1}cancel(){this.canceled=!0}},Zm=class{constructor(e,t){this.scheduler=e,this.name=t,c(this,"callbacks",[]),c(this,"exception",null),c(this,"running",!0),c(this,"result",null),c(this,"waitTarget",null),c(this,"top",null),c(this,"continuation",null)}getName(){return this.name}interrupt(e){if(this.raise(e||new Error("E_TASK_INTERRUPT")),this!==Xe&&this.continuation){this.continuation.cancel();let t=new Oc(this);this.waitTarget="interrupt",this.continuation=t,this.scheduler.schedule(t)}}getScheduler(){return this.scheduler}isRunning(){return this.running}whenDone(e){this.callbacks.push(e)}join(){let e=D("Task.join");if(!this.running)e.finish(this.result);else{let t=e.suspend(this);this.whenDone(()=>{t.schedule(this.result)})}return e.result()}unwind(){for(;this.top&&!this.top.handler;)this.top=this.top.parent;if(this.top&&this.top.handler&&this.exception){let e=this.exception;this.exception=null,this.top.handler(this.top,e)}else this.exception&&j.error(this.exception,"Unhandled exception in task",this.name)}raise(e,t){if(this.fillStack(e),t){let i=this.top;for(;i&&i!=t;)i=i.parent;i==t&&(this.top=i)}this.exception=e,this.unwind()}fillStack(e){let t=e.frameTrace;if(!t){t=e.stack?`${e.stack}
5
7
  ---- async ---
6
8
  `:"";for(let i=this.top;i;i=i.parent)t+=" ",t+=i.getName(),t+=`
7
- `;e.frameTrace=t}}},Lo=class Qu{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new Qu(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},Vg=class{constructor(e){this.frame=e}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new Ds(this.frame.task,this.frame.parent,"AsyncResult.thenAsync");return t.state=1,this.frame.parent=t,this.frame.then(i=>{e(i).then(n=>{t.finish(n)})}),t.result()}else return e(this.frame.res)}thenReturn(e){return this.isPending()?this.thenAsync(()=>new Lo(e)):new Lo(e)}thenFinish(e){this.isPending()?this.then(t=>{e.finish(t)}):e.finish(this.frame.res)}isPending(){return this.frame.state==1}get(){if(this.isPending())throw new Error("Result is pending");return this.frame.res}},Ds=class{constructor(e,t,i){this.task=e,this.parent=t,this.name=i,c(this,"res",null),c(this,"state"),c(this,"callback",null),c(this,"handler",null),this.state=0}checkEnvironment(){if(!Ue)throw new Error("F_TASK_NO_CONTEXT");if(this!==Ue.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new Vg(this)}finish(e){this.checkEnvironment(),Ue&&!Ue.exception&&(this.res=e),this.state=2;let t=this.parent;if(Ue&&(Ue.top=t),this.callback){try{this.callback(e)}catch(i){this.task.raise(i,t)}this.state=3}}getTask(){return this.task}getName(){return this.name}getScheduler(){return this.task.scheduler}then(e){switch(this.state){case 1:if(this.callback)throw new Error("F_TASK_FRAME_ALREADY_HAS_CALLBACK");this.callback=e;break;case 2:{let t=this.task,i=this.parent;try{e(this.res),this.state=3}catch(n){this.state=3,t.raise(n,i)}break}case 3:throw new Error("F_TASK_DEAD_FRAME");default:throw new Error(`F_TASK_UNEXPECTED_FRAME_STATE ${this.state}`)}}timeSlice(){let e=M("Frame.timeSlice");return e.getScheduler().isTimeSliceOver()?(W.debug("-- time slice --"),e.suspend().schedule(!0)):e.finish(!0),e.result()}sleep(e){let t=M("Frame.sleep");return t.suspend().schedule(!0,e),t.result()}loop(e){let t=M("Frame.loop"),i=n=>{try{for(;n;){let r=e();if(r.isPending()){r.then(i);return}else r.then(s=>{n=s})}t.finish(!0)}catch(r){t.task.raise(r,t)}};return i(!0),t.result()}loopWithFrame(e){let t=Ue;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new Ug(t,t.top);t.top=n,n.state=1,e(n),i=n.result()}while(!i.isPending()&&i.get());return i})}suspend(e){if(this.checkEnvironment(),this.task.continuation)throw new Error("E_TASK_ALREADY_SUSPENDED");let t=new Ju(this.task);return this.task.continuation=t,Ue=null,this.task.waitTarget=e||null,t}},Ug=class extends Ds{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},yr=class{constructor(e,t){this.fetch=e,c(this,"name"),c(this,"arrived",!1),c(this,"resource",null),c(this,"task",null),c(this,"piggybacks",[]),this.name=t}start(){this.task||(this.task=Fo().getScheduler().run(()=>{let e=M("Fetcher.run");return this.fetch().then(t=>{let i=this.piggybacks;if(this.arrived=!0,this.resource=t,this.task=null,this.piggybacks=[],i)for(let n=0;n<i.length;n++)try{i[n](t)}catch(r){W.error(r,"Error:")}e.finish(t)}),e.result()},this.name))}piggyback(e){this.arrived?e(this.resource):this.piggybacks.push(e)}get(){return this.arrived?N(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},vn=e=>{if(e.length==0)return N(!0);if(e.length==1)return e[0].get().thenReturn(!0);let t=M("waitForFetches"),i=0;return t.loop(()=>{for(;i<e.length;){let n=e[i++];if(!n.hasArrived())return n.get().thenReturn(!0)}return N(!1)}).then(()=>{t.finish(!0)}),t.result()},ec=`
9
+ `;e.frameTrace=t}}},Zs=class Bc{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new Bc(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},Km=class{constructor(e){this.frame=e}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new Qo(this.frame.task,this.frame.parent,"AsyncResult.thenAsync");return t.state=1,this.frame.parent=t,this.frame.then(i=>{e(i).then(n=>{t.finish(n)})}),t.result()}else return e(this.frame.res)}thenReturn(e){return this.isPending()?this.thenAsync(()=>new Zs(e)):new Zs(e)}thenFinish(e){this.isPending()?this.then(t=>{e.finish(t)}):e.finish(this.frame.res)}isPending(){return this.frame.state==1}get(){if(this.isPending())throw new Error("Result is pending");return this.frame.res}},Qo=class{constructor(e,t,i){this.task=e,this.parent=t,this.name=i,c(this,"res",null),c(this,"state"),c(this,"callback",null),c(this,"handler",null),this.state=0}checkEnvironment(){if(!Xe)throw new Error("F_TASK_NO_CONTEXT");if(this!==Xe.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new Km(this)}finish(e){this.checkEnvironment(),Xe&&!Xe.exception&&(this.res=e),this.state=2;let t=this.parent;if(Xe&&(Xe.top=t),this.callback){try{this.callback(e)}catch(i){this.task.raise(i,t)}this.state=3}}getTask(){return this.task}getName(){return this.name}getScheduler(){return this.task.scheduler}then(e){switch(this.state){case 1:if(this.callback)throw new Error("F_TASK_FRAME_ALREADY_HAS_CALLBACK");this.callback=e;break;case 2:{let t=this.task,i=this.parent;try{e(this.res),this.state=3}catch(n){this.state=3,t.raise(n,i)}break}case 3:throw new Error("F_TASK_DEAD_FRAME");default:throw new Error(`F_TASK_UNEXPECTED_FRAME_STATE ${this.state}`)}}timeSlice(){let e=D("Frame.timeSlice");return e.getScheduler().isTimeSliceOver()?(j.debug("-- time slice --"),e.suspend().schedule(!0)):e.finish(!0),e.result()}sleep(e){let t=D("Frame.sleep");return t.suspend().schedule(!0,e),t.result()}loop(e){let t=D("Frame.loop"),i=n=>{try{for(;n;){let r=e();if(r.isPending()){r.then(i);return}else r.then(o=>{n=o})}t.finish(!0)}catch(r){t.task.raise(r,t)}};return i(!0),t.result()}loopWithFrame(e){let t=Xe;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new Jm(t,t.top);t.top=n,n.state=1,e(n),i=n.result()}while(!i.isPending()&&i.get());return i})}suspend(e){if(this.checkEnvironment(),this.task.continuation)throw new Error("E_TASK_ALREADY_SUSPENDED");let t=new Oc(this.task);return this.task.continuation=t,Xe=null,this.task.waitTarget=e||null,t}},Jm=class extends Qo{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},Ar=class{constructor(e,t){this.fetch=e,c(this,"name"),c(this,"arrived",!1),c(this,"resource",null),c(this,"task",null),c(this,"piggybacks",[]),this.name=t}start(){this.task||(this.task=Ys().getScheduler().run(()=>{let e=D("Fetcher.run");return this.fetch().then(t=>{let i=this.piggybacks;if(this.arrived=!0,this.resource=t,this.task=null,this.piggybacks=[],i)for(let n=0;n<i.length;n++)try{i[n](t)}catch(r){j.error(r,"Error:")}e.finish(t)}),e.result()},this.name))}piggyback(e){this.arrived?e(this.resource):this.piggybacks.push(e)}get(){return this.arrived?T(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},En=e=>{if(e.length==0)return T(!0);if(e.length==1)return e[0].get().thenReturn(!0);let t=D("waitForFetches"),i=0;return t.loop(()=>{for(;i<e.length;){let n=e[i++];if(!n.hasArrived())return n.get().thenReturn(!0)}return T(!1)}).then(()=>{t.finish(!0)}),t.result()},Mc=`
8
10
  @media screen {
9
11
  [data-vivliostyle-viewer-viewport] {
10
12
  background: #aaaaaa;
@@ -73,7 +75,7 @@ var Dp=Object.create;var Nr=Object.defineProperty;var zp=Object.getOwnPropertyDe
73
75
  transform-origin: center top;
74
76
  }
75
77
  }
76
- `,tc=`
78
+ `,_c=`
77
79
  [data-vivliostyle-layout-box] {
78
80
  position: absolute;
79
81
  left: 0;
@@ -196,7 +198,7 @@ var Dp=Object.create;var Nr=Object.defineProperty;var zp=Object.getOwnPropertyDe
196
198
  break-after: page;
197
199
  }
198
200
  }
199
- `,ic=`
201
+ `,Dc=`
200
202
  /*
201
203
  * Copyright 2013 Google, Inc.
202
204
  * Copyright 2015 Daishinsha Inc.
@@ -829,7 +831,7 @@ word-wrap = overflow-wrap;
829
831
  [adapt,webkit]start = inline-start;
830
832
  [adapt,webkit]end = inline-end;
831
833
 
832
- `,nc=`
834
+ `,zc=`
833
835
  <!DOCTYPE html>
834
836
  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://www.pyroxy.com/ns/shadow">
835
837
  <head>
@@ -837,6 +839,7 @@ word-wrap = overflow-wrap;
837
839
 
838
840
  .-vivliostyle-footnote-content {
839
841
  float: footnote;
842
+ --viv-semantic-footnote-content: 1;
840
843
  }
841
844
 
842
845
  .-vivliostyle-table-cell-container {
@@ -852,7 +855,7 @@ word-wrap = overflow-wrap;
852
855
  <s:template id="table-cell"><div data-vivliostyle-flow-root="true" class="-vivliostyle-table-cell-container"><s:content/></div></s:template>
853
856
 
854
857
  </body>
855
- </html>`,rc=`
858
+ </html>`,Vc=`
856
859
  @namespace "http://www.w3.org/1999/xhtml";
857
860
 
858
861
  :root {
@@ -975,7 +978,7 @@ word-wrap = overflow-wrap;
975
978
  margin: 10%;
976
979
  }
977
980
  }
978
- `,sc=String.raw`
981
+ `,Uc=String.raw`
979
982
  @namespace "http://www.w3.org/1999/xhtml";
980
983
  @namespace m "http://www.w3.org/1998/Math/MathML";
981
984
  @namespace epub "http://www.idpf.org/2007/ops";
@@ -1323,10 +1326,13 @@ m|math[display="block"] {
1323
1326
 
1324
1327
  /* CSS GCPM footnotes */
1325
1328
  ::footnote-marker {
1326
- content: counter(footnote) ". ";
1327
1329
  list-style-position: inside;
1328
1330
  }
1329
- ::footnote-call {
1331
+ /* Semantic DPUB/EPUB footnotes provide their own default call/marker path. */
1332
+ :not(aside[epub|type~="footnote"], aside[epub\:type~="footnote"], aside[role~="doc-footnote"])::footnote-marker {
1333
+ content: counter(footnote) ". ";
1334
+ }
1335
+ :not(a[epub|type~="noteref"], a[epub\:type~="noteref"], a[role~="doc-noteref"])::footnote-call {
1330
1336
  content: counter(footnote);
1331
1337
  font-size: 0.75em;
1332
1338
  vertical-align: super;
@@ -1335,23 +1341,18 @@ m|math[display="block"] {
1335
1341
 
1336
1342
  /* EPUB/DPUB footnotes */
1337
1343
 
1338
- a[epub|type="noteref"],
1339
- a[epub\:type="noteref"],
1340
- a[role="doc-noteref"] {
1344
+ a[epub|type="noteref"]:not(sup > *, :has(> sup)),
1345
+ a[epub\:type="noteref"]:not(sup > *, :has(> sup)),
1346
+ a[role="doc-noteref"]:not(sup > *, :has(> sup)) {
1341
1347
  font-size: 0.75em;
1342
1348
  vertical-align: super;
1343
1349
  line-height: 0;
1344
1350
  }
1345
1351
 
1346
- sup > a[epub|type="noteref"],
1347
- a[epub|type="noteref"] > sup,
1348
- sup > a[epub\:type="noteref"],
1349
- a[epub\:type="noteref"] > sup,
1350
- sup > a[role="doc-noteref"],
1351
- a[role="doc-noteref"] > sup {
1352
- font-size: unset;
1353
- vertical-align: unset;
1354
- line-height: unset;
1352
+ a[epub|type="noteref"][data-vivliostyle-footnote-first-ref],
1353
+ a[epub\:type="noteref"][data-vivliostyle-footnote-first-ref],
1354
+ a[role="doc-noteref"][data-vivliostyle-footnote-first-ref] {
1355
+ counter-increment: footnote;
1355
1356
  }
1356
1357
 
1357
1358
  a[epub|type="noteref"]:href-epub-type(footnote, aside),
@@ -1408,7 +1409,7 @@ epub|case[required-namespace::supported] ~ epub|case {
1408
1409
  epub|case[required-namespace::supported] ~ epub|default {
1409
1410
  display: none;
1410
1411
  }
1411
- `,oc=`
1412
+ `,$c=`
1412
1413
  @namespace "http://www.w3.org/1999/xhtml";
1413
1414
 
1414
1415
  *:not([data-vivliostyle-role=doc-toc],
@@ -1438,7 +1439,7 @@ epub|case[required-namespace::supported] ~ epub|default {
1438
1439
  [data-vivliostyle-role=doc-toc]:is(ol,ul) {
1439
1440
  -adapt-behavior: toc-container;
1440
1441
  }
1441
- `,ac=`
1442
+ `,Hc=`
1442
1443
  [data-viv-margin-discard~="block-start"] {
1443
1444
  margin-block-start: 0 !important;
1444
1445
  }
@@ -1574,10 +1575,6 @@ span[data-viv-leader] {
1574
1575
  white-space: pre;
1575
1576
  text-transform: none;
1576
1577
  }
1577
- [style*="--viv-footnote-inline-separator"]::after {
1578
- content: var(--viv-footnote-inline-separator);
1579
- white-space: normal;
1580
- }
1581
1578
  [style*="--viv-footnote-white-space"] {
1582
1579
  white-space: var(--viv-footnote-white-space);
1583
1580
  }
@@ -1614,13 +1611,37 @@ span[data-viv-leader] {
1614
1611
  [style*="--viv-marker-text-combine-upright"]::marker {
1615
1612
  text-combine-upright: var(--viv-marker-text-combine-upright);
1616
1613
  }
1614
+ [style*="--viv-marker-text-orientation"]::marker {
1615
+ text-orientation: var(--viv-marker-text-orientation);
1616
+ }
1617
+ [style*="--viv-marker-hyphens"]::marker {
1618
+ hyphens: var(--viv-marker-hyphens);
1619
+ }
1620
+ [style*="--viv-marker-line-height"]::marker {
1621
+ line-height: var(--viv-marker-line-height);
1622
+ }
1623
+ [style*="--viv-marker-tab-size"]::marker {
1624
+ tab-size: var(--viv-marker-tab-size);
1625
+ }
1626
+ [style*="--viv-marker-text-emphasis-style"]::marker {
1627
+ text-emphasis-style: var(--viv-marker-text-emphasis-style);
1628
+ }
1629
+ [style*="--viv-marker-text-emphasis-color"]::marker {
1630
+ text-emphasis-color: var(--viv-marker-text-emphasis-color);
1631
+ }
1632
+ [style*="--viv-marker-text-emphasis-position"]::marker {
1633
+ text-emphasis-position: var(--viv-marker-text-emphasis-position);
1634
+ }
1635
+ [style*="--viv-marker-text-shadow"]::marker {
1636
+ text-shadow: var(--viv-marker-text-shadow);
1637
+ }
1617
1638
 
1618
1639
  /* initial-letter */
1619
1640
  [style*="--viv-initialLetter"]:has(>[data-adapt-pseudo="first-letter"])::first-letter {
1620
1641
  -webkit-initial-letter: var(--viv-initialLetter);
1621
1642
  initial-letter: var(--viv-initialLetter);
1622
1643
  }
1623
- `,lc=String.raw`
1644
+ `,Wc=String.raw`
1624
1645
  @counter-style decimal-leading-zero {
1625
1646
  system: extends decimal;
1626
1647
  pad: 2 '0';
@@ -1844,12 +1865,12 @@ span[data-viv-leader] {
1844
1865
  @counter-style upper-russian {
1845
1866
  system: alphabetic;
1846
1867
  symbols: \u0410 \u0411 \u0412 \u0413 \u0414 \u0415 \u0416 \u0417 \u0418 \u041A \u041B \u041C \u041D \u041E \u041F \u0420 \u0421 \u0422 \u0423 \u0424 \u0425 \u0426 \u0427 \u0428 \u0429 \u042D \u042E \u042F;
1847
- }`;function zs(e,t,i){let n=M("fetchFromURL"),r={method:i||"GET",mode:"cors"},s=n.suspend(),o={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(e,r).then(a=>{var h;if(o.status=a.status,o.url=a.url,o.statusText=a.statusText,o.contentType=(h=a.headers.get("Content-Type"))==null?void 0:h.replace(/;.*$/,"").toLowerCase(),!a.ok)throw new Error(`HTTP ${a.status}${a.statusText?` ${a.statusText}`:""}`);return t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?(o.contentType="text/html",a.arrayBuffer().then(l=>new TextDecoder("Shift_JIS").decode(l))):(/^data:,(<|%3c)/i.test(e)&&(o.contentType="text/html"),a.text())}).then(a=>{t==="blob"&&a instanceof Blob?o.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?o.responseBlob=hc([a]):t==="json"?o.responseText=JSON.stringify(a):typeof a=="string"&&(o.responseText=a),s.schedule(o)}).catch(a=>{o.status>=400?W.warn(`Error fetching ${e} (${o.status}${o.statusText?" "+o.statusText:""})`):W.warn(a,`Error fetching ${e}`),s.schedule(o)}),n.result()}function hc(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Hg(e){let t=M("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function $g(e){return URL.createObjectURL(e)}var _a=class{constructor(e,t){this.parser=e,this.type=t,c(this,"resources",{}),c(this,"fetchers",{})}load(e,t,i){e=Wt(e);let n=this.resources[e];return typeof n<"u"?N(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=M("fetch"),r=e.endsWith("?viv-toc-box");r&&(e=e.replace("?viv-toc-box",""));let s=Ee("user-agent.xml",fi),o=!r&&e===s;return o&&(e=`data:application/xml,${encodeURIComponent(nc)}`),zs(e,this.type).then(a=>{if(a.status>=400&&t)throw new Error((i||`Failed to fetch required resource: ${e}`)+` (${a.status}${a.statusText?" "+a.statusText:""})`);r?(e+="?viv-toc-box",a.url+="?viv-toc-box"):o&&(a.url=e=s),this.parser(a,this).then(h=>{delete this.fetchers[e],this.resources[e]=h,n.finish(h)})}),n.result()}fetch(e,t,i){if(e=Wt(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new yr(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[Wt(e)]}delete(e){delete this.resources[Wt(e)]}};function Wg(e,t){let i=e.responseText;return N(i?Ta(i):null)}function Gg(){return new _a(Wg,"text")}function Ut(e,t,i){let n=new yr(()=>{let r=M("loadElement"),s=r.suspend(e),o=!1,a=null,h=l=>{o||(o=!0,a!==null&&(clearTimeout(a),a=null),s.schedule(l?l.type:"timeout"))};if(e.addEventListener("load",h,!1),e.addEventListener("error",h,!1),e.addEventListener("abort",h,!1),e.namespaceURI=="http://www.w3.org/2000/svg")t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(h,300);else if(e.localName==="script")a=setTimeout(h,3e3);else if(t)if(e.localName==="img"){let l=e;l.loading==="lazy"&&(l.loading="eager"),l.src=t,i&&(l.alt=i),l.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4)}else e.src=t,i&&(e.alt=i);return r.result()},`loadElement ${t||e.localName}`);return n.start(),n}var Xl=0,jg=16777216,uc=33554432,cc=50331648,dc=67108864,Xg=83886080,qg=100663296,Da=class{constructor(e){this.scope=e,c(this,"flavor"),this.flavor="Author"}getCurrentToken(){return null}getScope(){return this.scope}error(e,t){}startStylesheet(e){this.flavor=e}tagSelector(e,t){}classSelector(e){}pseudoclassSelector(e,t){}pseudoelementSelector(e,t){}idSelector(e){}attributeSelector(e,t,i,n){}descendantSelector(){}childSelector(){}adjacentSiblingSelector(){}followingSiblingSelector(){}nextSelector(){}startSelectorRule(){}startFontFaceRule(){}startCounterStyleRule(e){}startFootnoteRule(e){}startViewportRule(){}startDefineRule(){}startRegionRule(){}startPageRule(){}startPageMarginBoxRule(e){}startWhenRule(e){}startMediaRule(e){this.startWhenRule(e)}startFlowRule(e){}startPageTemplateRule(){}startPageMasterRule(e,t,i){}startPartitionRule(e,t,i){}startPartitionGroupRule(e,t,i){}startRuleBody(){}property(e,t,i){}endRule(){}startFuncWithSelector(e,t){}endFuncWithSelector(){}pushSelectorText(e){}getImportantSpecificity(){switch(this.flavor){case"UA":return Xl;case"User":return qg;default:return Xg}}getBaseSpecificity(){switch(this.flavor){case"UA":return Xl;case"User":return jg;default:return uc}}},Yg=class extends Da{constructor(){super(null),c(this,"stack",[]),c(this,"tokenizer",null),c(this,"slave",null)}pushHandler(e){this.stack.push(this.slave),this.slave=e}popHandler(){this.slave=this.stack.pop()}getCurrentToken(){return this.tokenizer?this.tokenizer.token():null}getScope(){return this.slave.getScope()}error(e,t){this.slave.error(e,t)}errorMsg(e,t){var i;W.warn(e,(i=t?.toString())!=null?i:"")}startStylesheet(e){super.startStylesheet(e),this.stack.length>0&&(this.slave=this.stack[0],this.stack=[]),this.slave.startStylesheet(e)}tagSelector(e,t){this.slave.tagSelector(e,t)}classSelector(e){this.slave.classSelector(e)}pseudoclassSelector(e,t){this.slave.pseudoclassSelector(e,t)}pseudoelementSelector(e,t){this.slave.pseudoelementSelector(e,t)}idSelector(e){this.slave.idSelector(e)}attributeSelector(e,t,i,n){this.slave.attributeSelector(e,t,i,n)}descendantSelector(){this.slave.descendantSelector()}childSelector(){this.slave.childSelector()}adjacentSiblingSelector(){this.slave.adjacentSiblingSelector()}followingSiblingSelector(){this.slave.followingSiblingSelector()}nextSelector(){this.slave.nextSelector()}startSelectorRule(){this.slave.startSelectorRule()}startFontFaceRule(){this.slave.startFontFaceRule()}startCounterStyleRule(e){this.slave.startCounterStyleRule(e)}startFootnoteRule(e){this.slave.startFootnoteRule(e)}startViewportRule(){this.slave.startViewportRule()}startDefineRule(){this.slave.startDefineRule()}startRegionRule(){this.slave.startRegionRule()}startPageRule(){this.slave.startPageRule()}startPageMarginBoxRule(e){this.slave.startPageMarginBoxRule(e)}startWhenRule(e){this.slave.startWhenRule(e)}startFlowRule(e){this.slave.startFlowRule(e)}startPageTemplateRule(){this.slave.startPageTemplateRule()}startPageMasterRule(e,t,i){this.slave.startPageMasterRule(e,t,i)}startPartitionRule(e,t,i){this.slave.startPartitionRule(e,t,i)}startPartitionGroupRule(e,t,i){this.slave.startPartitionGroupRule(e,t,i)}startRuleBody(){this.slave.startRuleBody()}property(e,t,i){this.slave.property(e,t,i)}endRule(){this.slave.endRule()}startFuncWithSelector(e,t){this.slave.startFuncWithSelector(e,t)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},ql=class extends Da{constructor(e,t,i){super(e),this.owner=t,this.topLevel=i,c(this,"depth",0),t&&(this.flavor=t.flavor)}getCurrentToken(){var e;return(e=this.owner)==null?void 0:e.getCurrentToken()}error(e,t){var i;(i=this.owner)==null||i.errorMsg(e,t)}startRuleBody(){this.depth++}endRule(){--this.depth==0&&!this.topLevel&&this.owner.popHandler()}},In=class extends ql{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new ql(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startCounterStyleRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_COUNTER_STYLE")}startFootnoteRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FOOTNOTE")}startViewportRule(){this.reportAndSkip("E_CSS_UNEXPECTED_VIEWPORT")}startDefineRule(){this.reportAndSkip("E_CSS_UNEXPECTED_DEFINE")}startRegionRule(){this.reportAndSkip("E_CSS_UNEXPECTED_REGION")}startPageRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE")}startWhenRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startFlowRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(e,t){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(e,t,i){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},Le=[],fs=[],xe=[],Ae=[],Nt=[],ct=[],Fe=[],We=[],ve=[],qe=[],rt=[],$e=[],Re=[],Ki=55,Ji=56,Fr=57;Le[1]=28,Le[36]=29,Le[7]=29,Le[9]=29,Le[14]=29,Le[18]=29,Le[50]=29,Le[20]=30,Le[13]=27,Le[0]=200,fs[1]=46,fs[0]=200,ct[1]=2,ct[36]=4,ct[7]=6,ct[9]=8,ct[14]=10,ct[18]=14,ct[50]=42,xe[37]=11,xe[23]=12,xe[35]=56,xe[1]=1,xe[36]=3,xe[7]=5,xe[9]=7,xe[14]=9,xe[12]=13,xe[18]=55,xe[50]=58,xe[16]=41,Ae[37]=11,Ae[23]=12,Ae[35]=56,Ae[1]=1,Ae[36]=3,Ae[7]=5,Ae[9]=7,Ae[14]=9,Ae[18]=55,Nt[1]=2,Nt[36]=4,Nt[7]=6,Nt[9]=8,Nt[18]=14,Nt[50]=42,Nt[14]=10,Nt[12]=13,Fe[1]=15,Fe[7]=16,Fe[4]=17,Fe[5]=18,Fe[3]=19,Fe[2]=20,Fe[8]=21,Fe[27]=57,Fe[16]=22,Fe[19]=23,Fe[6]=24,Fe[11]=25,Fe[17]=26,Fe[13]=48,Fe[31]=47,Fe[23]=54,Fe[0]=44,We[1]=31,We[4]=32,We[5]=32,We[3]=33,We[2]=34,We[10]=40,We[6]=38,We[31]=36,We[24]=36,We[32]=35,ve[1]=45,ve[16]=37,ve[37]=37,ve[38]=37,ve[47]=37,ve[48]=37,ve[39]=37,ve[49]=37,ve[41]=37,ve[26]=37,ve[25]=37,ve[23]=37,ve[24]=37,ve[19]=37,ve[21]=37,ve[36]=37,ve[18]=37,ve[22]=37,ve[11]=39,ve[12]=43,ve[17]=49,qe[0]=200,qe[12]=50,qe[13]=51,qe[14]=50,qe[15]=51,qe[10]=50,qe[11]=51,qe[17]=53,rt[0]=200,rt[12]=50,rt[13]=52,rt[14]=50,rt[15]=51,rt[10]=50,rt[11]=51,rt[17]=53,$e[0]=200,$e[12]=50,$e[13]=51,$e[14]=50,$e[15]=51,$e[10]=50,$e[11]=51,Re[11]=0,Re[16]=0,Re[22]=1,Re[18]=1,Re[26]=2,Re[25]=2,Re[38]=3,Re[37]=3,Re[48]=3,Re[47]=3,Re[39]=3,Re[49]=3,Re[41]=3,Re[23]=4,Re[24]=4,Re[36]=5,Re[19]=5,Re[21]=5,Re[0]=6,Re[Ki]=2,Re[Ji]=2;var br=class{constructor(e,t,i,n){this.actions=e,this.tokenizer=t,this.handler=i,this.baseURL=n,c(this,"valStack",[]),c(this,"namespacePrefixToURI",{}),c(this,"defaultNamespaceURI",null),c(this,"propName",null),c(this,"propImportant",!1),c(this,"exprContext"),c(this,"result",null),c(this,"importReady",!1),c(this,"importURL",null),c(this,"importCondition",null),c(this,"errorBrackets",[]),c(this,"ruleStack",[]),c(this,"regionRule",!1),c(this,"pageRule",!1),c(this,"inStyleDeclaration",!1),this.exprContext=2}extractVals(e,t){let i=[],n=this.valStack;for(;t<n.length&&(i.push(n[t++]),t!==n.length);){if(n[t++]!==e)throw new Error("Unexpected state");t===n.length&&i.push(Y)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,r=0,s;do if(s=i[--n],e===")"&&s instanceof Xi){if(s.text===")")r++;else if(s.text==="("){if(r===0)return null;r--}}while(typeof s<"u"&&typeof s!="string");let o=i.length-(n+1);if(o>1&&i.splice(n+1,o,new te(i.slice(n+1,i.length))),e==",")return null;n++;do s=i[--n];while(typeof s<"u"&&(typeof s!="string"||s==","));if(o=i.length-(n+1),s=="("){e!=")"&&t.type!==0&&(this.handler.error("E_CSS_MISMATCHED_C_PAR",t),this.actions=rt);let h=new Ui(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,o+2,h),h.name==="var"){let l=h.values[0]instanceof de&&h.values[0].name;(!jt(l)||l===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${h.toString()}`,t),this.actions=rt)}return h}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=rt,null;if(o>1)return new tt(this.extractVals(",",n+1));let a=i[0];return a instanceof it?a:a?new Xi(a.toString()):Y}exprError(e,t){this.actions=this.propName?rt:qe,W.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,r=i.pop(),s;for(;;){let o=i.pop();if(e==11){let a=[r];for(;o==16;)a.unshift(i.pop()),o=i.pop();if(typeof o=="string"){if(o=="{"){for(;a.length>=2;){let h=a.shift(),l=a.shift(),u=new Tf(n.getScope(),h,l);a.unshift(u)}return i.push(new $(a[0])),!0}else if(o=="("){let h=i.pop(),l=i.pop();r=new Yn(n.getScope(),So(l,h),a),e=0;continue}}if(o==10){r.isMediaName()&&(r=new Nl(n.getScope(),r,null)),e=0;continue}}else if(typeof o=="string"){i.push(o);break}if(o<0)if(o==-31)r=new mi(n.getScope(),r);else if(o==-24)r=new rn(n.getScope(),r);else if(o==-Fr)r=new Pf(n.getScope(),r);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(Re[e]>Re[o]){i.push(o);break}switch(s=i.pop(),o){case 26:r=new Ra(n.getScope(),s,r);break;case Ki:r=new Nf(n.getScope(),s,r);break;case Ji:r=new If(n.getScope(),s,r);break;case 25:r=new Fa(n.getScope(),s,r);break;case 38:r=new Af(n.getScope(),s,r);break;case 37:r=new Ff(n.getScope(),s,r);break;case 48:r=new Rf(n.getScope(),s,r);break;case 47:r=new Eo(n.getScope(),s,r);break;case 39:case 49:r=new La(n.getScope(),s,r);break;case 41:r=new Lf(n.getScope(),s,r);break;case 23:r=new xu(n.getScope(),s,r);break;case 24:r=new Su(n.getScope(),s,r);break;case 36:r=new Oa(n.getScope(),s,r);break;case 19:r=new Cu(n.getScope(),s,r);break;case 21:r=new ku(n.getScope(),s,r);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),r=new Mf(n.getScope(),i.pop(),s,r);break;case 10:if(s.isMediaName())r=new Nl(n.getScope(),s,r);else return this.exprError("E_CSS_MEDIA_TEST",t),!1;break}else return this.exprError("E_CSS_EXPR_COND",t),!1;break;case 22:if(e!=18)return this.exprError("E_CSS_EXPR_COND",t),!1;case 10:return i.push(s),i.push(o),i.push(r),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(r),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,r;if(t)r=e.text,n=e.position+r.length+1;else if(e.type===10){let u=i.nthToken(1),d=i.nthToken(2);if(u.type===1&&d.type===18)i.consume(),i.consume(),r=u.text,n=d.position+1;else{if(u.type===10||u.type===6||u.type===1&&u.text.toLowerCase()==="not"&&(d.type===10||d.type===6))return null;n=e.position+1}}else return null;let s=0,o,a=0;for(;s>=0;)switch(i.consume(),o=i.token(),o.type){case 11:s--;break;case 10:case 6:s++;break;case 16:s===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",o),null}i.consume();let h=o.position,l=t&&r==="selector"&&a>0?"":i.input.substring(n,h).trim();return new _f(this.handler.getScope(),r,l,t)}readPseudoParams(){let e=[];for(;;){let t=this.tokenizer.token();switch(t.type){case 1:e.push(t.text);break;case 23:e.push("+");break;case 4:case 5:e.push(t.num);break;default:return e}this.tokenizer.consume()}}readNthPseudoParams(){let e=!1,t=this.tokenizer.token();if(t.type===23)e=!0,this.tokenizer.consume(),t=this.tokenizer.token();else if(t.type===1&&(t.text==="even"||t.text==="odd"))return this.tokenizer.consume(),[2,t.text==="odd"?1:0];switch(t.type){case 3:if(e&&t.num<0)return null;case 1:if(e&&t.text.charAt(0)==="-")return null;if(t.text==="n"||t.text==="-n"){if(e&&t.precededBySpace)return null;let i=t.text==="-n"?-1:1;t.type===3&&(i=t.num);let n=0;this.tokenizer.consume(),t=this.tokenizer.token();let r=t.type===24,s=t.type===23||r;if(s&&(this.tokenizer.consume(),t=this.tokenizer.token()),t.type===5){if(n=t.num,1/n===-1/0){if(n=0,s)return null}else if(n<0){if(s)return null}else if(n>=0&&!s)return null;this.tokenizer.consume()}else if(s)return null;return[i,r&&n>0?-n:n]}else if(t.text==="n-"||t.text==="-n-"){if(e&&t.precededBySpace)return null;let i=t.text==="-n-"?-1:1;if(t.type===3&&(i=t.num),this.tokenizer.consume(),t=this.tokenizer.token(),t.type===5)return t.num<0||1/t.num===-1/0?null:(this.tokenizer.consume(),[i,t.num])}else{let i=t.text.match(/^n(-[0-9]+)$/);if(i)return e&&t.precededBySpace?null:(this.tokenizer.consume(),[t.type===3?t.num:1,parseInt(i[1],10)]);if(i=t.text.match(/^-n(-[0-9]+)$/),i)return this.tokenizer.consume(),[-1,parseInt(i[1],10)]}return null;case 5:return e&&(t.precededBySpace||t.num<0)?null:(this.tokenizer.consume(),[0,t.num])}return null}makeCondition(e,t){let i=this.handler.getScope();if(!i)return null;if(t=t||i._true,e){let n=e.split(/\s+/);for(let r of n)switch(r){case"vertical":t=At(i,t,new mi(i,new je(i,"pref-horizontal")));break;case"horizontal":t=At(i,t,new je(i,"pref-horizontal"));break;case"day":t=At(i,t,new mi(i,new je(i,"pref-night-mode")));break;case"night":t=At(i,t,new je(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new $(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"counter-style":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":case"footnote":return!0}return!1}runParser(e,t,i,n,r,s){let o=this.handler,a=this.tokenizer,h=this.valStack,l,u,d,p,f,g,m,w=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),r&&w===null&&(w=l.position-1,a.input[w]==="("&&w++),this.actions===Fe&&this.errorBrackets.length>0&&(l.type===this.errorBrackets[this.errorBrackets.length-1]||l.type===17||l.type===31)){if(l.type===this.errorBrackets[this.errorBrackets.length-1]&&(this.errorBrackets.pop(),l.type===11&&this.valStackReduce(")",l))){a.consume();continue}h.push(new Xi(l.toString())),a.consume();continue}switch(this.actions[l.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(o.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=rt):(this.actions=ct,o.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Fe,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=rt,o.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Fe,h.splice(0,h.length);continue;case 29:this.actions=ct,o.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=$e,o.error("E_CSS_SPACE_EXPECTED",l);continue}o.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),d=this.namespacePrefixToURI[l.text],d!=null)switch(l=a.token(),l.type){case 1:o.tagSelector(d,l.text),r?this.actions=Ae:this.actions=xe,a.consume();break;case 36:o.tagSelector(d,null),r?this.actions=Ae:this.actions=xe,a.consume();break;default:this.actions=qe,o.error("E_CSS_NAMESPACE",l)}else this.actions=qe,o.error("E_CSS_UNDECLARED_PREFIX",l);else o.tagSelector(this.defaultNamespaceURI,l.text),r?this.actions=Ae:this.actions=xe,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=$e,o.error("E_CSS_SPACE_EXPECTED",l);continue}o.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),l=a.token(),l.type){case 1:o.tagSelector(null,l.text),r?this.actions=Ae:this.actions=xe,a.consume();break;case 36:o.tagSelector(null,null),r?this.actions=Ae:this.actions=xe,a.consume();break;default:this.actions=qe,o.error("E_CSS_NAMESPACE",l)}else o.tagSelector(this.defaultNamespaceURI,null),r?this.actions=Ae:this.actions=xe,a.consume();continue;case 5:l.precededBySpace&&o.descendantSelector();case 6:if(!l.text){o.error("E_CSS_SYNTAX",l),a.consume();continue}o.idSelector(l.text),r?this.actions=Ae:this.actions=xe,a.consume();continue;case 7:l.precededBySpace&&o.descendantSelector();case 8:o.classSelector(l.text),r?this.actions=Ae:this.actions=xe,a.consume();continue;case 55:l.precededBySpace&&o.descendantSelector();case 14:a.consume(),l=a.token();e:switch(l.type){case 1:o.pseudoclassSelector(l.text,null),a.consume(),r?this.actions=Ae:this.actions=xe;continue;case 6:switch(p=l.text,a.consume(),p){case"is":case"not":case"where":case"has":this.actions=ct,o.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=xe:this.actions=$e;continue;case"lang":case"href-epub-type":case"href-role-type":if(l=a.token(),l.type===1){m=[l.text],a.consume(),(p==="href-epub-type"||p==="href-role-type")&&a.token().type===16&&(a.consume(),l=a.token(),l.type===1&&(m.push(l.text),a.consume()));break}else break e;case"nth-child":case"nth-of-type":case"nth-last-child":case"nth-last-of-type":case"nth":if(m=this.readNthPseudoParams(),m)if(p==="nth-child"||p==="nth-last-child"){if(u=a.nthToken(0),u.type===1&&u.text==="of"){a.consume(),this.actions=ct,o.startFuncWithSelector(p,m),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?r?this.actions=Ae:this.actions=xe:this.actions=$e;continue}break}else if(p==="nth"){if(u=a.nthToken(0),u.type===1&&u.text==="of")if(a.consume(),u=a.token(),u.type===1)m.push(u.text),a.consume();else break e;break}else break;else break e;default:m=this.readPseudoParams()}if(l=a.token(),l.type==11){o.pseudoclassSelector(p,m),a.consume(),r?this.actions=Ae:this.actions=xe;continue}break}o.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=qe;continue;case 58:l.precededBySpace&&o.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:o.pseudoelementSelector(l.text,null),r?this.actions=Ae:this.actions=xe,a.consume();continue;case 6:if(p=l.text,a.consume(),p=="nth-fragment"){if(m=this.readNthPseudoParams(),m===null)break}else m=this.readPseudoParams();if(l=a.token(),l.type==11){o.pseudoelementSelector(p,m),r?this.actions=Ae:this.actions=xe,a.consume();continue}break}o.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=qe;continue;case 9:l.precededBySpace&&o.descendantSelector();case 10:if(a.consume(),l=a.token(),l.type==1)p=l.text,a.consume();else if(l.type==36)p=null,a.consume();else if(l.type==34)p="";else{this.actions=$e,o.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(d=p&&this.namespacePrefixToURI[p],d===void 0){this.actions=$e,o.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=$e,o.error("E_CSS_ATTR_NAME_EXPECTED",l);continue}p=l.text,a.consume(),l=a.token()}else d="";switch(l.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=l.type,a.consume(),l=a.token();break;case 15:o.attributeSelector(d,p,0,null),r?this.actions=Ae:this.actions=xe,a.consume();continue;default:this.actions=$e,o.error("E_CSS_ATTR_OP_EXPECTED",l);continue}switch(l.type){case 1:case 2:o.attributeSelector(d,p,f,l.text),a.consume(),l=a.token();break;default:this.actions=$e,o.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=$e,o.error("E_CSS_ATTR",l);continue}r?this.actions=Ae:this.actions=xe,a.consume();continue;case 11:o.childSelector(),this.actions=Nt,a.consume();continue;case 12:o.adjacentSiblingSelector(),this.actions=Nt,a.consume();continue;case 56:o.followingSiblingSelector(),this.actions=Nt,a.consume();continue;case 13:this.regionRule?(this.ruleStack.push("-epubx-region"),this.regionRule=!1):this.pageRule?(this.ruleStack.push("page"),this.pageRule=!1,this.inStyleDeclaration=!0):(this.ruleStack.push("[selector]"),this.inStyleDeclaration=!0),o.startRuleBody(),this.actions=Le,a.consume();continue;case 41:o.nextSelector(),this.actions=ct,a.consume();continue;case 15:h.push(B(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new Lu(l.text)),a.consume();continue;case 17:h.push(new vt(l.num)),a.consume();continue;case 18:h.push(new Be(l.num)),a.consume();continue;case 19:h.push(new F(l.num,l.text)),a.consume();continue;case 20:h.push(new j(l.text)),a.consume();continue;case 21:h.push(new ot(Ee(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new Ou(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(Tn),a.consume();continue;case 24:p=l.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=We,this.exprContext=0,h.push("{")):(h.push(p),h.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),a.consume();continue;case 25:this.valStackReduce(")",l),a.consume();continue;case 47:if(a.consume(),l=a.token(),u=a.nthToken(1),l.type==1&&l.text.toLowerCase()=="important"&&(u.type==17||u.type==0||u.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",l);continue;case 54:switch(u=a.nthToken(1),u.type){case 4:case 3:case 5:if(!u.precededBySpace){a.consume();continue}}h.push(new Xi("+")),a.consume();continue;case 26:a.consume();case 48:g=this.valStackReduce(";",l),g&&this.propName&&o.property(this.propName,g,this.propImportant),this.actions=i?fs:Le;continue;case 44:for(a.consume();h.length>0;){let b=h.length;if(g=this.valStackReduce(";",l),!g||h.length===b)break}return t?(this.result=g,!0):(this.propName&&g&&o.property(this.propName,g,this.propImportant),!0);case 31:if(u=a.nthToken(1),u.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(h.push(l.text,u.text,"("),a.consume()):(h.push(new je(o.getScope(),So(l.text,u.text))),this.actions=ve),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new Pl(o.getScope(),!0,u.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=u),h.push(new Pl(o.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==Ki&&h[h.length-1]!==Ji&&(u.type===10||u.type===6)){h.push(-Fr),a.consume();continue}else h.push(new je(o.getScope(),l.text));this.actions=ve}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=ve;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new Ye(o.getScope(),l.num)),a.consume(),this.actions=ve;continue;case 33:p=l.text,p=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?p="vh":p="vw"),h.push(new gr(o.getScope(),l.num,p)),a.consume(),this.actions=ve;continue;case 34:h.push(new Ye(o.getScope(),l.text)),a.consume(),this.actions=ve;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new Tu(o.getScope(),l.num)),a.consume(),this.actions=ve);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=We,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==Ji&&h[h.length-2]!==-Fr?(this.actions=We,this.exprStackReduce(Ki,l),h.push(Ki),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==Ki&&h[h.length-2]!==-Fr?(this.actions=We,this.exprStackReduce(Ji,l),h.push(Ji),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=Fe),a.consume();continue;case 43:this.exprStackReduce(11,l)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",l):(this.exprContext==1?o.startWhenRule(h.pop()):o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Le)),a.consume();continue;case 49:if(this.exprStackReduce(11,l))return this.propName||this.exprContext!=3?(this.exprError("E_CSS_UNEXPECTED_SEMICOL",l),this.actions=Le,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=Le,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let b=this.readSupportsTest(l);if(b){h.push(b),this.actions=ve;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=Le,a.consume(),o.endRule(),this.inStyleDeclaration=!1,this.ruleStack.length)switch(this.ruleStack.pop(),this.ruleStack[this.ruleStack.length-1]){case"page":case"-epubx-page-master":case"-epubx-partition-group":this.inStyleDeclaration=!0}continue;case 30:switch(p=l.text.toLowerCase(),p){case"import":if(a.consume(),l=a.token(),l.type==2||l.type==8){if(this.importURL=l.text,a.consume(),l=a.token(),l.type==17||l.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=We,h.push("{");continue}o.error("E_CSS_IMPORT_SYNTAX",l),this.actions=qe;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(p=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[p]=l.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=l.text,a.consume(),a.consume();continue}break}o.error("E_CSS_NAMESPACE_SYNTAX",l),this.actions=qe;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){p=l.text.toLowerCase(),p!="utf-8"&&p!="utf-16"&&o.error(`E_CSS_UNEXPECTED_CHARSET ${p}`,l),a.consume(),a.consume();continue}o.error("E_CSS_CHARSET_SYNTAX",l),this.actions=qe;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(a.nthToken(1).type==12){switch(a.consume(),a.consume(),p){case"font-face":o.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":o.startPageTemplateRule();break;case"-epubx-define":o.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":o.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(p),o.startRuleBody();continue}break;case"-epubx-region":a.consume(),o.startRegionRule(),this.regionRule=!0,this.actions=ct;continue;case"page":a.consume(),o.startPageRule(),this.pageRule=!0,this.actions=Nt;continue;case"-adapt-footnote-area":case"footnote":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),o.startFootnoteRule(null),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){let b=l.text;a.consume(),a.consume(),o.startFootnoteRule(b),this.ruleStack.push(p==="footnote"?"footnote":"-adapt-footnote-area"),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),l=a.token(),l.type==12){a.consume(),o.startPageMarginBoxRule(p),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=We,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=We,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=We,h.push("{");continue;case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){o.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"counter-style":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){o.startCounterStyleRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{a.consume(),l=a.token();let b=null,x=null,y=[];for(l.type==1&&(b=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(x=a.nthToken(1).text,a.consume(),a.consume(),l=a.token());l.type==6&&l.text.toLowerCase()=="class"&&a.nthToken(1).type==1&&a.nthToken(2).type==11;)y.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),l=a.token();if(l.type==12){switch(a.consume(),p){case"-epubx-page-master":o.startPageMasterRule(b,x,y);break;case"-epubx-partition":o.startPartitionRule(b,x,y);break;case"-epubx-partition-group":o.startPartitionGroupRule(b,x,y);break}this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":o.error(`E_CSS_UNEXPECTED_AT${p}`,l),this.actions=$e;continue;default:o.error(`E_CSS_AT_UNKNOWN ${p}`,l),this.actions=qe;continue}o.error(`E_CSS_AT_SYNTAX ${p}`,l),this.actions=qe;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Le;continue}case 51:if(r&&this.errorBrackets.length==0&&l.type==11)return a.consume(),o.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&l.type==13&&(this.actions=Le),a.consume();continue;case 53:this.errorBrackets.length==0&&(this.actions=Le),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,l)?(this.result=h.pop(),!0):!1;if(r){switch(l.type){case 16:case 11:if(this.actions===ct)o.error("E_CSS_SYNTAX",l);else{let b=a.input.substring(w,l.position);o.pushSelectorText(b),w=l.position+1}if(l.type===16){o.nextSelector(),this.actions=ct,a.consume();continue}else return o.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(s){this.actions=xe;continue}break;case 12:case 14:case 10:this.errorBrackets.push(l.type+1);break}o.error("E_CSS_SYNTAX",l),a.consume(),this.actions=$e;continue}if(this.actions!==qe&&this.actions!==$e&&this.actions!==rt){if(l.type==54)o.error("E_CSS_SYNTAX",l);else if(this.actions===Fe){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new Xi(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==We&&h.length>0){o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Le,a.consume();continue}else{if(l.type===17&&this.actions==We)return this.actions=Le,a.consume(),!1;o.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=rt:this.actions=$e;continue}a.consume();continue}}return!1}},pc=class extends Da{constructor(e){super(null),this.scope=e}error(e,t){W.warn(e,t.toString())}getScope(){return this.scope}};function Zg(e,t,i,n,r){let s=M("parseStylesheet"),o=new br(Le,e,t,i),a=null;return r&&(a=Jg(new Xt(r,t),t,i)),a=o.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),s.loop(()=>{for(;!o.runParser(100,!1,!1,!1,!1);){if(o.importReady){let l=Ee(o.importURL,i);o.importCondition&&(t.startMediaRule(o.importCondition),t.startRuleBody());let u=M("parseStylesheet.import");return fc(l,t,null,null).then(()=>{o.importCondition&&t.endRule(),o.importReady=!1,o.importURL=null,o.importCondition=null,u.finish(!0)}),u.result()}let h=s.timeSlice();if(h.isPending)return h}return N(!1)}).then(()=>{a&&t.endRule(),s.finish(!0)}),s.result()}function za(e,t,i,n,r){return bn("parseStylesheetFromText",s=>{let o=new Xt(e,t);Zg(o,t,i,n,r).thenFinish(s)},(s,o)=>{W.warn(o,`Failed to parse stylesheet text: ${e}`),s.finish(!1)})}function fc(e,t,i,n){return bn("parseStylesheetFromURL",r=>{zs(e).then(s=>{s.responseText?za(s.responseText,t,e,i,n).then(o=>{o||W.warn(`Failed to parse stylesheet from ${e}`),r.finish(!0)}):r.finish(!0)})},(r,s)=>{W.warn(s,"Exception while fetching and parsing:",e),r.finish(!0)})}function vr(e,t,i){let n=new br(Fe,t,new pc(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function Kg(e,t,i){new br(fs,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Jg(e,t,i){let n=new br(We,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var Qg={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function em(e){return!!Qg[e]}function tm(e,t,i){if(t instanceof Ie&&t.str==="viv-leader")return new $(t);if(i==="content"&&t instanceof Ie)return new $(t);let n=t.evaluate(e);switch(typeof n){case"number":return em(i)?n==Math.round(n)?new Be(n):new vt(n):new F(n,"px");case"string":return n?i==="content"?new j(n):vr(t.scope,new Xt(n,null),""):Y;case"boolean":return n?v._true:v._false;case"undefined":return Y}throw new Error("E_UNEXPECTED")}function gc(e,t){let i={};return Object.keys(e).forEach(n=>{let r=i[n]={},s=e[n];Object.keys(s).forEach(o=>{r[o]=s[o].map(a=>{let h=t?a.logical:a.physical,l=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function mc(e,t,i,n){let r=n[t];if(!r)throw new Error(`unknown writing-mode: ${t}`);let s=r[i||"ltr"];if(!s)throw new Error(`unknown direction: ${i}`);for(let o of s){let a=e.replace(o.regexp,o.to);if(a!==e)return a}return e}var wc={"horizontal-tb":{ltr:[{logical:"inline-start",physical:"left"},{logical:"inline-end",physical:"right"},{logical:"block-start",physical:"top"},{logical:"block-end",physical:"bottom"},{logical:"inline-size",physical:"width"},{logical:"block-size",physical:"height"}],rtl:[{logical:"inline-start",physical:"right"},{logical:"inline-end",physical:"left"},{logical:"block-start",physical:"top"},{logical:"block-end",physical:"bottom"},{logical:"inline-size",physical:"width"},{logical:"block-size",physical:"height"}]},"vertical-rl":{ltr:[{logical:"inline-start",physical:"top"},{logical:"inline-end",physical:"bottom"},{logical:"block-start",physical:"right"},{logical:"block-end",physical:"left"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}],rtl:[{logical:"inline-start",physical:"bottom"},{logical:"inline-end",physical:"top"},{logical:"block-start",physical:"right"},{logical:"block-end",physical:"left"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}]},"vertical-lr":{ltr:[{logical:"inline-start",physical:"top"},{logical:"inline-end",physical:"bottom"},{logical:"block-start",physical:"left"},{logical:"block-end",physical:"right"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}],rtl:[{logical:"inline-start",physical:"bottom"},{logical:"inline-end",physical:"top"},{logical:"block-start",physical:"left"},{logical:"block-end",physical:"right"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}]}},im=gc(wc,!0);function yc(e,t,i){return mc(e,t,i||null,im)}var nm=gc(wc,!1);function bc(e,t,i){return mc(e,t,i||null,nm)}var rm={"horizontal-tb":[{logical:"line-left",physical:"left"},{logical:"line-right",physical:"right"},{logical:"over",physical:"top"},{logical:"under",physical:"bottom"}],"vertical-rl":[{logical:"line-left",physical:"top"},{logical:"line-right",physical:"bottom"},{logical:"over",physical:"right"},{logical:"under",physical:"left"}],"vertical-lr":[{logical:"line-left",physical:"top"},{logical:"line-right",physical:"bottom"},{logical:"over",physical:"right"},{logical:"under",physical:"left"}]};function sm(e,t){let i=rm[t];if(!i)throw new Error(`unknown writing-mode: ${t}`);for(let n=0;n<i.length;n++)if(i[n].physical===e)return i[n].logical;return e}function Va(e,t,i){var n;let r=t,s={width:r.style.width,height:r.style.height};function o(p){return e.getElementComputedStyle(t).getPropertyValue(p)}let a=o("writing-mode")!=="horizontal-tb",h=a?"height":"width",l=a?"width":"height";function u(p,f){r.style[p]=f;let g=o(p);return r.style[p]=s[p],g}let d={};for(let p of i){let f;switch(p){case"max-content inline size":f=u(h,"max-content");break;case"min-content inline size":f=u(h,"min-content");break;case"fit-content inline size":f=u(h,"fit-content");break;case"max-content block size":f=u(l,"max-content");break;case"min-content block size":f=u(l,"min-content");break;case"fit-content block size":f=u(l,"fit-content");break;case"max-content width":f=u("width","max-content");break;case"max-content height":f=u("height","max-content");break;case"min-content width":f=u("width","min-content");break;case"min-content height":f=u("height","min-content");break;case"fit-content width":f=u("width","fit-content");break;case"fit-content height":f=u("height","fit-content");break}f==="0px"&&t.childNodes.length===1&&((n=t.firstElementChild)==null?void 0:n.localName)==="img"&&!t.firstElementChild.complete&&(f="1px"),d[p]=parseFloat(f)}return d}function on(e){var t,i;return((t=e?.style)==null?void 0:t["box-decoration-break"])==="clone"||((i=e?.style)==null?void 0:i["-webkit-box-decoration-break"])==="clone"}function vc(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function xc(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function gt(e,t){let i=vc(e);i.includes(t)||(i.push(t),xc(e,i))}function om(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function am(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function oo(e,t){let i=om(e);i.includes(t)||(i.push(t),am(e,i))}function lm(e){let t=e.name,i=e.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:i===v.always?v.page:i,important:e.important};default:return e}}var Oo={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ge(e){return!!Oo[e]}var hm={left:!0,right:!0,recto:!0,verso:!0};function xn(e){return!!hm[e]}function Yl(e){return Ge(e)&&e!=="column"&&e!=="region"}var um={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function gs(e){return!!um[e]}function et(e,t){if(e)if(t){if(xn(t))return t;if(xn(e))return e;{let i=Ge(e),n=Ge(t);if(i&&n)switch(t){case"column":return e;case"region":return e==="column"?t:e;default:return t}else return n?t:i?e:gs(t)?t:gs(e)?e:t}}else return e;else return t}function Zl(e){return Ge(e)?e:"auto"}kt("SIMPLE_PROPERTY",lm);var Zn=tf(rf());function cm(e,t){return(0,Zn.default)(e,t,0)}function Kl(e){return e.reduce((t,i)=>i[0]===Zn.default.DELETE?t:t+i[1],"")}function dm(e,t){return Sc(e,t,1)}function pm(e,t){return Sc(e,t,-1)}function Sc(e,t,i){let n=0,r=0;return e.some(s=>{for(let o=0;o<s[1].length;o++){switch(s[0]*i){case Zn.default.INSERT:n++;break;case Zn.default.DELETE:n--,r++;break;case Zn.default.EQUAL:r++;break}if(r>t)return!0}return!1}),Math.max(Math.min(t,r-1)+n,0)}var Bo;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(Bo||(Bo={}));var gn;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(gn||(gn={}));var ms;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(ms||(ms={}));var Mi;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||bi.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||bi.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(Mi||(Mi={}));var bi;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(bi||(bi={}));var ri;(e=>{let t;(n=>(n[n.IGNORE=0]="IGNORE",n[n.NEWLINE=1]="NEWLINE",n[n.PRESERVE=2]="PRESERVE"))(t=e.Whitespace||(e.Whitespace={}));let i;(n=>(n[n.NONE=0]="NONE",n[n.CONTENT=1]="CONTENT",n[n.ROOTLESS=2]="ROOTLESS",n[n.ROOTED=3]="ROOTED"))(i=e.ShadowType||(e.ShadowType={}))})(ri||(ri={}));var fm={transform:!0,"transform-origin":!0},gm={top:!0,bottom:!0,left:!0,right:!0},Ua=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},mm={show:function(e){e.style.visibility="visible"},hide:function(e){e.style.visibility="hidden"},play:function(e){e.currentTime=0,e.play()},pause:function(e){e.pause()},resume:function(e){e.play()},mute:function(e){e.muted=!0},unmute:function(e){e.muted=!1}};function wm(e,t){let i=mm[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Mo=class Un extends Ia{constructor(t,i){super(),this.container=t,this.bleedBox=i,c(this,"pageAreaElement",null),c(this,"delayedItems",[]),c(this,"hrefHandler"),c(this,"elementsById",{}),c(this,"dimensions",{width:0,height:0}),c(this,"isFirstPage",!1),c(this,"isLastPage",!1),c(this,"isBlankPage",!1),c(this,"isAutoPageWidth",!0),c(this,"isAutoPageHeight",!0),c(this,"spineIndex",0),c(this,"position",null),c(this,"offset",-1),c(this,"side",null),c(this,"fetchers",[]),c(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),c(this,"pageType",null),this.hrefHandler=n=>{let r=n.currentTarget,s=r.getAttribute("href")||r.getAttributeNS("http://www.w3.org/1999/xlink","href");if(s){let o={type:"hyperlink",target:null,currentTarget:null,anchorElement:r,href:s,preventDefault(){n.preventDefault()}};this.dispatchEvent(o)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute(Un.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Un.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(Un.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Un.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(t,i){let n=this.elementsById[i];n?n.push(t):this.elementsById[i]=[t]}finish(t,i){Object.keys(this.elementsById).forEach(s=>{let o=this.elementsById[s];for(let a=0;a<o.length;)this.container.contains(o[a])?a++:o.splice(a,1);o.length===0&&delete this.elementsById[s]});let n=this.delayedItems;for(let s=0;s<n.length;s++){let o=n[s];o.target===this.container&&o.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||I(o.target,o.name,o.value.toString())}let r=i.getElementClientRect(this.container);this.dimensions.width=r.width,this.dimensions.height=r.height;for(let s=0;s<t.length;s++){let o=t[s],a=this.elementsById[o.ref],h=this.elementsById[o.observer];if(a&&h){let l=wm(a,o.action);if(l)for(let u=0;u<h.length;u++)h[u].addEventListener(o.event,l,!1)}}}};c(Mo,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),c(Mo,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var Cc=Mo,dt=ri.Whitespace;function kc(e){switch(e){case"normal":case"nowrap":return dt.IGNORE;case"pre-line":return dt.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return dt.PRESERVE;default:return null}}function Me(e,t){return e?e.nodeType==1?!1:Ec(e.textContent,t):!0}function Ec(e,t){switch(t){case dt.PRESERVE:return e.length==0;case dt.NEWLINE:return!!e.match(/^[ \t]*$/);case dt.IGNORE:default:return!!e.match(/^[ \t\r\n\f]*$/)}}var ym=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,c(this,"forcedBreakOffsets",[]),c(this,"formattingContext",null)}},bm=class{constructor(e,t,i,n,r,s,o,a,h){this.flowName=e,this.element=t,this.startOffset=i,this.priority=n,this.linger=r,this.exclusive=s,this.repeated=o,this.last=a,this.breakBefore=h,c(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function vm(e,t){return e.top-t.top}function xm(e,t){return t.right-e.right}function Pc(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===ri.ShadowType.ROOTLESS&&t.shadowType===ri.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&_o(e.shadowContext,t.shadowContext)&&_o(e.nodeShadow,t.nodeShadow)&&Pc(e.shadowSibling,t.shadowSibling)}function vi(e,t){if(e===t)return!0;if(!e||!t||e.offsetInNode!==t.offsetInNode||e.after!==t.after||e.steps.length!==t.steps.length)return!1;for(let i=0;i<e.steps.length;i++)if(!Pc(e.steps[i],t.steps[i]))return!1;return!0}function Sm(e){return{steps:[{node:e,shadowType:ht.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function ws(e,t){return{steps:[{node:e.sourceNode,shadowType:ht.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:e.formattingContext,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function ys(e,t){let i=new Qi(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?ys(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var ht=ri.ShadowType,Wr=class{constructor(e,t,i,n,r,s,o){this.owner=e,this.root=t,this.xmldoc=i,this.parentShadow=n,this.type=s,this.styler=o,c(this,"subShadow",null),r&&(r.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&_o(this.parentShadow,e.parentShadow):!1}};function _o(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Cm=class{constructor(e,t){this.outer=e,this.count=t}},Qi=class Nc{constructor(t,i,n){this.sourceNode=t,this.parent=i,this.boxOffset=n,c(this,"offsetInNode",0),c(this,"after",!1),c(this,"shadowType"),c(this,"shadowContext"),c(this,"nodeShadow",null),c(this,"shadowSibling",null),c(this,"shared",!1),c(this,"inline",!0),c(this,"overflow",!1),c(this,"breakPenalty"),c(this,"display",null),c(this,"floatReference"),c(this,"floatSide",null),c(this,"clearSide",null),c(this,"floatMinWrapBlock",null),c(this,"columnSpan",null),c(this,"captionSide","top"),c(this,"inlineBorderSpacing",0),c(this,"blockBorderSpacing",0),c(this,"flexContainer",!1),c(this,"whitespace"),c(this,"hyphenateCharacter"),c(this,"breakWord"),c(this,"establishesBFC",!1),c(this,"containingBlockForAbsolute",!1),c(this,"breakBefore",null),c(this,"breakAfter",null),c(this,"viewNode",null),c(this,"clearSpacer",null),c(this,"inheritedProps"),c(this,"vertical"),c(this,"direction"),c(this,"firstPseudo"),c(this,"lang",null),c(this,"preprocessedTextContent",null),c(this,"formattingContext"),c(this,"repeatOnBreak",null),c(this,"pluginProps",{}),c(this,"fragmentIndex",1),c(this,"afterIfContinues",null),c(this,"footnotePolicy",null),c(this,"pageType"),this.shadowType=ht.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=gn.FloatReference.INLINE,this.whitespace=i?i.whitespace:dt.IGNORE,this.hyphenateCharacter=i?i.hyphenateCharacter:null,this.breakWord=i?i.breakWord:!1,this.inheritedProps=i?i.inheritedProps:{},this.vertical=i?i.vertical:!1,this.direction=i?i.direction:"ltr",this.firstPseudo=i?i.firstPseudo:null,this.formattingContext=i?i.formattingContext:null,this.pageType=i?i.pageType:null}resetView(){this.inline=!0,this.breakPenalty=this.parent?this.parent.breakPenalty:0,this.viewNode=null,this.clearSpacer=null,this.offsetInNode=0,this.after=!1,this.display=null,this.floatReference=gn.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:dt.IGNORE,this.hyphenateCharacter=this.parent?this.parent.hyphenateCharacter:null,this.breakWord=this.parent?this.parent.breakWord:!1,this.breakBefore=null,this.breakAfter=null,this.nodeShadow=null,this.establishesBFC=!1,this.containingBlockForAbsolute=!1,this.vertical=this.parent?this.parent.vertical:!1,this.nodeShadow=null,this.preprocessedTextContent=null,this.formattingContext=this.parent?this.parent.formattingContext:null,this.repeatOnBreak=null,this.pluginProps={},this.fragmentIndex=1,this.afterIfContinues=null,this.footnotePolicy=null}cloneItem(){let t=new Nc(this.sourceNode,this.parent,this.boxOffset);return t.offsetInNode=this.offsetInNode,t.after=this.after,t.nodeShadow=this.nodeShadow,t.shadowType=this.shadowType,t.shadowContext=this.shadowContext,t.shadowSibling=this.shadowSibling,t.inline=this.inline,t.breakPenalty=this.breakPenalty,t.display=this.display,t.floatReference=this.floatReference,t.floatSide=this.floatSide,t.clearSide=this.clearSide,t.floatMinWrapBlock=this.floatMinWrapBlock,t.columnSpan=this.columnSpan,t.captionSide=this.captionSide,t.inlineBorderSpacing=this.inlineBorderSpacing,t.blockBorderSpacing=this.blockBorderSpacing,t.establishesBFC=this.establishesBFC,t.containingBlockForAbsolute=this.containingBlockForAbsolute,t.flexContainer=this.flexContainer,t.whitespace=this.whitespace,t.hyphenateCharacter=this.hyphenateCharacter,t.breakWord=this.breakWord,t.breakBefore=this.breakBefore,t.breakAfter=this.breakAfter,t.viewNode=this.viewNode,t.clearSpacer=this.clearSpacer,t.firstPseudo=this.firstPseudo,t.vertical=this.vertical,t.overflow=this.overflow,t.preprocessedTextContent=this.preprocessedTextContent,t.formattingContext=this.formattingContext,t.repeatOnBreak=this.repeatOnBreak,t.pluginProps=Object.create(this.pluginProps),t.fragmentIndex=this.fragmentIndex,t.afterIfContinues=this.afterIfContinues,t.footnotePolicy=this.footnotePolicy,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),i=t,n;for(;(n=i.parent)!=null;)n=n.cloneItem(),i.parent=n,i=n;return t}toNodePositionStep(){var t;return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:((t=this.viewNode)==null?void 0:t.parentNode)===null?0:this.fragmentIndex}}toNodePosition(){var t,i,n;let r=this,s=[];r.shadowType===ri.ShadowType.ROOTLESS&&(r.floatReference!==gn.FloatReference.INLINE||r.floatSide==="footnote")&&(n=(i=(t=r.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(r=r.parent);do(!r.firstPseudo||!r.parent||r.parent.firstPseudo===r.firstPseudo)&&s.push(r.toNodePositionStep()),r=r.parent;while(r);let o=this.preprocessedTextContent?pm(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:s,offsetInNode:o,after:this.after,preprocessedTextContent:this.preprocessedTextContent}}isInsideBFC(){let t=this.parent;for(;t;){if(t.establishesBFC)return!0;t=t.parent}return!1}getContainingBlockForAbsolute(){let t=this.parent;for(;t;){if(t.containingBlockForAbsolute)return t;t=t.parent}return null}belongsTo(t){return this.formattingContext===t&&!!this.parent&&this.parent.formattingContext===t}},xi=class Tc{constructor(t){this.primary=t,c(this,"floats",null)}clone(){let t=new Tc(this.primary);if(this.floats){t.floats=[];for(let i=0;i<this.floats.length;++i)t.floats[i]=this.floats[i]}return t}isSamePosition(t){if(!t)return!1;if(this===t)return!0;if(!vi(this.primary,t.primary))return!1;if(this.floats){if(!t.floats||this.floats.length!==t.floats.length)return!1;for(let i=0;i<this.floats.length;i++)if(!vi(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},km=class Ic{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new Ic(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Em=class Ac{constructor(){c(this,"positions",[]),c(this,"startBreakType",null),c(this,"breakAfter",null)}clone(){let t=new Ac,i=this.positions,n=t.positions;for(let r=0;r<i.length;r++)n[r]=i[r].clone();return t.startBreakType=this.startBreakType,t.breakAfter=this.breakAfter,t}isSamePosition(t){if(this===t)return!0;if(!t||this.positions.length!==t.positions.length)return!1;for(let i=0;i<this.positions.length;i++)if(!this.positions[i].isSamePosition(t.positions[i]))return!1;return!0}hasContent(t){return this.positions.length>0&&this.positions[0].flowChunk.startOffset<=t}},Pm=class Rc{constructor(){c(this,"page",0),c(this,"flows",{}),c(this,"flowPositions",{}),c(this,"isBlankPage",!1),c(this,"highestSeenOffset",0),c(this,"highestSeenNode"),c(this,"lookupPositionOffset")}clone(){let t=new Rc;t.page=this.page,t.isBlankPage=this.isBlankPage,t.highestSeenNode=this.highestSeenNode,t.highestSeenOffset=this.highestSeenOffset,t.lookupPositionOffset=this.lookupPositionOffset,t.flows=this.flows;for(let i in this.flowPositions)t.flowPositions[i]=this.flowPositions[i].clone();return t}isSamePosition(t){if(this===t)return!0;if(!t||this.page!==t.page)return!1;let i=Object.keys(this.flowPositions),n=Object.keys(t.flowPositions);if(i.length!==n.length)return!1;for(let r of i)if(!this.flowPositions[r].isSamePosition(t.flowPositions[r]))return!1;return!0}hasContent(t,i){let n=this.flowPositions[t];return n?n.hasContent(i):!1}startSideOfFlow(t){var i;let n=(i=this.flowPositions[t])==null?void 0:i.startBreakType;return n&&xn(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},Fc=class{constructor(e){this.element=e,c(this,"left",0),c(this,"top",0),c(this,"marginLeft",0),c(this,"marginRight",0),c(this,"marginTop",0),c(this,"marginBottom",0),c(this,"borderLeft",0),c(this,"borderRight",0),c(this,"borderTop",0),c(this,"borderBottom",0),c(this,"paddingLeft",0),c(this,"paddingRight",0),c(this,"paddingTop",0),c(this,"paddingBottom",0),c(this,"width",0),c(this,"height",0),c(this,"originX",0),c(this,"originY",0),c(this,"exclusions",null),c(this,"innerShape",null),c(this,"computedBlockSize",0),c(this,"snapWidth",0),c(this,"snapHeight",0),c(this,"snapOffsetX",0),c(this,"snapOffsetY",0),c(this,"vertical",!1),c(this,"rtl",!1),c(this,"borderBoxSizing",!1)}getInsetTop(){return this.marginTop+(this.borderBoxSizing?0:this.borderTop+this.paddingTop)}getInsetBottom(){return this.marginBottom+(this.borderBoxSizing?0:this.borderBottom+this.paddingBottom)}getInsetLeft(){return this.marginLeft+(this.borderBoxSizing?0:this.borderLeft+this.paddingLeft)}getInsetRight(){return this.marginRight+(this.borderBoxSizing?0:this.borderRight+this.paddingRight)}getInsetBefore(){return this.vertical?this.getInsetRight():this.getInsetTop()}getInsetAfter(){return this.vertical?this.getInsetLeft():this.getInsetBottom()}getInsetStart(){return this.vertical?this.getInsetTop():this.getInsetLeft()}getInsetEnd(){return this.vertical?this.getInsetBottom():this.getInsetRight()}getBeforeEdge(e){return this.vertical?e.right:e.top}getAfterEdge(e){return this.vertical?e.left:e.bottom}getStartEdge(e){return this.vertical?this.rtl?e.bottom:e.top:this.rtl?e.right:e.left}getEndEdge(e){return this.vertical?this.rtl?e.top:e.bottom:this.rtl?e.left:e.right}getInlineSize(e){return this.vertical?e.bottom-e.top:e.right-e.left}getBoxSize(e){return this.vertical?e.right-e.left:e.bottom-e.top}getBoxDir(){return this.vertical?-1:1}getInlineDir(){return this.rtl?-1:1}copyFrom(e){this.element=e.element,this.left=e.left,this.top=e.top,this.marginLeft=e.marginLeft,this.marginRight=e.marginRight,this.marginTop=e.marginTop,this.marginBottom=e.marginBottom,this.borderLeft=e.borderLeft,this.borderRight=e.borderRight,this.borderTop=e.borderTop,this.borderBottom=e.borderBottom,this.paddingLeft=e.paddingLeft,this.paddingRight=e.paddingRight,this.paddingTop=e.paddingTop,this.paddingBottom=e.paddingBottom,this.width=e.width,this.height=e.height,this.originX=e.originX,this.originY=e.originY,this.innerShape=e.innerShape,this.exclusions=e.exclusions,this.computedBlockSize=e.computedBlockSize,this.snapWidth=e.snapWidth,this.snapHeight=e.snapHeight,this.vertical=e.vertical,this.rtl=e.rtl,this.borderBoxSizing=e.borderBoxSizing}setVerticalPosition(e,t){this.top=e,this.height=t,I(this.element,"top",`${e}px`),I(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,I(this.element,"left",`${e}px`),I(this.element,"width",`${t}px`)}setBlockPosition(e,t){if(this.vertical){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getBoxDir(),t)}else this.setVerticalPosition(e,t)}setInlinePosition(e,t){if(this.vertical)if(this.rtl){let i=t+this.marginTop+this.marginBottom+(this.borderBoxSizing?0:this.paddingTop+this.paddingBottom+this.borderTop+this.borderBottom);this.setVerticalPosition(e+i*this.getInlineDir(),t)}else this.setVerticalPosition(e,t);else if(this.rtl){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getInlineDir(),t)}else this.setHorizontalPosition(e,t)}clear(){let e=this.element,t;for(;t=e.lastChild;)e.removeChild(t)}getInnerShape(){let e=this.getInnerRect();return this.innerShape?this.innerShape.withOffset(e.x1,e.y1):Ma(e.x1,e.y1,e.x2,e.y2)}getInnerRect(){let e=this.originX+this.left+this.getInsetLeft(),t=this.originY+this.top+this.getInsetTop();return new Ct(e,t,e+this.width,t+this.height)}getPaddingRect(){let e=this.originX+this.left+this.marginLeft+this.borderLeft,t=this.originY+this.top+this.marginTop+this.borderTop,i=this.paddingLeft+this.width+this.paddingRight,n=this.paddingTop+this.height+this.paddingBottom;return new Ct(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return Yu(e,i.x1,i.y1,i.x2-i.x1,i.y2-i.y1,t)}getOuterRect(){let e=this.originX+this.left,t=this.originY+this.top,i=this.getInsetLeft()+this.width+this.getInsetRight(),n=this.getInsetTop()+this.height+this.getInsetBottom();return new Ct(e,t,e+i,t+n)}},sr=class extends oi{constructor(e,t,i,n){super(),this.elem=e,this.context=t,this.rootContentValue=i,this.exprContentListener=n}visitStrInner(e,t){var i;if(!t){if(((i=this.elem.lastChild)==null?void 0:i.nodeType)===3){this.elem.lastChild.textContent+=e;return}t=this.elem.ownerDocument.createTextNode(e)}this.elem.appendChild(t)}visitStr(e){return this.visitStrInner(e.str),null}visitURL(e){if(this.rootContentValue instanceof ot)this.elem.setAttribute("src",e.url);else{let t=this.elem.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","img");t.setAttribute("src",e.url),this.elem.appendChild(t)}return null}visitSpaceList(e){return this.visitValues(e.values),null}visitExpr(e){let t=e.toExpr(),i=t.evaluate(this.context);if(typeof i=="string"){this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof Ie&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function Rt(e){return e!=null&&e!==Y&&e!==v.normal&&e!==v.none&&!J(e)}var Te=gn.FloatReference;function Nm(e){switch(e){case"inline":return Te.INLINE;case"column":return Te.COLUMN;case"region":return Te.REGION;case"page":return Te.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function wi(e){switch(e){case Te.INLINE:return!1;case Te.COLUMN:case Te.REGION:case Te.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function ao(e,t,i,n){let r=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=bc(e,r,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let s=yc(e,r,i),o=sm(s,r);o==="line-left"?e="left":o==="line-right"&&(e="right")}else e==="inside"?e=n==="left"?"right":"left":e==="outside"&&(e=n==="left"?"left":"right");return e!=="left"&&e!=="right"&&(W.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var Lc=class{constructor(e,t,i,n,r,s){this.nodePosition=e,this.floatReference=t,this.floatSide=i,this.clearSide=n,this.flowName=r,this.floatMinWrapBlock=s,c(this,"order",null),c(this,"id",null),c(this,"insidePageFloatArea",!1),c(this,"parentPageFloat",null)}getOrder(){if(this.order===null)throw new Error("The page float is not yet added");return this.order}getId(){if(!this.id)throw new Error("The page float is not yet added");return this.id}isAllowedOnContext(e){return e.isAnchorAlreadyAppeared(this.getId())?!0:this.insidePageFloatArea&&this.parentPageFloat?!!e.findPageFloatFragment(this.parentPageFloat):!1}isAllowedToPrecede(e){return!1}},Tm=class{constructor(){c(this,"floats",[]),c(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(e){return`pf${e}`}addPageFloat(e){if(this.floats.findIndex(t=>vi(t.nodePosition,e.nodePosition))>=0)throw new Error("A page float with the same source node is already registered");{let t=e.order=this.nextOrder();e.id=this.createPageFloatId(t),this.floats.push(e)}}findPageFloatByNodePosition(e){let t=this.floats.findIndex(n=>vi(n.nodePosition,e));if(t>=0)return this.floats[t];let i=e?.steps;if(i!=null&&i.length){let n=this.floats.findIndex(r=>{let s=r.nodePosition.steps;if(!(s!=null&&s.length)||s.length===i.length||r.nodePosition.offsetInNode!==e.offsetInNode||r.nodePosition.after!==e.after)return!1;let o=Math.min(s.length,i.length);for(let a=0;a<o;a++)if(s[a].node!==i[a].node)return!1;return!0});if(n>=0)return this.floats[n]}return null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},Oc=class{constructor(e,t,i,n,r,s){this.floatReference=e,this.floatSide=t,this.clearSide=i,this.continuations=n,this.area=r,this.continues=s}hasFloat(e){return this.continuations.some(t=>t.float===e)}findNotAllowedFloat(e){for(let t=this.continuations.length-1;t>=0;t--){let i=this.continuations[t].float;if(!i.isAllowedOnContext(e))return i}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let e=this.continuations.map(t=>t.float);return Math.min.apply(null,e.map(t=>t.getOrder()))}shouldBeStashedBefore(e){return this.getOrder()<e.getOrder()}addContinuations(e){e.forEach(t=>{this.continuations.push(t)})}getFlowName(){let e=this.continuations[0].float.flowName;return this.continuations.every(t=>t.float.flowName===e),e}},Jl=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&vi(this.nodePosition,e.nodePosition):!1}},en=class{constructor(e,t,i,n,r,s,o){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=r,c(this,"children",[]),c(this,"writingMode"),c(this,"direction"),c(this,"invalidated",!1),c(this,"floatStore"),c(this,"forbiddenFloats",[]),c(this,"floatFragments",[]),c(this,"stashedFloatFragments",[]),c(this,"floatAnchors",{}),c(this,"floatsDeferredToNext",[]),c(this,"floatsDeferredFromPrevious"),c(this,"layoutConstraints",[]),c(this,"locked",!1),c(this,"outerContext",null),e&&e.children.push(this),this.writingMode=!J(s)&&s||e&&e.writingMode||v.horizontal_tb,this.direction=!J(o)&&o||e&&e.direction||v.ltr,this.floatStore=e?e.floatStore:new Tm;let a=this.getPreviousSibling();this.floatsDeferredFromPrevious=a?[].concat(a.floatsDeferredToNext):[]}get effectiveParent(){var e;return(e=this.parent)!=null?e:this.outerContext}getParent(e){if(this.parent)return this.parent;if(this.outerContext)return this.outerContext;throw new Error(`No PageFloatLayoutContext for ${e}`)}setOuterContext(e){this.outerContext=e,this.floatStore=e.floatStore}getPreviousSiblingOf(e,t,i,n){let r=this.children.indexOf(e);r<0&&(r=this.children.length);for(let s=r-1;s>=0;s--){let o=this.children[s];if(o.floatReference===t&&o.flowName===i&&vi(o.generatingNodePosition,n)||(o=o.getPreviousSiblingOf(null,t,i,n),o))return o}return null}getPreviousSibling(){let e=this,t=this.parent,i;for(;t;){if(i=t.getPreviousSiblingOf(e,this.floatReference,this.flowName,this.generatingNodePosition),i)return i;e=t,t=t.parent}return null}getContainer(e){return!e||e===this.floatReference?this.container:this.getParent(e).getContainer(e)}setContainer(e){this.container=e,this.reattachFloatFragments()}addPageFloat(e){this.floatStore.addPageFloat(e)}getPageFloatLayoutContext(e){return e===this.floatReference?this:this.getParent(e).getPageFloatLayoutContext(e)}findPageFloatByNodePosition(e){return this.floatStore.findPageFloatByNodePosition(e)}forbid(e){let t=e.getId(),i=e.floatReference;i===this.floatReference?this.forbiddenFloats.includes(t)||(this.forbiddenFloats.push(t),new Sn().findByFloat(e).forbid(e,this)):this.getParent(i).forbid(e)}isForbidden(e){let t=e.getId(),i=e.floatReference;return i===this.floatReference?this.forbiddenFloats.includes(t):this.getParent(i).isForbidden(e)}addPageFloatFragment(e,t){let i=e.floatReference;i!==this.floatReference?this.getParent(i).addPageFloatFragment(e,t):this.floatFragments.includes(e)||(this.floatFragments.push(e),this.floatFragments.sort((n,r)=>n.getOrder()-r.getOrder())),t||this.invalidate()}removePageFloatFragment(e,t){let i=e.floatReference;if(i!==this.floatReference)this.getParent(i).removePageFloatFragment(e,t);else{let n=this.floatFragments.indexOf(e);if(n>=0){let r=this.floatFragments.splice(n,1)[0],s=r.area&&r.area.element;s&&s.parentNode&&s.parentNode.removeChild(s),t||this.invalidate()}}}findPageFloatFragment(e){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).findPageFloatFragment(e);let t=this.floatFragments.findIndex(i=>i.hasFloat(e));return t>=0?this.floatFragments[t]:null}hasFloatFragments(e){return this.floatFragments.length>0&&(!e||this.floatFragments.some(e))?!0:this.parent?this.parent.hasFloatFragments(e):!1}hasContinuingFloatFragmentsInFlow(e){return this.hasFloatFragments(t=>t.continues&&t.getFlowName()===e)}registerPageFloatAnchor(e,t){this.floatAnchors[e.getId()]=t}collectPageFloatAnchors(){let e=Object.assign({},this.floatAnchors);return this.children.reduce((t,i)=>Object.assign(t,i.collectPageFloatAnchors()),e)}isAnchorAlreadyAppeared(e){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===e))return!0;let t=this.collectPageFloatAnchors()[e];return t&&this.container&&this.container.element?this.container.element.contains(t):!1}deferPageFloat(e){let t=e.float;if(t.floatReference===this.floatReference){let i=this.floatsDeferredToNext.findIndex(n=>n.float===t);i>=0?this.floatsDeferredToNext.splice(i,1,e):this.floatsDeferredToNext.push(e)}else this.getParent(t.floatReference).deferPageFloat(e)}hasPrecedingFloatsDeferredToNext(e,t){if(!t&&e.floatReference!==this.floatReference)return this.getParent(e.floatReference).hasPrecedingFloatsDeferredToNext(e,!1);let i=e.getOrder();return this.floatsDeferredToNext.some(n=>n.float.getOrder()<i&&!e.isAllowedToPrecede(n.float))?!0:this.parent?this.parent.hasPrecedingFloatsDeferredToNext(e,!0):!1}getLastFollowingFloatInFragments(e){let t=e.getOrder(),i=null;if(this.floatFragments.forEach(n=>{n.continuations.forEach(r=>{let s=r.float,o=s.getOrder();o>t&&(!i||o>i.getOrder())&&(i=s)})}),this.parent){let n=this.parent.getLastFollowingFloatInFragments(e);n&&(!i||n.getOrder()>i.getOrder())&&(i=n)}return i}getDeferredPageFloatContinuations(e){e=e||this.flowName;let t=this.floatsDeferredFromPrevious.filter(i=>!e||i.float.flowName===e);return this.parent&&(t=this.parent.getDeferredPageFloatContinuations(e).concat(t)),t.sort((i,n)=>i.float.getOrder()-n.float.getOrder())}getPageFloatContinuationsDeferredToNext(e){e=e||this.flowName;let t=this.floatsDeferredToNext.filter(i=>!e||i.float.flowName===e);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(e).concat(t):t}getFloatsDeferredToNextInChildContexts(){let e=[],t=[];for(let i=this.children.length-1;i>=0;i--){let n=this.children[i];t.includes(n.flowName)||(t.push(n.flowName),e=e.concat(n.floatsDeferredToNext.map(r=>r.float)),e=e.concat(n.getFloatsDeferredToNextInChildContexts()))}return e}checkAndForbidNotAllowedFloat(){if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let e=this.floatFragments.length-1;e>=0;e--){let t=this.floatFragments[e],i=t.findNotAllowedFloat(this);if(i)return this.locked?this.invalidate():(this.removePageFloatFragment(t),this.forbid(i),this.removeEndFloatFragments(t.floatSide)),!0}return this.floatReference===Te.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(r=>r.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(r=>!i.isAllowedToPrecede(r)&&n>r.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let r=this.findPageFloatFragment(i);this.removePageFloatFragment(r)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let e=this.floatsDeferredToNext.length-1;e>=0;e--)if(!this.floatsDeferredToNext[e].float.isAllowedOnContext(this)){if(this.locked){this.invalidate();return}this.floatsDeferredToNext.splice(e,1)}this.floatsDeferredFromPrevious.forEach(e=>{this.floatsDeferredToNext.findIndex(t=>e.equals(t))>=0||this.floatFragments.some(t=>t.hasFloat(e.float))||this.floatsDeferredToNext.push(e)})}}hasSameContainerAs(e){return!!this.container&&!!e.container&&this.container.element===e.container.element}invalidate(){this.invalidated=!0,!this.locked&&(this.container&&(this.children.forEach(e=>{this.hasSameContainerAs(e)&&e.floatFragments.forEach(t=>{let i=t.area.element;i&&i.parentNode&&i.parentNode.removeChild(i)})}),this.container.clear()),this.children.forEach(e=>{e.layoutConstraints.splice(0)}),this.children.splice(0),Object.keys(this.floatAnchors).forEach(e=>{delete this.floatAnchors[e]}))}detachChildren(){let e=this.children.splice(0);return e.forEach(t=>{t.floatFragments.forEach(i=>{let n=i.area.element;n&&n.parentNode&&n.parentNode.removeChild(n)})}),e}attachChildren(e){e.forEach(t=>{this.children.push(t),t.reattachFloatFragments()})}isInvalidated(){return this.invalidated||!!this.parent&&this.parent.isInvalidated()}validate(){this.invalidated=!1}toLogical(e){let t=this.writingMode.toString(),i=this.direction.toString();if(e==="inside"||e==="outside"){let n=!!this.container.element.closest("[data-vivliostyle-page-side='left']");e=e==="inside"?n?"right":"left":n?"left":"right"}return bc(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return yc(e,t,i)}toLogicalFloatSides(e){let t=e.split(" "),i=[];for(let o of t){let a=this.toLogical(o);i.includes(a)||i.push(a)}let n=[],r=!1,s=!1;for(let o=0;o<i.length;o++){let a=i[o];a.includes("block")?r||(i.slice(o+1).some(h=>h.includes("block"))?(n.push("snap-block"),r=!0):n.push(a)):a.includes("inline")&&(s||(i.slice(o+1).some(h=>h.includes("inline"))?(n.push("snap-inline"),s=!0):n.push(a)))}return n}removeEndFloatFragments(e){let t=this.toLogicalFloatSides(e)[0];if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogicalFloatSides(n.floatSide)[0]===t?this.removePageFloatFragment(n):i++}}}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogicalFloatSides(e.floatSide)[0];if(i==="block-end"||i==="snap-block"||i==="inline-end"||i==="snap-inline"){let n=0;for(;n<this.floatFragments.length;){let r=this.floatFragments[n],s=this.toLogicalFloatSides(r.floatSide)[0];(s===i||i==="snap-block"&&s==="block-end"||i==="snap-inline"&&s==="inline-end")&&r.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(r),this.floatFragments.splice(n,1)):n++}}}restoreStashedFragments(e){if(e!==this.floatReference){this.getParent(e).restoreStashedFragments(e);return}this.stashedFloatFragments.forEach(t=>{this.addPageFloatFragment(t,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(e){if(e!==this.floatReference){this.getParent(e).discardStashedFragments(e);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(e){return e===this.floatReference?this.stashedFloatFragments.concat().sort((t,i)=>i.getOrder()-t.getOrder()):this.getParent(e).getStashedFloatFragments(e)}getLimitValue(e,t,i,n,r,s=!0){this.container;let o=this.toLogical(e),a=this.toPhysical(e),h=t&&this.toLogical(t),l=t&&this.toPhysical(t),u=this.getLimitValueInner(o,h,i,n,r);if(s&&this.parent&&this.parent.container){let d=this.parent.getLimitValue(a,l,i,n,r,s);switch(a){case"top":return Math.max(u,d);case"left":return Math.max(u,d);case"bottom":return Math.min(u,d);case"right":return Math.min(u,d);default:}}return u}getLimitValueInner(e,t,i,n,r){this.container;let s=this.getLimitValuesInner(i,n,r,e,t);switch(e){case"block-start":return this.container.vertical?s.right:s.top;case"block-end":return this.container.vertical?s.left:s.bottom;case"inline-start":return this.container.vertical?this.container.rtl?s.bottom:s.top:this.container.rtl?s.right:s.left;case"inline-end":return this.container.vertical?this.container.rtl?s.top:s.bottom:this.container.rtl?s.left:s.right;default:throw new Error(`Unknown logical side: ${e}`)}}getLimitValuesInner(e,t,i,n,r){var s,o,a,h;this.container;let l=this.container.originX,u=this.container.originY,d=this.container.getPaddingRect(),p={top:d.y1-u,left:d.x1-l,bottom:d.y2-u,right:d.x2-l,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};if(this.container.vertical){let m=parseFloat((o=(s=this.container.element)==null?void 0:s.style)==null?void 0:o.width);isFinite(m)&&m>this.container.width&&(p.right+=m-this.container.width)}else{let m=parseFloat((h=(a=this.container.element)==null?void 0:a.style)==null?void 0:h.height);isFinite(m)&&m>this.container.height&&(p.bottom+=m-this.container.height)}function f(m,w,b){return m.unit==="%"?b*m.num/100:e.convertLengthToPx(m,w,t)}let g=this.floatFragments;return g.length>0&&(p=g.reduce((m,w)=>{if(i&&!i(w,this))return m;let[b,x]=this.toLogicalFloatSides(w.floatSide);if(x&&(n&&x.includes("block")===n.includes("block")&&x!==n||r&&x.includes("block")===r.includes("block")&&x!==r))return m;let y=w.area,P=w.continuations[0].float.floatMinWrapBlock,S=y.vertical?y.left+y.getInsetLeft()+y.width+y.getInsetRight():y.top+y.getInsetTop()+y.height+y.getInsetBottom(),R=y.vertical?y.top+y.getInsetTop()+y.height+y.getInsetBottom():y.left+y.getInsetLeft()+y.width+y.getInsetRight(),A=m.top,U=m.left,G=m.bottom,Z=m.right,fe=m.floatMinWrapBlockStart,ue=m.floatMinWrapBlockEnd;switch(b){case"inline-start":y.vertical?A=Math.max(A,R):U=Math.max(U,R);break;case"block-start":y.vertical?(P&&y.left<Z&&(fe=f(P,y.rootViewNodes[0],d.x2-d.x1)),Z=Math.min(Z,y.left)):(P&&S>A&&(fe=f(P,y.rootViewNodes[0],d.y2-d.y1)),A=Math.max(A,S));break;case"inline-end":y.vertical?G=Math.min(G,y.top):Z=Math.min(Z,y.left);break;case"block-end":y.vertical?(P&&S>U&&(ue=f(P,y.rootViewNodes[0],d.x2-d.x1)),U=Math.max(U,S)):(P&&y.top<G&&(ue=f(P,y.rootViewNodes[0],d.y2-d.y1)),G=Math.min(G,y.top));break;default:throw new Error(`Unknown logical float side: ${b}`)}return{top:A,left:U,bottom:G,right:Z,floatMinWrapBlockStart:fe,floatMinWrapBlockEnd:ue}},p)),p.left+=l,p.right+=l,p.top+=u,p.bottom+=u,p}setFloatAreaDimensions(e,t,i,n,r,s,o){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,r,s,o);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!o["block-start"]&&!o["block-end"])return null}else if(a[0].includes("block")&&!o[a[0]])return null;e.clientLayout;let h=a.find(S=>S.includes("inline")&&o[S==="inline-start"?"inline-end":"inline-start"]),l=a.find(S=>S.includes("block")),u=this.getLimitValue("block-start",h,e.layoutContext,e.clientLayout),d=this.getLimitValue("block-end",h,e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-start",l,e.layoutContext,e.clientLayout),f=this.getLimitValue("inline-end",l,e.layoutContext,e.clientLayout),g=e.vertical?e.originX:e.originY,m=e.vertical?e.originY:e.originX;u=e.vertical?Math.min(u,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+g):Math.max(u,e.top+g),d=e.vertical?Math.max(d,e.left+g):Math.min(d,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+g);function w(S,R){let A=S(e.bands,R);return A?(e.vertical&&(A=ju(A)),u=e.vertical?Math.min(u,A.x2):Math.max(u,A.y1),d=e.vertical?Math.max(d,A.x1):Math.min(d,A.y2),!0):s}let b,x,y,P;if(r){let S=e.vertical?ps(new Ct(d,p,u,f)):new Ct(p,u,f,d);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!w(Kf,S)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(Jf,S)||(y=(d-u)*e.getBoxDir(),b=y-e.getInsetBefore()-e.getInsetAfter(),P=(f-p)*e.getInlineDir(),x=P-e.getInsetStart()-e.getInsetEnd(),!s&&(b<=0||x<=0)))return null}else{let S=e.getContentBlockMarginAfter();b=Math.max(0,e.computedBlockSize+Math.min(0,S)),y=b+e.getInsetBefore()+e.getInsetAfter();let R=(d-u)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let U=this.container.getPaddingRect(),G=this.container.getBoxDir()*(n-(this.container.vertical?U.x2:U.y1)),Z=this.container.getBoxDir()*((this.container.vertical?U.x1:U.y2)-n-y);G<=Z?a[0]="block-start":a[0]="block-end"}if(!o[a[0]])if(o["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(o["inline-start"])a[0]="inline-start";else if(o["inline-end"])a[0]="inline-end";else return null;if(!s&&R<y)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?x=Va(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?x=e.getContentInlineSize():x=e.vertical?e.height:e.width,P=x+e.getInsetStart()+e.getInsetEnd();let A=(f-p)*e.getInlineDir();if(!s&&A<P)return null}return u-=g,d-=g,p-=m,f-=m,a.some(S=>S==="inline-start"||S==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(p,x):(a.some(S=>S==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-P*e.getInlineDir(),x),a.some(S=>S==="block-start"||S==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(u,b):(a.some(S=>S==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(d-y*e.getBoxDir(),b),a.join(" ")}getFloatFragmentExclusions(){let e=this.floatFragments.map(t=>t.getOuterShape());return this.parent?this.parent.getFloatFragmentExclusions().concat(e):e}reattachFloatFragments(){let e=this.container.element&&this.container.element.parentNode;e&&this.floatFragments.forEach(t=>{e.appendChild(t.area.element)})}getMaxReachedAfterEdge(){let e=this.getContainer().vertical;return this.floatFragments.reduce((t,i)=>{let n=i.getOuterRect();return e?Math.min(t,n.x1):Math.max(t,n.y2)},e?1/0:0)}getBlockEndEdgeOfBlockStartFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(s=>s.floatSide.includes("block-start")).filter(s=>{if(!isFinite(e))return!0;let o=s.getOuterRect();return n?o.y1<=e&&e<=o.y2:o.x1<=e&&e<=o.x2}).forEach(s=>{let o=s.getOuterRect(),a=n?o.x1:o.y2;r=isFinite(r)?n?Math.min(r,a):Math.max(r,a):a}),this.parent){let s=this.parent.getBlockEndEdgeOfBlockStartFloats(e);isFinite(s)&&(r=isFinite(r)?n?Math.min(r,s):Math.max(r,s):s)}return r}getBlockStartEdgeOfBlockEndFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(s=>s.floatSide.includes("block-end")).filter(s=>{if(!isFinite(e))return!0;let o=s.getOuterRect();return n?o.y1<=e&&e<=o.y2:o.x1<=e&&e<=o.x2}).forEach(s=>{let o=s.getOuterRect(),a=n?o.x2:o.y1;r=isFinite(r)?n?Math.max(r,a):Math.min(r,a):a}),this.parent){let s=this.parent.getBlockStartEdgeOfBlockEndFloats(e);isFinite(s)&&(r=isFinite(r)?n?Math.max(r,s):Math.min(r,s):s)}return r}getPageFloatClearEdge(e,t){function i(l){return u=>l.isAnchorAlreadyAppeared(u.float.getId())}function n(l,u){return e==="inline-start"&&(l.floatSide.includes("inline-end")||l.floatSide==="block-end")||e==="inline-end"&&(l.floatSide.includes("inline-start")||l.floatSide==="block-start")?!1:l.continuations.some(i(u))}let r=t.getPaddingRect(),s=t.vertical?r.x1:r.y2,o=this;for(;o;){if(o.floatsDeferredToNext.some(i(o)))return s;o=o.parent}function a(l){return l.floatFragments.some(u=>n(u,l))||l.children.some(u=>a(u))}if(e==="column"||e==="region"||e==="page"){for(o=this;o;o=o.parent)if(o.floatReference===e){if(a(o))return s;break}}t.clientLayout;let h=this.getLimitValue("block-start",null,t.layoutContext,t.clientLayout,n);return this.getLimitValue("block-end",null,t.layoutContext,t.clientLayout,n)*t.getBoxDir()<s*t.getBoxDir()?s:h}getPageFloatPlacementCondition(e,t,i){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).getPageFloatPlacementCondition(e,t,i);let n={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!i)return n;let r=this.toLogicalFloatSides(t)[0],s=this.toLogical(i),o;s==="all"?o=["block-start","block-end","inline-start","inline-end"]:s==="both"?o=["inline-start","inline-end"]:s==="same"?r==="snap-block"?o=["block-start","block-end"]:o=[r]:o=[s];let a=e.getOrder();function h(d){return p=>(!d||p.floatSide.includes(d))&&p.getOrder()<a}function l(d,p){return d.children.some(f=>f.floatFragments.some(h(p))||l(f,p))}function u(d,p){let f=d.parent;return!!f&&(f.floatFragments.some(h(p))||u(f,p))}if(i==="column"||i==="region"||i==="page"){for(let d=this;d;d=d.parent)if(d.floatReference===i){(d.floatFragments.some(h(null))||l(d,null))&&(n["block-start"]=!1,n["block-end"]=!1,n["inline-start"]=!1,n["inline-end"]=!1);break}return n}return o.forEach(d=>{switch(d){case"block-start":n[d]=!l(this,d);break;case"block-end":n[d]=!u(this,d);break;case"inline-start":case"inline-end":n[d]=!this.floatFragments.some(h(d));break;default:throw new Error(`Unexpected side: ${d}`)}}),n}getLayoutConstraints(){return(this.parent?this.parent.getLayoutConstraints():[]).concat(this.layoutConstraints)}addLayoutConstraint(e,t){t===this.floatReference?this.layoutConstraints.push(e):this.getParent(t).addLayoutConstraint(e,t)}isColumnFullWithPageFloats(e){let t=e.layoutContext,i=e.clientLayout,n=this,r=null;for(;n&&n.container;){let o=n.getLimitValuesInner(t,i);r?e.vertical?(o.right<r.right&&(r.right=o.right,r.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.left>r.left&&(r.left=o.left,r.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):(o.top>r.top&&(r.top=o.top,r.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.bottom<r.bottom&&(r.bottom=o.bottom,r.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):r=o,n=n.parent}let s=Math.max(r.floatMinWrapBlockStart,r.floatMinWrapBlockEnd);return(e.vertical?r.right-r.left:r.bottom-r.top)<=s}getMaxBlockSizeOfPageFloats(){let e=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(t=>{let i=t.area;return e?i.width:i.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},Bn=[],Sn=class{static register(e){Bn.push(e)}findByNodeContext(e){for(let t=Bn.length-1;t>=0;t--){let i=Bn[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=Bn.length-1;t>=0;t--){let i=Bn[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},Im=class{appliesToNodeContext(e){return wi(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let r=e.floatSide,s=e.toNodePosition(),o=!!t.generatingNodePosition;return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(a=>{n=a,t.flowName;let h=new Lc(s,n,r,e.clearSide,t.flowName,e.floatMinWrapBlock);if(h.insidePageFloatArea=o,o){let l=t.generatingNodePosition;l&&(h.parentPageFloat=t.findPageFloatByNodePosition(l))}return t.addPageFloat(h),N(h)})}createPageFloatFragment(e,t,i,n,r){let s=e[0].float;return new Oc(s.floatReference,t,i,e,n,r)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){return N(void 0)}forbid(e,t){}};Sn.register(new Im);var Am=Oc,Do=class Bc extends Lc{constructor(t,i,n,r,s){super(t,i,"block-end",null,n,s),this.footnotePolicy=r}isAllowedToPrecede(t){return!(t instanceof Bc)}},Ql=class extends Am{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof Do?!0:this.getOrder()<e.getOrder()}},Rm=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.toNodePosition();return!vi(t,this.footnote.nodePosition)}},Fm=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof Do}createPageFloat(e,t,i){let n=Te.REGION,r=t.getPageFloatLayoutContext(n);t.getPageFloatLayoutContext(Te.PAGE).hasSameContainerAs(r)&&(n=Te.PAGE);let s=!!t.generatingNodePosition;s&&n!==Te.PAGE&&(n=Te.PAGE);let o=e.toNodePosition();t.flowName;let a=new Do(o,n,t.flowName,e.footnotePolicy,e.floatMinWrapBlock);if(a.insidePageFloatArea=s,s){let h=t.generatingNodePosition;h&&(a.parentPageFloat=t.findPageFloatByNodePosition(h))}return t.addPageFloat(a),N(a)}createPageFloatFragment(e,t,i,n,r){let s=e[0].float;return new Ql(s.floatReference,e,n,r)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof Ql);return i.length<=1,i[0]||null}adjustPageFloatArea(e,t,i){e.isFootnote=!0,e.adjustContentRelativeSize=!1;let n=e.element;return i.layoutContext.applyFootnoteStyle(t.vertical,i.layoutContext.nodeContext&&i.layoutContext.nodeContext.direction==="rtl",n).thenAsync(r=>(e.vertical=r,e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e),N(void 0)))}forbid(e,t){let i=e;switch(i.footnotePolicy){case v.line:{let n=new Rm(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Sn.register(new Fm);var Lm="data-vivliostyle-flow-root";function Om(e){return e.getAttribute(Lm)==="true"}function eh(e){let t=e?.toString()||"block",i;switch(t){case"inline-flex":i="flex";break;case"inline-grid":i="grid";break;case"inline-table":i="table";break;case"initial":case"unset":case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":i="block";break;default:i=t}return B(i)}function Vs(e){return e===v.absolute||e===v.fixed}function bs(e){return e instanceof Ui&&e.name==="running"}function Mc(e,t,i,n){return e===v.none||(Vs(t)?(i=v.none,e=eh(e)):(i&&i!==v.none&&!J(i)||n)&&(e=eh(e))),{display:e,position:t,float:i}}function _c(e,t,i,n){return Mc(e,t,i,n).display===v.block}function Us(e){return e instanceof de||e instanceof te||typeof e=="string"}function Mt(e){if(!Us(e))return!1;let t=e.toString();switch(t){case"inline":case"inline-block":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return t.includes("inline")}}function Hn(e){return Us(e)?e.toString().includes("list-item"):!1}function Bm(e){if(!Us(e))return!1;switch(e.toString()){case"block":case"flex":case"grid":case"table":case"list-item":case"flow-root":return!0;default:return!1}}function Dc(e){if(!Us(e))return!1;switch(e.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function Mm(e,t,i,n,r,s,o){return r=r||s||v.horizontal_tb,!!o||!!i&&i!==v.none&&!J(i)||Vs(t)||e===v.inline_block||e===v.table_cell||e===v.table_caption||e==v.flex||e==v.grid||e==v.flow_root||(e===v.block||e===v.list_item)&&!!n&&n!==v.visible&&n!==v.clip&&!J(n)||!!s&&r!==s}function _m(e){return e===v.relative||e===v.absolute||e===v.fixed}var Ht=1e5;function Ha(e){let t=e.element.style;t.columnGap=`${Ht-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function Hs(e){let t=("element"in e?e.element:e).style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function vs(e){return e.element.style.columnCount==="1"}function Dm(e){e.element.setAttribute("data-vivliostyle-column","true")}function or(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/Ht)}function zc(e,t){let i=or(e,t);if(i===0)return 0;let n=t?e.top:Math.min(Math.abs(e.left),Math.abs(e.right)),r=Math.round(n/Ht),s=r*Ht,o=i*Ht;return t?(e.top-=s,e.bottom-=o,e.bottom<e.top&&(e.bottom+=Ht),e.right-=s,e.left-=o):e.left<-Ht/2?(e.right+=s,e.left+=o,e.left>e.right&&(e.left-=Ht),e.top+=s,e.bottom+=o):(e.left-=s,e.right-=o,e.right<e.left&&(e.right+=Ht),e.top+=s,e.bottom+=o),e.width=e.right-e.left,e.height=e.bottom-e.top,r}function zo(e,t){for(let i=0;i<e.length;i++)zc(e[i],t)}function It(e,t,i){let n=e.getElementClientRect(t);if(zc(n,i)>0&&e.getElementComputedStyle(t).display.startsWith("table")&&!$s(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return Hs(r),e.getElementClientRect(t)}return n}function zm(e,t){var i,n;if(e.nodeType===1){let r=e;((i=r.style)==null?void 0:i.breakAfter)==="column"&&(r.style.breakAfter="")}if(t.nodeType===1){let r=t;((n=r.style)==null?void 0:n.breakBefore)==="column"&&(r.style.breakBefore="")}}function $s(e){for(let t=e.nodeType===1?e:e.parentElement;t;t=t.parentElement){let i=t.style;if(!i||t.hasAttribute("data-vivliostyle-column"))break;if(!isNaN(parseFloat(i.columnCount))||!isNaN(parseFloat(i.columnWidth)))return t;if(i.position==="absolute")break}return null}function Vm(e){var t;if(e.nodeType!==1)return;let i=e,n=i.style,r=n?.breakBefore==="column",s=i.previousElementSibling,o=s&&((t=s.style)==null?void 0:t.breakAfter)==="column";if(!r&&!o)return;let a=$s(i);if(!a)return;let h=a.ownerDocument.defaultView.getComputedStyle(a),{writingMode:l,direction:u,columnGap:d,fontSize:p}=h,f=l==="vertical-rl"||l==="vertical-lr",g=u==="rtl",m=(parseFloat(d)||parseFloat(p)||16)/2,w=a.getBoundingClientRect(),b=i.getBoundingClientRect();(f?b.top>w.bottom+m:g?b.right<w.left-m:b.left>w.right+m)&&(r&&(n.breakBefore=""),o&&s&&(s.style.breakAfter=""),n.marginBlockStart=`${Ht}px`)}function Lr(e){let t=e.element.lastElementChild,i=t&&e.clientLayout.getElementClientRect(t);return i?or(i,e.vertical):0}function Vc(e,t){if(e.getAttribute("data-viv-saved-column-fill")!=="auto"||Lr(t))return;let i=t.clientLayout.getElementComputedStyle(e),n=parseFloat(i.blockSize);e.style.columnFill="auto";let r=parseFloat(i.blockSize),s=NaN;if(e.style.blockSize=`${r}px`,Lr(t)){if(e.style.blockSize=`${n}px`,!Lr(t)){let o=1/(t.clientLayout.pixelRatio||1),a=n,h=r;for(;h-a>o;){let l=(a+h)/2;e.style.blockSize=`${l}px`,Lr(t)?h=l:a=l}s=a,e.style.blockSize=`${s}px`}}else if(s=parseFloat(i.blockSize),s<r){let o=1/t.clientLayout.layoutUnitPerPixel;s=r+o,e.style.blockSize=`${s}px`}if(isNaN(s)){e.style.blockSize="",e.style.columnFill="balance";return}e.removeAttribute("data-viv-saved-column-fill")}function Um(e){let t=e.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let i of t)Vc(i,e)}function tn(e,t,i,n){let r=e.viewNode;if(!r)return NaN;let s=r.nodeType===1?r:r.parentElement;if(s&&s.namespaceURI==="http://www.w3.org/1999/xhtml"){let o=s.style;if(s.localName==="wbr"||o&&Mt(o.display)&&/^([\d\.]|super|(text-)?top)/.test(o.verticalAlign))return NaN}if(r===s){if(s.localName==="br"){let o=s.ownerDocument.createElement("span");s.parentNode.insertBefore(o,s);let a=t.getElementClientRect(o);if(o.remove(),a){let h=[a];zo(h,n);let l=h[0],u=n?l.left:l.bottom;if(!isNaN(u)&&u!==0)return u}return NaN}if(e.after||!e.inline){if(e.after&&!e.inline&&s.querySelector("ruby")){let a=s.parentNode,h=s.nextSibling;a.removeChild(s),a.insertBefore(s,h)}let o=It(t,s,n);if(o.left===0&&o.top===0&&o.right===0&&o.bottom===0)return NaN;if(o.right>=o.left&&o.bottom>=o.top)return e.after?n?o.left:o.bottom:n?o.right:o.top}return NaN}else{let o=NaN,a=r.ownerDocument.createRange(),h=r.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(r,i),a.setEnd(r,i+1);let l=t.getRangeClientRects(a);zo(l,n);let u=l.filter(d=>d.right>d.left&&d.bottom>d.top);if(u.length>0)l=u;else{let d=s?t.getElementComputedStyle(s).whiteSpace:"";l=d==="pre"||d==="pre-wrap"||d==="pre-line"||d==="break-spaces"?l.filter(p=>n?p.right>p.left:p.bottom>p.top):[]}return l.length?(n?o=Math.min.apply(null,l.map(d=>d.left)):o=Math.max.apply(null,l.map(d=>d.bottom)),o):NaN}}function Vo(e,t,i){let n=vs(t);n&&Hs(t);let r=t.clientLayout.getElementClientRect(e);n&&Ha(t);let s=t.getComputedMargin(e);return i?r.width+s.left+s.right:r.height+s.top+s.bottom}function an(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function Uc(e,t){var i;if(e)for(let n=e.lastChild,r=n;n!==t;n=r)r=n.previousSibling,!(n.nodeType===1&&n.hasAttribute("data-vivliostyle-float-box-moved")&&((i=t.style)==null?void 0:i.display)==="inline")&&e.removeChild(n)}var Cn="data-adapt-spec";function $a(e){return!!e.getAttribute(Cn)}function hi(e){return e?.nodeType!==1?!1:$a(e)?!0:Hc(e)}function Hc(e){var t,i;if(e?.nodeType!==1)return!1;let n=e,r=(t=n.style)==null?void 0:t.position;if(r==="absolute"||r==="fixed")return!0;let s=(i=n.style)==null?void 0:i.float;return s==="left"||s==="right"||s==="inline-start"||s==="inline-end"}function th(e){var t;return e?.nodeType!==1?!1:((t=e.style)==null?void 0:t.position)==="fixed"}function ln(e){let t=e?.viewNode;return t?.nodeType===1&&$a(t)}function Hm(e){return e!=="inline"&&(Mt(e)||Dc(e))}function ih(e){var t;for(let i=e.parent;i;i=i.parent)if((i.display!=="inline"||i.vertical!==((t=i.parent)==null?void 0:t.vertical))&&Mt(i.display))return i;return null}function $m(e){let t=e;for(;t;){if(t.nodeType===Node.TEXT_NODE&&t.textContent.length>0)return t;if(t.lastChild)t=t.lastChild;else{for(;t&&!t.previousSibling;)if(t=t.parentNode,t===e||!t)return null;t=t?.previousSibling||null}}return null}var Wa=class{calculateOffset(e){return mn(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function mn(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var xr=class extends Wa{constructor(e,t,i,n){super(),this.position=e,this.breakOnEdge=t,this.overflows=i,this.computedBlockSize=n,c(this,"overflowIfRepetitiveElementsDropped"),c(this,"isEdgeUpdated",!1),c(this,"edge",0),this.overflowIfRepetitiveElementsDropped=i}findAcceptableBreak(e,t){return this.updateOverflows(e),t<this.getMinBreakPenalty()?null:e.findEdgeBreakPosition(this)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");let e=this.isFirstContentOfRepetitiveElementsOwner()&&!this.overflowIfRepetitiveElementsDropped;return(gs(this.breakOnEdge)?1:0)+(this.overflows&&!e?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}updateEdge(e){var t;let i=e.calculateClonedPaddingBorder(this.position);if(this.edge=tn(this.position,e.clientLayout,0,e.vertical)+i,!this.position.after&&!this.position.inline){let n=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*n}else if(this.position.after&&((t=this.position.shadowContext)==null?void 0:t.root.id)==="table-cell"){let n=e.element.parentElement,r=n?.closest("table, [style*='display: table;']");if(r){let s=r.style.borderCollapse==="collapse",o=0,a=0;for(let h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===r&&!s)&&(o+=e.parseComputedLength(l.paddingBlockEnd)),h===r&&!s&&(o+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),s?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===r)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===r)break}this.edge+=(e.vertical?-1:1)*(o+a)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let t=this.edge,i=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(t+(e.vertical?-1:1)*i.minimum),this.overflows=this.position.overflow=e.isOverflown(t+(e.vertical?-1:1)*i.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:t}=e.parent;if(!Mi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},Mn=class{find(e){let t=Ft("RESOLVE_LAYOUT_PROCESSOR");for(let i=0;i<t.length;i++){let n=t[i](e);if(n)return n}throw new Error(`No processor found for a formatting context: ${e.getName()}`)}},hn=class{layout(e,t,i){return t.isFloatNodeContext(e)?t.layoutFloatOrFootnote(e):t.isBreakable(e)?t.layoutBreakableBlock(e):t.layoutUnbreakable(e)}createEdgeBreakPosition(e,t,i,n){return new xr(e.copy(),t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}clearOverflownViewNodes(e,t,i,n){var r;if(!i.viewNode||!i.viewNode.parentNode||i.shadowType===ri.ShadowType.ROOTLESS&&ln(i))return;let s=i.viewNode;((r=s.parentElement)==null?void 0:r.localName)==="viv-ts-inner"&&(s=s.parentElement.parentElement);let o=s.parentNode;Uc(o,s),n&&o.removeChild(s)}finishBreak(e,t,i,n){let r=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,r),n&&e.layoutContext.processFragmentedBlockEdge(t),N(!0)}},Ga=class{constructor(e){this.parent=e,c(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},ja=new hn,Wm=Bo.isInstanceOfBlockFormattingContext;kt("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,r,s)=>{let o=e.parent;return!o&&e.formattingContext||o&&e.formattingContext!==o.formattingContext?null:e.establishesBFC||!e.formattingContext&&_c(i,n,r,s)?new Ga(o?o.formattingContext:null):null});kt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Ga?ja:null);var Xa=class{constructor(){c(this,"initialBreakPositions",null),c(this,"initialStateOfFormattingContext",null),c(this,"initialPosition"),c(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=M("AbstractLayoutRetryer.tryLayout");this.saveState(e,t);let n=this.resolveLayoutMode(e);return n.doLayout(e,t).then(r=>{let s=n.accept(r,t);s=n.postLayout(r,this.initialPosition,t,s),s?i.finish(r):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(e,t),this.tryLayout(this.initialPosition,t).thenFinish(i))}),i.result()}prepareLayout(e,t){}clearNodes(e){let t=e.viewNode||e.parent.viewNode,i;for(;i=t.lastChild;)t.removeChild(i);let n;for(;n=t.nextSibling;)n.parentNode.removeChild(n)}saveState(e,t){this.initialPosition=e.copy(),this.initialBreakPositions=[].concat(t.breakPositions),this.initialFragmentLayoutConstraints=[].concat(t.fragmentLayoutConstraints),e.formattingContext&&(this.initialStateOfFormattingContext=e.formattingContext.saveState())}restoreState(e,t){t.breakPositions=this.initialBreakPositions,t.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,e.formattingContext&&e.formattingContext.restoreState(this.initialStateOfFormattingContext)}},Gm=class{initialState(e){return{nodeContext:e,atUnforcedBreak:!1,break:!1}}startNonDisplayableNode(e){}afterNonDisplayableNode(e){}startIgnoredTextNode(e){}afterIgnoredTextNode(e){}startNonElementNode(e){}afterNonElementNode(e){}startInlineElementNode(e){}afterInlineElementNode(e){}startNonInlineElementNode(e){}afterNonInlineElementNode(e){}finish(e){}},Uo=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=M("LayoutIterator");return n.loopWithFrame(r=>{let s;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Me(i.nodeContext.viewNode,i.nodeContext.whitespace)?i.nodeContext.after?s=t.afterIgnoredTextNode(i):s=t.startIgnoredTextNode(i):i.nodeContext.after?s=t.afterNonElementNode(i):s=t.startNonElementNode(i):i.nodeContext.inline?i.nodeContext.after?s=t.afterInlineElementNode(i):s=t.startInlineElementNode(i):i.nodeContext.after?s=t.afterNonInlineElementNode(i):s=t.startNonInlineElementNode(i):i.nodeContext.after?s=t.afterNonDisplayableNode(i):s=t.startNonDisplayableNode(i);let o=(s&&s.isPending()?s:N(!0)).thenAsync(()=>i.break?N(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(o.isPending()){o.then(a=>{i.break?r.breakLoop():(i.nodeContext=a,r.continueLoop())});return}else if(i.break){r.breakLoop();return}else i.nodeContext=o.get()}t.finish(i),r.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},Kn=class extends Gm{constructor(e){super(),this.leadingEdge=e}startNonInlineBox(e){}endEmptyNonInlineBox(e){}endNonInlineBox(e){}initialState(e){return{nodeContext:e,atUnforcedBreak:!!this.leadingEdge&&e.after,break:!1,leadingEdge:this.leadingEdge,breakAtTheEdge:null,onStartEdges:!1,leadingEdgeContexts:[],lastAfterNodeContext:null}}processForcedBreak(e,t){let i=!e.leadingEdge&&Ge(e.breakAtTheEdge);if(i){let n=e.nodeContext=e.leadingEdgeContexts[0]||e.nodeContext;n.viewNode.parentNode.removeChild(n.viewNode),t.pageBreakType=e.breakAtTheEdge}return i}saveEdgeAndProcessOverflow(e,t){let i=t.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,e.breakAtTheEdge);return i&&(e.nodeContext=(e.lastAfterNodeContext||e.nodeContext).modify(),e.nodeContext.overflow=!0),i}processLayoutConstraint(e,t,i){let n=e.nodeContext,r=!t.allowLayout(n);return r&&(i.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),n=e.nodeContext=n.modify(),n.overflow=!0),r}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=et(e.breakAtTheEdge,e.nodeContext.breakBefore),e.onStartEdges=!0,this.startNonInlineBox(e)}afterNonInlineElementNode(e){let t,i;return e.onStartEdges?(t=this.endEmptyNonInlineBox(e),i=t&&t.isPending()?t:N(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),N(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:N(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=et(e.breakAtTheEdge,e.nodeContext.breakAfter)),N(!0)))}},Ho=[];function jm(){Ho=[]}function $c(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var Xm=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},qm=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},Wc=class Gr{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let r=Gr.fragmentIndices;(!r[t]||r[t].priority<=n)&&(r[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){Gr.fragmentIndices={}}matches(){let t=Gr.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&$c(t.fragmentIndex,this.a,this.b)}};c(Wc,"fragmentIndices",{});var Ws=Wc,Or=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new Ws(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new qm(e)}static buildAnyMatcher(e){return new Xm(e)}},Gc={"border-collapse":!0,"border-spacing":!0,"caption-side":!0,"clip-rule":!0,color:!0,"color-interpolation":!0,"color-rendering":!0,cursor:!0,direction:!0,"empty-cells":!0,fill:!0,"fill-opacity":!0,"fill-rule":!0,"font-kerning":!0,"font-size":!0,"font-size-adjust":!0,"font-family":!0,"font-feature-settings":!0,"font-style":!0,"font-stretch":!0,"font-variant-ligatures":!0,"font-variant-caps":!0,"font-variant-numeric":!0,"font-variant-east-asian":!0,"font-weight":!0,"glyph-orientation-vertical":!0,"hanging-punctuation":!0,hyphens:!0,"hyphenate-character":!0,"hyphenate-limit-chars":!0,"hyphenate-limit-last":!0,"image-rendering":!0,"image-resolution":!0,"letter-spacing":!0,"line-break":!0,"line-height":!0,"list-style-image":!0,"list-style-position":!0,"list-style-type":!0,marker:!0,"marker-end":!0,"marker-mid":!0,"marker-start":!0,orphans:!0,"overflow-wrap":!0,"paint-order":!0,"pointer-events":!0,quotes:!0,"ruby-align":!0,"ruby-position":!0,"shape-rendering":!0,stroke:!0,"stroke-dasharray":!0,"stroke-dashoffset":!0,"stroke-linecap":!0,"stroke-linejoin":!0,"stroke-miterlimit":!0,"stroke-opacity":!0,"stroke-width":!0,"tab-size":!0,"text-align":!0,"text-align-last":!0,"text-anchor":!0,"text-autospace":!0,"text-decoration-skip":!0,"text-decoration-skip-ink":!0,"text-emphasis-color":!0,"text-emphasis-position":!0,"text-emphasis-style":!0,"text-fill-color":!0,"text-combine-upright":!0,"text-indent":!0,"text-justify":!0,"text-orientation":!0,"text-rendering":!0,"text-shadow":!0,"text-size-adjust":!0,"text-spacing-trim":!0,"text-stroke-color":!0,"text-stroke-width":!0,"text-transform":!0,"text-underline-offset":!0,"text-underline-position":!0,"text-wrap":!0,"text-wrap-mode":!0,"text-wrap-style":!0,visibility:!0,"white-space":!0,widows:!0,"word-break":!0,"word-spacing":!0,"writing-mode":!0},Ym=["image-resolution","orphans","widows"];function Zm(){return Ft("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(Ym))}var Km={"http://www.idpf.org/2007/ops":!0,"http://www.w3.org/1999/xhtml":!0,"http://www.w3.org/2000/svg":!0,"http://www.w3.org/1998/Math/MathML":!0},$o=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],Jm=["max-%","min-%","%"],nh=(()=>{let e=["left","right","top","bottom"],t={width:!0,height:!0,"max-width":!0,"max-height":!0,"min-width":!0,"min-height":!0};for(let i=0;i<$o.length;i++)for(let n=0;n<e.length;n++){let r=$o[i].replace("%",e[n]);t[r]=!0}return t})();function An(e,t){let i={};for(let n of $o)for(let r in e){let s=n.replace("%",r),o=n.replace("%",e[r]);i[s]=o,i[o]=s}for(let n of Jm)for(let r in t){let s=n.replace("%",r),o=n.replace("%",t[r]);i[s]=o,i[o]=s}return i}var jc=An({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),Xc=An({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),Qm=An({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),ew=An({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),tw=An({inside:"right",outside:"left"},{}),iw=An({inside:"left",outside:"right"},{}),D=class Wo{constructor(t,i){this.value=t,this.priority=i}getBaseValue(){return this}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new Wo(i,this.priority)}increaseSpecificity(t){return t==0?this:new Wo(this.value,this.priority+t)}evaluate(t,i,n,r){return i&&jt(i)?this.value:ks(t,this.value,i,n,r)}isEnabled(t){return!0}},Go=class jo extends D{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new D(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new jo(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new jo(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){W.warn(i)}return!1}};function Xo(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Dt(e,t,i,n){if(e)if(!i)delete e[t];else{let r=e[t];(!r||i.priority>=r.priority)&&(n?i.isEnabled(n)&&(e[t]=i.getBaseValue()):e[t]=i)}}var qc={"region-id":!0,"fragment-selector-id":!0},Yc="data-viv-footnote-counter";function Zc(e){let t=e.getAttribute(Yc);if(!t)return Object.create(null);let i;try{i=JSON.parse(t)}catch{return Object.create(null)}if(!i||typeof i!="object"||Array.isArray(i))return Object.create(null);let n=Object.create(null);return Object.entries(i).forEach(([r,s])=>{if(Array.isArray(s)){let o=s.filter(a=>typeof a=="number"&&isFinite(a));n[r]=o}else typeof s=="number"&&isFinite(s)&&(n[r]=[s])}),n}function nw(e,t,i){let n=Zc(e);n[t]=i,e.setAttribute(Yc,JSON.stringify(n))}function rw(e){return!!qc[e]}function jr(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Bi(e){return e.charAt(0)!=="_"&&!qc[e]}function un(e){return!!Gc[e]||jt(e)}function ke(e,t){return e[t]}function yi(e,t,i){i?e[t]=i:delete e[t]}function bt(e,t){return e[t]}function ei(e,t){let i=e[t];return i||(i={},e[t]=i),i}var Kc=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function Jc(e,t){return e[t]}function Qc(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function xs(e,t,i,n,r,s,o){var a,h;if([{id:r,styleKey:"_pseudos"},{id:s,styleKey:"_regions"}].forEach(l=>{if(l.id){let u=ei(t,l.styleKey);t=u[l.id],t||(t={},u[l.id]=t)}}),o){let l=Kc(t);t={},l.push({styles:t,matcher:o})}for(let l in i)if(!jr(l))if(rw(l)){let u=Jc(i,l),d=Qc(t,l);Array.prototype.push.apply(d,u)}else{let u=ke(i,l);if(!u.isEnabled(e))continue;let d=u.increaseSpecificity(n);Dt(t,l,d,e);let p=(h=(a=e.style)==null?void 0:a.validatorSet.shorthands[l])==null?void 0:h.propList;if(p)for(let f of p){let g=new D(Y,d.priority);Dt(t,f,g,e)}}}function sw(e,t){let i={};for(let n=0;n<t.length;n++)xs(e,i,t[n],0,null,null,null);return i}function qa(e,t){if(e.length>0){e.sort((n,r)=>r.getPriority()-n.getPriority());let i=null;for(let n=e.length-1;n>=0;n--)i=e[n],i.chained=t,t=i;return i}return t}var ow=class extends Vi{constructor(e,t){super(),this.props=e,this.context=t,c(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=ke(this.props,"font-size");if(!e.value.isNumeric())return _t.em;let t=e.value;if(!Cf(t.unit))throw new Error("Unexpected state");return t.num*_t[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?qo(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?Ya(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?ks(this.context,e,this.propName).visit(this):e}};function Ya(e,t,i){let n=e.unit,r=e.num;return n==="em"?new F(r*t,"px"):n==="rem"?new F(r*i.fontSize(),"px"):n==="rlh"?new F(r*i.rootLineHeight,"px"):e}function qo(e,t,i){e=Ya(e,t,i);let n=e.unit,r=e.num;return n==="px"?e:n==="%"?new F(r/100*t,"px"):new F(r*i.queryUnitSize(n,!1),"px")}var Rn=class{apply(e){}mergeWith(e){return new aw([this,e])}clone(){return this}},Br=class extends Rn{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},aw=class ed extends Rn{constructor(t){super(),this.list=t}apply(t){for(let i=0;i<this.list.length;i++)this.list[i].apply(t)}mergeWith(t){return this.list.push(t),this}clone(){return new ed([].concat(this.list))}},Za=class extends Rn{constructor(e,t,i,n,r){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=r}apply(e){xs(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},Se=class extends Rn{constructor(){super(),c(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},lw=class extends Se{constructor(e){super(),this.className=e}apply(e){e.currentClassNames.includes(this.className)&&this.chained.apply(e)}getPriority(){return 10}makePrimary(e){return this.chained&&e.insertInTable(e.classes,this.className,this.chained),!0}},hw=class extends Se{constructor(e){super(),this.id=e}apply(e){(e.currentId==this.id||e.currentXmlId==this.id)&&this.chained.apply(e)}getPriority(){return 11}makePrimary(e){return this.chained&&e.insertInTable(e.ids,this.id,this.chained),!0}},rh=class extends Se{constructor(e){super(),this.localName=e}apply(e){e.currentLocalName==this.localName&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){return this.chained&&e.insertInTable(e.tags,this.localName,this.chained),!0}},uw=class extends Se{constructor(e,t){super(),this.ns=e,this.localName=t}apply(e){e.currentLocalName==this.localName&&e.currentNamespace==this.ns&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){if(this.chained){let t=e.nsPrefix[this.ns];t||(t=`ns${e.nsCount++}:`,e.nsPrefix[this.ns]=t);let i=t+this.localName;e.insertInTable(e.nstags,i,this.chained)}return!0}},cw=class extends Se{constructor(e,t,i=!1){super(),this.epubTypePatt=e,this.targetLocalName=t,this.useRoleAttr=i}apply(e){let t=e.currentElement;if(t instanceof HTMLAnchorElement&&t.hash&&t.href==t.baseURI.replace(/#.*$/,"")+t.hash){let i=t.hash.substring(1),n=t.ownerDocument.getElementById(i);if(n&&(!this.targetLocalName||n.localName==this.targetLocalName)){let r=this.useRoleAttr?n.getAttribute("role"):n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");r&&r.match(this.epubTypePatt)&&this.chained.apply(e)}}}},dw=class extends Se{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function Gs(e,t,i,n){if(!e)return!1;if(t!==null)return n(e,t,i);for(let r of e.getAttributeNames())if((r===i||r.endsWith(`:${i}`))&&n(e,r===i?"":e.lookupNamespaceURI(r.split(":")[0]),i))return!0;return!1}var sh=class extends Se{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){Gs(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},pw=class extends Se{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){Gs(e.currentElement,this.ns,this.name,(t,i,n)=>t.getAttributeNS(i,n)==this.value)&&this.chained.apply(e)}getPriority(){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?9:0}makePrimary(e){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?(this.chained&&e.insertInTable(e.epubtypes,this.value,this.chained),!0):!1}},fw=class extends Se{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){Gs(e.currentElement,this.ns,this.name,(t,i,n)=>!!Km[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},_n=class extends Se{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){Gs(e.currentElement,this.ns,this.name,(t,i,n)=>{var r;return!!((r=t.getAttributeNS(i,n))!=null&&r.match(this.regexp))})&&this.chained.apply(e)}},gw=class extends Se{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},oh=class extends Se{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},mw=class extends Se{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},Hi=class extends Se{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return $c(e,this.a,this.b)}},ww=class extends Hi{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},Yo=class extends Hi{constructor(e,t){super(e,t)}apply(e){let t=e.currentSiblingTypeCounts[e.currentNamespace][e.currentLocalName];this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 5}},Zo=class extends Hi{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingOrder;t===null&&(t=e.currentFollowingSiblingOrder=e.currentElement.parentNode.childElementCount-e.currentSiblingOrder+1),this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 4}},Ko=class extends Hi{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingTypeCounts;if(!t[e.currentNamespace]){let i=e.currentElement;do{let n=i.namespaceURI,r=i.localName,s=t[n];s||(s=t[n]={}),s[r]=(s[r]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},yw=class extends Se{constructor(){super()}apply(e){let t=e.currentElement.firstChild;for(;t;){switch(t.nodeType){case Node.ELEMENT_NODE:return;case Node.TEXT_NODE:if(t.length>0)return}t=t.nextSibling}this.chained.apply(e)}getPriority(){return 4}},bw=class extends Se{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},vw=class extends Se{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},xw=class extends Se{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},Qe=class extends Se{constructor(e){super(),this.condition=e}apply(e){if(e.conditions[this.condition])try{e.dependentConditions.push(this.condition),this.chained.apply(e)}finally{e.dependentConditions.pop()}}getPriority(){return 5}},td=class id extends Rn{constructor(){super(),c(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new id;return t.applied=this.applied,t}},Ka=class extends Se{constructor(e){super(),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new td;for(let t of e)this.firstActions.push(qa(t,this.checkAppliedAction))}apply(e){for(let t of this.firstActions)if(t.apply(e),this.checkAppliedAction.applied)break;this.checkAppliedAction.applied===this.positive()&&this.chained.apply(e),this.checkAppliedAction.applied=!1}getPriority(){return Math.max(...this.firstActions.map(e=>e instanceof Se?e.getPriority():0))}positive(){return!0}relational(){return!1}},Sw=class extends Ka{positive(){return!1}},Cw=class extends Ka{constructor(e){super([]),this.selectorTexts=e}apply(e){for(let t of this.selectorTexts){let i,n;/^\s*[+~]/.test(t)?(n=e.currentElement.parentNode,i=`:scope > :nth-child(${Array.from(n.children).indexOf(e.currentElement)+1}) ${t}`):(n=e.currentElement,i=`:scope ${t}`);try{if(n.querySelector(i)){this.checkAppliedAction.apply(e);break}}catch{}}this.checkAppliedAction.applied&&this.chained.apply(e),this.checkAppliedAction.applied=!1}relational(){return!0}},nd=class extends Hi{constructor(e,t,i){super(e,t),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new td;for(let n of i)this.firstActions.push(qa(n,this.checkAppliedAction))}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.previousElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.previousElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}matchesSelector(e,t){let i=t.currentElement,n=t.currentNamespace,r=t.currentLocalName,s=t.currentId,o=t.currentClassNames,a=t.currentSiblingOrder;t.currentElement=e,t.currentNamespace=e.namespaceURI||"",t.currentLocalName=e.localName,t.currentId=e.id,t.currentClassNames=e.classList?Array.from(e.classList):[];let h=1,l=e.previousElementSibling;for(;l;)h++,l=l.previousElementSibling;t.currentSiblingOrder=h;for(let d of this.firstActions)if(d.apply(t),this.checkAppliedAction.applied)break;let u=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,t.currentElement=i,t.currentNamespace=n,t.currentLocalName=r,t.currentId=s,t.currentClassNames=o,t.currentSiblingOrder=a,u}getPriority(){return 5}},kw=class extends nd{constructor(e,t,i){super(e,t,i)}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.nextElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.nextElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 4}},js=class{constructor(e,t,i){this.condition=e,this.viewConditionId=t,this.viewCondition=i}increment(e){e.increment(this.condition,this.viewCondition)}decrement(e){e.decrement(this.condition,this.viewCondition)}buildViewConditionMatcher(e){return e.buildViewConditionMatcher(this.viewConditionId)}},Ew=class rd extends js{constructor(t,i,n){super(t,i,n)}fresh(t){return new rd(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return i==0&&this.increment(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):!1}},Pw=class sd extends js{constructor(t,i,n){super(t,i,n)}fresh(t){return new sd(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return i==0?this.increment(t):i==1&&this.decrement(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):(i==1&&this.increment(t),!1)}},Nw=class od extends js{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new od(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return this.fired?(this.decrement(t),!0):!1}pop(t,i){return this.fired?(this.decrement(t),!0):(i==0&&(this.fired=!0,this.increment(t)),!1)}},Tw=class ad extends js{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new ad(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return this.fired&&(i==-1?this.increment(t):i==0&&this.decrement(t)),!1}pop(t,i){if(this.fired){if(i==-1)return this.decrement(t),!0;i==0&&this.increment(t)}else i==0&&(this.fired=!0,this.increment(t));return!1}},Iw=class{constructor(e,t){this.afterprop=e,this.element=t}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.processPseudoelementProps(this.afterprop,this.element),!0):!1}},Aw=class{constructor(e){this.lang=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.lang=this.lang,!0):!1}},Rw=class{constructor(e){this.oldQuotes=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.quotes=this.oldQuotes,!0):!1}},Fw=class extends Vi{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new ot(e):new ot("about:invalid");case"string":default:return e?new j(e):new j("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let t="string",i=null,n=null;if(e.values[0]instanceof te){let r=e.values[0].values;r.length>=2&&(t=r[1].stringValue()),i=r[0].stringValue()}else i=e.values[0].stringValue();return e.values.length>1?n=this.createValueFromString(e.values[1].stringValue(),t):n=this.createValueFromString(null,t),this.element&&this.element.hasAttribute(i)?this.createValueFromString(this.element.getAttribute(i),t):n}};function Ss(e,t){if(Rt(e)){if(e instanceof j)return e.stringValue();if(e instanceof $&&t){let i=e.expr.evaluate(t);return typeof i=="string"?i:typeof i=="number"?String(i):""}if(e instanceof te)return e.values.map(i=>Ss(i,t)).join("")}return""}var Cs=class extends Vi{constructor(e,t,i,n){super(),this.cascade=e,this.element=t,this.counterResolver=i,this.pseudoName=n}getCounterStore(){var e,t;return(t=(e=this.cascade.context)==null?void 0:e.counterStore)!=null?t:null}getPageScope(){var e,t;return(t=(e=this.cascade.context)==null?void 0:e.style)==null?void 0:t.pageScope}evaluateAndGetString(e){if(!e)return"";let t=this.cascade.quoteDepth,i=e.visit(this),n=Ss(i,this.cascade.context);return this.cascade.quoteDepth=t,n}visitIdent(e){let t=this.cascade,i=t.quotes,n=Math.floor(i.length/2)-1;switch(e.name){case"open-quote":{let r=i[2*Math.min(n,t.quoteDepth)];return t.quoteDepth++,r}case"close-quote":return t.quoteDepth>0&&t.quoteDepth--,i[2*Math.min(n,t.quoteDepth)+1];case"no-open-quote":return t.quoteDepth++,new j("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new j("")}return e}format(e,t){return this.cascade.counterStyleStore.format(t,e)}formatCounterList(e,t,i){if(!e.length)return this.format(0,i);let n=new ii;for(let r=0;r<e.length;r++)r>0&&n.append(t),n.append(this.format(e[r],i));return n.toString()}formatLastValue(e,t){let i=e.length?e[e.length-1]:0;return this.format(i,t)}buildCounterText(e,t,i,n,r){var s,o,a,h,l,u;let d=typeof r=="string",p=w=>d?this.formatCounterList(w,r,i):this.formatLastValue(w,i),f=w=>{this.pseudoName==="footnote-call"&&this.element&&nw(this.element,t,w)};if(this.pseudoName==="footnote-marker"&&this.element){let w=Zc(this.element)[t];if(w)return p(w)}let g;if(t==="pages")return p([]);if(!this.element){let w=((s=e.currentPageCounters)==null?void 0:s[t])||[];if(w.length)return g=w,f(g),p(g)}let m=this.element?n:((o=e.currentPageDocCounters)==null?void 0:o[t])||n;if((a=e.isPageControlledCounter)!=null&&a.call(e,t)){let w=((h=e.currentPageDocCounters)==null?void 0:h[t])||[],b=((l=e.currentPageCounters)==null?void 0:l[t])||[],x=b.length?b[b.length-1]:0,y=w.length?w[0]:0,P=m.length?m[0]:0,S=x+(P-y);return g=m.length?[S,...m.slice(1)]:b.length?b:[0],f(g),p(g)}return m.length?(g=m,f(g),p(g)):(g=((u=e.currentPageCounters)==null?void 0:u[t])||[],f(g),p(g))}visitFuncCounter(e){var t;let i=e[0].toString(),n=e.length>1?e[1].stringValue():"decimal",r=(this.cascade.counters[i]||[]).slice(),s=this.getCounterStore();if(s){let a=i==="pages"||((t=s?.isPageControlledCounter)==null?void 0:t.call(s,i)),h=this.getPageScope(),l=new Ie(h,()=>this.buildCounterText(s,i,n,r),a?`page-counter-${i}`:`counter-${i}`);if(a&&s!=null&&s.registerPageCounterExpr){let u=d=>this.formatLastValue(d,n);s.registerPageCounterExpr(i,u,l)}return new $(l)}let o=this.cascade.counters[i];if(o&&o.length){let a=o&&o.length&&o[o.length-1]||0;return new j(this.format(a,n))}else{let a=new $(this.counterResolver.getPageCounterVal(i,h=>this.format(h||0,n)));return new te([a])}}visitFuncCounters(e){var t;let i=e[0].toString(),n=e[1].stringValue(),r=e.length>2?e[2].stringValue():"decimal",s=(this.cascade.counters[i]||[]).slice(),o=this.getCounterStore();if(o){let u=i==="pages"||((t=o?.isPageControlledCounter)==null?void 0:t.call(o,i)),d=this.getPageScope(),p=new Ie(d,()=>this.buildCounterText(o,i,r,s,n),u?`page-counters-${i}`:`counters-${i}`);return u&&o!=null&&o.registerPageCounterExpr&&o.registerPageCounterExpr(i,f=>this.formatCounterList(f,n,r),p),new $(p)}let a=this.cascade.counters[i],h=new ii;if(a&&a.length)for(let u=0;u<a.length;u++)u>0&&h.append(n),h.append(this.format(a[u],r));let l=new $(this.counterResolver.getPageCountersVal(i,u=>{let d=[];if(u.length)for(let f=0;f<u.length;f++)d.push(this.format(u[f],r));let p=h.toString();return p.length&&d.push(p),d.length?d.join(n):this.format(0,r)}));return new te([l])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof ot?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",s=new $(this.counterResolver.getTargetCounterVal(i,n,o=>this.format(o||0,r)));return new te([s])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof ot?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e[2].stringValue(),s=e.length>3?e[3].stringValue():"decimal",o=new $(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,s));return h.length?h.join(r):this.format(0,s)}));return new te([o])}visitFuncTargetText(e){let t=e[0],i;t instanceof ot?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",r=new $(this.counterResolver.getTargetTextVal(i,n));return new te([r])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new $(this.counterResolver.getNamedStringVal(t,i))}visitFuncElement(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new $(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,r,s,o,a,h;let l=e.length>0?e[0].stringValue():"text",u="";switch(l){case"text":u=this.element.textContent;break;case"before":case"after":case"marker":{let d=(t=this.element)==null?void 0:t.querySelectorAll(`[data-adapt-pseudo="${l}"]`),p=null;if(d&&this.element)for(let f=0;f<d.length;f++){let g=d[f];if(g.parentElement===this.element){p=g;break}}if(p)u=p.textContent||"";else{let f=bt(this.cascade.currentStyle,"_pseudos"),g=(n=(i=f?.[l])==null?void 0:i.content)==null?void 0:n.value;if(g)u=this.evaluateAndGetString(g);else if(l==="marker"){let m=(r=this.cascade.currentStyle["--viv-marker-content"])==null?void 0:r.value;u=Ss(m,this.cascade.context)}}}break;case"first-letter":{let d=bt(this.cascade.currentStyle,"_pseudos"),p=(o=(s=d?.before)==null?void 0:s.content)==null?void 0:o.value,f=(h=(a=d?.after)==null?void 0:a.content)==null?void 0:h.value,g=(this.evaluateAndGetString(p)||this.element.textContent||this.evaluateAndGetString(f)).match(cs);u=g?g[0]:""}break}return new j(u)}visitFuncLeader(e){let t="";if(e[0]instanceof de)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof j&&(t=e[0].stringValue());return t.length==0?new j(""):new $(new Ie(null,()=>t,"viv-leader"))}visitFunc(e){switch(e.name){case"counter":if(e.values.length<=2)return this.visitFuncCounter(e.values);break;case"counters":if(e.values.length<=3)return this.visitFuncCounters(e.values);break;case"target-counter":if(e.values.length<=3)return this.visitFuncTargetCounter(e.values);break;case"target-counters":if(e.values.length<=4)return this.visitFuncTargetCounters(e.values);break;case"target-text":if(e.values.length>=1&&e.values.length<=2)return this.visitFuncTargetText(e.values);break;case"string":if(e.values.length<=2)return this.visitFuncString(e.values);break;case"element":if(e.values.length<=2)return this.visitFuncElement(e.values);break;case"content":if(e.values.length<=1)return this.visitFuncContent(e.values);break;case"leader":if(e.values.length<=1)return this.visitFuncLeader(e.values);break}return e}};function lo(e,t,i){let n;if(e.nodeType===1)n=Array.from(e.getClientRects());else{let r=e.ownerDocument.createRange();r.selectNodeContents(e),n=t.getRangeClientRects(r)}return n.reduce((r,s)=>r+(i==="vertical-rl"||i==="vertical-lr"?s.height:s.width),0)}var Lw=(e,t,i)=>{let n=t.filter(h=>h.after&&h.viewNode.nodeType===1&&h.viewNode.getAttribute("data-viv-leader"));for(let h of n){let l=function(E){y==="rtl"?g.textContent=(E.startsWith("\u200F")?"":"\u200F")+E+(E.endsWith("\u200F")?"":"\u200F"):g.textContent=E},u=function(){let E=i.clientLayout.getElementClientRect(m);return x==="vertical-rl"||x==="vertical-lr"?y==="rtl"?E.top-=C:E.bottom+=C:y==="rtl"?E.left-=C:E.right+=C,A.left>E.left||A.right<E.right||A.top>E.top||A.bottom<E.bottom},d=function(){let E,T,L=b.repeat(1e4);if(l(L),u())E=1,T=1e4;else return;for(let z=0;z<16;z++){let H="",K=Math.floor((E+T)/2);for(let ee=0;ee<K;ee++)H+=b;if(l(H),u())T=K;else{if(E==K)return;E=K}}l(b)},p=function(E){let T=0,L=m.parentElement;for(;L&&L!==f.viewNode;)T+=i.getComputedInsets(L)[E],L=L.parentElement;return T};var r=l,s=u,o=d,a=p;let f=h.parent;for(;f&&f.inline;)f=f.parent;let g=h.viewNode,m=g.parentElement,w=m.getAttribute("data-adapt-pseudo"),b=g.getAttribute("data-viv-leader-value"),{writingMode:x,direction:y,marginInlineEnd:P}=i.clientLayout.getElementComputedStyle(m);g.style.marginInlineStart="1px",l(b),m.style.display="inline-block",m.style.textIndent="0";let S=$s(f.viewNode),R=S?.style.columnFill||null;S&&(S.style.columnFill="auto");let A=i.clientLayout.getElementClientRect(f.viewNode),U=i.clientLayout.getElementClientRect(m),G=i.parseComputedLength(P),Z=[],fe=m.parentElement;for(;fe.parentElement&&fe.parentElement!==f.viewNode;)fe=fe.parentElement;let ue=fe.nextSibling;for(;ue;){if(ue.nodeType===1){let E=ue,{display:T,float:L,position:z}=i.clientLayout.getElementComputedStyle(E);if(L!=="none"||z==="absolute"||z==="fixed"){ue=ue.nextSibling;continue}if(Mt(T))Z.push(E);else if(Bm(T))break}else if(ue.nodeType===3){let E=ue;E.length>0&&Z.push(E)}ue=ue.nextSibling}let C=Z.reduce((E,T)=>E+lo(T,i.clientLayout,x),0);if(w!=="after"){let E=lo(fe,i.clientLayout,x),T=lo(m,i.clientLayout,x);C+=E-T}x==="vertical-rl"||x==="vertical-lr"?(y==="rtl"?A.top+=G:A.bottom-=G,A.top=Math.min(U.top,A.top),A.bottom=Math.max(U.bottom,A.bottom)):(y==="rtl"?A.left+=G:A.right-=G,A.left=Math.min(U.left,A.left),A.right=Math.max(U.right,A.right)),d();let _=i.clientLayout.getElementClientRect(m);y=="rtl"?m.style.float="left":m.style.float="right";let k=i.clientLayout.getElementClientRect(m),O=0;y=="rtl"?x=="vertical-rl"||x=="vertical-lr"?O=_.top-k.top-p("top"):O=_.left-k.left-p("left"):x=="vertical-rl"||x=="vertical-lr"?O=k.bottom-_.bottom-p("bottom"):O=k.right-_.right-p("right"),O-=C,O=Math.max(0,O-.1),m.style.float="",g.style.marginInlineStart=`${O}px`,S&&(R?S.style.columnFill=R:S.style.removeProperty("column-fill"))}};kt("POST_LAYOUT_BLOCK",Lw);var Ja=1/1048576;function Gi(e,t){for(let i in e)t[i]=e[i].clone()}var Ow=class ld{constructor(){c(this,"nsCount",0),c(this,"nsPrefix",{}),c(this,"tags",{}),c(this,"nstags",{}),c(this,"epubtypes",{}),c(this,"classes",{}),c(this,"ids",{}),c(this,"pagetypes",{}),c(this,"order",0)}clone(){let t=new ld;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return Gi(this.tags,t.tags),Gi(this.nstags,t.nstags),Gi(this.epubtypes,t.epubtypes),Gi(this.classes,t.classes),Gi(this.ids,t.ids),Gi(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,i,n){let r=t[i];r&&(n=r.mergeWith(n)),t[i]=n}createInstance(t,i,n,r,s,o){return new Bw(this,t,i,n,r,s,o)}nextOrder(){return this.order+=Ja}},hd=class ud{constructor(t,i,n,r,s,o,a){this.context=i,this.counterListener=n,this.counterResolver=r,this.counterStyleStore=o,this.cmykStore=a,c(this,"code"),c(this,"stack",[[],[]]),c(this,"conditions",Object.create(null)),c(this,"currentElement",null),c(this,"currentElementOffset",null),c(this,"currentStyle",null),c(this,"currentClassNames",null),c(this,"currentLocalName",""),c(this,"currentNamespace",""),c(this,"currentId",""),c(this,"currentXmlId",""),c(this,"currentNSTag",""),c(this,"currentEpubTypes",null),c(this,"currentPageType",null),c(this,"previousPageType",null),c(this,"firstPageType",null),c(this,"pageTypePageIndices",Object.create(null)),c(this,"isFirst",!0),c(this,"isRoot",!0),c(this,"counters",Object.create(null)),c(this,"lastCounterChanges",[]),c(this,"lastCounterChangeTypes",Object.create(null)),c(this,"counterScoping",[Object.create(null)]),c(this,"quotes"),c(this,"quoteDepth",0),c(this,"lang",""),c(this,"siblingOrderStack",[0]),c(this,"currentSiblingOrder",0),c(this,"siblingTypeCountsStack",[{}]),c(this,"currentSiblingTypeCounts"),c(this,"currentFollowingSiblingOrder",null),c(this,"followingSiblingOrderStack"),c(this,"followingSiblingTypeCountsStack",[{}]),c(this,"currentFollowingSiblingTypeCounts"),c(this,"viewConditions",Object.create(null)),c(this,"dependentConditions",[]),c(this,"elementStack"),this.code=t,this.quotes=[new j("\u201C"),new j("\u201D"),new j("\u2018"),new j("\u2019")],this.currentSiblingTypeCounts=this.siblingTypeCountsStack[0],this.followingSiblingOrderStack=[this.currentFollowingSiblingOrder],this.currentFollowingSiblingTypeCounts=this.siblingTypeCountsStack[0]}pushConditionItem(t){this.stack[this.stack.length-1].push(t)}increment(t,i){this.conditions[t]=(this.conditions[t]||0)+1,i&&(this.viewConditions[t]?this.viewConditions[t].push(i):this.viewConditions[t]=[i])}decrement(t,i){this.conditions[t]--,this.viewConditions[t]&&(this.viewConditions[t]=this.viewConditions[t].filter(n=>n!==i),this.viewConditions[t].length===0&&delete this.viewConditions[t])}buildViewConditionMatcher(t){let i=null;t&&(this.currentElementOffset,i=Or.buildViewConditionMatcher(this.currentElementOffset,t));let n=this.dependentConditions.map(r=>{let s=this.viewConditions[r];return s&&s.length>0?s.length===1?s[0]:Or.buildAnyMatcher([].concat(s)):null}).filter(r=>r);return n.length<=0?i:i===null?n.length===1?n[0]:Or.buildAllMatcher(n):Or.buildAllMatcher([i].concat(n))}applyAction(t,i){let n=t[i];n&&n.apply(this)}pushRule(t,i,n){this.currentElement=null,this.currentElementOffset=null,this.currentStyle=n,this.currentNamespace="",this.currentLocalName="",this.currentId="",this.currentXmlId="",this.currentClassNames=t,this.currentNSTag="",this.currentEpubTypes=ho,this.currentPageType=i,this.applyActions()}defineCounter(t,i){let n=this.counterScoping[this.counterScoping.length-1];n||(n=Object.create(null),this.counterScoping[this.counterScoping.length-1]=n),this.counters[t]?(n[t]&&this.counters[t].pop(),this.counters[t].push(i)):this.counters[t]=[i],n[t]=!0}pushCounters(t){var i,n,r,s,o,a,h;let l=new Set,u=Object.create(null),d=v.inline,p=t.display;if(p&&(d=p.evaluate(this.context)),d===v.none){this.currentElement.setAttribute("data-viv-display-none","true"),this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}else if(this.currentElement.closest("[data-viv-display-none]")){this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}let f=v.inline,g=t.float;g&&(f=g.evaluate(this.context));let m=null,w=null,b=null,x=t["counter-reset"];if(x){let S=x.evaluate(this.context);S&&(m=fn(S,{reset:!0}))}let y=t["counter-set"];if(y){let S=y.evaluate(this.context);S&&(b=fn(S,{defaultValue:0}))}let P=t["counter-increment"];if(P){let S=P.evaluate(this.context);S&&(w=fn(S))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(m||(m=Object.create(null)),m["list-item"]=((n=(i=this.currentElement)==null?void 0:i.start)!=null?n:1)-1),Hn(d)&&(w||(w=Object.create(null)),w["list-item"]=(r=w["list-item"])!=null?r:1,/^\s*[-+]?\d/.test((o=(s=this.currentElement)==null?void 0:s.getAttribute("value"))!=null?o:"")&&(b||(b=Object.create(null)),b["list-item"]=this.currentElement.value)),((a=this.currentElement)==null?void 0:a.parentNode.nodeType)===Node.DOCUMENT_NODE&&(m||(m=Object.create(null)),m.footnote===void 0&&(m.footnote=0)),f===v.footnote&&(w||(w=Object.create(null)),w.footnote===void 0)){let S=(h=this.currentStyle["counter-increment"])==null?void 0:h.value;(!S||!(S===v.footnote||S instanceof te&&S.values.includes(v.footnote)))&&(w.footnote=1)}if(m)for(let S in m)l.add(S),u[S]="reset";if(w)for(let S in w)l.add(S),u[S]||(u[S]="increment");if(b)for(let S in b)l.add(S),u[S]="set";if(this.lastCounterChanges=Array.from(l),this.lastCounterChangeTypes=u,m)for(let S in m)this.defineCounter(S,m[S]);if(w)for(let S in w){this.counters[S]||this.defineCounter(S,0);let R=this.counters[S];R[R.length-1]+=w[S]}if(b)for(let S in b)if(!this.counters[S])this.defineCounter(S,b[S]);else{let R=this.counters[S];R[R.length-1]=b[S]}if(Hn(d)){let S=this.counters["list-item"],R=S[S.length-1];t["ua-list-item-count"]=new D(new vt(R),0);let A=ei(t,"_pseudos");A.marker||(A.marker={})}this.counterScoping.push(null)}popCounters(){let t=this.counterScoping.pop();if(t)for(let i in t){let n=this.counters[i];n&&(n.length==1?delete this.counters[i]:n.pop())}}setNamedStrings(t){let i=t["string-set"];if(!i)return;i=i.filterValue(new Cs(this,this.currentElement,this.counterResolver));let n=i.value instanceof tt?i.value.values:[i.value];for(let r of n)if(r instanceof te){let s=r.values[0].stringValue(),o=r.values.slice(1).map(a=>Ss(a,this.context)).join("");this.counterResolver.setNamedString(s,o,this.currentElementOffset)}delete t["string-set"]}setRunningElement(t){let i=t.position;if(i?.value instanceof Ui&&i.value.name==="running"){let n=i.value.values[0].stringValue();this.counterResolver.setRunningElement(n,this.currentElementOffset)}}processPseudoelementProps(t,i,n){this.pushCounters(t);let r=t.content;r&&(t.content=r.filterValue(new Cs(this,i,this.counterResolver,n))),this.popCounters()}pushElement(t,i,n,r){var s,o,a;this.currentPageType=null,this.currentElement=i,this.currentElementOffset=r,this.currentStyle=n,this.currentNamespace=i.namespaceURI,this.currentLocalName=i.localName;let h=this.code.nsPrefix[this.currentNamespace];h?this.currentNSTag=h+this.currentLocalName:this.currentNSTag="",this.currentId=i.getAttribute("id"),this.currentXmlId=i.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let l=i.getAttribute("class");l?this.currentClassNames=l.split(/\s+/):this.currentClassNames=ho;let u=i.getAttributeNS("http://www.idpf.org/2007/ops","type");u?this.currentEpubTypes=u.split(/\s+/):this.currentEpubTypes=ho;let d=xo(i);d&&(this.stack[this.stack.length-1].push(new Aw(this.lang)),this.lang=d.toLowerCase());let p=this.isRoot,f=this.siblingOrderStack;this.currentSiblingOrder=++f[f.length-1],f.push(0);let g=this.siblingTypeCountsStack,m=this.currentSiblingTypeCounts=g[g.length-1],w=m[this.currentNamespace];w||(w=m[this.currentNamespace]={}),w[this.currentLocalName]=(w[this.currentLocalName]||0)+1,g.push({});let b=this.followingSiblingOrderStack;b[b.length-1]!==null?this.currentFollowingSiblingOrder=--b[b.length-1]:this.currentFollowingSiblingOrder=null,b.push(null);let x=this.followingSiblingTypeCountsStack,y=this.currentFollowingSiblingTypeCounts=x[x.length-1];y&&y[this.currentNamespace]&&y[this.currentNamespace][this.currentLocalName]--,x.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],t,i),this.applyCalcFilter(this.currentStyle,this.context),this.applyCmykFilter(this.currentStyle,this.currentElement),this.applyAttrFilter(i);let P=n.quotes,S=null;if(P){let U=P.evaluate(this.context);U&&(S=new Rw(this.quotes),U===v.none?this.quotes=[new j(""),new j("")]:U===v.auto||U===v.initial?this.quotes=[new j("\u201C"),new j("\u201D"),new j("\u2018"),new j("\u2019")]:U instanceof te&&(this.quotes=U.values))}this.pushCounters(this.currentStyle);let R=this.currentId||this.currentXmlId||i.getAttribute("name")||"";if(p||R){let U=Object.create(null);Object.keys(this.counters).forEach(G=>{U[G]=Array.from(this.counters[G])}),this.counterListener.countersOfId(R,U)}let A=bt(this.currentStyle,"_pseudos");if(A){let U=!0;for(let G of Mw){G||(U=!1);let Z=A[G];if(Z)if((G==="before"||G==="after")&&!(Rt((s=Z.content)==null?void 0:s.value)||this.hasNonTrivialViewConditionalPseudoContent(Z))||G==="marker"&&!Hn((o=ke(this.currentStyle,"display"))==null?void 0:o.value)||(G==="footnote-call"||G==="footnote-marker")&&((a=ke(this.currentStyle,"float"))==null?void 0:a.value)!==v.footnote)delete A[G];else if(U){if(this.processPseudoelementProps(Z,i,G),G==="marker")this.processMarkerPseudoelementProps(Z,i,t),delete A[G];else if(G==="footnote-marker")this.resolvePseudoelementInheritedPropertyValue(Z,"list-style-position",t,i)===v.outside&&(this.processMarkerPseudoelementProps(Z,i,t),this.currentStyle.display=new D(B("list-item"),0),this.currentStyle["list-style-position"]=new D(v.outside,0),this.currentStyle["list-style-type"]=new D(v.none,0),this.currentStyle["list-style-image"]=new D(v.none,0),delete A[G]);else if(G==="first-letter"&&Z["initial-letter"]){let fe=Z["initial-letter"].evaluate(this.context);fe!==v.normal&&!J(fe)&&(this.currentStyle["--viv-initialLetter"]=new D(fe,0)),delete Z["initial-letter"]}}else this.stack[this.stack.length-2].push(new Iw(Z,i))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),S&&this.stack[this.stack.length-2].push(S)}hasNonTrivialViewConditionalPseudoContent(t){let i=t._viewConditionalStyles;return!i||i.length<=0?!1:i.some(n=>{var r;return Rt((r=n.styles.content)==null?void 0:r.value)})}processMarkerPseudoelementProps(t,i,n){var r,s,o,a,h;let l=Hn((r=this.currentStyle.display)==null?void 0:r.value);if(!Rt((s=t.content)==null?void 0:s.value)&&l){let d=this.getInheritedPropertyValue("list-style-type",n,i),p=this.getInheritedPropertyValue("list-style-image",n,i);if(p instanceof ot)t.content=new D(new te([p,new j(" ")]),0);else if(d instanceof j)t.content=new D(d,0);else if(d instanceof de&&d!==v.none){let f=(a=(o=this.currentStyle["ua-list-item-count"])==null?void 0:o.value)==null?void 0:a.num;if(f!=null){let g=d.name.toLowerCase();g==="disc"||g==="circle"||g==="square"||g==="disclosure-open"||g==="disclosure-closed"||(t.content=new D(new j(this.counterStyleStore.formatMarker(d.name,f)),0))}}}let u=t.content;if(u){let d=u.value;if(Rt(d)){let p=this.resolveMarkerContentVal(d);this.currentStyle["--viv-marker-content"]=new D(p,0)}}for(let d of ud.markerAllowedProps){let p=t[d];if(p){let f=p.evaluate(this.context,d);f&&!J(f)&&(this.currentStyle[`--viv-marker-${d}`]=new D(f,0))}}if(!Mt((h=ke(this.currentStyle,"display"))==null?void 0:h.value)){let d=this.getInheritedPropertyValue("list-style-position",n,i);d&&d!==v.outside&&!J(d)&&(this.currentStyle["list-style-position"]=new D(d,0))}}resolveMarkerContentVal(t){if(t instanceof $){let i=t.expr.evaluate(this.context);return typeof i=="string"?new j(i):typeof i=="number"?new j(String(i)):t}if(t instanceof te){let i=t.values.map(n=>this.resolveMarkerContentVal(n));return new te(i)}return t}getInheritedPropertyValue(t,i,n){var r;for(let o=n;o;o=o.parentElement){let a=(o===this.currentElement?this.currentStyle:i.getStyle(o,!1))[t];if(a){let h=a.evaluate(this.context,t);if(h===v.inherit||h===v.unset||h===v.revert)continue;if(h===v.initial)break;return h}}let s=i.validatorSet;return(r=s?.defaultValues[t])!=null?r:null}resolvePseudoelementInheritedPropertyValue(t,i,n,r){var s;let o=t[i];if(o){let a=o.evaluate(this.context,i);if(a!==v.inherit&&a!==v.unset&&a!==v.revert){if(a===v.initial){let h=n.validatorSet;return(s=h?.defaultValues[i])!=null?s:null}return a}}return this.getInheritedPropertyValue(i,n,r)}applyAttrFilterInner(t,i){for(let n in i)Bi(n)&&!jt(n)&&(i[n]=i[n].filterValue(t))}applyAttrFilter(t){let i=new Fw(t),n=this.currentStyle,r=bt(n,"_pseudos");for(let s in r)this.applyAttrFilterInner(i,r[s]);this.applyAttrFilterInner(i,n)}applyVarFilter(t,i,n){var r,s,o;let a=t[0],h=new jw(t,i,n),l=32,u={};for(let d in a)if(jr(d)){let p=bt(a,d);for(let f in p)this.applyVarFilter([p[f],...t],i,n)}else if(Bi(d)){let p=ke(a,d),f=p.value;for(let g=0;;g++){if(g>=l){f=Y;break}let m=f.visit(h);if(h.error){f=Y,h.error=!1;break}if(m===f)break;f=m}if(f!==p.value){let g=i.validatorSet,m=(r=g?.shorthands[d])==null?void 0:r.clone();if(m)if(J(f)){for(let w of m.propList){let b=new D(f,p.priority),x=ke(a,w);yi(u,w,Xo(this.context,x,b))}delete a[d]}else{let w=vr(i.scope,new Xt(f.toString(),null),"");if(w&&(w.visit(m),!m.error)){for(let b of m.propList){let x=new D((o=(s=m.values[b])!=null?s:g.defaultValues[b])!=null?o:v.initial,p.priority),y=ke(a,b);yi(u,b,Xo(this.context,y,x))}delete a[d]}}else a[d]=new D(f,p.priority)}if(u[d]){let g=ke(a,d);g&&g.value!==Y&&Dt(u,d,g,this.context)}}for(let d in u)a[d]=u[d]}applyCalcFilter(t,i){let n=new yd(i);for(let r in t)if(jr(r)){let s=bt(t,r);for(let o in s)this.applyCalcFilter(s[o],i)}else if(Bi(r)&&!jt(r)){let s=ke(t,r),o=s.value.visit(n);o!==s.value&&(t[r]=new D(o,s.priority))}}applyCmykFilter(t,i){let n=new Hu(this.cmykStore);if(this.applyCmykFilterInternal(t,n,""),i){let r=n.getConversions();r&&i.setAttribute("data-viv-device-cmyk",JSON.stringify(r))}}applyCmykFilterInternal(t,i,n){for(let r in t)if(jr(r)){let s=bt(t,r);for(let o in s)this.applyCmykFilterInternal(s[o],i,`::${o}:`)}else if(Bi(r)&&!jt(r)){let s=ke(t,r),o=s.value.toString();i.reset();let a=s.value.visit(i);a!==s.value&&(i.hadDeviceCmyk()&&i.recordConversion(n+r,o),t[r]=new D(a,s.priority))}}applyActions(){let t;for(t=0;t<this.currentClassNames.length;t++)this.applyAction(this.code.classes,this.currentClassNames[t]);for(t=0;t<this.currentEpubTypes.length;t++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[t]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let i=1;i>=-1;--i){let n=this.stack[this.stack.length-i-2];for(t=0;t<n.length;)n[t].push(this,i)?n.splice(t,1):t++}this.isFirst=!0,this.isRoot=!1}pop(){for(let t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2],n=0;for(;n<i.length;)i[n].pop(this,t)?i.splice(n,1):n++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(t){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}};c(hd,"markerAllowedProps",["color","font-family","font-size","font-style","font-weight","font-variant","unicode-bidi","direction","white-space","text-transform","text-combine-upright"]);var Bw=hd,ho=[],Mw=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"],Jo=null;function _w(e){Jo=e}var ar=class extends In{constructor(e,t,i,n,r,s,o){super(e,t,o),this.condition=i,this.regionId=r,this.validatorSet=s,c(this,"chain",null),c(this,"specificity",0),c(this,"elementStyle",null),c(this,"conditionCount",0),c(this,"pseudoelement",null),c(this,"footnoteContent",!1),c(this,"cascade"),c(this,"state"),c(this,"viewConditionId",null),c(this,"insideSelectorRule"),c(this,"invalid",!1),this.cascade=n?n.cascade:Jo?Jo.clone():new Ow,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=qa(this.chain,e);t!==e&&t.makePrimary(this.cascade)||this.insertNonPrimary(t)}isInsideSelectorRule(e){return this.state!=0?(this.reportAndSkip(e),!0):!1}tagSelector(e,t){!t&&!e||(t&&(this.specificity+=1),t&&e?this.chain.push(new uw(e,t.toLowerCase())):t?this.chain.push(new rh(t.toLowerCase())):this.chain.push(new dw(e)))}invalidSelector(e){W.warn(e),this.chain.push(new Qe("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof kn;e=e.parent)e.parent.invalid=!0}classSelector(e){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by .${e}`);return}this.specificity+=256,this.chain.push(new lw(e))}pseudoclassSelector(e,t){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new bw);break;case"disabled":this.chain.push(new vw);break;case"checked":this.chain.push(new xw);break;case"root":case"scope":this.chain.push(new mw);break;case"link":this.chain.push(new rh("a")),this.chain.push(new sh("","href"));break;case"href-epub-type":case"href-role-type":if(t&&t.length>=1&&typeof t[0]=="string"){let i=t[0],n=new RegExp(`(^|\\s)${ai(i)}($|\\s)`),r=t[1];this.chain.push(new cw(n,r,e==="href-role-type"))}else this.chain.push(new Qe(""));break;case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new Qe(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new gw(new RegExp(`^${ai(i.toLowerCase())}($|-)`)))}else this.chain.push(new Qe(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=Dw[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new Qe(""));break}case"first-child":this.chain.push(new oh);break;case"last-child":this.chain.push(new Zo(0,1));break;case"first-of-type":this.chain.push(new Yo(0,1));break;case"last-of-type":this.chain.push(new Ko(0,1));break;case"only-child":this.chain.push(new oh),this.chain.push(new Zo(0,1));break;case"only-of-type":this.chain.push(new Yo(0,1)),this.chain.push(new Ko(0,1));break;case"empty":this.chain.push(new yw);break;case"before":case"after":case"first-line":case"first-letter":this.pseudoelementSelector(e,t);return;default:this.invalidSelector(`Unknown pseudo-class :${e}`);return}this.specificity+=256}pseudoelementSelector(e,t){switch(e){case"before":case"after":case"first-line":case"first-letter":case"footnote-call":case"footnote-marker":case"marker":case"inner":case"after-if-continues":if(!this.pseudoelement)this.pseudoelement=e;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break;case"first-n-lines":if(t&&t.length==1&&typeof t[0]=="number"){let i=Math.round(t[0]);if(i>0&&i==t[0]){if(!this.pseudoelement)this.pseudoelement=`first-${i}-lines`;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break}}this.chain.push(new Qe(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new Qe(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}idSelector(e){this.specificity+=65536,this.chain.push(new hw(e))}attributeSelector(e,t,i,n){this.specificity+=256,t=t.toLowerCase(),n=n||"";let r;switch(i){case 0:r=new sh(e,t);break;case 39:r=new pw(e,t,n);break;case 45:!n||n.match(/\s/)?r=new Qe(""):r=new _n(e,t,new RegExp(`(^|\\s)${ai(n)}($|\\s)`));break;case 44:r=new _n(e,t,new RegExp(`^${ai(n)}($|-)`));break;case 43:n?r=new _n(e,t,new RegExp(`^${ai(n)}`)):r=new Qe("");break;case 42:n?r=new _n(e,t,new RegExp(`${ai(n)}$`)):r=new Qe("");break;case 46:n?r=new _n(e,t,new RegExp(ai(n))):r=new Qe("");break;case 50:if(n=="supported")r=new fw(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(r)}descendantSelector(){let e=`d${Mr++}`;this.processChain(new Br(new Ew(e,this.viewConditionId,null))),this.chain=[new Qe(e)],this.viewConditionId=null}childSelector(){let e=`c${Mr++}`;this.processChain(new Br(new Pw(e,this.viewConditionId,null))),this.chain=[new Qe(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${Mr++}`;this.processChain(new Br(new Nw(e,this.viewConditionId,null))),this.chain=[new Qe(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${Mr++}`;this.processChain(new Br(new Tw(e,this.viewConditionId,null))),this.chain=[new Qe(e)],this.viewConditionId=null}nextSelector(){this.finishChain(),this.pseudoelement=null,this.footnoteContent=!1,this.specificity=0,this.chain=[]}startSelectorRule(){this.isInsideSelectorRule("E_CSS_UNEXPECTED_SELECTOR")||(this.state=1,this.elementStyle={},this.pseudoelement=null,this.specificity=0,this.footnoteContent=!1,this.chain=[],this.invalid=!1)}error(e,t){super.error(e,t),this.state==1&&(this.state=0),this.setInvalid()}startStylesheet(e){super.startStylesheet(e),this.state=0}startRuleBody(){this.finishChain(),super.startRuleBody(),this.state==1&&(this.state=0)}endRule(){super.endRule(),this.insideSelectorRule=0}finishChain(){this.chain&&(this.processChain(this.makeApplyRuleAction(this.specificity)),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0)}makeApplyRuleAction(e){let t=this.regionId;return this.footnoteContent&&(t?t="xxx-bogus-xxx":t="footnote"),new Za(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new Go(t,0,this.condition):i=new D(t,0),Qc(this.elementStyle,e).push(i)}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){e=="display"&&(t===v.oeb_page_head||t===v.oeb_page_foot)&&(this.simpleProperty("flow-options",new te([v.exclusive,v._static]),i),this.simpleProperty("flow-into",t,i),t=v.block),Ft("SIMPLE_PROPERTY").forEach(s=>{let o=s({name:e,value:t,important:i});e=o.name,t=o.value,i=o.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),r=this.condition?new Go(t,n,this.condition):new D(t,n);Dt(this.elementStyle,e,r)}finish(){return this.cascade}startFuncWithSelector(e,t){let i;switch(e){case"is":i=new kn(this);break;case"not":i=new zw(this);break;case"where":i=new Vw(this);break;case"has":i=new Uw(this);break;case"nth-child":t&&t.length>=2&&(i=new dd(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new Hw(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},Dw={"nth-child":ww,"nth-of-type":Yo,"nth-last-child":Zo,"nth-last-of-type":Ko},Mr=0,kn=class cd extends ar{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),this.parent=t,c(this,"parentChain"),c(this,"chains",[]),c(this,"maxSpecificity",0),c(this,"selectorTexts",[]),this.parentChain=t.chain}nextSelector(){this.chain&&this.chains.push(this.chain),this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.chain=[],this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(this.relational()?new Cw(this.selectorTexts):this.positive()?new Ka(this.chains):new Sw(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new Qe("")),this.owner.popHandler()}startRuleBody(){this.reportAndSkip("E_CSS_UNEXPECTED_RULE_BODY")}error(t,i){super.error(t,i),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0;let n=!1;for(let r=this;r instanceof cd;r=r.parent)if(r.forgiving()){n=!0;break}n||this.owner.popHandler()}pushSelectorText(t){this.chain&&this.relational()&&this.selectorTexts.push(t)}positive(){return!0}increasingSpecificity(){return!0}forgiving(){return!0}relational(){return!1}},zw=class extends kn{positive(){return!1}forgiving(){return!1}},Vw=class extends kn{increasingSpecificity(){return!1}},Uw=class extends kn{relational(){return!0}},dd=class extends kn{constructor(e,t,i){super(e),this.a=t,this.b=i}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new nd(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Qe("")),this.owner.popHandler()}forgiving(){return!0}},Hw=class extends dd{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new kw(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Qe("")),this.owner.popHandler()}},$w=class extends In{constructor(e,t){super(e,t,!1)}property(e,t,i){if(this.scope.values[e])this.error(`E_CSS_NAME_REDEFINED ${e}`,this.getCurrentToken());else{let n=e.match(/height|^(top|bottom)$/)?"vh":"vw",r=new gr(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,r))}}},Xr=class extends In{constructor(e,t,i,n,r,s){super(e,t,!1),this.condition=i,this.elementStyle=n,this.validatorSet=r,this.ruleType=s,c(this,"order"),this.order=0}property(e,t,i){i?W.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){W.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){W.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=Ja;let r=this.condition?new Go(t,n,this.condition):new D(t,n);Dt(this.elementStyle,e,r)}},Ww=class extends pc{constructor(e,t){super(e),this.validatorSet=t,c(this,"elementStyle",{}),c(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){W.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){W.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?dc:cc;n+=this.order,this.order+=Ja;let r=new D(t,n);Dt(this.elementStyle,e,r)}};function pd(e,t){let i=Kc(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function Qo(e,t,i){pd(i,n=>{Jn(e,n,t)})}function Gw(e,t,i,n){let r=new Ww(e,t),s=new Xt(n,r);try{Kg(s,r,i)}catch(o){W.warn(o,"Style attribute parse error:")}return r.elementStyle}function fd(e,t,i){let n=e["writing-mode"];if(n){let r=n.evaluate(t,"writing-mode");if(r&&r!==v.inherit&&r!==v.revert&&r!==v.unset)return r===v.vertical_rl}return i}function gd(e,t,i){let n=e.direction;if(n){let r=n.evaluate(t,"direction");if(r&&r!==v.inherit&&r!==v.revert&&r!==v.unset)return r===v.rtl}return i}function ea(e,t,i,n,r){let s={};for(let o in e)Bi(o)&&(s[o]=ke(e,o));return Qo(s,t,e),md(e,i,n,(o,a)=>{Jn(s,a,t),Qo(s,t,a)}),s}function md(e,t,i,n){let r=bt(e,"_regions");if((t||i)&&r){if(i){let s=["footnote"];t?t=t.concat(s):t=s}for(let s of t){let o=r[s];o&&n(s,o)}}}function Jn(e,t,i){for(let n in t)if(Bi(n)){let r=ke(t,n),s=e[n];e[n]=Xo(i,s,r)}}var wd=(e,t,i,n,r,s)=>{var o,a;let h=i?n?Qm:jc:n?ew:Xc,l=r?tw:iw;for(let u in e){let d=e[u];if(!d)continue;let p=(o=h[u])!=null?o:h[l[u]],f=(a=l[u])!=null?a:l[h[u]],g=p??f,m;if(g){let w=e[g];if(w&&w.priority>d.priority||p&&f&&p!==f&&(g=f,w=e[g],w&&w.priority>d.priority))continue;m=nh[p]?p:nh[f]?f:u}else m=u,u.startsWith("text-align")&&(d.value===v.inside||d.value===v.outside)&&(d=new D(r===(d.value===v.inside)?v.right:v.left,d.priority));t[m]=s(u,d)}},jw=class extends Vi{constructor(e,t,i){super(),this.elementStyles=e,this.styler=t,this.element=i}getVarValue(e){var t,i,n,r,s;let o=(t=this.element)!=null?t:this.styler.root;if((i=this.elementStyles)!=null&&i.length){for(let a of this.elementStyles){let h=(n=a[e])==null?void 0:n.value;if(h)return h}this.element&&(o=this.element.parentElement)}for(;o;o=o.parentElement){let a=(s=(r=this.styler.getStyle(o,!1))==null?void 0:r[e])==null?void 0:s.value;if(a)return a}return null}visitFunc(e){if(e.name!=="var")return super.visitFunc(e);let t=e.values[0]instanceof de&&e.values[0].name;return!t||!jt(t)?(this.error=!0,Y):this.getVarValue(t)||(e.values.length<2?(this.error=!0,Y):e.values.length===2?e.values[1]:new tt(e.values.slice(1)))}},yd=class extends Vi{constructor(e,t,i,n){super(),this.context=e,this.resolveViewportUnit=t,this.percentRef=i,this.vertical=n}visitFunc(e){let t=super.visitFunc(e);if(e.name!=="calc")return t;let i=t.toString().replace(/^calc\b/,"-epubx-expr");if(/\d(%|em|ex|cap|ch|ic|lh|p?v[whbi]|p?vmin|p?vmax)\W|\Wvar\(\s*--/i.test(i))return t;let n=vr(this.context.rootScope,new Xt(i,null),"");if(n instanceof $)try{let r=n.expr.evaluate(this.context);typeof r=="number"&&!isNaN(r)&&(/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(i)?t=new F(r,"px"):/\d[a-z]/i.test(i)||(t=new vt(r)))}catch(r){W.warn(r)}return t}visitNumeric(e){return this.resolveViewportUnit&&mu(e.unit)||this.context.rootFontSize!=null&&Ef(e.unit)?new F(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new F(e.num*this.percentRef/100,"px"):e}};function ks(e,t,i,n,r){try{if(t instanceof $)return t.expr instanceof Ie&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:tm(e,t.expr,i);if(t instanceof F||t instanceof Ui||t instanceof te||t instanceof tt)return t.visit(new yd(e,!0,n,r))}catch(s){return W.warn(s),Y}return t}var ah={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function lh(e){let t=e instanceof it?e:typeof e=="string"?B(e):v.none;if(t===v.none)return ah;let i=t instanceof te?t.values:[t],n=Object.create(ah);for(let r of i)if(r instanceof de)switch(r.name){case"first":n.first=!0;break;case"force-end":n.forceEnd=!0,n.allowEnd=!1;break;case"allow-end":n.forceEnd=!1,n.allowEnd=!0;break;case"last":n.last=!0;break}return n}function hh(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var Xw={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},uh={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},ch={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function dh(e){let t=e instanceof it?e:typeof e=="string"?B(e):v.normal;if(t===v.normal)return uh;if(t===v.auto)return ch;let i=t instanceof te?t.values:[t],n=Object.create(uh);for(let r of i)if(r instanceof de)switch(r.name){case"trim-both":case"trim-auto":return ch;case"space-all":return Xw;case"trim-start":n.trimStart=!0,n.spaceFirst=!1;break;case"space-start":n.trimStart=!1,n.spaceFirst=!1;break;case"space-first":n.trimStart=!1,n.spaceFirst=!0;break;case"trim-end":n.trimEnd=!0,n.allowEnd=!1;break;case"space-end":n.trimEnd=!1,n.allowEnd=!1;break;case"allow-end":n.trimEnd=!1,n.allowEnd=!0;break;case"trim-adjacent":n.trimAdjacent=!0;break;case"space-adjacent":n.trimAdjacent=!1;break}return n}var uo={ideographAlpha:!1,ideographNumeric:!1},qw={ideographAlpha:!0,ideographNumeric:!0};function ph(e){let t=e instanceof it?e:typeof e=="string"?B(e):v.normal;if(t===v.normal||t===v.auto)return qw;if(t===v.none)return uo;let i=t instanceof te?t.values:[t],n=Object.create(uo);for(let r of i)if(r instanceof de)switch(r.name){case"no-autospace":return uo;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function fh(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function gh(e){return e?(e=e.toLowerCase(),/^zh\b.*-(hant|tw|hk)\b/.test(e)?"zh-hant":/^zh\b/.test(e)?"zh-hans":/^ja\b/.test(e)?"ja":/^ko\b/.test(e)?"ko":e):null}var Yw=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(e){e.body&&this.preprocessForTextSpacing(e.body)}preprocessForTextSpacing(e){var t;let i=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT);for(let n=i.nextNode();n;n=i.nextNode()){if(n.parentElement.namespaceURI!=="http://www.w3.org/1999/xhtml"||((t=n.parentElement.dataset)==null?void 0:t.mathTypeset)==="true")continue;let r=n.textContent.replace(/(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000]\p{M}*(?=\P{M})|.(?=(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000])|(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*(?=(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}])|(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}]\p{M}*(?=(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF])/gsu,"$&\0").split("\0");if(r.length>1){let s=r.length-1;for(let o=0;o<s;o++)n.parentNode.insertBefore(document.createTextNode(r[o]),n);n.textContent=r[s]}}}processGeneratedContent(e,t,i,n,r,s){r=gh(r);let o=ph(t),a=dh(i),h=lh(n);if(hh(h)&&fh(o,a))return;this.preprocessForTextSpacing(e);let l=e.style.whiteSpace;(s?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let u=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),d=null,p=null;for(let f=u.nextNode();f;f=p){p=u.nextNode();let g=!d,m=!d||/\n$/.test(d.textContent),w=!p||/^\n/.test(p.textContent),b=!p;this.processTextSpacing(f,g||m,g,m,w,b,d,p,o,a,h,r,s),d=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,r,s,o,a,h,l;let u=!e||e.fragmentIndex===1&&f(),d=u||g();function p(x){var y;if(x?.nodeType!==1)return!1;let P=x;if(P.hasAttribute(Cn))return!0;let{position:S,float:R}=(y=P.style)!=null?y:{};return S==="absolute"||S==="fixed"||R&&R!=="none"}function f(){let x=t[0];for(let y=x;;y=y.parent)if(!y||!y.inline){if(y?.fragmentIndex!==1)return!1;break}if(!x.inline)return!0;for(let y=x.viewNode.previousSibling;y;y=y.previousSibling)if(!Me(y,x.whitespace)&&!p(y))return!1;return!0}function g(){var x,y;let P=t[0],S;for(;P&&P.inline&&(S=(x=P.viewNode)==null?void 0:x.previousSibling,!(S&&(S.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(S.textContent)&&P.whitespace!==dt.PRESERVE&&(S=S.previousSibling),S)));)P=P.parent;for(;S;){if(S.nodeType===Node.ELEMENT_NODE){if(S.localName==="br")return!0;let R=(y=S.style)==null?void 0:y.display;if(R&&R!=="inline")return!/^(inline|ruby)\b/.test(R)}else if(S.nodeType===Node.TEXT_NODE){if(P.whitespace===dt.PRESERVE){if(/\n$/.test(S.textContent))return!0}else if(P.whitespace===dt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(S.textContent))return!0}S=S.lastChild}return!1}let m=-1;for(let x=0;x<t.length;x++){let y=t[x];if(!y.after&&y.inline&&!y.display&&y.parent&&y.viewNode.parentNode&&y.viewNode.nodeType===Node.TEXT_NODE&&!Me(y.viewNode,y.whitespace)){let P=function(E){var T,L,z;if(((T=E.viewNode)==null?void 0:T.nodeType)===Node.ELEMENT_NODE)return E.viewNode.localName==="br";if(((L=E.viewNode)==null?void 0:L.nodeType)===Node.TEXT_NODE){let H=E.viewNode;if(E.whitespace===dt.PRESERVE){if(/\n$/.test(H.textContent))return!0}else if(E.whitespace===dt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(H.textContent))return!0;if(((z=H.previousElementSibling)==null?void 0:z.localName)==="br")return Me(H,E.whitespace)}return!1},S=function(E){var T,L,z;if(((T=E.viewNode)==null?void 0:T.nodeType)===Node.ELEMENT_NODE)return E.viewNode.localName==="br";if(((L=E.viewNode)==null?void 0:L.nodeType)===Node.TEXT_NODE){let H=E.viewNode;if(E.whitespace===dt.PRESERVE){if(/^\n/.test(H.textContent))return!0}else if(E.whitespace===dt.NEWLINE&&/^[ \t\r\n\f]*\n/.test(H.textContent))return!0;if(((z=H.nextElementSibling)==null?void 0:z.localName)==="br")return Me(H,E.whitespace)}return!1};var w=P,b=S;m<0&&(m=x);let R=gh((s=(n=(i=y.lang)!=null?i:y.parent.lang)!=null?n:e?.lang)!=null?s:(r=e?.parent)==null?void 0:r.lang),A=ph(y.inheritedProps["text-autospace"]),U=dh(y.inheritedProps["text-spacing-trim"]),G=lh(y.inheritedProps["hanging-punctuation"]);if(hh(G)&&fh(A,U)||/\b(flex|grid)\b/.test(y.parent.display))continue;let Z=null,fe=null,ue=x===m,C=x===m&&u,_=x===m&&d,k=!1,O=!1;for(let E=x-1;E>=0;E--){let T=t[E];if(P(T)){_=!0;break}if(!T.display&&T.viewNode.nodeType===Node.TEXT_NODE&&T.viewNode.textContent.length>0){Z=T.viewNode;break}if(((o=T.viewNode)==null?void 0:o.nodeType)===Node.ELEMENT_NODE&&Kt(T.viewNode)==="footnote-call"){if(T.viewNode.contains(y.viewNode))continue;let L=$m(T.viewNode);if(L){Z=L;break}}if(T.display&&!/^(inline|ruby)\b/.test(T.display)||((a=T.viewNode)==null?void 0:a.nodeType)===Node.ELEMENT_NODE&&(T.viewNode.localName==="br"||Oi[T.viewNode.localName]))break;E===0&&(ue=!0,u&&(C=!0,_=!0))}for(let E=x+1;E<t.length;E++){let T=t[E];if(S(T)){k=!0;break}if(T.viewNode!==y.viewNode&&!T.display&&T.viewNode.nodeType===Node.TEXT_NODE&&T.viewNode.textContent.length>0){fe=T.viewNode;break}if(T.display&&!/^(inline|ruby)\b/.test(T.display)||((h=T.viewNode)==null?void 0:h.nodeType)===Node.ELEMENT_NODE&&(T.viewNode.localName==="br"||Oi[T.viewNode.localName])){E===t.length-1&&p(T.viewNode)&&(O=!0);break}if(E===t.length-1){k=!0,O=!0;for(let L=T.viewNode.nextSibling;L;L=L.nextSibling)if(!p(L)){O=!1;break}}}if(((l=y.parent)==null?void 0:l.display)==="inline-block"){if(!C){let E=y.parent.viewNode.firstChild;for(;Me(E,y.whitespace);)E=E.nextSibling;y.viewNode===E&&(C=!0)}if(!O){let E=y.parent.viewNode.lastChild;for(;Me(E,y.whitespace);)E=E.previousSibling;y.viewNode===E&&(O=!0)}}if(this.processTextSpacing(y.viewNode,ue,C,_,k,O,Z,fe,A,U,G,R,y.vertical)>0)break}}}processTextSpacing(e,t,i,n,r,s,o,a,h,l,u,d,p){let f=e.textContent,g=e.ownerDocument,m=0,w,b,x;function y(){if(t)return!0;if(!o)return!1;w||(w=g.createRange(),w.selectNode(e));let k=w.getClientRects()[0];if(!k)return!1;b||(b=g.createRange(),b.selectNode(o));let O=b.getClientRects(),E=O[O.length-1];return E?(m||(m=or(E,p)),p?k.top<E.top+E.height-k.width||k.left+k.width<E.left+k.width/10||k.left>E.left+E.width-k.width/10:k.left<E.left+E.width-k.height||k.top>E.top+E.height-k.height/10||k.top+k.height<E.top+k.height/10):!1}function P(){if(!a)return!1;w||(w=g.createRange(),w.selectNode(e));let k=w.getClientRects()[0];if(!k)return!1;m||(m=or(k,p)),x||(x=g.createRange(),x.selectNode(a));let O=x.getClientRects()[0];return O?p?k.top+k.height>O.top+k.width||k.left>O.left+O.width-k.width/10||k.left+k.width<O.left+k.width/10:k.left+k.width>O.left+k.height||k.top+k.height<O.top+k.height/10||k.top>O.top+O.height-k.height/10:!1}let S=!1,R=!1,A=!1,U=!1,G;if(i&&u.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(G="viv-ts-open",S=!0,R=!0):s&&u.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(G="viv-ts-close",S=!0,A=!0):(u.forceEnd||u.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(G="viv-ts-close",S=!0,U=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(G="viv-ts-open",S=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||d==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||d!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(G="viv-ts-close",S=!0),S){let k=function(z){let H=parseFloat(g.defaultView.getComputedStyle(z).fontSize)*.7;return(p?z.offsetHeight:z.offsetWidth)>H},O=function(){return p?E.offsetLeft:E.offsetTop};var Z=k,fe=O;if(e.parentElement.localName==="viv-ts-inner")return 0;let E=g.createElement(G),T=g.createElement("viv-ts-inner");E.appendChild(T),e.parentNode.insertBefore(E,e),T.appendChild(e);let L=k(T);if(L||R||A||U){if(G==="viv-ts-open"){if(R)E.className="viv-hang-first";else if(i||n)l.trimStart?E.className="viv-ts-trim":E.className="viv-ts-space";else if(!(l.trimStart||l.spaceFirst)&&y())E.className="viv-ts-space";else if(l.trimAdjacent&&o&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(o.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(o.textContent)||o.parentElement.localName==="viv-ts-inner"&&k(o.parentElement)))E.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&y()){let z=O();E.className="viv-ts-auto",z===O()&&!y()&&(E.className="viv-ts-trim")}}else if(G==="viv-ts-close"){if(A)E.className=L?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(s||r){let z=O();U?(E.className=L?u.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",u.allowEnd&&z===O()&&(l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-hang-end",z===O()&&(E.className="")):E.className="viv-ts-space")):l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-ts-auto",z===O()&&(E.className="")):E.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))L&&l.trimAdjacent&&(E.className="viv-ts-trim");else if(U){let z=P(),H=z&&u.allowEnd;H||(E.className=L?"viv-hang-end":"viv-hang-end viv-hang-hw"),L?H&&l.trimEnd?E.className="viv-ts-auto":!H&&!P()?E.className="":!z&&u.allowEnd&&(l.trimEnd?(E.className="viv-ts-auto",P()||(E.className="viv-hang-end")):(E.className="viv-ts-space",P()||(l.allowEnd?(E.className="viv-ts-auto",P()||(E.className="viv-hang-end")):E.className="viv-hang-end"))):!z&&!P()&&(E.className="")}else if(l.trimEnd||l.allowEnd)if(P())l.allowEnd?E.className="viv-ts-space":E.className="viv-ts-auto";else{let z=O();E.className="viv-ts-auto",z===O()&&(E.className="")}}}}let ue=!1;function C(k){var O;let E=(O=k?.ownerDocument.defaultView)==null?void 0:O.getComputedStyle(k);return!!E&&(E.textOrientation==="upright"||E.textCombineUpright==="all"||E["-webkit-text-combine"]==="horizontal")}function _(k,O){if(k.nodeType===Node.ELEMENT_NODE){let L=g.defaultView.getComputedStyle(k);if(parseFloat(L.marginInlineEnd)||parseFloat(L.borderInlineEndWidth)||parseFloat(L.paddingInlineEnd))return!0}let E=k.parentElement;if(E&&!E.contains(O))return _(E,O);if(O.nodeType===Node.ELEMENT_NODE){let L=g.defaultView.getComputedStyle(O);if(parseFloat(L.marginInlineStart)||parseFloat(L.borderInlineStartWidth)||parseFloat(L.paddingInlineStart))return!0}let T=O.parentElement;return T&&!T.contains(k)?_(k,T):!1}return(h.ideographAlpha||h.ideographNumeric)&&(o&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(h.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(o.textContent)||h.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(o.textContent))&&!(p&&C(o.parentElement))&&!_(o,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),ue=!0),a&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(f)&&(h.ideographAlpha&&/^(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}/u.test(a.textContent)||h.ideographNumeric&&/^(?![\uFF01-\uFF60])\p{Nd}/u.test(a.textContent))&&!(p&&C(a.parentElement))&&!_(e,a)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e.nextSibling),ue=!0)),m}registerHooks(){kt("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),kt("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),kt("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},Qa=new Yw;Qa.registerHooks();function Zw(e){Qa.preprocessForTextSpacing(e)}function Kw(e,t,i,n,r,s){Qa.processGeneratedContent(e,t,i,n,r,s)}var $n=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),Jw=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],el="data-adapt-pseudo";function Kt(e){return e.getAttribute(el)||""}function qr(e,t){e.setAttribute(el,t)}var co=class{constructor(e,t,i,n,r){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=r,c(this,"contentProcessed",{})}getStyle(e,t){let i=Kt(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=bt(this.style,"_pseudos"),r=n?.[i]||{};if(i.match(/^first-/)&&!r["x-first-pseudo"]){let s=1,o;i=="first-letter"?s=0:(o=i.match(/^first-([0-9]+)-lines$/))!=null&&(s=o[1]-0),r["x-first-pseudo"]=new D(new Be(s),0)}return r}processContent(e,t,i){let n=Kt(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let r=t.content;Rt(r)&&(r.visit(new sr(e,this.context,r,this.exprContentListener)),Zw(e))}}},C0=ms.isInstanceOfAfterIfContinuesLayoutConstraint,Qw=Ws.registerFragmentIndex,k0=Ws.clearFragmentIndices,ey=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new tl(e,i,t),r=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=r;let s=i.firstChild;return I(s,"display","block"),N(s)})}createNodePositionForPseudoElement(){let e=$n.createElementNS("http://www.w3.org/1999/xhtml","div");qr(e,"after-if-continues");let t=this.createShadowContext(e),i={steps:[{node:e,shadowType:t.type,shadowContext:t,nodeShadow:null,shadowSibling:null}],offsetInNode:0,after:!1,preprocessedTextContent:null};return new xi(i)}createShadowContext(e){return new Wr(this.sourceNode,e,null,null,null,ri.ShadowType.ROOTED,this.styler)}},ty=class bd{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,c(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,i,n){return!(i&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,i,n,r){}finishBreak(t,i){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(i,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),N(!0))):N(!0)}getRepetitiveElements(){return new iy(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof bd?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},iy=class{constructor(e,t){this.nodeContext=e,this.pseudoElementHeight=t}calculateOffset(e){return this.affectTo(e)?this.pseudoElementHeight:0}calculateMinimumOffset(e){return this.calculateOffset(e)}affectTo(e){if(!e)return!1;let t=e.shadowContext?e.shadowContext.owner:e.sourceNode;if(t===this.nodeContext.sourceNode)return!!e.after;for(let i=t.parentNode;i;i=i.parentNode)if(i===this.nodeContext.sourceNode)return!0;return!1}};function vd(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return N(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let r=ry(e,t,n);return t.fragmentLayoutConstraints.push(new ty(e,i,r)),N(e)})}function xd(e,t){return e.thenAsync(i=>vd(i,t))}function ny(e,t){let i=M("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let r=vd(n,t);return n=n.parent,r.thenReturn(!0)}else return N(!1)}).then(()=>{i.finish(!0)}),i.result()}function ry(e,t,i){let n=e.viewNode;n.appendChild(i);let r=Vo(i,t,e.vertical);return n.removeChild(i),r}var sy=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},Yr=class extends Wa{constructor(e,t){super(),this.checkPoints=e,this.penalty=t,c(this,"alreadyEvaluated",!1),c(this,"breakNodeContext",null)}findAcceptableBreak(e,t){return t<this.getMinBreakPenalty()?null:(this.alreadyEvaluated||(this.breakNodeContext=e.findBoxBreakPosition(this,t>0),this.alreadyEvaluated=!!this.breakNodeContext||t>0||!!e.pseudoParent),this.breakNodeContext)}getMinBreakPenalty(){return this.penalty}getNodeContext(){return this.alreadyEvaluated?this.breakNodeContext:this.checkPoints[this.checkPoints.length-1]}},Es=class extends Fc{constructor(e,t,i,n,r){super(e),this.layoutContext=t,this.clientLayout=i,this.layoutConstraint=n,this.pageFloatLayoutContext=r,c(this,"last"),c(this,"viewDocument"),c(this,"flowRootFormattingContext",null),c(this,"isNonFirstColumn",!1),c(this,"isFloat",!1),c(this,"isFootnote",!1),c(this,"startEdge",0),c(this,"endEdge",0),c(this,"beforeEdge",0),c(this,"afterEdge",0),c(this,"footnoteEdge",0),c(this,"box",null),c(this,"chunkPositions",null),c(this,"bands",null),c(this,"overflown",!1),c(this,"breakPositions",null),c(this,"pageBreakType",null),c(this,"forceNonfitting",!0),c(this,"leftFloatEdge",0),c(this,"rightFloatEdge",0),c(this,"bottommostFloatTop",0),c(this,"stopAtOverflow",!0),c(this,"lastAfterPosition",null),c(this,"fragmentLayoutConstraints",[]),c(this,"pseudoParent",null),c(this,"nodeContextOverflowingDueToRepetitiveElements",null),c(this,"blockDistanceToBlockEndFloats",NaN),c(this,"lastLineStride",0),c(this,"breakAtTheEdgeBeforeFloat",null),Dm(this),this.last=e.lastChild,this.viewDocument=e.ownerDocument,r.setContainer(this)}getTopEdge(){return this.vertical?this.rtl?this.endEdge:this.startEdge:this.beforeEdge}getBottomEdge(){return this.vertical?this.rtl?this.startEdge:this.endEdge:this.afterEdge}getLeftEdge(){return this.vertical?this.afterEdge:this.rtl?this.endEdge:this.startEdge}getRightEdge(){return this.vertical?this.beforeEdge:this.rtl?this.startEdge:this.endEdge}isFloatNodeContext(e){return!!e.floatSide&&(!this.isFloat||!!e.parent)}stopByOverflow(e){return this.stopAtOverflow&&!!e&&e.overflow}almostEquals(e,t,i=1.5/(this.clientLayout.pixelRatio||1)){return Math.abs(e-t)<i}isOverflown(e){return this.almostEquals(e,this.footnoteEdge)?!1:this.vertical?e<this.footnoteEdge:e>this.footnoteEdge}getExclusions(){let e=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(e)}openAllViews(e){let t=M("openAllViews"),i=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let n=i.length-1,r=null;return t.loop(()=>{for(;n>=0;){let s=r,o=i[n];if(r=ys(o,s),n===i.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),n==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),r.after=e.after,r.preprocessedTextContent=e.preprocessedTextContent,r.after))break;let a=this.layoutContext.setCurrent(r,n==0&&r.offsetInNode==0);if(n--,a.isPending())return a}return N(!1)}).then(()=>{t.finish(r)}),t.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?dm(e.preprocessedTextContent,e.offsetInNode):e.offsetInNode}maybePeelOff(e,t){var i,n;if(e.firstPseudo&&e.inline&&!e.after&&e.firstPseudo.count==0&&e.viewNode.nodeType!=1){let r=e.viewNode.textContent,s=r.match(cs),o=s?s[0].length:0;if(!s&&((i=e.sourceNode)==null?void 0:i.nodeType)===3&&((n=e.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&r===e.sourceNode.textContent){let a=r+e.sourceNode.nextSibling.textContent,h=a.match(cs);if(h){let l=h[0];o=l.length,e.sourceNode.textContent=l,e.viewNode.textContent=l,e.sourceNode.nextSibling.textContent=a.substr(o)}}return this.layoutContext.peelOff(e,o)}return N(e)}buildViewToNextBlockEdge(e,t){let i=!1,n=M("buildViewToNextBlockEdge");return n.loopWithFrame(r=>{var s;if(e.viewNode&&!ln(e)&&((s=e.viewNode.parentElement)==null?void 0:s.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(t.push(e.copy()),t.length>1e3)){let o=e.viewNode.nodeType===1?e.viewNode:e.viewNode.parentElement,a=this.clientLayout.getElementClientRect(o);if(or(a,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(o=>{let a=o;a!==e&&(e=a,ln(e)||t.push(e.copy())),this.nextInTree(e).then(h=>{if(e=h,!e){r.breakLoop();return}(i||!this.layoutConstraint.allowLayout(e))&&(i=!0,e=e.modify(),e.overflow=!0),this.isFloatNodeContext(e)&&(wi(e.floatReference)||e.floatSide==="footnote")?this.layoutFloatOrFootnote(e).then(l=>{if(e=l,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()}):e.inline?r.continueLoop():r.breakLoop()})})}).then(()=>{n.finish(e)}),n.result()}nextInTree(e,t){let i=this.layoutContext.nextInTree(e,t);return xd(i,this)}buildDeepElementView(e){if(!e.viewNode)return N(e);let t=[],i=e.sourceNode,n=M("buildDeepElementView");return n.loopWithFrame(r=>{e.viewNode&&e.inline&&!ln(e)?t.push(e.copy()):(t.length>0&&this.postLayoutBlock(e,t),t=[]),this.maybePeelOff(e,0).then(s=>{let o=s;if(o!==e){let a=o;for(;a&&a.sourceNode!=i;)a=a.parent;if(a==null){e=o,r.breakLoop();return}ln(o)||t.push(o.copy())}this.nextInTree(o).then(a=>{if(e=a,!e||e.sourceNode==i){r.breakLoop();return}if(!this.layoutConstraint.allowLayout(e)&&(e=e.modify(),e.overflow=!0,this.stopAtOverflow)){r.breakLoop();return}if(this.isFloatNodeContext(e)&&(wi(e.floatReference)||e.floatSide==="footnote")){this.layoutFloatOrFootnote(e).then(h=>{if(e=h,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()});return}r.continueLoop()})})}).then(()=>{t.length>0&&this.postLayoutBlock(e,t),n.finish(e)}),n.result()}createFloat(e,t,i,n){let r=this.viewDocument.createElement("div");return this.vertical?(n>=this.height&&(n-=.1),n<1&&(n=0),I(r,"height",`${i}px`),I(r,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),I(r,"width",`${i}px`),I(r,"height",`${n}px`)),I(r,"float",t),I(r,"clear",t),this.element.insertBefore(r,e),r}killFloats(){let e=this.element.firstChild;for(;e;){let t=e.nextSibling;if(e.nodeType==1){let i=e,n=i.style.cssFloat;if(n=="left"||n=="right"||n==="none")this.element.removeChild(i);else break}e=t}}createFloats(){let e=this.element.firstChild,t=this.bands,i=this.vertical?this.getTopEdge():this.getLeftEdge(),n=this.vertical?this.getBottomEdge():this.getRightEdge(),r=this.vertical?-this.getRightEdge():this.getTopEdge(),s=this.vertical?-this.getLeftEdge():this.getBottomEdge(),o=null;for(let d of t)this.almostEquals(d.x1,i)?d.x1=i:this.almostEquals(d.x1,n)&&(d.x1=n),this.almostEquals(d.x2,n)?d.x2=n:this.almostEquals(d.x2,i)&&(d.x2=i),this.almostEquals(d.y1,r)?d.y1=r:this.almostEquals(d.y1,s)&&(d.y1=s),this.almostEquals(d.y2,s)?d.y2=s:this.almostEquals(d.y2,r)&&(d.y2=r);let a=1/(this.clientLayout.pixelRatio||1),h=Na==="webkit"?Math.floor:Math.round,l=t.map(d=>(h(d.y2/a)-h(d.y1/a))*a),u=.01;for(let d=0;d<t.length;d++){let p=d<t.length-1?t[d+1].x1:i,f=d<t.length-1?t[d+1].x2:n,g=p-t[d].x1,m=t[d].x2-f,w=0,b=0;g>u?w=1:g<-u&&(w=-1),m>u?b=1:m<-u&&(b=-1);let x=w!==0&&b!==0?w===b?w:0:w||b;if(x!==0){let y=x*a;l[d]+y>=0&&(d>=t.length-1||l[d+1]-y>=0)&&(l[d]+=y,d<t.length-1&&(l[d+1]-=y))}}for(let d=0;d<t.length;d++){let p=t[d];p.left=this.createFloat(e,"left",p.x1-i,l[d]),p.right=this.createFloat(e,"right",n-p.x2,l[d]),p.x1<n&&p.x2>i?o=p:o||I(p.right,"float","none")}if(o){let d=t[t.length-1];if(o!==d&&d.y2>=s&&(this.footnoteEdge=this.vertical?-o.y2:o.y2,o.x1===i&&o.x2===n))for(let p=t.indexOf(o);p<t.length;p++){let f=t[p];this.element.removeChild(f.left),this.element.removeChild(f.right),f.left=null,f.right=null}}this.adjustColumnBlockSizeForBlockEndFloats()}adjustColumnBlockSizeForBlockEndFloats(){var e;if(this.element.hasAttribute("data-vivliostyle-in-column-balancing")||(e=this.element.parentElement)!=null&&e.hasAttribute("data-vivliostyle-in-column-balancing"))return;let t=this.vertical?this.width:this.height,i=this.getBoxDir()*(this.footnoteEdge-this.beforeEdge);if(i>0&&i<t&&!this.almostEquals(i,t)){let n=this.vertical?"width":"height";if(I(this.element,n,`${i}px`),this.vertical){let r=this.left+(t-i);I(this.element,"left",`${r}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(e,t,i,n){let r;if(e&&an(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(r=tn(e,this.clientLayout,0,this.vertical),!isNaN(r)))return r;e=t[i];let s=n-e.boxOffset;for(;;){if(r=tn(e,this.clientLayout,s,this.vertical),!isNaN(r))return r;if(s>0){s--;continue}if(i--,i<0)return this.beforeEdge;e=t[i],e.viewNode.nodeType!=1&&(s=e.viewNode.textContent.length)}}parseComputedLength(e){let t=e.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return t?this.clientLayout.adjustLengthValue(parseFloat(t[0])):0}getComputedMargin(e){let t=this.clientLayout.getElementComputedStyle(e),i=new io(0,0,0,0);return t&&(i.left=this.parseComputedLength(t.marginLeft),i.top=this.parseComputedLength(t.marginTop),i.right=this.parseComputedLength(t.marginRight),i.bottom=this.parseComputedLength(t.marginBottom)),i}getComputedPaddingBorder(e){let t=this.clientLayout.getElementComputedStyle(e),i=new io(0,0,0,0);return t&&(i.left=this.parseComputedLength(t.borderLeftWidth)+this.parseComputedLength(t.paddingLeft),i.top=this.parseComputedLength(t.borderTopWidth)+this.parseComputedLength(t.paddingTop),i.right=this.parseComputedLength(t.borderRightWidth)+this.parseComputedLength(t.paddingRight),i.bottom=this.parseComputedLength(t.borderBottomWidth)+this.parseComputedLength(t.paddingBottom)),i}getComputedInsets(e){let t=this.clientLayout.getElementComputedStyle(e),i=new io(0,0,0,0);if(t){if(t.boxSizing=="border-box")return this.getComputedMargin(e);i.left=this.parseComputedLength(t.marginLeft)+this.parseComputedLength(t.borderLeftWidth)+this.parseComputedLength(t.paddingLeft),i.top=this.parseComputedLength(t.marginTop)+this.parseComputedLength(t.borderTopWidth)+this.parseComputedLength(t.paddingTop),i.right=this.parseComputedLength(t.marginRight)+this.parseComputedLength(t.borderRightWidth)+this.parseComputedLength(t.paddingRight),i.bottom=this.parseComputedLength(t.marginBottom)+this.parseComputedLength(t.borderBottomWidth)+this.parseComputedLength(t.paddingBottom)}return i}setComputedInsets(e,t){let i=this.clientLayout.getElementComputedStyle(e);i&&(t.marginLeft=this.parseComputedLength(i.marginLeft),t.borderLeft=this.parseComputedLength(i.borderLeftWidth),t.paddingLeft=this.parseComputedLength(i.paddingLeft),t.marginTop=this.parseComputedLength(i.marginTop),t.borderTop=this.parseComputedLength(i.borderTopWidth),t.paddingTop=this.parseComputedLength(i.paddingTop),t.marginRight=this.parseComputedLength(i.marginRight),t.borderRight=this.parseComputedLength(i.borderRightWidth),t.paddingRight=this.parseComputedLength(i.paddingRight),t.marginBottom=this.parseComputedLength(i.marginBottom),t.borderBottom=this.parseComputedLength(i.borderBottomWidth),t.paddingBottom=this.parseComputedLength(i.paddingBottom))}setComputedWidthAndHeight(e,t){let i=this.clientLayout.getElementComputedStyle(e);i&&(t.width=this.parseComputedLength(i.width),t.height=this.parseComputedLength(i.height))}layoutUnbreakable(e){return this.buildDeepElementView(e)}layoutFloat(e){let t=M("layoutFloat"),i=e.viewNode,n=ao(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return I(i,"float","none"),I(i,"display","inline-block"),I(i,"vertical-align","top"),this.buildDeepElementView(e).then(r=>{let s=It(this.clientLayout,i,this.vertical),o=this.getComputedMargin(i),a=new Ct(s.left-o.left,s.top-o.top,s.right+o.right,s.bottom+o.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,u=e.parent;for(;u&&u.inline;)u=u.parent;if(u){let y=u.viewNode.ownerDocument.createElement("div");y.style.left="0px",y.style.top="0px",this.vertical?(y.style.bottom="0px",y.style.width="1px"):(y.style.right="0px",y.style.height="1px"),u.viewNode.appendChild(y);let P=It(this.clientLayout,y,this.vertical);h=Math.max(this.rtl?this.getEndEdge(P):this.getStartEdge(P),h),l=Math.min(this.rtl?this.getStartEdge(P):this.getEndEdge(P),l),u.viewNode.removeChild(y);let S=this.vertical?a.y2-a.y1:a.x2-a.x1;n=="left"?l=Math.max(l,h+S):h=Math.min(h,l-S),u!==e.parent&&!e.firstPseudo&&(u.viewNode.appendChild(i),i.setAttribute("data-vivliostyle-float-box-moved","true"))}let d=new Ct(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),p=a;this.vertical&&(p=ps(a));let f=this.getBoxDir();if(p.y1<this.bottommostFloatTop*f){let y=p.y2-p.y1;p.y1=this.bottommostFloatTop*f,p.y2=p.y1+y}if(e.clearSide){let y=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(e.clearSide)?ao(e.clearSide,e.vertical,e.direction,this.layoutContext.page.side):e.clearSide==="same"?n:e.clearSide,P=this.beforeEdge;y!=="right"&&(P=f*Math.max(P*f,this.leftFloatEdge*f)),y!=="left"&&(P=f*Math.max(P*f,this.rightFloatEdge*f));let S=P*f;if(p.y1<S){let R=p.y2-p.y1;p.y1=S,p.y2=p.y1+R}}d.y2+=1/(this.clientLayout.pixelRatio||1),Qf(d,this.bands,p,n),this.vertical&&(a=ju(p));let g=this.getComputedInsets(i);I(i,"width",`${a.x2-a.x1-g.left-g.right}px`),I(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),I(i,"position","absolute"),e.display,I(i,"display",e.display);let m,w=null;if(u&&(u.containingBlockForAbsolute?w=u:w=u.getContainingBlockForAbsolute()),w){let y=w.viewNode.ownerDocument.createElement("div");y.style.position="absolute",w.vertical?y.style.right="0":y.style.left="0",y.style.top="0",w.viewNode.appendChild(y),m=It(this.clientLayout,y,this.vertical),w.viewNode.removeChild(y)}else m={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};(w?w.vertical:this.vertical)?I(i,"right",`${m.right-a.x2}px`):I(i,"left",`${a.x1-m.left}px`),I(i,"top",`${a.y1-m.top}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let b=this.vertical?a.x1:a.y2,x=this.vertical?a.x2:a.y1;!this.isOverflown(b)||this.breakPositions.length==0?(this.killFloats(),d=new Ct(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(d=ps(d)),eg(d,this.bands,p,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=b:this.rightFloatEdge=b,this.bottommostFloatTop=x,this.updateMaxReachedAfterEdge(b),t.finish(r)):(e=e.modify(),e.overflow=!0,t.finish(e))}),t.result()}setupFloatArea(e,t,i,n,r,s){let o=this.pageFloatLayoutContext,a=o.getContainer(t),h=e.element;a.element.parentNode.appendChild(h),e.isFloat=!0,e.originX=a.originX,e.originY=a.originY,e.vertical=a.vertical,e.rtl=a.rtl,e.marginLeft=e.marginRight=e.marginTop=e.marginBottom=0,e.borderLeft=e.borderRight=e.borderTop=e.borderBottom=0,e.paddingLeft=e.paddingRight=e.paddingTop=e.paddingBottom=0,e.exclusions=(a.exclusions||[]).concat(),e.forceNonfitting=!o.hasFloatFragments(),e.innerShape=null;let l=a.getPaddingRect();return e.setHorizontalPosition(l.x1-a.originX,l.x2-l.x1),e.setVerticalPosition(l.y1-a.originY,l.y2-l.y1),r.adjustPageFloatArea(e,a,this).thenAsync(()=>{e.init();let u=!!o.setFloatAreaDimensions(e,t,i,n,!0,!o.hasFloatFragments(),s);return u?(e.killFloats(),e.init()):a.element.parentNode.removeChild(h),N(u)})}createPageFloatArea(e,t,i,n,r){let s=this.element.ownerDocument.createElement("div");I(s,"position","absolute");let o=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new en(null,Te.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null);a.setOuterContext(this.pageFloatLayoutContext);let h=o.getContainer(),l=new ly(t,s,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h);return a.setContainer(l),this.setupFloatArea(l,e.floatReference,t,i,n,r).thenAsync(u=>N(u?l:null))}layoutSinglePageFloatFragment(e,t,i,n,r,s,o){let a=this.pageFloatLayoutContext;e=(o?o.continuations:[]).concat(e);let h=e[0].float,l=a.getPageFloatPlacementCondition(h,t,i),u={floatArea:null,pageFloatFragment:null,newPosition:null},d=M("layoutSinglePageFloatFragment");return this.createPageFloatArea(h,t,s,r,l).then(p=>{if(u.floatArea=p,!p){d.finish(u);return}let f=!1,g=0;d.loopWithFrame(m=>{if(g>=e.length){m.breakLoop();return}let w=e[g],b=new xi(w.nodePosition);p.layout(b,!0).then(x=>{u.newPosition=x,!x||n?(g++,m.continueLoop()):(f=!0,m.breakLoop())})}).then(()=>{if(!f){p.isFootnote&&p.applyCompactFootnoteDisplay();let m=a.setFloatAreaDimensions(p,h.floatReference,t,s,!1,n,l);if(!m)f=!0;else{let w=r.createPageFloatFragment(e,m,i,p,!!u.newPosition);a.addPageFloatFragment(w,!0),u.pageFloatFragment=w}}d.finish(u)})}),d.result()}layoutPageFloatInner(e,t,i,n){let r=this.pageFloatLayoutContext,s=e.float,o=new Set;for(let l=r;l;l=l.effectiveParent)for(let u of l.floatFragments)u.continuations.some(d=>d.float.insidePageFloatArea)&&o.add(u);r.stashEndFloatFragments(s);function a(l,u){u?r.removePageFloatFragment(u,!0):l&&l.element.parentNode.removeChild(l.element);let d=[];for(let p=r;p;p=p.effectiveParent)for(let f of p.floatFragments)!o.has(f)&&f.continuations.some(g=>g.float.insidePageFloatArea)&&d.push(f);for(let p of d)r.removePageFloatFragment(p,!0);r.restoreStashedFragments(s.floatReference),r.deferPageFloat(e)}let h=M("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],s.floatSide,s.clearSide,!r.hasFloatFragments(),t,i,n).then(l=>{let u=l.floatArea,d=l.pageFloatFragment,p=l.newPosition;d?this.layoutStashedPageFloats(s.floatReference,[n]).then(f=>{if(f){let g=!!r.generatingNodePosition;if(r.addPageFloatFragment(d,g),r.discardStashedFragments(s.floatReference),p){let m=new Jl(s,p.primary);r.deferPageFloat(m)}h.finish(!0)}else a(u,d),h.finish(!1)}):(a(u,d),h.finish(!1))}),h.result()}layoutStashedPageFloats(e,t){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(e),r=[],s=[],o=!1,a=M("layoutStashedPageFloats"),h=0;return a.loopWithFrame(l=>{if(h>=n.length){l.breakLoop();return}let u=n[h];if(t.includes(u)){h++,l.continueLoop();return}let d=new Sn().findByFloat(u.continuations[0].float);this.layoutSinglePageFloatFragment(u.continuations,u.floatSide,u.clearSide,!1,d,null).then(p=>{let f=p.floatArea;f&&r.push(f);let g=p.pageFloatFragment;g?(s.push(g),h++,l.continueLoop()):(o=!0,l.breakLoop())})}).then(()=>{o?(s.forEach(l=>{i.removePageFloatFragment(l,!0)}),r.forEach(l=>{let u=l.element;u&&u.parentNode&&u.parentNode.removeChild(u)})):n.forEach(l=>{let u=l.area.element;u&&u.parentNode&&u.parentNode.removeChild(u)}),a.finish(!o)}),a.result()}findFootnoteCallElement(e){let t=e.previousSibling;for(;t;){if(t.nodeType===Node.ELEMENT_NODE&&Kt(t)==="footnote-call")return t;t=t.previousSibling}return null}setFloatAnchorViewNode(e){let t=e.viewNode.parentNode,i=t.ownerDocument.createElement("span");if(i.setAttribute(Cn,"1"),e.floatSide==="footnote"){let r=this.findFootnoteCallElement(e.viewNode);r?i=r:t.insertBefore(i,e.viewNode)}else t.appendChild(i);t.removeChild(e.viewNode);let n=e.modify();return n.after=!0,n.viewNode=i,e.floatSide==="footnote"&&(n.display="inline"),n}resolveFloatReferenceFromColumnSpan(e,t,i){let n=M("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,s=r.getPageFloatLayoutContext(Te.REGION);return r.getContainer().width<s.getContainer().width&&e===Te.COLUMN?t===v.auto?this.buildDeepElementView(i.copy()).then(o=>{let a=o.viewNode,h=Va(this.clientLayout,a,["min-content inline size"])["min-content inline size"],l=this.getComputedMargin(a);this.vertical?h+=l.top+l.bottom:h+=l.left+l.right,h>this.width?n.finish(Te.REGION):n.finish(e)}):t===v.all?n.finish(Te.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new Sn().findByNodeContext(e),n,r=t.findPageFloatByNodePosition(e.toNodePosition());return r?n=N(r):n=i.createPageFloat(e,t,this),n.thenAsync(s=>{let o=ws(e,0),a=this.setFloatAnchorViewNode(e),h=i.findPageFloatFragment(s,t),l=new Jl(s,o);if(h&&h.hasFloat(s))return t.registerPageFloatAnchor(s,a.viewNode),N(a);if(t.isForbidden(s)||t.hasPrecedingFloatsDeferredToNext(s))return t.deferPageFloat(l),t.registerPageFloatAnchor(s,a.viewNode),N(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return N(null);{let u=tn(a,this.clientLayout,0,this.vertical);return this.isOverflown(u)?N(a):this.layoutPageFloatInner(l,i,u,h).thenAsync(d=>d?e.floatSide==="footnote"||t.generatingNodePosition?N(a):N(null):(t.registerPageFloatAnchor(s,a.viewNode),N(a)))}})}processLineStyling(e,t,i){let n=M("processLineStyling"),r=i.concat([]);i.splice(0,i.length);let s=0,o=e.firstPseudo;return o.count==0&&(o=o.outer),n.loopWithFrame(a=>{if(!o){a.breakLoop();return}let h=this.findLinePositions(r),l=o.count-s;if(h.length<=l){a.breakLoop();return}let u=this.findAcceptableBreakInside(r,h[l-1],!0);if(u==null){a.breakLoop();return}this.finishBreak(u,!1,!1).then(()=>{s+=l,this.layoutContext.peelOff(u,0).then(d=>{e=d,o=e.firstPseudo,r=[],this.buildViewToNextBlockEdge(e,r).then(p=>{t=p,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,r),n.finish(t)}),n.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&Oi[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let t=0,i=0;for(let n=e.length-1;n>=0;n--){let r=e[n];if(!r||!r.after||!r.viewNode||r.viewNode.nodeType!=1)break;let s=this.getComputedMargin(r.viewNode),o=this.vertical?-s.left:s.bottom;o>0?t=Math.max(t,o):i=Math.min(i,o)}return t+i}layoutBreakableBlock(e){let t=M("layoutBreakableBlock"),i=[];return this.buildViewToNextBlockEdge(e,i).then(n=>{let r=i.length-1;if(r<0){t.finish(n);return}this.postLayoutBlock(n,i);let s=this.suppressOpenAncestorBlockEndInset(n??e),o=this.calculateEdge(n,i,r,i[r].boxOffset);s();let a=!1;if(!n||!an(n.viewNode)){let l=mn(n,this.collectElementsOffset());a=this.isOverflown(o+(this.vertical?-1:1)*l.minimum),this.isOverflown(o+(this.vertical?-1:1)*l.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(o+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(o);let h;e.firstPseudo?h=this.processLineStyling(e,n,i):h=N(n),h.then(l=>{i.length>0&&(this.saveBoxBreakPosition(i),a&&!this.isLoneImage(i)&&l&&(l=l.modify(),l.overflow=!0)),t.finish(l)})}),t.result()}postLayoutBlock(e,t){Ft("POST_LAYOUT_BLOCK").forEach(i=>{i(e,t,this)})}findEndOfLine(e,t,i){let n=this.vertical?e-1:e+1,r=0,s=t[0].boxOffset,o=r,a=t.length-1,h=t[a].boxOffset,l;for(;s<h;){l=s+Math.ceil((h-s)/2),o=r;let u=a;for(;o<u;){let p=o+Math.ceil((u-o)/2);t[p].boxOffset>l?u=p-1:o=p}let d=this.calculateEdge(null,t,o,l);if(this.vertical?d<=n:d>=n){for(h=l-1;t[o].boxOffset==l;)o--;a=o}else i&&this.updateMaxReachedAfterEdge(d),s=l,r=o}return{nodeContext:t[o],index:s,checkPointIndex:o}}findAcceptableBreakInside(e,t,i){var n,r,s;let o=this.findEndOfLine(t,e,!0),a=o.nodeContext;if(o.checkPointIndex===0&&o.index===a.boxOffset)return null;let h=a.viewNode;if(h.nodeType!=1&&((n=h.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let l=h;a=this.resolveTextNodeBreaker(a).breakTextNode(l,a,o.index,e,o.checkPointIndex,i)}else{let l=ih(a);if(l){if(((r=this.breakPositions)==null?void 0:r[0])instanceof Yr&&l!=null&&l.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(a=l;!a.after&&a.inline&&a.parent;){let u=(s=a.viewNode)==null?void 0:s.previousSibling;for(;u&&(Me(u,a.parent.whitespace)||hi(u));)u=u.previousSibling;if(u)break;a=a.parent}}}return this.clearOverflownViewNodes(a,!1),a}resolveTextNodeBreaker(e){return Ft("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,Ps.instance)}getRangeBoxes(e,t){let i=[],n=e.ownerDocument.createRange(),r=!1,s=e,o=null,a=!1,h=!0;for(;h;){let l=!0;do{let u=null;s==t&&(t.nodeType===1?h=!(!t.firstChild||r):h=!1);let d=s.nodeType===1?s:null;d?r?r=!1:$a(d)?l=!a:!d.firstChild||Oi[d.localName]||/^r(uby|[bt]c?)$/.test(d.localName)||Hm(this.clientLayout.getElementComputedStyle(d).display)?(l=!a,l?(d.localName==="ruby"&&s.firstChild&&(s=s.firstChild),n.setStartBefore(s),a=!0,o=s):/^r(uby|tc?)$/.test(d.localName)||(o=s),s.contains(t)&&(h=!1)):u=s.firstChild:(a||(s.parentNode==null?h=!1:(n.setStartBefore(s),a=!0)),o=s),u||(u=s.nextSibling,u||(r=!0,u=s.parentNode)),s=u}while(l&&h);if(a){n.setEndAfter(o);let u=this.clientLayout.getRangeClientRects(n);zo(u,this.vertical);for(let d=0;d<u.length;d++)i.push(u[d]);a=!1}}return i}findLinePositions(e){let t=[],i=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);i.sort(this.vertical?xm:vm);let n=0,r=0,s=0,o=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],u=1;if(o>0){let d=Math.max(this.getBoxSize(l),1);h*this.getBeforeEdge(l)<h*n?u=h*(this.getAfterEdge(l)-n)/d:h*this.getAfterEdge(l)>h*r?u=h*(r-this.getBeforeEdge(l))/d:u=1}if(o==0||u>=.6||u>=.2&&this.getStartEdge(l)>=s-1){s=this.getEndEdge(l),this.vertical?(n=o==0?l.right:Math.max(n,l.right),r=o==0?l.left:Math.min(r,l.left)):(n=o==0?l.top:Math.min(n,l.top),r=o==0?l.bottom:Math.max(r,l.bottom)),o++,a++;continue}}if(o>0&&(t.push(r),o=0),a>=i.length)break}return t.sort(cu),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&on(i.viewNode)){let n=this.getComputedPaddingBorder(i.viewNode);t+=i.vertical?-n.left:n.bottom,i.display==="table"&&(t+=(i.vertical?-1:1)*i.blockBorderSpacing)}return t}getOffsetByRepetitiveElements(e){let t;return e?t=e.calculateOffset(this):t=mn(null,this.collectElementsOffset()),t.current}findBoxBreakPosition(e,t){let i=this.element.parentNode,n=this.element.nextSibling;i.removeChild(this.element),i.insertBefore(this.element,n);let r=e.checkPoints,s=r[0];for(;s.parent&&s.inline;)s=s.parent;let o,a;t?(o=1,a=1):(o=Math.max((s.inheritedProps.widows||2)-0,1),a=Math.max((s.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(s),l=this.findLinePositions(r),u=this.footnoteEdge-h,d=this.getBoxDir(),p=this.getOffsetByRepetitiveElements(e);u-=d*p;let f=this.findFirstOverflowingEdgeAndCheckPoint(r);isNaN(f.edge)&&(f.edge=d*(1/0));let g=ni(l.length,x=>{let y=l[x];return this.vertical?y<u||y<=f.edge:y>u||y>=f.edge}),m=g<=0;m&&(g=ni(l.length,x=>this.vertical?l[x]<u:l[x]>u));let w=r[r.length-1].viewNode;if(w?.parentElement.localName==="viv-ts-inner"&&(w=w.parentElement.parentElement),(g===l.length&&w.nextSibling||g>=l.length-1&&w.parentElement.querySelector(".MJXc-display"))&&(o=0,a=1),g=Math.min(l.length-o,g),g<a)return null;u=l[g-1];let b;if(m?b=f.checkPoint:b=this.findAcceptableBreakInside(e.checkPoints,u,t),b){let x=this.getAfterEdgeOfBlockContainer(b);if(!isNaN(x)&&d*(u-x)>0&&(u=x),this.computedBlockSize=d*(u-this.beforeEdge)+p,l.length>=2){let y=Math.max(1,Math.min(g-1,l.length-1));this.lastLineStride=Math.abs(l[y]-l[y-1])}}return b}getAfterEdgeOfBlockContainer(e){let t=e;do t=t.parent;while(t&&t.inline);return t?(t=t.copy().modify(),t.after=!0,tn(t,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(e){let t=e.findIndex(n=>n.overflow);if(t<0)return{edge:NaN,checkPoint:null};let i=e[t];return{edge:this.calculateEdge(null,e,t,i.boxOffset),checkPoint:i}}findEdgeBreakPosition(e){return this.computedBlockSize=e.computedBlockSize+this.getOffsetByRepetitiveElements(e),e.position}finishBreak(e,t,i){e.formattingContext;let n=new Mn().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=ja.finishBreak(this,e,t,i)),n}findAcceptableBreakPosition(){let e=null,t=null,i=0,n=0;do{i=n,n=Number.MAX_VALUE;for(let r=this.breakPositions.length-1;r>=0&&!t;--r){e=this.breakPositions[r],t=e.findAcceptableBreak(this,i);let s=e.getMinBreakPenalty();s>i&&(n=Math.min(n,s))}}while(n>i&&!t&&this.forceNonfitting);return{breakPosition:t?e:null,nodeContext:t}}doFinishBreak(e,t,i,n){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!t)return N(e);let r=M("doFinishBreak"),s=!1;if(!e){if(this.forceNonfitting)return W.warn("Could not find any page breaks?!!"),this.skipTailEdges(t).then(o=>{o?(o=o.modify(),o.overflow=!1,this.finishBreak(o,s,!0).then(()=>{r.finish(o)})):r.finish(o)}),r.result();e=i,s=!0,this.computedBlockSize=n}return this.finishBreak(e,s,!0).then(()=>{r.finish(e)}),r.result()}isBreakable(e){for(let t=e;t;t=t.parent)if(hi(t.viewNode))return!1;if(e.after)return!0;switch(e.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!e.flexContainer}isZeroLength(e){let t=e.trim();return t===""||/^0+(?:\.0+)?(?:[a-z%]*)$/i.test(t)}hasNonZeroBlockStartInset(e){return this.vertical?!(this.isZeroLength(e.paddingRight)&&this.isZeroLength(e.borderRightWidth)):!(this.isZeroLength(e.paddingTop)&&this.isZeroLength(e.borderTopWidth))}hasNonZeroBlockEndInset(e){return this.vertical?!(this.isZeroLength(e.paddingLeft)&&this.isZeroLength(e.borderLeftWidth)):!(this.isZeroLength(e.paddingBottom)&&this.isZeroLength(e.borderBottomWidth))}suppressOpenAncestorBlockEndInset(e){if(!vs(this))return()=>{};let t=[];for(let i=e?.parent;i;i=i.parent){if(i.after||i.inline)continue;let n=i.viewNode;if(!n||n.nodeType!==1||on(n))continue;let r=this.clientLayout.getElementComputedStyle(n);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let s=n.getAttribute("data-viv-box-break");gt(n,"block-end"),t.push({element:n,original:s})}return()=>{for(let{element:i,original:n}of t)n===null?i.removeAttribute("data-viv-box-break"):i.setAttribute("data-viv-box-break",n)}}checkOverflowAndSaveEdge(e,t){if(!e)return!1;for(let o=e;o;o=o.parent)if(hi(o.viewNode))return!1;if(an(e.viewNode))return!1;let i=this.suppressOpenAncestorBlockEndInset(e),n=tn(e,this.clientLayout,0,this.vertical);i();let r=mn(e,this.collectElementsOffset()),s=this.isOverflown(n+(this.vertical?-1:1)*r.minimum);if(this.isOverflown(n+(this.vertical?-1:1)*r.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(t){let o=n+this.getTrailingMarginEdgeAdjustment(t),a=this.footnoteEdge-this.getBoxDir()*r.current;n=this.vertical?Math.min(n,Math.max(o,a)):Math.max(n,Math.min(o,a))}return this.updateMaxReachedAfterEdge(n),s}checkOverflowAndSaveEdgeAndBreakPosition(e,t,i,n){if(!e||an(e.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(e,t);return(i||!r)&&this.saveEdgeBreakPosition(e,n,r),r}applyClearance(e){if(!e.viewNode.parentNode||e.floatReference!==Te.INLINE||e.floatSide)return!1;let t=this.getComputedMargin(e.viewNode),i=e.viewNode.ownerDocument.createElement("div");this.vertical?(i.style.bottom="0px",i.style.width="1px",i.style.marginRight=`${t.right}px`):(i.style.right="0px",i.style.height="1px",i.style.marginTop=`${t.top}px`),e.viewNode.parentNode.insertBefore(i,e.viewNode);let n=It(this.clientLayout,i,this.vertical),r=this.getBeforeEdge(n),s=this.getBoxDir(),o=e.clearSide==="same"?e.floatSide:e.clearSide,a=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(o)?ao(o,e.vertical,e.direction,this.layoutContext.page.side):o,h=a==="left"||a==="right"?e.direction==="rtl"==(a==="left")?"inline-end":"inline-start":a,l=this.pageFloatLayoutContext.getPageFloatClearEdge(h,this),u=l;switch(a){case"left":l=s*Math.max(l*s,this.leftFloatEdge*s);break;case"right":l=s*Math.max(l*s,this.rightFloatEdge*s);break;default:l=s*Math.max(l*s,Math.max(this.rightFloatEdge*s,this.leftFloatEdge*s))}let d=1/(this.clientLayout.pixelRatio||1),p=l*s>u*s;l=s*(Math.ceil(l*s/d)+(p?1:0))*d;let f=d;if(r*s+f>l*s)return e.viewNode.parentNode.removeChild(i),!1;{let g=Math.max(1,(l-r)*s);this.vertical?i.style.width=`${g}px`:i.style.height=`${g}px`,n=It(this.clientLayout,i,this.vertical);let m=this.getAfterEdge(n);if(!e.floatSide)if(this.vertical){let w=m-t.right-l;w>0==t.right>=0&&(w+=t.right),i.style.marginLeft=`${w}px`}else{let w=l-(m+t.top);w>0==t.top>=0&&(w+=t.top),i.style.marginBottom=`${w}px`}return e.clearSpacer=i,!0}}isBFC(e){return!!(Wm(e)||Mi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let t=e;t;t=t.parent)if(th(t.viewNode))return!0;return!1}skipEdges(e,t,i){var n;let r=e.after?(n=e.parent)==null?void 0:n.formattingContext:e.formattingContext;if(r&&!this.isBFC(r))return N(e);let s=M("skipEdges"),o=this,a=!i&&t&&e&&e.after,h=i,l=null,u=[],d=[],p=!1;function f(P){var S,R;if(!(!t||o.isNonFirstColumn||i||!Yl(h))){for(let A=P;A;A=A.parent)if(A.breakBefore==="column"&&(A.breakBefore=null),((S=A.viewNode)==null?void 0:S.nodeType)===1){let U=A.viewNode;((R=U.style)==null?void 0:R.breakBefore)==="column"&&(U.style.breakBefore="")}}}function g(P){var S,R;if(!(!t||!o.isNonFirstColumn||i||h!=="column")){for(let A=P;A;A=A.parent)if(A.breakBefore==="column"&&(A.breakBefore=null),((S=A.viewNode)==null?void 0:S.nodeType)===1){let U=A.viewNode;((R=U.style)==null?void 0:R.breakBefore)==="column"&&(U.style.breakBefore="")}h=null}}function m(P){var S,R;if(!(i||!Yl(h))){for(let A=P;A;A=A.parent)if(A.breakAfter==="column"&&(A.breakAfter=null),((S=A.viewNode)==null?void 0:S.nodeType)===1){let U=A.viewNode;((R=U.style)==null?void 0:R.breakAfter)==="column"&&(U.style.breakAfter="")}}}function w(P){h=et(h,P)}function b(){return i?!0:Ge(h)?t?o.isNonFirstColumn&&h!=="column"&&h!=="region":!x():!1}function x(){var P;if(!l||!e||e.floatSide)return!1;for(let S=l;S!=null&&S.parent;S=S.parent){if(S.parent.viewNode&&hi(S.parent.viewNode))continue;let R=S.after?S.viewNode:(P=S.viewNode)==null?void 0:P.previousSibling;for(;R&&(Me(R,S.parent.whitespace)||hi(R));)R=R.previousSibling;if(R)return!1}return!0}let y=()=>{e=u[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=h};return s.loopWithFrame(P=>{for(var S;e;){e.formattingContext;let R=new Mn().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Me(e.viewNode,e.whitespace)||this.hasFixedPositionAncestor(e))break;if(!e.after){b()?y():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)?(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0):(!l&&!t&&u.length===0&&this.saveEdgeBreakPosition(e,h,!1),e=e.modify(),e.breakBefore=h),P.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=gs(h)?h:null),R&&R.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&t&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),h,!1),!e.inline&&!e.repeatOnBreak&&(l?ih(l):this.breakPositions[this.breakPositions.length-1]instanceof Yr||!t&&u.length===0)&&this.saveEdgeBreakPosition(e.copy(),h,!1),!this.isBFC(e.formattingContext)||Mi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Me(e.sourceNode.firstChild,e.whitespace)){u.push(e.copy()),w(e.breakBefore),f(e),g(e),b()?y():(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),P.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let U=e.viewNode,G=U.style;if(e.after){Vc(U,this),e.floatSide&&(h=h??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let Z=e.sourceNode;if(Z.localName==="svg"||Z.localName==="math"||Z.getAttribute("data-math-typeset")==="true"){p=!1,l=e.copy(),d.push(l),h=null,w(e.breakAfter),m(e),this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h);break}if(e.inline||R&&R.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(p){if(th(e.viewNode))break;if(b()){y(),P.breakLoop();return}u=[],t=!1,a=!1,h=null}p=!1,Hc(e.viewNode)||(l=e.copy(),d.push(l)),w(e.breakAfter),m(e),G&&!hi(e.viewNode)&&this.hasNonZeroBlockEndInset(G)&&(d=l?[l]:[])}else{if(u.push(e.copy()),w(e.breakBefore),f(e),g(e),l&&Ge(h)&&zm(l.viewNode,e.viewNode),(e.pageType!=((S=e.parent)==null?void 0:S.pageType)||!Ge(h))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){P.breakLoop();return}let Z=e.viewNode.localName;if(Oi[Z]){b()?y():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),P.breakLoop();return}G&&this.hasNonZeroBlockStartInset(G)&&(a=!1,d=[]),p=!0}}while(!1);let A=this.nextInTree(e,a);if(A.isPending()){A.then(U=>{e=U,P.continueLoop()});return}else e=A.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(l,d,!this.stopAtOverflow,h)?l&&this.stopAtOverflow&&(e=l.modify(),e.overflow=!0):Ge(h)&&(this.pageBreakType=h),P.breakLoop()}).then(()=>{l&&(this.lastAfterPosition=l.toNodePosition()),s.finish(e)}),s.result()}skipTailEdges(e){let t=e.copy(),i=M("skipEdges"),n=null,r=!1;return i.loopWithFrame(s=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Me(e.viewNode,e.whitespace))break;if(!e.after){Ge(n)&&(this.pageBreakType=n),s.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=et(n,e.breakBefore),Ge(n)&&(this.pageBreakType=n),s.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(r){if(Ge(n)){this.pageBreakType=n,s.breakLoop();return}n=null}r=!1,n=et(n,e.breakAfter)}else{n=et(n,e.breakBefore);let h=e.viewNode.localName;if(Oi[h]){Ge(n)&&(this.pageBreakType=n),s.breakLoop();return}if(a&&this.hasNonZeroBlockStartInset(a)){s.breakLoop();return}}r=!0}while(!1);let o=this.layoutContext.nextInTree(e);if(o.isPending()){o.then(a=>{e=a,s.continueLoop()});return}else e=o.get()}t=null,s.breakLoop()}).then(()=>{i.finish(t)}),i.result()}layoutFloatOrFootnote(e){if(wi(e.floatReference)||e.floatSide==="footnote"){let t=this.pageFloatLayoutContext.generatingNodePosition;if(t&&e.sourceNode===t.steps[0].node){let i=e.modify();return i.floatSide=null,i.floatReference=Te.INLINE,i.clearSide=null,this.isBreakable(i)?this.layoutBreakableBlock(i):this.layoutUnbreakable(i)}return this.layoutPageFloat(e)}else return this.layoutFloat(e)}layoutNext(e,t,i){let n=M("layoutNext");return this.skipEdges(e,t,i||null).then(r=>{if(e=r,!e||this.pageBreakType||this.stopByOverflow(e))n.finish(e);else{let s=e.formattingContext;new Mn().find(s).layout(e,this,t).thenFinish(n)}}),n.result()}clearOverflownViewNodes(e,t){if(e)for(let i=e.parent;e;e=i,i=i?i.parent:null){let n=(i||e).formattingContext;new Mn().find(n).clearOverflownViewNodes(this,i,e,t),t=!1}}initGeom(){let e=this.element.ownerDocument.createElement("div");e.style.position="absolute",e.style.top=`${this.paddingTop}px`,e.style.right=`${this.paddingRight}px`,e.style.bottom=`${this.paddingBottom}px`,e.style.left=`${this.paddingLeft}px`,this.element.appendChild(e);let t=this.clientLayout.getElementClientRect(e);this.element.removeChild(e);let i=this.originX+this.left+this.getInsetLeft(),n=this.originY+this.top+this.getInsetTop();this.box=new Ct(i,n,i+this.width,n+this.height),this.startEdge=t?this.vertical?this.rtl?t.bottom:t.top:this.rtl?t.right:t.left:0,this.endEdge=t?this.vertical?this.rtl?t.top:t.bottom:this.rtl?t.left:t.right:0,this.beforeEdge=t?this.vertical?t.right:t.top:0,this.afterEdge=t?this.vertical?t.left:t.bottom:0,this.leftFloatEdge=this.beforeEdge,this.rightFloatEdge=this.beforeEdge,this.bottommostFloatTop=this.beforeEdge,this.footnoteEdge=this.afterEdge,this.bands=Zf(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],I(this.element,"width",`${this.width}px`),I(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null,this.lastLineStride=0}saveEdgeBreakPosition(e,t,i){e.formattingContext;let n=e.copy(),r=new Mn().find(e.formattingContext),s=this.calculateClonedPaddingBorder(n),o=r.createEdgeBreakPosition(n,t,i,this.computedBlockSize+s);this.breakPositions.push(o)}saveBoxBreakPosition(e){let t=e[0].breakPenalty;if(t){let n=e[0];for(;n.parent&&n.inline;)n=n.parent;t=n.breakPenalty}let i=new Yr(e,t);this.breakPositions.push(i)}updateMaxReachedAfterEdge(e){if(!isNaN(e)){let t=this.getBoxDir()*(e-this.beforeEdge);this.computedBlockSize=Math.max(t,this.computedBlockSize)}}layout(e,t,i){if(this.chunkPositions.push(e),e.primary.after&&(this.lastAfterPosition=e.primary),this.stopAtOverflow&&this.overflown)return N(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?N(null):N(e);Ha(this);let n=M("layout");return this.openAllViews(e.primary).then(r=>{let s=null;if(r.viewNode)s=r.copy();else{let a=h=>{h.nodeContext.viewNode&&(s=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let o=new oy(t,i);o.layout(r,this).then(a=>{this.doFinishBreak(a,o.context.overflownNodeContext,s,o.initialComputedBlockSize).then(h=>{let l=null;this.pseudoParent?l=N(null):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(vs(this)&&(Um(this),Hs(this)),this.element.hasAttribute("data-vivliostyle-column-block-size-adjusted")&&(this.vertical?(I(this.element,"width",`${this.width}px`),I(this.element,"left",`${this.left}px`)):I(this.element,"height",`${this.height}px`),this.element.removeAttribute("data-vivliostyle-column-block-size-adjusted")),this.pageFloatLayoutContext.isInvalidated()){n.finish(null);return}if(!h)n.finish(null);else{this.overflown=!0;let u=new xi(h.toNodePosition());n.finish(u)}})})})}),n.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let t=M("doFinishBreakOfFragmentLayoutConstraints"),i=[].concat(this.fragmentLayoutConstraints);i.sort((r,s)=>r.getPriorityOfFinishBreak()-s.getPriorityOfFinishBreak());let n=0;return t.loop(()=>n<i.length?i[n++].finishBreak(e,this).thenReturn(!0):N(!1)).then(()=>{t.finish(!0)}),t.result()}doLayout(e,t,i){let n=M("doLayout"),r=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,n.loopWithFrame(s=>{for(;e;){let o=!0;if(this.layoutNext(e,t,i||null).then(a=>{if(t=!1,i=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,e=this.nodeContextOverflowingDueToRepetitiveElements,e.overflow=!0):e=a,this.pageFloatLayoutContext.isInvalidated())s.breakLoop();else if(this.pageBreakType)s.breakLoop();else if(e&&this.stopByOverflow(e)){r=e;let h=this.findAcceptableBreakPosition();e=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),s.breakLoop()}else o?o=!1:s.continueLoop()}),o){o=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),s.breakLoop()}).then(()=>{n.finish({nodeContext:e,overflownNodeContext:r})}),n.result()}redoLayout(){let e=this.chunkPositions,t=this.element.lastChild;for(;t!=this.last;){let o=t.previousSibling;this.element===t.parentNode&&this.layoutContext.isPseudoelement(t)||this.element.removeChild(t),t=o}this.killFloats(),this.init();let i=M("redoLayout"),n=0,r=null,s=!0;return i.loopWithFrame(o=>{if(n<e.length){let a=e[n++];this.layout(a,s).then(h=>{s=!1,h?(r=h,o.breakLoop()):o.continueLoop()});return}o.breakLoop()}).then(()=>{i.finish(r)}),i.result()}saveDistanceToBlockEndFloats(){let e=this.pageFloatLayoutContext.getBlockStartEdgeOfBlockEndFloats();e>0&&isFinite(e)&&(this.blockDistanceToBlockEndFloats=this.getBoxDir()*(e-this.beforeEdge-this.computedBlockSize))}collectElementsOffset(){let e=[];for(let t=this;t;t=t.pseudoParent)t.fragmentLayoutConstraints.forEach(i=>{if(Mi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(ms.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}bi.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},tl=class{constructor(e,t,i){c(this,"startNodeContexts",[]),c(this,"column"),c(this,"flowRootSourceNode"),this.flowRootSourceNode=i.sourceNode,this.column=Object.create(e),this.column.element=t,this.column.layoutContext=e.layoutContext.clone(),this.column.stopAtOverflow=!1,this.column.flowRootFormattingContext=i.formattingContext,this.column.pseudoParent=e;let n=this.column.calculateClonedPaddingBorder(i);this.column.footnoteEdge=this.column.footnoteEdge-n;let r=this;this.column.openAllViews=function(s){return Es.prototype.openAllViews.call(this,s).thenAsync(o=>(r.startNodeContexts.push(o.copy()),N(o)))}}layout(e,t){return this.column.layout(e,t)}findAcceptableBreakPosition(e){let t=this.column.findAcceptableBreakPosition();if(e){let i=this.startNodeContexts[0].copy(),n=new xr(i,null,i.overflow,0);if(n.findAcceptableBreak(this.column,0),!t.nodeContext)return{breakPosition:n,nodeContext:i}}return t}finishBreak(e,t,i){return this.column.finishBreak(e,t,i)}doFinishBreakOfFragmentLayoutConstraints(e){this.column.doFinishBreakOfFragmentLayoutConstraints(e)}isStartNodeContext(e){let t=this.startNodeContexts[0];return t.viewNode===e.viewNode&&t.after===e.after&&t.offsetInNode===e.offsetInNode}isLastAfterNodeContext(e){return vi(e.toNodePosition(),this.column.lastAfterPosition)||this.isEffectivelyLastAfterNodeContext(e)}isEffectivelyLastAfterNodeContext(e){var t;let i=this.flowRootSourceNode,n=e.sourceNode;if(!i||!n||!e.after||i!==n&&!((t=i.contains)!=null&&t.call(i,n)))return!1;if(n.nodeType===Node.TEXT_NODE){let r=n;if(e.offsetInNode<r.length){let s=r.data.slice(e.offsetInNode);if(!Ec(s,e.whitespace))return!1}}for(let r=n;r&&r!==i;r=r.parentNode)for(let s=r.nextSibling;s;s=s.nextSibling)if(!Me(s,e.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},Ps=class{breakTextNode(e,t,i,n,r,s){if(t.after)t.offsetInNode=e.length;else{let o=i-t.boxOffset,a=e.data;a.charCodeAt(o)==173?o=this.breakAfterSoftHyphen(e,a,o,t):o=this.breakAfterOtherCharacter(e,a,o,t),o>0&&(t=this.updateNodeContext(t,o,e))}return t}breakAfterSoftHyphen(e,t,i,n){let r=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(t.slice(0,i))?"\u200D":"";if(e.replaceData(i,t.length-i,n.breakWord?"":r+mh(n)),r){let s=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=s.slice(0,i+1)+r+s.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let r=t.charAt(i);i++;let s=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&Cl(r)&&Cl(s)?mh(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};c(Ps,"instance");Ps.instance=new Ps;function mh(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var oy=class extends Xa{constructor(e,t){super(),this.leadingEdge=e,c(this,"breakAfter"),c(this,"initialPageBreakType",null),c(this,"initialComputedBlockSize",0),c(this,"initialOverflown",!1),c(this,"initialLastLineStride",0),c(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new ay(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||jm()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Uc(i.parentNode,i),t=t.parent}}saveState(e,t){super.saveState(e,t),this.initialPageBreakType=t.pageBreakType,this.initialComputedBlockSize=t.computedBlockSize,this.initialOverflown=t.overflown,this.initialLastLineStride=t.lastLineStride}restoreState(e,t){super.restoreState(e,t),t.pageBreakType=this.initialPageBreakType,t.computedBlockSize=this.initialComputedBlockSize,t.overflown=this.initialOverflown,t.lastLineStride=this.initialLastLineStride}},ay=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=M("DefaultLayoutMode.doLayout");return ny(e,t).then(()=>{t.doLayout(e,this.leadingEdge,this.breakAfter).then(n=>{this.context.overflownNodeContext=n.overflownNodeContext,i.finish(n.nodeContext)})}),i.result()}accept(e,t){return t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||t.fragmentLayoutConstraints.length<=0?!0:t.fragmentLayoutConstraints.every(i=>i.allowLayout(e,this.context.overflownNodeContext,t))}postLayout(e,t,i,n){return n||(n=!i.fragmentLayoutConstraints.some(r=>r.nextCandidate(e))),i.fragmentLayoutConstraints.forEach(r=>{r.postLayout(n,e,t,i)}),n}},ly=class extends Es{constructor(e,t,i,n,r,s,o){super(t,i,n,r,s),this.floatSide=e,this.parentContainer=o,c(this,"rootViewNodes",[]),c(this,"floatMargins",[]),c(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),N(t)))}convertPercentageSizesToPx(e){let t=this.parentContainer.getPaddingRect(),i=t.x2-t.x1,n=t.y2-t.y1;function r(s,o){s.forEach(a=>{let h=ci(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),u=o*l/100;I(e,a,`${u}px`)}})}r(["width","max-width","min-width"],i),r(["height","max-height","min-height"],n),r(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?n:i),["margin-top","margin-right","margin-bottom","margin-left"].forEach(s=>{ci(e,s)==="auto"&&I(e,s,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let t=e.viewNode;if(this.rootViewNodes.push(t),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(t),this.floatMargins.push(this.getComputedMargin(t)),this.adjustContentRelativeSize){let i=this.floatSide;if(this.parentContainer.vertical){if(i==="block-end"||i==="left"){let n=ci(t,"height");n!==""&&n!=="auto"&&I(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=ci(t,"width");n!==""&&n!=="auto"&&I(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=It(this.clientLayout,e,this.vertical),n=this.floatMargins[t];return this.vertical?n.top+i.height+n.bottom:n.left+i.width+n.right}))}getContentBlockMarginAfter(){return this.rootViewNodes.length===0?0:Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=this.floatMargins[t];return this.vertical?i.left:i.bottom}))}applyCompactFootnoteDisplay(){let e=this.layoutContext,t=e?.styler,i=e?.xmldoc,n=this.rootViewNodes.filter(h=>{var l,u,d;let p=h.getAttribute($t);if(!p||!t||!i)return!1;let f=i.getNodeByOffset(parseInt(p,10));if(!f||f.nodeType!==Node.ELEMENT_NODE)return!1;let g=t.getStyle(f,!1),m=(u=(l=ke(g,"footnote-display"))==null?void 0:l.value)==null?void 0:u.toString(),w=!!((d=ke(g,"--viv-marker-content"))!=null&&d.value);return m==="compact"&&!w});if(n.length===0){this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea();return}let r=this.element.getBoundingClientRect(),s=this.vertical?r.height:r.width;n.forEach(h=>{I(h,"display","inline"),h.style.setProperty("--viv-footnote-white-space","nowrap")});let o=1.5/(this.clientLayout.pixelRatio||1),a=h=>{let l=h.cloneNode(!0);l.style.removeProperty("--viv-footnote-inline-separator"),I(l,"display","inline-block"),I(l,"position","absolute"),I(l,"visibility","hidden"),I(l,"white-space","nowrap"),I(l,"max-width","none"),I(l,"left","0"),I(l,"top","0"),this.element.appendChild(l);let u=l.getBoundingClientRect();return this.element.removeChild(l),this.vertical?u.height:u.width};n.forEach(h=>{a(h)>s+o&&(I(h,"display","block"),h.style.removeProperty("--viv-footnote-white-space"))}),this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea()}updateComputedBlockSizeForFootnoteArea(){if(this.rootViewNodes.length===0){this.computedBlockSize=0;return}let e=this.getBoxDir();this.computedBlockSize=Math.max(0,...this.rootViewNodes.map(t=>{let i=It(this.clientLayout,t,this.vertical),n=this.getComputedMargin(t),r=this.vertical?n.left:n.bottom;return e*(this.getAfterEdge(i)-this.beforeEdge)+Math.max(0,r)}))}updateInlineFootnoteSeparators(){this.rootViewNodes.forEach((e,t)=>{var i,n;let r=e,s=(i=r.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(r).display,o=this.rootViewNodes[t+1],a=(n=o?.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(o).display;s==="inline"&&a==="inline"?r.style.setProperty("--viv-footnote-inline-separator",'" "'):r.style.removeProperty("--viv-footnote-inline-separator")})}},zi=class{constructor(e,t){this.parent=e,this.rootSourceNode=t,c(this,"formattingContextType","RepetitiveElementsOwner"),c(this,"isRoot",!1),c(this,"repetitiveElements",null)}getName(){return"Repetitive elements owner formatting context (RepetitiveElementsOwnerFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}getRepetitiveElements(){return this.repetitiveElements}getRootViewNode(e){let t=this.getRootNodeContext(e);return t?t.viewNode:null}getRootNodeContext(e){do if(!e.belongsTo(this)&&e.sourceNode===this.rootSourceNode)return e;while(e=e.parent);return null}initializeRepetitiveElements(e){this.repetitiveElements||Ho.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new hy(e,this.rootSourceNode),Ho.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},hy=class{constructor(e,t){this.vertical=e,this.ownerSourceNode=t,c(this,"headerSourceNode",null),c(this,"footerSourceNode",null),c(this,"headerViewNode",null),c(this,"footerViewNode",null),c(this,"headerNodePosition",null),c(this,"footerNodePosition",null),c(this,"headerHeight",0),c(this,"footerHeight",0),c(this,"isSkipHeader",!1),c(this,"isSkipFooter",!1),c(this,"enableSkippingFooter",!0),c(this,"enableSkippingHeader",!0),c(this,"doneInitialLayout",!1),c(this,"firstContentSourceNode",null),c(this,"lastContentSourceNode",null),c(this,"affectedNodeCache",[]),c(this,"afterLastContentNodeCache",[]),c(this,"allowInsert",!1),c(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=ws(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=ws(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=Vo(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=Vo(this.footerViewNode,e,this.vertical),this.footerViewNode=null)}prepareLayoutFragment(){this.isSkipHeader=this.isSkipFooter=!1,this.enableSkippingFooter=!0,this.enableSkippingHeader=!0}appendHeaderToFragment(e,t,i){return!this.headerNodePosition||this.isSkipHeader?N(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?N(!0):this.appendElementToFragment(this.footerNodePosition,e,t,i)}appendElementToFragment(e,t,i,n){let r=t.viewNode.ownerDocument,s=t.viewNode,o=r.createElement("div");s.appendChild(o);let a=new tl(n,o,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new xi(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,s.removeChild(o),this.moveChildren(o,s,i),a.getColumn().pageBreakType=h,N(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(Cn,"1"),i?t.insertBefore(n,i):t.appendChild(n)}}calculateOffset(e){let t=0;return e&&!this.affectTo(e)||((!this.isSkipFooter||e&&this.isAfterLastContent(e))&&(t+=this.footerHeight),this.isSkipHeader||(t+=this.headerHeight)),t}calculateMinimumOffset(e){let t=0;return e&&!this.affectTo(e)||(!this.enableSkippingFooter&&e&&this.isAfterLastContent(e)&&(t+=this.footerHeight),this.enableSkippingHeader||(t+=this.headerHeight)),t}isAfterLastContent(e){return this.findResultFromCache(e,this.afterLastContentNodeCache,t=>this.isAfterNodeContextOf(this.lastContentSourceNode,e,!1))}affectTo(e){return this.findResultFromCache(e,this.affectedNodeCache,t=>this.isAfterNodeContextOf(this.ownerSourceNode,e,!0))}findResultFromCache(e,t,i){let n=t.filter(r=>r.nodeContext.sourceNode===e.sourceNode&&r.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let r=i(e);return t.push({nodeContext:e,result:r}),r}}isAfterNodeContextOf(e,t,i){let n=[];for(let r=e;r;r=r.parentNode){if(t.sourceNode===r)return t.after;n.push(r)}for(let r=t.sourceNode;r;r=r.parentNode){let s=n.indexOf(r);if(s>=0)return i?s===0:!1;for(let o=r;o;o=o.previousElementSibling)if(n.includes(o))return!0}return t.after}isFirstContentNode(e){return e&&this.firstContentSourceNode===e.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(e){return this.headerSourceNode===e}isFooterSourceNode(e){return this.footerSourceNode===e}},Sd=class{constructor(e){this.formattingContext=e}accept(e,t){return!!e}postLayout(e,t,i,n){let r=this.formattingContext.getRepetitiveElements();return r&&(i.clientLayout,r.doneInitialLayout||(r.updateHeight(i),r.doneInitialLayout=!0)),n}},Cd=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},uy=class extends Sd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},cy=class extends Cd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new il(e)),this.processor.doLayout(e,t)}},il=class kd{constructor(t){c(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),c(this,"nodeContext");let i=Jt(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||an(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=this.getRepetitiveElements();return i&&i.isEnableToUpdateState()?(i.updateState(),!0):!1}postLayout(t,i,n,r){let s=this.getRepetitiveElements();s&&t&&r.stopAtOverflow&&(i==null||s.isAfterLastContent(i))&&s.preventSkippingFooter()}finishBreak(t,i){let n=Jt(this.nodeContext.formattingContext),r=this.getRepetitiveElements();if(!r)return N(!0);let s=this.nodeContext;return my(n,s,i).thenAsync(()=>wy(n,s,i).thenAsync(()=>(r.prepareLayoutFragment(),N(!0))))}getRepetitiveElements(){return Jt(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof kd?Jt(this.nodeContext.formattingContext)===Jt(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},dy=class extends Xa{constructor(e,t){super(),this.formattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.formattingContext.getRepetitiveElements();return!e.belongsTo(this.formattingContext)&&!t.doneInitialLayout?new uy(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new cy(this.formattingContext,this.processor))}},py=class extends Kn{constructor(e,t){super(),this.formattingContext=e,this.column=t}startNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=t.getRepetitiveElements();if(i.parent&&t.rootSourceNode===i.parent.sourceNode){switch(i.repeatOnBreak){case"header":if(n.isHeaderRegistered())i.repeatOnBreak="none";else return n.setHeaderNodeContext(i),N(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),N(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return Kn.prototype.startNonInlineElementNode.call(this,e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext;return i.sourceNode===t.rootSourceNode&&(t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0),i.repeatOnBreak==="header"||i.repeatOnBreak==="footer"?N(!0):Kn.prototype.afterNonInlineElementNode.call(this,e)}},fy=class extends hn{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=Jt(e.formattingContext);return n.getRootViewNode(e)?(i&&Ed(e.parent,t),e.belongsTo(n)?hn.prototype.layout.call(this,e,t,i):new dy(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=yy(e).getRepetitiveElements();return t&&!t.allowInsertRepeatitiveElements&&(t.isHeaderSourceNode(e.sourceNode)||t.isFooterSourceNode(e.sourceNode))&&e.viewNode.parentNode.removeChild(e.viewNode),!1}doInitialLayout(e,t){let i=Jt(e.formattingContext),n=M("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=Jt(e.formattingContext),n=new py(i,t);return new Uo(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=Jt(e.formattingContext),n=M("doLayout"),r=t.layoutContext.nextInTree(e,!1);return xd(r,t).then(s=>{let o=s;n.loopWithFrame(a=>{for(;o;){let h=!0;if(t.layoutNext(o,!1).then(l=>{o=l,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||o&&t.stopByOverflow(o)||o&&o.after&&o.sourceNode==i.rootSourceNode?a.breakLoop():h?h=!1:a.continueLoop()}),h){h=!1;return}}a.breakLoop()}).then(()=>{n.finish(o)})}),n.result()}finishBreak(e,t,i,n){return hn.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){hn.prototype.clearOverflownViewNodes(e,t,i,n)}};function gy(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof zi&&!i.belongsTo(n)&&t(n,i)}}function Ed(e,t){e&&gy(e.after?e.parent:e,(i,n)=>{bi.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new il(n))})}function my(e,t,i){let n=e.getRepetitiveElements();if(n){let r=e.getRootNodeContext(t);if(r.viewNode){let s=r.viewNode.firstChild;return n.appendHeaderToFragment(r,s,i)}}return N(!0)}function wy(e,t,i){let n=e.getRepetitiveElements();if(n&&!n.isSkipFooter){let r=e.getRootNodeContext(t);if(r.viewNode)return n.appendFooterToFragment(r,null,i)}return N(!0)}function yy(e){let t=e.formattingContext;return!t||!(t instanceof zi)?null:t}function Jt(e){return e instanceof zi,e}var by=new fy;kt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof zi&&!bi.isInstanceOfTableFormattingContext(e)?by:null);var Pd=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,c(this,"cells",[]),c(this,"breakBefore",null),c(this,"breakAfter",null)}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},vy=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,c(this,"viewElement"),c(this,"colSpan"),c(this,"rowSpan"),c(this,"height",0),c(this,"anchorSlot",null),this.viewElement=i,this.colSpan=i.colSpan||1,this.rowSpan=i.rowSpan||1}setHeight(e){this.height=e}setAnchorSlot(e){this.anchorSlot=e}},xy=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},Sy=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,c(this,"pseudoColumn"),c(this,"empty",!1),this.pseudoColumn=new tl(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&I(e,"vertical-align","top"),i&&i!=="normal"&&I(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return I(e,"vertical-align",t),i&&i!=="normal"&&I(e,"align-content",i),n}},Cy=class{constructor(e,t){this.viewNode=e,this.side=t}},ky=class extends xr{constructor(e,t,i,n){super(e,t,i,n),c(this,"formattingContext"),c(this,"acceptableCellBreakPositions",null),c(this,"rowIndex",null),this.formattingContext=e.formattingContext}findAcceptableBreak(e,t){let i=super.findAcceptableBreak(e,t);return t<this.getMinBreakPenalty()?null:this.getAcceptableCellBreakPositions().every(n=>!!n.nodeContext)?this.hasUnfinishedCells()?null:i:null}hasUnfinishedCells(){let e=this.getRowIndex(),t=this.formattingContext.getCellsFallingOnRow(e);for(let i of t){if(i.rowIndex+i.rowSpan-1>e)continue;let n=this.formattingContext.getCellFragmentOfCell(i);if(n){let r=n.findAcceptableBreakPosition();if(r.nodeContext&&!n.pseudoColumn.isLastAfterNodeContext(r.nodeContext))return!0}}return!1}getMinBreakPenalty(){let e=super.getMinBreakPenalty();this.getAcceptableCellBreakPositions().forEach(i=>{e+=i.breakPosition.getMinBreakPenalty()});let t=this.getCellFragments();return e+=Math.max(0,...t.map(i=>i.cellNodeContext.breakPenalty)),e}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.formattingContext,t=this.getCellFragments();this.acceptableCellBreakPositions=t.map(i=>i.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getRowIndex(){return this.rowIndex!=null?this.rowIndex:this.rowIndex=this.formattingContext.findRowIndexBySourceNode(this.position.sourceNode)}getCellFragments(){return this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.getRowIndex()).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},Ey=class extends Wa{constructor(e,t,i){super(),this.rowIndex=e,this.beforeNodeContext=t,this.formattingContext=i,c(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,t){if(this!==e.breakPositions[0]&&t<this.getMinBreakPenalty())return null;let i=this.getCellFragments(),n=this.getAcceptableCellBreakPositions(),r=n.every(s=>!!s.nodeContext)&&n.some((s,o)=>{let a=i[o].pseudoColumn,h=s.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(s=>s.nodeContext&&s.nodeContext.overflow),r?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext.getRowByIndex(this.rowIndex),t=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),n=this.getCellFragments();t+=Math.max(0,...n.map(s=>s.cellNodeContext.breakPenalty));let r=i.some((s,o)=>s.breakPosition instanceof Yr&&n[o].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((s,o)=>{let a=s.breakPosition.getMinBreakPenalty();r&&s.breakPosition instanceof xr&&s.breakPosition.overflows&&a>=3&&(n[o].column.checkOverflowAndSaveEdge(s.nodeContext,null)||(a-=3)),t+=a}),t}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.getCellFragments();this.acceptableCellBreakPositions=e.map(t=>t.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},wn=class extends zi{constructor(e,t){super(e,t),this.tableSourceNode=t,c(this,"formattingContextType","Table"),c(this,"vertical",!1),c(this,"columnCount",-1),c(this,"tableWidth",0),c(this,"captions",[]),c(this,"colGroups",null),c(this,"colWidths",null),c(this,"inlineBorderSpacing",0),c(this,"rows",[]),c(this,"slots",[]),c(this,"cellFragments",[]),c(this,"lastRowViewNode",null),c(this,"cellBreakPositions",[]),c(this,"repetitiveElements",null)}getName(){return"Table formatting context (Table.TableFormattingContext)"}isFirstTime(e,t){var i;if(!t)return t;switch(e.display){case"table-row":return this.cellBreakPositions.length===0&&e.fragmentIndex<=1;case"table-cell":return e.fragmentIndex>1||((i=e.parent)==null?void 0:i.display)==="table-row"&&e.parent.fragmentIndex>1?!1:!this.cellBreakPositions.some(n=>n.cellNodePosition.steps[0].node===e.sourceNode);default:return t}}getParent(){return this.parent}finishFragment(){this.cellFragments=[]}addRow(e,t){this.rows[e]=t}getRowSlots(e){let t=this.slots[e];return t||(t=this.slots[e]=[]),t}addCell(e,t){let i=this.rows[e];i||(this.addRow(e,new Pd(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,r=this.getRowSlots(e),s=0;for(;r[s];)s++;for(;e<n;e++){r=this.getRowSlots(e);for(let o=s;o<s+t.colSpan;o++){let a=r[o]=new xy(e,o,t);t.anchorSlot||t.setAnchorSlot(a)}}}getRowByIndex(e){return this.rows[e]}findRowIndexBySourceNode(e){return this.rows.findIndex(t=>e===t.sourceNode)}addCellFragment(e,t,i){let n=this.cellFragments[e];n||(n=this.cellFragments[e]=[]),n[t]=i}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((t,i)=>i.cell!==t[t.length-1]?t.concat(i.cell):t,[])}getRowSpanningCellsOverflowingTheRow(e){return this.getCellsFallingOnRow(e).filter(t=>t.rowIndex+t.rowSpan-1>e)}getCellFragmentOfCell(e){return this.cellFragments[e.rowIndex]&&this.cellFragments[e.rowIndex][e.columnIndex]}getColumnCount(){return this.columnCount<0&&(this.columnCount=Math.max.apply(null,this.rows.map(e=>e.cells.reduce((t,i)=>t+i.colSpan,0)))),this.columnCount}updateCellSizes(e){this.rows.forEach(t=>{t.cells.forEach(i=>{let n=It(e,i.viewElement,this.vertical);i.viewElement=null,i.setHeight(this.vertical?n.width:n.height)})})}findCellFromColumn(e){if(!e)return null;let t=null,i=0,n=0;e:for(i=0;i<this.cellFragments.length;i++)if(this.cellFragments[i]){for(n=0;n<this.cellFragments[i].length;n++)if(this.cellFragments[i][n]&&e===this.cellFragments[i][n].pseudoColumn.getColumn()){t=this.rows[i].cells[n];break e}}if(!t)return null;for(;i<this.slots.length;i++)for(;n<this.slots[i].length;n++){let r=this.slots[i][n];if(r.cell===t)return{rowIndex:r.rowIndex,columnIndex:r.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,r)=>{if(r>=e.rowIndex)return i;let s=n[e.columnIndex]&&this.getCellFragmentOfCell(n[e.columnIndex].cell);return!s||t.includes(s)||(this.collectElementsOffsetFromColumn(s.pseudoColumn.getColumn(),i),t.push(s)),i},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(t=>{t.cells.forEach((i,n)=>{e[n]||(e[n]={collected:[],elements:[]});let r=e[n],s=this.getCellFragmentOfCell(i);!s||r.collected.includes(s)||(this.collectElementsOffsetFromColumn(s.pseudoColumn.getColumn(),r.elements),r.collected.push(s))})}),[new Py(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(Mi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}bi.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=[].concat(e)}},Py=class{constructor(e){this.repeatitiveElementsInColumns=e}calculateOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.current)}calculateMinimumOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.minimum)}calculateMaxOffsetOfColumn(e,t){let i=0;return this.repeatitiveElementsInColumns.forEach(n=>{let r=mn(e,n);i=Math.max(i,t(r))}),i}};function Tt(e){return e instanceof wn,e}function Ny(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Ty(e){return e==="table"||e==="inline-table"}function wh(e){return Ny(e)||Ty(e)}function Nd(e,t,i){let n=e.nodeContext,r=n.display,s=n.parent?n.parent.display:null,o=!1;if(s==="inline-table"&&!(n.formattingContext instanceof wn)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof wn){o=a.formattingContext===t;break}}return o||r==="table-row"&&!wh(s)||r==="table-cell"&&s!=="table-row"&&!wh(s)||n.formattingContext instanceof wn&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,N(!0))):null}function Td(e,t){let i=t.nodeContext;return!(i!=null&&i.floatSide)||!(wi(i.floatReference)||i.floatSide==="footnote")?null:e.layoutFloatOrFootnote(i).thenAsync(n=>(n&&(t.nodeContext=n),N(!0)))}var Iy=class extends Kn{constructor(e,t){super(),this.formattingContext=e,this.column=t,c(this,"rowIndex",-1),c(this,"columnIndex",0),c(this,"inRow",!1),c(this,"checkPoints",[]),c(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=Nd(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=Td(this.column,e);if(n)return n;let r=e.nodeContext,s=r.display,o=t.getRepetitiveElements();switch(s){case"table":t.inlineBorderSpacing=r.inlineBorderSpacing;break;case"table-caption":{let a=new Cy(r.viewNode,r.captionSide);t.captions.push(a);break}case"table-header-group":return o.isHeaderRegistered()||(this.inHeaderOrFooter=!0,o.setHeaderNodeContext(r)),N(!0);case"table-footer-group":return o.isFooterRegistered()||(this.inHeaderOrFooter=!0,o.setFooterNodeContext(r)),N(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,r.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new Pd(this.rowIndex,r.sourceNode)),r.breakBefore&&(t.rows[this.rowIndex].breakBefore=r.breakBefore),o.firstContentSourceNode||(o.firstContentSourceNode=r.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,r=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let s=r.getElementComputedStyle(t.getRootViewNode(i));t.tableWidth=parseFloat(s[t.vertical?"height":"width"]),t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(n){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,N(!0);break;case"table-row":if(!this.inHeaderOrFooter){t.lastRowViewNode=i.viewNode,this.inRow=!1;let s=t.rows[this.rowIndex];s&&i.breakAfter&&(s.breakAfter=et(s.breakAfter,i.breakAfter))}break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let s=i.viewNode;t.addCell(this.rowIndex,new vy(this.rowIndex,this.columnIndex,s)),this.columnIndex++;let o=t.rows[this.rowIndex];o&&(i.breakBefore&&(o.breakBefore=et(o.breakBefore,i.breakBefore)),i.breakAfter&&(o.breakAfter=et(o.breakAfter,i.breakAfter)))}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let t=e.nodeContext;t&&t.viewNode&&!ln(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},Id=class Ad extends Kn{constructor(t,i){super(!0),this.formattingContext=t,this.column=i,c(this,"inRow",!1),c(this,"currentRowIndex",-1),c(this,"currentColumnIndex",0),c(this,"originalStopAtOverflow"),c(this,"inHeader"),c(this,"inFooter"),this.originalStopAtOverflow=i.stopAtOverflow,i.stopAtOverflow=!1}startNonInlineElementNode(t){return Td(this.column,t)||super.startNonInlineElementNode(t)}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(t){let i=this.formattingContext.colWidths,n=0;for(let r=0;r<t.colSpan;r++)n+=i[t.anchorSlot.columnIndex+r];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let r=t.rowIndex,s=t.columnIndex,o=t.colSpan,a=i.viewNode;o>1&&(I(a,"box-sizing","border-box"),I(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let l=new Sy(this.column,h,i);return this.formattingContext.addCellFragment(r,s,l),n.primary.steps.length===1&&n.primary.after&&(l.empty=!0),l.pseudoColumn.layout(n,!0).thenReturn(!0)}findBrokenCellAtSlot(t,i){let n=this.formattingContext.cellBreakPositions;for(let r=0;r<n.length;r++){let s=n[r];if(s.cell.anchorSlot.columnIndex===t&&s.cellNodePosition.steps[0].node===i)return{position:s,index:r}}return null}extractRowSpanningCellBreakPositions(){let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[],n=0;do{let r=t[n],s=r.cell,o=s.rowIndex;if(o<this.currentRowIndex&&o+s.rowSpan>this.currentRowIndex){let a=i[o];a||(a=i[o]=[]),a.push(r),t.splice(n,1)}else n++}while(n<t.length);return i}layoutRowSpanningCellsFromPreviousFragment(t){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),r=n.reduce(d=>d+1,0);if(r===0)return N(!0);let s=this.column.layoutContext,o=t.nodeContext;o.viewNode.parentNode.removeChild(o.viewNode);let a=M("layoutRowSpanningCellsFromPreviousFragment"),h=N(!0),l=0,u=[];return n.forEach(d=>{h=h.thenAsync(()=>{let p=ys(d[0].cellNodePosition.steps[1],o.parent);return s.setCurrent(p,!1).thenAsync(()=>{let f=N(!0),g=0;function m(w){for(;g<w;){if(!u.includes(g)){let b=p.viewNode.ownerDocument.createElement("td");I(b,"padding","0"),p.viewNode.appendChild(b)}g++}}return d.forEach(w=>{f=f.thenAsync(()=>{let b=w.cell;m(b.anchorSlot.columnIndex);let x=w.cellNodePosition,y=ys(x.steps[0],p);return y.offsetInNode=x.offsetInNode,y.after=x.after,y.fragmentIndex=x.steps[0].fragmentIndex+1,s.setCurrent(y,!1).thenAsync(()=>{let P=w.breakChunkPosition;for(let S=0;S<b.colSpan;S++)u.push(g+S);return g+=b.colSpan,this.layoutCell(b,y,P).thenAsync(()=>(y.viewNode.rowSpan=b.rowIndex+b.rowSpan-this.currentRowIndex+r-l,N(!0)))})})}),f.thenAsync(()=>(m(i.getColumnCount()),l++,N(!0)))})})}),h.then(()=>{s.setCurrent(o,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return N(!0);let i=t.nodeContext,n=this.formattingContext;return this.currentRowIndex<0?(i.sourceNode,this.currentRowIndex=n.findRowIndexBySourceNode(i.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(t).thenAsync(()=>{var r;this.registerCellFragmentIndex();let s=t.breakAtTheEdge;if(this.currentRowIndex>0){let a=n.rows[this.currentRowIndex-1];a!=null&&a.breakAfter&&(s=et(s,a.breakAfter))}let o=n.rows[this.currentRowIndex];return o!=null&&o.breakBefore&&(s=et(s,o.breakBefore)),!t.leadingEdge&&Ge(s)?(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,s),(r=i.viewNode)!=null&&r.parentNode&&i.viewNode.parentNode.removeChild(i.viewNode),t.lastAfterNodeContext&&this.column.layoutContext.processFragmentedBlockEdge(t.lastAfterNodeContext),this.column.pageBreakType=s,this.resetColumn(),t.break=!0,N(!0)):(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,s)&&n.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0),N(!0))})}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(t=>{let i=this.formattingContext.cellBreakPositions.find(n=>n.cell===t);if(i){let n=i.cellNodePosition.steps[0],r=this.column.layoutContext.xmldoc.getElementOffset(n.node);Qw(r,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return N(!0);let i=t.nodeContext;this.inRow||(this.currentRowIndex<0?this.currentRowIndex=0:this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0);let n=this.formattingContext.getRowByIndex(this.currentRowIndex).cells[this.currentColumnIndex];if(!n)return t.break=!0,N(!0);let r=i.copy().modify();r.after=!0,t.nodeContext=r;let s=M("startTableCell"),o,a=this.findBrokenCellAtSlot(n.anchorSlot.columnIndex,i.sourceNode);if(a){let h=a.position;this.formattingContext.cellBreakPositions.splice(a.index,1),i.fragmentIndex=h.cellNodePosition.steps[0].fragmentIndex+1,o=N(h.breakChunkPosition)}else o=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(h=>{h.viewNode&&i.viewNode.removeChild(h.viewNode);let l=ws(h,0);return N(new xi(l))});return o.then(h=>{this.layoutCell(n,i,h).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,s.finish(!0)})}),s.result()}startNonInlineBox(t){let i=Nd(t,Tt(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,r=this.formattingContext.getRepetitiveElements(),s=n.display;return s==="table-header-group"&&r&&r.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,N(!0)):s==="table-footer-group"&&r&&r.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,N(!0)):s==="table-row"?this.startTableRow(t):s==="table-cell"?this.startTableCell(t):N(!0)}endNonInlineBox(t){let i=t.nodeContext;if(i.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let n=i.copy().modify();n.after=!1;let r=new Ey(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(r)}return N(!0)}afterNonInlineElementNode(t){let i=t.nodeContext,n=this.formattingContext.getRepetitiveElements(),r=i.display;if(r==="table-header-group"?n&&!n.allowInsertRepeatitiveElements&&n.isHeaderSourceNode(i.sourceNode)?(this.inHeader=!1,i.viewNode.parentNode.removeChild(i.viewNode)):I(i.viewNode,"display","table-row-group"):r==="table-footer-group"&&(n&&!n.allowInsertRepeatitiveElements&&n.isFooterSourceNode(i.sourceNode)?(this.inFooter=!1,i.viewNode.parentNode.removeChild(i.viewNode)):I(i.viewNode,"display","table-row-group")),r&&Ad.ignoreList[r])i.viewNode.parentNode.removeChild(i.viewNode);else if(i.sourceNode===this.formattingContext.tableSourceNode)i.overflow=this.column.checkOverflowAndSaveEdge(i,null),this.resetColumn(),t.break=!0;else return super.afterNonInlineElementNode(t);return N(!0)}};c(Id,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Ay=Id,lr=[];function Ry(e){let t=lr.findIndex(n=>n.root===e),i=lr[t];return i?i.tableLayoutOption:null}function Fy(e){let t=lr.findIndex(i=>i.root===e);t>=0&&lr.splice(t,1)}var Rd=class{layoutEntireTable(e,t){let i=Tt(e.formattingContext),n=new Iy(i,t);return new Uo(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let r=e.ownerDocument,s=r.createElement("tr"),o=[];for(let h=0;h<t;h++){let l=r.createElement("td");s.appendChild(l),o.push(l)}e.parentNode.insertBefore(s,e.nextSibling);let a=o.map(h=>{let l=It(n,h,i),u=i?l.height:l.width;return Math.ceil(u)});return e.parentNode.removeChild(s),a}getColGroupElements(e){let t=[],i=e.firstElementChild;for(;i;)i.localName==="colgroup"&&t.push(i),i=i.nextElementSibling;return t}normalizeAndGetColElements(e){let t=[];return e.forEach(i=>{let n=i.span;i.removeAttribute("span");let r=i.firstElementChild;for(;r;){if(r.localName==="col"){let s=r.span;for(r.removeAttribute("span"),n-=s;s-- >1;){let o=r.cloneNode(!0);i.insertBefore(o,r),t.push(o)}t.push(r)}r=r.nextElementSibling}for(;n-- >0;)r=i.ownerDocument.createElement("col"),i.appendChild(r),t.push(r)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let r=n.ownerDocument.createElement("colgroup");t.push(r);for(let s=e.length;s<i;s++){let o=n.ownerDocument.createElement("col");r.appendChild(o),e.push(o)}}}normalizeColGroups(e,t,i){let n=e.vertical,r=e.lastRowViewNode;if(!r)return;e.lastRowViewNode=null;let s=r.ownerDocument.createDocumentFragment(),o=e.getColumnCount();if(!(o>0)){e.colGroups=s;return}let a=e.colWidths=this.getColumnWidths(r,o,n,i.clientLayout),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,o,t),l.forEach((u,d)=>{I(u,n?"height":"width",`${a[d]}px`)}),h.forEach(u=>{s.appendChild(u.cloneNode(!0))}),e.colGroups=s}doInitialLayout(e,t){let i=Tt(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=Ry(e.sourceNode);Fy(e.sourceNode);let r=M("TableLayoutProcessor.doInitialLayout"),s=e.copy();return this.layoutEntireTable(e,t).then(o=>{let a=o.viewNode,h=It(t.clientLayout,a,t.vertical),l=t.vertical?h.left:h.bottom;if(l+=(t.vertical?-1:1)*mn(e,t.collectElementsOffset()).current,!t.isOverflown(l)&&(!n||!n.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(i)){t.breakPositions.push(new My(s)),r.finish(o);return}this.normalizeColGroups(i,a,t),i.updateCellSizes(t.clientLayout),r.finish(null)}),r.result()}hasForcedBreakInRows(e){for(let t=0;t<e.rows.length;t++){let i=e.rows[t];if(i&&(t>0&&Ge(i.breakBefore)||t<e.rows.length-1&&Ge(i.breakAfter)))return!0}return!1}addCaptions(e,t,i){let n=e.captions;n.forEach((r,s)=>{r&&(t.insertBefore(r.viewNode,i),r.side==="top"&&(n[s]=null))})}addColGroups(e,t,i){e.colGroups&&this.getColGroupElements(t).length===0&&(t.insertBefore(e.colGroups.cloneNode(!0),i),I(t,"table-layout","fixed"),I(t,e.vertical?"height":"width",`${e.tableWidth}px`))}removeColGroups(e,t){if(e.colGroups&&t){let i=this.getColGroupElements(t);i&&i.forEach(n=>{t.removeChild(n)})}}doLayout(e,t){let i=Tt(e.formattingContext),n=i.getRootViewNode(e),r=n.firstChild;this.addCaptions(i,n,r),this.addColGroups(i,n,r);let s=new Ay(i,t),o=new Uo(s,t.layoutContext),a=M("TableFormattingContext.doLayout");return o.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=Tt(e.formattingContext);return n.getRootViewNode(e)?(i&&Ed(e.parent,t),new Oy(n,this).layout(e,t)):t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new ky(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return po(e),!1}finishBreak(e,t,i,n){let r=Tt(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let s=r.findRowIndexBySourceNode(t.sourceNode),o;if(t.after?o=r.getRowSpanningCellsOverflowingTheRow(s):o=r.getCellsFallingOnRow(s),r.cellBreakPositions=r.cellBreakPositions.filter(a=>!o.includes(a.cell)),o.length){let a=M("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===o.length){l.breakLoop();return}let u=o[h++],d=r.getCellFragmentOfCell(u),p=d.findAcceptableBreakPosition().nodeContext,f=d.cellNodeContext,g=f.toNodePosition(),m=new xi(p.toNodePosition());r.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:m,cell:u});let w=f.viewNode;d.column.layoutContext.processFragmentedBlockEdge(d.cellNodeContext),s<u.rowIndex+u.rowSpan-1&&(w.rowSpan=s-u.rowIndex+1),d.empty?l.continueLoop():d.pseudoColumn.finishBreak(p,!1,!0).then(()=>{Ly(d,r,p),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),po(t),r.finishFragment(),a.finish(!0)}),a.result()}}return po(t),r.finishFragment(),ja.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){hn.prototype.clearOverflownViewNodes(e,t,i,n)}};function Ly(e,t,i){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let r=t.vertical,s=e.column,o=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,h=It(s.clientLayout,a,r),l=s.getComputedPaddingBorder(a);if(r){let u=h.right-s.footnoteEdge-n.calculateOffset(i)-l.right;I(o,"max-width",`${u}px`)}else{let u=s.footnoteEdge-n.calculateOffset(i)-h.top-l.top;I(o,"max-height",`${u}px`)}}function po(e){let t=e.display==="table-row"?e.viewNode.parentElement:e.display==="table"?e.viewNode.querySelector("tbody"):null;if(!t)return;let i;try{i=t.querySelectorAll(":scope>tr:has(>:empty):not(:has(>:not([rowspan]:not([rowspan='1']),:empty)))")}catch{return}if(i.length===0)return;let n=Array.from(i).reduce((d,p)=>{let f=p.getBoundingClientRect(),g=e.vertical?f.width:f.height;return d+g},0),r=i[i.length-1],s=Array.from(t.children).indexOf(r),o=Array.from(r.children).reduce((d,p)=>{let f=p.rowSpan;return f>1&&s+f<t.childElementCount?Math.max(d,f):d},0),a=o?t.children[s+o-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let d=a;d&&d!==t.lastElementChild;d=d.nextElementSibling)if(d.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=d;break}}let h=a.getBoundingClientRect(),l=e.vertical?h.width:h.height,u=n+l;I(a,e.vertical?"width":"height",`${u}px`)}var Oy=class extends Xa{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new By(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new Dy(this.tableFormattingContext,this.processor))}clearNodes(e){super.clearNodes(e);let t=this.tableFormattingContext.getRootViewNode(e);this.processor.removeColGroups(this.tableFormattingContext,t)}restoreState(e,t){super.restoreState(e,t),this.tableFormattingContext.finishFragment()}},By=class extends Sd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},My=class extends xr{constructor(e){super(e,null,e.overflow,0)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");return(this.overflows?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}breakPositionChosen(e){e.fragmentLayoutConstraints.push(new _y(this.position.sourceNode))}},_y=class Fd{constructor(t){this.tableRootNode=t,c(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,r){i.sourceNode,lr.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return N(!0)}equalsTo(t){return t instanceof Fd&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},Dy=class extends Cd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new zy(e);t.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},zy=class Ld extends il{constructor(t){super(t),c(this,"flagmentLayoutConstraintType","TableRow"),c(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||n.pseudoParent||an(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=Tt(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(t,i).some(n=>n.constraints.some(r=>r.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,r){let s=Tt(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,s),this.cellFragmentLayoutConstraints.forEach(o=>{o.constraints.forEach(a=>{a.postLayout(t,o.breakPosition,n,r)})}),!t){let o=s.getRootViewNode(this.nodeContext);new Rd().removeColGroups(s,o),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,r)}finishBreak(t,i){let n=Tt(this.nodeContext.formattingContext),r=M("finishBreak"),s=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.breakPosition}))),[]),o=0;return r.loop(()=>{if(o<s.length){let a=s[o++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return N(!1)}).then(()=>{r.finish(!0)}),r.result().thenAsync(()=>super.finishBreak(t,i))}removeDummyRowNodes(t){if(!(!t||t.display!=="table-row"||!t.viewNode))for(;t.viewNode.previousElementSibling;){let i=t.viewNode.previousElementSibling;i.parentNode&&i.parentNode.removeChild(i)}}collectCellFragmentLayoutConstraints(t,i){return this.getCellFragemnts(t,i).map(n=>({constraints:n.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:n.breakPosition}))}getCellFragemnts(t,i){let n=Number.MAX_VALUE;t&&t.display==="table-row"&&(t.sourceNode,n=i.findRowIndexBySourceNode(t.sourceNode)+1),n=Math.min(i.cellFragments.length,n);let r=[];for(let s=0;s<n;s++)i.cellFragments[s]&&i.cellFragments[s].forEach(o=>{o&&r.push({fragment:o,breakPosition:o.findAcceptableBreakPosition().nodeContext})});return r}getElementsOffsetsForTableCell(t){let i=Tt(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof Ld?Tt(this.nodeContext.formattingContext)===Tt(t.nodeContext.formattingContext):!1}},Vy=new Rd;function Uy(e,t,i,n,r,s){if(!t)return null;if(i===v.table){let o=e.parent;return new wn(o?o.formattingContext:null,e.sourceNode)}return null}function Hy(e){return e instanceof wn?Vy:null}kt("RESOLVE_FORMATTING_CONTEXT",Uy);kt("RESOLVE_LAYOUT_PROCESSOR",Hy);function yh(e){return e.reduce((t,i)=>t+i,0)/e.length}function $y(e){let t=yh(e);return yh(e.map(i=>{let n=i-t;return n*n}))}var Wy=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function hr(e){return e.vertical?e.width:e.height}function ur(e,t){e.vertical?e.width=t:e.height=t}var Od=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,c(this,"originalContainerBlockSize"),this.originalContainerBlockSize=hr(e)}balanceColumns(e){let t=M("ColumnBalancer#balanceColumns");this.layoutContainer.element.setAttribute("data-vivliostyle-in-column-balancing","true"),this.preBalance(e),this.savePageFloatLayoutContexts(e),this.layoutContainer.clear();let i=[this.createTrialResult(e)];return t.loopWithFrame(n=>{if(!this.hasNextCandidate(i)){n.breakLoop();return}this.updateCondition(i),this.columnGenerator().then(r=>{if(this.savePageFloatLayoutContexts(r),this.layoutContainer.clear(),!r){n.breakLoop();return}i.push(this.createTrialResult(r)),n.continueLoop()})}).then(()=>{let n=i.reduce((r,s)=>s.penalty<r.penalty?s:r,i[0]);this.layoutContainer.element.removeAttribute("data-vivliostyle-in-column-balancing"),this.restoreContents(n.layoutResult),this.tightenColumnBlockSizes(n.layoutResult.columns),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new Wy(e,t)}preBalance(e){}postBalance(){ur(this.layoutContainer,this.originalContainerBlockSize)}tightenColumnBlockSizes(e){if(e.length<=1)return;let t=Math.max.apply(null,e.map(i=>i.computedBlockSize));if(!(t<=0))for(let i of e)if(i.vertical){let n=parseFloat(i.element.style.width),r=parseFloat(i.element.style.left);if(isFinite(n)&&isFinite(r)&&n>t){let s=r+n-t;I(i.element,"width",`${t}px`),I(i.element,"left",`${s}px`),i.width=t,i.left=s}}else{let n=parseFloat(i.element.style.height);isFinite(n)&&n>t&&(I(i.element,"height",`${t}px`),i.height=t)}}savePageFloatLayoutContexts(e){let t=this.regionPageFloatLayoutContext.detachChildren();e&&(e.columnPageFloatLayoutContexts=t)}restoreContents(e){let t=this.layoutContainer.element;e.columns.forEach(i=>{t.appendChild(i.element)}),e.columnPageFloatLayoutContexts,this.regionPageFloatLayoutContext.attachChildren(e.columnPageFloatLayoutContexts)}},ta=1;function Bd(e){let t=e[e.length-1];if(t.penalty===0)return!1;let i=e[e.length-2];if(i&&t.penalty>=i.penalty)return!1;let n=t.layoutResult.columns,r=Math.max.apply(null,n.map(o=>o.computedBlockSize)),s=Math.max.apply(null,n.map(o=>o.getMaxBlockSizeOfPageFloats()));return r>s+ta}function Md(e,t){let i=e[e.length-1].layoutResult.columns,n=Math.max.apply(null,i.map(r=>isNaN(r.blockDistanceToBlockEndFloats)?r.computedBlockSize:r.computedBlockSize-r.blockDistanceToBlockEndFloats+ta))-ta;n<hr(t)?ur(t,n):ur(t,hr(t)-1)}var Gy=class extends Od{constructor(e,t,i,n){super(i,e,t),this.columnCount=n,c(this,"originalPosition",null),c(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);ur(this.layoutContainer,t/this.columnCount),this.originalPosition=e.position}checkPosition(e){return this.originalPosition?this.originalPosition.isSamePosition(e):e===null}calculatePenalty(e){if(!this.checkPosition(e.position))return 1/0;let t=e.columns;return bh(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return Bd(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!bh(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):hr(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Md(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,hr(this.layoutContainer)+this.originalContainerBlockSize*.1);ur(this.layoutContainer,t)}}};function bh(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize,i=e.slice(0,e.length-1),n=Math.max(...e.map(s=>s.lastLineStride||0)),r=n>0?n/2:6;return i.every(s=>t>s.computedBlockSize+r)}var jy=class extends Od{constructor(e,t,i){super(i,e,t)}calculatePenalty(e){if(e.columns.every(i=>i.computedBlockSize===0))return 1/0;let t=e.columns.filter(i=>!i.pageBreakType).map(i=>i.computedBlockSize);return $y(t)}hasNextCandidate(e){return Bd(e)}updateCondition(e){Md(e,this.layoutContainer)}};function Xy(e,t,i,n,r,s,o){if(t===v.auto)return null;{let a=o.positions.length===0,h=s[s.length-1],l=!!(h&&h.pageBreakType);return a||l?new Gy(i,n,r,e):t===v.balance_all?new jy(i,n,r):(v.balance,null)}}var qy=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],Yy=new Set(qy);function Zy(e){return!(e.toLowerCase()==="none"||Yy.has(e))}var Ky=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],Jy=new Set(Ky),Qy=["fixed","extends"],eb=new Set(Qy),E0=Symbol();function Sr(e){return e instanceof de&&e.name.toLowerCase()!=="none"}function _d(e){return e.name}function tb(e){if(e instanceof de)return Jy.has(e.name);if(e instanceof te&&e.values.length===2){let t=e.values[0],i=e.values[1];if(t instanceof de){let n=t.name;return eb.has(n)&&(n==="fixed"&&i instanceof Be||n==="extends"&&Sr(i))}}return!1}function ib(e){let t=st(e,"system");return t instanceof de&&t.name==="cyclic"}function nb(e){let t=st(e,"system");if(t instanceof de&&t.name==="fixed")return!0;if(t instanceof te&&t.values.length===2){let[i,n]=t.values;return i instanceof de&&i.name==="fixed"&&n instanceof Be}return!1}function rb(e){let t=st(e,"system");return t instanceof de?1:t.values[1].num}function sb(e){let t=st(e,"system");return t instanceof de&&t.name==="alphabetic"}function ob(e){let t=st(e,"system");return t instanceof de&&t.name==="numeric"}function ab(e){let t=st(e,"system");return t instanceof de&&t.name==="additive"}function lb(e){let t=st(e,"system");if(t instanceof te&&t.values.length===2){let[i,n]=t.values;return i instanceof de&&i.name==="extends"&&Sr(n)}return!1}function hb(e){let t=st(e,"system");return _d(t.values[1])}function Lt(e){return e instanceof j||e instanceof de}function ti(e){return e instanceof j?e.str:e.name}function Dd(e){if(Lt(e))return!0;if(e instanceof te&&e.values.length===2){let t=e.values[0],i=e.values[1];return Lt(t)&&Lt(i)}return!1}function ub(e){if(Lt(e))return{prefix:ti(e),suffix:null};{let t=e.values[0],i=e.values[1];return{prefix:ti(t),suffix:ti(i)}}}function vh(e){return e instanceof Be||e instanceof de&&e.name==="infinite"}function Ns(e,t){return e instanceof Be?e.num:t?-1/0:1/0}var P0=Symbol();function ia(e){if(!(e instanceof te&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(vh(t)&&vh(i)))return!1;let n=Ns(t,!0),r=Ns(i,!1);return!(n>r)}function cb(e){return{lower:Ns(e.values[0],!0),upper:Ns(e.values[1],!1)}}function zd(e){return e instanceof de&&e.name==="auto"||ia(e)||e instanceof tt&&e.values.length>=1&&e.values.every(t=>ia(t))}function db(e){return e instanceof de?null:(ia(e)?[e]:e.values).map(t=>cb(t))}var N0=Symbol();function Ts(e){if(!(e instanceof te&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];return t instanceof Be&&t.num>=0&&Lt(i)||Lt(t)&&i instanceof Be&&i.num>=0}function Is(e){let[t,i]=e.values;return t instanceof Be?[t.num,ti(i)]:[i.num,ti(t)]}function Vd(e){return Ts(e)}function pb(e){let[t,i]=Is(e);return{minLength:t,symbol:i}}function Ud(e){return Lt(e)||e instanceof te&&e.values.length>=1&&e.values.every(t=>Lt(t))}function fb(e){return Lt(e)?[ti(e)]:e.values.map(t=>ti(t))}var T0=Symbol();function Hd(e){if(Ts(e))return!0;if(e instanceof tt&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!Ts(i))return!1;let[n]=Is(i);if(n>=t)return!1;t=n}return!0}return!1}function gb(e){if(Ts(e)){let[t,i]=Is(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=Is(t);return{weight:i,symbol:n}})}var mb=["auto","bullets","numbers","words","spell-out"],wb=new Set(mb);function yb(e){return e instanceof de&&wb.has(e.name)||Sr(e)}function bb(e,t){switch(e){case"system":return tb(t);case"negative":return Dd(t);case"prefix":case"suffix":return Lt(t);case"range":return zd(t);case"pad":return Vd(t);case"fallback":return Sr(t);case"symbols":return Ud(t);case"additive-symbols":return Hd(t);case"speak-as":return yb(t);default:return!0}}function st(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function vb(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function En(e){let t=e.get("decimal");return t||(t=ce.createDecimal(e),e.set("decimal",t)),t}var Zr,Kr,Jr,Qr,es,ts,is,ns,na,ra,sa,oa,aa,la,ha,ut,fo,$d,Wd,xh,Sh,go,Ch,Wn,li=class Ri{constructor(t,i){ne(this,ut),c(this,"_store"),ne(this,Zr),ne(this,Kr),ne(this,Jr),ne(this,Qr),ne(this,es),ne(this,ts),ne(this,is),ne(this,ns),this._store=t;let n=st(i,"negative");Oe(this,Zr,n&&Dd(n)?ub(n):null);let r=st(i,"prefix");Oe(this,Kr,r&&Lt(r)?ti(r):null);let s=st(i,"suffix");Oe(this,Jr,s&&Lt(s)?ti(s):null);let o=st(i,"range");Oe(this,Qr,o&&zd(o)?db(o):null);let a=st(i,"pad");Oe(this,es,a&&Vd(a)?pb(a):null);let h=st(i,"fallback");Oe(this,ts,h&&Sr(h)?_d(h):null);let l=st(i,"symbols");Oe(this,is,l&&Ud(l)?fb(l):null);let u=st(i,"additive-symbols");Oe(this,ns,u&&Hd(u)?gb(u):null)}static create(t,i){return ib(i)?new Pi(t,i):nb(i)?new xb(t,i):sb(i)?new Cb(t,i):ob(i)?new kh(t,i):ab(i)?new kb(t,i):lb(i)?new Eb(t,i):new Sb(t,i)}static createDecimal(t){return new kh(t,V(Ri,na))}static createDisc(t){return new Pi(t,V(Ri,ra))}static createSquare(t){return new Pi(t,V(Ri,sa))}static createCircle(t){return new Pi(t,V(Ri,oa))}static createDisclosureOpen(t){return new Pi(t,V(Ri,aa))}static createDisclosureClosed(t){return new Pi(t,V(this,la))}static createNone(t){return new Pi(t,V(Ri,ha))}static get CHINESE_LONGHAND_NAMES(){return Eh.NAMES}static createChineseLonghand(t,i){return new Eh(t,i)}static createEthiopicNumeric(t){return new Nb(t)}_getNegative(){return V(this,Zr)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return V(this,Kr)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return V(this,Jr)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return V(this,Qr)}static _getRangeFrom(t){return t._getRange()}_getPad(){return V(this,es)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(V(this,ts)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return V(this,is)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return V(this,ns)}static _getAdditiveSymbolsFrom(t){return t._getAdditiveSymbols()}static _useNegativeSignFrom(t,i){return t._usesNegativeSign(i)}static _generateInitialRepresentationFrom(t,i){return t._generateInitialRepresentation(i)}format(t){return Ce(this,ut,Wn).call(this,t,new Set)}formatMarker(t){return Ce(this,ut,$d).call(this)+this.format(t)+Ce(this,ut,Wd).call(this)}};Zr=new WeakMap,Kr=new WeakMap,Jr=new WeakMap,Qr=new WeakMap,es=new WeakMap,ts=new WeakMap,is=new WeakMap,ns=new WeakMap,na=new WeakMap,ra=new WeakMap,sa=new WeakMap,oa=new WeakMap,aa=new WeakMap,la=new WeakMap,ha=new WeakMap,ut=new WeakSet,fo=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},$d=function(){var e;return(e=this._getPrefix())!=null?e:""},Wd=function(){var e;return(e=this._getSuffix())!=null?e:". "},xh=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},Sh=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},go=function(){var e;return(e=this._getFallback())!=null?e:En(this._store)},Ch=function(e,t){let{minLength:i,symbol:n}=Ce(this,ut,Sh).call(this);if(i===0||n==="")return e;let{prefix:r,suffix:s}=Ce(this,ut,fo).call(this),o=t?[...r].length+(s?[...s].length:0):0,a=i-[...e].length-o;if(a<=0)return e;let h=[...n].length,l=Math.ceil(a/h);return n.repeat(l)+e},Wn=function(e,t){var i,n,r;if(t.has(this))return Ce(i=En(this._store),ut,Wn).call(i,e,new Set);if(t.add(this),!vb(e,Ce(this,ut,xh).call(this))){let l=Ce(this,ut,go).call(this);return Ce(n=l,ut,Wn).call(n,e,t)}let s=this._usesNegativeSign(e),o=s?Math.abs(e):e,a=this._generateInitialRepresentation(o);if(a===null){let l=Ce(this,ut,go).call(this);return Ce(r=l,ut,Wn).call(r,e,t)}let h=Ce(this,ut,Ch).call(this,a,s);if(s){let{prefix:l,suffix:u}=Ce(this,ut,fo).call(this);h=l+h+(u??"")}return h},ne(li,na,{system:new D(B("numeric"),0),symbols:new D(new te([new j("0"),new j("1"),new j("2"),new j("3"),new j("4"),new j("5"),new j("6"),new j("7"),new j("8"),new j("9")]),0)}),ne(li,ra,{system:new D(B("cyclic"),0),symbols:new D(new j("\u2022"),0),suffix:new D(new j(" "),0)}),ne(li,sa,{system:new D(B("cyclic"),0),symbols:new D(new j("\u25AA"),0),suffix:new D(new j(" "),0)}),ne(li,oa,{system:new D(B("cyclic"),0),symbols:new D(new j("\u25E6"),0),suffix:new D(new j(" "),0)}),ne(li,aa,{system:new D(B("cyclic"),0),symbols:new D(new j("\u25BE"),0),suffix:new D(new j(" "),0)}),ne(li,la,{system:new D(B("cyclic"),0),symbols:new D(new j("\u25B8"),0),suffix:new D(new j(" "),0)}),ne(li,ha,{system:new D(B("cyclic"),0),symbols:new D(new j(""),0),suffix:new D(new j(""),0)});var ce=li,Pi=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0)return null;let i=t.length,n=((e-1)%i+i)%i;return t[n]}},rs,xb=class extends ce{constructor(e,t){super(e,t),ne(this,rs),Oe(this,rs,rb(t))}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){var t;let i=this._getSymbols();if(!i||i.length===0)return null;let n=e-V(this,rs);return(t=i[n])!=null?t:null}};rs=new WeakMap;var Sb=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0||e<1)return null;let i=t.length,n=t[(e-1)%i],r=Math.ceil(e/i);return n.repeat(r)}},Cb=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2||e<1)return null;let i=t.length,n="",r=e;for(;r!==0;)r=r-1,n=t[r%i]+n,r=Math.floor(r/i);return n}},kh=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2)return null;let i=t.length;if(e===0)return t[0];let n="",r=e;for(;r!==0;)n=t[r%i]+n,r=Math.floor(r/i);return n}},kb=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getAdditiveSymbols();if(!t||t.length===0)return null;let i="";if(e===0){let r=t.find(s=>s.weight===0);return r?r.symbol:null}let n=e;for(let r of t){let{weight:s,symbol:o}=r;if(s===0||s>n)continue;let a=Math.floor(n/s);if(i+=o.repeat(a),n-=s*a,n===0)return i}return null}},Qn,mt,St,Gd=class extends ce{constructor(t,i){super(t,i),ne(this,mt),ne(this,Qn);let n=hb(i),r=n.toLowerCase();r==="disc"||r==="circle"||r==="square"||r==="disclosure-open"||r==="disclosure-closed"?Oe(this,Qn,r):Oe(this,Qn,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:ce._getNegativeFrom(Ce(this,mt,St).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:ce._getPrefixFrom(Ce(this,mt,St).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:ce._getSuffixFrom(Ce(this,mt,St).call(this))}_getAutoRange(){return ce._getAutoRangeFrom(Ce(this,mt,St).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:ce._getRangeFrom(Ce(this,mt,St).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:ce._getPadFrom(Ce(this,mt,St).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:ce._getFallbackFrom(Ce(this,mt,St).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:ce._getSymbolsFrom(Ce(this,mt,St).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:ce._getAdditiveSymbolsFrom(Ce(this,mt,St).call(this))}_usesNegativeSign(t){return ce._useNegativeSignFrom(Ce(this,mt,St).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:ce._generateInitialRepresentationFrom(Ce(this,mt,St).call(this),t)}};Qn=new WeakMap,mt=new WeakSet,St=function(e=new Set){var t;if(e.has(this))return En(this._store);e.add(this);let i=this._store.get(V(this,Qn));return i?i instanceof Gd?Ce(t=i,mt,St).call(t,e):i:En(this._store)};var Eb=Gd,Pb=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],mo,wo,_r,yo,ua,ss,Pt=class jd extends ce{constructor(t,i){let{chars:n,descriptors:r}=V(jd,ua).get(i);super(t,r),ne(this,ss),Oe(this,ss,n)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=V(this,ss);if(t===0)return i.digits[0];let n=[],r=0,s=t;for(;s>0;)n.unshift({digit:s%10,position:r}),s=Math.floor(s/10),r++;let o=i.informal&&t>=10&&t<=19,a="",h=!1;for(let l=0;l<n.length;l++){let{digit:u,position:d}=n[l],p=l===n.length-1;u===0?!p&&!h&&(h=!0):(h&&(a+=i.digits[0],h=!1),o&&d===1?a+=i.markers[d]:(a+=i.digits[u],d>0&&(a+=i.markers[d])))}return a}};mo=new WeakMap,wo=new WeakMap,_r=new WeakMap,yo=new WeakMap,ua=new WeakMap,ss=new WeakMap,ne(Pt,mo,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new D(new j("\u3001"),0),fallback:new D(B("cjk-decimal"),0),range:new D(new te([new Be(-9999),new Be(9999)]),0),negative:new D(new j("\u8D1F"),0)}}),ne(Pt,wo,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new D(new j("\u3001"),0),fallback:new D(B("cjk-decimal"),0),range:new D(new te([new Be(-9999),new Be(9999)]),0),negative:new D(new j("\u8D1F"),0)}}),ne(Pt,_r,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new D(new j("\u3001"),0),fallback:new D(B("cjk-decimal"),0),range:new D(new te([new Be(-9999),new Be(9999)]),0),negative:new D(new j("\u8CA0"),0)}}),ne(Pt,yo,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new D(new j("\u3001"),0),fallback:new D(B("cjk-decimal"),0),range:new D(new te([new Be(-9999),new Be(9999)]),0),negative:new D(new j("\u8CA0"),0)}}),c(Pt,"NAMES",new Set(Pb)),ne(Pt,ua,new Map([["simp-chinese-informal",V(Pt,mo)],["simp-chinese-formal",V(Pt,wo)],["trad-chinese-informal",V(Pt,_r)],["trad-chinese-formal",V(Pt,yo)],["cjk-ideographic",V(Pt,_r)]]));var Eh=Pt,ca,da,As,pa,fa,nn=class Fi extends ce{constructor(t){super(t,V(Fi,ca))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return V(Fi,As)[1];let i=[],n=t;for(;n>0;)i.push(n%100),n=Math.floor(n/100);let r=i.length,s="";for(let o=r-1;o>=0;o--){let a=i[o],h=o%2===1,l=o===r-1;if(!(a===0||l&&a===1||h&&a===1)){let u=Math.floor(a/10),d=a%10;s+=V(Fi,da)[u]+V(Fi,As)[d]}h?a!==0&&(s+=V(Fi,pa)):o!==0&&(s+=V(Fi,fa))}return s}};ca=new WeakMap,da=new WeakMap,As=new WeakMap,pa=new WeakMap,fa=new WeakMap,ne(nn,ca,{range:new D(new te([new Be(1),B("infinite")]),0),suffix:new D(new j("/ "),0)}),ne(nn,da,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ne(nn,As,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ne(nn,pa,"\u137B"),ne(nn,fa,"\u137C");var Nb=nn,Pe,Tb=class{constructor(){ne(this,Pe),Oe(this,Pe,new Map),V(this,Pe).set("none",ce.createNone(V(this,Pe))),V(this,Pe).set("decimal",ce.createDecimal(V(this,Pe))),V(this,Pe).set("disc",ce.createDisc(V(this,Pe))),V(this,Pe).set("square",ce.createSquare(V(this,Pe))),V(this,Pe).set("circle",ce.createCircle(V(this,Pe))),V(this,Pe).set("disclosure-open",ce.createDisclosureOpen(V(this,Pe))),V(this,Pe).set("disclosure-closed",ce.createDisclosureClosed(V(this,Pe)));for(let e of ce.CHINESE_LONGHAND_NAMES)V(this,Pe).set(e,ce.createChineseLonghand(V(this,Pe),e));V(this,Pe).set("ethiopic-numeric",ce.createEthiopicNumeric(V(this,Pe)))}define(e,t){if(!Zy(e))return null;let i=ce.create(V(this,Pe),t);return V(this,Pe).set(e,i),i}getStyle(e){var t;return(t=V(this,Pe).get(e))!=null?t:null}format(e,t){var i;return((i=this.getStyle(e))!=null?i:En(V(this,Pe))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:En(V(this,Pe))).formatMarker(t)}};Pe=new WeakMap;var bo=class{constructor(e,t,i){c(this,"endStuckFixed"),c(this,"endFixed"),c(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},Ib=class{constructor(){c(this,"map",[])}getMaxFixed(){return this.map.length==0?0:this.map[this.map.length-1].endFixed}getMaxSlipped(){return this.map.length==0?0:this.map[this.map.length-1].endSlipped}addStuckRange(e){if(this.map.length==0)this.map.push(new bo(e,e,e));else{let t=this.map[this.map.length-1],i=t.endSlipped+e-t.endFixed;t.endFixed==t.endStuckFixed?(t.endFixed=e,t.endStuckFixed=e,t.endSlipped=i):this.map.push(new bo(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new bo(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=ni(this.map.length,n=>e<=this.map[n].endFixed),i=this.map[t];return i.endSlipped-Math.max(0,i.endStuckFixed-e)}fixedBySlipped(e){let t=ni(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}};function Ab(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}var Rb=class ga{constructor(t,i,n,r,s,o,a,h){if(this.context=t,this.style=i,this.offset=n,this.isRoot=r,this.flowChunk=s,this.atBlockStart=o,this.atFlowStart=a,this.isParentBoxDisplayed=h,c(this,"flowName"),c(this,"isBlockValue",null),c(this,"hasBoxValue",null),c(this,"styleValues",{}),c(this,"beforeBox",null),c(this,"afterBox",null),c(this,"breakBefore",null),this.flowName=s.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let u=new ga(t,l.before,n,!1,s,this.isBlock(),a,!0),d=u.styleValue("content");Rt(d)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=et(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Ge(this.breakBefore)&&(s.breakBefore=et(s.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let r=this.style._pseudos;if(r&&r.after){let s=new ga(this.context,r.after,t,!1,this.flowChunk,i,n,!0),o=s.styleValue("content");Rt(o)&&(this.afterBox=s)}}}styleValue(t,i){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):i||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",v.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=_c(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==v.none&&!bs(this.styleValue("position"))),this.hasBoxValue}getBreakValue(t){let i=null;if(this.isBlock()){let n=this.styleValue(`break-${t}`);n&&(i=n.toString())}return i}},Fb=class{constructor(e){this.context=e,c(this,"stack",[]),c(this,"atBlockStart",!0),c(this,"atFlowStart",!0),c(this,"atStartStack",[])}empty(){return this.stack.length===0}lastBox(){return this.stack[this.stack.length-1]}lastFlowName(){let e=this.lastBox();return e?e.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(e=>e.displayValue()!==v.none)}push(e,t,i,n){let r=this.lastBox();n&&r&&n.flowName!==r.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let s=n||r.flowChunk,o=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),h=new Rb(this.context,e,t,i,s,o||this.atBlockStart,o,a);return this.stack.push(h),this.atBlockStart=h.hasBox()?!h.beforeBox&&h.isBlock():this.atBlockStart,this.atFlowStart=h.hasBox()?!h.beforeBox&&o:this.atFlowStart,h}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",v.normal).toString(),n=kc(i);n&&!Me(e,n)&&(this.atBlockStart=!1,this.atFlowStart=!1)}}pop(e){let t=this.stack.pop();if(t.buildAfterPseudoElementBox(e,this.atBlockStart,this.atFlowStart),this.atFlowStart&&t.afterBox){let n=t.afterBox.getBreakValue("before");t.flowChunk.breakBefore=et(t.flowChunk.breakBefore,n)}let i=this.lastBox();if(i)if(i.flowName===t.flowName)t.hasBox()&&(this.atBlockStart=this.atFlowStart=!1);else{let n=this.atStartStack.pop();this.atBlockStart=n.atBlockStart,this.atFlowStart=n.atFlowStart}return t}nearestBlockStartOffset(e){if(!e.atBlockStart)return e.offset;let t=this.stack.length-1,i=this.stack[t];for(i===e&&(t--,i=this.stack[t]);t>=0;){if(i.flowName!==e.flowName)return e.offset;if(!i.atBlockStart||i.isRoot)return i.offset;e=i,i=this.stack[--t]}throw new Error("No block start offset found!")}},Ph=class{constructor(e,t,i,n,r,s,o,a,h,l){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=r,this.validatorSet=s,this.counterListener=o,c(this,"root"),c(this,"cascadeHolder"),c(this,"last"),c(this,"rootStyle",{}),c(this,"styleMap",{}),c(this,"counterSnapshots",[]),c(this,"flows",{}),c(this,"flowChunks",[]),c(this,"flowListener",null),c(this,"flowToReach",null),c(this,"idToReach",null),c(this,"cascade"),c(this,"offsetMap"),c(this,"primary",!0),c(this,"primaryStack",[]),c(this,"rootBackgroundAssigned",!1),c(this,"rootLayoutAssigned",!1),c(this,"lastOffset"),c(this,"breakBeforeValues",{}),c(this,"boxStack"),c(this,"bodyReached",!0),this.root=e.root,this.cascadeHolder=t,this.last=this.root,this.cascade=t.createInstance(n,o,a,e.lang,h,l),this.offsetMap=new Ib;let u=e.getElementOffset(this.root);this.lastOffset=u,this.boxStack=new Fb(n),this.offsetMap.addStuckRange(u);let d=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,d,u),this.recordCounterSnapshot(u,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes),this.postprocessTopStyle(d,!1),this.root.namespaceURI){case"http://www.w3.org/1999/xhtml":this.bodyReached=!1;break}this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${u}`]=d,this.lastOffset++,this.replayFlowElementsFromOffset(-1)}hasProp(e,t,i){let n=e[i];return n&&n.evaluate(this.context)!==t[i]}transferPropsToRoot(e,t){for(let i in t){let n=e[i];if(n)this.rootStyle[i]=n,delete e[i];else{let r=t[i];r&&(this.rootStyle[i]=new D(r,uc))}}}postprocessTopStyle(e,t){var i;if(t)for(let n of["writing-mode","direction"])e[n]&&!(t&&this.rootStyle[n])&&(this.rootStyle[n]=e[n]);else for(let n in e)un(n)&&(this.rootStyle[n]=e[n]);if(!this.rootBackgroundAssigned){let n=this.hasProp(e,this.validatorSet.backgroundProps,"background-color")?e["background-color"].evaluate(this.context):null,r=this.hasProp(e,this.validatorSet.backgroundProps,"background-image")?e["background-image"].evaluate(this.context):null;(n&&!J(n)||r&&!J(r))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<Nh.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,Nh[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],r=!0;if(n&&!J(n.value)){let a=n.evaluate(this.context);if(a instanceof F){let h=a.num;switch(a.unit){case"em":case"rem":h*=this.context.initialFontSize;break;case"%":h*=this.context.initialFontSize/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*_t.lh/_t.em;break;default:{let l=_t[a.unit];l&&(h*=l),r=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=r}}let s=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,o=e["line-height"];if(o&&!J(o.value)){let a=o.evaluate(this.context);if(a instanceof vt)this.context.rootLineHeight=a.num*s;else if(a instanceof F){let h=a.num;switch(a.unit){case"em":case"rem":h*=s;break;case"%":h*=s/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let l=_t[a.unit];l&&(h*=l)}}this.context.rootLineHeight=h}}else this.context.rootLineHeight=this.context.fontSize()*this.context.pref.lineHeight}}getTopContainerStyle(){let e=0;for(;!this.bodyReached&&(e+=5e3,this.styleUntil(e,0)!=Number.POSITIVE_INFINITY););return this.rootStyle}getAttrStyle(e){if(e.style instanceof CSSStyleDeclaration){let t=e.getAttribute("style");if(t)return Gw(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}recordCounterSnapshot(e,t,i=[],n){let r={offset:e,counters:Ab(t),changes:Array.from(i||[]),changeTypes:n?{...n}:void 0},s=this.counterSnapshots[this.counterSnapshots.length-1];if(s&&s.offset===e){this.counterSnapshots[this.counterSnapshots.length-1]=r;return}this.counterSnapshots.push(r)}getCounterSnapshotAtOffset(e){if(!this.counterSnapshots.length)return null;let t=ni(this.counterSnapshots.length,n=>e<this.counterSnapshots[n].offset),i=t===0?0:t-1;return this.counterSnapshots[i]||null}getLastCounterSnapshot(){return this.counterSnapshots.length?this.counterSnapshots[this.counterSnapshots.length-1]:null}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(e){if(e>=this.lastOffset)return;let t=this.context,i=this.xmldoc.getElementOffset(this.root);if(e<i){let s=this.getStyle(this.root,!1);if(!this.cascade.firstPageType){let l=s.page,u=l&&!J(l.value)&&l.value.toString();u&&u.toLowerCase()!=="auto"&&(this.cascade.firstPageType=u)}let o=ke(s,"flow-into"),a=o?o.evaluate(t,"flow-into").toString():"body",h=this.encounteredFlowElement(a,s,this.root,i);this.boxStack.empty()&&this.boxStack.push(s,i,!0,h)}let n=this.xmldoc.getNodeByOffset(e),r=this.xmldoc.getNodeOffset(n,0,!1);if(!(r>=this.lastOffset))for(;;){if(n.nodeType!=1)r+=n.textContent.length;else{let o=n,a=this.getStyle(o,!1),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,a,o,r)}r++}if(r>=this.lastOffset)break;let s=n.firstChild;if(s==null){for(;s=n.nextSibling,!s;)if(n=n.parentNode,n===this.root)return}n=s}}resetFlowChunkStream(e){this.flowListener=e;for(let t=0;t<this.flowChunks.length;t++)this.flowListener.encounteredFlowChunk(this.flowChunks[t],this.flows[this.flowChunks[t].flowName])}styleUntilFlowIsReached(e){this.flowToReach=e;let t=0;for(;!(this.flowToReach==null||(t+=5e3,this.styleUntil(t,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(e){if(!e)return;this.idToReach=e;let t=0;for(;!(!this.idToReach||(t+=5e3,this.styleUntil(t,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(e,t,i,n){let r=0,s=Number.POSITIVE_INFINITY,o=!1,a=!1,h=!1,l=t["flow-options"];if(l){let m=ig(l.evaluate(this.context,"flow-options"));o=!!m.exclusive,a=!!m.static,h=!!m.last}let u=t["flow-linger"];u&&(s=$l(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let d=t["flow-priority"];d&&(r=$l(d.evaluate(this.context,"flow-priority"),0));let p=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let m=this.boxStack.lastFlowName();f=this.flows[e]=new ym(e,m)}let g=new bm(e,i,n,r,s,o,a,h,p);return this.flowChunks.push(g),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(e,t,i){if(Ge(e)){let r=this.flows[i].forcedBreakOffsets;(r.length===0||r[r.length-1]<t)&&r.push(t)}let n=this.breakBeforeValues[t];this.breakBeforeValues[t]=et(n,e)}styleUntil(e,t){let i=-1,n;if(e<=this.lastOffset&&(n=this.offsetMap.slippedByFixed(e),i=n+t,i<this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i);if(this.last==null)return Number.POSITIVE_INFINITY;let r=this.context;for(;;){let s=this.last.firstChild;if(s==null)for(;;){if(this.last.nodeType==1){this.cascade.popElement(this.last),this.primary=this.primaryStack.pop();let o=this.boxStack.pop(this.lastOffset),a=null;if(o.afterBox){let h=o.afterBox.getBreakValue("before");this.registerForcedBreakOffset(h,o.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(o):o.afterBox.offset,o.flowName),a=o.afterBox.getBreakValue("after")}a=et(a,o.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,o.flowName)}if(s=this.last.nextSibling,s)break;if(this.last=this.last.parentNode,this.last===this.root)return this.last=null,e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(i):Number.POSITIVE_INFINITY}if(this.last=s,this.last.nodeType!=1)this.lastOffset+=this.last.textContent.length,this.boxStack.encounteredTextNode(this.last),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let o=this.last,a=this.getAttrStyle(o);this.primaryStack.push(this.primary),this.cascade.pushElement(this,o,a,this.lastOffset),this.cascade.lastCounterChanges.length>0&&this.recordCounterSnapshot(this.lastOffset,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes);let h=o.getAttribute("id")||o.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");h&&h===this.idToReach&&(this.idToReach=null),!this.bodyReached&&o.localName=="body"&&o.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let l,u=a["flow-into"];if(u){let p=u.evaluate(r,"flow-into").toString(),f=this.encounteredFlowElement(p,a,o,this.lastOffset);this.primary=!!this.primaryFlows[p],l=this.boxStack.push(a,this.lastOffset,o===this.root,f)}else l=this.boxStack.push(a,this.lastOffset,o===this.root),o===this.xmldoc.body&&(l.breakBefore=et(l.flowChunk.breakBefore,l.breakBefore));let d=this.boxStack.nearestBlockStartOffset(l);if(d===0||o===this.xmldoc.body){let p=a.page,f=p&&!J(p.value)&&p.value.toString();!this.cascade.firstPageType&&f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(l.breakBefore,d,l.flowName),l.beforeBox){let p=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(p,l.beforeBox.atBlockStart?d:l.offset,l.flowName)}if(this.primary&&l.displayValue()===v.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=a,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&d===0)continue;if(e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i)}}}getStyle(e,t){let i=this.xmldoc.getElementOffset(e),n=`e${i}`;return t&&(i=this.xmldoc.getNodeOffset(e,0,!0)),this.lastOffset<=i&&this.styleUntil(i,0),this.styleMap[n]}processContent(e,t,i){}},Nh=["column-count","column-width","column-fill"],cn=class{constructor(e){this.validator=e,c(this,"success",null),c(this,"failure",null),c(this,"code",0)}isSpecial(){return this.code!=0}markAsStartGroup(){this.code=-1}isStartGroup(){return this.code==-1}markAsEndGroup(){this.code=-2}isEndGroup(){return this.code==-2}markAsStartAlternate(e){this.code=2*e+1}isStartAlternate(){return this.code>0&&this.code%2!=0}markAsEndAlternate(e){this.code=2*e+2}isEndAlternate(){return this.code>0&&this.code%2==0}getAlternate(){return Math.floor((this.code-1)/2)}},Ni=class{constructor(e,t){this.where=e,this.success=t,c(this,"what",-1)}},Dn=class Xd{constructor(){c(this,"nodes",[]),c(this,"connections",[]),c(this,"match",[]),c(this,"nomatch",[]),c(this,"error",[]),c(this,"emptyHead",!0)}connect(t,i){for(let n=0;n<t.length;n++)this.connections[t[n]].what=i;t.splice(0,t.length)}clone(){let t=new Xd;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],r=new cn(n.validator);r.code=n.code,t.nodes.push(r)}for(let i=0;i<this.connections.length;i++){let n=this.connections[i],r=new Ni(n.where,n.success);r.what=n.what,t.connections.push(r)}return t.match.push(...this.match),t.nomatch.push(...this.nomatch),t.error.push(...this.error),t}addSpecialToArr(t,i,n){let r=this.nodes.length,s=new cn(Th);n>=0?i?s.markAsStartAlternate(n):s.markAsEndAlternate(n):i?s.markAsStartGroup():s.markAsEndGroup(),this.nodes.push(s),this.connect(t,r);let o=new Ni(r,!0),a=new Ni(r,!1);t.push(this.connections.length),this.connections.push(a),t.push(this.connections.length),this.connections.push(o)}endSpecialGroup(){let t=[this.match,this.nomatch,this.error];for(let i=0;i<t.length;i++)this.addSpecialToArr(t[i],!1,-1)}startSpecialGroup(){if(this.nodes.length)throw new Error("invalid call");this.addSpecialToArr(this.match,!0,-1)}endClause(t){this.addSpecialToArr(this.match,!1,t)}startClause(t){if(this.nodes.length)throw new Error("invalid call");let i=new cn(Th);i.markAsStartAlternate(t),this.nodes.push(i);let n=new Ni(0,!0),r=new Ni(0,!1);this.nomatch.push(this.connections.length),this.connections.push(r),this.match.push(this.connections.length),this.connections.push(n)}addPrimitive(t){let i=this.nodes.length;this.nodes.push(new cn(t));let n=new Ni(i,!0),r=new Ni(i,!1);this.connect(this.match,i),this.emptyHead?(this.nomatch.push(this.connections.length),this.emptyHead=!1):this.error.push(this.connections.length),this.connections.push(r),this.match.push(this.connections.length),this.connections.push(n)}isSimple(){return this.nodes.length==1&&!this.nodes[0].isSpecial()}isPrimitive(){return this.isSimple()&&this.nodes[0].validator instanceof ze}addGroup(t,i){if(t.nodes.length==0)return;let n=this.nodes.length;if(i==4&&n==1&&t.isPrimitive()&&this.isPrimitive()){this.nodes[0].validator=this.nodes[0].validator.combine(t.nodes[0].validator);return}for(let s=0;s<t.nodes.length;s++)this.nodes.push(t.nodes[s]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let r=this.connections.length;for(let s=0;s<t.connections.length;s++){let o=t.connections[s];o.where+=n,o.what>=0&&(o.what+=n),this.connections.push(o)}for(let s=0;s<t.match.length;s++)this.match.push(t.match[s]+r);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let s=0;s<t.nomatch.length;s++)this.match.push(t.nomatch[s]+r);else if(this.emptyHead){for(let s=0;s<t.nomatch.length;s++)this.nomatch.push(t.nomatch[s]+r);this.emptyHead=t.emptyHead}else for(let s=0;s<t.nomatch.length;s++)this.error.push(t.nomatch[s]+r);for(let s=0;s<t.error.length;s++)this.error.push(t.error[s]+r);t.nodes=null,t.connections=null}finish(t,i){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(i),this.connect(this.match,n),this.connect(this.nomatch,n+1),this.connect(this.error,n+1);for(let r of this.connections)r.success?this.nodes[r.where].success=this.nodes[r.what]:this.nodes[r.where].failure=this.nodes[r.what];for(let r=0;r<n;r++)if(this.nodes[r].failure==null||this.nodes[r].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},Lb=1,qd=2,Yd=4,Li=8,os=16,ma=32,as=64,Zd=128,Gn=256,jn=512,wa=1024,Kd=2048,Jd=4096,Qd=8192,ep=class extends oi{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},ze=class tp extends ep{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&Lb?t:null}visitSlash(t){return this.allowed&Kd?t:null}visitStr(t){return this.allowed&qd?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&Yd||this.allowed&as&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&jn)?t.unit=="%"&&this.allowed&wa?t:null:t.num<0&&!(this.allowed&Gn)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&jn?t:null:t.num<=0&&!(this.allowed&Gn)?null:this.allowed&os?t:null}visitInt(t){return t.num==0?this.allowed&jn?t:null:t.num<=0&&!(this.allowed&Gn)?null:this.allowed&(ma|os)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&as&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&Zd?t:null}visitURange(t){return this.allowed&Jd?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){if(this.allowed&as){if(t.name==="device-cmyk"||t.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&zu(t)!==null?t:null;if(CSS.supports("color",t.toString()))return t}if(this.allowed&Qd){let i=t.visit(new Hu);if(CSS.supports("background-image",i.toString()))return t}return t.name==="calc"&&this.allowed&(Li|os|ma|Gn|jn|wa)?t:null}visitExpr(t){return this.allowed&2046?t:null}combine(t){let i={},n={};for(let r in this.idents)i[r]=this.idents[r];for(let r in t.idents)i[r]=t.idents[r];for(let r in this.units)n[r]=this.units[r];for(let r in t.units)n[r]=t.units[r];return new tp(this.allowed|t.allowed,i,n)}},ae=Object.create(null),Th=new ze(0,ae,ae),nl=class extends ep{constructor(e){super(),c(this,"successTerminal"),c(this,"failureTerminal"),c(this,"first"),this.successTerminal=new cn(null),this.failureTerminal=new cn(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,r=this.first,s=i,o=null,a=null;for(;r!==this.successTerminal&&r!==this.failureTerminal;){if(s>=e.length){r=r.failure;continue}let h=e[s],l=h;if(r.isSpecial()){let u=!0;r.isStartGroup()?(o?o.push(a):o=[a],a=[]):r.isEndGroup()?o.length>0?a=o.pop():a=null:r.isEndAlternate()?a[r.getAlternate()]="taken":u=a[r.getAlternate()]==null,r=u?r.success:r.failure}else{if(s==0&&!t&&r.validator instanceof er&&this instanceof er){if(l=new te(e).visit(r.validator),l){s=e.length,r=r.success;continue}}else if(s==0&&!t&&r.validator instanceof rl&&this instanceof er){if(l=new tt(e).visit(r.validator),l){s=e.length,r=r.success;continue}}else l=h.visit(r.validator);if(!l){r=r.failure;continue}if(l!==h&&e===n){n=[];for(let u=0;u<s;u++)n[u]=e[u]}e!==n&&(n[s-i]=l),s++,r=r.success}}return r===this.successTerminal&&(t?n.length>0:s==e.length)?n:null}validateSingle(e){let t=null,i=this.first;for(;i!==this.successTerminal&&i!==this.failureTerminal;){if(!e){i=i.failure;continue}if(i.isSpecial()){i=i.success;continue}if(t=e.visit(i.validator),!t){i=i.failure;continue}e=null,i=i.success}return i===this.successTerminal?t:null}visitEmpty(e){return this.validateSingle(e)}visitSlash(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitURange(e){return this.validateSingle(e)}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return null}},er=class extends nl{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new te(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof rl){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new tt(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},rl=class extends nl{constructor(e){super(e)}visitSpaceList(e){return this.validateSingle(e)}visitCommaList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new tt(t):null}validateForShorthand(e,t){let i=this.first,n;for(;i!==this.failureTerminal;){if(n=i.validator.validateForShorthand(e,t),n)return n;i=i.failure}return null}},Ob=class extends nl{constructor(e,t){super(t),this.name=e}validateSingle(e){return null}visitFunc(e){if(e.name.toLowerCase()!=this.name)return null;let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new Ui(e.name,t):null}},ip=class{tryParse(e,t,i){return t}success(e,t){}},np=class extends ip{constructor(e,t){super(),this.name=t,c(this,"validator"),this.validator=e.validators[this.name]}tryParse(e,t,i){if(i.values[this.name])return t;let n=this.validator.validateForShorthand(e,t);if(n){let r=n.length,s=r>1?new te(n):n[0];return this.success(s,i),t+r}return t}success(e,t){t.values[this.name]=e}},Bb=class extends np{constructor(e,t){super(e,t[0]),this.names=t}success(e,t){for(let i=0;i<this.names.length;i++)t.values[this.names[i]]=e}},Mb=class extends ip{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==Tn){if(++t==e.length)return n}else return n;let r=this.nodes[0].tryParse(e,t,i);if(r==t)return n;t=r;for(let s=1;s<this.nodes.length&&t<e.length&&(r=this.nodes[s].tryParse(e,t,i),r!=t);s++)t=r;return t}},sl=class extends oi{constructor(){super(...arguments),c(this,"syntax",null),c(this,"propList",null),c(this,"error",!1),c(this,"values",{}),c(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new np(this.validatorSet,e)}clone(){let e=new this.constructor;return e.syntax=this.syntax,e.propList=this.propList,e.validatorSet=this.validatorSet,e}init(e,t){this.syntax=e,this.propList=t}finish(e,t){var i,n;if(!this.error){for(let r of this.propList)t.simpleProperty(r,(n=(i=this.values[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:v.initial,e);return!0}return!1}propagateDefaultingValue(e,t,i){for(let n of this.propList)i.simpleProperty(n,e,t)}validateList(e){return this.error=!0,0}validateSingle(e){return this.validateList([e]),null}visitEmpty(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitSpaceList(e){return this.validateList(e.values),null}visitCommaList(e){return this.error=!0,null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return this.validateSingle(e)}},Fn=class extends sl{constructor(){super()}validateList(e){let t=0,i=0;for(;t<e.length;){let n=this.syntax[i].tryParse(e,t,this);if(n>t){t=n,i=0;continue}if(++i==this.syntax.length){this.error=!0;break}}return t}},rp=class extends sl{constructor(){super()}validateList(e){if(e.length>this.syntax.length||e.length==0)return this.error=!0,0;for(let t=0;t<this.syntax.length;t++){let i=t;for(;i>=e.length;)i=i==1?0:i-2;if(this.syntax[t].tryParse(e,i,this)!=i+1)return this.error=!0,0}return e.length}createSyntaxNode(){return new Bb(this.validatorSet,this.propList)}},_b=class extends sl{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===Tn){t=i;break}if(t>this.syntax.length||e.length==0)return this.error=!0,0;for(let i=0;i<this.syntax.length;i++){let n=i;for(;n>=t;)n=n==1?0:n-2;let r;if(t+1<e.length)for(r=t+i+1;r>=e.length;)r=r-(r==t+2?1:2);else r=n;let s=[e[n],e[r]];if(this.syntax[i].tryParse(s,0,this)!=2)return this.error=!0,0}return e.length}},Db=class extends Fn{constructor(){super()}mergeIn(e,t){var i,n;for(let r of this.propList){let s=(n=(i=t[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:v.initial,o=e[r];o||(o=[],e[r]=o),o.push(s)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof tt?this.error=!0:(e.values[i].visit(this),this.mergeIn(t,this.values),this.values["background-color"]&&i!=e.values.length-1&&(this.error=!0)),this.error)return null;this.values={};for(let i in t)i=="background-color"?this.values[i]=t[i].pop():this.values[i]=new tt(t[i]);return null}},zb=class extends Fn{constructor(){super()}init(e,t){super.init(e,t),this.propList.push("font-family","line-height","font-size","font-stretch","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian")}validateList(e){let t=super.validateList(e),i=this.values["font-variant_css2"];i&&(delete this.values["font-variant_css2"],this.values["font-variant-caps"]=i);let n=this.values["font-stretch_css3"];if(n&&(delete this.values["font-stretch_css3"],this.values["font-stretch"]=n),t+2>e.length)return this.error=!0,t;this.error=!1;let r=this.validatorSet.validators;if(!e[t].visit(r["font-size"]))return this.error=!0,t;if(this.values["font-size"]=e[t++],e[t]===Tn){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(r["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let s=t==e.length-1?e[t]:new te(e.slice(t,e.length));return s.visit(r["font-family"])?(this.values["font-family"]=s,e.length):(this.error=!0,t)}visitCommaList(e){if(e.values[0].visit(this),this.error)return null;let t=[this.values["font-family"]];for(let n=1;n<e.values.length;n++)t.push(e.values[n]);let i=new tt(t);return i.visit(this.validatorSet.validators["font-family"])?this.values["font-family"]=i:this.error=!0,null}visitIdent(e){let t=this.validatorSet.systemFonts[e.name];if(t)for(let i in t)this.values[i]=t[i];else this.error=!0;return null}},Vb=class extends Fn{validateList(e){if(e.length===1&&e[0]instanceof de)switch(e[0].name.toLowerCase()){case"normal":e=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":e=[v.auto,v.auto];break;case"none":e=[B("no-autospace"),B("space-all")];break}return super.validateList(e)}},Ub=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","crop-marks-line-color","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","src","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],Hb=class extends Fn{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)Ub.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},Ih={SIMPLE:Fn,INSETS:rp,INSETS_SLASH:_b,COMMA:Db,FONT:zb,TEXT_SPACING:Vb,ALL:Hb},$b=["initial-letter"],Wb=class{constructor(){c(this,"validators",{}),c(this,"prefixes",{}),c(this,"defaultValues",{}),c(this,"namedValidators",{}),c(this,"systemFonts",{}),c(this,"shorthands",{}),c(this,"layoutProps",{}),c(this,"backgroundProps",{})}addReplacement(e,t){let i;if(t.type==3)i=new F(t.num,t.text);else if(t.type==7)i=new Lu(t.text);else if(t.type==1)i=B(t.text);else throw new Error("unexpected replacement");if(e.isPrimitive()){let n=e.nodes[0].validator.idents;for(let r in n)n[r]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new Dn;if(e=="||"){for(let r=0;r<t.length;r++){let s=new Dn;s.startClause(r),s.addGroup(t[r],1),s.endClause(r),i.addGroup(s,r==0?1:4)}let n=new Dn;return n.startSpecialGroup(),n.addGroup(i,3),n.endSpecialGroup(),n}else{let n;switch(e){case" ":n=1;break;case"|":case"||":n=4;break;default:throw new Error("unexpected op")}for(let r=0;r<t.length;r++)i.addGroup(t[r],r==0?1:n);return i}}addCounts(e,t,i){let n=new Dn;for(let r=0;r<t;r++)n.addGroup(e.clone(),1);if(i==Number.POSITIVE_INFINITY)n.addGroup(e,3);else for(let r=t;r<i;r++)n.addGroup(e.clone(),2);return n}primitive(e){let t=new Dn;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new rl(t);break;case"SPACE":i=new er(t);break;default:i=new Ob(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new ze(as,ae,ae)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new ze(Qd,ae,ae)),this.namedValidators.POS_INT=this.primitive(new ze(ma,ae,ae)),this.namedValidators.POS_NUM=this.primitive(new ze(os,ae,ae)),this.namedValidators.POS_PERCENTAGE=this.primitive(new ze(Li,ae,{"%":Y})),this.namedValidators.NEGATIVE=this.primitive(new ze(Gn,ae,ae)),this.namedValidators.ZERO=this.primitive(new ze(jn,ae,ae)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new ze(wa,ae,ae)),this.namedValidators.POS_LENGTH=this.primitive(new ze(Li,ae,{em:Y,ex:Y,ch:Y,rem:Y,lh:Y,rlh:Y,vw:Y,vh:Y,vi:Y,vb:Y,vmin:Y,vmax:Y,pvw:Y,pvh:Y,pvi:Y,pvb:Y,pvmin:Y,pvmax:Y,cm:Y,mm:Y,in:Y,px:Y,pt:Y,pc:Y,q:Y})),this.namedValidators.POS_ANGLE=this.primitive(new ze(Li,ae,{deg:Y,grad:Y,rad:Y,turn:Y})),this.namedValidators.POS_TIME=this.primitive(new ze(Li,ae,{s:Y,ms:Y})),this.namedValidators.FREQUENCY=this.primitive(new ze(Li,ae,{Hz:Y,kHz:Y})),this.namedValidators.RESOLUTION=this.primitive(new ze(Li,ae,{dpi:Y,dpcm:Y,dppx:Y})),this.namedValidators.URI=this.primitive(new ze(Zd,ae,ae)),this.namedValidators.URANGE=this.primitive(new ze(Jd,ae,ae)),this.namedValidators.IDENT=this.primitive(new ze(Yd,ae,ae)),this.namedValidators.STRING=this.primitive(new ze(qd,ae,ae)),this.namedValidators.SLASH=this.primitive(new ze(Kd,ae,ae));let e={"font-family":B("sans-serif")};this.systemFonts.caption=e,this.systemFonts.icon=e,this.systemFonts.menu=e,this.systemFonts["message-box"]=e,this.systemFonts["small-caption"]=e,this.systemFonts["status-bar"]=e}isBuiltIn(e){return!!e.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(e,t){let i=e.token();if(i.type==0)return null;let n={"":!0};if(i.type==14){do{if(e.consume(),i=e.token(),i.type!=1)throw new Error("Prefix name expected");n[i.text]=!0,e.consume(),i=e.token()}while(i.type==16);if(i.type!=15)throw new Error("']' expected");e.consume(),i=e.token()}if(i.type!=1)throw new Error("Property name expected");if(t==2?i.text=="SHORTHANDS":i.text=="DEFAULTS")return e.consume(),null;let r=i.text;if(e.consume(),t!=2){if(e.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(r)||(this.prefixes[r]=n)}else if(e.token().type!=18)throw new Error("':' expected");return r}parseValidators(e){for(;;){let t=this.readNameAndPrefixes(e,1);if(!t)return;let i=[],n=[],r="",s,o=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(r,i)},h=u=>{if(o)throw new Error(`'${u}': unexpected`);if(r&&r!=u)throw new Error(`mixed operators: '${u}' and '${r}'`);r=u,o=!0},l=null;for(;!l;){e.consume();let u=e.token();switch(u.type){case 1:if(o||h(" "),this.isBuiltIn(u.text)){let d=this.namedValidators[u.text];if(!d)throw new Error(`'${u.text}' unexpected`);i.push(d.clone())}else{let d={};d[u.text.toLowerCase()]=B(u.text),i.push(this.primitive(new ze(0,d,ae)))}o=!1;break;case 5:{let d={};d[`${u.num}`]=new Be(u.num),i.push(this.primitive(new ze(0,d,ae))),o=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:o||h(" "),n.push({vals:i,op:r,b:"["}),r="",i=[],o=!0;break;case 6:o||h(" "),n.push({vals:i,op:r,b:"(",fn:u.text}),r="",i=[],o=!0;break;case 15:{s=a();let d=n.pop();if(d.b!="[")throw new Error("']' unexpected");i=d.vals,i.push(s),r=d.op,o=!1;break}case 11:{s=a();let d=n.pop();if(d.b!="(")throw new Error("')' unexpected");i=d.vals,i.push(this.newFunc(d.fn,s)),r=d.op,o=!1;break}case 18:if(o)throw new Error("':' unexpected");e.consume(),i.push(this.addReplacement(i.pop(),e.token()));break;case 22:if(o)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(o)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(o)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");let d=u.num,p=d;if(e.consume(),u=e.token(),u.type==16){if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");p=u.num,e.consume(),u=e.token()}if(u.type!=13)throw new Error("'}' expected");i.push(this.addCounts(i.pop(),d,p));break}case 17:if(l=a(),n.length>0)throw new Error(`unclosed '${n.pop().b}'`);break;default:throw new Error("unexpected token")}}e.consume(),this.isBuiltIn(t)?this.namedValidators[t]=l:l.isSimple()?this.validators[t]=l.nodes[0].validator:this.validators[t]=new er(l)}}parseDefaults(e){for(;;){let t=this.readNameAndPrefixes(e,2);if(!t)return;let i=[];for(;;){e.consume();let n=e.token();if(n.type==17){e.consume();break}switch(n.type){case 1:i.push(B(n.text));break;case 4:i.push(new vt(n.num));break;case 5:i.push(new Be(n.num));break;case 3:i.push(new F(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new te(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&Ih[i.text]?(n=new Ih[i.text],e.consume()):n=new Fn,n.setOwner(this);let r=!1,s=[],o=!1,a=[],h=[];for(;!r;)switch(e.consume(),i=e.token(),i.type){case 1:if(this.validators[i.text])s.push(n.syntaxNodeForProperty(i.text)),i.text.includes("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof rp){let l=this.shorthands[i.text];s.push(l.createSyntaxNode()),h.push(...l.propList)}else throw new Error(`'${i.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(s.length>0||o)throw new Error("unexpected slash");o=!0;break;case 14:a.push({slash:o,syntax:s}),s=[],o=!1;break;case 15:{let l=new Mb(s,o),u=a.pop();s=u.syntax,o=u.slash,s.push(l);break}case 17:r=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(s,h),this.shorthands[t]=n}}parse(e){let t=new Xt(e,null);this.parseValidators(t),this.parseDefaults(t),this.parseShorthands(t),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(e){var t;let i={};for(let n of e){let r=this.shorthands[n],s=r?r.propList:[n];for(let o of s)i[o]=(t=this.defaultValues[o])!=null?t:v.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){let r=n.ruleType;if(jt(e)||r==="font-face"||jb(t)){n.simpleProperty(e,t,i);return}if(r==="counter-style"){bb(e,t)?n.simpleProperty(e,t,i):n.invalidPropertyValue(e,t);return}let s="",o=e;e=e.toLowerCase();let a=e.match(/^-([a-z]+)-([-a-z0-9]+)$/);a&&(s=a[1],e=a[2]);let h=this.prefixes[e];if(!h||!h[s]){CSS.supports(o,t.toString())?n.simpleProperty(o,t,i):s&&!lu.includes(`-${s}-`)||n.unknownProperty(o,t);return}else if($b.includes(e)&&!Object.keys(h).some(u=>Ur(u?`-${u}-`:"",e))){n.unknownProperty(o,t);return}let l=this.validators[e];if(l){let u=J(t)||t.isExpr()?t:t.visit(l);u?n.simpleProperty(e,u,i):!s&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(o,t)}else{let u=this.shorthands[e].clone();J(t)?u.propagateDefaultingValue(t,i,n):(t.visit(u),u.finish(i,n)||n.invalidPropertyValue(o,t))}}};function sp(){let e=new Wb;return e.initBuiltInValidators(),e.parse(ic),e}var Gb=class extends oi{constructor(){super(...arguments),c(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function jb(e){let t=new Gb;return e.visit(t),t.varFound}var A0=`OTTO${new Date().valueOf()}`;function ol(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function Xb(e){let t=new ii;for(let i of ol(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function qb(e,t){let i={};for(let n in e)i[n]=ke(e,n).evaluate(t,n);return i}var op=class{constructor(e){this.properties=e,c(this,"fontTraitKey"),c(this,"src"),c(this,"blobURLs",[]),c(this,"blobs",[]),c(this,"family"),this.fontTraitKey=Xb(this.properties),this.src=this.properties.src?this.properties.src.toString():null;let t=this.properties["font-family"];this.family=t?t.stringValue():null}traitsEqual(e){return this.fontTraitKey==e.fontTraitKey}makeAtRule(e,t){let i=new ii;i.append(`@font-face {
1868
+ }`;function es(e,t,i){let n=D("fetchFromURL"),r={method:i||"GET",mode:"cors"},o=n.suspend(),s={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(e,r).then(a=>{var h;if(s.status=a.status,s.url=a.url,s.statusText=a.statusText,s.contentType=(h=a.headers.get("Content-Type"))==null?void 0:h.replace(/;.*$/,"").toLowerCase(),!a.ok)throw new Error(`HTTP ${a.status}${a.statusText?` ${a.statusText}`:""}`);return t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?(s.contentType="text/html",a.arrayBuffer().then(l=>new TextDecoder("Shift_JIS").decode(l))):(/^data:,(<|%3c)/i.test(e)&&(s.contentType="text/html"),a.text())}).then(a=>{t==="blob"&&a instanceof Blob?s.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?s.responseBlob=Gc([a]):t==="json"?s.responseText=JSON.stringify(a):typeof a=="string"&&(s.responseText=a),o.schedule(s)}).catch(a=>{s.status>=400?j.warn(`Error fetching ${e} (${s.status}${s.statusText?" "+s.statusText:""})`):j.warn(a,`Error fetching ${e}`),o.schedule(s)}),n.result()}function Gc(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Qm(e){let t=D("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function ew(e){return URL.createObjectURL(e)}var il=class{constructor(e,t){this.parser=e,this.type=t,c(this,"resources",{}),c(this,"fetchers",{})}load(e,t,i){e=Bt(e);let n=this.resources[e];return typeof n<"u"?T(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=D("fetch"),r=e.endsWith("?viv-toc-box");r&&(e=e.replace("?viv-toc-box",""));let o=Ie("user-agent.xml",vi),s=!r&&e===o;return s&&(e=`data:application/xml,${encodeURIComponent(zc)}`),es(e,this.type).then(a=>{if(a.status>=400&&t)throw new Error((i||`Failed to fetch required resource: ${e}`)+` (${a.status}${a.statusText?" "+a.statusText:""})`);r?(e+="?viv-toc-box",a.url+="?viv-toc-box"):s&&(a.url=e=o),this.parser(a,this).then(h=>{delete this.fetchers[e],this.resources[e]=h,n.finish(h)})}),n.result()}fetch(e,t,i){if(e=Bt(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new Ar(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[Bt(e)]}delete(e){delete this.resources[Bt(e)]}};function tw(e,t){let i=e.responseText;return T(i?ja(i):null)}function iw(){return new il(tw,"text")}function vt(e,t,i){let n=new Ar(()=>{let r=D("loadElement"),o=r.suspend(e),s=!1,a=null,h=l=>{s||(s=!0,a!==null&&(clearTimeout(a),a=null),o.schedule(l?l.type:"timeout"))};if(e.addEventListener("load",h,!1),e.addEventListener("error",h,!1),e.addEventListener("abort",h,!1),e.namespaceURI=="http://www.w3.org/2000/svg")t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(h,300);else if(e.localName==="script")a=setTimeout(h,3e3);else if(t)if(e.localName==="img"){let l=e;l.loading==="lazy"&&(l.loading="eager"),l.src=t,i&&(l.alt=i),l.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4)}else e.src=t,i&&(e.alt=i);else(e.localName==="img"||e.localName==="embed"||e.localName==="object"||e.localName==="iframe")&&(e.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4));return r.result()},`loadElement ${t||e.localName}`);return n.start(),n}var wh=0,nw=16777216,jc=33554432,Xc=50331648,qc=67108864,rw=83886080,ow=100663296,ts=class{constructor(e){this.scope=e,c(this,"flavor"),this.flavor="Author"}getCurrentToken(){return null}getScope(){return this.scope}error(e,t){}startStylesheet(e){this.flavor=e}tagSelector(e,t){}classSelector(e){}pseudoclassSelector(e,t){}pseudoelementSelector(e,t){}idSelector(e){}attributeSelector(e,t,i,n){}descendantSelector(){}childSelector(){}adjacentSiblingSelector(){}followingSiblingSelector(){}nextSelector(){}startSelectorRule(){}startFontFaceRule(){}startCounterStyleRule(e){}startFootnoteRule(e){}startViewportRule(){}startDefineRule(){}startRegionRule(){}startPageRule(){}startPageMarginBoxRule(e){}startWhenRule(e){}startMediaRule(e){this.startWhenRule(e)}startFlowRule(e){}startPageTemplateRule(){}startPageMasterRule(e,t,i){}startPartitionRule(e,t,i){}startPartitionGroupRule(e,t,i){}startRuleBody(){}property(e,t,i){}endRule(){}startFuncWithSelector(e,t){}endFuncWithSelector(){}pushSelectorText(e){}getImportantSpecificity(){switch(this.flavor){case"UA":return wh;case"User":return ow;default:return rw}}getBaseSpecificity(){switch(this.flavor){case"UA":return wh;case"User":return nw;default:return jc}}},Ks=class extends ts{constructor(){super(null),c(this,"stack",[]),c(this,"tokenizer",null),c(this,"slave",null)}pushHandler(e){this.stack.push(this.slave),this.slave=e}popHandler(){this.slave=this.stack.pop()}getCurrentToken(){return this.tokenizer?this.tokenizer.token():null}getScope(){return this.slave.getScope()}error(e,t){this.slave.error(e,t)}errorMsg(e,t){var i;j.warn(e,(i=t?.toString())!=null?i:"")}startStylesheet(e){super.startStylesheet(e),this.stack.length>0&&(this.slave=this.stack[0],this.stack=[]),this.slave.startStylesheet(e)}tagSelector(e,t){this.slave.tagSelector(e,t)}classSelector(e){this.slave.classSelector(e)}pseudoclassSelector(e,t){this.slave.pseudoclassSelector(e,t)}pseudoelementSelector(e,t){this.slave.pseudoelementSelector(e,t)}idSelector(e){this.slave.idSelector(e)}attributeSelector(e,t,i,n){this.slave.attributeSelector(e,t,i,n)}descendantSelector(){this.slave.descendantSelector()}childSelector(){this.slave.childSelector()}adjacentSiblingSelector(){this.slave.adjacentSiblingSelector()}followingSiblingSelector(){this.slave.followingSiblingSelector()}nextSelector(){this.slave.nextSelector()}startSelectorRule(){this.slave.startSelectorRule()}startFontFaceRule(){this.slave.startFontFaceRule()}startCounterStyleRule(e){this.slave.startCounterStyleRule(e)}startFootnoteRule(e){this.slave.startFootnoteRule(e)}startViewportRule(){this.slave.startViewportRule()}startDefineRule(){this.slave.startDefineRule()}startRegionRule(){this.slave.startRegionRule()}startPageRule(){this.slave.startPageRule()}startPageMarginBoxRule(e){this.slave.startPageMarginBoxRule(e)}startWhenRule(e){this.slave.startWhenRule(e)}startFlowRule(e){this.slave.startFlowRule(e)}startPageTemplateRule(){this.slave.startPageTemplateRule()}startPageMasterRule(e,t,i){this.slave.startPageMasterRule(e,t,i)}startPartitionRule(e,t,i){this.slave.startPartitionRule(e,t,i)}startPartitionGroupRule(e,t,i){this.slave.startPartitionGroupRule(e,t,i)}startRuleBody(){this.slave.startRuleBody()}property(e,t,i){this.slave.property(e,t,i)}endRule(){this.slave.endRule()}startFuncWithSelector(e,t){this.slave.startFuncWithSelector(e,t)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},yh=class extends ts{constructor(e,t,i){super(e),this.owner=t,this.topLevel=i,c(this,"depth",0),t&&(this.flavor=t.flavor)}getCurrentToken(){var e;return(e=this.owner)==null?void 0:e.getCurrentToken()}error(e,t){var i;(i=this.owner)==null||i.errorMsg(e,t)}startRuleBody(){this.depth++}endRule(){--this.depth==0&&!this.topLevel&&this.owner.popHandler()}},Xi=class extends yh{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new yh(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startCounterStyleRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_COUNTER_STYLE")}startFootnoteRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FOOTNOTE")}startViewportRule(){this.reportAndSkip("E_CSS_UNEXPECTED_VIEWPORT")}startDefineRule(){this.reportAndSkip("E_CSS_UNEXPECTED_DEFINE")}startRegionRule(){this.reportAndSkip("E_CSS_UNEXPECTED_REGION")}startPageRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE")}startWhenRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startFlowRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(e,t){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(e,t,i){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},ze=[],No=[],xe=[],Be=[],Lt=[],ot=[],De=[],Ye=[],be=[],Je=[],lt=[],Ge=[],_e=[],rn=55,on=56,Gr=57;ze[1]=28,ze[36]=29,ze[7]=29,ze[9]=29,ze[14]=29,ze[18]=29,ze[50]=29,ze[20]=30,ze[13]=27,ze[0]=200,No[1]=46,No[0]=200,ot[1]=2,ot[36]=4,ot[7]=6,ot[9]=8,ot[14]=10,ot[18]=14,ot[50]=42,xe[37]=11,xe[23]=12,xe[35]=56,xe[1]=1,xe[36]=3,xe[7]=5,xe[9]=7,xe[14]=9,xe[12]=13,xe[18]=55,xe[50]=58,xe[16]=41,Be[37]=11,Be[23]=12,Be[35]=56,Be[1]=1,Be[36]=3,Be[7]=5,Be[9]=7,Be[14]=9,Be[18]=55,Lt[1]=2,Lt[36]=4,Lt[7]=6,Lt[9]=8,Lt[18]=14,Lt[50]=42,Lt[14]=10,Lt[12]=13,De[1]=15,De[7]=16,De[4]=17,De[5]=18,De[3]=19,De[2]=20,De[8]=21,De[27]=57,De[16]=22,De[19]=23,De[6]=24,De[11]=25,De[17]=26,De[13]=48,De[31]=47,De[23]=54,De[0]=44,Ye[1]=31,Ye[4]=32,Ye[5]=32,Ye[3]=33,Ye[2]=34,Ye[10]=40,Ye[6]=38,Ye[31]=36,Ye[24]=36,Ye[32]=35,be[1]=45,be[16]=37,be[37]=37,be[38]=37,be[47]=37,be[48]=37,be[39]=37,be[49]=37,be[41]=37,be[26]=37,be[25]=37,be[23]=37,be[24]=37,be[19]=37,be[21]=37,be[36]=37,be[18]=37,be[22]=37,be[11]=39,be[12]=43,be[17]=49,Je[0]=200,Je[12]=50,Je[13]=51,Je[14]=50,Je[15]=51,Je[10]=50,Je[11]=51,Je[17]=53,lt[0]=200,lt[12]=50,lt[13]=52,lt[14]=50,lt[15]=51,lt[10]=50,lt[11]=51,lt[17]=53,Ge[0]=200,Ge[12]=50,Ge[13]=51,Ge[14]=50,Ge[15]=51,Ge[10]=50,Ge[11]=51,_e[11]=0,_e[16]=0,_e[22]=1,_e[18]=1,_e[26]=2,_e[25]=2,_e[38]=3,_e[37]=3,_e[48]=3,_e[47]=3,_e[39]=3,_e[49]=3,_e[41]=3,_e[23]=4,_e[24]=4,_e[36]=5,_e[19]=5,_e[21]=5,_e[0]=6,_e[rn]=2,_e[on]=2;var Fr=class{constructor(e,t,i,n){this.actions=e,this.tokenizer=t,this.handler=i,this.baseURL=n,c(this,"valStack",[]),c(this,"namespacePrefixToURI",{}),c(this,"defaultNamespaceURI",null),c(this,"propName",null),c(this,"propImportant",!1),c(this,"exprContext"),c(this,"result",null),c(this,"importReady",!1),c(this,"importURL",null),c(this,"importCondition",null),c(this,"errorBrackets",[]),c(this,"ruleStack",[]),c(this,"regionRule",!1),c(this,"pageRule",!1),c(this,"inStyleDeclaration",!1),this.exprContext=2}extractVals(e,t){let i=[],n=this.valStack;for(;t<n.length&&(i.push(n[t++]),t!==n.length);){if(n[t++]!==e)throw new Error("Unexpected state");t===n.length&&i.push(Y)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,r=0,o;do if(o=i[--n],e===")"&&o instanceof Qi){if(o.text===")")r++;else if(o.text==="("){if(r===0)return null;r--}}while(typeof o<"u"&&typeof o!="string");let s=i.length-(n+1);if(s>1&&i.splice(n+1,s,new J(i.slice(n+1,i.length))),e==",")return null;n++;do o=i[--n];while(typeof o<"u"&&(typeof o!="string"||o==","));if(s=i.length-(n+1),o=="("){e!=")"&&t.type!==0&&(this.handler.error("E_CSS_MISMATCHED_C_PAR",t),this.actions=lt);let h=new ci(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,s+2,h),h.name==="var"){let l=h.values[0]instanceof de&&h.values[0].name;(!Qt(l)||l===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${h.toString()}`,t),this.actions=lt)}return h}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=lt,null;if(s>1)return new it(this.extractVals(",",n+1));let a=i[0];return a instanceof nt?a:a?new Qi(a.toString()):Y}exprError(e,t){this.actions=this.propName?lt:Je,j.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,r=i.pop(),o;for(;;){let s=i.pop();if(e==11){let a=[r];for(;s==16;)a.unshift(i.pop()),s=i.pop();if(typeof s=="string"){if(s=="{"){for(;a.length>=2;){let h=a.shift(),l=a.shift(),u=new wg(n.getScope(),h,l);a.unshift(u)}return i.push(new G(a[0])),!0}else if(s=="("){let h=i.pop(),l=i.pop();r=new tr(n.getScope(),Ds(l,h),a),e=0;continue}}if(s==10){r.isMediaName()&&(r=new Zl(n.getScope(),r,null)),e=0;continue}}else if(typeof s=="string"){i.push(s);break}if(s<0)if(s==-31)r=new xi(n.getScope(),r);else if(s==-24)r=new un(n.getScope(),r);else if(s==-Gr)r=new gg(n.getScope(),r);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(_e[e]>_e[s]){i.push(s);break}switch(o=i.pop(),s){case 26:r=new Za(n.getScope(),o,r);break;case rn:r=new mg(n.getScope(),o,r);break;case on:r=new yg(n.getScope(),o,r);break;case 25:r=new Ka(n.getScope(),o,r);break;case 38:r=new vg(n.getScope(),o,r);break;case 37:r=new xg(n.getScope(),o,r);break;case 48:r=new bg(n.getScope(),o,r);break;case 47:r=new Us(n.getScope(),o,r);break;case 39:case 49:r=new Ja(n.getScope(),o,r);break;case 41:r=new Sg(n.getScope(),o,r);break;case 23:r=new qu(n.getScope(),o,r);break;case 24:r=new Yu(n.getScope(),o,r);break;case 36:r=new Qa(n.getScope(),o,r);break;case 19:r=new Zu(n.getScope(),o,r);break;case 21:r=new Ku(n.getScope(),o,r);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),r=new Eg(n.getScope(),i.pop(),o,r);break;case 10:if(o.isMediaName())r=new Zl(n.getScope(),o,r);else return this.exprError("E_CSS_MEDIA_TEST",t),!1;break}else return this.exprError("E_CSS_EXPR_COND",t),!1;break;case 22:if(e!=18)return this.exprError("E_CSS_EXPR_COND",t),!1;case 10:return i.push(o),i.push(s),i.push(r),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(r),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,r;if(t)r=e.text,n=e.position+r.length+1;else if(e.type===10){let u=i.nthToken(1),d=i.nthToken(2);if(u.type===1&&d.type===18)i.consume(),i.consume(),r=u.text,n=d.position+1;else{if(u.type===10||u.type===6||u.type===1&&u.text.toLowerCase()==="not"&&(d.type===10||d.type===6))return null;n=e.position+1}}else return null;let o=0,s,a=0;for(;o>=0;)switch(i.consume(),s=i.token(),s.type){case 11:o--;break;case 10:case 6:o++;break;case 16:o===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",s),null}i.consume();let h=s.position,l=t&&r==="selector"&&a>0?"":i.input.substring(n,h).trim();return new Pg(this.handler.getScope(),r,l,t)}readPseudoParams(){let e=[];for(;;){let t=this.tokenizer.token();switch(t.type){case 1:e.push(t.text);break;case 23:e.push("+");break;case 4:case 5:e.push(t.num);break;default:return e}this.tokenizer.consume()}}skipPseudoFunctionContents(){let e=0;for(;;){switch(this.tokenizer.token().type){case 0:return!1;case 11:if(e===0)return!0;e--;break;case 10:case 6:e++;break}this.tokenizer.consume()}}readNthPseudoParams(){let e=!1,t=this.tokenizer.token();if(t.type===23)e=!0,this.tokenizer.consume(),t=this.tokenizer.token();else if(t.type===1&&(t.text==="even"||t.text==="odd"))return this.tokenizer.consume(),[2,t.text==="odd"?1:0];switch(t.type){case 3:if(e&&t.num<0)return null;case 1:if(e&&t.text.charAt(0)==="-")return null;if(t.text==="n"||t.text==="-n"){if(e&&t.precededBySpace)return null;let i=t.text==="-n"?-1:1;t.type===3&&(i=t.num);let n=0;this.tokenizer.consume(),t=this.tokenizer.token();let r=t.type===24,o=t.type===23||r;if(o&&(this.tokenizer.consume(),t=this.tokenizer.token()),t.type===5){if(n=t.num,1/n===-1/0){if(n=0,o)return null}else if(n<0){if(o)return null}else if(n>=0&&!o)return null;this.tokenizer.consume()}else if(o)return null;return[i,r&&n>0?-n:n]}else if(t.text==="n-"||t.text==="-n-"){if(e&&t.precededBySpace)return null;let i=t.text==="-n-"?-1:1;if(t.type===3&&(i=t.num),this.tokenizer.consume(),t=this.tokenizer.token(),t.type===5)return t.num<0||1/t.num===-1/0?null:(this.tokenizer.consume(),[i,t.num])}else{let i=t.text.match(/^n(-[0-9]+)$/);if(i)return e&&t.precededBySpace?null:(this.tokenizer.consume(),[t.type===3?t.num:1,parseInt(i[1],10)]);if(i=t.text.match(/^-n(-[0-9]+)$/),i)return this.tokenizer.consume(),[-1,parseInt(i[1],10)]}return null;case 5:return e&&(t.precededBySpace||t.num<0)?null:(this.tokenizer.consume(),[0,t.num])}return null}makeCondition(e,t){let i=this.handler.getScope();if(!i)return null;if(t=t||i._true,e){let n=e.split(/\s+/);for(let r of n)switch(r){case"vertical":t=Mt(i,t,new xi(i,new Ze(i,"pref-horizontal")));break;case"horizontal":t=Mt(i,t,new Ze(i,"pref-horizontal"));break;case"day":t=Mt(i,t,new xi(i,new Ze(i,"pref-night-mode")));break;case"night":t=Mt(i,t,new Ze(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new G(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"counter-style":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":case"footnote":return!0}return!1}runParser(e,t,i,n,r,o){let s=this.handler,a=this.tokenizer,h=this.valStack,l,u,d,p,f,g,m,w=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),r&&w===null&&(w=l.position-1,a.input[w]==="("&&w++),this.actions===De&&this.errorBrackets.length>0&&(l.type===this.errorBrackets[this.errorBrackets.length-1]||l.type===17||l.type===31)){if(l.type===this.errorBrackets[this.errorBrackets.length-1]&&(this.errorBrackets.pop(),l.type===11&&this.valStackReduce(")",l))){a.consume();continue}h.push(new Qi(l.toString())),a.consume();continue}switch(this.actions[l.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(s.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=lt):(this.actions=ot,s.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=De,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=lt,s.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=De,h.splice(0,h.length);continue;case 29:this.actions=ot,s.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=Ge,s.error("E_CSS_SPACE_EXPECTED",l);continue}s.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),d=this.namespacePrefixToURI[l.text],d!=null)switch(l=a.token(),l.type){case 1:s.tagSelector(d,l.text),r?this.actions=Be:this.actions=xe,a.consume();break;case 36:s.tagSelector(d,null),r?this.actions=Be:this.actions=xe,a.consume();break;default:this.actions=Je,s.error("E_CSS_NAMESPACE",l)}else this.actions=Je,s.error("E_CSS_UNDECLARED_PREFIX",l);else s.tagSelector(this.defaultNamespaceURI,l.text),r?this.actions=Be:this.actions=xe,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=Ge,s.error("E_CSS_SPACE_EXPECTED",l);continue}s.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),l=a.token(),l.type){case 1:s.tagSelector(null,l.text),r?this.actions=Be:this.actions=xe,a.consume();break;case 36:s.tagSelector(null,null),r?this.actions=Be:this.actions=xe,a.consume();break;default:this.actions=Je,s.error("E_CSS_NAMESPACE",l)}else s.tagSelector(this.defaultNamespaceURI,null),r?this.actions=Be:this.actions=xe,a.consume();continue;case 5:l.precededBySpace&&s.descendantSelector();case 6:if(!l.text){s.error("E_CSS_SYNTAX",l),a.consume();continue}s.idSelector(l.text),r?this.actions=Be:this.actions=xe,a.consume();continue;case 7:l.precededBySpace&&s.descendantSelector();case 8:s.classSelector(l.text),r?this.actions=Be:this.actions=xe,a.consume();continue;case 55:l.precededBySpace&&s.descendantSelector();case 14:a.consume(),l=a.token();e:switch(l.type){case 1:s.pseudoclassSelector(l.text,null),a.consume(),r?this.actions=Be:this.actions=xe;continue;case 6:switch(p=l.text,a.consume(),p){case"is":case"not":case"where":case"has":this.actions=ot,s.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=xe:this.actions=Ge;continue;case"lang":case"href-epub-type":case"href-role-type":if(l=a.token(),l.type===1){m=[l.text],a.consume(),(p==="href-epub-type"||p==="href-role-type")&&a.token().type===16&&(a.consume(),l=a.token(),l.type===1&&(m.push(l.text),a.consume()));break}else break e;case"nth-child":case"nth-of-type":case"nth-last-child":case"nth-last-of-type":case"nth":if(m=this.readNthPseudoParams(),m)if(p==="nth-child"||p==="nth-last-child"){if(u=a.nthToken(0),u.type===1&&u.text==="of"){a.consume(),this.actions=ot,s.startFuncWithSelector(p,m),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?r?this.actions=Be:this.actions=xe:this.actions=Ge;continue}break}else if(p==="nth"){if(u=a.nthToken(0),u.type===1&&u.text==="of")if(a.consume(),u=a.token(),u.type===1)m.push(u.text),a.consume();else break e;break}else break;else break e;default:if(m=[],!this.skipPseudoFunctionContents())break e}if(l=a.token(),l.type==11){s.pseudoclassSelector(p,m),a.consume(),r?this.actions=Be:this.actions=xe;continue}break}s.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=Je;continue;case 58:l.precededBySpace&&s.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:s.pseudoelementSelector(l.text,null),r?this.actions=Be:this.actions=xe,a.consume();continue;case 6:if(p=l.text,a.consume(),p=="nth-fragment"){if(m=this.readNthPseudoParams(),m===null)break}else m=this.readPseudoParams();if(l=a.token(),l.type==11){s.pseudoelementSelector(p,m),r?this.actions=Be:this.actions=xe,a.consume();continue}break}s.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=Je;continue;case 9:l.precededBySpace&&s.descendantSelector();case 10:if(a.consume(),l=a.token(),l.type==1)p=l.text,a.consume();else if(l.type==36)p=null,a.consume();else if(l.type==34)p="";else{this.actions=Ge,s.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(d=p&&this.namespacePrefixToURI[p],d===void 0){this.actions=Ge,s.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=Ge,s.error("E_CSS_ATTR_NAME_EXPECTED",l);continue}p=l.text,a.consume(),l=a.token()}else d="";switch(l.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=l.type,a.consume(),l=a.token();break;case 15:s.attributeSelector(d,p,0,null),r?this.actions=Be:this.actions=xe,a.consume();continue;default:this.actions=Ge,s.error("E_CSS_ATTR_OP_EXPECTED",l);continue}switch(l.type){case 1:case 2:s.attributeSelector(d,p,f,l.text),a.consume(),l=a.token();break;default:this.actions=Ge,s.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=Ge,s.error("E_CSS_ATTR",l);continue}r?this.actions=Be:this.actions=xe,a.consume();continue;case 11:s.childSelector(),this.actions=Lt,a.consume();continue;case 12:s.adjacentSiblingSelector(),this.actions=Lt,a.consume();continue;case 56:s.followingSiblingSelector(),this.actions=Lt,a.consume();continue;case 13:this.regionRule?(this.ruleStack.push("-epubx-region"),this.regionRule=!1):this.pageRule?(this.ruleStack.push("page"),this.pageRule=!1,this.inStyleDeclaration=!0):(this.ruleStack.push("[selector]"),this.inStyleDeclaration=!0),s.startRuleBody(),this.actions=ze,a.consume();continue;case 41:s.nextSelector(),this.actions=ot,a.consume();continue;case 15:h.push(M(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new sc(l.text)),a.consume();continue;case 17:h.push(new Ct(l.num)),a.consume();continue;case 18:h.push(new Ue(l.num)),a.consume();continue;case 19:h.push(new R(l.num,l.text)),a.consume();continue;case 20:h.push(new X(l.text)),a.consume();continue;case 21:h.push(new ut(Ie(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new ac(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(Ln),a.consume();continue;case 24:p=l.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=Ye,this.exprContext=0,h.push("{")):(h.push(p),h.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),a.consume();continue;case 25:this.valStackReduce(")",l),a.consume();continue;case 47:if(a.consume(),l=a.token(),u=a.nthToken(1),l.type==1&&l.text.toLowerCase()=="important"&&(u.type==17||u.type==0||u.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",l);continue;case 54:switch(u=a.nthToken(1),u.type){case 4:case 3:case 5:if(!u.precededBySpace){a.consume();continue}}h.push(new Qi("+")),a.consume();continue;case 26:a.consume();case 48:g=this.valStackReduce(";",l),g&&this.propName&&s.property(this.propName,g,this.propImportant),this.actions=i?No:ze;continue;case 44:for(a.consume();h.length>0;){let x=h.length;if(g=this.valStackReduce(";",l),!g||h.length===x)break}return t?(this.result=g,!0):(this.propName&&g&&s.property(this.propName,g,this.propImportant),!0);case 31:if(u=a.nthToken(1),u.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(h.push(l.text,u.text,"("),a.consume()):(h.push(new Ze(s.getScope(),Ds(l.text,u.text))),this.actions=be),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new Yl(s.getScope(),!0,u.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=u),h.push(new Yl(s.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==rn&&h[h.length-1]!==on&&(u.type===10||u.type===6)){h.push(-Gr),a.consume();continue}else h.push(new Ze(s.getScope(),l.text));this.actions=be}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=be;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new Qe(s.getScope(),l.num)),a.consume(),this.actions=be;continue;case 33:p=l.text,p=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?p="vh":p="vw"),h.push(new Er(s.getScope(),l.num,p)),a.consume(),this.actions=be;continue;case 34:h.push(new Qe(s.getScope(),l.text)),a.consume(),this.actions=be;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new tc(s.getScope(),l.num)),a.consume(),this.actions=be);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=Ye,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==on&&h[h.length-2]!==-Gr?(this.actions=Ye,this.exprStackReduce(rn,l),h.push(rn),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==rn&&h[h.length-2]!==-Gr?(this.actions=Ye,this.exprStackReduce(on,l),h.push(on),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=De),a.consume();continue;case 43:this.exprStackReduce(11,l)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",l):(this.exprContext==1?s.startWhenRule(h.pop()):s.startMediaRule(h.pop()),this.ruleStack.push("media"),s.startRuleBody(),this.actions=ze)),a.consume();continue;case 49:if(this.exprStackReduce(11,l))return this.propName||this.exprContext!=3?(this.exprError("E_CSS_UNEXPECTED_SEMICOL",l),this.actions=ze,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=ze,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let x=this.readSupportsTest(l);if(x){h.push(x),this.actions=be;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=ze,a.consume(),s.endRule(),this.inStyleDeclaration=!1,this.ruleStack.length)switch(this.ruleStack.pop(),this.ruleStack[this.ruleStack.length-1]){case"page":case"-epubx-page-master":case"-epubx-partition-group":this.inStyleDeclaration=!0}continue;case 30:switch(p=l.text.toLowerCase(),p){case"import":if(a.consume(),l=a.token(),l.type==2||l.type==8){if(this.importURL=l.text,a.consume(),l=a.token(),l.type==17||l.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Ye,h.push("{");continue}s.error("E_CSS_IMPORT_SYNTAX",l),this.actions=Je;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(p=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[p]=l.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=l.text,a.consume(),a.consume();continue}break}s.error("E_CSS_NAMESPACE_SYNTAX",l),this.actions=Je;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){p=l.text.toLowerCase(),p!="utf-8"&&p!="utf-16"&&s.error(`E_CSS_UNEXPECTED_CHARSET ${p}`,l),a.consume(),a.consume();continue}s.error("E_CSS_CHARSET_SYNTAX",l),this.actions=Je;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(a.nthToken(1).type==12){switch(a.consume(),a.consume(),p){case"font-face":s.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":s.startPageTemplateRule();break;case"-epubx-define":s.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":s.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(p),s.startRuleBody();continue}break;case"-epubx-region":a.consume(),s.startRegionRule(),this.regionRule=!0,this.actions=ot;continue;case"page":a.consume(),s.startPageRule(),this.pageRule=!0,this.actions=Lt;continue;case"-adapt-footnote-area":case"footnote":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),s.startFootnoteRule(null),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){let x=l.text;a.consume(),a.consume(),s.startFootnoteRule(x),this.ruleStack.push(p==="footnote"?"footnote":"-adapt-footnote-area"),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),l=a.token(),l.type==12){a.consume(),s.startPageMarginBoxRule(p),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=Ye,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Ye,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Ye,h.push("{");continue;case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){s.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"counter-style":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){s.startCounterStyleRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{a.consume(),l=a.token();let x=null,y=null,b=[];for(l.type==1&&(x=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(y=a.nthToken(1).text,a.consume(),a.consume(),l=a.token());l.type==6&&l.text.toLowerCase()=="class"&&a.nthToken(1).type==1&&a.nthToken(2).type==11;)b.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),l=a.token();if(l.type==12){switch(a.consume(),p){case"-epubx-page-master":s.startPageMasterRule(x,y,b);break;case"-epubx-partition":s.startPartitionRule(x,y,b);break;case"-epubx-partition-group":s.startPartitionGroupRule(x,y,b);break}this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":s.error(`E_CSS_UNEXPECTED_AT${p}`,l),this.actions=Ge;continue;default:s.error(`E_CSS_AT_UNKNOWN ${p}`,l),this.actions=Je;continue}s.error(`E_CSS_AT_SYNTAX ${p}`,l),this.actions=Je;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=ze;continue}case 51:if(r&&this.errorBrackets.length==0&&l.type==11)return a.consume(),s.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&l.type==13&&(this.actions=ze),a.consume();continue;case 53:if(r&&this.errorBrackets.length==0&&l.type==16){s.nextSelector(),this.actions=ot,w=l.position+1,a.consume();continue}this.errorBrackets.length==0&&(this.actions=ze),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,l)?(this.result=h.pop(),!0):!1;if(r){if(this.actions===Ge)switch(l.type){case 16:this.errorBrackets.length==0&&(s.nextSelector(),w=l.position+1,this.actions=ot),a.consume();continue;case 11:if(this.errorBrackets.length==0)return s.endFuncWithSelector(),a.consume(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),a.consume();continue;case 12:case 14:case 10:this.errorBrackets.push(l.type+1),a.consume();continue;case 6:this.errorBrackets.push(11),a.consume();continue;case 13:case 15:this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),a.consume();continue;default:a.consume();continue}switch(l.type){case 16:case 11:if(this.actions===ot)s.error("E_CSS_SYNTAX",l);else{let x=a.input.substring(w,l.position);s.pushSelectorText(x),w=l.position+1}if(l.type===16){s.nextSelector(),this.actions=ot,a.consume();continue}else return s.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(o){this.actions=xe;continue}break;case 12:case 14:case 10:this.errorBrackets.push(l.type+1);break}s.error("E_CSS_SYNTAX",l),a.consume(),this.actions=Ge;continue}if(this.actions!==Je&&this.actions!==Ge&&this.actions!==lt){if(l.type==54)s.error("E_CSS_SYNTAX",l);else if(this.actions===De){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new Qi(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==Ye&&h.length>0){s.startMediaRule(h.pop()),this.ruleStack.push("media"),s.startRuleBody(),this.actions=ze,a.consume();continue}else{if(l.type===17&&this.actions==Ye)return this.actions=ze,a.consume(),!1;s.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=lt:this.actions=Ge;continue}a.consume();continue}}return!1}},Yc=class extends ts{constructor(e){super(null),this.scope=e}error(e,t){j.warn(e,t.toString())}getScope(){return this.scope}};function sw(e,t,i,n,r){let o=Zc(t),s=sm(e.input);return s!==e.input?vh(new Vt(s,o),o,i,n,r):vh(e,o,i,n,r)}function vh(e,t,i,n,r){let o=D("parseStylesheet"),s=new Fr(ze,e,t,i),a=null;return r&&(a=Jc(new Vt(r,t),t,i)),a=s.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),o.loop(()=>{for(;!s.runParser(100,!1,!1,!1,!1);){if(s.importReady){let l=Ie(s.importURL,i);s.importCondition&&(t.startMediaRule(s.importCondition),t.startRuleBody());let u=D("parseStylesheet.import");return Kc(l,t,null,null).then(()=>{s.importCondition&&t.endRule(),s.importReady=!1,s.importURL=null,s.importCondition=null,u.finish(!0)}),u.result()}let h=o.timeSlice();if(h.isPending)return h}return T(!1)}).then(()=>{a&&t.endRule(),o.finish(!0)}),o.result()}function nl(e,t,i,n,r){let o=Zc(t);return kn("parseStylesheetFromText",s=>{let a=new Vt(e,o);sw(a,o,i,n,r).thenFinish(s)},(s,a)=>{j.warn(a,`Failed to parse stylesheet text: ${e}`),s.finish(!1)})}function Zc(e){if(e instanceof Ks)return e;if(e instanceof Xi){if(e.owner)return e.owner;let t=new Ks;return t.flavor=e.flavor,t.slave=e,e.owner=t,t}return e}function Kc(e,t,i,n){return kn("parseStylesheetFromURL",r=>{es(e).then(o=>{o.responseText?nl(o.responseText,t,e,i,n).then(s=>{s||j.warn(`Failed to parse stylesheet from ${e}`),r.finish(!0)}):r.finish(!0)})},(r,o)=>{j.warn(o,"Exception while fetching and parsing:",e),r.finish(!0)})}function Rr(e,t,i){let n=new Fr(De,t,new Yc(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function aw(e,t,i){new Fr(No,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Jc(e,t,i){let n=new Fr(Ye,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var lw={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function hw(e){return!!lw[e]}function uw(e,t,i){if(t instanceof Re&&t.str==="viv-leader")return new G(t);if(i==="content"&&t instanceof Re)return new G(t);let n=t.evaluate(e);switch(typeof n){case"number":return hw(i)?n==Math.round(n)?new Ue(n):new Ct(n):new R(n,"px");case"string":return n?i==="content"?new X(n):Rr(t.scope,new Vt(n,null),""):Y;case"boolean":return n?v._true:v._false;case"undefined":return Y}throw new Error("E_UNEXPECTED")}var cw="data-vivliostyle-flow-root";function dw(e){return e.getAttribute(cw)==="true"}function bh(e){let t=e?.toString()||"block",i;switch(t){case"inline-flex":i="flex";break;case"inline-grid":i="grid";break;case"inline-table":i="table";break;case"initial":case"unset":case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":i="block";break;default:i=t}return M(i)}function is(e){return e===v.absolute||e===v.fixed}function To(e){return e instanceof ci&&e.name==="running"}function Qc(e,t,i,n){return e===v.none||(is(t)?(i=v.none,e=bh(e)):(i&&i!==v.none&&!Z(i)||n)&&(e=bh(e))),{display:e,position:t,float:i}}function ed(e,t,i,n){return Qc(e,t,i,n).display===v.block}function ns(e){return e instanceof de||e instanceof J||typeof e=="string"}function Ht(e){if(!ns(e))return!1;let t=e.toString();switch(t){case"inline":case"inline-block":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return t.includes("inline")}}function jn(e){return ns(e)?e.toString().includes("list-item"):!1}function pw(e){if(!ns(e))return!1;switch(e.toString()){case"block":case"flex":case"grid":case"table":case"list-item":case"flow-root":return!0;default:return!1}}function td(e){if(!ns(e))return!1;switch(e.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function fw(e,t,i,n,r,o,s){return r=r||o||v.horizontal_tb,!!s||!!i&&i!==v.none&&!Z(i)||is(t)||e===v.inline_block||e===v.table_cell||e===v.table_caption||e==v.flex||e==v.grid||e==v.flow_root||(e===v.block||e===v.list_item)&&!!n&&n!==v.visible&&n!==v.clip&&!Z(n)||!!o&&r!==o}function gw(e){return e===v.relative||e===v.absolute||e===v.fixed}var Yt=1e5;function rl(e){let t=e.element.style;t.columnGap=`${Yt-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function rs(e){let t=("element"in e?e.element:e).style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function Io(e){return e.element.style.columnCount==="1"}function mw(e){e.element.setAttribute("data-vivliostyle-column","true")}function fr(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/Yt)}function id(e,t){let i=fr(e,t);if(i===0)return 0;let n=t?e.top:Math.min(Math.abs(e.left),Math.abs(e.right)),r=Math.round(n/Yt),o=r*Yt,s=i*Yt;return t?(e.top-=o,e.bottom-=s,e.bottom<e.top&&(e.bottom+=Yt),e.right-=o,e.left-=s):e.left<-Yt/2?(e.right+=o,e.left+=s,e.left>e.right&&(e.left-=Yt),e.top+=o,e.bottom+=s):(e.left-=o,e.right-=s,e.right<e.left&&(e.right+=Yt),e.top+=o,e.bottom+=s),e.width=e.right-e.left,e.height=e.bottom-e.top,r}function Js(e,t){for(let i=0;i<e.length;i++)id(e[i],t)}function Tt(e,t,i){let n=e.getElementClientRect(t);if(id(n,i)>0&&e.getElementComputedStyle(t).display.startsWith("table")&&!Lr(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return rs(r),e.getElementClientRect(t)}return n}function ww(e,t){var i,n;if(e.nodeType===1){let r=e;((i=r.style)==null?void 0:i.breakAfter)==="column"&&(r.style.breakAfter="")}if(t.nodeType===1){let r=t;((n=r.style)==null?void 0:n.breakBefore)==="column"&&(r.style.breakBefore="")}}function Qs(e){let t=e.style;return t?!isNaN(parseFloat(t.columnCount))||!isNaN(parseFloat(t.columnWidth)):!1}function yw(e){if(!e.hasAttribute("data-vivliostyle-column")&&Qs(e))return!0;for(let t of e.querySelectorAll("*"))if(!t.hasAttribute("data-vivliostyle-column")&&Qs(t))return!0;return!1}function Lr(e){for(let t=e.nodeType===1?e:e.parentElement;t;t=t.parentElement){let i=t.style;if(!i||t.hasAttribute("data-vivliostyle-column"))break;if(Qs(t))return t;if(i.position==="absolute")break}return null}function vw(e){var t;if(e.nodeType!==1)return;let i=e,n=i.style,r=n?.breakBefore==="column",o=i.previousElementSibling,s=o&&((t=o.style)==null?void 0:t.breakAfter)==="column";if(!r&&!s)return;let a=Lr(i);if(!a)return;let h=a.ownerDocument.defaultView.getComputedStyle(a),{writingMode:l,direction:u,columnGap:d,fontSize:p}=h,f=l==="vertical-rl"||l==="vertical-lr",g=u==="rtl",m=(parseFloat(d)||parseFloat(p)||16)/2,w=a.getBoundingClientRect(),x=i.getBoundingClientRect();(f?x.top>w.bottom+m:g?x.right<w.left-m:x.left>w.right+m)&&(r&&(n.breakBefore=""),s&&o&&(o.style.breakAfter=""),n.marginBlockStart=`${Yt}px`)}function jr(e){let t=e.element.lastElementChild,i=t&&e.clientLayout.getElementClientRect(t);return i?fr(i,e.vertical):0}function nd(e,t){if(e.getAttribute("data-viv-saved-column-fill")!=="auto"||jr(t))return;let i=t.clientLayout.getElementComputedStyle(e),n=parseFloat(i.blockSize);e.style.columnFill="auto";let r=parseFloat(i.blockSize);if(r<=0||e.parentElement&&Lr(e.parentElement)){e.removeAttribute("data-viv-saved-column-fill");return}let o=NaN;if(e.style.blockSize=`${r}px`,jr(t)){if(e.style.blockSize=`${n}px`,!jr(t)){let s=1/(t.clientLayout.pixelRatio||1),a=n,h=r;for(;h-a>s;){let l=(a+h)/2;e.style.blockSize=`${l}px`,jr(t)?h=l:a=l}o=a,e.style.blockSize=`${o}px`}}else if(o=parseFloat(i.blockSize),o<r){let s=1/t.clientLayout.layoutUnitPerPixel;o=r+s,e.style.blockSize=`${o}px`}if(isNaN(o)){e.style.blockSize="",e.style.columnFill="balance";return}e.removeAttribute("data-viv-saved-column-fill")}function bw(e){let t=e.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let i of t)nd(i,e)}function sn(e,t,i,n){let r=e.viewNode;if(!r)return NaN;let o=r.nodeType===1?r:r.parentElement;if(o&&o.namespaceURI==="http://www.w3.org/1999/xhtml"){let s=o.style;if(o.localName==="wbr"||s&&Ht(s.display)&&/^([\d\.]|super|(text-)?top)/.test(s.verticalAlign))return NaN}if(r===o){if(o.localName==="br"){let s=o.ownerDocument.createElement("span");o.parentNode.insertBefore(s,o);let a=t.getElementClientRect(s);if(s.remove(),a){let h=[a];Js(h,n);let l=h[0],u=n?l.left:l.bottom;if(!isNaN(u)&&u!==0)return u}return NaN}if(e.after||!e.inline){if(e.after&&!e.inline&&o.querySelector("ruby")){let a=o.parentNode,h=o.nextSibling;a.removeChild(o),a.insertBefore(o,h)}let s=Tt(t,o,n);if(s.left===0&&s.top===0&&s.right===0&&s.bottom===0)return NaN;if(s.right>=s.left&&s.bottom>=s.top)return e.after?n?s.left:s.bottom:n?s.right:s.top}return NaN}else{let s=NaN,a=r.ownerDocument.createRange(),h=r.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(r,i),a.setEnd(r,i+1);let l=t.getRangeClientRects(a);Js(l,n);let u=l.filter(d=>d.right>d.left&&d.bottom>d.top);if(u.length>0)l=u;else{let d=o?t.getElementComputedStyle(o).whiteSpace:"";l=d==="pre"||d==="pre-wrap"||d==="pre-line"||d==="break-spaces"?l.filter(p=>n?p.right>p.left:p.bottom>p.top):[]}return l.length?(n?s=Math.min.apply(null,l.map(d=>d.left)):s=Math.max.apply(null,l.map(d=>d.bottom)),s):NaN}}function ea(e,t,i){let n=Io(t);n&&rs(t);let r=t.clientLayout.getElementClientRect(e);n&&rl(t);let o=t.getComputedMargin(e);return i?r.width+o.left+o.right:r.height+o.top+o.bottom}function dn(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function rd(e,t){var i;if(e)for(let n=e.lastChild,r=n;n!==t;n=r)r=n.previousSibling,!(n.nodeType===1&&n.hasAttribute("data-vivliostyle-float-box-moved")&&((i=t.style)==null?void 0:i.display)==="inline")&&e.removeChild(n)}var Pn="data-adapt-spec";function ol(e){return!!e.getAttribute(Pn)}function Nt(e){return e?.nodeType!==1?!1:ol(e)?!0:od(e)}function od(e){var t,i;if(e?.nodeType!==1)return!1;let n=e,r=(t=n.style)==null?void 0:t.position;if(r==="absolute"||r==="fixed")return!0;let o=(i=n.style)==null?void 0:i.float;return o==="left"||o==="right"||o==="inline-start"||o==="inline-end"}function xh(e){var t;return e?.nodeType!==1?!1:((t=e.style)==null?void 0:t.position)==="fixed"}function pn(e){let t=e?.viewNode;return t?.nodeType===1&&ol(t)}function xw(e){return e!=="inline"&&(Ht(e)||td(e))}function Sh(e){var t;for(let i=e.parent;i;i=i.parent)if((i.display!=="inline"||i.vertical!==((t=i.parent)==null?void 0:t.vertical))&&Ht(i.display))return i;return null}function Sw(e){let t=e;for(;t;){if(t.nodeType===Node.TEXT_NODE&&t.textContent.length>0)return t;if(t.lastChild)t=t.lastChild;else{for(;t&&!t.previousSibling;)if(t=t.parentNode,t===e||!t)return null;t=t?.previousSibling||null}}return null}function sd(e,t){let i={};return Object.keys(e).forEach(n=>{let r=i[n]={},o=e[n];Object.keys(o).forEach(s=>{r[s]=o[s].map(a=>{let h=t?a.logical:a.physical,l=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function ad(e,t,i,n){let r=n[t];if(!r)throw new Error(`unknown writing-mode: ${t}`);let o=r[i||"ltr"];if(!o)throw new Error(`unknown direction: ${i}`);for(let s of o){let a=e.replace(s.regexp,s.to);if(a!==e)return a}return e}var ld={"horizontal-tb":{ltr:[{logical:"inline-start",physical:"left"},{logical:"inline-end",physical:"right"},{logical:"block-start",physical:"top"},{logical:"block-end",physical:"bottom"},{logical:"inline-size",physical:"width"},{logical:"block-size",physical:"height"}],rtl:[{logical:"inline-start",physical:"right"},{logical:"inline-end",physical:"left"},{logical:"block-start",physical:"top"},{logical:"block-end",physical:"bottom"},{logical:"inline-size",physical:"width"},{logical:"block-size",physical:"height"}]},"vertical-rl":{ltr:[{logical:"inline-start",physical:"top"},{logical:"inline-end",physical:"bottom"},{logical:"block-start",physical:"right"},{logical:"block-end",physical:"left"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}],rtl:[{logical:"inline-start",physical:"bottom"},{logical:"inline-end",physical:"top"},{logical:"block-start",physical:"right"},{logical:"block-end",physical:"left"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}]},"vertical-lr":{ltr:[{logical:"inline-start",physical:"top"},{logical:"inline-end",physical:"bottom"},{logical:"block-start",physical:"left"},{logical:"block-end",physical:"right"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}],rtl:[{logical:"inline-start",physical:"bottom"},{logical:"inline-end",physical:"top"},{logical:"block-start",physical:"left"},{logical:"block-end",physical:"right"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}]}},Cw=sd(ld,!0);function hd(e,t,i){return ad(e,t,i||null,Cw)}var kw=sd(ld,!1);function ud(e,t,i){return ad(e,t,i||null,kw)}var Ew={"horizontal-tb":[{logical:"line-left",physical:"left"},{logical:"line-right",physical:"right"},{logical:"over",physical:"top"},{logical:"under",physical:"bottom"}],"vertical-rl":[{logical:"line-left",physical:"top"},{logical:"line-right",physical:"bottom"},{logical:"over",physical:"right"},{logical:"under",physical:"left"}],"vertical-lr":[{logical:"line-left",physical:"top"},{logical:"line-right",physical:"bottom"},{logical:"over",physical:"right"},{logical:"under",physical:"left"}]};function Pw(e,t){let i=Ew[t];if(!i)throw new Error(`unknown writing-mode: ${t}`);for(let n=0;n<i.length;n++)if(i[n].physical===e)return i[n].logical;return e}function sl(e,t,i){var n;let r=t,o={width:r.style.width,height:r.style.height};function s(p){return e.getElementComputedStyle(t).getPropertyValue(p)}let a=s("writing-mode")!=="horizontal-tb",h=a?"height":"width",l=a?"width":"height";function u(p,f){r.style[p]=f;let g=s(p);return r.style[p]=o[p],g}let d={};for(let p of i){let f;switch(p){case"max-content inline size":f=u(h,"max-content");break;case"min-content inline size":f=u(h,"min-content");break;case"fit-content inline size":f=u(h,"fit-content");break;case"max-content block size":f=u(l,"max-content");break;case"min-content block size":f=u(l,"min-content");break;case"fit-content block size":f=u(l,"fit-content");break;case"max-content width":f=u("width","max-content");break;case"max-content height":f=u("height","max-content");break;case"min-content width":f=u("width","min-content");break;case"min-content height":f=u("height","min-content");break;case"fit-content width":f=u("width","fit-content");break;case"fit-content height":f=u("height","fit-content");break}f==="0px"&&t.childNodes.length===1&&((n=t.firstElementChild)==null?void 0:n.localName)==="img"&&!t.firstElementChild.complete&&(f="1px"),d[p]=parseFloat(f)}return d}function fn(e){var t,i;return((t=e?.style)==null?void 0:t["box-decoration-break"])==="clone"||((i=e?.style)==null?void 0:i["-webkit-box-decoration-break"])==="clone"}function cd(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function dd(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function wt(e,t){let i=cd(e);i.includes(t)||(i.push(t),dd(e,i))}function Nw(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function Tw(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function Ss(e,t){let i=Nw(e);i.includes(t)||(i.push(t),Tw(e,i))}function Iw(e){let t=e.name,i=e.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:i===v.always?v.page:i,important:e.important};default:return e}}var ta={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function qe(e){return!!ta[e]}var Aw={left:!0,right:!0,recto:!0,verso:!0};function Nn(e){return!!Aw[e]}function Ch(e){return qe(e)&&e!=="column"&&e!=="region"}var Fw={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Ao(e){return!!Fw[e]}function tt(e,t){if(e)if(t){if(Nn(t))return t;if(Nn(e))return e;{let i=qe(e),n=qe(t);if(i&&n)switch(t){case"column":return e;case"region":return e==="column"?t:e;default:return t}else return n?t:i?e:Ao(t)?t:Ao(e)?e:t}}else return e;else return t}function kh(e){return qe(e)?e:"auto"}At("SIMPLE_PROPERTY",Iw);var ir=Gf(Xf());function Rw(e,t){return(0,ir.default)(e,t,0)}function Eh(e){return e.reduce((t,i)=>i[0]===ir.default.DELETE?t:t+i[1],"")}function Lw(e,t){return pd(e,t,1)}function Ow(e,t){return pd(e,t,-1)}function pd(e,t,i){let n=0,r=0;return e.some(o=>{for(let s=0;s<o[1].length;s++){switch(o[0]*i){case ir.default.INSERT:n++;break;case ir.default.DELETE:n--,r++;break;case ir.default.EQUAL:r++;break}if(r>t)return!0}return!1}),Math.max(Math.min(t,r-1)+n,0)}var ia;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(ia||(ia={}));var bn;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(bn||(bn={}));var Fo;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Fo||(Fo={}));var zi;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||ki.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||ki.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(zi||(zi={}));var ki;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(ki||(ki={}));var li;(e=>{let t;(n=>(n[n.IGNORE=0]="IGNORE",n[n.NEWLINE=1]="NEWLINE",n[n.PRESERVE=2]="PRESERVE"))(t=e.Whitespace||(e.Whitespace={}));let i;(n=>(n[n.NONE=0]="NONE",n[n.CONTENT=1]="CONTENT",n[n.ROOTLESS=2]="ROOTLESS",n[n.ROOTED=3]="ROOTED"))(i=e.ShadowType||(e.ShadowType={}))})(li||(li={}));var Bw={transform:!0,"transform-origin":!0},Mw={top:!0,bottom:!0,left:!0,right:!0},al=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},_w={show:function(e){e.style.visibility="visible"},hide:function(e){e.style.visibility="hidden"},play:function(e){e.currentTime=0,e.play()},pause:function(e){e.pause()},resume:function(e){e.play()},mute:function(e){e.muted=!0},unmute:function(e){e.muted=!1}};function Dw(e,t){let i=_w[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var na=class Xn extends qa{constructor(t,i){super(),this.container=t,this.bleedBox=i,c(this,"pageAreaElement",null),c(this,"delayedItems",[]),c(this,"hrefHandler"),c(this,"elementsById",{}),c(this,"dimensions",{width:0,height:0}),c(this,"isFirstPage",!1),c(this,"isLastPage",!1),c(this,"isBlankPage",!1),c(this,"isAutoPageWidth",!0),c(this,"isAutoPageHeight",!0),c(this,"spineIndex",0),c(this,"position",null),c(this,"offset",-1),c(this,"side",null),c(this,"fetchers",[]),c(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),c(this,"pageType",null),this.hrefHandler=n=>{let r=n.currentTarget,o=r.getAttribute("href")||r.getAttributeNS("http://www.w3.org/1999/xlink","href");if(o){let s={type:"hyperlink",target:null,currentTarget:null,anchorElement:r,href:o,preventDefault(){n.preventDefault()}};this.dispatchEvent(s)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute(Xn.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Xn.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(Xn.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Xn.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(t,i){let n=this.elementsById[i];n?n.push(t):this.elementsById[i]=[t]}finish(t,i){Object.keys(this.elementsById).forEach(o=>{let s=this.elementsById[o];for(let a=0;a<s.length;)this.container.contains(s[a])?a++:s.splice(a,1);s.length===0&&delete this.elementsById[o]});let n=this.delayedItems;for(let o=0;o<n.length;o++){let s=n[o];s.target===this.container&&s.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||I(s.target,s.name,s.value.toString())}let r=i.getElementClientRect(this.container);this.dimensions.width=r.width,this.dimensions.height=r.height;for(let o=0;o<t.length;o++){let s=t[o],a=this.elementsById[s.ref],h=this.elementsById[s.observer];if(a&&h){let l=Dw(a,s.action);if(l)for(let u=0;u<h.length;u++)h[u].addEventListener(s.event,l,!1)}}}};c(na,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),c(na,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var fd=na,ft=li.Whitespace;function gd(e){switch(e){case"normal":case"nowrap":return ft.IGNORE;case"pre-line":return ft.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return ft.PRESERVE;default:return null}}function Le(e,t){return e?e.nodeType==1?!1:md(e.textContent,t):!0}function md(e,t){switch(t){case ft.PRESERVE:return e.length==0;case ft.NEWLINE:return!!e.match(/^[ \t]*$/);case ft.IGNORE:default:return!!e.match(/^[ \t\r\n\f]*$/)}}var zw=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,c(this,"forcedBreakOffsets",[]),c(this,"formattingContext",null)}},Vw=class{constructor(e,t,i,n,r,o,s,a,h){this.flowName=e,this.element=t,this.startOffset=i,this.priority=n,this.linger=r,this.exclusive=o,this.repeated=s,this.last=a,this.breakBefore=h,c(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function Uw(e,t){return e.top-t.top}function $w(e,t){return t.right-e.right}function wd(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===li.ShadowType.ROOTLESS&&t.shadowType===li.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&ra(e.shadowContext,t.shadowContext)&&ra(e.nodeShadow,t.nodeShadow)&&wd(e.shadowSibling,t.shadowSibling)}function Hi(e,t){if(e===t)return!0;if(!e||!t||e.offsetInNode!==t.offsetInNode||e.after!==t.after||e.steps.length!==t.steps.length)return!1;for(let i=0;i<e.steps.length;i++)if(!wd(e.steps[i],t.steps[i]))return!1;return!0}function Hw(e){return{steps:[{node:e,shadowType:rt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function Ro(e,t){return{steps:[{node:e.sourceNode,shadowType:rt.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:e.formattingContext,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function Lo(e,t){let i=new an(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?Lo(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var rt=li.ShadowType,no=class{constructor(e,t,i,n,r,o,s){this.owner=e,this.root=t,this.xmldoc=i,this.parentShadow=n,this.type=o,this.styler=s,c(this,"subShadow",null),r&&(r.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&ra(this.parentShadow,e.parentShadow):!1}};function ra(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Ww=class{constructor(e,t){this.outer=e,this.count=t}},an=class yd{constructor(t,i,n){this.sourceNode=t,this.parent=i,this.boxOffset=n,c(this,"offsetInNode",0),c(this,"after",!1),c(this,"shadowType"),c(this,"shadowContext"),c(this,"nodeShadow",null),c(this,"shadowSibling",null),c(this,"shared",!1),c(this,"inline",!0),c(this,"overflow",!1),c(this,"breakPenalty"),c(this,"display",null),c(this,"floatReference"),c(this,"floatSide",null),c(this,"clearSide",null),c(this,"floatMinWrapBlock",null),c(this,"columnSpan",null),c(this,"captionSide","top"),c(this,"inlineBorderSpacing",0),c(this,"blockBorderSpacing",0),c(this,"flexContainer",!1),c(this,"whitespace"),c(this,"hyphenateCharacter"),c(this,"breakWord"),c(this,"establishesBFC",!1),c(this,"containingBlockForAbsolute",!1),c(this,"breakBefore",null),c(this,"breakAfter",null),c(this,"viewNode",null),c(this,"clearSpacer",null),c(this,"inheritedProps"),c(this,"vertical"),c(this,"direction"),c(this,"firstPseudo"),c(this,"lang",null),c(this,"preprocessedTextContent",null),c(this,"formattingContext"),c(this,"repeatOnBreak",null),c(this,"pluginProps",{}),c(this,"fragmentIndex",1),c(this,"afterIfContinues",null),c(this,"footnotePolicy",null),c(this,"pageType"),this.shadowType=rt.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=bn.FloatReference.INLINE,this.whitespace=i?i.whitespace:ft.IGNORE,this.hyphenateCharacter=i?i.hyphenateCharacter:null,this.breakWord=i?i.breakWord:!1,this.inheritedProps=i?i.inheritedProps:{},this.vertical=i?i.vertical:!1,this.direction=i?i.direction:"ltr",this.firstPseudo=i?i.firstPseudo:null,this.formattingContext=i?i.formattingContext:null,this.pageType=i?i.pageType:null}resetView(){this.inline=!0,this.breakPenalty=this.parent?this.parent.breakPenalty:0,this.viewNode=null,this.clearSpacer=null,this.offsetInNode=0,this.after=!1,this.display=null,this.floatReference=bn.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:ft.IGNORE,this.hyphenateCharacter=this.parent?this.parent.hyphenateCharacter:null,this.breakWord=this.parent?this.parent.breakWord:!1,this.breakBefore=null,this.breakAfter=null,this.nodeShadow=null,this.establishesBFC=!1,this.containingBlockForAbsolute=!1,this.vertical=this.parent?this.parent.vertical:!1,this.nodeShadow=null,this.preprocessedTextContent=null,this.formattingContext=this.parent?this.parent.formattingContext:null,this.repeatOnBreak=null,this.pluginProps={},this.fragmentIndex=1,this.afterIfContinues=null,this.footnotePolicy=null}cloneItem(){let t=new yd(this.sourceNode,this.parent,this.boxOffset);return t.offsetInNode=this.offsetInNode,t.after=this.after,t.nodeShadow=this.nodeShadow,t.shadowType=this.shadowType,t.shadowContext=this.shadowContext,t.shadowSibling=this.shadowSibling,t.inline=this.inline,t.breakPenalty=this.breakPenalty,t.display=this.display,t.floatReference=this.floatReference,t.floatSide=this.floatSide,t.clearSide=this.clearSide,t.floatMinWrapBlock=this.floatMinWrapBlock,t.columnSpan=this.columnSpan,t.captionSide=this.captionSide,t.inlineBorderSpacing=this.inlineBorderSpacing,t.blockBorderSpacing=this.blockBorderSpacing,t.establishesBFC=this.establishesBFC,t.containingBlockForAbsolute=this.containingBlockForAbsolute,t.flexContainer=this.flexContainer,t.whitespace=this.whitespace,t.hyphenateCharacter=this.hyphenateCharacter,t.breakWord=this.breakWord,t.breakBefore=this.breakBefore,t.breakAfter=this.breakAfter,t.viewNode=this.viewNode,t.clearSpacer=this.clearSpacer,t.firstPseudo=this.firstPseudo,t.vertical=this.vertical,t.overflow=this.overflow,t.preprocessedTextContent=this.preprocessedTextContent,t.formattingContext=this.formattingContext,t.repeatOnBreak=this.repeatOnBreak,t.pluginProps=Object.create(this.pluginProps),t.fragmentIndex=this.fragmentIndex,t.afterIfContinues=this.afterIfContinues,t.footnotePolicy=this.footnotePolicy,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),i=t,n;for(;(n=i.parent)!=null;)n=n.cloneItem(),i.parent=n,i=n;return t}toNodePositionStep(){var t;return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:((t=this.viewNode)==null?void 0:t.parentNode)===null?0:this.fragmentIndex}}toNodePosition(){var t,i,n;let r=this,o=[];r.shadowType===li.ShadowType.ROOTLESS&&(r.floatReference!==bn.FloatReference.INLINE||r.floatSide==="footnote")&&(n=(i=(t=r.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(r=r.parent);do(!r.firstPseudo||!r.parent||r.parent.firstPseudo===r.firstPseudo)&&o.push(r.toNodePositionStep()),r=r.parent;while(r);let s=this.preprocessedTextContent?Ow(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:o,offsetInNode:s,after:this.after,preprocessedTextContent:this.preprocessedTextContent}}isInsideBFC(){let t=this.parent;for(;t;){if(t.establishesBFC)return!0;t=t.parent}return!1}getContainingBlockForAbsolute(){let t=this.parent;for(;t;){if(t.containingBlockForAbsolute)return t;t=t.parent}return null}belongsTo(t){return this.formattingContext===t&&!!this.parent&&this.parent.formattingContext===t}},Ei=class vd{constructor(t){this.primary=t,c(this,"floats",null)}clone(){let t=new vd(this.primary);if(this.floats){t.floats=[];for(let i=0;i<this.floats.length;++i)t.floats[i]=this.floats[i]}return t}isSamePosition(t){if(!t)return!1;if(this===t)return!0;if(!Hi(this.primary,t.primary))return!1;if(this.floats){if(!t.floats||this.floats.length!==t.floats.length)return!1;for(let i=0;i<this.floats.length;i++)if(!Hi(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},Gw=class bd{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new bd(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},jw=class xd{constructor(){c(this,"positions",[]),c(this,"startBreakType",null),c(this,"breakAfter",null)}clone(){let t=new xd,i=this.positions,n=t.positions;for(let r=0;r<i.length;r++)n[r]=i[r].clone();return t.startBreakType=this.startBreakType,t.breakAfter=this.breakAfter,t}isSamePosition(t){if(this===t)return!0;if(!t||this.positions.length!==t.positions.length)return!1;for(let i=0;i<this.positions.length;i++)if(!this.positions[i].isSamePosition(t.positions[i]))return!1;return!0}hasContent(t){return this.positions.length>0&&this.positions[0].flowChunk.startOffset<=t}},Xw=class Sd{constructor(){c(this,"page",0),c(this,"flows",{}),c(this,"flowPositions",{}),c(this,"isBlankPage",!1),c(this,"highestSeenOffset",0),c(this,"highestSeenNode"),c(this,"lookupPositionOffset")}clone(){let t=new Sd;t.page=this.page,t.isBlankPage=this.isBlankPage,t.highestSeenNode=this.highestSeenNode,t.highestSeenOffset=this.highestSeenOffset,t.lookupPositionOffset=this.lookupPositionOffset,t.flows=this.flows;for(let i in this.flowPositions)t.flowPositions[i]=this.flowPositions[i].clone();return t}isSamePosition(t){if(this===t)return!0;if(!t||this.page!==t.page)return!1;let i=Object.keys(this.flowPositions),n=Object.keys(t.flowPositions);if(i.length!==n.length)return!1;for(let r of i)if(!this.flowPositions[r].isSamePosition(t.flowPositions[r]))return!1;return!0}hasContent(t,i){let n=this.flowPositions[t];return n?n.hasContent(i):!1}startSideOfFlow(t){var i;let n=(i=this.flowPositions[t])==null?void 0:i.startBreakType;return n&&Nn(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},Cd=class{constructor(e){this.element=e,c(this,"left",0),c(this,"top",0),c(this,"marginLeft",0),c(this,"marginRight",0),c(this,"marginTop",0),c(this,"marginBottom",0),c(this,"borderLeft",0),c(this,"borderRight",0),c(this,"borderTop",0),c(this,"borderBottom",0),c(this,"paddingLeft",0),c(this,"paddingRight",0),c(this,"paddingTop",0),c(this,"paddingBottom",0),c(this,"width",0),c(this,"height",0),c(this,"originX",0),c(this,"originY",0),c(this,"exclusions",null),c(this,"innerShape",null),c(this,"computedBlockSize",0),c(this,"snapWidth",0),c(this,"snapHeight",0),c(this,"snapOffsetX",0),c(this,"snapOffsetY",0),c(this,"vertical",!1),c(this,"rtl",!1),c(this,"borderBoxSizing",!1)}getInsetTop(){return this.marginTop+(this.borderBoxSizing?0:this.borderTop+this.paddingTop)}getInsetBottom(){return this.marginBottom+(this.borderBoxSizing?0:this.borderBottom+this.paddingBottom)}getInsetLeft(){return this.marginLeft+(this.borderBoxSizing?0:this.borderLeft+this.paddingLeft)}getInsetRight(){return this.marginRight+(this.borderBoxSizing?0:this.borderRight+this.paddingRight)}getInsetBefore(){return this.vertical?this.getInsetRight():this.getInsetTop()}getInsetAfter(){return this.vertical?this.getInsetLeft():this.getInsetBottom()}getInsetStart(){return this.vertical?this.getInsetTop():this.getInsetLeft()}getInsetEnd(){return this.vertical?this.getInsetBottom():this.getInsetRight()}getBeforeEdge(e){return this.vertical?e.right:e.top}getAfterEdge(e){return this.vertical?e.left:e.bottom}getStartEdge(e){return this.vertical?this.rtl?e.bottom:e.top:this.rtl?e.right:e.left}getEndEdge(e){return this.vertical?this.rtl?e.top:e.bottom:this.rtl?e.left:e.right}getInlineSize(e){return this.vertical?e.bottom-e.top:e.right-e.left}getBoxSize(e){return this.vertical?e.right-e.left:e.bottom-e.top}getBoxDir(){return this.vertical?-1:1}getInlineDir(){return this.rtl?-1:1}copyFrom(e){this.element=e.element,this.left=e.left,this.top=e.top,this.marginLeft=e.marginLeft,this.marginRight=e.marginRight,this.marginTop=e.marginTop,this.marginBottom=e.marginBottom,this.borderLeft=e.borderLeft,this.borderRight=e.borderRight,this.borderTop=e.borderTop,this.borderBottom=e.borderBottom,this.paddingLeft=e.paddingLeft,this.paddingRight=e.paddingRight,this.paddingTop=e.paddingTop,this.paddingBottom=e.paddingBottom,this.width=e.width,this.height=e.height,this.originX=e.originX,this.originY=e.originY,this.innerShape=e.innerShape,this.exclusions=e.exclusions,this.computedBlockSize=e.computedBlockSize,this.snapWidth=e.snapWidth,this.snapHeight=e.snapHeight,this.vertical=e.vertical,this.rtl=e.rtl,this.borderBoxSizing=e.borderBoxSizing}setVerticalPosition(e,t){this.top=e,this.height=t,I(this.element,"top",`${e}px`),I(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,I(this.element,"left",`${e}px`),I(this.element,"width",`${t}px`)}setBlockPosition(e,t){if(this.vertical){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getBoxDir(),t)}else this.setVerticalPosition(e,t)}setInlinePosition(e,t){if(this.vertical)if(this.rtl){let i=t+this.marginTop+this.marginBottom+(this.borderBoxSizing?0:this.paddingTop+this.paddingBottom+this.borderTop+this.borderBottom);this.setVerticalPosition(e+i*this.getInlineDir(),t)}else this.setVerticalPosition(e,t);else if(this.rtl){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getInlineDir(),t)}else this.setHorizontalPosition(e,t)}clear(){let e=this.element,t;for(;t=e.lastChild;)e.removeChild(t)}getInnerShape(){let e=this.getInnerRect();return this.innerShape?this.innerShape.withOffset(e.x1,e.y1):tl(e.x1,e.y1,e.x2,e.y2)}getInnerRect(){let e=this.originX+this.left+this.getInsetLeft(),t=this.originY+this.top+this.getInsetTop();return new It(e,t,e+this.width,t+this.height)}getPaddingRect(){let e=this.originX+this.left+this.marginLeft+this.borderLeft,t=this.originY+this.top+this.marginTop+this.borderTop,i=this.paddingLeft+this.width+this.paddingRight,n=this.paddingTop+this.height+this.paddingBottom;return new It(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return Sc(e,i.x1,i.y1,i.x2-i.x1,i.y2-i.y1,t)}getOuterRect(){let e=this.originX+this.left,t=this.originY+this.top,i=this.getInsetLeft()+this.width+this.getInsetRight(),n=this.getInsetTop()+this.height+this.getInsetBottom();return new It(e,t,e+i,t+n)}},gr=class extends ui{constructor(e,t,i,n){super(),this.elem=e,this.context=t,this.rootContentValue=i,this.exprContentListener=n}visitStrInner(e,t){var i;if(!t){if(((i=this.elem.lastChild)==null?void 0:i.nodeType)===3){this.elem.lastChild.textContent+=e;return}t=this.elem.ownerDocument.createTextNode(e)}this.elem.appendChild(t)}visitStr(e){return this.visitStrInner(e.str),null}visitURL(e){if(this.rootContentValue instanceof ut)this.elem.setAttribute("src",e.url);else{let t=this.elem.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","img");t.setAttribute("src",e.url),this.elem.appendChild(t)}return null}visitSpaceList(e){return this.visitValues(e.values),null}visitExpr(e){let t=e.toExpr(),i=t.evaluate(this.context);if(typeof i=="string"){this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof Re&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function kt(e){return e!=null&&e!==Y&&e!==v.normal&&e!==v.none&&!Z(e)}var Te=bn.FloatReference,qw=20;function Yw(e){switch(e){case"inline":return Te.INLINE;case"column":return Te.COLUMN;case"region":return Te.REGION;case"page":return Te.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function Si(e){switch(e){case Te.INLINE:return!1;case Te.COLUMN:case Te.REGION:case Te.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function Cs(e,t,i,n){let r=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=ud(e,r,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let o=hd(e,r,i),s=Pw(o,r);s==="line-left"?e="left":s==="line-right"&&(e="right")}else e==="inside"?e=n==="left"?"right":"left":e==="outside"&&(e=n==="left"?"left":"right");return e!=="left"&&e!=="right"&&(j.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var kd=class{constructor(e,t,i,n,r,o){this.nodePosition=e,this.floatReference=t,this.floatSide=i,this.clearSide=n,this.flowName=r,this.floatMinWrapBlock=o,c(this,"order",null),c(this,"id",null),c(this,"insidePageFloatArea",!1),c(this,"parentPageFloat",null)}getOrder(){if(this.order===null)throw new Error("The page float is not yet added");return this.order}getId(){if(!this.id)throw new Error("The page float is not yet added");return this.id}isAllowedOnContext(e){return e.isAnchorAlreadyAppeared(this.getId())?!0:this.insidePageFloatArea&&this.parentPageFloat?!!e.findPageFloatFragment(this.parentPageFloat):!1}isAllowedToPrecede(e){return!1}},Zw=class{constructor(){c(this,"floats",[]),c(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(e){return`pf${e}`}addPageFloat(e){if(this.floats.findIndex(t=>Hi(t.nodePosition,e.nodePosition))>=0)throw new Error("A page float with the same source node is already registered");{let t=e.order=this.nextOrder();e.id=this.createPageFloatId(t),this.floats.push(e)}}findPageFloatByNodePosition(e){let t=this.floats.findIndex(n=>Hi(n.nodePosition,e));if(t>=0)return this.floats[t];let i=e?.steps;if(i!=null&&i.length){let n=this.floats.findIndex(r=>{let o=r.nodePosition.steps;if(!(o!=null&&o.length)||o.length===i.length||r.nodePosition.offsetInNode!==e.offsetInNode||r.nodePosition.after!==e.after)return!1;let s=Math.min(o.length,i.length);for(let a=0;a<s;a++)if(o[a].node!==i[a].node)return!1;return!0});if(n>=0)return this.floats[n]}return null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},Ed=class{constructor(e,t,i,n,r,o){this.floatReference=e,this.floatSide=t,this.clearSide=i,this.continuations=n,this.area=r,this.continues=o}hasFloat(e){return this.continuations.some(t=>t.float===e)}findNotAllowedFloat(e){for(let t=this.continuations.length-1;t>=0;t--){let i=this.continuations[t].float;if(!i.isAllowedOnContext(e))return i}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let e=this.continuations.map(t=>t.float);return Math.min.apply(null,e.map(t=>t.getOrder()))}shouldBeStashedBefore(e){return this.getOrder()<e.getOrder()}addContinuations(e){e.forEach(t=>{this.continuations.push(t)})}getFlowName(){let e=this.continuations[0].float.flowName;return this.continuations.every(t=>t.float.flowName===e),e}},Ph=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&Hi(this.nodePosition,e.nodePosition):!1}},ln=class{constructor(e,t,i,n,r,o,s){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=r,c(this,"children",[]),c(this,"writingMode"),c(this,"direction"),c(this,"invalidated",!1),c(this,"floatStore"),c(this,"forbiddenFloats",[]),c(this,"floatFragments",[]),c(this,"stashedFloatFragments",[]),c(this,"floatAnchors",{}),c(this,"floatsDeferredToNext",[]),c(this,"floatsDeferredFromPrevious"),c(this,"layoutConstraints",[]),c(this,"locked",!1),c(this,"footnoteMaxBlockSize",null),c(this,"ignoreFootnoteAreaMaxHeight",!1),c(this,"footnoteAnchorsSeen",new Set),c(this,"outerContext",null),e&&e.children.push(this),this.writingMode=!Z(o)&&o||e&&e.writingMode||v.horizontal_tb,this.direction=!Z(s)&&s||e&&e.direction||v.ltr,this.floatStore=e?e.floatStore:new Zw;let a=this.getPreviousSibling();this.floatsDeferredFromPrevious=a?[].concat(a.floatsDeferredToNext):[]}get effectiveParent(){var e;return(e=this.parent)!=null?e:this.outerContext}getParent(e){if(this.parent)return this.parent;if(this.outerContext)return this.outerContext;throw new Error(`No PageFloatLayoutContext for ${e}`)}setOuterContext(e){this.outerContext=e,this.floatStore=e.floatStore}getPreviousSiblingOf(e,t,i,n){let r=this.children.indexOf(e);r<0&&(r=this.children.length);for(let o=r-1;o>=0;o--){let s=this.children[o];if(s.floatReference===t&&s.flowName===i&&Hi(s.generatingNodePosition,n)||(s=s.getPreviousSiblingOf(null,t,i,n),s))return s}return null}getPreviousSibling(){let e=this,t=this.parent,i;for(;t;){if(i=t.getPreviousSiblingOf(e,this.floatReference,this.flowName,this.generatingNodePosition),i)return i;e=t,t=t.parent}return null}getContainer(e){return!e||e===this.floatReference?this.container:this.getParent(e).getContainer(e)}setContainer(e){this.container=e,this.reattachFloatFragments()}addPageFloat(e){this.floatStore.addPageFloat(e)}getPageFloatLayoutContext(e){return e===this.floatReference?this:this.getParent(e).getPageFloatLayoutContext(e)}findPageFloatByNodePosition(e){return this.floatStore.findPageFloatByNodePosition(e)}forbid(e){let t=e.getId(),i=e.floatReference;i===this.floatReference?this.forbiddenFloats.includes(t)||(this.forbiddenFloats.push(t),new Tn().findByFloat(e).forbid(e,this)):this.getParent(i).forbid(e)}isForbidden(e){let t=e.getId(),i=e.floatReference;return i===this.floatReference?this.forbiddenFloats.includes(t):this.getParent(i).isForbidden(e)}addPageFloatFragment(e,t){let i=e.floatReference;i!==this.floatReference?this.getParent(i).addPageFloatFragment(e,t):this.floatFragments.includes(e)||(this.floatFragments.push(e),this.floatFragments.sort((n,r)=>n.getOrder()-r.getOrder())),t||this.invalidate()}removePageFloatFragment(e,t){let i=e.floatReference;if(i!==this.floatReference)this.getParent(i).removePageFloatFragment(e,t);else{let n=this.floatFragments.indexOf(e);if(n>=0){let r=this.floatFragments.splice(n,1)[0],o=r.area&&r.area.element;o&&o.parentNode&&o.parentNode.removeChild(o),t||this.invalidate()}}}findPageFloatFragment(e){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).findPageFloatFragment(e);let t=this.floatFragments.findIndex(i=>i.hasFloat(e));return t>=0?this.floatFragments[t]:null}hasFloatFragments(e){return this.floatFragments.length>0&&(!e||this.floatFragments.some(e))?!0:this.parent?this.parent.hasFloatFragments(e):!1}hasContinuingFloatFragmentsInFlow(e){return this.hasFloatFragments(t=>t.continues&&t.getFlowName()===e&&t.floatSide!=="block-end")}markPageFloatAnchorSeen(e){var t;if(!("footnotePolicy"in e))return;let i=this;for(;i;)i.footnoteAnchorsSeen.add(e.getId()),i=(t=i.parent)!=null?t:i.outerContext}registerPageFloatAnchor(e,t){this.floatAnchors[e.getId()]=t,this.markPageFloatAnchorSeen(e)}collectPageFloatAnchors(){let e=Object.assign({},this.floatAnchors);return this.children.reduce((t,i)=>Object.assign(t,i.collectPageFloatAnchors()),e)}isAnchorAlreadyAppeared(e){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===e))return!0;let t=this.collectPageFloatAnchors()[e];return t&&this.container&&this.container.element?this.container.element.contains(t):!1}deferPageFloat(e){let t=e.float;if(t.floatReference===this.floatReference){let i=this.floatsDeferredToNext.findIndex(n=>n.float===t);i>=0?this.floatsDeferredToNext.splice(i,1,e):this.floatsDeferredToNext.push(e)}else this.getParent(t.floatReference).deferPageFloat(e)}removeFloatDeferredToNext(e){let t=this.floatsDeferredToNext.findIndex(i=>i.float===e);t>=0&&this.floatsDeferredToNext.splice(t,1)}hasPrecedingFloatsDeferredToNext(e,t){if(!t&&e.floatReference!==this.floatReference)return this.getParent(e.floatReference).hasPrecedingFloatsDeferredToNext(e,!1);let i=e.getOrder();return this.floatsDeferredToNext.some(n=>n.float.getOrder()<i&&!e.isAllowedToPrecede(n.float))?!0:this.parent?this.parent.hasPrecedingFloatsDeferredToNext(e,!0):!1}getLastFollowingFloatInFragments(e){let t=e.getOrder(),i=null;if(this.floatFragments.forEach(n=>{n.continuations.forEach(r=>{let o=r.float,s=o.getOrder();s>t&&(!i||s>i.getOrder())&&(i=o)})}),this.parent){let n=this.parent.getLastFollowingFloatInFragments(e);n&&(!i||n.getOrder()>i.getOrder())&&(i=n)}return i}getDeferredPageFloatContinuations(e){e=e||this.flowName;let t=this.floatsDeferredFromPrevious.filter(i=>!e||i.float.flowName===e);return this.parent&&(t=this.parent.getDeferredPageFloatContinuations(e).concat(t)),t.sort((i,n)=>i.float.getOrder()-n.float.getOrder())}getPageFloatContinuationsDeferredToNext(e){e=e||this.flowName;let t=this.floatsDeferredToNext.filter(i=>!e||i.float.flowName===e);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(e).concat(t):t}getFloatsDeferredToNextInChildContexts(){let e=[],t=[];for(let i=this.children.length-1;i>=0;i--){let n=this.children[i];t.includes(n.flowName)||(t.push(n.flowName),e=e.concat(n.floatsDeferredToNext.map(r=>r.float)),e=e.concat(n.getFloatsDeferredToNextInChildContexts()))}return e}hasRootMultiColumnFootnoteContext(){return this.children.some(e=>{let t=0;for(let i of e.children)if(!i.generatingNodePosition&&(t+=1,t>1))return!0;return!1})}hasNonRootMultiColumnFootnoteContext(){return this.children.some(e=>e.children.some(t=>{var i;let n=(i=t.getContainer())==null?void 0:i.element;return n!=null&&yw(n)}))}hasMultiColumnFootnoteContext(){return this.hasRootMultiColumnFootnoteContext()||this.hasNonRootMultiColumnFootnoteContext()}trySetFootnoteRetryMaxBlockSize(e){let t=this.footnoteMaxBlockSize!=null?this.footnoteMaxBlockSize/2:e/2;return t<qw?!1:(this.footnoteMaxBlockSize=t,!0)}initFootnoteRetryFromEmptyFragment(e,t){if(!("footnotePolicy"in e&&this.footnoteMaxBlockSize==null&&this.footnoteAnchorsSeen.has(e.getId())&&this.hasMultiColumnFootnoteContext()))return!1;let i=(t.vertical?t.width:t.height)+t.getInsetBefore()+t.getInsetAfter();return this.trySetFootnoteRetryMaxBlockSize(i)}checkAndForbidNotAllowedFloat(){if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let e=this.floatFragments.length-1;e>=0;e--){let t=this.floatFragments[e],i=t.findNotAllowedFloat(this);if(i){let n=t.area&&"isFootnote"in t.area&&t.area.isFootnote;if(this.locked)this.invalidate();else{if(n&&this.footnoteAnchorsSeen.has(i.getId())&&this.hasMultiColumnFootnoteContext()){let r=t.area.computedBlockSize+t.area.getInsetBefore()+t.area.getInsetAfter();if(this.trySetFootnoteRetryMaxBlockSize(r))return this.removePageFloatFragment(t),this.removeEndFloatFragments(t.floatSide),!0}this.removePageFloatFragment(t),this.forbid(i),this.removeEndFloatFragments(t.floatSide)}return!0}}return this.floatReference===Te.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(r=>r.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(r=>!i.isAllowedToPrecede(r)&&n>r.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let r=this.findPageFloatFragment(i);this.removePageFloatFragment(r)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let e=this.floatsDeferredToNext.length-1;e>=0;e--){let t=this.floatsDeferredToNext[e].float,i=this.findPageFloatFragment(t);if(this.floatReference===Te.PAGE&&"footnotePolicy"in t&&t.footnotePolicy===v.line&&this.footnoteAnchorsSeen.has(t.getId())&&!i){if(this.locked){this.invalidate();return}this.removeFloatDeferredToNext(t),this.forbid(t),this.invalidate();return}}for(let e=this.floatsDeferredToNext.length-1;e>=0;e--)if(!this.floatsDeferredToNext[e].float.isAllowedOnContext(this)){if(this.locked){this.invalidate();return}this.floatsDeferredToNext.splice(e,1)}this.floatsDeferredFromPrevious.forEach(e=>{this.floatsDeferredToNext.findIndex(t=>e.equals(t))>=0||this.floatFragments.some(t=>t.hasFloat(e.float))||this.floatsDeferredToNext.push(e)})}}hasSameContainerAs(e){return!!this.container&&!!e.container&&this.container.element===e.container.element}invalidate(){this.invalidated=!0,!this.locked&&(this.container&&(this.children.forEach(e=>{this.hasSameContainerAs(e)&&e.floatFragments.forEach(t=>{let i=t.area.element;i&&i.parentNode&&i.parentNode.removeChild(i)})}),this.container.clear()),this.children.forEach(e=>{e.layoutConstraints.splice(0)}),this.children.splice(0),Object.keys(this.floatAnchors).forEach(e=>{delete this.floatAnchors[e]}))}detachChildren(){let e=this.children.splice(0);return e.forEach(t=>{t.floatFragments.forEach(i=>{let n=i.area.element;n&&n.parentNode&&n.parentNode.removeChild(n)})}),e}attachChildren(e){e.forEach(t=>{this.children.push(t),t.reattachFloatFragments()})}isInvalidated(){return this.invalidated||!!this.parent&&this.parent.isInvalidated()}validate(){this.invalidated=!1}toLogical(e){let t=this.writingMode.toString(),i=this.direction.toString();if(e==="inside"||e==="outside"){let n=!!this.container.element.closest("[data-vivliostyle-page-side='left']");e=e==="inside"?n?"right":"left":n?"left":"right"}return ud(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return hd(e,t,i)}toLogicalFloatSides(e){let t=e.split(" "),i=[];for(let s of t){let a=this.toLogical(s);i.includes(a)||i.push(a)}let n=[],r=!1,o=!1;for(let s=0;s<i.length;s++){let a=i[s];a.includes("block")?r||(i.slice(s+1).some(h=>h.includes("block"))?(n.push("snap-block"),r=!0):n.push(a)):a.includes("inline")&&(o||(i.slice(s+1).some(h=>h.includes("inline"))?(n.push("snap-inline"),o=!0):n.push(a)))}return n}removeEndFloatFragments(e){let t=this.toLogicalFloatSides(e)[0];if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogicalFloatSides(n.floatSide)[0]===t?this.removePageFloatFragment(n):i++}}}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogicalFloatSides(e.floatSide)[0];if(i==="block-end"||i==="snap-block"||i==="inline-end"||i==="snap-inline"){let n=0;for(;n<this.floatFragments.length;){let r=this.floatFragments[n],o=this.toLogicalFloatSides(r.floatSide)[0];(o===i||i==="snap-block"&&o==="block-end"||i==="snap-inline"&&o==="inline-end")&&r.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(r),this.floatFragments.splice(n,1)):n++}}}restoreStashedFragments(e){if(e!==this.floatReference){this.getParent(e).restoreStashedFragments(e);return}this.stashedFloatFragments.forEach(t=>{this.addPageFloatFragment(t,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(e){if(e!==this.floatReference){this.getParent(e).discardStashedFragments(e);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(e){return e===this.floatReference?this.stashedFloatFragments.concat().sort((t,i)=>i.getOrder()-t.getOrder()):this.getParent(e).getStashedFloatFragments(e)}getLimitValue(e,t,i,n,r,o=!0){this.container;let s=this.toLogical(e),a=this.toPhysical(e),h=t&&this.toLogical(t),l=t&&this.toPhysical(t),u=this.getLimitValueInner(s,h,i,n,r);if(o&&this.parent&&this.parent.container){let d=this.parent.getLimitValue(a,l,i,n,r,o);switch(a){case"top":return Math.max(u,d);case"left":return Math.max(u,d);case"bottom":return Math.min(u,d);case"right":return Math.min(u,d);default:}}return u}getLimitValueInner(e,t,i,n,r){this.container;let o=this.getLimitValuesInner(i,n,r,e,t);switch(e){case"block-start":return this.container.vertical?o.right:o.top;case"block-end":return this.container.vertical?o.left:o.bottom;case"inline-start":return this.container.vertical?this.container.rtl?o.bottom:o.top:this.container.rtl?o.right:o.left;case"inline-end":return this.container.vertical?this.container.rtl?o.top:o.bottom:this.container.rtl?o.left:o.right;default:throw new Error(`Unknown logical side: ${e}`)}}getLimitValuesInner(e,t,i,n,r){var o,s,a,h;this.container;let l=this.container.originX,u=this.container.originY,d=this.container.getPaddingRect(),p={top:d.y1-u,left:d.x1-l,bottom:d.y2-u,right:d.x2-l,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};if(this.container.vertical){let m=parseFloat((s=(o=this.container.element)==null?void 0:o.style)==null?void 0:s.width);isFinite(m)&&m>this.container.width&&(p.right+=m-this.container.width)}else{let m=parseFloat((h=(a=this.container.element)==null?void 0:a.style)==null?void 0:h.height);isFinite(m)&&m>this.container.height&&(p.bottom+=m-this.container.height)}function f(m,w,x){return m.unit==="%"?x*m.num/100:e.convertLengthToPx(m,w,t)}let g=this.floatFragments;return g.length>0&&(p=g.reduce((m,w)=>{if(i&&!i(w,this))return m;let[x,y]=this.toLogicalFloatSides(w.floatSide);if(y&&(n&&y.includes("block")===n.includes("block")&&y!==n||r&&y.includes("block")===r.includes("block")&&y!==r))return m;let b=w.area,S=w.continuations[0].float.floatMinWrapBlock,C=b.vertical?b.left+b.getInsetLeft()+b.width+b.getInsetRight():b.top+b.getInsetTop()+b.height+b.getInsetBottom(),N=b.vertical?b.top+b.getInsetTop()+b.height+b.getInsetBottom():b.left+b.getInsetLeft()+b.width+b.getInsetRight(),F=m.top,B=m.left,U=m.bottom,q=m.right,he=m.floatMinWrapBlockStart,ae=m.floatMinWrapBlockEnd;switch(x){case"inline-start":b.vertical?F=Math.max(F,N):B=Math.max(B,N);break;case"block-start":b.vertical?(S&&b.left<q&&(he=f(S,b.rootViewNodes[0],d.x2-d.x1)),q=Math.min(q,b.left)):(S&&C>F&&(he=f(S,b.rootViewNodes[0],d.y2-d.y1)),F=Math.max(F,C));break;case"inline-end":b.vertical?U=Math.min(U,b.top):q=Math.min(q,b.left);break;case"block-end":b.vertical?(S&&C>B&&(ae=f(S,b.rootViewNodes[0],d.x2-d.x1)),B=Math.max(B,C)):(S&&b.top<U&&(ae=f(S,b.rootViewNodes[0],d.y2-d.y1)),U=Math.min(U,b.top));break;default:throw new Error(`Unknown logical float side: ${x}`)}return{top:F,left:B,bottom:U,right:q,floatMinWrapBlockStart:he,floatMinWrapBlockEnd:ae}},p)),p.left+=l,p.right+=l,p.top+=u,p.bottom+=u,p}setFloatAreaDimensions(e,t,i,n,r,o,s){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,r,o,s);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!s["block-start"]&&!s["block-end"])return null}else if(a[0].includes("block")&&!s[a[0]])return null;e.clientLayout;let h=a.find(C=>C.includes("inline")&&s[C==="inline-start"?"inline-end":"inline-start"]),l=a.find(C=>C.includes("block")),u=this.getLimitValue("block-start",h,e.layoutContext,e.clientLayout),d=this.getLimitValue("block-end",h,e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-start",l,e.layoutContext,e.clientLayout),f=this.getLimitValue("inline-end",l,e.layoutContext,e.clientLayout),g=e.vertical?e.originX:e.originY,m=e.vertical?e.originY:e.originX;e.isFootnote||(u=e.vertical?Math.min(u,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+g):Math.max(u,e.top+g),d=e.vertical?Math.max(d,e.left+g):Math.min(d,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+g));function w(C,N){let F=C(e.bands,N);return F?(e.vertical&&(F=vc(F)),u=e.vertical?Math.min(u,F.x2):Math.max(u,F.y1),d=e.vertical?Math.max(d,F.x1):Math.min(d,F.y2),!0):o}let x,y,b,S;if(r){let C=e.vertical?Po(new It(d,p,u,f)):new It(p,u,f,d);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!w(Vg,C)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(Ug,C)||(e.isFootnote&&n!==null&&isFinite(n)&&a[0]==="block-end"&&(e.vertical?u=Math.min(u,n):u=Math.max(u,n)),b=(d-u)*e.getBoxDir(),e.isFootnote&&this.footnoteMaxBlockSize!=null&&(b=Math.min(b,this.footnoteMaxBlockSize),e.vertical?u=d+b:u=d-b),x=Math.max(0,b-e.getInsetBefore()-e.getInsetAfter()),S=(f-p)*e.getInlineDir(),y=S-e.getInsetStart()-e.getInsetEnd(),!o&&(x<=0||y<=0)))return null}else{let C=e.getContentBlockMarginAfter();x=Math.max(0,e.computedBlockSize+Math.min(0,C)),b=x+e.getInsetBefore()+e.getInsetAfter();let N=(d-u)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let B=this.container.getPaddingRect(),U=this.container.getBoxDir()*(n-(this.container.vertical?B.x2:B.y1)),q=this.container.getBoxDir()*((this.container.vertical?B.x1:B.y2)-n-b);U<=q?a[0]="block-start":a[0]="block-end"}if(!s[a[0]])if(s["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(s["inline-start"])a[0]="inline-start";else if(s["inline-end"])a[0]="inline-end";else return null;if(!o&&N<b)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?y=sl(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?y=e.getContentInlineSize():y=e.vertical?e.height:e.width,S=y+e.getInsetStart()+e.getInsetEnd();let F=(f-p)*e.getInlineDir();if(!o&&F<S)return null}return u-=g,d-=g,p-=m,f-=m,a.some(C=>C==="inline-start"||C==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(p,y):(a.some(C=>C==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-S*e.getInlineDir(),y),a.some(C=>C==="block-start"||C==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(u,x):(a.some(C=>C==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(d-b*e.getBoxDir(),x),a.join(" ")}getFloatFragmentExclusions(){let e=this.floatFragments.map(t=>t.getOuterShape());return this.parent?this.parent.getFloatFragmentExclusions().concat(e):e}reattachFloatFragments(){let e=this.container.element&&this.container.element.parentNode;e&&this.floatFragments.forEach(t=>{e.appendChild(t.area.element)})}getMaxReachedAfterEdge(){let e=this.getContainer().vertical;return this.floatFragments.reduce((t,i)=>{let n=i.getOuterRect();return e?Math.min(t,n.x1):Math.max(t,n.y2)},e?1/0:0)}getBlockEndEdgeOfBlockStartFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(o=>o.floatSide.includes("block-start")).filter(o=>{if(!isFinite(e))return!0;let s=o.getOuterRect();return n?s.y1<=e&&e<=s.y2:s.x1<=e&&e<=s.x2}).forEach(o=>{let s=o.getOuterRect(),a=n?s.x1:s.y2;r=isFinite(r)?n?Math.min(r,a):Math.max(r,a):a}),this.parent){let o=this.parent.getBlockEndEdgeOfBlockStartFloats(e);isFinite(o)&&(r=isFinite(r)?n?Math.min(r,o):Math.max(r,o):o)}return r}getBlockStartEdgeOfBlockEndFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(o=>o.floatSide.includes("block-end")).filter(o=>{if(!isFinite(e))return!0;let s=o.getOuterRect();return n?s.y1<=e&&e<=s.y2:s.x1<=e&&e<=s.x2}).forEach(o=>{let s=o.getOuterRect(),a=n?s.x2:s.y1;r=isFinite(r)?n?Math.max(r,a):Math.min(r,a):a}),this.parent){let o=this.parent.getBlockStartEdgeOfBlockEndFloats(e);isFinite(o)&&(r=isFinite(r)?n?Math.max(r,o):Math.min(r,o):o)}return r}getPageFloatClearEdge(e,t){function i(l){return u=>l.isAnchorAlreadyAppeared(u.float.getId())}function n(l,u){return e==="inline-start"&&(l.floatSide.includes("inline-end")||l.floatSide==="block-end")||e==="inline-end"&&(l.floatSide.includes("inline-start")||l.floatSide==="block-start")?!1:l.continuations.some(i(u))}let r=t.getPaddingRect(),o=t.vertical?r.x1:r.y2,s=this;for(;s;){if(s.floatsDeferredToNext.some(i(s)))return o;s=s.parent}function a(l){return l.floatFragments.some(u=>n(u,l))||l.children.some(u=>a(u))}if(e==="column"||e==="region"||e==="page"){for(s=this;s;s=s.parent)if(s.floatReference===e){if(a(s))return o;break}}t.clientLayout;let h=this.getLimitValue("block-start",null,t.layoutContext,t.clientLayout,n);return this.getLimitValue("block-end",null,t.layoutContext,t.clientLayout,n)*t.getBoxDir()<o*t.getBoxDir()?o:h}getPageFloatPlacementCondition(e,t,i){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).getPageFloatPlacementCondition(e,t,i);let n={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!i)return n;let r=this.toLogicalFloatSides(t)[0],o=this.toLogical(i),s;o==="all"?s=["block-start","block-end","inline-start","inline-end"]:o==="both"?s=["inline-start","inline-end"]:o==="same"?r==="snap-block"?s=["block-start","block-end"]:s=[r]:s=[o];let a=e.getOrder();function h(d){return p=>(!d||p.floatSide.includes(d))&&p.getOrder()<a}function l(d,p){return d.children.some(f=>f.floatFragments.some(h(p))||l(f,p))}function u(d,p){let f=d.parent;return!!f&&(f.floatFragments.some(h(p))||u(f,p))}if(i==="column"||i==="region"||i==="page"){for(let d=this;d;d=d.parent)if(d.floatReference===i){(d.floatFragments.some(h(null))||l(d,null))&&(n["block-start"]=!1,n["block-end"]=!1,n["inline-start"]=!1,n["inline-end"]=!1);break}return n}return s.forEach(d=>{switch(d){case"block-start":n[d]=!l(this,d);break;case"block-end":n[d]=!u(this,d);break;case"inline-start":case"inline-end":n[d]=!this.floatFragments.some(h(d));break;default:throw new Error(`Unexpected side: ${d}`)}}),n}getLayoutConstraints(){return(this.parent?this.parent.getLayoutConstraints():[]).concat(this.layoutConstraints)}addLayoutConstraint(e,t){t===this.floatReference?this.layoutConstraints.push(e):this.getParent(t).addLayoutConstraint(e,t)}isColumnFullWithPageFloats(e){let t=e.layoutContext,i=e.clientLayout,n=this,r=null;for(;n&&n.container;){let s=n.getLimitValuesInner(t,i);r?e.vertical?(s.right<r.right&&(r.right=s.right,r.floatMinWrapBlockStart=s.floatMinWrapBlockStart),s.left>r.left&&(r.left=s.left,r.floatMinWrapBlockEnd=s.floatMinWrapBlockEnd)):(s.top>r.top&&(r.top=s.top,r.floatMinWrapBlockStart=s.floatMinWrapBlockStart),s.bottom<r.bottom&&(r.bottom=s.bottom,r.floatMinWrapBlockEnd=s.floatMinWrapBlockEnd)):r=s,n=n.parent}let o=Math.max(r.floatMinWrapBlockStart,r.floatMinWrapBlockEnd);return(e.vertical?r.right-r.left:r.bottom-r.top)<=o}getMaxBlockSizeOfPageFloats(){let e=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(t=>{let i=t.area;return e?i.width:i.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},Vn=[],Tn=class{static register(e){Vn.push(e)}findByNodeContext(e){for(let t=Vn.length-1;t>=0;t--){let i=Vn[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=Vn.length-1;t>=0;t--){let i=Vn[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},Kw=class{appliesToNodeContext(e){return Si(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let r=e.floatSide,o=e.toNodePosition(),s=!!t.generatingNodePosition;return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(a=>{n=a,t.flowName;let h=new kd(o,n,r,e.clearSide,t.flowName,e.floatMinWrapBlock);if(h.insidePageFloatArea=s,s){let l=t.generatingNodePosition;l&&(h.parentPageFloat=t.findPageFloatByNodePosition(l))}return t.addPageFloat(h),T(h)})}createPageFloatFragment(e,t,i,n,r){let o=e[0].float;return new Ed(o.floatReference,t,i,e,n,r)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){return T(void 0)}forbid(e,t){}};Tn.register(new Kw);var Pd="data-vivliostyle-footnote-first-ref",Nd="data-vivliostyle-footnote-referenced";function Oo(e,t){return!!(e&&e.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function bt(e){if(e.localName!=="aside")return!1;if(Oo(e.getAttribute("role"),"doc-footnote"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return Oo(t,"footnote")}function _t(e){if(e.localName!=="a")return!1;if(Oo(e.getAttribute("role"),"doc-noteref"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return Oo(t,"noteref")}function ll(e,t){if(!_t(e))return null;let i=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!i)return null;let n=ko(i,t);return n==="#"?null:n}function Td(e,t,i){let n=ll(e,t);if(!n)return null;let r=i(n);return r&&bt(r)?r:null}function Jw(e,t,i,n,r){if(r.value)return;let o=e.getElementsByTagName("a");for(let s=0;s<o.length;s++){let a=o.item(s),h=ll(a,t);!h||n.has(h)||n.set(h,i(a))}r.value=!0}function Nh(e,t,i,n,r){if(e.localName!=="a"||!_t(e))return!0;let o=ll(e,t);if(!o)return!0;Jw(e.ownerDocument,t,i,n,r);let s=n.get(o);return s==null||i(e)===s}function hl(e,t){let i=t.getProp(e,"footnote-display");if(i)return i;let n=t.getProp(e,"display");return n?.value===v.inline?t.createCascadeValue(v.inline,n.priority):null}function Qw(e,t,i,n,r,o,s){if(e.namespaceURI!=="http://www.pyroxy.com/ns/shadow"||e.localName!=="include"||!e.classList.contains("-vivliostyle-footnote-content"))return t;let a=i?.owner;if(!(a instanceof Element)||!_t(a))return t;let h=Td(a,n,r);if(!h)return t;let l=a.getAttribute(o);l?(e.setAttribute(o,l),h.setAttribute(o,l)):(e.removeAttribute(o),h.removeAttribute(o));let u=s.getStyle(h);if(!u)return t;let d={...t},p=hl(u,s),f=s.getProp(u,"footnote-policy"),g=s.getStyleMap(u,"_pseudos"),m=g?.after;if(p&&(d["footnote-display"]=p),f&&(d["footnote-policy"]=f),m){let w=s.getMutableStyleMap(d,"_pseudos");w.after={...m}}return d}function ey(e,t,i,n,r){var o;if(!(i?.type===rt.ROOTED&&bt(e)))return t;let s=r.getStyle(e);if(!s)return t;let a={...t},h=hl(s,r),l=r.getProp(s,"footnote-policy"),u=r.getStyleMap(s,"_pseudos"),d=u?.["footnote-marker"],p=r.getProp(d,"content"),f=r.getProp(d,"list-style-position");if(h&&(a["footnote-display"]=h),l&&(a["footnote-policy"]=l),p&&((o=f?.evaluate)==null?void 0:o.call(f,n,"list-style-position"))===v.outside){let g=r.filterFootnoteMarkerContent(p,e);a["--viv-marker-content"]=r.createCascadeValue(g,0),a.display=r.createCascadeValue(M("list-item"),0),a["list-style-position"]=r.createCascadeValue(v.outside,0),a["list-style-type"]=r.createCascadeValue(v.none,0),a["list-style-image"]=r.createCascadeValue(v.none,0)}return a}function ty(e,t,i){var n,r;let o=t?.type===rt.ROOTED&&bt(e)?i.getStyle(e):null;return{sourceStyle:o,footnoteDisplay:((n=hl(o,i))==null?void 0:n.value)||null,footnotePolicy:((r=i.getProp(o,"footnote-policy"))==null?void 0:r.value)||null}}function Id(e,t){if(e instanceof G){let i=e.expr.evaluate(t);return typeof i=="string"?new X(i):typeof i=="number"?new X(String(i)):e}return e instanceof J?new J(e.values.map(i=>Id(i,t))):e}function iy(e,t,i){let n=e?.["_footnote-marker-content"];n&&(t["--viv-marker-content"]=Id(n.value,i))}function ny(e){let t=e.getElementsByTagName("a"),i=new Set;for(let n=0;n<t.length;n++){let r=t.item(n);if(!_t(r)||!(r instanceof HTMLAnchorElement)||!r.hash||r.href!==r.baseURI.replace(/#.*$/,"")+r.hash)continue;let o=r.hash.substring(1),s=e.getElementById(o);if(s&&bt(s)){let a=r.baseURI.replace(/#.*$/,"")+r.hash;i.has(a)||(i.add(a),r.setAttribute(Pd,"true")),s.setAttribute(Nd,"true")}}}At("PREPROCESS_SINGLE_DOCUMENT",ny);var ry=Ed,Bo=class Ad extends kd{constructor(t,i,n,r,o,s){super(t,i,"block-end",null,n,o),this.footnotePolicy=r,this.policyAnchorNode=s}isAllowedToPrecede(t){return!(t instanceof Ad)}};function oy(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;for(;t;){if(/^(p|li|dd|dt|td|th|blockquote)$/i.test(t.localName)&&!t.querySelector("br"))return t;t=t.parentElement}return e}var Th=class extends ry{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof Bo?!0:this.getOrder()<e.getOrder()}},sy=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.shadowContext?e.shadowContext.owner:e.sourceNode;for(;t;){if(t===this.footnote.policyAnchorNode)return!1;t=t.parentNode}return!0}},ay=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof Bo}createPageFloat(e,t,i){var n;let r=Te.REGION,o=t.getPageFloatLayoutContext(r);t.getPageFloatLayoutContext(Te.PAGE).hasSameContainerAs(o)&&(r=Te.PAGE);let s=!!t.generatingNodePosition;s&&r!==Te.PAGE&&(r=Te.PAGE);let a=e.toNodePosition();t.flowName;let h=e.sourceNode,l=(n=e.shadowContext)==null?void 0:n.owner;l instanceof Element&&_t(l)&&(h=l),h=oy(h);let u=new Bo(a,r,t.flowName,e.footnotePolicy,e.floatMinWrapBlock,h);if(u.insidePageFloatArea=s,s){let d=t.generatingNodePosition;d&&(u.parentPageFloat=t.findPageFloatByNodePosition(d))}return t.addPageFloat(u),T(u)}createPageFloatFragment(e,t,i,n,r){let o=e[0].float;return new Th(o.floatReference,e,n,r)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof Th);return i.length<=1,i[0]||null}adjustPageFloatArea(e,t,i){e.isFootnote=!0,e.adjustContentRelativeSize=!1;let n=e.element;return i.layoutContext.applyFootnoteStyle(t.vertical,i.layoutContext.nodeContext&&i.layoutContext.nodeContext.direction==="rtl",n).thenAsync(r=>{var o,s;if(e.vertical=r,e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e),((o=i.clientLayout.getElementComputedStyle(n))==null?void 0:o.boxSizing)==="border-box"){let h=e.vertical?e.paddingLeft+e.paddingRight+e.borderLeft+e.borderRight:e.paddingTop+e.paddingBottom+e.borderTop+e.borderBottom,l=e.vertical?["max-width","min-width","width"]:["max-height","min-height","height"],u=getComputedStyle(n);for(let d of l){let p=u.getPropertyValue(d);if(p&&p!=="none"){let f=parseFloat(p);isNaN(f)||I(n,d,`${Math.max(0,f-h)}px`)}}I(n,"box-sizing","content-box")}let a=i.pageFloatLayoutContext;for(;a;){if(a.ignoreFootnoteAreaMaxHeight){I(n,"max-block-size",""),I(n,e.vertical?"max-width":"max-height","");break}a=(s=a.parent)!=null?s:null}return T(void 0)})}forbid(e,t){let i=e;switch(i.footnotePolicy){case v.line:{let n=new sy(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Tn.register(new ay);var ul=class{calculateOffset(e){return xn(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function xn(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var Or=class extends ul{constructor(e,t,i,n){super(),this.position=e,this.breakOnEdge=t,this.overflows=i,this.computedBlockSize=n,c(this,"overflowIfRepetitiveElementsDropped"),c(this,"isEdgeUpdated",!1),c(this,"edge",0),this.overflowIfRepetitiveElementsDropped=i}findAcceptableBreak(e,t){return this.updateOverflows(e),t<this.getMinBreakPenalty()?null:e.findEdgeBreakPosition(this)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");let e=this.isFirstContentOfRepetitiveElementsOwner()&&!this.overflowIfRepetitiveElementsDropped;return(Ao(this.breakOnEdge)?1:0)+(this.overflows&&!e?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}updateEdge(e){var t;let i=e.calculateClonedPaddingBorder(this.position);if(this.edge=sn(this.position,e.clientLayout,0,e.vertical)+i,!this.position.after&&!this.position.inline){let n=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*n}else if(this.position.after&&((t=this.position.shadowContext)==null?void 0:t.root.id)==="table-cell"){let n=e.element.parentElement,r=n?.closest("table, [style*='display: table;']");if(r){let o=r.style.borderCollapse==="collapse",s=0,a=0;for(let h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===r&&!o)&&(s+=e.parseComputedLength(l.paddingBlockEnd)),h===r&&!o&&(s+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),o?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===r)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===r)break}this.edge+=(e.vertical?-1:1)*(s+a)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let t=this.edge,i=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(t+(e.vertical?-1:1)*i.minimum),this.overflows=this.position.overflow=e.isOverflown(t+(e.vertical?-1:1)*i.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:t}=e.parent;if(!zi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},Un=class{find(e){let t=Dt("RESOLVE_LAYOUT_PROCESSOR");for(let i=0;i<t.length;i++){let n=t[i](e);if(n)return n}throw new Error(`No processor found for a formatting context: ${e.getName()}`)}},gn=class{layout(e,t,i){return t.isFloatNodeContext(e)?t.layoutFloatOrFootnote(e):t.isBreakable(e)?t.layoutBreakableBlock(e):t.layoutUnbreakable(e)}createEdgeBreakPosition(e,t,i,n){return new Or(e.copy(),t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}clearOverflownViewNodes(e,t,i,n){var r;if(!i.viewNode||!i.viewNode.parentNode||i.shadowType===li.ShadowType.ROOTLESS&&pn(i))return;let o=i.viewNode;((r=o.parentElement)==null?void 0:r.localName)==="viv-ts-inner"&&(o=o.parentElement.parentElement);let s=o.parentNode;rd(s,o),n&&s.removeChild(o)}finishBreak(e,t,i,n){let r=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,r),n&&e.layoutContext.processFragmentedBlockEdge(t),T(!0)}},cl=class{constructor(e){this.parent=e,c(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},dl=new gn,ly=ia.isInstanceOfBlockFormattingContext;At("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,r,o)=>{let s=e.parent;return!s&&e.formattingContext||s&&e.formattingContext!==s.formattingContext?null:e.establishesBFC||!e.formattingContext&&ed(i,n,r,o)?new cl(s?s.formattingContext:null):null});At("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof cl?dl:null);var pl=class{constructor(){c(this,"initialBreakPositions",null),c(this,"initialStateOfFormattingContext",null),c(this,"initialPosition"),c(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=D("AbstractLayoutRetryer.tryLayout");this.saveState(e,t);let n=this.resolveLayoutMode(e);return n.doLayout(e,t).then(r=>{let o=n.accept(r,t);o=n.postLayout(r,this.initialPosition,t,o),o?i.finish(r):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(e,t),this.tryLayout(this.initialPosition,t).thenFinish(i))}),i.result()}prepareLayout(e,t){}clearNodes(e){let t=e.viewNode||e.parent.viewNode,i;for(;i=t.lastChild;)t.removeChild(i);let n;for(;n=t.nextSibling;)n.parentNode.removeChild(n)}saveState(e,t){this.initialPosition=e.copy(),this.initialBreakPositions=[].concat(t.breakPositions),this.initialFragmentLayoutConstraints=[].concat(t.fragmentLayoutConstraints),e.formattingContext&&(this.initialStateOfFormattingContext=e.formattingContext.saveState())}restoreState(e,t){t.breakPositions=this.initialBreakPositions,t.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,e.formattingContext&&e.formattingContext.restoreState(this.initialStateOfFormattingContext)}},hy=class{initialState(e){return{nodeContext:e,atUnforcedBreak:!1,break:!1}}startNonDisplayableNode(e){}afterNonDisplayableNode(e){}startIgnoredTextNode(e){}afterIgnoredTextNode(e){}startNonElementNode(e){}afterNonElementNode(e){}startInlineElementNode(e){}afterInlineElementNode(e){}startNonInlineElementNode(e){}afterNonInlineElementNode(e){}finish(e){}},oa=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=D("LayoutIterator");return n.loopWithFrame(r=>{let o;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Le(i.nodeContext.viewNode,i.nodeContext.whitespace)?i.nodeContext.after?o=t.afterIgnoredTextNode(i):o=t.startIgnoredTextNode(i):i.nodeContext.after?o=t.afterNonElementNode(i):o=t.startNonElementNode(i):i.nodeContext.inline?i.nodeContext.after?o=t.afterInlineElementNode(i):o=t.startInlineElementNode(i):i.nodeContext.after?o=t.afterNonInlineElementNode(i):o=t.startNonInlineElementNode(i):i.nodeContext.after?o=t.afterNonDisplayableNode(i):o=t.startNonDisplayableNode(i);let s=(o&&o.isPending()?o:T(!0)).thenAsync(()=>i.break?T(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(s.isPending()){s.then(a=>{i.break?r.breakLoop():(i.nodeContext=a,r.continueLoop())});return}else if(i.break){r.breakLoop();return}else i.nodeContext=s.get()}t.finish(i),r.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},nr=class extends hy{constructor(e){super(),this.leadingEdge=e}startNonInlineBox(e){}endEmptyNonInlineBox(e){}endNonInlineBox(e){}initialState(e){return{nodeContext:e,atUnforcedBreak:!!this.leadingEdge&&e.after,break:!1,leadingEdge:this.leadingEdge,breakAtTheEdge:null,onStartEdges:!1,leadingEdgeContexts:[],lastAfterNodeContext:null}}processForcedBreak(e,t){let i=!e.leadingEdge&&qe(e.breakAtTheEdge);if(i){let n=e.nodeContext=e.leadingEdgeContexts[0]||e.nodeContext;n.viewNode.parentNode.removeChild(n.viewNode),t.pageBreakType=e.breakAtTheEdge}return i}saveEdgeAndProcessOverflow(e,t){let i=t.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,e.breakAtTheEdge);return i&&(e.nodeContext=(e.lastAfterNodeContext||e.nodeContext).modify(),e.nodeContext.overflow=!0),i}processLayoutConstraint(e,t,i){let n=e.nodeContext,r=!t.allowLayout(n);return r&&(i.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),n=e.nodeContext=n.modify(),n.overflow=!0),r}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=tt(e.breakAtTheEdge,e.nodeContext.breakBefore),e.onStartEdges=!0,this.startNonInlineBox(e)}afterNonInlineElementNode(e){let t,i;return e.onStartEdges?(t=this.endEmptyNonInlineBox(e),i=t&&t.isPending()?t:T(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),T(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:T(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=tt(e.breakAtTheEdge,e.nodeContext.breakAfter)),T(!0)))}},sa=[];function uy(){sa=[]}function Fd(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var cy=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},dy=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},Rd=class ro{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let r=ro.fragmentIndices;(!r[t]||r[t].priority<=n)&&(r[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){ro.fragmentIndices={}}matches(){let t=ro.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&Fd(t.fragmentIndex,this.a,this.b)}};c(Rd,"fragmentIndices",{});var os=Rd,Xr=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new os(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new dy(e)}static buildAnyMatcher(e){return new cy(e)}},Ld={"border-collapse":!0,"border-spacing":!0,"caption-side":!0,"clip-rule":!0,color:!0,"color-interpolation":!0,"color-rendering":!0,cursor:!0,direction:!0,"empty-cells":!0,fill:!0,"fill-opacity":!0,"fill-rule":!0,"font-kerning":!0,"font-size":!0,"font-size-adjust":!0,"font-family":!0,"font-feature-settings":!0,"font-style":!0,"font-stretch":!0,"font-variant-ligatures":!0,"font-variant-caps":!0,"font-variant-numeric":!0,"font-variant-east-asian":!0,"font-weight":!0,"glyph-orientation-vertical":!0,"hanging-punctuation":!0,hyphens:!0,"hyphenate-character":!0,"hyphenate-limit-chars":!0,"hyphenate-limit-last":!0,"image-rendering":!0,"image-resolution":!0,"letter-spacing":!0,"line-break":!0,"line-height":!0,"list-style-image":!0,"list-style-position":!0,"list-style-type":!0,marker:!0,"marker-end":!0,"marker-mid":!0,"marker-start":!0,orphans:!0,"overflow-wrap":!0,"paint-order":!0,"pointer-events":!0,quotes:!0,"ruby-align":!0,"ruby-position":!0,"shape-rendering":!0,stroke:!0,"stroke-dasharray":!0,"stroke-dashoffset":!0,"stroke-linecap":!0,"stroke-linejoin":!0,"stroke-miterlimit":!0,"stroke-opacity":!0,"stroke-width":!0,"tab-size":!0,"text-align":!0,"text-align-last":!0,"text-anchor":!0,"text-autospace":!0,"text-decoration-skip":!0,"text-decoration-skip-ink":!0,"text-emphasis-color":!0,"text-emphasis-position":!0,"text-emphasis-style":!0,"text-fill-color":!0,"text-combine-upright":!0,"text-indent":!0,"text-justify":!0,"text-orientation":!0,"text-rendering":!0,"text-shadow":!0,"text-size-adjust":!0,"text-spacing-trim":!0,"text-stroke-color":!0,"text-stroke-width":!0,"text-transform":!0,"text-underline-offset":!0,"text-underline-position":!0,"text-wrap":!0,"text-wrap-mode":!0,"text-wrap-style":!0,visibility:!0,"white-space":!0,widows:!0,"word-break":!0,"word-spacing":!0,"writing-mode":!0},py=["image-resolution","orphans","widows"];function fy(){return Dt("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(py))}var gy={"http://www.idpf.org/2007/ops":!0,"http://www.w3.org/1999/xhtml":!0,"http://www.w3.org/2000/svg":!0,"http://www.w3.org/1998/Math/MathML":!0},aa=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],my=["max-%","min-%","%"],Ih=(()=>{let e=["left","right","top","bottom"],t={width:!0,height:!0,"max-width":!0,"max-height":!0,"min-width":!0,"min-height":!0};for(let i=0;i<aa.length;i++)for(let n=0;n<e.length;n++){let r=aa[i].replace("%",e[n]);t[r]=!0}return t})();function On(e,t){let i={};for(let n of aa)for(let r in e){let o=n.replace("%",r),s=n.replace("%",e[r]);i[o]=s,i[s]=o}for(let n of my)for(let r in t){let o=n.replace("%",r),s=n.replace("%",t[r]);i[o]=s,i[s]=o}return i}var Od=On({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),Bd=On({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),wy=On({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),yy=On({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),vy=On({inside:"right",outside:"left"},{}),by=On({inside:"left",outside:"right"},{}),V=class la{constructor(t,i){this.value=t,this.priority=i}getBaseValue(){return this}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new la(i,this.priority)}increaseSpecificity(t){return t==0?this:new la(this.value,this.priority+t)}evaluate(t,i,n,r){return i&&Qt(i)?this.value:zo(t,this.value,i,n,r)}isEnabled(t){return!0}},ha=class ua extends V{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new V(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new ua(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new ua(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){j.warn(i)}return!1}};function ca(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Gt(e,t,i,n){if(e)if(!i)delete e[t];else{let r=e[t];(!r||i.priority>=r.priority)&&(n?i.isEnabled(n)&&(e[t]=i.getBaseValue()):e[t]=i)}}var Md={"region-id":!0,"fragment-selector-id":!0},rr="data-viv-footnote-counter";function Mo(e){let t=e.getAttribute(rr);if(!t)return Object.create(null);let i;try{i=JSON.parse(t)}catch{return Object.create(null)}if(!i||typeof i!="object"||Array.isArray(i))return Object.create(null);let n=Object.create(null);return Object.entries(i).forEach(([r,o])=>{if(Array.isArray(o)){let s=o.filter(a=>typeof a=="number"&&isFinite(a));n[r]=s}else typeof o=="number"&&isFinite(o)&&(n[r]=[o])}),n}function _d(e,t,i){let n=Mo(e);n[t]=i,e.setAttribute(rr,JSON.stringify(n))}function xy(e,t){var i,n;if(!_t(e)||e.hasAttribute(Pd))return null;let r=Mo(e)[t];if(r)return r;let o=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!o)return null;let s=e.baseURI||((i=e.ownerDocument)==null?void 0:i.baseURI)||"",a=ko(o,s);if(a==="#"||a.replace(/#.*$/,"")!==s.replace(/#.*$/,""))return null;let h=a.indexOf("#");if(h<0||h===a.length-1)return null;let l=(n=e.ownerDocument)==null?void 0:n.getElementById(a.substring(h+1));if(!(l instanceof Element))return null;let u=Mo(l)[t];return u?(_d(e,t,u),u):null}function Sy(e){let t=me(e,"content");return!!t&&kt(t.value)}function Cy(e){return!!Md[e]}function oo(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Di(e){return e.charAt(0)!=="_"&&!Md[e]}function mn(e){return!!Ld[e]||Qt(e)}function me(e,t){return e[t]}function Ci(e,t,i){i?e[t]=i:delete e[t]}function gt(e,t){return e[t]}function ei(e,t){let i=e[t];return i||(i={},e[t]=i),i}var Dd=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function zd(e,t){return e[t]}function Vd(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function _o(e,t,i,n,r,o,s){var a,h;if([{id:r,styleKey:"_pseudos"},{id:o,styleKey:"_regions"}].forEach(l=>{if(l.id){let u=ei(t,l.styleKey);t=u[l.id],t||(t={},u[l.id]=t)}}),s){let l=Dd(t);t={},l.push({styles:t,matcher:s})}for(let l in i)if(!oo(l))if(Cy(l)){let u=zd(i,l),d=Vd(t,l);Array.prototype.push.apply(d,u)}else{let u=me(i,l);if(!u.isEnabled(e))continue;let d=u.increaseSpecificity(n);Gt(t,l,d,e);let p=(h=(a=e.style)==null?void 0:a.validatorSet.shorthands[l])==null?void 0:h.propList;if(p)for(let f of p){let g=new V(Y,d.priority);Gt(t,f,g,e)}}}function ky(e,t){let i={};for(let n=0;n<t.length;n++)_o(e,i,t[n],0,null,null,null);return i}function fl(e,t){if(e.length>0){e.sort((n,r)=>r.getPriority()-n.getPriority());let i=null;for(let n=e.length-1;n>=0;n--)i=e[n],i.chained=t,t=i;return i}return t}var Ey=class extends Gi{constructor(e,t){super(),this.props=e,this.context=t,c(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=me(this.props,"font-size");if(!e.value.isNumeric())return Wt.em;let t=e.value;if(!dg(t.unit))throw new Error("Unexpected state");return t.num*Wt[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?da(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?gl(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?zo(this.context,e,this.propName).visit(this):e}};function gl(e,t,i){let n=e.unit,r=e.num;return n==="em"?new R(r*t,"px"):n==="rem"?new R(r*i.fontSize(),"px"):n==="rlh"?new R(r*i.rootLineHeight,"px"):e}function da(e,t,i){e=gl(e,t,i);let n=e.unit,r=e.num;return n==="px"?e:n==="%"?new R(r/100*t,"px"):new R(r*i.queryUnitSize(n,!1),"px")}var Bn=class{apply(e){}mergeWith(e){return new Py([this,e])}clone(){return this}},qr=class extends Bn{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},Py=class Ud extends Bn{constructor(t){super(),this.list=t}apply(t){for(let i=0;i<this.list.length;i++)this.list[i].apply(t)}mergeWith(t){return this.list.push(t),this}clone(){return new Ud([].concat(this.list))}},ml=class extends Bn{constructor(e,t,i,n,r){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=r}apply(e){_o(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},ke=class extends Bn{constructor(){super(),c(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Ny=class extends ke{constructor(e){super(),this.className=e}apply(e){e.currentClassNames.includes(this.className)&&this.chained.apply(e)}getPriority(){return 10}makePrimary(e){return this.chained&&e.insertInTable(e.classes,this.className,this.chained),!0}},Ty=class extends ke{constructor(e){super(),this.id=e}apply(e){(e.currentId==this.id||e.currentXmlId==this.id)&&this.chained.apply(e)}getPriority(){return 11}makePrimary(e){return this.chained&&e.insertInTable(e.ids,this.id,this.chained),!0}},Ah=class extends ke{constructor(e){super(),this.localName=e}apply(e){e.currentLocalName==this.localName&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){return this.chained&&e.insertInTable(e.tags,this.localName,this.chained),!0}},Iy=class extends ke{constructor(e,t){super(),this.ns=e,this.localName=t}apply(e){e.currentLocalName==this.localName&&e.currentNamespace==this.ns&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){if(this.chained){let t=e.nsPrefix[this.ns];t||(t=`ns${e.nsCount++}:`,e.nsPrefix[this.ns]=t);let i=t+this.localName;e.insertInTable(e.nstags,i,this.chained)}return!0}},Ay=class extends ke{constructor(e,t,i=!1){super(),this.epubTypePatt=e,this.targetLocalName=t,this.useRoleAttr=i}apply(e){let t=e.currentElement;if(t instanceof HTMLAnchorElement&&t.hash&&t.href==t.baseURI.replace(/#.*$/,"")+t.hash){let i=t.hash.substring(1),n=t.ownerDocument.getElementById(i);if(n&&(!this.targetLocalName||n.localName==this.targetLocalName)){let r=this.useRoleAttr?n.getAttribute("role"):n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");r&&r.match(this.epubTypePatt)&&this.chained.apply(e)}}}},Fy=class extends ke{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function ss(e,t,i,n){if(!e)return!1;if(t!==null)return n(e,t,i);for(let r of e.getAttributeNames())if((r===i||r.endsWith(`:${i}`))&&n(e,r===i?"":e.lookupNamespaceURI(r.split(":")[0]),i))return!0;return!1}var Fh=class extends ke{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){ss(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},Ry=class extends ke{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){ss(e.currentElement,this.ns,this.name,(t,i,n)=>t.getAttributeNS(i,n)==this.value)&&this.chained.apply(e)}getPriority(){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?9:0}makePrimary(e){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?(this.chained&&e.insertInTable(e.epubtypes,this.value,this.chained),!0):!1}},Ly=class extends ke{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){ss(e.currentElement,this.ns,this.name,(t,i,n)=>!!gy[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},$n=class extends ke{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){ss(e.currentElement,this.ns,this.name,(t,i,n)=>{var r;return!!((r=t.getAttributeNS(i,n))!=null&&r.match(this.regexp))})&&this.chained.apply(e)}},Oy=class extends ke{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Rh=class extends ke{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},By=class extends ke{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},qi=class extends ke{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return Fd(e,this.a,this.b)}},My=class extends qi{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},pa=class extends qi{constructor(e,t){super(e,t)}apply(e){let t=e.currentSiblingTypeCounts[e.currentNamespace][e.currentLocalName];this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 5}},fa=class extends qi{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingOrder;t===null&&(t=e.currentFollowingSiblingOrder=e.currentElement.parentNode.childElementCount-e.currentSiblingOrder+1),this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 4}},ga=class extends qi{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingTypeCounts;if(!t[e.currentNamespace]){let i=e.currentElement;do{let n=i.namespaceURI,r=i.localName,o=t[n];o||(o=t[n]={}),o[r]=(o[r]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},_y=class extends ke{constructor(){super()}apply(e){let t=e.currentElement.firstChild;for(;t;){switch(t.nodeType){case Node.ELEMENT_NODE:return;case Node.TEXT_NODE:if(t.length>0)return}t=t.nextSibling}this.chained.apply(e)}getPriority(){return 4}},Dy=class extends ke{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},zy=class extends ke{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},Vy=class extends ke{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},et=class extends ke{constructor(e){super(),this.condition=e}apply(e){if(e.conditions[this.condition])try{e.dependentConditions.push(this.condition),this.chained.apply(e)}finally{e.dependentConditions.pop()}}getPriority(){return 5}},$d=class Hd extends Bn{constructor(){super(),c(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new Hd;return t.applied=this.applied,t}},wl=class extends ke{constructor(e){super(),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new $d;for(let t of e)this.firstActions.push(fl(t,this.checkAppliedAction))}apply(e){for(let t of this.firstActions)if(t.apply(e),this.checkAppliedAction.applied)break;this.checkAppliedAction.applied===this.positive()&&this.chained.apply(e),this.checkAppliedAction.applied=!1}getPriority(){return Math.max(...this.firstActions.map(e=>e instanceof ke?e.getPriority():0))}positive(){return!0}relational(){return!1}},Uy=class extends wl{positive(){return!1}},$y=class extends wl{constructor(e){super([]),this.selectorTexts=e}apply(e){for(let t of this.selectorTexts){let i,n;/^\s*[+~]/.test(t)?(n=e.currentElement.parentNode,i=`:scope > :nth-child(${Array.from(n.children).indexOf(e.currentElement)+1}) ${t}`):(n=e.currentElement,i=`:scope ${t}`);try{if(n.querySelector(i)){this.checkAppliedAction.apply(e);break}}catch{}}this.checkAppliedAction.applied&&this.chained.apply(e),this.checkAppliedAction.applied=!1}relational(){return!0}},Wd=class extends qi{constructor(e,t,i){super(e,t),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new $d;for(let n of i)this.firstActions.push(fl(n,this.checkAppliedAction))}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.previousElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.previousElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}matchesSelector(e,t){let i=t.currentElement,n=t.currentNamespace,r=t.currentLocalName,o=t.currentId,s=t.currentClassNames,a=t.currentSiblingOrder;t.currentElement=e,t.currentNamespace=e.namespaceURI||"",t.currentLocalName=e.localName,t.currentId=e.id,t.currentClassNames=e.classList?Array.from(e.classList):[];let h=1,l=e.previousElementSibling;for(;l;)h++,l=l.previousElementSibling;t.currentSiblingOrder=h;for(let d of this.firstActions)if(d.apply(t),this.checkAppliedAction.applied)break;let u=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,t.currentElement=i,t.currentNamespace=n,t.currentLocalName=r,t.currentId=o,t.currentClassNames=s,t.currentSiblingOrder=a,u}getPriority(){return 5}},Hy=class extends Wd{constructor(e,t,i){super(e,t,i)}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.nextElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.nextElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 4}},as=class{constructor(e,t,i){this.condition=e,this.viewConditionId=t,this.viewCondition=i}increment(e){e.increment(this.condition,this.viewCondition)}decrement(e){e.decrement(this.condition,this.viewCondition)}buildViewConditionMatcher(e){return e.buildViewConditionMatcher(this.viewConditionId)}},Wy=class Gd extends as{constructor(t,i,n){super(t,i,n)}fresh(t){return new Gd(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return i==0&&this.increment(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):!1}},Gy=class jd extends as{constructor(t,i,n){super(t,i,n)}fresh(t){return new jd(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return i==0?this.increment(t):i==1&&this.decrement(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):(i==1&&this.increment(t),!1)}},jy=class Xd extends as{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new Xd(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return this.fired?(this.decrement(t),!0):!1}pop(t,i){return this.fired?(this.decrement(t),!0):(i==0&&(this.fired=!0,this.increment(t)),!1)}},Xy=class qd extends as{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new qd(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return this.fired&&(i==-1?this.increment(t):i==0&&this.decrement(t)),!1}pop(t,i){if(this.fired){if(i==-1)return this.decrement(t),!0;i==0&&this.increment(t)}else i==0&&(this.fired=!0,this.increment(t));return!1}},qy=class{constructor(e,t){this.afterprop=e,this.element=t}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.processPseudoelementProps(this.afterprop,this.element),!0):!1}},Yy=class{constructor(e){this.lang=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.lang=this.lang,!0):!1}},Zy=class{constructor(e){this.oldQuotes=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.quotes=this.oldQuotes,!0):!1}},Ky=class extends Gi{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new ut(e):new ut("about:invalid");case"string":default:return e?new X(e):new X("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let t="string",i=null,n=null;if(e.values[0]instanceof J){let r=e.values[0].values;r.length>=2&&(t=r[1].stringValue()),i=r[0].stringValue()}else i=e.values[0].stringValue();return e.values.length>1?n=this.createValueFromString(e.values[1].stringValue(),t):n=this.createValueFromString(null,t),this.element&&this.element.hasAttribute(i)?this.createValueFromString(this.element.getAttribute(i),t):n}};function Do(e,t){if(kt(e)){if(e instanceof X)return e.stringValue();if(e instanceof G&&t){let i=e.expr.evaluate(t);return typeof i=="string"?i:typeof i=="number"?String(i):""}if(e instanceof J)return e.values.map(i=>Do(i,t)).join("")}return""}var mr=class extends Gi{constructor(e,t,i,n){super(),this.cascade=e,this.element=t,this.counterResolver=i,this.pseudoName=n}getCounterStore(){var e,t;return(t=(e=this.cascade.context)==null?void 0:e.counterStore)!=null?t:null}getPageScope(){var e,t;return(t=(e=this.cascade.context)==null?void 0:e.style)==null?void 0:t.pageScope}evaluateAndGetString(e){if(!e)return"";let t=this.cascade.quoteDepth,i=e.visit(this),n=Do(i,this.cascade.context);return this.cascade.quoteDepth=t,n}visitIdent(e){let t=this.cascade,i=t.quotes,n=Math.floor(i.length/2)-1;switch(e.name){case"open-quote":{let r=i[2*Math.min(n,t.quoteDepth)];return t.quoteDepth++,r}case"close-quote":return t.quoteDepth>0&&t.quoteDepth--,i[2*Math.min(n,t.quoteDepth)+1];case"no-open-quote":return t.quoteDepth++,new X("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new X("")}return e}format(e,t){return this.cascade.counterStyleStore.format(t,e)}formatCounterList(e,t,i){if(!e.length)return this.format(0,i);let n=new si;for(let r=0;r<e.length;r++)r>0&&n.append(t),n.append(this.format(e[r],i));return n.toString()}formatLastValue(e,t){let i=e.length?e[e.length-1]:0;return this.format(i,t)}buildCounterText(e,t,i,n,r){var o,s,a,h,l,u;let d=typeof r=="string",p=w=>d?this.formatCounterList(w,r,i):this.formatLastValue(w,i),f=w=>{this.pseudoName==="footnote-call"&&this.element&&_d(this.element,t,w)};if(this.pseudoName==="footnote-call"&&this.element){let w=xy(this.element,t);if(w)return p(w)}if(this.pseudoName==="footnote-marker"&&this.element){let w=Mo(this.element)[t];if(w)return p(w)}let g;if(t==="pages")return p([]);if(!this.element){let w=((o=e.currentPageCounters)==null?void 0:o[t])||[];if(w.length)return g=w,f(g),p(g)}let m=this.element?n:((s=e.currentPageDocCounters)==null?void 0:s[t])||n;if((a=e.isPageControlledCounter)!=null&&a.call(e,t)){let w=((h=e.currentPageDocCounters)==null?void 0:h[t])||[],x=((l=e.currentPageCounters)==null?void 0:l[t])||[],y=x.length?x[x.length-1]:0,b=w.length?w[0]:0,S=m.length?m[0]:0,C=y+(S-b);return g=m.length?[C,...m.slice(1)]:x.length?x:[0],f(g),p(g)}return m.length?(g=m,f(g),p(g)):(g=((u=e.currentPageCounters)==null?void 0:u[t])||[],f(g),p(g))}visitFuncCounter(e){var t;let i=e[0].toString(),n=e.length>1?e[1].stringValue():"decimal",r=(this.cascade.counters[i]||[]).slice(),o=this.getCounterStore();if(o){let a=i==="pages"||((t=o?.isPageControlledCounter)==null?void 0:t.call(o,i)),h=this.getPageScope(),l=new Re(h,()=>this.buildCounterText(o,i,n,r),a?`page-counter-${i}`:`counter-${i}`);if(a&&o!=null&&o.registerPageCounterExpr){let u=d=>this.formatLastValue(d,n);o.registerPageCounterExpr(i,u,l)}return new G(l)}let s=this.cascade.counters[i];if(s&&s.length){let a=s&&s.length&&s[s.length-1]||0;return new X(this.format(a,n))}else{let a=new G(this.counterResolver.getPageCounterVal(i,h=>this.format(h||0,n)));return new J([a])}}visitFuncCounters(e){var t;let i=e[0].toString(),n=e[1].stringValue(),r=e.length>2?e[2].stringValue():"decimal",o=(this.cascade.counters[i]||[]).slice(),s=this.getCounterStore();if(s){let u=i==="pages"||((t=s?.isPageControlledCounter)==null?void 0:t.call(s,i)),d=this.getPageScope(),p=new Re(d,()=>this.buildCounterText(s,i,r,o,n),u?`page-counters-${i}`:`counters-${i}`);return u&&s!=null&&s.registerPageCounterExpr&&s.registerPageCounterExpr(i,f=>this.formatCounterList(f,n,r),p),new G(p)}let a=this.cascade.counters[i],h=new si;if(a&&a.length)for(let u=0;u<a.length;u++)u>0&&h.append(n),h.append(this.format(a[u],r));let l=new G(this.counterResolver.getPageCountersVal(i,u=>{let d=[];if(u.length)for(let f=0;f<u.length;f++)d.push(this.format(u[f],r));let p=h.toString();return p.length&&d.push(p),d.length?d.join(n):this.format(0,r)}));return new J([l])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof ut?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",o=new G(this.counterResolver.getTargetCounterVal(i,n,s=>this.format(s||0,r)));return new J([o])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof ut?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e[2].stringValue(),o=e.length>3?e[3].stringValue():"decimal",s=new G(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,o));return h.length?h.join(r):this.format(0,o)}));return new J([s])}visitFuncTargetText(e){let t=e[0],i;t instanceof ut?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",r=new G(this.counterResolver.getTargetTextVal(i,n));return new J([r])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new G(this.counterResolver.getNamedStringVal(t,i))}visitFuncElement(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new G(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,r,o,s,a,h;let l=e.length>0?e[0].stringValue():"text",u="";switch(l){case"text":u=this.element.textContent;break;case"before":case"after":case"marker":{let d=(t=this.element)==null?void 0:t.querySelectorAll(`[data-adapt-pseudo="${l}"]`),p=null;if(d&&this.element)for(let f=0;f<d.length;f++){let g=d[f];if(g.parentElement===this.element){p=g;break}}if(p)u=p.textContent||"";else{let f=gt(this.cascade.currentStyle,"_pseudos"),g=(n=(i=f?.[l])==null?void 0:i.content)==null?void 0:n.value;if(g)u=this.evaluateAndGetString(g);else if(l==="marker"){let m=(r=this.cascade.currentStyle["--viv-marker-content"])==null?void 0:r.value;u=Do(m,this.cascade.context)}}}break;case"first-letter":{let d=gt(this.cascade.currentStyle,"_pseudos"),p=(s=(o=d?.before)==null?void 0:o.content)==null?void 0:s.value,f=(h=(a=d?.after)==null?void 0:a.content)==null?void 0:h.value,g=(this.evaluateAndGetString(p)||this.element.textContent||this.evaluateAndGetString(f)).match(Co);u=g?g[0]:""}break}return new X(u)}visitFuncLeader(e){let t="";if(e[0]instanceof de)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof X&&(t=e[0].stringValue());return t.length==0?new X(""):new G(new Re(null,()=>t,"viv-leader"))}visitFunc(e){switch(e.name){case"counter":if(e.values.length<=2)return this.visitFuncCounter(e.values);break;case"counters":if(e.values.length<=3)return this.visitFuncCounters(e.values);break;case"target-counter":if(e.values.length<=3)return this.visitFuncTargetCounter(e.values);break;case"target-counters":if(e.values.length<=4)return this.visitFuncTargetCounters(e.values);break;case"target-text":if(e.values.length>=1&&e.values.length<=2)return this.visitFuncTargetText(e.values);break;case"string":if(e.values.length<=2)return this.visitFuncString(e.values);break;case"element":if(e.values.length<=2)return this.visitFuncElement(e.values);break;case"content":if(e.values.length<=1)return this.visitFuncContent(e.values);break;case"leader":if(e.values.length<=1)return this.visitFuncLeader(e.values);break}return e}};function ks(e,t,i){let n;if(e.nodeType===1)n=Array.from(e.getClientRects());else{let r=e.ownerDocument.createRange();r.selectNodeContents(e),n=t.getRangeClientRects(r)}return n.reduce((r,o)=>r+(i==="vertical-rl"||i==="vertical-lr"?o.height:o.width),0)}var Jy=(e,t,i)=>{let n=t.filter(h=>h.after&&h.viewNode.nodeType===1&&h.viewNode.getAttribute("data-viv-leader"));for(let h of n){let l=function(P){b==="rtl"?g.textContent=(P.startsWith("\u200F")?"":"\u200F")+P+(P.endsWith("\u200F")?"":"\u200F"):g.textContent=P},u=function(){let P=i.clientLayout.getElementClientRect(m);return y==="vertical-rl"||y==="vertical-lr"?b==="rtl"?P.top-=k:P.bottom+=k:b==="rtl"?P.left-=k:P.right+=k,F.left>P.left||F.right<P.right||F.top>P.top||F.bottom<P.bottom},d=function(){let P,A,O=x.repeat(1e4);if(l(O),u())P=1,A=1e4;else return;for(let z=0;z<16;z++){let W="",K=Math.floor((P+A)/2);for(let Q=0;Q<K;Q++)W+=x;if(l(W),u())A=K;else{if(P==K)return;P=K}}l(x)},p=function(P){let A=0,O=m.parentElement;for(;O&&O!==f.viewNode;)A+=i.getComputedInsets(O)[P],O=O.parentElement;return A};var r=l,o=u,s=d,a=p;let f=h.parent;for(;f&&f.inline;)f=f.parent;let g=h.viewNode,m=g.parentElement,w=m.getAttribute("data-adapt-pseudo"),x=g.getAttribute("data-viv-leader-value"),{writingMode:y,direction:b,marginInlineEnd:S}=i.clientLayout.getElementComputedStyle(m);g.style.marginInlineStart="1px",l(x),m.style.display="inline-block",m.style.textIndent="0";let C=Lr(f.viewNode),N=C?.style.columnFill||null;C&&(C.style.columnFill="auto");let F=i.clientLayout.getElementClientRect(f.viewNode),B=i.clientLayout.getElementClientRect(m),U=i.parseComputedLength(S),q=[],he=m.parentElement;for(;he.parentElement&&he.parentElement!==f.viewNode;)he=he.parentElement;let ae=he.nextSibling;for(;ae;){if(ae.nodeType===1){let P=ae,{display:A,float:O,position:z}=i.clientLayout.getElementComputedStyle(P);if(O!=="none"||z==="absolute"||z==="fixed"){ae=ae.nextSibling;continue}if(Ht(A))q.push(P);else if(pw(A))break}else if(ae.nodeType===3){let P=ae;P.length>0&&q.push(P)}ae=ae.nextSibling}let k=q.reduce((P,A)=>P+ks(A,i.clientLayout,y),0);if(w!=="after"){let P=ks(he,i.clientLayout,y),A=ks(m,i.clientLayout,y);k+=P-A}y==="vertical-rl"||y==="vertical-lr"?(b==="rtl"?F.top+=U:F.bottom-=U,F.top=Math.min(B.top,F.top),F.bottom=Math.max(B.bottom,F.bottom)):(b==="rtl"?F.left+=U:F.right-=U,F.left=Math.min(B.left,F.left),F.right=Math.max(B.right,F.right)),d();let _=i.clientLayout.getElementClientRect(m);b=="rtl"?m.style.float="left":m.style.float="right";let E=i.clientLayout.getElementClientRect(m),L=0;b=="rtl"?y=="vertical-rl"||y=="vertical-lr"?L=_.top-E.top-p("top"):L=_.left-E.left-p("left"):y=="vertical-rl"||y=="vertical-lr"?L=E.bottom-_.bottom-p("bottom"):L=E.right-_.right-p("right"),L-=k,L=Math.max(0,L-.1),m.style.float="",g.style.marginInlineStart=`${L}px`,C&&(N?C.style.columnFill=N:C.style.removeProperty("column-fill"))}};At("POST_LAYOUT_BLOCK",Jy);var yl=1/1048576;function Ki(e,t){for(let i in e)t[i]=e[i].clone()}var Qy=class Yd{constructor(){c(this,"nsCount",0),c(this,"nsPrefix",{}),c(this,"tags",{}),c(this,"nstags",{}),c(this,"epubtypes",{}),c(this,"classes",{}),c(this,"ids",{}),c(this,"pagetypes",{}),c(this,"order",0)}clone(){let t=new Yd;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return Ki(this.tags,t.tags),Ki(this.nstags,t.nstags),Ki(this.epubtypes,t.epubtypes),Ki(this.classes,t.classes),Ki(this.ids,t.ids),Ki(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,i,n){let r=t[i];r&&(n=r.mergeWith(n)),t[i]=n}createInstance(t,i,n,r,o,s){return new ev(this,t,i,n,r,o,s)}nextOrder(){return this.order+=yl}},Zd=class Kd{constructor(t,i,n,r,o,s,a){this.context=i,this.counterListener=n,this.counterResolver=r,this.counterStyleStore=s,this.cmykStore=a,c(this,"code"),c(this,"stack",[[],[]]),c(this,"conditions",Object.create(null)),c(this,"currentElement",null),c(this,"currentElementOffset",null),c(this,"currentStyle",null),c(this,"currentClassNames",null),c(this,"currentLocalName",""),c(this,"currentNamespace",""),c(this,"currentId",""),c(this,"currentXmlId",""),c(this,"currentNSTag",""),c(this,"currentEpubTypes",null),c(this,"currentPageType",null),c(this,"previousPageType",null),c(this,"firstPageType",null),c(this,"pageTypePageIndices",Object.create(null)),c(this,"isFirst",!0),c(this,"isRoot",!0),c(this,"counters",Object.create(null)),c(this,"lastCounterChanges",[]),c(this,"lastCounterChangeTypes",Object.create(null)),c(this,"counterScoping",[Object.create(null)]),c(this,"quotes"),c(this,"quoteDepth",0),c(this,"lang",""),c(this,"siblingOrderStack",[0]),c(this,"currentSiblingOrder",0),c(this,"siblingTypeCountsStack",[{}]),c(this,"currentSiblingTypeCounts"),c(this,"currentFollowingSiblingOrder",null),c(this,"followingSiblingOrderStack"),c(this,"followingSiblingTypeCountsStack",[{}]),c(this,"currentFollowingSiblingTypeCounts"),c(this,"viewConditions",Object.create(null)),c(this,"dependentConditions",[]),c(this,"elementStack"),this.code=t,this.quotes=[new X("\u201C"),new X("\u201D"),new X("\u2018"),new X("\u2019")],this.currentSiblingTypeCounts=this.siblingTypeCountsStack[0],this.followingSiblingOrderStack=[this.currentFollowingSiblingOrder],this.currentFollowingSiblingTypeCounts=this.siblingTypeCountsStack[0]}pushConditionItem(t){this.stack[this.stack.length-1].push(t)}increment(t,i){this.conditions[t]=(this.conditions[t]||0)+1,i&&(this.viewConditions[t]?this.viewConditions[t].push(i):this.viewConditions[t]=[i])}decrement(t,i){this.conditions[t]--,this.viewConditions[t]&&(this.viewConditions[t]=this.viewConditions[t].filter(n=>n!==i),this.viewConditions[t].length===0&&delete this.viewConditions[t])}buildViewConditionMatcher(t){let i=null;t&&(this.currentElementOffset,i=Xr.buildViewConditionMatcher(this.currentElementOffset,t));let n=this.dependentConditions.map(r=>{let o=this.viewConditions[r];return o&&o.length>0?o.length===1?o[0]:Xr.buildAnyMatcher([].concat(o)):null}).filter(r=>r);return n.length<=0?i:i===null?n.length===1?n[0]:Xr.buildAllMatcher(n):Xr.buildAllMatcher([i].concat(n))}applyAction(t,i){let n=t[i];n&&n.apply(this)}pushRule(t,i,n){this.currentElement=null,this.currentElementOffset=null,this.currentStyle=n,this.currentNamespace="",this.currentLocalName="",this.currentId="",this.currentXmlId="",this.currentClassNames=t,this.currentNSTag="",this.currentEpubTypes=Es,this.currentPageType=i,this.applyActions()}defineCounter(t,i){let n=this.counterScoping[this.counterScoping.length-1];n||(n=Object.create(null),this.counterScoping[this.counterScoping.length-1]=n),this.counters[t]?(n[t]&&this.counters[t].pop(),this.counters[t].push(i)):this.counters[t]=[i],n[t]=!0}pushCounters(t){var i,n,r,o,s,a,h,l;let u=new Set,d=Object.create(null),p=v.inline,f=t.display;if(f&&(p=f.evaluate(this.context)),p===v.none){this.currentElement.setAttribute("data-viv-display-none","true"),this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}else if(this.currentElement.closest("[data-viv-display-none]")){this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}let g=v.inline,m=t.float;m&&(g=m.evaluate(this.context));let w=null,x=null,y=null,b=t["counter-reset"];if(b){let N=b.evaluate(this.context);N&&(w=vn(N,{reset:!0}))}let S=t["counter-set"];if(S){let N=S.evaluate(this.context);N&&(y=vn(N,{defaultValue:0}))}let C=t["counter-increment"];if(C){let N=C.evaluate(this.context);N&&(x=vn(N))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(w||(w=Object.create(null)),w["list-item"]=((n=(i=this.currentElement)==null?void 0:i.start)!=null?n:1)-1),jn(p)&&(x||(x=Object.create(null)),x["list-item"]=(r=x["list-item"])!=null?r:1,/^\s*[-+]?\d/.test((s=(o=this.currentElement)==null?void 0:o.getAttribute("value"))!=null?s:"")&&(y||(y=Object.create(null)),y["list-item"]=this.currentElement.value)),((h=(a=this.currentElement)==null?void 0:a.parentNode)==null?void 0:h.nodeType)===Node.DOCUMENT_NODE&&(w||(w=Object.create(null)),w.footnote===void 0&&(w.footnote=0)),g===v.footnote&&!this.currentStyle["--viv-semantic-footnote-content"]&&(x||(x=Object.create(null)),x.footnote===void 0)){let N=(l=this.currentStyle["counter-increment"])==null?void 0:l.value;(!N||!(N===v.footnote||N instanceof J&&N.values.includes(v.footnote)))&&(x.footnote=1)}if(w)for(let N in w)u.add(N),d[N]="reset";if(x)for(let N in x)u.add(N),d[N]||(d[N]="increment");if(y)for(let N in y)u.add(N),d[N]="set";if(this.lastCounterChanges=Array.from(u),this.lastCounterChangeTypes=d,w)for(let N in w)this.defineCounter(N,w[N]);if(x)for(let N in x){this.counters[N]||this.defineCounter(N,0);let F=this.counters[N];F[F.length-1]+=x[N]}if(y)for(let N in y)if(!this.counters[N])this.defineCounter(N,y[N]);else{let F=this.counters[N];F[F.length-1]=y[N]}if(jn(p)){let N=this.counters["list-item"],F=N[N.length-1];t["ua-list-item-count"]=new V(new Ct(F),0);let B=ei(t,"_pseudos");B.marker||(B.marker={})}this.counterScoping.push(null)}popCounters(){let t=this.counterScoping.pop();if(t)for(let i in t){let n=this.counters[i];n&&(n.length==1?delete this.counters[i]:n.pop())}}setNamedStrings(t){let i=t["string-set"];if(!i)return;i=i.filterValue(new mr(this,this.currentElement,this.counterResolver));let n=i.value instanceof it?i.value.values:[i.value];for(let r of n)if(r instanceof J){let o=r.values[0].stringValue(),s=r.values.slice(1).map(a=>Do(a,this.context)).join("");this.counterResolver.setNamedString(o,s,this.currentElementOffset)}delete t["string-set"]}setRunningElement(t){let i=t.position;if(i?.value instanceof ci&&i.value.name==="running"){let n=i.value.values[0].stringValue();this.counterResolver.setRunningElement(n,this.currentElementOffset)}}processPseudoelementProps(t,i,n){this.pushCounters(t);let r=t.content;r&&(t.content=r.filterValue(new mr(this,i,this.counterResolver,n))),this.popCounters()}pushElement(t,i,n,r){var o,s,a;this.currentPageType=null,this.currentElement=i,this.currentElementOffset=r,this.currentStyle=n,this.currentNamespace=i.namespaceURI,this.currentLocalName=i.localName;let h=this.code.nsPrefix[this.currentNamespace];h?this.currentNSTag=h+this.currentLocalName:this.currentNSTag="",this.currentId=i.getAttribute("id"),this.currentXmlId=i.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let l=i.getAttribute("class");l?this.currentClassNames=l.split(/\s+/):this.currentClassNames=Es;let u=i.getAttributeNS("http://www.idpf.org/2007/ops","type");u?this.currentEpubTypes=u.split(/\s+/):this.currentEpubTypes=Es;let d=_s(i);d&&(this.stack[this.stack.length-1].push(new Yy(this.lang)),this.lang=d.toLowerCase());let p=this.isRoot,f=this.siblingOrderStack;this.currentSiblingOrder=++f[f.length-1],f.push(0);let g=this.siblingTypeCountsStack,m=this.currentSiblingTypeCounts=g[g.length-1],w=m[this.currentNamespace];w||(w=m[this.currentNamespace]={}),w[this.currentLocalName]=(w[this.currentLocalName]||0)+1,g.push({});let x=this.followingSiblingOrderStack;x[x.length-1]!==null?this.currentFollowingSiblingOrder=--x[x.length-1]:this.currentFollowingSiblingOrder=null,x.push(null);let y=this.followingSiblingTypeCountsStack,b=this.currentFollowingSiblingTypeCounts=y[y.length-1];b&&b[this.currentNamespace]&&b[this.currentNamespace][this.currentLocalName]--,y.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],t,i),this.applyCalcFilter(this.currentStyle,this.context),this.applyCmykFilter(this.currentStyle,this.currentElement),this.applyAttrFilter(i);let S=n.quotes,C=null;if(S){let B=S.evaluate(this.context);B&&(C=new Zy(this.quotes),B===v.none?this.quotes=[new X(""),new X("")]:B===v.auto||B===v.initial?this.quotes=[new X("\u201C"),new X("\u201D"),new X("\u2018"),new X("\u2019")]:B instanceof J&&(this.quotes=B.values))}this.pushCounters(this.currentStyle);let N=this.currentId||this.currentXmlId||i.getAttribute("name")||"";if(p||N){let B=Object.create(null);Object.keys(this.counters).forEach(U=>{B[U]=Array.from(this.counters[U])}),this.counterListener.countersOfId(N,B)}let F=gt(this.currentStyle,"_pseudos");if(F){let B=!0;for(let U of tv){U||(B=!1);let q=F[U];if(q){let he=(o=me(this.currentStyle,"float"))==null?void 0:o.value,ae=i instanceof Element&&_t(i),k=i instanceof Element&&bt(i),_=!!me(this.currentStyle,"--viv-semantic-footnote-content"),E=he===v.footnote,L=(U==="before"||U==="after")&&(E||k||_)&&!!q.content,P=Sy(q),A=U==="footnote-call"&&ae&&P,O=U==="footnote-marker"&&(k||_)&&P;if((U==="before"||U==="after")&&!(L||kt((s=q.content)==null?void 0:s.value)||this.hasNonTrivialViewConditionalPseudoContent(q))||U==="marker"&&!jn((a=me(this.currentStyle,"display"))==null?void 0:a.value)||(U==="footnote-call"||U==="footnote-marker")&&he!==v.footnote&&!A&&!O||(U==="footnote-call"||U==="footnote-marker")&&_&&!P)delete F[U];else if(B){if(this.processPseudoelementProps(q,i,U),U==="marker")this.processMarkerPseudoelementProps(q,i,t),delete F[U];else if(U==="footnote-marker"){if(this.resolvePseudoelementInheritedPropertyValue(q,"list-style-position",t,i)===v.outside){this.processMarkerPseudoelementProps(q,i,t);let z=q.content;z&&(this.currentStyle["_footnote-marker-content"]=z),this.currentStyle.display=new V(M("list-item"),0),this.currentStyle["list-style-position"]=new V(v.outside,0),this.currentStyle["list-style-type"]=new V(v.none,0),this.currentStyle["list-style-image"]=new V(v.none,0),delete F[U]}}else if(U==="first-letter"&&q["initial-letter"]){let z=q["initial-letter"].evaluate(this.context);z!==v.normal&&!Z(z)&&(this.currentStyle["--viv-initialLetter"]=new V(z,0)),delete q["initial-letter"]}}else this.stack[this.stack.length-2].push(new qy(q,i))}}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),C&&this.stack[this.stack.length-2].push(C)}hasNonTrivialViewConditionalPseudoContent(t){let i=t._viewConditionalStyles;return!i||i.length<=0?!1:i.some(n=>{var r;return kt((r=n.styles.content)==null?void 0:r.value)})}processMarkerPseudoelementProps(t,i,n){var r,o,s,a,h;let l=jn((r=this.currentStyle.display)==null?void 0:r.value);if(!kt((o=t.content)==null?void 0:o.value)&&l){let d=this.getInheritedPropertyValue("list-style-type",n,i),p=this.getInheritedPropertyValue("list-style-image",n,i);if(p instanceof ut)t.content=new V(new J([p,new X(" ")]),0);else if(d instanceof X)t.content=new V(d,0);else if(d instanceof de&&d!==v.none){let f=(a=(s=this.currentStyle["ua-list-item-count"])==null?void 0:s.value)==null?void 0:a.num;if(f!=null){let g=d.name.toLowerCase();g==="disc"||g==="circle"||g==="square"||g==="disclosure-open"||g==="disclosure-closed"||(t.content=new V(new X(this.counterStyleStore.formatMarker(d.name,f)),0))}}}let u=t.content;if(u){let d=u.value;if(kt(d)){let p=this.resolveMarkerContentVal(d);this.currentStyle["--viv-marker-content"]=new V(p,0)}}for(let d of Kd.markerAllowedProps){let p=t[d];if(p){let f=p.evaluate(this.context,d);f&&!Z(f)&&(this.currentStyle[`--viv-marker-${d}`]=new V(f,0))}}if(!Ht((h=me(this.currentStyle,"display"))==null?void 0:h.value)){let d=this.getInheritedPropertyValue("list-style-position",n,i);d&&d!==v.outside&&!Z(d)&&(this.currentStyle["list-style-position"]=new V(d,0))}}resolveMarkerContentVal(t){if(t instanceof G){let i=t.expr.evaluate(this.context);return typeof i=="string"?new X(i):typeof i=="number"?new X(String(i)):t}if(t instanceof J){let i=t.values.map(n=>this.resolveMarkerContentVal(n));return new J(i)}return t}getInheritedPropertyValue(t,i,n){var r;for(let s=n;s;s=s.parentElement){let a=(s===this.currentElement?this.currentStyle:i.getStyle(s,!1))[t];if(a){let h=a.evaluate(this.context,t);if(h===v.inherit||h===v.unset||h===v.revert)continue;if(h===v.initial)break;return h}}let o=i.validatorSet;return(r=o?.defaultValues[t])!=null?r:null}resolvePseudoelementInheritedPropertyValue(t,i,n,r){var o;let s=t[i];if(s){let a=s.evaluate(this.context,i);if(a!==v.inherit&&a!==v.unset&&a!==v.revert){if(a===v.initial){let h=n.validatorSet;return(o=h?.defaultValues[i])!=null?o:null}return a}}return this.getInheritedPropertyValue(i,n,r)}applyAttrFilterInner(t,i){for(let n in i)Di(n)&&!Qt(n)&&(i[n]=i[n].filterValue(t))}applyAttrFilter(t){let i=new Ky(t),n=this.currentStyle,r=gt(n,"_pseudos");for(let o in r)this.applyAttrFilterInner(i,r[o]);this.applyAttrFilterInner(i,n)}applyVarFilter(t,i,n){var r,o,s;let a=t[0],h=new cv(t,i,n),l=32,u={};for(let d in a)if(oo(d)){let p=gt(a,d);for(let f in p)this.applyVarFilter([p[f],...t],i,n)}else if(Di(d)){let p=me(a,d),f=p.value;for(let g=0;;g++){if(g>=l){f=Y;break}let m=f.visit(h);if(h.error){f=Y,h.error=!1;break}if(m===f)break;f=m}if(f!==p.value){let g=i.validatorSet,m=(r=g?.shorthands[d])==null?void 0:r.clone();if(m)if(Z(f)){for(let w of m.propList){let x=new V(f,p.priority),y=me(a,w);Ci(u,w,ca(this.context,y,x))}delete a[d]}else{let w=Rr(i.scope,new Vt(f.toString(),null),"");if(w&&(w.visit(m),!m.error)){for(let x of m.propList){let y=new V((s=(o=m.values[x])!=null?o:g.defaultValues[x])!=null?s:v.initial,p.priority),b=me(a,x);Ci(u,x,ca(this.context,b,y))}delete a[d]}}else a[d]=new V(f,p.priority)}if(u[d]){let g=me(a,d);g&&g.value!==Y&&Gt(u,d,g,this.context)}}for(let d in u)a[d]=u[d]}applyCalcFilter(t,i){let n=new op(i);for(let r in t)if(oo(r)){let o=gt(t,r);for(let s in o)this.applyCalcFilter(o[s],i)}else if(Di(r)&&!Qt(r)){let o=me(t,r),s=o.value.visit(n);s!==o.value&&(t[r]=new V(s,o.priority))}}applyCmykFilter(t,i){let n=new gc(this.cmykStore);if(this.applyCmykFilterInternal(t,n,""),i){let r=n.getConversions();r&&i.setAttribute("data-viv-device-cmyk",JSON.stringify(r))}}applyCmykFilterInternal(t,i,n){for(let r in t)if(oo(r)){let o=gt(t,r);for(let s in o)this.applyCmykFilterInternal(o[s],i,`::${s}:`)}else if(Di(r)&&!Qt(r)){let o=me(t,r),s=o.value.toString();i.reset();let a=o.value.visit(i);a!==o.value&&(i.hadDeviceCmyk()&&i.recordConversion(n+r,s),t[r]=new V(a,o.priority))}}applyActions(){let t;for(t=0;t<this.currentClassNames.length;t++)this.applyAction(this.code.classes,this.currentClassNames[t]);for(t=0;t<this.currentEpubTypes.length;t++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[t]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let i=1;i>=-1;--i){let n=this.stack[this.stack.length-i-2];for(t=0;t<n.length;)n[t].push(this,i)?n.splice(t,1):t++}this.isFirst=!0,this.isRoot=!1}pop(){for(let t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2],n=0;for(;n<i.length;)i[n].pop(this,t)?i.splice(n,1):n++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(t){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}};c(Zd,"markerAllowedProps",["color","font-family","font-size","font-style","font-weight","font-variant","hyphens","line-height","tab-size","text-combine-upright","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-orientation","text-shadow","text-transform","unicode-bidi","direction","white-space"]);var ev=Zd,Es=[],tv=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"],ma=null;function iv(e){ma=e}var wr=class extends Xi{constructor(e,t,i,n,r,o,s){super(e,t,s),this.condition=i,this.regionId=r,this.validatorSet=o,c(this,"chain",null),c(this,"specificity",0),c(this,"elementStyle",null),c(this,"conditionCount",0),c(this,"pseudoelement",null),c(this,"selectorFunctionContainsPseudoelement",!1),c(this,"footnoteContent",!1),c(this,"cascade"),c(this,"state"),c(this,"viewConditionId",null),c(this,"insideSelectorRule"),c(this,"invalid",!1),this.cascade=n?n.cascade:ma?ma.clone():new Qy,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=fl(this.chain,e);t!==e&&t.makePrimary(this.cascade)||this.insertNonPrimary(t)}invalidContinuationAfterPseudoelement(e){return this.pseudoelement?(this.invalidSelector(`::${this.pseudoelement} followed by ${e}`),!0):this.selectorFunctionContainsPseudoelement?(this.invalidSelector(`Selector containing pseudo-element followed by ${e}`),!0):!1}isInsideSelectorRule(e){return this.state!=0?(this.reportAndSkip(e),!0):!1}tagSelector(e,t){!t&&!e||this.invalidContinuationAfterPseudoelement(t||"*")||(t&&(this.specificity+=1),t&&e?this.chain.push(new Iy(e,t.toLowerCase())):t?this.chain.push(new Ah(t.toLowerCase())):this.chain.push(new Fy(e)))}invalidSelector(e){j.warn(e),this.chain.push(new et("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof In;e=e.parent)e.parent.invalid=!0}classSelector(e){this.invalidContinuationAfterPseudoelement(`.${e}`)||(this.specificity+=256,this.chain.push(new Ny(e)))}pseudoclassSelector(e,t){if(!this.invalidContinuationAfterPseudoelement(`:${e}`)){switch(e.toLowerCase()){case"enabled":this.chain.push(new Dy);break;case"disabled":this.chain.push(new zy);break;case"checked":this.chain.push(new Vy);break;case"root":case"scope":this.chain.push(new By);break;case"link":this.chain.push(new Ah("a")),this.chain.push(new Fh("","href"));break;case"href-epub-type":case"href-role-type":if(t&&t.length>=1&&typeof t[0]=="string"){let i=t[0],n=new RegExp(`(^|\\s)${di(i)}($|\\s)`),r=t[1];this.chain.push(new Ay(n,r,e==="href-role-type"))}else this.chain.push(new et(""));break;case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new et(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new Oy(new RegExp(`^${di(i.toLowerCase())}($|-)`)))}else this.chain.push(new et(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=nv[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new et(""));break}case"first-child":this.chain.push(new Rh);break;case"last-child":this.chain.push(new fa(0,1));break;case"first-of-type":this.chain.push(new pa(0,1));break;case"last-of-type":this.chain.push(new ga(0,1));break;case"only-child":this.chain.push(new Rh),this.chain.push(new fa(0,1));break;case"only-of-type":this.chain.push(new pa(0,1)),this.chain.push(new ga(0,1));break;case"empty":this.chain.push(new _y);break;case"before":case"after":case"first-line":case"first-letter":this.pseudoelementSelector(e,t);return;default:this.invalidSelector(`Unknown pseudo-class :${e}`);return}this.specificity+=256}}pseudoelementSelector(e,t){if(!this.invalidContinuationAfterPseudoelement(`::${e}`)){switch(e){case"before":case"after":case"first-line":case"first-letter":case"footnote-call":case"footnote-marker":case"marker":case"inner":case"after-if-continues":if(!this.pseudoelement)this.pseudoelement=e;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break;case"first-n-lines":if(t&&t.length==1&&typeof t[0]=="number"){let i=Math.round(t[0]);if(i>0&&i==t[0]){if(!this.pseudoelement)this.pseudoelement=`first-${i}-lines`;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break}}this.chain.push(new et(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new et(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}}idSelector(e){this.invalidContinuationAfterPseudoelement(`#${e}`)||(this.specificity+=65536,this.chain.push(new Ty(e)))}attributeSelector(e,t,i,n){if(this.invalidContinuationAfterPseudoelement(`[${t}]`))return;this.specificity+=256,t=t.toLowerCase(),n=n||"";let r;switch(i){case 0:r=new Fh(e,t);break;case 39:r=new Ry(e,t,n);break;case 45:!n||n.match(/\s/)?r=new et(""):r=new $n(e,t,new RegExp(`(^|\\s)${di(n)}($|\\s)`));break;case 44:r=new $n(e,t,new RegExp(`^${di(n)}($|-)`));break;case 43:n?r=new $n(e,t,new RegExp(`^${di(n)}`)):r=new et("");break;case 42:n?r=new $n(e,t,new RegExp(`${di(n)}$`)):r=new et("");break;case 46:n?r=new $n(e,t,new RegExp(di(n))):r=new et("");break;case 50:if(n=="supported")r=new Ly(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(r)}descendantSelector(){if(this.invalidContinuationAfterPseudoelement("descendant selector"))return;let e=`d${Yr++}`;this.processChain(new qr(new Wy(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}childSelector(){if(this.invalidContinuationAfterPseudoelement("child selector"))return;let e=`c${Yr++}`;this.processChain(new qr(new Gy(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}adjacentSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("adjacent sibling selector"))return;let e=`a${Yr++}`;this.processChain(new qr(new jy(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}followingSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("following sibling selector"))return;let e=`f${Yr++}`;this.processChain(new qr(new Xy(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}nextSelector(){this.finishChain(),this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.footnoteContent=!1,this.specificity=0,this.chain=[]}startSelectorRule(){this.isInsideSelectorRule("E_CSS_UNEXPECTED_SELECTOR")||(this.state=1,this.elementStyle={},this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.specificity=0,this.footnoteContent=!1,this.chain=[],this.invalid=!1)}error(e,t){super.error(e,t),this.state==1&&(this.state=0),this.setInvalid()}startStylesheet(e){super.startStylesheet(e),this.state=0}startRuleBody(){this.finishChain(),super.startRuleBody(),this.state==1&&(this.state=0)}endRule(){super.endRule(),this.insideSelectorRule=0}finishChain(){this.chain&&(this.processChain(this.makeApplyRuleAction(this.specificity)),this.chain=null,this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0)}makeApplyRuleAction(e){let t=this.regionId;return this.footnoteContent&&(t?t="xxx-bogus-xxx":t="footnote"),new ml(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new ha(t,0,this.condition):i=new V(t,0),Vd(this.elementStyle,e).push(i)}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){e=="display"&&(t===v.oeb_page_head||t===v.oeb_page_foot)&&(this.simpleProperty("flow-options",new J([v.exclusive,v._static]),i),this.simpleProperty("flow-into",t,i),t=v.block),Dt("SIMPLE_PROPERTY").forEach(o=>{let s=o({name:e,value:t,important:i});e=s.name,t=s.value,i=s.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),r=this.condition?new ha(t,n,this.condition):new V(t,n);Gt(this.elementStyle,e,r)}finish(){return this.cascade}startFuncWithSelector(e,t){let i;switch(e){case"is":i=new In(this);break;case"not":i=new rv(this);break;case"where":i=new ov(this);break;case"has":i=new sv(this);break;case"nth-child":t&&t.length>=2&&(i=new Qd(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new av(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},nv={"nth-child":My,"nth-of-type":pa,"nth-last-child":fa,"nth-last-of-type":ga},Yr=0,In=class Jd extends wr{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),this.parent=t,c(this,"parentChain"),c(this,"chains",[]),c(this,"maxSpecificity",0),c(this,"selectorTexts",[]),c(this,"containsPseudoelementSelector",!1),this.parentChain=t.chain}nextSelector(){this.containsPseudoelementSelector||(this.containsPseudoelementSelector=!!this.pseudoelement),this.chain&&this.chains.push(this.chain),this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.chain=[],this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0}endFuncWithSelector(){var t;this.containsPseudoelementSelector||(this.containsPseudoelementSelector=!!this.pseudoelement),this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(this.relational()?new $y(this.selectorTexts):this.positive()?new wl(this.chains):new Uy(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity),(t=this.parent).selectorFunctionContainsPseudoelement||(t.selectorFunctionContainsPseudoelement=this.containsPseudoelementSelector)):this.parentChain.push(new et("")),this.owner.popHandler()}startRuleBody(){this.reportAndSkip("E_CSS_UNEXPECTED_RULE_BODY")}error(t,i){super.error(t,i),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0;let n=!1;for(let r=this;r instanceof Jd;r=r.parent)if(r.forgiving()){n=!0;break}n||this.owner.popHandler()}pushSelectorText(t){this.chain&&this.relational()&&this.selectorTexts.push(t)}positive(){return!0}increasingSpecificity(){return!0}forgiving(){return!0}relational(){return!1}},rv=class extends In{positive(){return!1}forgiving(){return!1}},ov=class extends In{increasingSpecificity(){return!1}},sv=class extends In{relational(){return!0}},Qd=class extends In{constructor(e,t,i){super(e),this.a=t,this.b=i}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Wd(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new et("")),this.owner.popHandler()}forgiving(){return!0}},av=class extends Qd{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Hy(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new et("")),this.owner.popHandler()}},lv=class extends Xi{constructor(e,t){super(e,t,!1)}property(e,t,i){if(this.scope.values[e])this.error(`E_CSS_NAME_REDEFINED ${e}`,this.getCurrentToken());else{let n=e.match(/height|^(top|bottom)$/)?"vh":"vw",r=new Er(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,r))}}},so=class extends Xi{constructor(e,t,i,n,r,o){super(e,t,!1),this.condition=i,this.elementStyle=n,this.validatorSet=r,this.ruleType=o,c(this,"order"),this.order=0}property(e,t,i){i?j.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){j.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){j.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=yl;let r=this.condition?new ha(t,n,this.condition):new V(t,n);Gt(this.elementStyle,e,r)}},hv=class extends Yc{constructor(e,t){super(e),this.validatorSet=t,c(this,"elementStyle",{}),c(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){j.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){j.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?qc:Xc;n+=this.order,this.order+=yl;let r=new V(t,n);Gt(this.elementStyle,e,r)}};function ep(e,t){let i=Dd(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function wa(e,t,i){ep(i,n=>{or(e,n,t)})}function uv(e,t,i,n){let r=new hv(e,t),o=new Vt(n,r);try{aw(o,r,i)}catch(s){j.warn(s,"Style attribute parse error:")}return r.elementStyle}function tp(e,t,i){let n=e["writing-mode"];if(n){let r=n.evaluate(t,"writing-mode");if(r&&r!==v.inherit&&r!==v.revert&&r!==v.unset)return r===v.vertical_rl}return i}function ip(e,t,i){let n=e.direction;if(n){let r=n.evaluate(t,"direction");if(r&&r!==v.inherit&&r!==v.revert&&r!==v.unset)return r===v.rtl}return i}function ya(e,t,i,n,r){let o={};for(let s in e)Di(s)&&(o[s]=me(e,s));return wa(o,t,e),np(e,i,n,(s,a)=>{or(o,a,t),wa(o,t,a)}),o}function np(e,t,i,n){let r=gt(e,"_regions");if((t||i)&&r){if(i){let o=["footnote"];t?t=t.concat(o):t=o}for(let o of t){let s=r[o];s&&n(o,s)}}}function or(e,t,i){for(let n in t)if(Di(n)){let r=me(t,n),o=e[n];e[n]=ca(i,o,r)}}var rp=(e,t,i,n,r,o)=>{var s,a;let h=i?n?wy:Od:n?yy:Bd,l=r?vy:by;for(let u in e){let d=e[u];if(!d)continue;let p=(s=h[u])!=null?s:h[l[u]],f=(a=l[u])!=null?a:l[h[u]],g=p??f,m;if(g){let w=e[g];if(w&&w.priority>d.priority||p&&f&&p!==f&&(g=f,w=e[g],w&&w.priority>d.priority))continue;m=Ih[p]?p:Ih[f]?f:u}else m=u,u.startsWith("text-align")&&(d.value===v.inside||d.value===v.outside)&&(d=new V(r===(d.value===v.inside)?v.right:v.left,d.priority));t[m]=o(u,d)}},cv=class extends Gi{constructor(e,t,i){super(),this.elementStyles=e,this.styler=t,this.element=i}getVarValue(e){var t,i,n,r,o;let s=(t=this.element)!=null?t:this.styler.root;if((i=this.elementStyles)!=null&&i.length){for(let a of this.elementStyles){let h=(n=a[e])==null?void 0:n.value;if(h)return h}this.element&&(s=this.element.parentElement)}for(;s;s=s.parentElement){let a=(o=(r=this.styler.getStyle(s,!1))==null?void 0:r[e])==null?void 0:o.value;if(a)return a}return null}visitFunc(e){if(e.name!=="var")return super.visitFunc(e);let t=e.values[0]instanceof de&&e.values[0].name;return!t||!Qt(t)?(this.error=!0,Y):this.getVarValue(t)||(e.values.length<2?(this.error=!0,Y):e.values.length===2?e.values[1]:new it(e.values.slice(1)))}},op=class extends Gi{constructor(e,t,i,n){super(),this.context=e,this.resolveViewportUnit=t,this.percentRef=i,this.vertical=n}visitFunc(e){let t=super.visitFunc(e);if(e.name!=="calc")return t;let i=t.toString().replace(/^calc\b/,"-epubx-expr");if(/\d(%|em|ex|cap|ch|ic|lh|p?v[whbi]|p?vmin|p?vmax)\W|\Wvar\(\s*--/i.test(i))return t;let n=Rr(this.context.rootScope,new Vt(i,null),"");if(n instanceof G)try{let r=n.expr.evaluate(this.context);typeof r=="number"&&!isNaN(r)&&(/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(i)?t=new R(r,"px"):/\d[a-z]/i.test(i)||(t=new Ct(r)))}catch(r){j.warn(r)}return t}visitNumeric(e){return this.resolveViewportUnit&&Hu(e.unit)||this.context.rootFontSize!=null&&fg(e.unit)?new R(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new R(e.num*this.percentRef/100,"px"):e}};function zo(e,t,i,n,r){try{if(t instanceof G)return t.expr instanceof Re&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:uw(e,t.expr,i);if(t instanceof R||t instanceof ci||t instanceof J||t instanceof it)return t.visit(new op(e,!0,n,r))}catch(o){return j.warn(o),Y}return t}var Lh={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Oh(e){let t=e instanceof nt?e:typeof e=="string"?M(e):v.none;if(t===v.none)return Lh;let i=t instanceof J?t.values:[t],n=Object.create(Lh);for(let r of i)if(r instanceof de)switch(r.name){case"first":n.first=!0;break;case"force-end":n.forceEnd=!0,n.allowEnd=!1;break;case"allow-end":n.forceEnd=!1,n.allowEnd=!0;break;case"last":n.last=!0;break}return n}function Bh(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var dv={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},Mh={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},_h={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Dh(e){let t=e instanceof nt?e:typeof e=="string"?M(e):v.normal;if(t===v.normal)return Mh;if(t===v.auto)return _h;let i=t instanceof J?t.values:[t],n=Object.create(Mh);for(let r of i)if(r instanceof de)switch(r.name){case"trim-both":case"trim-auto":return _h;case"space-all":return dv;case"trim-start":n.trimStart=!0,n.spaceFirst=!1;break;case"space-start":n.trimStart=!1,n.spaceFirst=!1;break;case"space-first":n.trimStart=!1,n.spaceFirst=!0;break;case"trim-end":n.trimEnd=!0,n.allowEnd=!1;break;case"space-end":n.trimEnd=!1,n.allowEnd=!1;break;case"allow-end":n.trimEnd=!1,n.allowEnd=!0;break;case"trim-adjacent":n.trimAdjacent=!0;break;case"space-adjacent":n.trimAdjacent=!1;break}return n}var Ps={ideographAlpha:!1,ideographNumeric:!1},pv={ideographAlpha:!0,ideographNumeric:!0};function zh(e){let t=e instanceof nt?e:typeof e=="string"?M(e):v.normal;if(t===v.normal||t===v.auto)return pv;if(t===v.none)return Ps;let i=t instanceof J?t.values:[t],n=Object.create(Ps);for(let r of i)if(r instanceof de)switch(r.name){case"no-autospace":return Ps;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Vh(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function Uh(e){return e?(e=e.toLowerCase(),/^zh\b.*-(hant|tw|hk)\b/.test(e)?"zh-hant":/^zh\b/.test(e)?"zh-hans":/^ja\b/.test(e)?"ja":/^ko\b/.test(e)?"ko":e):null}var fv=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(e){e.body&&this.preprocessForTextSpacing(e.body)}preprocessForTextSpacing(e){var t;let i=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT);for(let n=i.nextNode();n;n=i.nextNode()){if(n.parentElement.namespaceURI!=="http://www.w3.org/1999/xhtml"||((t=n.parentElement.dataset)==null?void 0:t.mathTypeset)==="true")continue;let r=n.textContent.replace(/(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000]\p{M}*(?=\P{M})|.(?=(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000])|(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*(?=(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}])|(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}]\p{M}*(?=(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF])/gsu,"$&\0").split("\0");if(r.length>1){let o=r.length-1;for(let s=0;s<o;s++)n.parentNode.insertBefore(document.createTextNode(r[s]),n);n.textContent=r[o]}}}processGeneratedContent(e,t,i,n,r,o){r=Uh(r);let s=zh(t),a=Dh(i),h=Oh(n);if(Bh(h)&&Vh(s,a))return;this.preprocessForTextSpacing(e);let l=e.style.whiteSpace;(o?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let u=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),d=null,p=null;for(let f=u.nextNode();f;f=p){p=u.nextNode();let g=!d,m=!d||/\n$/.test(d.textContent),w=!p||/^\n/.test(p.textContent),x=!p;this.processTextSpacing(f,g||m,g,m,w,x,d,p,s,a,h,r,o),d=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,r,o,s,a,h,l;let u=!e||e.fragmentIndex===1&&f(),d=u||g();function p(y){var b;if(y?.nodeType!==1)return!1;let S=y;if(S.hasAttribute(Pn))return!0;let{position:C,float:N}=(b=S.style)!=null?b:{};return C==="absolute"||C==="fixed"||N&&N!=="none"}function f(){let y=t[0];for(let b=y;;b=b.parent)if(!b||!b.inline){if(b?.fragmentIndex!==1)return!1;break}if(!y.inline)return!0;for(let b=y.viewNode.previousSibling;b;b=b.previousSibling)if(!Le(b,y.whitespace)&&!p(b))return!1;return!0}function g(){var y,b;let S=t[0],C;for(;S&&S.inline&&(C=(y=S.viewNode)==null?void 0:y.previousSibling,!(C&&(C.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(C.textContent)&&S.whitespace!==ft.PRESERVE&&(C=C.previousSibling),C)));)S=S.parent;for(;C;){if(C.nodeType===Node.ELEMENT_NODE){if(C.localName==="br")return!0;let N=(b=C.style)==null?void 0:b.display;if(N&&N!=="inline")return!/^(inline|ruby)\b/.test(N)}else if(C.nodeType===Node.TEXT_NODE){if(S.whitespace===ft.PRESERVE){if(/\n$/.test(C.textContent))return!0}else if(S.whitespace===ft.NEWLINE&&/\n[ \t\r\n\f]*$/.test(C.textContent))return!0}C=C.lastChild}return!1}let m=-1;for(let y=0;y<t.length;y++){let b=t[y];if(!b.after&&b.inline&&!b.display&&b.parent&&b.viewNode.parentNode&&b.viewNode.nodeType===Node.TEXT_NODE&&!Le(b.viewNode,b.whitespace)){let S=function(P){var A,O,z;if(((A=P.viewNode)==null?void 0:A.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((O=P.viewNode)==null?void 0:O.nodeType)===Node.TEXT_NODE){let W=P.viewNode;if(P.whitespace===ft.PRESERVE){if(/\n$/.test(W.textContent))return!0}else if(P.whitespace===ft.NEWLINE&&/\n[ \t\r\n\f]*$/.test(W.textContent))return!0;if(((z=W.previousElementSibling)==null?void 0:z.localName)==="br")return Le(W,P.whitespace)}return!1},C=function(P){var A,O,z;if(((A=P.viewNode)==null?void 0:A.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((O=P.viewNode)==null?void 0:O.nodeType)===Node.TEXT_NODE){let W=P.viewNode;if(P.whitespace===ft.PRESERVE){if(/^\n/.test(W.textContent))return!0}else if(P.whitespace===ft.NEWLINE&&/^[ \t\r\n\f]*\n/.test(W.textContent))return!0;if(((z=W.nextElementSibling)==null?void 0:z.localName)==="br")return Le(W,P.whitespace)}return!1};var w=S,x=C;m<0&&(m=y);let N=Uh((o=(n=(i=b.lang)!=null?i:b.parent.lang)!=null?n:e?.lang)!=null?o:(r=e?.parent)==null?void 0:r.lang),F=zh(b.inheritedProps["text-autospace"]),B=Dh(b.inheritedProps["text-spacing-trim"]),U=Oh(b.inheritedProps["hanging-punctuation"]);if(Bh(U)&&Vh(F,B)||/\b(flex|grid)\b/.test(b.parent.display))continue;let q=null,he=null,ae=y===m,k=y===m&&u,_=y===m&&d,E=!1,L=!1;for(let P=y-1;P>=0;P--){let A=t[P];if(S(A)){_=!0;break}if(!A.display&&A.viewNode.nodeType===Node.TEXT_NODE&&A.viewNode.textContent.length>0){q=A.viewNode;break}if(((s=A.viewNode)==null?void 0:s.nodeType)===Node.ELEMENT_NODE&&Kt(A.viewNode)==="footnote-call"){if(A.viewNode.contains(b.viewNode))continue;let O=Sw(A.viewNode);if(O){q=O;break}}if(A.display&&!/^(inline|ruby)\b/.test(A.display)||((a=A.viewNode)==null?void 0:a.nodeType)===Node.ELEMENT_NODE&&(A.viewNode.localName==="br"||_i[A.viewNode.localName]))break;P===0&&(ae=!0,u&&(k=!0,_=!0))}for(let P=y+1;P<t.length;P++){let A=t[P];if(C(A)){E=!0;break}if(A.viewNode!==b.viewNode&&!A.display&&A.viewNode.nodeType===Node.TEXT_NODE&&A.viewNode.textContent.length>0){he=A.viewNode;break}if(A.display&&!/^(inline|ruby)\b/.test(A.display)||((h=A.viewNode)==null?void 0:h.nodeType)===Node.ELEMENT_NODE&&(A.viewNode.localName==="br"||_i[A.viewNode.localName])){P===t.length-1&&p(A.viewNode)&&(L=!0);break}if(P===t.length-1){E=!0,L=!0;for(let O=A.viewNode.nextSibling;O;O=O.nextSibling)if(!p(O)){L=!1;break}}}if(((l=b.parent)==null?void 0:l.display)==="inline-block"){if(!k){let P=b.parent.viewNode.firstChild;for(;Le(P,b.whitespace);)P=P.nextSibling;b.viewNode===P&&(k=!0)}if(!L){let P=b.parent.viewNode.lastChild;for(;Le(P,b.whitespace);)P=P.previousSibling;b.viewNode===P&&(L=!0)}}if(this.processTextSpacing(b.viewNode,ae,k,_,E,L,q,he,F,B,U,N,b.vertical)>0)break}}}processTextSpacing(e,t,i,n,r,o,s,a,h,l,u,d,p){let f=e.textContent,g=e.ownerDocument,m=0,w,x,y;function b(){if(t)return!0;if(!s)return!1;w||(w=g.createRange(),w.selectNode(e));let E=w.getClientRects()[0];if(!E)return!1;x||(x=g.createRange(),x.selectNode(s));let L=x.getClientRects(),P=L[L.length-1];return P?(m||(m=fr(P,p)),p?E.top<P.top+P.height-E.width||E.left+E.width<P.left+E.width/10||E.left>P.left+P.width-E.width/10:E.left<P.left+P.width-E.height||E.top>P.top+P.height-E.height/10||E.top+E.height<P.top+E.height/10):!1}function S(){if(!a)return!1;w||(w=g.createRange(),w.selectNode(e));let E=w.getClientRects()[0];if(!E)return!1;m||(m=fr(E,p)),y||(y=g.createRange(),y.selectNode(a));let L=y.getClientRects()[0];return L?p?E.top+E.height>L.top+E.width||E.left>L.left+L.width-E.width/10||E.left+E.width<L.left+E.width/10:E.left+E.width>L.left+E.height||E.top+E.height<L.top+E.height/10||E.top>L.top+L.height-E.height/10:!1}let C=!1,N=!1,F=!1,B=!1,U;if(i&&u.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(U="viv-ts-open",C=!0,N=!0):o&&u.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(U="viv-ts-close",C=!0,F=!0):(u.forceEnd||u.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(U="viv-ts-close",C=!0,B=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(U="viv-ts-open",C=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||d==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||d!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(U="viv-ts-close",C=!0),C){let E=function(z){let W=parseFloat(g.defaultView.getComputedStyle(z).fontSize)*.7;return(p?z.offsetHeight:z.offsetWidth)>W},L=function(){return p?P.offsetLeft:P.offsetTop};var q=E,he=L;if(e.parentElement.localName==="viv-ts-inner")return 0;let P=g.createElement(U),A=g.createElement("viv-ts-inner");P.appendChild(A),e.parentNode.insertBefore(P,e),A.appendChild(e);let O=E(A);if(O||N||F||B){if(U==="viv-ts-open"){if(N)P.className="viv-hang-first";else if(i||n)l.trimStart?P.className="viv-ts-trim":P.className="viv-ts-space";else if(!(l.trimStart||l.spaceFirst)&&b())P.className="viv-ts-space";else if(l.trimAdjacent&&s&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(s.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(s.textContent)||s.parentElement.localName==="viv-ts-inner"&&E(s.parentElement)))P.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&b()){let z=L();P.className="viv-ts-auto",z===L()&&!b()&&(P.className="viv-ts-trim")}}else if(U==="viv-ts-close"){if(F)P.className=O?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(o||r){let z=L();B?(P.className=O?u.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",u.allowEnd&&z===L()&&(l.trimEnd?P.className="viv-ts-trim":l.allowEnd?(P.className="viv-hang-end",z===L()&&(P.className="")):P.className="viv-ts-space")):l.trimEnd?P.className="viv-ts-trim":l.allowEnd?(P.className="viv-ts-auto",z===L()&&(P.className="")):P.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))O&&l.trimAdjacent&&(P.className="viv-ts-trim");else if(B){let z=S(),W=z&&u.allowEnd;W||(P.className=O?"viv-hang-end":"viv-hang-end viv-hang-hw"),O?W&&l.trimEnd?P.className="viv-ts-auto":!W&&!S()?P.className="":!z&&u.allowEnd&&(l.trimEnd?(P.className="viv-ts-auto",S()||(P.className="viv-hang-end")):(P.className="viv-ts-space",S()||(l.allowEnd?(P.className="viv-ts-auto",S()||(P.className="viv-hang-end")):P.className="viv-hang-end"))):!z&&!S()&&(P.className="")}else if(l.trimEnd||l.allowEnd)if(S())l.allowEnd?P.className="viv-ts-space":P.className="viv-ts-auto";else{let z=L();P.className="viv-ts-auto",z===L()&&(P.className="")}}}}let ae=!1;function k(E){var L;let P=(L=E?.ownerDocument.defaultView)==null?void 0:L.getComputedStyle(E);return!!P&&(P.textOrientation==="upright"||P.textCombineUpright==="all"||P["-webkit-text-combine"]==="horizontal")}function _(E,L){if(E.nodeType===Node.ELEMENT_NODE){let O=g.defaultView.getComputedStyle(E);if(parseFloat(O.marginInlineEnd)||parseFloat(O.borderInlineEndWidth)||parseFloat(O.paddingInlineEnd))return!0}let P=E.parentElement;if(P&&!P.contains(L))return _(P,L);if(L.nodeType===Node.ELEMENT_NODE){let O=g.defaultView.getComputedStyle(L);if(parseFloat(O.marginInlineStart)||parseFloat(O.borderInlineStartWidth)||parseFloat(O.paddingInlineStart))return!0}let A=L.parentElement;return A&&!A.contains(E)?_(E,A):!1}return(h.ideographAlpha||h.ideographNumeric)&&(s&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(h.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(s.textContent)||h.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(s.textContent))&&!(p&&k(s.parentElement))&&!_(s,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),ae=!0),a&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(f)&&(h.ideographAlpha&&/^(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}/u.test(a.textContent)||h.ideographNumeric&&/^(?![\uFF01-\uFF60])\p{Nd}/u.test(a.textContent))&&!(p&&k(a.parentElement))&&!_(e,a)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e.nextSibling),ae=!0)),m}registerHooks(){At("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),At("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),At("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},vl=new fv;vl.registerHooks();function gv(e){vl.preprocessForTextSpacing(e)}function mv(e,t,i,n,r,o){vl.processGeneratedContent(e,t,i,n,r,o)}var qn=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),wv=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","footnote-call","","after"],bl="data-adapt-pseudo";function Kt(e){return e.getAttribute(bl)||""}function sr(e,t){e.setAttribute(bl,t)}var Ns=class{constructor(e,t,i,n,r){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=r,c(this,"contentProcessed",{})}getStyle(e,t){let i=Kt(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=gt(this.style,"_pseudos"),r=n?.[i]||{};if(i.match(/^first-/)&&!r["x-first-pseudo"]){let o=1,s;i=="first-letter"?o=0:(s=i.match(/^first-([0-9]+)-lines$/))!=null&&(o=s[1]-0),r["x-first-pseudo"]=new V(new Ue(o),0)}return r}processContent(e,t,i){let n=Kt(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let r=t.content;kt(r)&&(r.visit(new gr(e,this.context,r,this.exprContentListener)),gv(e))}}},jx=Fo.isInstanceOfAfterIfContinuesLayoutConstraint,yv=os.registerFragmentIndex,Xx=os.clearFragmentIndices,vv=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new xl(e,i,t),r=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=r;let o=i.firstChild;return I(o,"display","block"),T(o)})}createNodePositionForPseudoElement(){let e=qn.createElementNS("http://www.w3.org/1999/xhtml","div");sr(e,"after-if-continues");let t=this.createShadowContext(e),i={steps:[{node:e,shadowType:t.type,shadowContext:t,nodeShadow:null,shadowSibling:null}],offsetInNode:0,after:!1,preprocessedTextContent:null};return new Ei(i)}createShadowContext(e){return new no(this.sourceNode,e,null,null,null,li.ShadowType.ROOTED,this.styler)}},bv=class sp{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,c(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,i,n){return!(i&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,i,n,r){}finishBreak(t,i){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(i,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),T(!0))):T(!0)}getRepetitiveElements(){return new xv(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof sp?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},xv=class{constructor(e,t){this.nodeContext=e,this.pseudoElementHeight=t}calculateOffset(e){return this.affectTo(e)?this.pseudoElementHeight:0}calculateMinimumOffset(e){return this.calculateOffset(e)}affectTo(e){if(!e)return!1;let t=e.shadowContext?e.shadowContext.owner:e.sourceNode;if(t===this.nodeContext.sourceNode)return!!e.after;for(let i=t.parentNode;i;i=i.parentNode)if(i===this.nodeContext.sourceNode)return!0;return!1}};function ap(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return T(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let r=Cv(e,t,n);return t.fragmentLayoutConstraints.push(new bv(e,i,r)),T(e)})}function lp(e,t){return e.thenAsync(i=>ap(i,t))}function Sv(e,t){let i=D("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let r=ap(n,t);return n=n.parent,r.thenReturn(!0)}else return T(!1)}).then(()=>{i.finish(!0)}),i.result()}function Cv(e,t,i){let n=e.viewNode;n.appendChild(i);let r=ea(i,t,e.vertical);return n.removeChild(i),r}var kv=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},Yn=class extends ul{constructor(e,t){super(),this.checkPoints=e,this.penalty=t,c(this,"alreadyEvaluated",!1),c(this,"breakNodeContext",null)}findAcceptableBreak(e,t){return t<this.getMinBreakPenalty()?null:(this.alreadyEvaluated||(this.breakNodeContext=e.findBoxBreakPosition(this,t>0),this.alreadyEvaluated=!!this.breakNodeContext||t>0||!!e.pseudoParent),this.breakNodeContext)}getMinBreakPenalty(){return this.penalty}getNodeContext(){return this.alreadyEvaluated?this.breakNodeContext:this.checkPoints[this.checkPoints.length-1]}},Vo=class extends Cd{constructor(e,t,i,n,r){super(e),this.layoutContext=t,this.clientLayout=i,this.layoutConstraint=n,this.pageFloatLayoutContext=r,c(this,"last"),c(this,"viewDocument"),c(this,"flowRootFormattingContext",null),c(this,"isNonFirstColumn",!1),c(this,"isFloat",!1),c(this,"isFootnote",!1),c(this,"startEdge",0),c(this,"endEdge",0),c(this,"beforeEdge",0),c(this,"afterEdge",0),c(this,"footnoteEdge",0),c(this,"box",null),c(this,"chunkPositions",null),c(this,"bands",null),c(this,"overflown",!1),c(this,"breakPositions",null),c(this,"pageBreakType",null),c(this,"forceNonfitting",!0),c(this,"leftFloatEdge",0),c(this,"rightFloatEdge",0),c(this,"bottommostFloatTop",0),c(this,"stopAtOverflow",!0),c(this,"lastAfterPosition",null),c(this,"fragmentLayoutConstraints",[]),c(this,"pseudoParent",null),c(this,"nodeContextOverflowingDueToRepetitiveElements",null),c(this,"blockDistanceToBlockEndFloats",NaN),c(this,"lastLineStride",0),c(this,"breakAtTheEdgeBeforeFloat",null),mw(this),this.last=e.lastChild,this.viewDocument=e.ownerDocument,r.setContainer(this)}getTopEdge(){return this.vertical?this.rtl?this.endEdge:this.startEdge:this.beforeEdge}getBottomEdge(){return this.vertical?this.rtl?this.startEdge:this.endEdge:this.afterEdge}getLeftEdge(){return this.vertical?this.afterEdge:this.rtl?this.endEdge:this.startEdge}getRightEdge(){return this.vertical?this.beforeEdge:this.rtl?this.startEdge:this.endEdge}isFloatNodeContext(e){return!!e.floatSide&&(!this.isFloat||!!e.parent)}stopByOverflow(e){return this.stopAtOverflow&&!!e&&e.overflow}almostEquals(e,t,i=this.clientLayout.pixelRatio===0?.5:1.5/(this.clientLayout.pixelRatio||1)){return Math.abs(e-t)<i}getFloatLayoutUnit(){return this.clientLayout.pixelRatio===0?0:1/(this.clientLayout.pixelRatio||1)}getFloatLayoutTolerance(e){return e||1}isOverflown(e){let t=1.5/(this.clientLayout.pixelRatio||1);return this.almostEquals(e,this.footnoteEdge,t)?!1:this.vertical?e<this.footnoteEdge:e>this.footnoteEdge}getExclusions(){let e=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(e)}openAllViews(e){let t=D("openAllViews"),i=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let n=i.length-1,r=null;return t.loop(()=>{for(;n>=0;){let o=r,s=i[n];if(r=Lo(s,o),n===i.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),n==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),r.after=e.after,r.preprocessedTextContent=e.preprocessedTextContent,r.after))break;let a=this.layoutContext.setCurrent(r,n==0&&r.offsetInNode==0);if(n--,a.isPending())return a}return T(!1)}).then(()=>{t.finish(r)}),t.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?Lw(e.preprocessedTextContent,e.offsetInNode):e.offsetInNode}maybePeelOff(e,t){var i,n;if(e.firstPseudo&&e.inline&&!e.after&&e.firstPseudo.count==0&&e.viewNode.nodeType!=1){let r=e.viewNode.textContent,o=r.match(Co),s=o?o[0].length:0;if(!o&&((i=e.sourceNode)==null?void 0:i.nodeType)===3&&((n=e.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&r===e.sourceNode.textContent){let a=r+e.sourceNode.nextSibling.textContent,h=a.match(Co);if(h){let l=h[0];s=l.length,e.sourceNode.textContent=l,e.viewNode.textContent=l,e.sourceNode.nextSibling.textContent=a.substr(s)}}return this.layoutContext.peelOff(e,s)}return T(e)}buildViewToNextBlockEdge(e,t){let i=!1,n=D("buildViewToNextBlockEdge");return n.loopWithFrame(r=>{var o;if(e.viewNode&&!pn(e)&&((o=e.viewNode.parentElement)==null?void 0:o.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(t.push(e.copy()),t.length>1e3)){let s=e.viewNode.nodeType===1?e.viewNode:e.viewNode.parentElement,a=this.clientLayout.getElementClientRect(s);if(fr(a,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(s=>{let a=s;a!==e&&(e=a,pn(e)||t.push(e.copy())),this.nextInTree(e).then(h=>{if(e=h,!e){r.breakLoop();return}(i||!this.layoutConstraint.allowLayout(e))&&(i=!0,e=e.modify(),e.overflow=!0),this.isFloatNodeContext(e)&&(Si(e.floatReference)||e.floatSide==="footnote")?this.layoutFloatOrFootnote(e).then(l=>{if(e=l,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()}):e.inline?r.continueLoop():r.breakLoop()})})}).then(()=>{n.finish(e)}),n.result()}nextInTree(e,t){let i=this.layoutContext.nextInTree(e,t);return lp(i,this)}buildDeepElementView(e){if(!e.viewNode)return T(e);let t=[],i=e.sourceNode,n=D("buildDeepElementView");return n.loopWithFrame(r=>{e.viewNode&&e.inline&&!pn(e)?t.push(e.copy()):(t.length>0&&this.postLayoutBlock(e,t),t=[]),this.maybePeelOff(e,0).then(o=>{let s=o;if(s!==e){let a=s;for(;a&&a.sourceNode!=i;)a=a.parent;if(a==null){e=s,r.breakLoop();return}pn(s)||t.push(s.copy())}this.nextInTree(s).then(a=>{if(e=a,!e||e.sourceNode==i){r.breakLoop();return}if(!this.layoutConstraint.allowLayout(e)&&(e=e.modify(),e.overflow=!0,this.stopAtOverflow)){r.breakLoop();return}if(this.isFloatNodeContext(e)&&(Si(e.floatReference)||e.floatSide==="footnote")){this.layoutFloatOrFootnote(e).then(h=>{if(e=h,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()});return}r.continueLoop()})})}).then(()=>{t.length>0&&this.postLayoutBlock(e,t),n.finish(e)}),n.result()}createFloat(e,t,i,n){let r=this.viewDocument.createElement("div");return this.vertical?(n>=this.height&&(n-=.1),n<1&&(n=0),I(r,"height",`${i}px`),I(r,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),I(r,"width",`${i}px`),I(r,"height",`${n}px`)),I(r,"float",t),I(r,"clear",t),this.element.insertBefore(r,e),r}killFloats(){let e=this.element.firstChild;for(;e;){let t=e.nextSibling;if(e.nodeType==1){let i=e,n=i.style.cssFloat;if(n=="left"||n=="right"||n==="none")this.element.removeChild(i);else break}e=t}}createFloats(){let e=this.element.firstChild,t=this.bands,i=this.vertical?this.getTopEdge():this.getLeftEdge(),n=this.vertical?this.getBottomEdge():this.getRightEdge(),r=this.vertical?-this.getRightEdge():this.getTopEdge(),o=this.vertical?-this.getLeftEdge():this.getBottomEdge(),s=null,a=1.5/(this.clientLayout.pixelRatio||1);for(let p of t){let f=Math.abs(p.x1-i)<a&&Math.abs(p.x2-n)<a?a:void 0;this.almostEquals(p.x1,i,f)?p.x1=i:this.almostEquals(p.x1,n,f)&&(p.x1=n),this.almostEquals(p.x2,n,f)?p.x2=n:this.almostEquals(p.x2,i,f)&&(p.x2=i),this.almostEquals(p.y1,r,f)?p.y1=r:this.almostEquals(p.y1,o,f)&&(p.y1=o),this.almostEquals(p.y2,o,f)?p.y2=o:this.almostEquals(p.y2,r,f)&&(p.y2=r)}let h=this.getFloatLayoutUnit(),l=Ga==="webkit"?Math.floor:Math.round,u=t.map(p=>h>0?(l(p.y2/h)-l(p.y1/h))*h:p.y2-p.y1),d=.01;for(let p=0;p<t.length;p++){let f=p<t.length-1?t[p+1].x1:i,g=p<t.length-1?t[p+1].x2:n,m=f-t[p].x1,w=t[p].x2-g,x=0,y=0;m>d?x=1:m<-d&&(x=-1),w>d?y=1:w<-d&&(y=-1);let b=x!==0&&y!==0?x===y?x:0:x||y;if(h>0&&b!==0){let S=b*h;u[p]+S>=0&&(p>=t.length-1||u[p+1]-S>=0)&&(u[p]+=S,p<t.length-1&&(u[p+1]-=S))}}for(let p=0;p<t.length;p++){let f=t[p];f.left=this.createFloat(e,"left",f.x1-i,u[p]),f.right=this.createFloat(e,"right",n-f.x2,u[p]),f.x1<n&&f.x2>i?s=f:s||I(f.right,"float","none")}if(s){let p=t[t.length-1],f=1.5/(this.clientLayout.pixelRatio||1);if(s!==p&&(p.y2>=o||this.almostEquals(p.y2,o,f))&&(this.footnoteEdge=this.vertical?-s.y2:s.y2,s.x1===i&&s.x2===n))for(let g=t.indexOf(s);g<t.length;g++){let m=t[g];this.element.removeChild(m.left),this.element.removeChild(m.right),m.left=null,m.right=null}}this.adjustColumnBlockSizeForBlockEndFloats()}adjustColumnBlockSizeForBlockEndFloats(){var e;if(this.element.hasAttribute("data-vivliostyle-in-column-balancing")||(e=this.element.parentElement)!=null&&e.hasAttribute("data-vivliostyle-in-column-balancing"))return;let t=this.vertical?this.width:this.height,i=this.getBoxDir()*(this.footnoteEdge-this.beforeEdge),n=1.5/(this.clientLayout.pixelRatio||1);if(i>0&&i<t&&!this.almostEquals(i,t,n)){let r=this.vertical?"width":"height";if(I(this.element,r,`${i}px`),this.vertical){let o=this.left+(t-i);I(this.element,"left",`${o}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(e,t,i,n){let r;if(e&&dn(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(r=sn(e,this.clientLayout,0,this.vertical),!isNaN(r)))return r;e=t[i];let o=n-e.boxOffset;for(;;){if(r=sn(e,this.clientLayout,o,this.vertical),!isNaN(r))return r;if(o>0){o--;continue}if(i--,i<0)return this.beforeEdge;e=t[i],e.viewNode.nodeType!=1&&(o=e.viewNode.textContent.length)}}parseComputedLength(e){let t=e.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return t?this.clientLayout.adjustLengthValue(parseFloat(t[0])):0}getComputedMargin(e){let t=this.clientLayout.getElementComputedStyle(e),i=new ys(0,0,0,0);return t&&(i.left=this.parseComputedLength(t.marginLeft),i.top=this.parseComputedLength(t.marginTop),i.right=this.parseComputedLength(t.marginRight),i.bottom=this.parseComputedLength(t.marginBottom)),i}getComputedPaddingBorder(e){let t=this.clientLayout.getElementComputedStyle(e),i=new ys(0,0,0,0);return t&&(i.left=this.parseComputedLength(t.borderLeftWidth)+this.parseComputedLength(t.paddingLeft),i.top=this.parseComputedLength(t.borderTopWidth)+this.parseComputedLength(t.paddingTop),i.right=this.parseComputedLength(t.borderRightWidth)+this.parseComputedLength(t.paddingRight),i.bottom=this.parseComputedLength(t.borderBottomWidth)+this.parseComputedLength(t.paddingBottom)),i}getComputedInsets(e){let t=this.clientLayout.getElementComputedStyle(e),i=new ys(0,0,0,0);if(t){if(t.boxSizing=="border-box")return this.getComputedMargin(e);i.left=this.parseComputedLength(t.marginLeft)+this.parseComputedLength(t.borderLeftWidth)+this.parseComputedLength(t.paddingLeft),i.top=this.parseComputedLength(t.marginTop)+this.parseComputedLength(t.borderTopWidth)+this.parseComputedLength(t.paddingTop),i.right=this.parseComputedLength(t.marginRight)+this.parseComputedLength(t.borderRightWidth)+this.parseComputedLength(t.paddingRight),i.bottom=this.parseComputedLength(t.marginBottom)+this.parseComputedLength(t.borderBottomWidth)+this.parseComputedLength(t.paddingBottom)}return i}setComputedInsets(e,t){let i=this.clientLayout.getElementComputedStyle(e);i&&(t.marginLeft=this.parseComputedLength(i.marginLeft),t.borderLeft=this.parseComputedLength(i.borderLeftWidth),t.paddingLeft=this.parseComputedLength(i.paddingLeft),t.marginTop=this.parseComputedLength(i.marginTop),t.borderTop=this.parseComputedLength(i.borderTopWidth),t.paddingTop=this.parseComputedLength(i.paddingTop),t.marginRight=this.parseComputedLength(i.marginRight),t.borderRight=this.parseComputedLength(i.borderRightWidth),t.paddingRight=this.parseComputedLength(i.paddingRight),t.marginBottom=this.parseComputedLength(i.marginBottom),t.borderBottom=this.parseComputedLength(i.borderBottomWidth),t.paddingBottom=this.parseComputedLength(i.paddingBottom))}setComputedWidthAndHeight(e,t){let i=this.clientLayout.getElementComputedStyle(e);i&&(t.width=this.parseComputedLength(i.width),t.height=this.parseComputedLength(i.height))}layoutUnbreakable(e){return this.buildDeepElementView(e)}layoutFloat(e){let t=D("layoutFloat"),i=e.viewNode,n=Cs(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return I(i,"float","none"),I(i,"display","inline-block"),I(i,"vertical-align","top"),this.buildDeepElementView(e).then(r=>{let o=Tt(this.clientLayout,i,this.vertical),s=this.getComputedMargin(i),a=new It(o.left-s.left,o.top-s.top,o.right+s.right,o.bottom+s.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,u=e.parent;for(;u&&u.inline;)u=u.parent;if(u){let S=u.viewNode.ownerDocument.createElement("div");S.style.left="0px",S.style.top="0px",this.vertical?(S.style.bottom="0px",S.style.width="1px"):(S.style.right="0px",S.style.height="1px"),u.viewNode.appendChild(S);let C=Tt(this.clientLayout,S,this.vertical);h=Math.max(this.rtl?this.getEndEdge(C):this.getStartEdge(C),h),l=Math.min(this.rtl?this.getStartEdge(C):this.getEndEdge(C),l),u.viewNode.removeChild(S);let N=this.vertical?a.y2-a.y1:a.x2-a.x1;n=="left"?l=Math.max(l,h+N):h=Math.min(h,l-N),u!==e.parent&&!e.firstPseudo&&(u.viewNode.appendChild(i),i.setAttribute("data-vivliostyle-float-box-moved","true"))}let d=new It(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),p=a;this.vertical&&(p=Po(a));let f=this.getBoxDir();if(p.y1<this.bottommostFloatTop*f){let S=p.y2-p.y1;p.y1=this.bottommostFloatTop*f,p.y2=p.y1+S}if(e.clearSide){let S=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(e.clearSide)?Cs(e.clearSide,e.vertical,e.direction,this.layoutContext.page.side):e.clearSide==="same"?n:e.clearSide,C=this.beforeEdge;S!=="right"&&(C=f*Math.max(C*f,this.leftFloatEdge*f)),S!=="left"&&(C=f*Math.max(C*f,this.rightFloatEdge*f));let N=C*f;if(p.y1<N){let F=p.y2-p.y1;p.y1=N,p.y2=p.y1+F}}d.y2+=this.getFloatLayoutUnit(),$g(d,this.bands,p,n),this.vertical&&(a=vc(p));let g=this.getComputedInsets(i);I(i,"width",`${a.x2-a.x1-g.left-g.right}px`),I(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),I(i,"position","absolute"),e.display,I(i,"display",e.display);let m,w=null;if(u&&(u.containingBlockForAbsolute?w=u:w=u.getContainingBlockForAbsolute()),w){let S=w.viewNode.ownerDocument.createElement("div");S.style.position="absolute",w.vertical?S.style.right="0":S.style.left="0",S.style.top="0",w.viewNode.appendChild(S),m=Tt(this.clientLayout,S,this.vertical),w.viewNode.removeChild(S)}else m={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};if(w?w.vertical:this.vertical){let S=Math.max(0,m.right-a.x2);I(i,"right",`${S}px`)}else{let S=Math.max(0,a.x1-m.left);I(i,"left",`${S}px`)}let x=Math.max(0,a.y1-m.top);I(i,"top",`${x}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let y=this.vertical?a.x1:a.y2,b=this.vertical?a.x2:a.y1;!this.isOverflown(y)||this.breakPositions.length==0?(this.killFloats(),d=new It(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(d=Po(d)),Hg(d,this.bands,p,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=y:this.rightFloatEdge=y,this.bottommostFloatTop=b,this.updateMaxReachedAfterEdge(y),t.finish(r)):(e=e.modify(),e.overflow=!0,t.finish(e))}),t.result()}setupFloatArea(e,t,i,n,r,o){let s=this.pageFloatLayoutContext,a=s.getContainer(t),h=e.element;a.element.parentNode.appendChild(h),e.isFloat=!0,e.originX=a.originX,e.originY=a.originY,e.vertical=a.vertical,e.rtl=a.rtl,e.marginLeft=e.marginRight=e.marginTop=e.marginBottom=0,e.borderLeft=e.borderRight=e.borderTop=e.borderBottom=0,e.paddingLeft=e.paddingRight=e.paddingTop=e.paddingBottom=0,e.exclusions=(a.exclusions||[]).concat(),e.forceNonfitting=!s.hasFloatFragments(),e.innerShape=null;let l=a.getPaddingRect();return e.setHorizontalPosition(l.x1-a.originX,l.x2-l.x1),e.setVerticalPosition(l.y1-a.originY,l.y2-l.y1),r.adjustPageFloatArea(e,a,this).thenAsync(()=>{e.init();let u=!!s.setFloatAreaDimensions(e,t,i,n,!0,e.isFootnote||!s.hasFloatFragments(),o);if(u){if(e.isFootnote){let d=getComputedStyle(e.element);if(e.vertical){let p=parseFloat(d.maxWidth);!isNaN(p)&&e.width>p&&(e.width=p,I(e.element,"width",`${p}px`))}else{let p=parseFloat(d.maxHeight);!isNaN(p)&&e.height>p&&(e.height=p,I(e.element,"height",`${p}px`))}}e.killFloats(),e.init()}else a.element.parentNode.removeChild(h);return T(u)})}createPageFloatArea(e,t,i,n,r){let o=this.element.ownerDocument.createElement("div");I(o,"position","absolute");let s=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new ln(null,Te.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null);a.setOuterContext(this.pageFloatLayoutContext);let h=s.getContainer(),l=new Nv(t,o,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h);return a.setContainer(l),this.setupFloatArea(l,e.floatReference,t,i,n,r).thenAsync(u=>T(u?l:null))}layoutSinglePageFloatFragment(e,t,i,n,r,o,s){let a=this.pageFloatLayoutContext;e=(s?s.continuations:[]).concat(e);let h=e[0].float,l=a.getPageFloatPlacementCondition(h,t,i),u={floatArea:null,pageFloatFragment:null,newPosition:null},d=D("layoutSinglePageFloatFragment");return this.createPageFloatArea(h,t,o,r,l).then(p=>{if(u.floatArea=p,!p){d.finish(u);return}let f=!1,g=0;d.loopWithFrame(m=>{if(g>=e.length){m.breakLoop();return}let w=e[g],x=new Ei(w.nodePosition),y=p.breakPositions?p.breakPositions.length:0;p.layout(x,!0).then(b=>{if(u.newPosition=b,!b||n){if(b&&p.isFootnote&&p.breakPositions&&!(p.breakPositions.length>y&&p.breakPositions.slice(y).some(S=>S instanceof Yn))){f=!0,m.breakLoop();return}g++,m.continueLoop()}else f=!0,m.breakLoop()})}).then(()=>{if(!f&&p.isFootnote&&p.computedBlockSize<=0&&u.newPosition){let m=a.getPageFloatLayoutContext(h.floatReference);if(m.footnoteMaxBlockSize==null){if(m.initFootnoteRetryFromEmptyFragment(h,p)){p.element.parentNode&&p.element.parentNode.removeChild(p.element),this.layoutSinglePageFloatFragment(e,t,i,n,r,o,s).then(w=>{d.finish(w)});return}f=!0}}if(!f){p.isFootnote&&p.applyCompactFootnoteDisplay();let m=a.setFloatAreaDimensions(p,h.floatReference,t,o,!1,n,l);if(!m)f=!0;else{let w=r.createPageFloatFragment(e,m,i,p,!!u.newPosition);a.addPageFloatFragment(w,!0),u.pageFloatFragment=w}}d.finish(u)})}),d.result()}layoutPageFloatInner(e,t,i,n){let r=this.pageFloatLayoutContext,o=e.float,s=new Set;for(let u=r;u;u=u.effectiveParent)for(let d of u.floatFragments)d.continuations.some(p=>p.float.insidePageFloatArea)&&s.add(d);r.stashEndFloatFragments(o);function a(u,d){d?r.removePageFloatFragment(d,!0):u&&u.element.parentNode.removeChild(u.element);let p=[];for(let f=r;f;f=f.effectiveParent)for(let g of f.floatFragments)!s.has(g)&&g.continuations.some(m=>m.float.insidePageFloatArea)&&p.push(g);for(let f of p)r.removePageFloatFragment(f,!0);r.restoreStashedFragments(o.floatReference),r.deferPageFloat(e)}let h=o instanceof Bo,l=D("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],o.floatSide,o.clearSide,h||!r.hasFloatFragments(),t,i,n).then(u=>{let d=u.floatArea,p=u.pageFloatFragment,f=u.newPosition;p?this.layoutStashedPageFloats(o.floatReference,[n]).then(g=>{if(g){let m=!!r.generatingNodePosition;if(r.addPageFloatFragment(p,m),r.discardStashedFragments(o.floatReference),f){let w=new Ph(o,f.primary);r.deferPageFloat(w)}l.finish(!0)}else a(d,p),l.finish(!1)}):(a(d,p),l.finish(!1))}),l.result()}layoutStashedPageFloats(e,t){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(e),r=[],o=[],s=!1,a=D("layoutStashedPageFloats"),h=0;return a.loopWithFrame(l=>{if(h>=n.length){l.breakLoop();return}let u=n[h];if(t.includes(u)){h++,l.continueLoop();return}let d=new Tn().findByFloat(u.continuations[0].float);this.layoutSinglePageFloatFragment(u.continuations,u.floatSide,u.clearSide,!1,d,null).then(p=>{let f=p.floatArea;f&&r.push(f);let g=p.pageFloatFragment;g?(o.push(g),h++,l.continueLoop()):(s=!0,l.breakLoop())})}).then(()=>{s?(o.forEach(l=>{i.removePageFloatFragment(l,!0)}),r.forEach(l=>{let u=l.element;u&&u.parentNode&&u.parentNode.removeChild(u)})):n.forEach(l=>{let u=l.area.element;u&&u.parentNode&&u.parentNode.removeChild(u)}),a.finish(!s)}),a.result()}findFootnoteCallElement(e){let t=e.previousSibling;for(;t;){if(t.nodeType===Node.ELEMENT_NODE&&Kt(t)==="footnote-call")return t;t=t.previousSibling}return null}setFloatAnchorViewNode(e){let t=e.viewNode.parentNode,i=t.ownerDocument.createElement("span");if(i.setAttribute(Pn,"1"),e.floatSide==="footnote"){let r=this.findFootnoteCallElement(e.viewNode);r?i=r:t.insertBefore(i,e.viewNode)}else t.appendChild(i);t.removeChild(e.viewNode);let n=e.modify();return n.after=!0,n.viewNode=i,e.floatSide==="footnote"&&(n.display="inline"),n}resolveFloatReferenceFromColumnSpan(e,t,i){let n=D("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,o=r.getPageFloatLayoutContext(Te.REGION);return r.getContainer().width<o.getContainer().width&&e===Te.COLUMN?t===v.auto?this.buildDeepElementView(i.copy()).then(s=>{let a=s.viewNode,h=sl(this.clientLayout,a,["min-content inline size"])["min-content inline size"],l=this.getComputedMargin(a);this.vertical?h+=l.top+l.bottom:h+=l.left+l.right,h>this.width?n.finish(Te.REGION):n.finish(e)}):t===v.all?n.finish(Te.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new Tn().findByNodeContext(e),n,r=t.findPageFloatByNodePosition(e.toNodePosition());return r?n=T(r):n=i.createPageFloat(e,t,this),n.thenAsync(o=>{let s=Ro(e,0),a=this.setFloatAnchorViewNode(e);t.markPageFloatAnchorSeen(o);let h=i.findPageFloatFragment(o,t),l=new Ph(o,s);if(h&&h.hasFloat(o))return t.registerPageFloatAnchor(o,a.viewNode),T(a);if(t.isForbidden(o)||t.hasPrecedingFloatsDeferredToNext(o))return t.deferPageFloat(l),t.registerPageFloatAnchor(o,a.viewNode),T(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return T(null);{let u=p=>{if(!p||p.nodeType!==1)return NaN;let f=Tt(this.clientLayout,p,this.vertical);return f.right>=f.left&&f.bottom>=f.top?this.vertical?f.left:f.bottom:NaN},d=sn(a,this.clientLayout,0,this.vertical);if(e.floatSide==="footnote"){let p=o;if(p.footnotePolicy===v.line||isNaN(d)){let f=a;for(;f;){if((f.shadowContext?f.shadowContext.owner:f.sourceNode)===p.policyAnchorNode){let g=u(f.viewNode);isNaN(g)||(d=g);break}f=f.parent}}}return isNaN(d)&&e.floatSide==="footnote"&&(d=u(a.viewNode)),this.isOverflown(d)?T(a):this.layoutPageFloatInner(l,i,d,h).thenAsync(p=>p?e.floatSide==="footnote"||t.generatingNodePosition?T(a):T(null):(t.registerPageFloatAnchor(o,a.viewNode),T(a)))}})}processLineStyling(e,t,i){let n=D("processLineStyling"),r=i.concat([]);i.splice(0,i.length);let o=0,s=e.firstPseudo;return s?.count===0&&(s=s.outer),n.loopWithFrame(a=>{if(!s){a.breakLoop();return}let h=this.findLinePositions(r),l=s.count-o;if(h.length<=l){a.breakLoop();return}let u=this.findAcceptableBreakInside(r,h[l-1],!0);if(u==null){a.breakLoop();return}this.finishBreak(u,!1,!1).then(()=>{o+=l,this.layoutContext.peelOff(u,0).then(d=>{e=d,s=e.firstPseudo,r=[],this.buildViewToNextBlockEdge(e,r).then(p=>{t=p,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,r),n.finish(t)}),n.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&_i[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let t=0,i=0;for(let n=e.length-1;n>=0;n--){let r=e[n];if(!r||!r.after||!r.viewNode||r.viewNode.nodeType!=1)break;let o=this.getComputedMargin(r.viewNode),s=this.vertical?-o.left:o.bottom;s>0?t=Math.max(t,s):i=Math.min(i,s)}return t+i}layoutBreakableBlock(e){let t=D("layoutBreakableBlock"),i=[];return this.buildViewToNextBlockEdge(e,i).then(n=>{let r=i.length-1;if(r<0){t.finish(n);return}this.postLayoutBlock(n,i);let o=this.suppressOpenAncestorBlockEndInset(n??e),s=this.calculateEdge(n,i,r,i[r].boxOffset);o();let a=!1;if(!n||!dn(n.viewNode)){let l=xn(n,this.collectElementsOffset());a=this.isOverflown(s+(this.vertical?-1:1)*l.minimum),this.isOverflown(s+(this.vertical?-1:1)*l.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(s+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(s);let h;e.firstPseudo?h=this.processLineStyling(e,n,i):h=T(n),h.then(l=>{i.length>0&&(this.saveBoxBreakPosition(i),a&&!this.isLoneImage(i)&&l&&(l=l.modify(),l.overflow=!0)),t.finish(l)})}),t.result()}postLayoutBlock(e,t){Dt("POST_LAYOUT_BLOCK").forEach(i=>{i(e,t,this)})}findEndOfLine(e,t,i){let n=this.vertical?e-1:e+1,r=0,o=t[0].boxOffset,s=r,a=t.length-1,h=t[a].boxOffset,l;for(;o<h;){l=o+Math.ceil((h-o)/2),s=r;let u=a;for(;s<u;){let p=s+Math.ceil((u-s)/2);t[p].boxOffset>l?u=p-1:s=p}let d=this.calculateEdge(null,t,s,l);if(this.vertical?d<=n:d>=n){for(h=l-1;t[s].boxOffset==l;)s--;a=s}else i&&this.updateMaxReachedAfterEdge(d),o=l,r=s}return{nodeContext:t[s],index:o,checkPointIndex:s}}findAcceptableBreakInside(e,t,i){var n,r,o;let s=this.findEndOfLine(t,e,!0),a=s.nodeContext;if(s.checkPointIndex===0&&s.index===a.boxOffset)return null;let h=a.viewNode;if(h.nodeType!=1&&((n=h.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let l=h;a=this.resolveTextNodeBreaker(a).breakTextNode(l,a,s.index,e,s.checkPointIndex,i)}else{let l=Sh(a);if(l){if(((r=this.breakPositions)==null?void 0:r[0])instanceof Yn&&l!=null&&l.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(a=l;!a.after&&a.inline&&a.parent;){let u=(o=a.viewNode)==null?void 0:o.previousSibling;for(;u&&(Le(u,a.parent.whitespace)||Nt(u));)u=u.previousSibling;if(u)break;a=a.parent}}}return this.clearOverflownViewNodes(a,!1),a}resolveTextNodeBreaker(e){return Dt("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,Uo.instance)}getRangeBoxes(e,t){let i=[],n=e.ownerDocument.createRange(),r=!1,o=e,s=null,a=!1,h=!0;for(;h;){let l=!0;do{let u=null;o==t&&(t.nodeType===1?h=!(!t.firstChild||r):h=!1);let d=o.nodeType===1?o:null;d?r?r=!1:ol(d)?l=!a:!d.firstChild||_i[d.localName]||/^r(uby|[bt]c?)$/.test(d.localName)||xw(this.clientLayout.getElementComputedStyle(d).display)?(l=!a,l?(d.localName==="ruby"&&o.firstChild&&(o=o.firstChild),n.setStartBefore(o),a=!0,s=o):/^r(uby|tc?)$/.test(d.localName)||(s=o),o.contains(t)&&(h=!1)):u=o.firstChild:(a||(o.parentNode==null?h=!1:(n.setStartBefore(o),a=!0)),s=o),u||(u=o.nextSibling,u||(r=!0,u=o.parentNode)),o=u}while(l&&h);if(a){n.setEndAfter(s);let u=this.clientLayout.getRangeClientRects(n);Js(u,this.vertical);for(let d=0;d<u.length;d++)i.push(u[d]);a=!1}}return i}findLinePositions(e){let t=[],i=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);i.sort(this.vertical?$w:Uw);let n=0,r=0,o=0,s=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],u=1;if(s>0){let d=Math.max(this.getBoxSize(l),1);h*this.getBeforeEdge(l)<h*n?u=h*(this.getAfterEdge(l)-n)/d:h*this.getAfterEdge(l)>h*r?u=h*(r-this.getBeforeEdge(l))/d:u=1}if(s==0||u>=.6||u>=.2&&this.getStartEdge(l)>=o-1){o=this.getEndEdge(l),this.vertical?(n=s==0?l.right:Math.max(n,l.right),r=s==0?l.left:Math.min(r,l.left)):(n=s==0?l.top:Math.min(n,l.top),r=s==0?l.bottom:Math.max(r,l.bottom)),s++,a++;continue}}if(s>0&&(t.push(r),s=0),a>=i.length)break}return t.sort(Du),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&fn(i.viewNode)){let n=this.getComputedPaddingBorder(i.viewNode);t+=i.vertical?-n.left:n.bottom,i.display==="table"&&(t+=(i.vertical?-1:1)*i.blockBorderSpacing)}return t}getOffsetByRepetitiveElements(e){let t;return e?t=e.calculateOffset(this):t=xn(null,this.collectElementsOffset()),t.current}findBoxBreakPosition(e,t){let i=this.element.parentNode,n=this.element.nextSibling;i.removeChild(this.element),i.insertBefore(this.element,n);let r=e.checkPoints,o=r[0];for(;o.parent&&o.inline;)o=o.parent;let s,a;t&&!this.isFootnote?(s=1,a=1):(s=Math.max((o.inheritedProps.widows||2)-0,1),a=Math.max((o.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(o),l=this.findLinePositions(r),u=this.footnoteEdge-h,d=this.getBoxDir(),p=this.getOffsetByRepetitiveElements(e);u-=d*p;let f=this.findFirstOverflowingEdgeAndCheckPoint(r);isNaN(f.edge)&&(f.edge=d*(1/0));let g=ai(l.length,y=>{let b=l[y];return this.vertical?b<u||b<=f.edge:b>u||b>=f.edge}),m=g<=0;m&&(g=ai(l.length,y=>this.vertical?l[y]<u:l[y]>u));let w=r[r.length-1].viewNode;if(w?.parentElement.localName==="viv-ts-inner"&&(w=w.parentElement.parentElement),(g===l.length&&w.nextSibling||g>=l.length-1&&w.parentElement.querySelector(".MJXc-display"))&&(s=0,a=1),g=Math.min(l.length-s,g),g<a)return null;u=l[g-1];let x;if(m?x=f.checkPoint:x=this.findAcceptableBreakInside(e.checkPoints,u,t),x){let y=this.getAfterEdgeOfBlockContainer(x);if(!isNaN(y)&&d*(u-y)>0&&(u=y),this.computedBlockSize=d*(u-this.beforeEdge)+p,l.length>=2){let b=Math.max(1,Math.min(g-1,l.length-1));this.lastLineStride=Math.abs(l[b]-l[b-1])}}return x}getAfterEdgeOfBlockContainer(e){let t=e;do t=t.parent;while(t&&t.inline);return t?(t=t.copy().modify(),t.after=!0,sn(t,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(e){let t=e.findIndex(n=>n.overflow);if(t<0)return{edge:NaN,checkPoint:null};let i=e[t];return{edge:this.calculateEdge(null,e,t,i.boxOffset),checkPoint:i}}findEdgeBreakPosition(e){return this.computedBlockSize=e.computedBlockSize+this.getOffsetByRepetitiveElements(e),e.position}finishBreak(e,t,i){e.formattingContext;let n=new Un().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=dl.finishBreak(this,e,t,i)),n}findAcceptableBreakPosition(){let e=null,t=null,i=0,n=0;do{i=n,n=Number.MAX_VALUE;for(let r=this.breakPositions.length-1;r>=0&&!t;--r){e=this.breakPositions[r],t=e.findAcceptableBreak(this,i);let o=e.getMinBreakPenalty();o>i&&(n=Math.min(n,o))}}while(n>i&&!t&&this.forceNonfitting);return{breakPosition:t?e:null,nodeContext:t}}doFinishBreak(e,t,i,n){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!t)return T(e);let r=D("doFinishBreak"),o=!1;if(!e){if(this.forceNonfitting&&!this.isFootnote)return j.warn("Could not find any page breaks?!!"),this.skipTailEdges(t).then(s=>{s?(s=s.modify(),s.overflow=!1,this.finishBreak(s,o,!0).then(()=>{r.finish(s)})):r.finish(s)}),r.result();e=i,o=!0,this.computedBlockSize=n}return this.finishBreak(e,o,!0).then(()=>{r.finish(e)}),r.result()}isBreakable(e){for(let t=e;t;t=t.parent)if(Nt(t.viewNode))return!1;if(e.after)return!0;switch(e.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!e.flexContainer}isZeroLength(e){let t=e.trim();return t===""||/^0+(?:\.0+)?(?:[a-z%]*)$/i.test(t)}hasNonZeroBlockStartInset(e){return this.vertical?!(this.isZeroLength(e.paddingRight)&&this.isZeroLength(e.borderRightWidth)):!(this.isZeroLength(e.paddingTop)&&this.isZeroLength(e.borderTopWidth))}hasNonZeroBlockEndInset(e){return this.vertical?!(this.isZeroLength(e.paddingLeft)&&this.isZeroLength(e.borderLeftWidth)):!(this.isZeroLength(e.paddingBottom)&&this.isZeroLength(e.borderBottomWidth))}suppressOpenAncestorBlockEndInset(e){if(!Io(this))return()=>{};let t=[];for(let i=e?.parent;i;i=i.parent){if(i.after||i.inline)continue;let n=i.viewNode;if(!n||n.nodeType!==1||fn(n))continue;let r=this.clientLayout.getElementComputedStyle(n);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let o=n.getAttribute("data-viv-box-break");wt(n,"block-end"),t.push({element:n,original:o})}return()=>{for(let{element:i,original:n}of t)n===null?i.removeAttribute("data-viv-box-break"):i.setAttribute("data-viv-box-break",n)}}checkOverflowAndSaveEdge(e,t){if(!e)return!1;for(let s=e;s;s=s.parent)if(Nt(s.viewNode))return!1;if(dn(e.viewNode))return!1;let i=this.suppressOpenAncestorBlockEndInset(e),n=sn(e,this.clientLayout,0,this.vertical);i();let r=xn(e,this.collectElementsOffset()),o=this.isOverflown(n+(this.vertical?-1:1)*r.minimum);if(this.isOverflown(n+(this.vertical?-1:1)*r.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(t){let s=n+this.getTrailingMarginEdgeAdjustment(t),a=this.footnoteEdge-this.getBoxDir()*r.current;n=this.vertical?Math.min(n,Math.max(s,a)):Math.max(n,Math.min(s,a))}return this.updateMaxReachedAfterEdge(n),o}checkOverflowAndSaveEdgeAndBreakPosition(e,t,i,n){if(!e||dn(e.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(e,t);return(i||!r)&&this.saveEdgeBreakPosition(e,n,r),r}applyClearance(e){if(!e.viewNode.parentNode||e.floatReference!==Te.INLINE||e.floatSide)return!1;let t=this.getComputedMargin(e.viewNode),i=e.viewNode.ownerDocument.createElement("div");this.vertical?(i.style.bottom="0px",i.style.width="1px",i.style.marginRight=`${t.right}px`):(i.style.right="0px",i.style.height="1px",i.style.marginTop=`${t.top}px`),e.viewNode.parentNode.insertBefore(i,e.viewNode);let n=Tt(this.clientLayout,i,this.vertical),r=this.getBeforeEdge(n),o=this.getBoxDir(),s=e.clearSide==="same"?e.floatSide:e.clearSide,a=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(s)?Cs(s,e.vertical,e.direction,this.layoutContext.page.side):s,h=a==="left"||a==="right"?e.direction==="rtl"==(a==="left")?"inline-end":"inline-start":a,l=this.pageFloatLayoutContext.getPageFloatClearEdge(h,this),u=l;switch(a){case"left":l=o*Math.max(l*o,this.leftFloatEdge*o);break;case"right":l=o*Math.max(l*o,this.rightFloatEdge*o);break;default:l=o*Math.max(l*o,Math.max(this.rightFloatEdge*o,this.leftFloatEdge*o))}let d=this.getFloatLayoutUnit(),p=this.leftFloatEdge*o>this.beforeEdge*o||this.rightFloatEdge*o>this.beforeEdge*o;if(d>0&&p){let g=l*o>u*o;l=o*(Math.ceil(l*o/d)+(g?1:0))*d}let f=this.getFloatLayoutTolerance(d);if(r*o+f>l*o)return e.viewNode.parentNode.removeChild(i),!1;{let g=Math.max(1,(l-r)*o);this.vertical?i.style.width=`${g}px`:i.style.height=`${g}px`,n=Tt(this.clientLayout,i,this.vertical);let m=this.getAfterEdge(n);if(!e.floatSide)if(this.vertical){let w=m-t.right-l;w>0==t.right>=0&&(w+=t.right),i.style.marginLeft=`${w}px`}else{let w=l-(m+t.top);w>0==t.top>=0&&(w+=t.top),i.style.marginBottom=`${w}px`}return e.clearSpacer=i,!0}}isBFC(e){return!!(ly(e)||zi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let t=e;t;t=t.parent)if(xh(t.viewNode))return!0;return!1}skipEdges(e,t,i){var n;let r=e.after?(n=e.parent)==null?void 0:n.formattingContext:e.formattingContext;if(r&&!this.isBFC(r))return T(e);let o=D("skipEdges"),s=this,a=!i&&t&&e&&e.after,h=i,l=null,u=[],d=[],p=!1;function f(C){var N,F;if(!(!t||s.isNonFirstColumn||i||!Ch(h))){for(let B=C;B;B=B.parent)if(B.breakBefore==="column"&&(B.breakBefore=null),((N=B.viewNode)==null?void 0:N.nodeType)===1){let U=B.viewNode;((F=U.style)==null?void 0:F.breakBefore)==="column"&&(U.style.breakBefore="")}}}function g(C){var N,F;if(!(!t||!s.isNonFirstColumn||i||h!=="column")){for(let B=C;B;B=B.parent)if(B.breakBefore==="column"&&(B.breakBefore=null),((N=B.viewNode)==null?void 0:N.nodeType)===1){let U=B.viewNode;((F=U.style)==null?void 0:F.breakBefore)==="column"&&(U.style.breakBefore="")}h=null}}function m(C){var N,F;if(!(i||!Ch(h))){for(let B=C;B;B=B.parent)if(B.breakAfter==="column"&&(B.breakAfter=null),((N=B.viewNode)==null?void 0:N.nodeType)===1){let U=B.viewNode;((F=U.style)==null?void 0:F.breakAfter)==="column"&&(U.style.breakAfter="")}}}function w(C){h=tt(h,C)}function x(){return i?!0:qe(h)?t?s.isNonFirstColumn&&h!=="column"&&h!=="region":!y()&&!b():!1}function y(){var C;if(!l||!e||e.floatSide)return!1;for(let N=l;N!=null&&N.parent;N=N.parent){if(N.parent.viewNode&&Nt(N.parent.viewNode))continue;let F=N.after?N.viewNode:(C=N.viewNode)==null?void 0:C.previousSibling;for(;F&&(Le(F,N.parent.whitespace)||Nt(F));)F=F.previousSibling;if(F)return!1}return!0}function b(){var C,N;if(l||!(e!=null&&e.viewNode)||e.shadowContext||e.after||e.floatSide||!((C=e.parent)!=null&&C.viewNode)||Nt(e.parent.viewNode))return!1;let F=!1;for(let B=e;B!=null&&B.parent&&!B.after;B=B.parent){if(B!==e&&Nt(B.viewNode))return!1;let U=(N=B.viewNode)==null?void 0:N.previousSibling;for(;U&&(Le(U,B.parent.whitespace)||Nt(U));)Nt(U)&&(F=!0),U=U.previousSibling;if(U)return!1}return F}let S=()=>{e=u[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=h};return o.loopWithFrame(C=>{for(var N;e;){e.formattingContext;let F=new Un().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Le(e.viewNode,e.whitespace)||this.hasFixedPositionAncestor(e))break;if(!e.after){x()?S():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)?(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0):(!l&&!t&&u.length===0&&this.saveEdgeBreakPosition(e,h,!1),e=e.modify(),e.breakBefore=h),C.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=Ao(h)?h:null),F&&F.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&t&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),h,!1),!e.inline&&!e.repeatOnBreak&&(l?Sh(l):this.breakPositions[this.breakPositions.length-1]instanceof Yn||!t&&u.length===0)&&this.saveEdgeBreakPosition(e.copy(),h,!1),!this.isBFC(e.formattingContext)||zi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Le(e.sourceNode.firstChild,e.whitespace)){u.push(e.copy()),w(e.breakBefore),f(e),g(e),x()?S():(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let U=e.viewNode,q=U.style;if(e.after){nd(U,this),e.floatSide&&(h=h??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let he=e.sourceNode;if(he.localName==="svg"||he.localName==="math"||he.getAttribute("data-math-typeset")==="true"){p=!1,l=e.copy(),d.push(l),h=null,w(e.breakAfter),m(e),this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h);break}if(e.inline||F&&F.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(p){if(xh(e.viewNode))break;if(x()){S(),C.breakLoop();return}u=[],t=!1,a=!1,h=null}p=!1,od(e.viewNode)||(l=e.copy(),d.push(l)),w(e.breakAfter),m(e),q&&!Nt(e.viewNode)&&this.hasNonZeroBlockEndInset(q)&&(d=l?[l]:[])}else{if(u.push(e.copy()),w(e.breakBefore),f(e),g(e),l&&qe(h)&&ww(l.viewNode,e.viewNode),(e.pageType!=((N=e.parent)==null?void 0:N.pageType)||!qe(h))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){C.breakLoop();return}let he=e.viewNode.localName;if(_i[he]){x()?S():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}q&&this.hasNonZeroBlockStartInset(q)&&(a=!1,d=[]),p=!0}}while(!1);let B=this.nextInTree(e,a);if(B.isPending()){B.then(U=>{e=U,C.continueLoop()});return}else e=B.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(l,d,!this.stopAtOverflow,h)?l&&this.stopAtOverflow&&(e=l.modify(),e.overflow=!0):qe(h)&&(this.pageBreakType=h),C.breakLoop()}).then(()=>{l&&(this.lastAfterPosition=l.toNodePosition()),o.finish(e)}),o.result()}skipTailEdges(e){let t=e.copy(),i=D("skipEdges"),n=null,r=!1;return i.loopWithFrame(o=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Le(e.viewNode,e.whitespace))break;if(!e.after){qe(n)&&(this.pageBreakType=n),o.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=tt(n,e.breakBefore),qe(n)&&(this.pageBreakType=n),o.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(r){if(qe(n)){this.pageBreakType=n,o.breakLoop();return}n=null}r=!1,n=tt(n,e.breakAfter)}else{n=tt(n,e.breakBefore);let h=e.viewNode.localName;if(_i[h]){qe(n)&&(this.pageBreakType=n),o.breakLoop();return}if(a&&this.hasNonZeroBlockStartInset(a)){o.breakLoop();return}}r=!0}while(!1);let s=this.layoutContext.nextInTree(e);if(s.isPending()){s.then(a=>{e=a,o.continueLoop()});return}else e=s.get()}t=null,o.breakLoop()}).then(()=>{i.finish(t)}),i.result()}layoutFloatOrFootnote(e){if(Si(e.floatReference)||e.floatSide==="footnote"){let t=this.pageFloatLayoutContext.generatingNodePosition;if(t&&e.sourceNode===t.steps[0].node){let i=e.modify();return i.floatSide=null,i.floatReference=Te.INLINE,i.clearSide=null,this.isBreakable(i)?this.layoutBreakableBlock(i):this.layoutUnbreakable(i)}return this.layoutPageFloat(e)}else return this.layoutFloat(e)}layoutNext(e,t,i){let n=D("layoutNext");return this.skipEdges(e,t,i||null).then(r=>{if(e=r,!e||this.pageBreakType||this.stopByOverflow(e))n.finish(e);else{let o=e.formattingContext;new Un().find(o).layout(e,this,t).thenFinish(n)}}),n.result()}clearOverflownViewNodes(e,t){if(e)for(let i=e.parent;e;e=i,i=i?i.parent:null){let n=(i||e).formattingContext;new Un().find(n).clearOverflownViewNodes(this,i,e,t),t=!1}}initGeom(){let e=this.element.ownerDocument.createElement("div");e.style.position="absolute",e.style.top=`${this.paddingTop}px`,e.style.right=`${this.paddingRight}px`,e.style.bottom=`${this.paddingBottom}px`,e.style.left=`${this.paddingLeft}px`,this.element.appendChild(e);let t=this.clientLayout.getElementClientRect(e);this.element.removeChild(e);let i=this.originX+this.left+this.getInsetLeft(),n=this.originY+this.top+this.getInsetTop();this.box=new It(i,n,i+this.width,n+this.height),this.startEdge=t?this.vertical?this.rtl?t.bottom:t.top:this.rtl?t.right:t.left:0,this.endEdge=t?this.vertical?this.rtl?t.top:t.bottom:this.rtl?t.left:t.right:0,this.beforeEdge=t?this.vertical?t.right:t.top:0,this.afterEdge=t?this.vertical?t.left:t.bottom:0,this.leftFloatEdge=this.beforeEdge,this.rightFloatEdge=this.beforeEdge,this.bottommostFloatTop=this.beforeEdge,this.footnoteEdge=this.afterEdge,this.bands=zg(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],I(this.element,"width",`${this.width}px`),I(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null,this.lastLineStride=0}saveEdgeBreakPosition(e,t,i){e.formattingContext;let n=e.copy(),r=new Un().find(e.formattingContext),o=this.calculateClonedPaddingBorder(n),s=r.createEdgeBreakPosition(n,t,i,this.computedBlockSize+o);this.breakPositions.push(s)}saveBoxBreakPosition(e){let t=e[0].breakPenalty;if(t){let n=e[0];for(;n.parent&&n.inline;)n=n.parent;t=n.breakPenalty}let i=new Yn(e,t);this.breakPositions.push(i)}updateMaxReachedAfterEdge(e){if(!isNaN(e)){let t=this.getBoxDir()*(e-this.beforeEdge);this.computedBlockSize=Math.max(t,this.computedBlockSize)}}layout(e,t,i){if(this.chunkPositions.push(e),e.primary.after&&(this.lastAfterPosition=e.primary),this.stopAtOverflow&&this.overflown)return T(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?T(null):T(e);rl(this);let n=D("layout");return this.openAllViews(e.primary).then(r=>{let o=null;if(r.viewNode)o=r.copy();else{let a=h=>{h.nodeContext.viewNode&&(o=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let s=new Ev(t,i);s.layout(r,this).then(a=>{this.doFinishBreak(a,s.context.overflownNodeContext,o,s.initialComputedBlockSize).then(h=>{let l=null;this.pseudoParent?l=T(null):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(Io(this)&&(bw(this),rs(this)),this.element.hasAttribute("data-vivliostyle-column-block-size-adjusted")&&(this.vertical?(I(this.element,"width",`${this.width}px`),I(this.element,"left",`${this.left}px`)):I(this.element,"height",`${this.height}px`),this.element.removeAttribute("data-vivliostyle-column-block-size-adjusted")),this.pageFloatLayoutContext.isInvalidated()){n.finish(null);return}if(!h)n.finish(null);else{this.overflown=!0;let u=new Ei(h.toNodePosition());n.finish(u)}})})})}),n.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let t=D("doFinishBreakOfFragmentLayoutConstraints"),i=[].concat(this.fragmentLayoutConstraints);i.sort((r,o)=>r.getPriorityOfFinishBreak()-o.getPriorityOfFinishBreak());let n=0;return t.loop(()=>n<i.length?i[n++].finishBreak(e,this).thenReturn(!0):T(!1)).then(()=>{t.finish(!0)}),t.result()}doLayout(e,t,i){let n=D("doLayout"),r=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,n.loopWithFrame(o=>{for(;e;){let s=!0;if(this.layoutNext(e,t,i||null).then(a=>{if(t=!1,i=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,e=this.nodeContextOverflowingDueToRepetitiveElements,e.overflow=!0):e=a,this.pageFloatLayoutContext.isInvalidated())o.breakLoop();else if(this.pageBreakType)o.breakLoop();else if(e&&this.stopByOverflow(e)){r=e;let h=this.findAcceptableBreakPosition();e=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),o.breakLoop()}else s?s=!1:o.continueLoop()}),s){s=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),o.breakLoop()}).then(()=>{n.finish({nodeContext:e,overflownNodeContext:r})}),n.result()}redoLayout(){let e=this.chunkPositions,t=this.element.lastChild;for(;t!=this.last;){let s=t.previousSibling;this.element===t.parentNode&&this.layoutContext.isPseudoelement(t)||this.element.removeChild(t),t=s}this.killFloats(),this.init();let i=D("redoLayout"),n=0,r=null,o=!0;return i.loopWithFrame(s=>{if(n<e.length){let a=e[n++];this.layout(a,o).then(h=>{o=!1,h?(r=h,s.breakLoop()):s.continueLoop()});return}s.breakLoop()}).then(()=>{i.finish(r)}),i.result()}saveDistanceToBlockEndFloats(){let e=this.pageFloatLayoutContext.getBlockStartEdgeOfBlockEndFloats();e>0&&isFinite(e)&&(this.blockDistanceToBlockEndFloats=this.getBoxDir()*(e-this.beforeEdge-this.computedBlockSize))}collectElementsOffset(){let e=[];for(let t=this;t;t=t.pseudoParent)t.fragmentLayoutConstraints.forEach(i=>{if(zi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(Fo.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}ki.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},xl=class{constructor(e,t,i){c(this,"startNodeContexts",[]),c(this,"column"),c(this,"flowRootSourceNode"),this.flowRootSourceNode=i.sourceNode,this.column=Object.create(e),this.column.element=t,this.column.layoutContext=e.layoutContext.clone(),this.column.stopAtOverflow=!1,this.column.flowRootFormattingContext=i.formattingContext,this.column.pseudoParent=e;let n=this.column.calculateClonedPaddingBorder(i);this.column.footnoteEdge=this.column.footnoteEdge-n;let r=this;this.column.openAllViews=function(o){return Vo.prototype.openAllViews.call(this,o).thenAsync(s=>(r.startNodeContexts.push(s.copy()),T(s)))}}layout(e,t){return this.column.layout(e,t)}findAcceptableBreakPosition(e){let t=this.column.findAcceptableBreakPosition();if(e){let i=this.startNodeContexts[0].copy(),n=new Or(i,null,i.overflow,0);if(n.findAcceptableBreak(this.column,0),!t.nodeContext)return{breakPosition:n,nodeContext:i}}return t}finishBreak(e,t,i){return this.column.finishBreak(e,t,i)}doFinishBreakOfFragmentLayoutConstraints(e){this.column.doFinishBreakOfFragmentLayoutConstraints(e)}isStartNodeContext(e){let t=this.startNodeContexts[0];return t.viewNode===e.viewNode&&t.after===e.after&&t.offsetInNode===e.offsetInNode}isLastAfterNodeContext(e){return Hi(e.toNodePosition(),this.column.lastAfterPosition)||this.isEffectivelyLastAfterNodeContext(e)}isEffectivelyLastAfterNodeContext(e){var t;let i=this.flowRootSourceNode,n=e.sourceNode;if(!i||!n||!e.after||i!==n&&!((t=i.contains)!=null&&t.call(i,n)))return!1;if(n.nodeType===Node.TEXT_NODE){let r=n;if(e.offsetInNode<r.length){let o=r.data.slice(e.offsetInNode);if(!md(o,e.whitespace))return!1}}for(let r=n;r&&r!==i;r=r.parentNode)for(let o=r.nextSibling;o;o=o.nextSibling)if(!Le(o,e.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},Uo=class{breakTextNode(e,t,i,n,r,o){if(t.after)t.offsetInNode=e.length;else{let s=i-t.boxOffset,a=e.data;a.charCodeAt(s)==173?s=this.breakAfterSoftHyphen(e,a,s,t):s=this.breakAfterOtherCharacter(e,a,s,t),s>0&&(t=this.updateNodeContext(t,s,e))}return t}breakAfterSoftHyphen(e,t,i,n){let r=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(t.slice(0,i))?"\u200D":"";if(e.replaceData(i,t.length-i,n.breakWord?"":r+$h(n)),r){let o=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=o.slice(0,i+1)+r+o.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let r=t.charAt(i);i++;let o=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&jl(r)&&jl(o)?$h(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};c(Uo,"instance");Uo.instance=new Uo;function $h(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var Ev=class extends pl{constructor(e,t){super(),this.leadingEdge=e,c(this,"breakAfter"),c(this,"initialPageBreakType",null),c(this,"initialComputedBlockSize",0),c(this,"initialOverflown",!1),c(this,"initialLastLineStride",0),c(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new Pv(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||uy()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&rd(i.parentNode,i),t=t.parent}}saveState(e,t){super.saveState(e,t),this.initialPageBreakType=t.pageBreakType,this.initialComputedBlockSize=t.computedBlockSize,this.initialOverflown=t.overflown,this.initialLastLineStride=t.lastLineStride}restoreState(e,t){super.restoreState(e,t),t.pageBreakType=this.initialPageBreakType,t.computedBlockSize=this.initialComputedBlockSize,t.overflown=this.initialOverflown,t.lastLineStride=this.initialLastLineStride}},Pv=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=D("DefaultLayoutMode.doLayout");return Sv(e,t).then(()=>{t.doLayout(e,this.leadingEdge,this.breakAfter).then(n=>{this.context.overflownNodeContext=n.overflownNodeContext,i.finish(n.nodeContext)})}),i.result()}accept(e,t){return t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||t.fragmentLayoutConstraints.length<=0?!0:t.fragmentLayoutConstraints.every(i=>i.allowLayout(e,this.context.overflownNodeContext,t))}postLayout(e,t,i,n){return n||(n=!i.fragmentLayoutConstraints.some(r=>r.nextCandidate(e))),i.fragmentLayoutConstraints.forEach(r=>{r.postLayout(n,e,t,i)}),n}},Nv=class extends Vo{constructor(e,t,i,n,r,o,s){super(t,i,n,r,o),this.floatSide=e,this.parentContainer=s,c(this,"rootViewNodes",[]),c(this,"floatMargins",[]),c(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),T(t)))}convertPercentageSizesToPx(e){let t=this.parentContainer.getPaddingRect(),i=t.x2-t.x1,n=t.y2-t.y1;function r(o,s){o.forEach(a=>{let h=mi(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),u=s*l/100;I(e,a,`${u}px`)}})}r(["width","max-width","min-width"],i),r(["height","max-height","min-height"],n),r(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?n:i),["margin-top","margin-right","margin-bottom","margin-left"].forEach(o=>{mi(e,o)==="auto"&&I(e,o,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let t=e.viewNode;if(this.rootViewNodes.push(t),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(t),this.floatMargins.push(this.getComputedMargin(t)),this.adjustContentRelativeSize){let i=this.floatSide;if(this.parentContainer.vertical){if(i==="block-end"||i==="left"){let n=mi(t,"height");n!==""&&n!=="auto"&&I(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=mi(t,"width");n!==""&&n!=="auto"&&I(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=Tt(this.clientLayout,e,this.vertical),n=this.floatMargins[t];return this.vertical?n.top+i.height+n.bottom:n.left+i.width+n.right}))}getContentBlockMarginAfter(){return this.rootViewNodes.length===0?0:Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=this.floatMargins[t];return this.vertical?i.left:i.bottom}))}applyCompactFootnoteDisplay(){let e=this.layoutContext,t=e?.styler,i=e?.xmldoc,n=this.rootViewNodes.filter(h=>{var l,u,d,p;let f=(l=h.ownerDocument.defaultView)==null?void 0:l.getComputedStyle(h);if((f?.getPropertyValue("--viv-footnote-display").trim()||"")==="compact")return!(f?.display==="list-item"&&f.getPropertyValue("list-style-position").trim()==="outside");let g=h.getAttribute(Zt);if(!g||!t||!i)return!1;let m=i.getNodeByOffset(parseInt(g,10));if(!m||m.nodeType!==Node.ELEMENT_NODE)return!1;let w=t.getStyle(m,!1),x=(d=(u=me(w,"footnote-display"))==null?void 0:u.value)==null?void 0:d.toString(),y=!!((p=me(w,"--viv-marker-content"))!=null&&p.value);return x==="compact"&&!y});if(n.length===0){this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea();return}let r=this.element.getBoundingClientRect(),o=this.vertical?r.height:r.width;n.forEach(h=>{I(h,"display","inline"),h.style.setProperty("--viv-footnote-white-space","nowrap")});let s=1.5/(this.clientLayout.pixelRatio||1),a=h=>{let l=h.cloneNode(!0);I(l,"display","inline-block"),I(l,"position","absolute"),I(l,"visibility","hidden"),I(l,"white-space","nowrap"),I(l,"max-width","none"),I(l,"left","0"),I(l,"top","0"),this.element.appendChild(l);let u=l.getBoundingClientRect();return this.element.removeChild(l),this.vertical?u.height:u.width};n.forEach(h=>{a(h)>o+s&&(I(h,"display","block"),h.style.removeProperty("--viv-footnote-white-space"))}),this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea()}updateComputedBlockSizeForFootnoteArea(){if(this.rootViewNodes.length===0){this.computedBlockSize=0;return}let e=this.getBoxDir();this.computedBlockSize=Math.max(0,...this.rootViewNodes.map(t=>{let i=Tt(this.clientLayout,t,this.vertical),n=this.getComputedMargin(t),r=this.vertical?n.left:n.bottom;return e*(this.getAfterEdge(i)-this.beforeEdge)+Math.max(0,r)}))}getFootnoteAfterPseudo(e){return Array.from(e.children).find(t=>Kt(t)==="after")}hasAuthorFootnoteAfterPseudo(e){let t=this.getFootnoteAfterPseudo(e);if(t&&!t.hasAttribute("data-vivliostyle-default-footnote-separator"))return!0;let i=Array.from(e.children).find(r=>r instanceof Element&&bt(r)),n=i?this.getFootnoteAfterPseudo(i):null;return!!n&&!n.hasAttribute("data-vivliostyle-default-footnote-separator")}createDefaultFootnoteAfterPseudo(e){let t=e.ownerDocument.createElement("span");sr(t,"after"),t.setAttribute("data-vivliostyle-default-footnote-separator","1"),t.style.whiteSpace="normal",t.textContent=" ",e.appendChild(t)}getFootnoteBreakOpportunity(e){let t=e.nextElementSibling;return t!=null&&t.hasAttribute("data-vivliostyle-footnote-break")?t:null}createFootnoteBreakOpportunity(e){let t=e.ownerDocument.createElement("wbr");t.setAttribute("data-vivliostyle-footnote-break","1"),e.insertAdjacentElement("afterend",t)}updateInlineFootnoteSeparators(){this.rootViewNodes.forEach((e,t)=>{var i,n;let r=e,o=(i=r.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(r).display,s=this.rootViewNodes[t+1],a=(n=s?.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(s).display,h=this.getFootnoteAfterPseudo(r),l=this.hasAuthorFootnoteAfterPseudo(r),u=!!(h!=null&&h.hasAttribute("data-vivliostyle-default-footnote-separator")),d=this.getFootnoteBreakOpportunity(r);if(o==="inline"&&a==="inline"){let p=!h&&!l;p&&this.createDefaultFootnoteAfterPseudo(r),!p&&!d?this.createFootnoteBreakOpportunity(r):p&&d?.remove()}else u&&h.remove(),d?.remove()})}},Wi=class{constructor(e,t){this.parent=e,this.rootSourceNode=t,c(this,"formattingContextType","RepetitiveElementsOwner"),c(this,"isRoot",!1),c(this,"repetitiveElements",null)}getName(){return"Repetitive elements owner formatting context (RepetitiveElementsOwnerFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}getRepetitiveElements(){return this.repetitiveElements}getRootViewNode(e){let t=this.getRootNodeContext(e);return t?t.viewNode:null}getRootNodeContext(e){do if(!e.belongsTo(this)&&e.sourceNode===this.rootSourceNode)return e;while(e=e.parent);return null}initializeRepetitiveElements(e){this.repetitiveElements||sa.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new Tv(e,this.rootSourceNode),sa.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},Tv=class{constructor(e,t){this.vertical=e,this.ownerSourceNode=t,c(this,"headerSourceNode",null),c(this,"footerSourceNode",null),c(this,"headerViewNode",null),c(this,"footerViewNode",null),c(this,"headerNodePosition",null),c(this,"footerNodePosition",null),c(this,"headerHeight",0),c(this,"footerHeight",0),c(this,"isSkipHeader",!1),c(this,"isSkipFooter",!1),c(this,"enableSkippingFooter",!0),c(this,"enableSkippingHeader",!0),c(this,"doneInitialLayout",!1),c(this,"firstContentSourceNode",null),c(this,"lastContentSourceNode",null),c(this,"affectedNodeCache",[]),c(this,"afterLastContentNodeCache",[]),c(this,"allowInsert",!1),c(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=Ro(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=Ro(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=ea(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=ea(this.footerViewNode,e,this.vertical),this.footerViewNode=null)}prepareLayoutFragment(){this.isSkipHeader=this.isSkipFooter=!1,this.enableSkippingFooter=!0,this.enableSkippingHeader=!0}appendHeaderToFragment(e,t,i){return!this.headerNodePosition||this.isSkipHeader?T(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?T(!0):this.appendElementToFragment(this.footerNodePosition,e,t,i)}appendElementToFragment(e,t,i,n){let r=t.viewNode.ownerDocument,o=t.viewNode,s=r.createElement("div");o.appendChild(s);let a=new xl(n,s,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new Ei(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,o.removeChild(s),this.moveChildren(s,o,i),a.getColumn().pageBreakType=h,T(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(Pn,"1"),i?t.insertBefore(n,i):t.appendChild(n)}}calculateOffset(e){let t=0;return e&&!this.affectTo(e)||((!this.isSkipFooter||e&&this.isAfterLastContent(e))&&(t+=this.footerHeight),this.isSkipHeader||(t+=this.headerHeight)),t}calculateMinimumOffset(e){let t=0;return e&&!this.affectTo(e)||(!this.enableSkippingFooter&&e&&this.isAfterLastContent(e)&&(t+=this.footerHeight),this.enableSkippingHeader||(t+=this.headerHeight)),t}isAfterLastContent(e){return this.findResultFromCache(e,this.afterLastContentNodeCache,t=>this.isAfterNodeContextOf(this.lastContentSourceNode,e,!1))}affectTo(e){return this.findResultFromCache(e,this.affectedNodeCache,t=>this.isAfterNodeContextOf(this.ownerSourceNode,e,!0))}findResultFromCache(e,t,i){let n=t.filter(r=>r.nodeContext.sourceNode===e.sourceNode&&r.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let r=i(e);return t.push({nodeContext:e,result:r}),r}}isAfterNodeContextOf(e,t,i){let n=[];for(let r=e;r;r=r.parentNode){if(t.sourceNode===r)return t.after;n.push(r)}for(let r=t.sourceNode;r;r=r.parentNode){let o=n.indexOf(r);if(o>=0)return i?o===0:!1;for(let s=r;s;s=s.previousElementSibling)if(n.includes(s))return!0}return t.after}isFirstContentNode(e){return e&&this.firstContentSourceNode===e.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(e){return this.headerSourceNode===e}isFooterSourceNode(e){return this.footerSourceNode===e}},hp=class{constructor(e){this.formattingContext=e}accept(e,t){return!!e}postLayout(e,t,i,n){let r=this.formattingContext.getRepetitiveElements();return r&&(i.clientLayout,r.doneInitialLayout||(r.updateHeight(i),r.doneInitialLayout=!0)),n}},up=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},Iv=class extends hp{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},Av=class extends up{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new Sl(e)),this.processor.doLayout(e,t)}},Sl=class cp{constructor(t){c(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),c(this,"nodeContext");let i=ni(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||dn(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!pp(t,i,r):!0}nextCandidate(t){let i=this.getRepetitiveElements();return i&&i.isEnableToUpdateState()?(i.updateState(),!0):!1}postLayout(t,i,n,r){let o=this.getRepetitiveElements();o&&t&&r.stopAtOverflow&&(i==null||o.isAfterLastContent(i))&&o.preventSkippingFooter()}finishBreak(t,i){let n=ni(this.nodeContext.formattingContext),r=this.getRepetitiveElements();if(!r)return T(!0);let o=this.nodeContext;return Bv(n,o,i).thenAsync(()=>Mv(n,o,i).thenAsync(()=>(r.prepareLayoutFragment(),T(!0))))}getRepetitiveElements(){return ni(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof cp?ni(this.nodeContext.formattingContext)===ni(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},Fv=class extends pl{constructor(e,t){super(),this.formattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.formattingContext.getRepetitiveElements();return!e.belongsTo(this.formattingContext)&&!t.doneInitialLayout?new Iv(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new Av(this.formattingContext,this.processor))}},Rv=class extends nr{constructor(e,t){super(),this.formattingContext=e,this.column=t}startNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=t.getRepetitiveElements();if(i.parent&&t.rootSourceNode===i.parent.sourceNode){switch(i.repeatOnBreak){case"header":if(n.isHeaderRegistered())i.repeatOnBreak="none";else return n.setHeaderNodeContext(i),T(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),T(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return nr.prototype.startNonInlineElementNode.call(this,e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext;return i.sourceNode===t.rootSourceNode&&(t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0),i.repeatOnBreak==="header"||i.repeatOnBreak==="footer"?T(!0):nr.prototype.afterNonInlineElementNode.call(this,e)}},Lv=class extends gn{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=ni(e.formattingContext);return n.getRootViewNode(e)?(i&&dp(e.parent,t),e.belongsTo(n)?gn.prototype.layout.call(this,e,t,i):new Fv(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=_v(e).getRepetitiveElements();return t&&!t.allowInsertRepeatitiveElements&&(t.isHeaderSourceNode(e.sourceNode)||t.isFooterSourceNode(e.sourceNode))&&e.viewNode.parentNode.removeChild(e.viewNode),!1}doInitialLayout(e,t){let i=ni(e.formattingContext),n=D("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=ni(e.formattingContext),n=new Rv(i,t);return new oa(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=ni(e.formattingContext),n=D("doLayout"),r=t.layoutContext.nextInTree(e,!1);return lp(r,t).then(o=>{let s=o;n.loopWithFrame(a=>{for(;s;){let h=!0;if(t.layoutNext(s,!1).then(l=>{s=l,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||s&&t.stopByOverflow(s)||s&&s.after&&s.sourceNode==i.rootSourceNode?a.breakLoop():h?h=!1:a.continueLoop()}),h){h=!1;return}}a.breakLoop()}).then(()=>{n.finish(s)})}),n.result()}finishBreak(e,t,i,n){return gn.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){gn.prototype.clearOverflownViewNodes(e,t,i,n)}};function Ov(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof Wi&&!i.belongsTo(n)&&t(n,i)}}function dp(e,t){e&&Ov(e.after?e.parent:e,(i,n)=>{ki.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new Sl(n))})}function Bv(e,t,i){let n=e.getRepetitiveElements();if(n){let r=e.getRootNodeContext(t);if(r.viewNode){let o=r.viewNode.firstChild;return n.appendHeaderToFragment(r,o,i)}}return T(!0)}function Mv(e,t,i){let n=e.getRepetitiveElements();if(n&&!n.isSkipFooter){let r=e.getRootNodeContext(t);if(r.viewNode)return n.appendFooterToFragment(r,null,i)}return T(!0)}function pp(e,t,i){let n=i.ownerSourceNode,r=e||t;return!r||n.contains(r.sourceNode)}function _v(e){let t=e.formattingContext;return!t||!(t instanceof Wi)?null:t}function ni(e){return e instanceof Wi,e}var Dv=new Lv;At("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Wi&&!ki.isInstanceOfTableFormattingContext(e)?Dv:null);var fp=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,c(this,"cells",[]),c(this,"breakBefore",null),c(this,"breakAfter",null)}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},zv=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,c(this,"viewElement"),c(this,"colSpan"),c(this,"rowSpan"),c(this,"height",0),c(this,"anchorSlot",null),this.viewElement=i,this.colSpan=i.colSpan||1,this.rowSpan=i.rowSpan||1}setHeight(e){this.height=e}setAnchorSlot(e){this.anchorSlot=e}},Vv=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},Uv=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,c(this,"pseudoColumn"),c(this,"empty",!1),this.pseudoColumn=new xl(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&I(e,"vertical-align","top"),i&&i!=="normal"&&I(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return I(e,"vertical-align",t),i&&i!=="normal"&&I(e,"align-content",i),n}},$v=class{constructor(e,t){this.viewNode=e,this.side=t}},Hv=class extends Or{constructor(e,t,i,n){super(e,t,i,n),c(this,"formattingContext"),c(this,"acceptableCellBreakPositions",null),c(this,"rowIndex",null),this.formattingContext=e.formattingContext}findAcceptableBreak(e,t){let i=super.findAcceptableBreak(e,t);return t<this.getMinBreakPenalty()?null:this.getAcceptableCellBreakPositions().every(n=>!!n.nodeContext)?this.hasUnfinishedCells()?null:i:null}hasUnfinishedCells(){let e=this.getRowIndex(),t=this.formattingContext.getCellsFallingOnRow(e);for(let i of t){if(i.rowIndex+i.rowSpan-1>e)continue;let n=this.formattingContext.getCellFragmentOfCell(i);if(n){let r=n.findAcceptableBreakPosition();if(r.nodeContext&&!n.pseudoColumn.isLastAfterNodeContext(r.nodeContext))return!0}}return!1}getMinBreakPenalty(){let e=super.getMinBreakPenalty();this.getAcceptableCellBreakPositions().forEach(i=>{e+=i.breakPosition.getMinBreakPenalty()});let t=this.getCellFragments();return e+=Math.max(0,...t.map(i=>i.cellNodeContext.breakPenalty)),e}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.formattingContext,t=this.getCellFragments();this.acceptableCellBreakPositions=t.map(i=>i.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getRowIndex(){return this.rowIndex!=null?this.rowIndex:this.rowIndex=this.formattingContext.findRowIndexBySourceNode(this.position.sourceNode)}getCellFragments(){return this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.getRowIndex()).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},Wv=class extends ul{constructor(e,t,i){super(),this.rowIndex=e,this.beforeNodeContext=t,this.formattingContext=i,c(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,t){if(this!==e.breakPositions[0]&&t<this.getMinBreakPenalty())return null;let i=this.getCellFragments(),n=this.getAcceptableCellBreakPositions(),r=n.every(o=>!!o.nodeContext)&&n.some((o,s)=>{let a=i[s].pseudoColumn,h=o.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(o=>o.nodeContext&&o.nodeContext.overflow),r?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext.getRowByIndex(this.rowIndex),t=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),n=this.getCellFragments();t+=Math.max(0,...n.map(o=>o.cellNodeContext.breakPenalty));let r=i.some((o,s)=>o.breakPosition instanceof Yn&&n[s].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((o,s)=>{let a=o.breakPosition.getMinBreakPenalty();r&&o.breakPosition instanceof Or&&o.breakPosition.overflows&&a>=3&&(n[s].column.checkOverflowAndSaveEdge(o.nodeContext,null)||(a-=3)),t+=a}),t}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.getCellFragments();this.acceptableCellBreakPositions=e.map(t=>t.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},Sn=class extends Wi{constructor(e,t){super(e,t),this.tableSourceNode=t,c(this,"formattingContextType","Table"),c(this,"vertical",!1),c(this,"columnCount",-1),c(this,"tableWidth",0),c(this,"captions",[]),c(this,"colGroups",null),c(this,"colWidths",null),c(this,"inlineBorderSpacing",0),c(this,"rows",[]),c(this,"slots",[]),c(this,"cellFragments",[]),c(this,"lastRowViewNode",null),c(this,"cellBreakPositions",[]),c(this,"repetitiveElements",null)}getName(){return"Table formatting context (Table.TableFormattingContext)"}isFirstTime(e,t){var i;if(!t)return t;switch(e.display){case"table-row":{let n=this.findRowIndexBySourceNode(e.sourceNode);return this.cellBreakPositions.every(r=>this.isPreviousFragmentRowSpanningCellBreakPosition(r,n))&&e.fragmentIndex<=1}case"table-cell":return e.fragmentIndex>1||((i=e.parent)==null?void 0:i.display)==="table-row"&&e.parent.fragmentIndex>1?!1:!this.cellBreakPositions.some(n=>n.cellNodePosition.steps[0].node===e.sourceNode);default:return t}}getParent(){return this.parent}finishFragment(){this.cellFragments=[]}addRow(e,t){this.rows[e]=t}getRowSlots(e){let t=this.slots[e];return t||(t=this.slots[e]=[]),t}addCell(e,t){let i=this.rows[e];i||(this.addRow(e,new fp(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,r=this.getRowSlots(e),o=0;for(;r[o];)o++;for(;e<n;e++){r=this.getRowSlots(e);for(let s=o;s<o+t.colSpan;s++){let a=r[s]=new Vv(e,s,t);t.anchorSlot||t.setAnchorSlot(a)}}}getRowByIndex(e){return this.rows[e]}findRowIndexBySourceNode(e){return this.rows.findIndex(t=>e===t.sourceNode)}isPreviousFragmentRowSpanningCellBreakPosition(e,t){let i=e.cell;return t>=0&&i.rowIndex<t&&i.rowIndex+i.rowSpan>t}addCellFragment(e,t,i){let n=this.cellFragments[e];n||(n=this.cellFragments[e]=[]),n[t]=i}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((t,i)=>i.cell!==t[t.length-1]?t.concat(i.cell):t,[])}getRowSpanningCellsOverflowingTheRow(e){return this.getCellsFallingOnRow(e).filter(t=>t.rowIndex+t.rowSpan-1>e)}getCellFragmentOfCell(e){return this.cellFragments[e.rowIndex]&&this.cellFragments[e.rowIndex][e.columnIndex]}getColumnCount(){return this.columnCount<0&&(this.columnCount=Math.max.apply(null,this.rows.map(e=>e.cells.reduce((t,i)=>t+i.colSpan,0)))),this.columnCount}updateCellSizes(e){this.rows.forEach(t=>{t.cells.forEach(i=>{let n=Tt(e,i.viewElement,this.vertical);i.viewElement=null,i.setHeight(this.vertical?n.width:n.height)})})}findCellFromColumn(e){if(!e)return null;let t=null,i=0,n=0;e:for(i=0;i<this.cellFragments.length;i++)if(this.cellFragments[i]){for(n=0;n<this.cellFragments[i].length;n++)if(this.cellFragments[i][n]&&e===this.cellFragments[i][n].pseudoColumn.getColumn()){t=this.rows[i].cells[n];break e}}if(!t)return null;for(;i<this.slots.length;i++)for(;n<this.slots[i].length;n++){let r=this.slots[i][n];if(r.cell===t)return{rowIndex:r.rowIndex,columnIndex:r.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,r)=>{if(r>=e.rowIndex)return i;let o=n[e.columnIndex]&&this.getCellFragmentOfCell(n[e.columnIndex].cell);return!o||t.includes(o)||(this.collectElementsOffsetFromColumn(o.pseudoColumn.getColumn(),i),t.push(o)),i},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(t=>{t.cells.forEach((i,n)=>{e[n]||(e[n]={collected:[],elements:[]});let r=e[n],o=this.getCellFragmentOfCell(i);!o||r.collected.includes(o)||(this.collectElementsOffsetFromColumn(o.pseudoColumn.getColumn(),r.elements),r.collected.push(o))})}),[new Gv(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(zi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}ki.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=[].concat(e)}},Gv=class{constructor(e){this.repeatitiveElementsInColumns=e}calculateOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.current)}calculateMinimumOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.minimum)}calculateMaxOffsetOfColumn(e,t){let i=0;return this.repeatitiveElementsInColumns.forEach(n=>{let r=xn(e,n);i=Math.max(i,t(r))}),i}};function Ot(e){return e instanceof Sn,e}function jv(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Xv(e){return e==="table"||e==="inline-table"}function Hh(e){return jv(e)||Xv(e)}function gp(e,t,i){let n=e.nodeContext,r=n.display,o=n.parent?n.parent.display:null,s=!1;if(o==="inline-table"&&!(n.formattingContext instanceof Sn)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof Sn){s=a.formattingContext===t;break}}return s||r==="table-row"&&!Hh(o)||r==="table-cell"&&o!=="table-row"&&!Hh(o)||n.formattingContext instanceof Sn&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,T(!0))):null}function mp(e,t){let i=t.nodeContext;return!(i!=null&&i.floatSide)||!(Si(i.floatReference)||i.floatSide==="footnote")?null:e.layoutFloatOrFootnote(i).thenAsync(n=>(n&&(t.nodeContext=n),T(!0)))}var qv=class extends nr{constructor(e,t){super(),this.formattingContext=e,this.column=t,c(this,"rowIndex",-1),c(this,"columnIndex",0),c(this,"inRow",!1),c(this,"checkPoints",[]),c(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=gp(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=mp(this.column,e);if(n)return n;let r=e.nodeContext,o=r.display,s=t.getRepetitiveElements();switch(o){case"table":t.inlineBorderSpacing=r.inlineBorderSpacing;break;case"table-caption":{let a=new $v(r.viewNode,r.captionSide);t.captions.push(a);break}case"table-header-group":return s.isHeaderRegistered()||(this.inHeaderOrFooter=!0,s.setHeaderNodeContext(r)),T(!0);case"table-footer-group":return s.isFooterRegistered()||(this.inHeaderOrFooter=!0,s.setFooterNodeContext(r)),T(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,r.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new fp(this.rowIndex,r.sourceNode)),r.breakBefore&&(t.rows[this.rowIndex].breakBefore=r.breakBefore),s.firstContentSourceNode||(s.firstContentSourceNode=r.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,r=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let o=r.getElementComputedStyle(t.getRootViewNode(i));t.tableWidth=parseFloat(o[t.vertical?"height":"width"]),t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(n){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,T(!0);break;case"table-row":if(!this.inHeaderOrFooter){t.lastRowViewNode=i.viewNode,this.inRow=!1;let o=t.rows[this.rowIndex];o&&i.breakAfter&&(o.breakAfter=tt(o.breakAfter,i.breakAfter))}break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let o=i.viewNode;t.addCell(this.rowIndex,new zv(this.rowIndex,this.columnIndex,o)),this.columnIndex++,bp(o);let s=t.rows[this.rowIndex];s&&(i.breakBefore&&(s.breakBefore=tt(s.breakBefore,i.breakBefore)),i.breakAfter&&(s.breakAfter=tt(s.breakAfter,i.breakAfter)))}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let t=e.nodeContext;t&&t.viewNode&&!pn(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},wp=class yp extends nr{constructor(t,i){super(!0),this.formattingContext=t,this.column=i,c(this,"inRow",!1),c(this,"currentRowIndex",-1),c(this,"currentColumnIndex",0),c(this,"originalStopAtOverflow"),c(this,"inHeader"),c(this,"inFooter"),c(this,"didExtractRowSpanningCellBreakPositions",!1),this.originalStopAtOverflow=i.stopAtOverflow,i.stopAtOverflow=!1}startNonInlineElementNode(t){return mp(this.column,t)||super.startNonInlineElementNode(t)}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(t){let i=this.formattingContext.colWidths,n=0;for(let r=0;r<t.colSpan;r++)n+=i[t.anchorSlot.columnIndex+r];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let r=t.rowIndex,o=t.columnIndex,s=t.colSpan,a=i.viewNode;s>1&&(I(a,"box-sizing","border-box"),I(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let l=new Uv(this.column,h,i);return this.formattingContext.addCellFragment(r,o,l),n.primary.steps.length===1&&n.primary.after&&(l.empty=!0),l.pseudoColumn.layout(n,!0).thenAsync(()=>(bp(a),T(!0)))}findBrokenCellAtSlot(t,i){let n=this.formattingContext.cellBreakPositions;for(let r=0;r<n.length;r++){let o=n[r];if(o.cell.anchorSlot.columnIndex===t&&o.cellNodePosition.steps[0].node===i)return{position:o,index:r}}return null}extractRowSpanningCellBreakPositions(){if(this.didExtractRowSpanningCellBreakPositions)return[];let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[];return t.forEach(n=>{let r=n.cell,o=r.rowIndex;if(o<this.currentRowIndex&&o+r.rowSpan>this.currentRowIndex){let s=i[o];s||(s=i[o]=[]),s.push(n)}}),this.didExtractRowSpanningCellBreakPositions=i.length>0,i}layoutRowSpanningCellsFromPreviousFragment(t){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),r=n.reduce(d=>d+1,0);if(r===0)return T(!0);let o=this.column.layoutContext,s=t.nodeContext;s.viewNode.parentNode.removeChild(s.viewNode);let a=D("layoutRowSpanningCellsFromPreviousFragment"),h=T(!0),l=0,u=[];return n.forEach(d=>{h=h.thenAsync(()=>{let p=Lo(d[0].cellNodePosition.steps[1],s.parent);return o.setCurrent(p,!1).thenAsync(()=>{let f=T(!0),g=0;function m(w){for(;g<w;){if(!u.includes(g)){let x=p.viewNode.ownerDocument.createElement("td");I(x,"padding","0"),p.viewNode.appendChild(x)}g++}}return d.forEach(w=>{f=f.thenAsync(()=>{let x=w.cell;m(x.anchorSlot.columnIndex);let y=w.cellNodePosition,b=Lo(y.steps[0],p);return b.offsetInNode=y.offsetInNode,b.after=y.after,b.fragmentIndex=y.steps[0].fragmentIndex+1,o.setCurrent(b,!1).thenAsync(()=>{let S=w.breakChunkPosition;for(let C=0;C<x.colSpan;C++)u.push(g+C);return g+=x.colSpan,this.layoutCell(x,b,S).thenAsync(()=>(b.viewNode.rowSpan=x.rowIndex+x.rowSpan-this.currentRowIndex+r-l,T(!0)))})})}),f.thenAsync(()=>(m(i.getColumnCount()),l++,T(!0)))})})}),h.then(()=>{o.setCurrent(s,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return T(!0);let i=t.nodeContext,n=this.formattingContext;return this.currentRowIndex<0?(i.sourceNode,this.currentRowIndex=n.findRowIndexBySourceNode(i.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(t).thenAsync(()=>{var r;this.registerCellFragmentIndex();let o=t.breakAtTheEdge;if(this.currentRowIndex>0){let a=n.rows[this.currentRowIndex-1];a!=null&&a.breakAfter&&(o=tt(o,a.breakAfter))}let s=n.rows[this.currentRowIndex];return s!=null&&s.breakBefore&&(o=tt(o,s.breakBefore)),!t.leadingEdge&&qe(o)?(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,o),(r=i.viewNode)!=null&&r.parentNode&&i.viewNode.parentNode.removeChild(i.viewNode),t.lastAfterNodeContext&&this.column.layoutContext.processFragmentedBlockEdge(t.lastAfterNodeContext),this.column.pageBreakType=o,this.resetColumn(),t.break=!0,T(!0)):(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,o)&&n.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0),T(!0))})}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(t=>{let i=this.formattingContext.cellBreakPositions.find(n=>n.cell===t);if(i){let n=i.cellNodePosition.steps[0],r=this.column.layoutContext.xmldoc.getElementOffset(n.node);yv(r,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return T(!0);let i=t.nodeContext;this.inRow||(this.currentRowIndex<0?this.currentRowIndex=0:this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0);let n=this.formattingContext.getRowByIndex(this.currentRowIndex).cells[this.currentColumnIndex];if(!n)return t.break=!0,T(!0);let r=i.copy().modify();r.after=!0,t.nodeContext=r;let o=D("startTableCell"),s,a=this.findBrokenCellAtSlot(n.anchorSlot.columnIndex,i.sourceNode);if(a){let h=a.position;this.formattingContext.cellBreakPositions.splice(a.index,1),i.fragmentIndex=h.cellNodePosition.steps[0].fragmentIndex+1,s=T(h.breakChunkPosition)}else s=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(h=>{h.viewNode&&i.viewNode.removeChild(h.viewNode);let l=Ro(h,0);return T(new Ei(l))});return s.then(h=>{this.layoutCell(n,i,h).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,o.finish(!0)})}),o.result()}startNonInlineBox(t){let i=gp(t,Ot(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,r=this.formattingContext.getRepetitiveElements(),o=n.display;return o==="table-header-group"&&r&&r.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,T(!0)):o==="table-footer-group"&&r&&r.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,T(!0)):o==="table-row"?this.startTableRow(t):o==="table-cell"?this.startTableCell(t):T(!0)}endNonInlineBox(t){let i=t.nodeContext;if(i.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let n=i.copy().modify();n.after=!1;let r=new Wv(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(r)}return T(!0)}afterNonInlineElementNode(t){let i=t.nodeContext,n=this.formattingContext.getRepetitiveElements(),r=i.display;if(r==="table-header-group"?n&&!n.allowInsertRepeatitiveElements&&n.isHeaderSourceNode(i.sourceNode)?(this.inHeader=!1,i.viewNode.parentNode.removeChild(i.viewNode)):I(i.viewNode,"display","table-row-group"):r==="table-footer-group"&&(n&&!n.allowInsertRepeatitiveElements&&n.isFooterSourceNode(i.sourceNode)?(this.inFooter=!1,i.viewNode.parentNode.removeChild(i.viewNode)):I(i.viewNode,"display","table-row-group")),r&&yp.ignoreList[r])i.viewNode.parentNode.removeChild(i.viewNode);else if(i.sourceNode===this.formattingContext.tableSourceNode)i.overflow=this.column.checkOverflowAndSaveEdge(i,null),this.resetColumn(),t.break=!0;else if(r==="table-row"&&!this.inHeader&&!this.inFooter){let o=super.afterNonInlineElementNode(t);return(o&&o.isPending()?o:T(!0)).thenAsync(()=>{if(!t.break){let s=this.column.checkOverflowAndSaveEdge(i,null),a=this.formattingContext.getRepetitiveElements(),h=this.column.nodeContextOverflowingDueToRepetitiveElements===i,l=!s&&h&&!!(a!=null&&a.isFooterRegistered());(s||h)&&!l&&this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0)}return T(!0)})}else return super.afterNonInlineElementNode(t);return T(!0)}};c(wp,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Yv=wp,yr=[];function Zv(e){let t=yr.findIndex(n=>n.root===e),i=yr[t];return i?i.tableLayoutOption:null}function Kv(e){let t=yr.findIndex(i=>i.root===e);t>=0&&yr.splice(t,1)}var vp=class{layoutEntireTable(e,t){let i=Ot(e.formattingContext),n=new qv(i,t);return new oa(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let r=e.ownerDocument,o=r.createElement("tr"),s=[];for(let h=0;h<t;h++){let l=r.createElement("td");o.appendChild(l),s.push(l)}e.parentNode.insertBefore(o,e.nextSibling);let a=s.map(h=>{let l=Tt(n,h,i),u=i?l.height:l.width;return Math.ceil(u)});return e.parentNode.removeChild(o),a}getColGroupElements(e){let t=[],i=e.firstElementChild;for(;i;)i.localName==="colgroup"&&t.push(i),i=i.nextElementSibling;return t}normalizeAndGetColElements(e){let t=[];return e.forEach(i=>{let n=i.span;i.removeAttribute("span");let r=i.firstElementChild;for(;r;){if(r.localName==="col"){let o=r.span;for(r.removeAttribute("span"),n-=o;o-- >1;){let s=r.cloneNode(!0);i.insertBefore(s,r),t.push(s)}t.push(r)}r=r.nextElementSibling}for(;n-- >0;)r=i.ownerDocument.createElement("col"),i.appendChild(r),t.push(r)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let r=n.ownerDocument.createElement("colgroup");t.push(r);for(let o=e.length;o<i;o++){let s=n.ownerDocument.createElement("col");r.appendChild(s),e.push(s)}}}normalizeColGroups(e,t,i){let n=e.vertical,r=e.lastRowViewNode;if(!r)return;e.lastRowViewNode=null;let o=r.ownerDocument.createDocumentFragment(),s=e.getColumnCount();if(!(s>0)){e.colGroups=o;return}let a=e.colWidths=this.getColumnWidths(r,s,n,i.clientLayout),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,s,t),l.forEach((u,d)=>{I(u,n?"height":"width",`${a[d]}px`)}),h.forEach(u=>{o.appendChild(u.cloneNode(!0))}),e.colGroups=o}doInitialLayout(e,t){let i=Ot(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=Zv(e.sourceNode);Kv(e.sourceNode);let r=D("TableLayoutProcessor.doInitialLayout"),o=e.copy();return this.layoutEntireTable(e,t).then(s=>{var a;let h=s.viewNode,l=i.rows[0];if(l&&qe(l.breakBefore)&&this.hasInFlowContentBefore(h,t)){(a=h.parentNode)==null||a.removeChild(h),t.pageBreakType=l.breakBefore,r.finish(o);return}let u=Tt(t.clientLayout,h,t.vertical),d=t.vertical?u.left:u.bottom;if(d+=(t.vertical?-1:1)*xn(e,t.collectElementsOffset()).current,!t.isOverflown(d)&&(!n||!n.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(i)){t.breakPositions.push(new tb(o)),r.finish(s);return}this.normalizeColGroups(i,h,t),i.updateCellSizes(t.clientLayout),r.finish(null)}),r.result()}hasForcedBreakInRows(e){for(let t=0;t<e.rows.length;t++){let i=e.rows[t];if(i&&(t>0&&qe(i.breakBefore)||t<e.rows.length-1&&qe(i.breakAfter)))return!0}return!1}hasInFlowContentBefore(e,t){let i=e;for(;i&&i!==t.element;){let n=i.previousSibling;for(;n;){if(n.nodeType===1&&!Nt(n)||n.nodeType===3&&!Le(n))return!0;n=n.previousSibling}i=i.parentNode}return!1}addCaptions(e,t,i){let n=e.captions;n.forEach((r,o)=>{r&&(t.insertBefore(r.viewNode,i),r.side==="top"&&(n[o]=null))})}addColGroups(e,t,i){e.colGroups&&this.getColGroupElements(t).length===0&&(t.insertBefore(e.colGroups.cloneNode(!0),i),I(t,"table-layout","fixed"),I(t,e.vertical?"height":"width",`${e.tableWidth}px`))}removeColGroups(e,t){if(e.colGroups&&t){let i=this.getColGroupElements(t);i&&i.forEach(n=>{t.removeChild(n)})}}doLayout(e,t){let i=Ot(e.formattingContext),n=i.getRootViewNode(e),r=n.firstChild;this.addCaptions(i,n,r),this.addColGroups(i,n,r);let o=new Yv(i,t),s=new oa(o,t.layoutContext),a=D("TableFormattingContext.doLayout");return s.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=Ot(e.formattingContext);return n.getRootViewNode(e)?(i&&dp(e.parent,t),new Qv(n,this).layout(e,t)):t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new Hv(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return Ts(e),!1}finishBreak(e,t,i,n){let r=Ot(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let o=r.findRowIndexBySourceNode(t.sourceNode),s;if(t.after?s=r.getRowSpanningCellsOverflowingTheRow(o):s=r.getCellsFallingOnRow(o),r.cellBreakPositions=r.cellBreakPositions.filter(a=>!s.includes(a.cell)),s.length){let a=D("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===s.length){l.breakLoop();return}let u=s[h++],d=r.getCellFragmentOfCell(u),p=d.findAcceptableBreakPosition().nodeContext,f=d.cellNodeContext,g=f.toNodePosition(),m=new Ei(p.toNodePosition());r.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:m,cell:u});let w=f.viewNode;d.column.layoutContext.processFragmentedBlockEdge(d.cellNodeContext),o<u.rowIndex+u.rowSpan-1&&(w.rowSpan=o-u.rowIndex+1),d.empty?l.continueLoop():d.pseudoColumn.finishBreak(p,!1,!0).then(()=>{Jv(d,r,p),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),Ts(t),r.finishFragment(),a.finish(!0)}),a.result()}}return Ts(t),r.finishFragment(),dl.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){gn.prototype.clearOverflownViewNodes(e,t,i,n)}};function Jv(e,t,i){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let r=t.vertical,o=e.column,s=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,h=Tt(o.clientLayout,a,r),l=o.getComputedPaddingBorder(a);if(r){let u=h.right-o.footnoteEdge-n.calculateOffset(i)-l.right;I(s,"max-width",`${u}px`)}else{let u=o.footnoteEdge-n.calculateOffset(i)-h.top-l.top;I(s,"max-height",`${u}px`)}}function bp(e){let t=e.matches("td, th")?e:e.closest("td, th");if(!t||t.style.verticalAlign!=="baseline")return;let i=t.querySelector(".-vivliostyle-table-cell-container");if(!i)return;let n=i.children;if(n.length!==0){for(let r=0;r<n.length;r++){let o=n[r].style.position;if(o!=="absolute"&&o!=="fixed")return}I(i,"display","contents")}}function Ts(e){let t=e.display==="table-row"?e.viewNode.parentElement:e.display==="table"?e.viewNode.querySelector("tbody"):null;if(!t)return;let i;try{i=t.querySelectorAll(":scope>tr:has(>:empty):not(:has(>:not([rowspan]:not([rowspan='1']),:empty)))")}catch{return}if(i.length===0)return;let n=Array.from(i).reduce((d,p)=>{let f=p.getBoundingClientRect(),g=e.vertical?f.width:f.height;return d+g},0),r=i[i.length-1],o=Array.from(t.children).indexOf(r),s=Array.from(r.children).reduce((d,p)=>{let f=p.rowSpan;return f>1&&o+f<t.childElementCount?Math.max(d,f):d},0),a=s?t.children[o+s-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let d=a;d&&d!==t.lastElementChild;d=d.nextElementSibling)if(d.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=d;break}}let h=a.getBoundingClientRect(),l=e.vertical?h.width:h.height,u=n+l;I(a,e.vertical?"width":"height",`${u}px`)}var Qv=class extends pl{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new eb(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new nb(this.tableFormattingContext,this.processor))}clearNodes(e){super.clearNodes(e);let t=this.tableFormattingContext.getRootViewNode(e);this.processor.removeColGroups(this.tableFormattingContext,t)}restoreState(e,t){super.restoreState(e,t),this.tableFormattingContext.finishFragment()}},eb=class extends hp{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},tb=class extends Or{constructor(e){super(e,null,e.overflow,0)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");return(this.overflows?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}breakPositionChosen(e){e.fragmentLayoutConstraints.push(new ib(this.position.sourceNode))}},ib=class xp{constructor(t){this.tableRootNode=t,c(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,r){i.sourceNode,yr.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return T(!0)}equalsTo(t){return t instanceof xp&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},nb=class extends up{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new rb(e);t.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},rb=class Sp extends Sl{constructor(t){super(t),c(this,"flagmentLayoutConstraintType","TableRow"),c(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||n.pseudoParent||dn(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!pp(t,i,r):!0}nextCandidate(t){let i=Ot(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(t,i).some(n=>n.constraints.some(r=>r.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,r){let o=Ot(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,o),this.cellFragmentLayoutConstraints.forEach(s=>{s.constraints.forEach(a=>{a.postLayout(t,s.breakPosition,n,r)})}),!t){let s=o.getRootViewNode(this.nodeContext);new vp().removeColGroups(o,s),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,r)}finishBreak(t,i){let n=Ot(this.nodeContext.formattingContext),r=D("finishBreak"),o=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.breakPosition}))),[]),s=0;return r.loop(()=>{if(s<o.length){let a=o[s++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return T(!1)}).then(()=>{r.finish(!0)}),r.result().thenAsync(()=>super.finishBreak(t,i))}removeDummyRowNodes(t){if(!(!t||t.display!=="table-row"||!t.viewNode))for(;t.viewNode.previousElementSibling;){let i=t.viewNode.previousElementSibling;i.parentNode&&i.parentNode.removeChild(i)}}collectCellFragmentLayoutConstraints(t,i){return this.getCellFragemnts(t,i).map(n=>({constraints:n.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:n.breakPosition}))}getCellFragemnts(t,i){let n=Number.MAX_VALUE;t&&t.display==="table-row"&&(t.sourceNode,n=i.findRowIndexBySourceNode(t.sourceNode)+1),n=Math.min(i.cellFragments.length,n);let r=[];for(let o=0;o<n;o++)i.cellFragments[o]&&i.cellFragments[o].forEach(s=>{s&&r.push({fragment:s,breakPosition:s.findAcceptableBreakPosition().nodeContext})});return r}getElementsOffsetsForTableCell(t){let i=Ot(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof Sp?Ot(this.nodeContext.formattingContext)===Ot(t.nodeContext.formattingContext):!1}},ob=new vp;function sb(e,t,i,n,r,o){if(!t)return null;if(i===v.table){let s=e.parent;return new Sn(s?s.formattingContext:null,e.sourceNode)}return null}function ab(e){return e instanceof Sn?ob:null}At("RESOLVE_FORMATTING_CONTEXT",sb);At("RESOLVE_LAYOUT_PROCESSOR",ab);function Wh(e){return e.reduce((t,i)=>t+i,0)/e.length}function lb(e){let t=Wh(e);return Wh(e.map(i=>{let n=i-t;return n*n}))}var hb=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function vr(e){return e.vertical?e.width:e.height}function br(e,t){e.vertical?e.width=t:e.height=t}var Cp=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,c(this,"originalContainerBlockSize"),this.originalContainerBlockSize=vr(e)}balanceColumns(e){let t=D("ColumnBalancer#balanceColumns");this.layoutContainer.element.setAttribute("data-vivliostyle-in-column-balancing","true"),this.preBalance(e),this.savePageFloatLayoutContexts(e),this.layoutContainer.clear();let i=[this.createTrialResult(e)];return t.loopWithFrame(n=>{if(!this.hasNextCandidate(i)){n.breakLoop();return}this.updateCondition(i),this.columnGenerator().then(r=>{if(this.savePageFloatLayoutContexts(r),this.layoutContainer.clear(),!r){n.breakLoop();return}i.push(this.createTrialResult(r)),n.continueLoop()})}).then(()=>{let n=i.reduce((r,o)=>o.penalty<r.penalty?o:r,i[0]);this.layoutContainer.element.removeAttribute("data-vivliostyle-in-column-balancing"),this.restoreContents(n.layoutResult),this.tightenColumnBlockSizes(n.layoutResult.columns),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new hb(e,t)}preBalance(e){}postBalance(){br(this.layoutContainer,this.originalContainerBlockSize)}tightenColumnBlockSizes(e){if(e.length<=1)return;let t=Math.max.apply(null,e.map(i=>i.computedBlockSize));if(!(t<=0))for(let i of e)if(i.vertical){let n=parseFloat(i.element.style.width),r=parseFloat(i.element.style.left);if(isFinite(n)&&isFinite(r)&&n>t){let o=r+n-t;I(i.element,"width",`${t}px`),I(i.element,"left",`${o}px`),i.width=t,i.left=o}}else{let n=parseFloat(i.element.style.height);isFinite(n)&&n>t&&(I(i.element,"height",`${t}px`),i.height=t)}}savePageFloatLayoutContexts(e){let t=this.regionPageFloatLayoutContext.detachChildren();e&&(e.columnPageFloatLayoutContexts=t)}restoreContents(e){let t=this.layoutContainer.element;e.columns.forEach(i=>{t.appendChild(i.element)}),e.columnPageFloatLayoutContexts,this.regionPageFloatLayoutContext.attachChildren(e.columnPageFloatLayoutContexts)}},va=1;function kp(e){let t=e[e.length-1];if(t.penalty===0)return!1;let i=e[e.length-2];if(i&&t.penalty>=i.penalty)return!1;let n=t.layoutResult.columns,r=Math.max.apply(null,n.map(s=>s.computedBlockSize)),o=Math.max.apply(null,n.map(s=>s.getMaxBlockSizeOfPageFloats()));return r>o+va}function Ep(e,t){let i=e[e.length-1].layoutResult.columns,n=Math.max.apply(null,i.map(r=>isNaN(r.blockDistanceToBlockEndFloats)?r.computedBlockSize:r.computedBlockSize-r.blockDistanceToBlockEndFloats+va))-va;n<vr(t)?br(t,n):br(t,vr(t)-1)}var ub=class extends Cp{constructor(e,t,i,n){super(i,e,t),this.columnCount=n,c(this,"originalPosition",null),c(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);br(this.layoutContainer,t/this.columnCount),this.originalPosition=e.position}checkPosition(e){return this.originalPosition?this.originalPosition.isSamePosition(e):e===null}calculatePenalty(e){if(!this.checkPosition(e.position))return 1/0;let t=e.columns;return Gh(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return kp(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!Gh(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):vr(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Ep(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,vr(this.layoutContainer)+this.originalContainerBlockSize*.1);br(this.layoutContainer,t)}}};function Gh(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize,i=e.slice(0,e.length-1),n=Math.max(...e.map(o=>o.lastLineStride||0)),r=n>0?n/2:6;return i.every(o=>t>o.computedBlockSize+r)}var cb=class extends Cp{constructor(e,t,i){super(i,e,t)}calculatePenalty(e){if(e.columns.every(i=>i.computedBlockSize===0))return 1/0;let t=e.columns.filter(i=>!i.pageBreakType).map(i=>i.computedBlockSize);return lb(t)}hasNextCandidate(e){return kp(e)}updateCondition(e){Ep(e,this.layoutContainer)}};function db(e,t,i,n,r,o,s){if(t===v.auto)return null;{let a=s.positions.length===0,h=o[o.length-1],l=!!(h&&h.pageBreakType);return a||l?new ub(i,n,r,e):t===v.balance_all?new cb(i,n,r):(v.balance,null)}}var pb=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],fb=new Set(pb);function gb(e){return!(e.toLowerCase()==="none"||fb.has(e))}var mb=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],wb=new Set(mb),yb=["fixed","extends"],vb=new Set(yb),qx=Symbol();function Br(e){return e instanceof de&&e.name.toLowerCase()!=="none"}function Pp(e){return e.name}function bb(e){if(e instanceof de)return wb.has(e.name);if(e instanceof J&&e.values.length===2){let t=e.values[0],i=e.values[1];if(t instanceof de){let n=t.name;return vb.has(n)&&(n==="fixed"&&i instanceof Ue||n==="extends"&&Br(i))}}return!1}function xb(e){let t=ht(e,"system");return t instanceof de&&t.name==="cyclic"}function Sb(e){let t=ht(e,"system");if(t instanceof de&&t.name==="fixed")return!0;if(t instanceof J&&t.values.length===2){let[i,n]=t.values;return i instanceof de&&i.name==="fixed"&&n instanceof Ue}return!1}function Cb(e){let t=ht(e,"system");return t instanceof de?1:t.values[1].num}function kb(e){let t=ht(e,"system");return t instanceof de&&t.name==="alphabetic"}function Eb(e){let t=ht(e,"system");return t instanceof de&&t.name==="numeric"}function Pb(e){let t=ht(e,"system");return t instanceof de&&t.name==="additive"}function Nb(e){let t=ht(e,"system");if(t instanceof J&&t.values.length===2){let[i,n]=t.values;return i instanceof de&&i.name==="extends"&&Br(n)}return!1}function Tb(e){let t=ht(e,"system");return Pp(t.values[1])}function zt(e){return e instanceof X||e instanceof de}function oi(e){return e instanceof X?e.str:e.name}function Np(e){if(zt(e))return!0;if(e instanceof J&&e.values.length===2){let t=e.values[0],i=e.values[1];return zt(t)&&zt(i)}return!1}function Ib(e){if(zt(e))return{prefix:oi(e),suffix:null};{let t=e.values[0],i=e.values[1];return{prefix:oi(t),suffix:oi(i)}}}function jh(e){return e instanceof Ue||e instanceof de&&e.name==="infinite"}function $o(e,t){return e instanceof Ue?e.num:t?-1/0:1/0}var Yx=Symbol();function ba(e){if(!(e instanceof J&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(jh(t)&&jh(i)))return!1;let n=$o(t,!0),r=$o(i,!1);return!(n>r)}function Ab(e){return{lower:$o(e.values[0],!0),upper:$o(e.values[1],!1)}}function Tp(e){return e instanceof de&&e.name==="auto"||ba(e)||e instanceof it&&e.values.length>=1&&e.values.every(t=>ba(t))}function Fb(e){return e instanceof de?null:(ba(e)?[e]:e.values).map(t=>Ab(t))}var Zx=Symbol();function Ho(e){if(!(e instanceof J&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];return t instanceof Ue&&t.num>=0&&zt(i)||zt(t)&&i instanceof Ue&&i.num>=0}function Wo(e){let[t,i]=e.values;return t instanceof Ue?[t.num,oi(i)]:[i.num,oi(t)]}function Ip(e){return Ho(e)}function Rb(e){let[t,i]=Wo(e);return{minLength:t,symbol:i}}function Ap(e){return zt(e)||e instanceof J&&e.values.length>=1&&e.values.every(t=>zt(t))}function Lb(e){return zt(e)?[oi(e)]:e.values.map(t=>oi(t))}var Kx=Symbol();function Fp(e){if(Ho(e))return!0;if(e instanceof it&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!Ho(i))return!1;let[n]=Wo(i);if(n>=t)return!1;t=n}return!0}return!1}function Ob(e){if(Ho(e)){let[t,i]=Wo(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=Wo(t);return{weight:i,symbol:n}})}var Bb=["auto","bullets","numbers","words","spell-out"],Mb=new Set(Bb);function _b(e){return e instanceof de&&Mb.has(e.name)||Br(e)}function Db(e,t){switch(e){case"system":return bb(t);case"negative":return Np(t);case"prefix":case"suffix":return zt(t);case"range":return Tp(t);case"pad":return Ip(t);case"fallback":return Br(t);case"symbols":return Ap(t);case"additive-symbols":return Fp(t);case"speak-as":return _b(t);default:return!0}}function ht(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function zb(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function An(e){let t=e.get("decimal");return t||(t=ce.createDecimal(e),e.set("decimal",t)),t}var ao,lo,ho,uo,co,po,fo,go,xa,Sa,Ca,ka,Ea,Pa,Na,pt,Is,Rp,Lp,Xh,qh,As,Yh,Zn,fi=class Li{constructor(t,i){ie(this,pt),c(this,"_store"),ie(this,ao),ie(this,lo),ie(this,ho),ie(this,uo),ie(this,co),ie(this,po),ie(this,fo),ie(this,go),this._store=t;let n=ht(i,"negative");Ve(this,ao,n&&Np(n)?Ib(n):null);let r=ht(i,"prefix");Ve(this,lo,r&&zt(r)?oi(r):null);let o=ht(i,"suffix");Ve(this,ho,o&&zt(o)?oi(o):null);let s=ht(i,"range");Ve(this,uo,s&&Tp(s)?Fb(s):null);let a=ht(i,"pad");Ve(this,co,a&&Ip(a)?Rb(a):null);let h=ht(i,"fallback");Ve(this,po,h&&Br(h)?Pp(h):null);let l=ht(i,"symbols");Ve(this,fo,l&&Ap(l)?Lb(l):null);let u=ht(i,"additive-symbols");Ve(this,go,u&&Fp(u)?Ob(u):null)}static create(t,i){return xb(i)?new Ti(t,i):Sb(i)?new Vb(t,i):kb(i)?new $b(t,i):Eb(i)?new Zh(t,i):Pb(i)?new Hb(t,i):Nb(i)?new Wb(t,i):new Ub(t,i)}static createDecimal(t){return new Zh(t,$(Li,xa))}static createDisc(t){return new Ti(t,$(Li,Sa))}static createSquare(t){return new Ti(t,$(Li,Ca))}static createCircle(t){return new Ti(t,$(Li,ka))}static createDisclosureOpen(t){return new Ti(t,$(Li,Ea))}static createDisclosureClosed(t){return new Ti(t,$(this,Pa))}static createNone(t){return new Ti(t,$(Li,Na))}static get CHINESE_LONGHAND_NAMES(){return Kh.NAMES}static createChineseLonghand(t,i){return new Kh(t,i)}static createEthiopicNumeric(t){return new jb(t)}_getNegative(){return $(this,ao)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return $(this,lo)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return $(this,ho)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return $(this,uo)}static _getRangeFrom(t){return t._getRange()}_getPad(){return $(this,co)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get($(this,po)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return $(this,fo)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return $(this,go)}static _getAdditiveSymbolsFrom(t){return t._getAdditiveSymbols()}static _useNegativeSignFrom(t,i){return t._usesNegativeSign(i)}static _generateInitialRepresentationFrom(t,i){return t._generateInitialRepresentation(i)}format(t){return Ne(this,pt,Zn).call(this,t,new Set)}formatMarker(t){return Ne(this,pt,Rp).call(this)+this.format(t)+Ne(this,pt,Lp).call(this)}};ao=new WeakMap,lo=new WeakMap,ho=new WeakMap,uo=new WeakMap,co=new WeakMap,po=new WeakMap,fo=new WeakMap,go=new WeakMap,xa=new WeakMap,Sa=new WeakMap,Ca=new WeakMap,ka=new WeakMap,Ea=new WeakMap,Pa=new WeakMap,Na=new WeakMap,pt=new WeakSet,Is=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},Rp=function(){var e;return(e=this._getPrefix())!=null?e:""},Lp=function(){var e;return(e=this._getSuffix())!=null?e:". "},Xh=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},qh=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},As=function(){var e;return(e=this._getFallback())!=null?e:An(this._store)},Yh=function(e,t){let{minLength:i,symbol:n}=Ne(this,pt,qh).call(this);if(i===0||n==="")return e;let{prefix:r,suffix:o}=Ne(this,pt,Is).call(this),s=t?[...r].length+(o?[...o].length:0):0,a=i-[...e].length-s;if(a<=0)return e;let h=[...n].length,l=Math.ceil(a/h);return n.repeat(l)+e},Zn=function(e,t){var i,n,r;if(t.has(this))return Ne(i=An(this._store),pt,Zn).call(i,e,new Set);if(t.add(this),!zb(e,Ne(this,pt,Xh).call(this))){let l=Ne(this,pt,As).call(this);return Ne(n=l,pt,Zn).call(n,e,t)}let o=this._usesNegativeSign(e),s=o?Math.abs(e):e,a=this._generateInitialRepresentation(s);if(a===null){let l=Ne(this,pt,As).call(this);return Ne(r=l,pt,Zn).call(r,e,t)}let h=Ne(this,pt,Yh).call(this,a,o);if(o){let{prefix:l,suffix:u}=Ne(this,pt,Is).call(this);h=l+h+(u??"")}return h},ie(fi,xa,{system:new V(M("numeric"),0),symbols:new V(new J([new X("0"),new X("1"),new X("2"),new X("3"),new X("4"),new X("5"),new X("6"),new X("7"),new X("8"),new X("9")]),0)}),ie(fi,Sa,{system:new V(M("cyclic"),0),symbols:new V(new X("\u2022"),0),suffix:new V(new X(" "),0)}),ie(fi,Ca,{system:new V(M("cyclic"),0),symbols:new V(new X("\u25AA"),0),suffix:new V(new X(" "),0)}),ie(fi,ka,{system:new V(M("cyclic"),0),symbols:new V(new X("\u25E6"),0),suffix:new V(new X(" "),0)}),ie(fi,Ea,{system:new V(M("cyclic"),0),symbols:new V(new X("\u25BE"),0),suffix:new V(new X(" "),0)}),ie(fi,Pa,{system:new V(M("cyclic"),0),symbols:new V(new X("\u25B8"),0),suffix:new V(new X(" "),0)}),ie(fi,Na,{system:new V(M("cyclic"),0),symbols:new V(new X(""),0),suffix:new V(new X(""),0)});var ce=fi,Ti=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0)return null;let i=t.length,n=((e-1)%i+i)%i;return t[n]}},mo,Vb=class extends ce{constructor(e,t){super(e,t),ie(this,mo),Ve(this,mo,Cb(t))}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){var t;let i=this._getSymbols();if(!i||i.length===0)return null;let n=e-$(this,mo);return(t=i[n])!=null?t:null}};mo=new WeakMap;var Ub=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0||e<1)return null;let i=t.length,n=t[(e-1)%i],r=Math.ceil(e/i);return n.repeat(r)}},$b=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2||e<1)return null;let i=t.length,n="",r=e;for(;r!==0;)r=r-1,n=t[r%i]+n,r=Math.floor(r/i);return n}},Zh=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2)return null;let i=t.length;if(e===0)return t[0];let n="",r=e;for(;r!==0;)n=t[r%i]+n,r=Math.floor(r/i);return n}},Hb=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getAdditiveSymbols();if(!t||t.length===0)return null;let i="";if(e===0){let r=t.find(o=>o.weight===0);return r?r.symbol:null}let n=e;for(let r of t){let{weight:o,symbol:s}=r;if(o===0||o>n)continue;let a=Math.floor(n/o);if(i+=s.repeat(a),n-=o*a,n===0)return i}return null}},ar,yt,Pt,Op=class extends ce{constructor(t,i){super(t,i),ie(this,yt),ie(this,ar);let n=Tb(i),r=n.toLowerCase();r==="disc"||r==="circle"||r==="square"||r==="disclosure-open"||r==="disclosure-closed"?Ve(this,ar,r):Ve(this,ar,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:ce._getNegativeFrom(Ne(this,yt,Pt).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:ce._getPrefixFrom(Ne(this,yt,Pt).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:ce._getSuffixFrom(Ne(this,yt,Pt).call(this))}_getAutoRange(){return ce._getAutoRangeFrom(Ne(this,yt,Pt).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:ce._getRangeFrom(Ne(this,yt,Pt).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:ce._getPadFrom(Ne(this,yt,Pt).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:ce._getFallbackFrom(Ne(this,yt,Pt).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:ce._getSymbolsFrom(Ne(this,yt,Pt).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:ce._getAdditiveSymbolsFrom(Ne(this,yt,Pt).call(this))}_usesNegativeSign(t){return ce._useNegativeSignFrom(Ne(this,yt,Pt).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:ce._generateInitialRepresentationFrom(Ne(this,yt,Pt).call(this),t)}};ar=new WeakMap,yt=new WeakSet,Pt=function(e=new Set){var t;if(e.has(this))return An(this._store);e.add(this);let i=this._store.get($(this,ar));return i?i instanceof Op?Ne(t=i,yt,Pt).call(t,e):i:An(this._store)};var Wb=Op,Gb=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],Fs,Rs,Zr,Ls,Ta,wo,Rt=class Bp extends ce{constructor(t,i){let{chars:n,descriptors:r}=$(Bp,Ta).get(i);super(t,r),ie(this,wo),Ve(this,wo,n)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=$(this,wo);if(t===0)return i.digits[0];let n=[],r=0,o=t;for(;o>0;)n.unshift({digit:o%10,position:r}),o=Math.floor(o/10),r++;let s=i.informal&&t>=10&&t<=19,a="",h=!1;for(let l=0;l<n.length;l++){let{digit:u,position:d}=n[l],p=l===n.length-1;u===0?!p&&!h&&(h=!0):(h&&(a+=i.digits[0],h=!1),s&&d===1?a+=i.markers[d]:(a+=i.digits[u],d>0&&(a+=i.markers[d])))}return a}};Fs=new WeakMap,Rs=new WeakMap,Zr=new WeakMap,Ls=new WeakMap,Ta=new WeakMap,wo=new WeakMap,ie(Rt,Fs,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new V(new X("\u3001"),0),fallback:new V(M("cjk-decimal"),0),range:new V(new J([new Ue(-9999),new Ue(9999)]),0),negative:new V(new X("\u8D1F"),0)}}),ie(Rt,Rs,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new V(new X("\u3001"),0),fallback:new V(M("cjk-decimal"),0),range:new V(new J([new Ue(-9999),new Ue(9999)]),0),negative:new V(new X("\u8D1F"),0)}}),ie(Rt,Zr,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new V(new X("\u3001"),0),fallback:new V(M("cjk-decimal"),0),range:new V(new J([new Ue(-9999),new Ue(9999)]),0),negative:new V(new X("\u8CA0"),0)}}),ie(Rt,Ls,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new V(new X("\u3001"),0),fallback:new V(M("cjk-decimal"),0),range:new V(new J([new Ue(-9999),new Ue(9999)]),0),negative:new V(new X("\u8CA0"),0)}}),c(Rt,"NAMES",new Set(Gb)),ie(Rt,Ta,new Map([["simp-chinese-informal",$(Rt,Fs)],["simp-chinese-formal",$(Rt,Rs)],["trad-chinese-informal",$(Rt,Zr)],["trad-chinese-formal",$(Rt,Ls)],["cjk-ideographic",$(Rt,Zr)]]));var Kh=Rt,Ia,Aa,Go,Fa,Ra,hn=class Oi extends ce{constructor(t){super(t,$(Oi,Ia))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return $(Oi,Go)[1];let i=[],n=t;for(;n>0;)i.push(n%100),n=Math.floor(n/100);let r=i.length,o="";for(let s=r-1;s>=0;s--){let a=i[s],h=s%2===1,l=s===r-1;if(!(a===0||l&&a===1||h&&a===1)){let u=Math.floor(a/10),d=a%10;o+=$(Oi,Aa)[u]+$(Oi,Go)[d]}h?a!==0&&(o+=$(Oi,Fa)):s!==0&&(o+=$(Oi,Ra))}return o}};Ia=new WeakMap,Aa=new WeakMap,Go=new WeakMap,Fa=new WeakMap,Ra=new WeakMap,ie(hn,Ia,{range:new V(new J([new Ue(1),M("infinite")]),0),suffix:new V(new X("/ "),0)}),ie(hn,Aa,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ie(hn,Go,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ie(hn,Fa,"\u137B"),ie(hn,Ra,"\u137C");var jb=hn,Ae,Xb=class{constructor(){ie(this,Ae),Ve(this,Ae,new Map),$(this,Ae).set("none",ce.createNone($(this,Ae))),$(this,Ae).set("decimal",ce.createDecimal($(this,Ae))),$(this,Ae).set("disc",ce.createDisc($(this,Ae))),$(this,Ae).set("square",ce.createSquare($(this,Ae))),$(this,Ae).set("circle",ce.createCircle($(this,Ae))),$(this,Ae).set("disclosure-open",ce.createDisclosureOpen($(this,Ae))),$(this,Ae).set("disclosure-closed",ce.createDisclosureClosed($(this,Ae)));for(let e of ce.CHINESE_LONGHAND_NAMES)$(this,Ae).set(e,ce.createChineseLonghand($(this,Ae),e));$(this,Ae).set("ethiopic-numeric",ce.createEthiopicNumeric($(this,Ae)))}define(e,t){if(!gb(e))return null;let i=ce.create($(this,Ae),t);return $(this,Ae).set(e,i),i}getStyle(e){var t;return(t=$(this,Ae).get(e))!=null?t:null}format(e,t){var i;return((i=this.getStyle(e))!=null?i:An($(this,Ae))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:An($(this,Ae))).formatMarker(t)}};Ae=new WeakMap;var Os=class{constructor(e,t,i){c(this,"endStuckFixed"),c(this,"endFixed"),c(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},qb=class{constructor(){c(this,"map",[])}getMaxFixed(){return this.map.length==0?0:this.map[this.map.length-1].endFixed}getMaxSlipped(){return this.map.length==0?0:this.map[this.map.length-1].endSlipped}addStuckRange(e){if(this.map.length==0)this.map.push(new Os(e,e,e));else{let t=this.map[this.map.length-1],i=t.endSlipped+e-t.endFixed;t.endFixed==t.endStuckFixed?(t.endFixed=e,t.endStuckFixed=e,t.endSlipped=i):this.map.push(new Os(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new Os(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=ai(this.map.length,n=>e<=this.map[n].endFixed),i=this.map[t];return i.endSlipped-Math.max(0,i.endStuckFixed-e)}fixedBySlipped(e){let t=ai(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}};function Yb(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}var Zb=class La{constructor(t,i,n,r,o,s,a,h){if(this.context=t,this.style=i,this.offset=n,this.isRoot=r,this.flowChunk=o,this.atBlockStart=s,this.atFlowStart=a,this.isParentBoxDisplayed=h,c(this,"flowName"),c(this,"isBlockValue",null),c(this,"hasBoxValue",null),c(this,"styleValues",{}),c(this,"beforeBox",null),c(this,"afterBox",null),c(this,"breakBefore",null),this.flowName=o.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let u=new La(t,l.before,n,!1,o,this.isBlock(),a,!0),d=u.styleValue("content");kt(d)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=tt(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&qe(this.breakBefore)&&(o.breakBefore=tt(o.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let r=this.style._pseudos;if(r&&r.after){let o=new La(this.context,r.after,t,!1,this.flowChunk,i,n,!0),s=o.styleValue("content");kt(s)&&(this.afterBox=o)}}}styleValue(t,i){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):i||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",v.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=ed(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==v.none&&!To(this.styleValue("position"))),this.hasBoxValue}getBreakValue(t){let i=null;if(this.isBlock()){let n=this.styleValue(`break-${t}`);n&&(i=n.toString())}return i}},Kb=class{constructor(e){this.context=e,c(this,"stack",[]),c(this,"atBlockStart",!0),c(this,"atFlowStart",!0),c(this,"atStartStack",[])}empty(){return this.stack.length===0}lastBox(){return this.stack[this.stack.length-1]}lastFlowName(){let e=this.lastBox();return e?e.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(e=>e.displayValue()!==v.none)}push(e,t,i,n){let r=this.lastBox();n&&r&&n.flowName!==r.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let o=n||r.flowChunk,s=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),h=new Zb(this.context,e,t,i,o,s||this.atBlockStart,s,a);return this.stack.push(h),this.atBlockStart=h.hasBox()?!h.beforeBox&&h.isBlock():this.atBlockStart,this.atFlowStart=h.hasBox()?!h.beforeBox&&s:this.atFlowStart,h}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",v.normal).toString(),n=gd(i);n&&!Le(e,n)&&(this.atBlockStart=!1,this.atFlowStart=!1)}}pop(e){let t=this.stack.pop();if(t.buildAfterPseudoElementBox(e,this.atBlockStart,this.atFlowStart),this.atFlowStart&&t.afterBox){let n=t.afterBox.getBreakValue("before");t.flowChunk.breakBefore=tt(t.flowChunk.breakBefore,n)}let i=this.lastBox();if(i)if(i.flowName===t.flowName)t.hasBox()&&(this.atBlockStart=this.atFlowStart=!1);else{let n=this.atStartStack.pop();this.atBlockStart=n.atBlockStart,this.atFlowStart=n.atFlowStart}return t}nearestBlockStartOffset(e){if(!e.atBlockStart)return e.offset;let t=this.stack.length-1,i=this.stack[t];for(i===e&&(t--,i=this.stack[t]);t>=0;){if(i.flowName!==e.flowName)return e.offset;if(!i.atBlockStart||i.isRoot)return i.offset;e=i,i=this.stack[--t]}throw new Error("No block start offset found!")}},Jh=class{constructor(e,t,i,n,r,o,s,a,h,l){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=r,this.validatorSet=o,this.counterListener=s,c(this,"root"),c(this,"cascadeHolder"),c(this,"last"),c(this,"rootStyle",{}),c(this,"styleMap",{}),c(this,"counterSnapshots",[]),c(this,"flows",{}),c(this,"flowChunks",[]),c(this,"flowListener",null),c(this,"flowToReach",null),c(this,"idToReach",null),c(this,"cascade"),c(this,"offsetMap"),c(this,"primary",!0),c(this,"primaryStack",[]),c(this,"rootBackgroundAssigned",!1),c(this,"rootLayoutAssigned",!1),c(this,"lastOffset"),c(this,"breakBeforeValues",{}),c(this,"boxStack"),c(this,"bodyReached",!0),this.root=e.root,this.cascadeHolder=t,this.last=this.root,this.cascade=t.createInstance(n,s,a,e.lang,h,l),this.offsetMap=new qb;let u=e.getElementOffset(this.root);this.lastOffset=u,this.boxStack=new Kb(n),this.offsetMap.addStuckRange(u);let d=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,d,u),this.recordCounterSnapshot(u,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes),this.postprocessTopStyle(d,!1),this.root.namespaceURI){case"http://www.w3.org/1999/xhtml":this.bodyReached=!1;break}this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${u}`]=d,this.lastOffset++,this.replayFlowElementsFromOffset(-1)}hasProp(e,t,i){let n=e[i];return n&&n.evaluate(this.context)!==t[i]}transferPropsToRoot(e,t){for(let i in t){let n=e[i];if(n)this.rootStyle[i]=n,delete e[i];else{let r=t[i];r&&(this.rootStyle[i]=new V(r,jc))}}}postprocessTopStyle(e,t){var i;if(t)for(let n of["writing-mode","direction"])e[n]&&!(t&&this.rootStyle[n])&&(this.rootStyle[n]=e[n]);else for(let n in e)mn(n)&&(this.rootStyle[n]=e[n]);if(!this.rootBackgroundAssigned){let n=this.hasProp(e,this.validatorSet.backgroundProps,"background-color")?e["background-color"].evaluate(this.context):null,r=this.hasProp(e,this.validatorSet.backgroundProps,"background-image")?e["background-image"].evaluate(this.context):null;(n&&!Z(n)||r&&!Z(r))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<Qh.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,Qh[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],r=!0;if(n&&!Z(n.value)){let a=n.evaluate(this.context);if(a instanceof R){let h=a.num;switch(a.unit){case"em":case"rem":h*=this.context.initialFontSize;break;case"%":h*=this.context.initialFontSize/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*Wt.lh/Wt.em;break;default:{let l=Wt[a.unit];l&&(h*=l),r=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=r}}let o=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,s=e["line-height"];if(s&&!Z(s.value)){let a=s.evaluate(this.context);if(a instanceof Ct)this.context.rootLineHeight=a.num*o;else if(a instanceof R){let h=a.num;switch(a.unit){case"em":case"rem":h*=o;break;case"%":h*=o/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let l=Wt[a.unit];l&&(h*=l)}}this.context.rootLineHeight=h}}else this.context.rootLineHeight=this.context.fontSize()*this.context.pref.lineHeight}}getTopContainerStyle(){let e=0;for(;!this.bodyReached&&(e+=5e3,this.styleUntil(e,0)!=Number.POSITIVE_INFINITY););return this.rootStyle}getAttrStyle(e){if(e.style instanceof CSSStyleDeclaration){let t=e.getAttribute("style");if(t)return uv(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}recordCounterSnapshot(e,t,i=[],n){let r={offset:e,counters:Yb(t),changes:Array.from(i||[]),changeTypes:n?{...n}:void 0},o=this.counterSnapshots[this.counterSnapshots.length-1];if(o&&o.offset===e){this.counterSnapshots[this.counterSnapshots.length-1]=r;return}this.counterSnapshots.push(r)}getCounterSnapshotAtOffset(e){if(!this.counterSnapshots.length)return null;let t=ai(this.counterSnapshots.length,n=>e<this.counterSnapshots[n].offset),i=t===0?0:t-1;return this.counterSnapshots[i]||null}getLastCounterSnapshot(){return this.counterSnapshots.length?this.counterSnapshots[this.counterSnapshots.length-1]:null}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(e){if(e>=this.lastOffset)return;let t=this.context,i=this.xmldoc.getElementOffset(this.root);if(e<i){let o=this.getStyle(this.root,!1);if(!this.cascade.firstPageType){let l=o.page,u=l&&!Z(l.value)&&l.value.toString();u&&u.toLowerCase()!=="auto"&&(this.cascade.firstPageType=u)}let s=me(o,"flow-into"),a=s?s.evaluate(t,"flow-into").toString():"body",h=this.encounteredFlowElement(a,o,this.root,i);this.boxStack.empty()&&this.boxStack.push(o,i,!0,h)}let n=this.xmldoc.getNodeByOffset(e),r=this.xmldoc.getNodeOffset(n,0,!1);if(!(r>=this.lastOffset))for(;;){if(n.nodeType!=1)r+=n.textContent.length;else{let s=n,a=this.getStyle(s,!1),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,a,s,r)}r++}if(r>=this.lastOffset)break;let o=n.firstChild;if(o==null){for(;o=n.nextSibling,!o;)if(n=n.parentNode,n===this.root)return}n=o}}resetFlowChunkStream(e){this.flowListener=e;for(let t=0;t<this.flowChunks.length;t++)this.flowListener.encounteredFlowChunk(this.flowChunks[t],this.flows[this.flowChunks[t].flowName])}styleUntilFlowIsReached(e){this.flowToReach=e;let t=0;for(;!(this.flowToReach==null||(t+=5e3,this.styleUntil(t,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(e){if(!e)return;this.idToReach=e;let t=0;for(;!(!this.idToReach||(t+=5e3,this.styleUntil(t,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(e,t,i,n){let r=0,o=Number.POSITIVE_INFINITY,s=!1,a=!1,h=!1,l=t["flow-options"];if(l){let m=Gg(l.evaluate(this.context,"flow-options"));s=!!m.exclusive,a=!!m.static,h=!!m.last}let u=t["flow-linger"];u&&(o=dh(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let d=t["flow-priority"];d&&(r=dh(d.evaluate(this.context,"flow-priority"),0));let p=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let m=this.boxStack.lastFlowName();f=this.flows[e]=new zw(e,m)}let g=new Vw(e,i,n,r,o,s,a,h,p);return this.flowChunks.push(g),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(e,t,i){if(qe(e)){let r=this.flows[i].forcedBreakOffsets;(r.length===0||r[r.length-1]<t)&&r.push(t)}let n=this.breakBeforeValues[t];this.breakBeforeValues[t]=tt(n,e)}styleUntil(e,t){let i=-1,n;if(e<=this.lastOffset&&(n=this.offsetMap.slippedByFixed(e),i=n+t,i<this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i);if(this.last==null)return Number.POSITIVE_INFINITY;let r=this.context;for(;this.last;){let o=this.last.firstChild;if(o==null)for(;this.last;){if(this.last.nodeType==1){this.cascade.popElement(this.last),this.primary=this.primaryStack.pop();let s=this.boxStack.pop(this.lastOffset),a=null;if(s.afterBox){let h=s.afterBox.getBreakValue("before");this.registerForcedBreakOffset(h,s.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(s):s.afterBox.offset,s.flowName),a=s.afterBox.getBreakValue("after")}a=tt(a,s.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,s.flowName)}if(o=this.last.nextSibling,o)break;if(this.last=this.last.parentNode,!this.last||this.last===this.root)return this.last=null,e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(i):Number.POSITIVE_INFINITY}if(this.last=o,this.last.nodeType!=1)this.lastOffset+=this.last.textContent.length,this.boxStack.encounteredTextNode(this.last),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let s=this.last,a=this.getAttrStyle(s);this.primaryStack.push(this.primary),this.cascade.pushElement(this,s,a,this.lastOffset),this.cascade.lastCounterChanges.length>0&&this.recordCounterSnapshot(this.lastOffset,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes);let h=s.getAttribute("id")||s.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");h&&h===this.idToReach&&(this.idToReach=null),!this.bodyReached&&s.localName=="body"&&s.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let l,u=a["flow-into"];if(u){let p=u.evaluate(r,"flow-into").toString(),f=this.encounteredFlowElement(p,a,s,this.lastOffset);this.primary=!!this.primaryFlows[p],l=this.boxStack.push(a,this.lastOffset,s===this.root,f)}else l=this.boxStack.push(a,this.lastOffset,s===this.root),s===this.xmldoc.body&&(l.breakBefore=tt(l.flowChunk.breakBefore,l.breakBefore));let d=this.boxStack.nearestBlockStartOffset(l);if(d===0||s===this.xmldoc.body){let p=a.page,f=p&&!Z(p.value)&&p.value.toString();!this.cascade.firstPageType&&f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(l.breakBefore,d,l.flowName),l.beforeBox){let p=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(p,l.beforeBox.atBlockStart?d:l.offset,l.flowName)}if(this.primary&&l.displayValue()===v.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=a,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&d===0)continue;if(e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i)}}return Number.POSITIVE_INFINITY}getStyle(e,t){let i=this.xmldoc.getElementOffset(e),n=`e${i}`;return t&&(i=this.xmldoc.getNodeOffset(e,0,!0)),this.lastOffset<=i&&this.styleUntil(i,0),this.styleMap[n]}processContent(e,t,i){}},Qh=["column-count","column-width","column-fill"],wn=class{constructor(e){this.validator=e,c(this,"success",null),c(this,"failure",null),c(this,"code",0)}isSpecial(){return this.code!=0}markAsStartGroup(){this.code=-1}isStartGroup(){return this.code==-1}markAsEndGroup(){this.code=-2}isEndGroup(){return this.code==-2}markAsStartAlternate(e){this.code=2*e+1}isStartAlternate(){return this.code>0&&this.code%2!=0}markAsEndAlternate(e){this.code=2*e+2}isEndAlternate(){return this.code>0&&this.code%2==0}getAlternate(){return Math.floor((this.code-1)/2)}},Ii=class{constructor(e,t){this.where=e,this.success=t,c(this,"what",-1)}},Hn=class Mp{constructor(){c(this,"nodes",[]),c(this,"connections",[]),c(this,"match",[]),c(this,"nomatch",[]),c(this,"error",[]),c(this,"emptyHead",!0)}connect(t,i){for(let n=0;n<t.length;n++)this.connections[t[n]].what=i;t.splice(0,t.length)}clone(){let t=new Mp;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],r=new wn(n.validator);r.code=n.code,t.nodes.push(r)}for(let i=0;i<this.connections.length;i++){let n=this.connections[i],r=new Ii(n.where,n.success);r.what=n.what,t.connections.push(r)}return t.match.push(...this.match),t.nomatch.push(...this.nomatch),t.error.push(...this.error),t}addSpecialToArr(t,i,n){let r=this.nodes.length,o=new wn(eu);n>=0?i?o.markAsStartAlternate(n):o.markAsEndAlternate(n):i?o.markAsStartGroup():o.markAsEndGroup(),this.nodes.push(o),this.connect(t,r);let s=new Ii(r,!0),a=new Ii(r,!1);t.push(this.connections.length),this.connections.push(a),t.push(this.connections.length),this.connections.push(s)}endSpecialGroup(){let t=[this.match,this.nomatch,this.error];for(let i=0;i<t.length;i++)this.addSpecialToArr(t[i],!1,-1)}startSpecialGroup(){if(this.nodes.length)throw new Error("invalid call");this.addSpecialToArr(this.match,!0,-1)}endClause(t){this.addSpecialToArr(this.match,!1,t)}startClause(t){if(this.nodes.length)throw new Error("invalid call");let i=new wn(eu);i.markAsStartAlternate(t),this.nodes.push(i);let n=new Ii(0,!0),r=new Ii(0,!1);this.nomatch.push(this.connections.length),this.connections.push(r),this.match.push(this.connections.length),this.connections.push(n)}addPrimitive(t){let i=this.nodes.length;this.nodes.push(new wn(t));let n=new Ii(i,!0),r=new Ii(i,!1);this.connect(this.match,i),this.emptyHead?(this.nomatch.push(this.connections.length),this.emptyHead=!1):this.error.push(this.connections.length),this.connections.push(r),this.match.push(this.connections.length),this.connections.push(n)}isSimple(){return this.nodes.length==1&&!this.nodes[0].isSpecial()}isPrimitive(){return this.isSimple()&&this.nodes[0].validator instanceof We}addGroup(t,i){if(t.nodes.length==0)return;let n=this.nodes.length;if(i==4&&n==1&&t.isPrimitive()&&this.isPrimitive()){this.nodes[0].validator=this.nodes[0].validator.combine(t.nodes[0].validator);return}for(let o=0;o<t.nodes.length;o++)this.nodes.push(t.nodes[o]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let r=this.connections.length;for(let o=0;o<t.connections.length;o++){let s=t.connections[o];s.where+=n,s.what>=0&&(s.what+=n),this.connections.push(s)}for(let o=0;o<t.match.length;o++)this.match.push(t.match[o]+r);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let o=0;o<t.nomatch.length;o++)this.match.push(t.nomatch[o]+r);else if(this.emptyHead){for(let o=0;o<t.nomatch.length;o++)this.nomatch.push(t.nomatch[o]+r);this.emptyHead=t.emptyHead}else for(let o=0;o<t.nomatch.length;o++)this.error.push(t.nomatch[o]+r);for(let o=0;o<t.error.length;o++)this.error.push(t.error[o]+r);t.nodes=null,t.connections=null}finish(t,i){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(i),this.connect(this.match,n),this.connect(this.nomatch,n+1),this.connect(this.error,n+1);for(let r of this.connections)r.success?this.nodes[r.where].success=this.nodes[r.what]:this.nodes[r.where].failure=this.nodes[r.what];for(let r=0;r<n;r++)if(this.nodes[r].failure==null||this.nodes[r].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},Jb=1,_p=2,Dp=4,Bi=8,yo=16,Oa=32,vo=64,zp=128,Kn=256,Jn=512,Ba=1024,Vp=2048,Up=4096,$p=8192,Hp=class extends ui{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},We=class Wp extends Hp{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&Jb?t:null}visitSlash(t){return this.allowed&Vp?t:null}visitStr(t){return this.allowed&_p?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&Dp||this.allowed&vo&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&Jn)?t.unit=="%"&&this.allowed&Ba?t:null:t.num<0&&!(this.allowed&Kn)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&Jn?t:null:t.num<=0&&!(this.allowed&Kn)?null:this.allowed&yo?t:null}visitInt(t){return t.num==0?this.allowed&Jn?t:null:t.num<=0&&!(this.allowed&Kn)?null:this.allowed&(Oa|yo)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&vo&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&zp?t:null}visitURange(t){return this.allowed&Up?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){if(this.allowed&vo){if(t.name==="device-cmyk"||t.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&dc(t)!==null?t:null;if(CSS.supports("color",t.toString()))return t}if(this.allowed&$p){let i=t.visit(new gc);if(CSS.supports("background-image",i.toString()))return t}return t.name==="calc"&&this.allowed&(Bi|yo|Oa|Kn|Jn|Ba)?t:null}visitExpr(t){return this.allowed&2046?t:null}combine(t){let i={},n={};for(let r in this.idents)i[r]=this.idents[r];for(let r in t.idents)i[r]=t.idents[r];for(let r in this.units)n[r]=this.units[r];for(let r in t.units)n[r]=t.units[r];return new Wp(this.allowed|t.allowed,i,n)}},le=Object.create(null),eu=new We(0,le,le),Cl=class extends Hp{constructor(e){super(),c(this,"successTerminal"),c(this,"failureTerminal"),c(this,"first"),this.successTerminal=new wn(null),this.failureTerminal=new wn(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,r=this.first,o=i,s=null,a=null;for(;r!==this.successTerminal&&r!==this.failureTerminal;){if(o>=e.length){r=r.failure;continue}let h=e[o],l=h;if(r.isSpecial()){let u=!0;r.isStartGroup()?(s?s.push(a):s=[a],a=[]):r.isEndGroup()?s.length>0?a=s.pop():a=null:r.isEndAlternate()?a[r.getAlternate()]="taken":u=a[r.getAlternate()]==null,r=u?r.success:r.failure}else{if(o==0&&!t&&r.validator instanceof lr&&this instanceof lr){if(l=new J(e).visit(r.validator),l){o=e.length,r=r.success;continue}}else if(o==0&&!t&&r.validator instanceof kl&&this instanceof lr){if(l=new it(e).visit(r.validator),l){o=e.length,r=r.success;continue}}else l=h.visit(r.validator);if(!l){r=r.failure;continue}if(l!==h&&e===n){n=[];for(let u=0;u<o;u++)n[u]=e[u]}e!==n&&(n[o-i]=l),o++,r=r.success}}return r===this.successTerminal&&(t?n.length>0:o==e.length)?n:null}validateSingle(e){let t=this.validateList([e],!1,0);return t?t[0]:null}visitEmpty(e){return this.validateSingle(e)}visitSlash(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitURange(e){return this.validateSingle(e)}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return null}},lr=class extends Cl{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new J(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof kl){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new it(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},kl=class extends Cl{constructor(e){super(e)}visitSpaceList(e){return this.validateSingle(e)}visitCommaList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new it(t):null}validateForShorthand(e,t){let i=this.first,n;for(;i!==this.failureTerminal;){if(n=i.validator.validateForShorthand(e,t),n)return n;i=i.failure}return null}},Qb=class extends Cl{constructor(e,t){super(t),this.name=e}validateSingle(e){return null}visitFunc(e){if(e.name.toLowerCase()!=this.name)return null;let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new ci(e.name,t):null}},Gp=class{tryParse(e,t,i){return t}success(e,t){}},jp=class extends Gp{constructor(e,t){super(),this.name=t,c(this,"validator"),this.validator=e.validators[this.name]}tryParse(e,t,i){if(i.values[this.name])return t;let n=this.validator.validateForShorthand(e,t);if(n){let r=n.length,o=r>1?new J(n):n[0];return this.success(o,i),t+r}return t}success(e,t){t.values[this.name]=e}},e0=class extends jp{constructor(e,t){super(e,t[0]),this.names=t}success(e,t){for(let i=0;i<this.names.length;i++)t.values[this.names[i]]=e}},t0=class extends Gp{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==Ln){if(++t==e.length)return n}else return n;let r=this.nodes[0].tryParse(e,t,i);if(r==t)return n;t=r;for(let o=1;o<this.nodes.length&&t<e.length&&(r=this.nodes[o].tryParse(e,t,i),r!=t);o++)t=r;return t}},El=class extends ui{constructor(){super(...arguments),c(this,"syntax",null),c(this,"propList",null),c(this,"error",!1),c(this,"values",{}),c(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new jp(this.validatorSet,e)}clone(){let e=new this.constructor;return e.syntax=this.syntax,e.propList=this.propList,e.validatorSet=this.validatorSet,e}init(e,t){this.syntax=e,this.propList=t}finish(e,t){var i,n;if(!this.error){for(let r of this.propList)t.simpleProperty(r,(n=(i=this.values[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:v.initial,e);return!0}return!1}propagateDefaultingValue(e,t,i){for(let n of this.propList)i.simpleProperty(n,e,t)}validateList(e){return this.error=!0,0}validateSingle(e){return this.validateList([e]),null}visitEmpty(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitSpaceList(e){return this.validateList(e.values),null}visitCommaList(e){return this.error=!0,null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return this.validateSingle(e)}},Mn=class extends El{constructor(){super()}validateList(e){let t=0,i=0;for(;t<e.length;){let n=this.syntax[i].tryParse(e,t,this);if(n>t){t=n,i=0;continue}if(++i==this.syntax.length){this.error=!0;break}}return t}},Xp=class extends El{constructor(){super()}validateList(e){if(e.length>this.syntax.length||e.length==0)return this.error=!0,0;for(let t=0;t<this.syntax.length;t++){let i=t;for(;i>=e.length;)i=i==1?0:i-2;if(this.syntax[t].tryParse(e,i,this)!=i+1)return this.error=!0,0}return e.length}createSyntaxNode(){return new e0(this.validatorSet,this.propList)}},i0=class extends El{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===Ln){t=i;break}if(t>this.syntax.length||e.length==0)return this.error=!0,0;for(let i=0;i<this.syntax.length;i++){let n=i;for(;n>=t;)n=n==1?0:n-2;let r;if(t+1<e.length)for(r=t+i+1;r>=e.length;)r=r-(r==t+2?1:2);else r=n;let o=[e[n],e[r]];if(this.syntax[i].tryParse(o,0,this)!=2)return this.error=!0,0}return e.length}},n0=class extends Mn{constructor(){super()}mergeIn(e,t){var i,n;for(let r of this.propList){let o=(n=(i=t[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:v.initial,s=e[r];s||(s=[],e[r]=s),s.push(o)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof it?this.error=!0:(e.values[i].visit(this),this.mergeIn(t,this.values),this.values["background-color"]&&i!=e.values.length-1&&(this.error=!0)),this.error)return null;this.values={};for(let i in t)i=="background-color"?this.values[i]=t[i].pop():this.values[i]=new it(t[i]);return null}},r0=class extends Mn{constructor(){super()}init(e,t){super.init(e,t),this.propList.push("font-family","line-height","font-size","font-stretch","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian")}validateList(e){let t=super.validateList(e),i=this.values["font-variant_css2"];i&&(delete this.values["font-variant_css2"],this.values["font-variant-caps"]=i);let n=this.values["font-stretch_css3"];if(n&&(delete this.values["font-stretch_css3"],this.values["font-stretch"]=n),t+2>e.length)return this.error=!0,t;this.error=!1;let r=this.validatorSet.validators;if(!e[t].visit(r["font-size"])){let s=this.values["font-weight"],a=s instanceof ci&&s.name==="calc"?e.indexOf(s):-1;if(a>=0&&e[a].visit(r["font-size"]))delete this.values["font-weight"],t=a;else return this.error=!0,t}if(this.values["font-size"]=e[t++],e[t]===Ln){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(r["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let o=t==e.length-1?e[t]:new J(e.slice(t,e.length));return o.visit(r["font-family"])?(this.values["font-family"]=o,e.length):(this.error=!0,t)}visitCommaList(e){if(e.values[0].visit(this),this.error)return null;let t=[this.values["font-family"]];for(let n=1;n<e.values.length;n++)t.push(e.values[n]);let i=new it(t);return i.visit(this.validatorSet.validators["font-family"])?this.values["font-family"]=i:this.error=!0,null}visitIdent(e){let t=this.validatorSet.systemFonts[e.name];if(t)for(let i in t)this.values[i]=t[i];else this.error=!0;return null}},o0=class extends Mn{validateList(e){if(e.length===1&&e[0]instanceof de)switch(e[0].name.toLowerCase()){case"normal":e=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":e=[v.auto,v.auto];break;case"none":e=[M("no-autospace"),M("space-all")];break}return super.validateList(e)}},s0=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","crop-marks-line-color","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","src","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],a0=class extends Mn{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)s0.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},tu={SIMPLE:Mn,INSETS:Xp,INSETS_SLASH:i0,COMMA:n0,FONT:r0,TEXT_SPACING:o0,ALL:a0},l0=["initial-letter"],h0=class{constructor(){c(this,"validators",{}),c(this,"prefixes",{}),c(this,"defaultValues",{}),c(this,"namedValidators",{}),c(this,"systemFonts",{}),c(this,"shorthands",{}),c(this,"layoutProps",{}),c(this,"backgroundProps",{})}addReplacement(e,t){let i;if(t.type==3)i=new R(t.num,t.text);else if(t.type==7)i=new sc(t.text);else if(t.type==1)i=M(t.text);else throw new Error("unexpected replacement");if(e.isPrimitive()){let n=e.nodes[0].validator.idents;for(let r in n)n[r]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new Hn;if(e=="||"){for(let r=0;r<t.length;r++){let o=new Hn;o.startClause(r),o.addGroup(t[r],1),o.endClause(r),i.addGroup(o,r==0?1:4)}let n=new Hn;return n.startSpecialGroup(),n.addGroup(i,3),n.endSpecialGroup(),n}else{let n;switch(e){case" ":n=1;break;case"|":case"||":n=4;break;default:throw new Error("unexpected op")}for(let r=0;r<t.length;r++)i.addGroup(t[r],r==0?1:n);return i}}addCounts(e,t,i){let n=new Hn;for(let r=0;r<t;r++)n.addGroup(e.clone(),1);if(i==Number.POSITIVE_INFINITY)n.addGroup(e,3);else for(let r=t;r<i;r++)n.addGroup(e.clone(),2);return n}primitive(e){let t=new Hn;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new kl(t);break;case"SPACE":i=new lr(t);break;default:i=new Qb(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new We(vo,le,le)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new We($p,le,le)),this.namedValidators.POS_INT=this.primitive(new We(Oa,le,le)),this.namedValidators.POS_NUM=this.primitive(new We(yo,le,le)),this.namedValidators.POS_PERCENTAGE=this.primitive(new We(Bi,le,{"%":Y})),this.namedValidators.NEGATIVE=this.primitive(new We(Kn,le,le)),this.namedValidators.ZERO=this.primitive(new We(Jn,le,le)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new We(Ba,le,le)),this.namedValidators.POS_LENGTH=this.primitive(new We(Bi,le,{em:Y,ex:Y,ch:Y,rem:Y,lh:Y,rlh:Y,vw:Y,vh:Y,vi:Y,vb:Y,vmin:Y,vmax:Y,pvw:Y,pvh:Y,pvi:Y,pvb:Y,pvmin:Y,pvmax:Y,cm:Y,mm:Y,in:Y,px:Y,pt:Y,pc:Y,q:Y})),this.namedValidators.POS_ANGLE=this.primitive(new We(Bi,le,{deg:Y,grad:Y,rad:Y,turn:Y})),this.namedValidators.POS_TIME=this.primitive(new We(Bi,le,{s:Y,ms:Y})),this.namedValidators.FREQUENCY=this.primitive(new We(Bi,le,{Hz:Y,kHz:Y})),this.namedValidators.RESOLUTION=this.primitive(new We(Bi,le,{dpi:Y,dpcm:Y,dppx:Y})),this.namedValidators.URI=this.primitive(new We(zp,le,le)),this.namedValidators.URANGE=this.primitive(new We(Up,le,le)),this.namedValidators.IDENT=this.primitive(new We(Dp,le,le)),this.namedValidators.STRING=this.primitive(new We(_p,le,le)),this.namedValidators.SLASH=this.primitive(new We(Vp,le,le));let e={"font-family":M("sans-serif")};this.systemFonts.caption=e,this.systemFonts.icon=e,this.systemFonts.menu=e,this.systemFonts["message-box"]=e,this.systemFonts["small-caption"]=e,this.systemFonts["status-bar"]=e}isBuiltIn(e){return!!e.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(e,t){let i=e.token();if(i.type==0)return null;let n={"":!0};if(i.type==14){do{if(e.consume(),i=e.token(),i.type!=1)throw new Error("Prefix name expected");n[i.text]=!0,e.consume(),i=e.token()}while(i.type==16);if(i.type!=15)throw new Error("']' expected");e.consume(),i=e.token()}if(i.type!=1)throw new Error("Property name expected");if(t==2?i.text=="SHORTHANDS":i.text=="DEFAULTS")return e.consume(),null;let r=i.text;if(e.consume(),t!=2){if(e.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(r)||(this.prefixes[r]=n)}else if(e.token().type!=18)throw new Error("':' expected");return r}parseValidators(e){for(;;){let t=this.readNameAndPrefixes(e,1);if(!t)return;let i=[],n=[],r="",o,s=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(r,i)},h=u=>{if(s)throw new Error(`'${u}': unexpected`);if(r&&r!=u)throw new Error(`mixed operators: '${u}' and '${r}'`);r=u,s=!0},l=null;for(;!l;){e.consume();let u=e.token();switch(u.type){case 1:if(s||h(" "),this.isBuiltIn(u.text)){let d=this.namedValidators[u.text];if(!d)throw new Error(`'${u.text}' unexpected`);i.push(d.clone())}else{let d={};d[u.text.toLowerCase()]=M(u.text),i.push(this.primitive(new We(0,d,le)))}s=!1;break;case 5:{let d={};d[`${u.num}`]=new Ue(u.num),i.push(this.primitive(new We(0,d,le))),s=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:s||h(" "),n.push({vals:i,op:r,b:"["}),r="",i=[],s=!0;break;case 6:s||h(" "),n.push({vals:i,op:r,b:"(",fn:u.text}),r="",i=[],s=!0;break;case 15:{o=a();let d=n.pop();if(d.b!="[")throw new Error("']' unexpected");i=d.vals,i.push(o),r=d.op,s=!1;break}case 11:{o=a();let d=n.pop();if(d.b!="(")throw new Error("')' unexpected");i=d.vals,i.push(this.newFunc(d.fn,o)),r=d.op,s=!1;break}case 18:if(s)throw new Error("':' unexpected");e.consume(),i.push(this.addReplacement(i.pop(),e.token()));break;case 22:if(s)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(s)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(s)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");let d=u.num,p=d;if(e.consume(),u=e.token(),u.type==16){if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");p=u.num,e.consume(),u=e.token()}if(u.type!=13)throw new Error("'}' expected");i.push(this.addCounts(i.pop(),d,p));break}case 17:if(l=a(),n.length>0)throw new Error(`unclosed '${n.pop().b}'`);break;default:throw new Error("unexpected token")}}e.consume(),this.isBuiltIn(t)?this.namedValidators[t]=l:l.isSimple()?this.validators[t]=l.nodes[0].validator:this.validators[t]=new lr(l)}}parseDefaults(e){for(;;){let t=this.readNameAndPrefixes(e,2);if(!t)return;let i=[];for(;;){e.consume();let n=e.token();if(n.type==17){e.consume();break}switch(n.type){case 1:i.push(M(n.text));break;case 4:i.push(new Ct(n.num));break;case 5:i.push(new Ue(n.num));break;case 3:i.push(new R(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new J(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&tu[i.text]?(n=new tu[i.text],e.consume()):n=new Mn,n.setOwner(this);let r=!1,o=[],s=!1,a=[],h=[];for(;!r;)switch(e.consume(),i=e.token(),i.type){case 1:if(this.validators[i.text])o.push(n.syntaxNodeForProperty(i.text)),i.text.includes("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof Xp){let l=this.shorthands[i.text];o.push(l.createSyntaxNode()),h.push(...l.propList)}else throw new Error(`'${i.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(o.length>0||s)throw new Error("unexpected slash");s=!0;break;case 14:a.push({slash:s,syntax:o}),o=[],s=!1;break;case 15:{let l=new t0(o,s),u=a.pop();o=u.syntax,s=u.slash,o.push(l);break}case 17:r=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(o,h),this.shorthands[t]=n}}parse(e){let t=new Vt(e,null);this.parseValidators(t),this.parseDefaults(t),this.parseShorthands(t),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(e){var t;let i={};for(let n of e){let r=this.shorthands[n],o=r?r.propList:[n];for(let s of o)i[s]=(t=this.defaultValues[s])!=null?t:v.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){let r=n.ruleType;if(Qt(e)||r==="font-face"||c0(t)){n.simpleProperty(e,t,i);return}if(r==="counter-style"){Db(e,t)?n.simpleProperty(e,t,i):n.invalidPropertyValue(e,t);return}let o="",s=e;e=e.toLowerCase();let a=e.match(/^-([a-z]+)-([-a-z0-9]+)$/);a&&(o=a[1],e=a[2]);let h=this.prefixes[e];if(!h||!h[o]){CSS.supports(s,t.toString())?n.simpleProperty(s,t,i):o&&!Mu.includes(`-${o}-`)||n.unknownProperty(s,t);return}else if(l0.includes(e)&&!Object.keys(h).some(u=>eo(u?`-${u}-`:"",e))){n.unknownProperty(s,t);return}let l=this.validators[e];if(l){let u=Z(t)||t.isExpr()?t:t.visit(l);u?n.simpleProperty(e,u,i):!o&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(s,t)}else{let u=this.shorthands[e].clone();Z(t)?u.propagateDefaultingValue(t,i,n):(t.visit(u),u.finish(i,n)||n.invalidPropertyValue(s,t))}}};function qp(){let e=new h0;return e.initBuiltInValidators(),e.parse(Dc),e}var u0=class extends ui{constructor(){super(...arguments),c(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function c0(e){let t=new u0;return e.visit(t),t.varFound}var Qx=`OTTO${new Date().valueOf()}`;function Pl(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function d0(e){let t=new si;for(let i of Pl(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function p0(e,t){let i={};for(let n in e)i[n]=me(e,n).evaluate(t,n);return i}var Yp=class{constructor(e){this.properties=e,c(this,"fontTraitKey"),c(this,"src"),c(this,"blobURLs",[]),c(this,"blobs",[]),c(this,"family"),this.fontTraitKey=d0(this.properties),this.src=this.properties.src?this.properties.src.toString():null;let t=this.properties["font-family"];this.family=t?t.stringValue():null}traitsEqual(e){return this.fontTraitKey==e.fontTraitKey}makeAtRule(e,t){let i=new si;i.append(`@font-face {
1848
1869
  font-family: `),i.append(this.family),i.append(`;
1849
- `);for(let n of ol(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
1850
- `);if(t){i.append('src: url("');let n=$g(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
1870
+ `);for(let n of Pl(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
1871
+ `);if(t){i.append('src: url("');let n=ew(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
1851
1872
  }
1852
- `),i.toString()}},Yb=class{constructor(e){this.deobfuscator=e,c(this,"familyMap",{})}registerFamily(e,t){let i=e.family,n=this.familyMap[i],r=t.family;if(n){if(n!=r)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${e.family}`)}else this.familyMap[i]=r}filterFontFamily(e){if(e instanceof tt){let t=e.values,i=[];for(let n of t){let r=this.familyMap[n.stringValue()];r&&i.push(B(r)),i.push(n)}return new tt(i)}else{let t=this.familyMap[e.stringValue()];return t?new tt([B(t),e]):e}}},Zb=class{constructor(e,t,i){this.head=e,this.body=t,c(this,"srcURLMap",{}),c(this,"familyPrefix"),c(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=M("initFont"),r=e.src,s={};for(let l of ol(e.properties))s[l]=e.properties[l];let o=this.getViewFontFamily(e,i);s["font-family"]=B(o);let a=new op(s),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(r,t),this.head.appendChild(h),W.debug("Load font:",r),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i+";"+e.fontTraitKey,r=this.srcURLMap[n];return r?r.piggyback(s=>{t.registerFamily(e,s),W.debug("Found already-loaded font:",i)}):(r=new yr(()=>{let s=M("loadFont"),o=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(o):null;return a?zs(o,"blob").then(h=>{if(!h.responseBlob){s.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(e,l,t).thenFinish(s)})}):this.initFont(e,null,t).thenFinish(s),s.result()},`loadFont ${i}`),this.srcURLMap[n]=r,r.start()),r}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){W.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return vn(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(r=>{}))}),t===0)return N(!0);let i=M("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?N(!0):N(!1))).thenFinish(i),i.result()}},Kb=1,Xs=class{constructor(e,t,i,n,r){this.name=t,this.pseudoName=i,this.classes=n,this.parent=r,c(this,"specified",{}),c(this,"children",[]),c(this,"pageMaster",null),c(this,"index",0),c(this,"key"),c(this,"_scope"),this._scope=e,this.key=`p${Kb++}`,r&&(this.index=r.children.length,r.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})}},Jb=class extends Xs{constructor(e){super(e,null,null,[],null),this.specified.width=new D(mr,0),this.specified.height=new D(wr,0)}},Ah=class extends Co{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(r,s){let o=r.match(/^([^.]+)\.([^.]+)$/);if(o){let a=i.pageMaster.keyMap[o[1]];if(a){let h=this.lookupInstance(a);if(h)return s?h.resolveFunc(o[2]):h.resolveName(o[2])}}return null}}},ap=class lp extends Xs{constructor(t,i,n,r,s,o,a){super(t,i,n,r,s),this.condition=o,this.specificity=a,c(this,"keyMap",{}),t instanceof Ah||(this._scope=new Ah(t,this)),this.pageMaster=this,this.specified.width=new D(mr,0),this.specified.height=new D(wr,0),this.specified["wrap-flow"]=new D(v.auto,0),this.specified.position=new D(v.relative,0),this.specified.overflow=new D(v.visible,0)}createInstance(t){return new ll(t,this)}clone(t){let i=new lp(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}},hp=class up extends Xs{constructor(t,i,n,r,s){super(t,i,n,r,s),this.pageMaster=s.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new D(v.auto,0)}createInstance(t){return new iv(t,this)}clone(t){let i=new up(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},Cr=class cp extends Xs{constructor(t,i,n,r,s){super(t,i,n,r,s),this.pageMaster=s.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new Pn(t,this)}clone(t){let i=new cp(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function Qb(e,t,i){return!t||J(t)?new Ye(e,i):t.toExpr(e,e.zero)}function be(e,t,i){return!t||t===v.auto||J(t)?null:t.toExpr(e,i)}function ev(e,t,i){return!t||t===v.normal||J(t)?null:t.toExpr(e,i)}function yt(e,t,i){return!t||t===v.auto||J(t)?e.zero:t.toExpr(e,i)}function Rh(e,t,i){return!t||J(t)?e.zero:t===v.auto?null:t.toExpr(e,i)}function Gt(e,t,i,n){return!t||i===v.none||J(t)?e.zero:t.toExpr(e,n)}function dp(e,t,i){return!t||J(t)?i:t===v._true?e._true:t===v._false?e._false:t.toExpr(e,e.zero)}var qs=class{constructor(e,t){this.parentInstance=e,this.pageBox=t,c(this,"cascaded",{}),c(this,"style",{}),c(this,"autoWidth",null),c(this,"autoHeight",null),c(this,"children",[]),c(this,"isAutoWidth",!1),c(this,"isAutoHeight",!1),c(this,"isTopDependentOnAutoHeight",!1),c(this,"isRightDependentOnAutoWidth",!1),c(this,"calculatedWidth",0),c(this,"calculatedHeight",0),c(this,"pageMasterInstance",null),c(this,"namedValues",{}),c(this,"namedFuncs",{}),c(this,"vertical",!1),c(this,"rtl",!1),c(this,"suppressEmptyBoxGeneration",!1),c(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 ie(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 r=this.vertical?jc:Xc;n=e;for(let s in r)n=n.replace(s,r[s])}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 Tu(i,0),r=this.resolveName("column-count"),s=this.resolveName("column-width"),o=this.resolveName("column-gap");t=ye(i,Hr(i,new Yn(i,"min",[n,r]),ie(i,s,o)),o);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=dp(e,t.enabled,e._true),n=be(e,t.page,e.zero);if(n){let o=new je(e,"page-number");i=At(e,i,new La(e,n,o))}let r=be(e,t["min-page-width"],e.zero);r&&(i=At(e,i,new Eo(e,new je(e,"page-width"),r)));let s=be(e,t["min-page-height"],e.zero);s&&(i=At(e,i,new Eo(e,new je(e,"page-height"),s))),i=this.boxSpecificEnabled(i),t.enabled=new $(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=be(e,t.left,i),r=be(e,t["margin-left"],i),s=Gt(e,t["border-left-width"],t["border-left-style"],i),o=yt(e,t["padding-left"],i),a=be(e,t.width,i),h=be(e,t["max-width"],i),l=yt(e,t["padding-right"],i),u=Gt(e,t["border-right-width"],t["border-right-style"],i),d=be(e,t["margin-right"],i),p=be(e,t.right,i),f=ie(e,s,o),g=ie(e,s,l);if(n&&p&&a){let b=ye(e,i,ie(e,a,ie(e,ie(e,n,f),g)));r?d?p=ye(e,b,d):d=ye(e,b,ie(e,p,r)):(b=ye(e,b,p),d?r=ye(e,b,d):(r=Hr(e,b,new Ye(e,.5)),d=r))}else{r||(r=e.zero),d||(d=e.zero),!n&&!p&&!a&&(n=e.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!p?n=e.zero:!a&&!p&&(a=this.autoWidth,this.isAutoWidth=!0);let b=ye(e,i,ie(e,ie(e,r,f),ie(e,d,g)));this.isAutoWidth&&(h||(h=ye(e,b,n||p)),!this.vertical&&(be(e,t["column-width"],null)||be(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?p||(p=ye(e,b,ie(e,n,a))):a=ye(e,b,ie(e,n,p)):n=ye(e,b,ie(e,p,a))}let m=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=yt(e,m,i);t.left=new $(n),t["margin-left"]=new $(r),t["border-left-width"]=new $(s),t["padding-left"]=new $(o),t.width=new $(a),t["max-width"]=new $(h||a),t["padding-right"]=new $(l),t["border-right-width"]=new $(u),t["margin-right"]=new $(d),t.right=new $(p),t["snap-width"]=new $(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,r=be(e,t.top,n),s=be(e,t["margin-top"],i),o=Gt(e,t["border-top-width"],t["border-top-style"],i),a=yt(e,t["padding-top"],i),h=be(e,t.height,n),l=be(e,t["max-height"],n),u=yt(e,t["padding-bottom"],i),d=Gt(e,t["border-bottom-width"],t["border-bottom-style"],i),p=be(e,t["margin-bottom"],i),f=be(e,t.bottom,n),g=ie(e,o,a),m=ie(e,d,u);if(r&&f&&h){let x=ye(e,n,ie(e,h,ie(e,ie(e,r,g),m)));s?p?f=ye(e,x,s):p=ye(e,x,ie(e,f,s)):(x=ye(e,x,f),p?s=ye(e,x,p):(s=Hr(e,x,new Ye(e,.5)),p=s))}else{s||(s=e.zero),p||(p=e.zero),!r&&!f&&!h&&(r=e.zero),!r&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!r&&!f?r=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let x=ye(e,n,ie(e,ie(e,s,g),ie(e,p,m)));this.isAutoHeight&&(l||(l=ye(e,x,r||f)),this.vertical&&(be(e,t["column-width"],null)||be(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),r?h?f||(f=ye(e,x,ie(e,r,h))):h=ye(e,x,ie(e,f,r)):r=ye(e,x,ie(e,f,h))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),b=yt(e,w,i);t.top=new $(r),t["margin-top"]=new $(s),t["border-top-width"]=new $(o),t["padding-top"]=new $(a),t.height=new $(h),t["max-height"]=new $(l||h),t["padding-bottom"]=new $(u),t["border-bottom-width"]=new $(d),t["margin-bottom"]=new $(p),t.bottom=new $(f),t["snap-height"]=new $(b)}initColumns(){let e=this.pageBox.scope,t=this.style,i=be(e,t[this.vertical?"height":"width"],null),n=be(e,t["column-width"],i),r=be(e,t["column-count"],null),s=ev(e,t["column-gap"],null);s||(s=new gr(e,1,"em")),n&&!r&&(r=new Yn(e,"floor",[Po(e,ie(e,i,s),ie(e,n,s))]),r=new Yn(e,"max",[e.one,r])),r||(r=e.one),n=ye(e,Po(e,ie(e,i,s),r),s),t["column-width"]=new $(n),t["column-count"]=new $(r),t["column-gap"]=new $(s)}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,r=this.parentInstance?this.parentInstance.getActiveRegions(e):null,s=ea(this.cascaded,e,r,!1,null);this.vertical=fd(s,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=gd(s,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=s["box-sizing"])==null?void 0:t.value)===v.border_box;let o=!!(e instanceof pl&&e.currentLayoutPosition&&new je(i,"left-page").evaluate(e));wd(s,n,this.vertical,this.rtl,o,(a,h)=>h.value),this.autoWidth=new Ie(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new Ie(i,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(e,t){var i,n;let r=this.style[t];return!r&&un(t)&&this.pageMasterInstance instanceof yn&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?r=new F(e.rootFontSize,"px"):r=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),r&&(r=ks(e,r,t)),r}getPropAsNumber(e,t){var i,n;let r=this.style[t];if(r){let s=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();r=ks(e,r,t,s)}return nt(r,e)}getSpecial(e,t){let i=Jc(this.cascaded,t);if(i){let n=[];for(let r=0;r<i.length;r++){let s=i[r].evaluate(e,"");s&&s!==Y&&n.push(s)}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 r=this.getProp(e,i);r&&(r.isNumeric()&&wu(r.unit)&&(r=Bu(r,e)),i==="font-family"&&(r=n.filterFontFamily(r)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),I(t,i,r.toString()))}propagateDelayedProperty(e,t,i,n){let r=this.getProp(e,i);r&&n.push(new Ua(t.element,i,r))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),r=this.getPropAsNumber(e,"padding-left"),s=this.getPropAsNumber(e,"border-left-width"),o=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,o),I(t.element,"margin-left",`${n}px`),I(t.element,"padding-left",`${r}px`),I(t.element,"border-left-width",`${s}px`),t.marginLeft=n,t.borderLeft=s,t.paddingLeft=r}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),r=this.getPropAsNumber(e,"margin-right"),s=this.getPropAsNumber(e,"padding-right"),o=this.getPropAsNumber(e,"border-right-width");if(I(t.element,"margin-right",`${r}px`),I(t.element,"padding-right",`${s}px`),I(t.element,"border-right-width",`${o}px`),t.marginRight=r,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,s+=t.snapOffsetX)}t.paddingRight=s,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),r=this.getPropAsNumber(e,"margin-top"),s=this.getPropAsNumber(e,"padding-top"),o=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=r,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,s+=t.snapOffsetY)}t.paddingTop=s,I(t.element,"top",`${n}px`),I(t.element,"margin-top",`${r}px`),I(t.element,"padding-top",`${s}px`),I(t.element,"border-top-width",`${o}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),r=this.getPropAsNumber(e,"border-bottom-width"),s=this.getPropAsNumber(e,"height")-t.snapOffsetY;I(t.element,"height",`${s}px`),I(t.element,"margin-bottom",`${i}px`),I(t.element,"padding-bottom",`${n}px`),I(t.element,"border-bottom-width",`${r}px`),t.height=s-t.snapOffsetY,t.marginBottom=i,t.borderBottom=r,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){I(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,I(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){I(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");I(t.element,"right",`${n}px`),I(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,r){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&I(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&I(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 s=0;s<Fh.length;s++)this.propagateProperty(e,t,Fh[s],n)}transferContentProps(e,t,i,n){for(let r=0;r<Oh.length;r++)this.propagateProperty(e,t,Oh[r],n);if(this.style["text-overflow"]){let r=t.element.firstElementChild;I(r,"text-overflow","inherit"),I(r,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var s,o;let a=(o=(s=this.cascaded.width)!=null?s:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:o.value;return!!a&&a!==v.auto&&!J(a)},r=()=>{var s,o;let a=(o=(s=this.cascaded.height)!=null?s:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:o.value;return!!a&&a!==v.auto&&!J(a)};for(let s=0;s<Bh.length;s++){let o=Bh[s];if(o==="width"||o==="height"){if(o==="width"&&!n()||o==="height"&&!r())continue;I(t,o,"100%");continue}this.propagatePropertyToElement(e,t,o,i)}}finishContainer(e,t,i,n,r,s,o){var a,h,l,u,d,p,f,g,m,w;this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let b=(this.vertical||!n)&&this.isAutoHeight,x=(!this.vertical||!n)&&this.isAutoWidth,y=null;if(x||b){x&&I(t.element,"width","auto"),b&&I(t.element,"height","auto");let P=n&&vs(n);P&&Hs(n),y=s.getElementClientRect(n?n.element:t.element),P&&Ha(n),x&&(this.calculatedWidth=Math.ceil(y.right-y.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),b&&(this.calculatedHeight=y.bottom-y.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)),r>1){let P=this.getPropAsNumber(e,"column-rule-width"),S=this.getProp(e,"column-rule-style"),R=this.getProp(e,"column-rule-color");if(P>0&&S&&S!=v.none&&R!=v.transparent){let A=this.getPropAsNumber(e,"column-gap"),U=this.vertical?t.height:t.width,G=parseFloat(this.vertical?(a=n?.element.style.left)!=null?a:"":(h=n?.element.style.top)!=null?h:""),Z=t.getPaddingRect(),fe=n,ue=this.vertical?"border-top":"border-left";for(let C=1;C<r;C++){let _=this.vertical?(U+A)*C/r-A/2+t.paddingTop-P/2:(U+A)*C/r-A/2+t.paddingLeft-P/2,k=this.vertical?Z.y1+_+P/2:Z.x1+_+P/2,O=(d=(u=(l=fe.pageFloatLayoutContext)==null?void 0:l.parent)==null?void 0:u.getBlockEndEdgeOfBlockStartFloats)==null?void 0:d.call(u,k),E=(g=(f=(p=fe.pageFloatLayoutContext)==null?void 0:p.parent)==null?void 0:f.getBlockStartEdgeOfBlockEndFloats)==null?void 0:g.call(f,k),T=isFinite(O)?this.vertical?O-Z.x1:O-Z.y1:NaN,L=isFinite(E)?this.vertical?E-Z.x1:E-Z.y1:NaN,z=parseFloat(this.vertical?(m=n?.element.style.width)!=null?m:"":(w=n?.element.style.height)!=null?w:""),H=z>0?z:this.vertical?n.width:n.height,K=Math.max(G>0?G:0,0),ee=K+H,Q=Math.max(K,isFinite(this.vertical?L:T)?Math.max(0,this.vertical?L:T):0),ge=Math.min(ee,isFinite(this.vertical?T:L)?Math.max(0,this.vertical?T:L):ee),re=Math.max(0,ge-Q),se=t.element.ownerDocument.createElement("div");I(se,"position","absolute"),I(se,this.vertical?"left":"top",`${Q}px`),I(se,this.vertical?"top":"left",`${_}px`),I(se,this.vertical?"height":"width","0px"),I(se,this.vertical?"width":"height",`${re}px`),I(se,ue,`${P}px ${S.toString()}${R?` ${R.toString()}`:""}`),t.element.insertBefore(se,t.element.firstChild)}}}for(let P=0;P<Lh.length;P++)this.propagateProperty(e,t,Lh[P],o);for(let P=0;P<Mh.length;P++)this.propagateDelayedProperty(e,t,Mh[P],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let s in n)this instanceof yn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(s==="writing-mode"||s==="direction")||Bi(s)&&yi(i,s,ke(n,s));if(this.pageBox.pseudoName==al)for(let s in t)(s.match(/^background-/)||s=="writing-mode")&&(i[s]=t[s]);if(this.pageBox.pseudoName=="layout-host")for(let s in t)!s.match(/^background-/)&&s!="writing-mode"&&(i[s]=t[s]);e.pushRule(this.pageBox.classes,null,i);let r=i.content;r&&(i.content=r.filterValue(new Cs(e,null,e.counterResolver))),this.init(e.context);for(let s of this.pageBox.children)s.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)}},Fh=["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"],Lh=["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"],Oh=["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"],Bh=["width","height","image-resolution","object-fit","object-position"],Mh=["transform","transform-origin"],al="background-host",tv=class extends qs{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)}},ll=class extends qs{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=At(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},iv=class extends qs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},Pn=class extends qs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof de&&(n=[t]),t instanceof tt&&(n=t.values),n){let r=this.pageBox.scope;for(let s=0;s<n.length;s++)if(n[s]instanceof de){let o=So(n[s].name,"enabled"),a=new je(r,o);i&&(a=new mi(r,a)),e=At(r,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=dp(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let r=Qb(t,i["flow-from"],"body"),s=new Yn(t,"has-content",[r]);e=At(t,e,s)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let r=this.pageMasterInstance.style.enabled,s=r?r.toExpr(t,null):t._true;s=At(t,s,e),this.pageMasterInstance.style.enabled=new $(s)}return e}prepareContainer(e,t,i,n,r){var s;this.pageBox.pageMaster instanceof wp||(I(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(s=this.pageBox.name)!=null?s:"")),super.prepareContainer(e,t,i,n,r)}},hl=class extends In{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 D(t,i?cc:dc)}},pp=class extends hl{constructor(e,t,i,n){super(e,t,i,n)}},nv=class fp extends hl{constructor(t,i,n,r){super(t,i,n,r),n.specified.width=new D(Tl,0),n.specified.height=new D(Tl,0)}startPartitionRule(t,i,n){let r=new Cr(this.scope,t,i,n,this.target),s=new pp(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(t,i,n){let r=new hp(this.scope,t,i,n,this.target),s=new fp(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(s)}},rv=class extends hl{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new Cr(this.scope,e,t,i,this.target),r=new pp(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(e,t,i){let n=new hp(this.scope,e,t,i,this.target),r=new nv(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}};function gp(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,r=(i=e.direction)==null?void 0:i.value;return n===v.vertical_lr||n!==v.vertical_rl&&r!==v.rtl?"ltr":"rtl"}var sv={a10:{width:new F(26,"mm"),height:new F(37,"mm")},a9:{width:new F(37,"mm"),height:new F(52,"mm")},a8:{width:new F(52,"mm"),height:new F(74,"mm")},a7:{width:new F(74,"mm"),height:new F(105,"mm")},a6:{width:new F(105,"mm"),height:new F(148,"mm")},a5:{width:new F(148,"mm"),height:new F(210,"mm")},a4:{width:new F(210,"mm"),height:new F(297,"mm")},a3:{width:new F(297,"mm"),height:new F(420,"mm")},a2:{width:new F(420,"mm"),height:new F(594,"mm")},a1:{width:new F(594,"mm"),height:new F(841,"mm")},a0:{width:new F(841,"mm"),height:new F(1189,"mm")},b10:{width:new F(31,"mm"),height:new F(44,"mm")},b9:{width:new F(44,"mm"),height:new F(62,"mm")},b8:{width:new F(62,"mm"),height:new F(88,"mm")},b7:{width:new F(88,"mm"),height:new F(125,"mm")},b6:{width:new F(125,"mm"),height:new F(176,"mm")},b5:{width:new F(176,"mm"),height:new F(250,"mm")},b4:{width:new F(250,"mm"),height:new F(353,"mm")},b3:{width:new F(353,"mm"),height:new F(500,"mm")},b2:{width:new F(500,"mm"),height:new F(707,"mm")},b1:{width:new F(707,"mm"),height:new F(1e3,"mm")},b0:{width:new F(1e3,"mm"),height:new F(1414,"mm")},c10:{width:new F(28,"mm"),height:new F(40,"mm")},c9:{width:new F(40,"mm"),height:new F(57,"mm")},c8:{width:new F(57,"mm"),height:new F(81,"mm")},c7:{width:new F(81,"mm"),height:new F(114,"mm")},c6:{width:new F(114,"mm"),height:new F(162,"mm")},c5:{width:new F(162,"mm"),height:new F(229,"mm")},c4:{width:new F(229,"mm"),height:new F(324,"mm")},c3:{width:new F(324,"mm"),height:new F(458,"mm")},c2:{width:new F(458,"mm"),height:new F(648,"mm")},c1:{width:new F(648,"mm"),height:new F(917,"mm")},c0:{width:new F(917,"mm"),height:new F(1297,"mm")},"jis-b10":{width:new F(32,"mm"),height:new F(45,"mm")},"jis-b9":{width:new F(45,"mm"),height:new F(64,"mm")},"jis-b8":{width:new F(64,"mm"),height:new F(91,"mm")},"jis-b7":{width:new F(91,"mm"),height:new F(128,"mm")},"jis-b6":{width:new F(128,"mm"),height:new F(182,"mm")},"jis-b5":{width:new F(182,"mm"),height:new F(257,"mm")},"jis-b4":{width:new F(257,"mm"),height:new F(364,"mm")},"jis-b3":{width:new F(364,"mm"),height:new F(515,"mm")},"jis-b2":{width:new F(515,"mm"),height:new F(728,"mm")},"jis-b1":{width:new F(728,"mm"),height:new F(1030,"mm")},"jis-b0":{width:new F(1030,"mm"),height:new F(1456,"mm")},letter:{width:new F(8.5,"in"),height:new F(11,"in")},legal:{width:new F(8.5,"in"),height:new F(14,"in")},ledger:{width:new F(11,"in"),height:new F(17,"in")}},ov=new F(.24,"pt"),R0=new F(3,"mm"),av=new F(10,"mm"),lv=new F(13,"mm");function Rs(e){let t={width:mr,height:wr,bleed:Ne,bleedOffset:Ne,cropOffset:Ne},i=e.size;if(!(!i||i.value===v.auto)){let l=i.value,u,d;if(l.isSpaceList()?(u=l.values[0],d=l.values[1]):(u=l,d=null),u.isNumeric())t.width=u,t.height=d||u;else{let p=u.name&&sv[u.name.toLowerCase()];p&&(d&&d===v.landscape?(t.width=p.height,t.height=p.width):(t.width=p.width,t.height=p.height))}}let n=e.marks,r=e.bleed,s=n&&!J(n.value)?n.value:v.none,o=r&&!J(r.value)?r.value:v.auto;if(o===v.auto){if(s!==v.none){let l=!1;s.isSpaceList()?l=s.values.some(u=>u===v.crop):l=s===v.crop,l&&(t.bleed=new F(6,"pt"))}}else o.isNumeric()&&(t.bleed=o);let a=e["crop-offset"],h=a&&!J(a.value)?a.value:v.auto;return h===v.auto?s!==v.none&&(t.bleedOffset=lv):h.isNumeric()&&(t.cropOffset=h),t}function _h(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),r=!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),s=n+r,o=e.width;o===mr?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)-s*2:i.pageWidth=o.num*t.queryUnitSize(o.unit,!1);let a=e.height;return a===wr?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-s*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=r,i.cropOffset=s,i}function mp(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 tr(e,t,i,n){n=n||"polyline";let r=e.createElementNS("http://www.w3.org/2000/svg",n);return r.setAttribute("stroke",i===v.auto?"#010101":i.toString()),r.setAttribute("stroke-width",t),r.setAttribute("fill","none"),r}var ya=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(ya||{});function hv(e,t,i,n,r,s,o){let a=r;a<=s+2*_t.mm&&(a=s+r/2);let h=Math.max(r,a),l=s+h+i/2,u=mp(e,l,l),d=[[0,s+r],[r,s+r],[r,s+r-a]],p=d.map(m=>[m[1],m[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(m=>[s+h-m[0],m[1]]),p=p.map(m=>[s+h-m[0],m[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(m=>[m[0],s+h-m[1]]),p=p.map(m=>[m[0],s+h-m[1]]));let f=tr(e,i,n);f.setAttribute("points",d.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=tr(e,i,n);return g.setAttribute("points",p.map(m=>m.join(",")).join(" ")),u.appendChild(g),t.split(" ").forEach(m=>{u.style[m]=`${o}px`}),u}var cr=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(cr||{});function uv(e,t,i,n,r,s){let o=r*2,a,h;t==="top"||t==="bottom"?(a=o,h=r):(a=r,h=o);let l=mp(e,a,h),u=tr(e,i,n);u.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(u);let d=tr(e,i,n);d.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(d);let p=tr(e,i,n,"circle");p.setAttribute("cx",a/2),p.setAttribute("cy",h/2),p.setAttribute("r",r/4),l.appendChild(p);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(cr).forEach(g=>{let m=cr[g];m===t?l.style[m]=`${s}px`:m!==f&&(l.style[m]="0",l.style[`margin-${m}`]="auto")}),l}function cv(e,t,i,n){let r=!1,s=!1,o=e.marks;if(o){let m=o.value;m instanceof te?m.values.forEach(w=>{w===v.crop?r=!0:w===v.cross&&(s=!0)}):m===v.crop?r=!0:m===v.cross&&(s=!0)}let a=t.bleed;if(!r&&!s)return;let h=i.container,l=h.ownerDocument,u=nt(ov,n),d=Math.max(0,t.bleedOffset-nt(av,n)),p=t.bleedOffset-d,f=e["crop-marks-line-color"],g=f&&!J(f.value)?f.value:v.auto;r&&Object.keys(ya).forEach(m=>{let w=ya[m],b=hv(l,w,u,g,p,a,d);h.appendChild(b)}),s&&Object.keys(cr).forEach(m=>{let w=cr[m],b=uv(l,w,u,g,p,d);h.appendChild(b)})}var ba=(()=>{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})(),ul={"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"}},dv=(()=>{let e=ul;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),cl="vivliostyle-page-rule-master",dr="_marginBoxes",Fs="_footnoteArea",wp=class extends ap{constructor(e,t,i){super(e,null,cl,[],t,null,0),c(this,"pageMarginBoxes",{});let n=Rs(i),r=new pv(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[dr];t&&dv.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new gv(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new D(v.relative,0),this.specified.width=new D(t.width,0),this.specified.height=new D(t.height,0);for(let i in e)!ba[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new yn(e,this)}},pv=class extends Cr{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let r=new fv(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new D(v.auto,0),this.specified["z-index"]=new D(new Be(0),0),this.specified.position=new D(v.absolute,0),this.specified.overflow=new D(v.visible,0);for(let t in ba)ba.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new wv(e,this)}},fv=class extends Cr{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new D(B("body"),0)}createInstance(e){return new yp(e,this)}},gv=class extends Cr{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[dr][this.marginBoxName];for(let i in e){let n=e[i],r=t[i];(Gc[i]||r&&r.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!==Y&&n.value!==v.inherit&&n.value!==v.unset&&n.value!==v.revert&&(this.specified[i]=n)}}createInstance(e){return new bp(e,this)}},yn=class extends ll{constructor(e,t){super(e,t),c(this,"pageAreaDimension",null),c(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=Ne,e["margin-left"]=Ne,e["border-left-width"]=Ne,e["padding-left"]=Ne,e["padding-right"]=Ne,e["border-right-width"]=Ne,e["margin-right"]=Ne,e.right=Ne}initVertical(){let e=this.style;e.top=Ne,e["margin-top"]=Ne,e["border-top-width"]=Ne,e["padding-top"]=Ne,e["padding-bottom"]=Ne,e["border-bottom-width"]=Ne,e["margin-bottom"]=Ne,e.bottom=Ne}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new $(e.borderBoxWidth),t.height=new $(e.borderBoxHeight),t["padding-left"]=new $(e.marginLeft),t["padding-right"]=new $(e.marginRight),t["padding-top"]=new $(e.marginTop),t["padding-bottom"]=new $(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,r={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},s={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,s,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,r){let s="start",o="center",a="end",h=this.pageBox.scope,l={},u={},d={};for(let y in e){let P=ul[y];if(P){let S=e[y],R=this.pageMarginBoxInstances[y],A=new ls(S,R.style,t,h,r);l[P.positionAlongVariableDimension]=S,u[P.positionAlongVariableDimension]=R,d[P.positionAlongVariableDimension]=A}}let p={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),g=!1,m={};Object.keys(l).forEach(y=>{let P=y,S=be(h,u[P].style[t?"max-width":"max-height"],i.extent);if(S){let R=S.evaluate(n);if(f[P]>R){let A=d[P]=new Dh(l[P],u[P].style,t,h,r,R);m[P]=A.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),g=!1,[s,o,a].forEach(y=>{var P;f[y]=(P=m[y])!=null?P:f[y]}));let w={};Object.keys(l).forEach(y=>{let P=y,S=be(h,u[P].style[t?"min-width":"min-height"],i.extent);if(S){let R=S.evaluate(n);if(f[P]<R){let A=d[P]=new Dh(l[P],u[P].style,t,h,r,R);w[P]=A.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),[s,o,a].forEach(y=>{f[y]=w[y]||f[y]}));let b=p.start+p.extent,x=p.start+(p.start+p.extent);[s,o,a].forEach(y=>{let P=f[y];if(P!=null){let S=l[y],R=0;switch(y){case s:R=t?S.left:S.top;break;case o:R=(x-P)/2;break;case a:R=b-P;break}t?S.setHorizontalPosition(R,P-S.getInsetLeft()-S.getInsetRight()):S.setVerticalPosition(R,P-S.getInsetTop()-S.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,r=e.center,s=e.end,o={};if(r){let a=[n,s],h=new mv(a),l=this.distributeAutoMarginBoxSizes(r,h,t);l.xSize!=null&&(o.center=l.xSize);let u=(i=l.xSize)!=null?i:r.getOuterSize(),d=Math.max((t-u)/2,0);n&&(o.start=n.hasAutoSize()?d:n.getOuterSize()),s&&(o.end=s.hasAutoSize()?d:s.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,s,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 ls&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof ls&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let r=e.getOuterMaxContentSize(),s=t.getOuterMaxContentSize();if(r>0&&s>0){let o=r+s;if(o<i)n.xSize=i*r/o;else{let a=e.getOuterMinContentSize(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(r-a)/(o-l):l>0&&(n.xSize=i*a/l)}n.xSize>0&&(n.ySize=i-n.xSize)}else r>0?n.xSize=i:s>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,r){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,r)}},ls=class{constructor(e,t,i,n,r){this.container=e,this.isHorizontal=i,this.clientLayout=r,c(this,"hasAutoSize_"),c(this,"size",null),c(this,"minMaxFitContent",null);let s=t[i?"width":"height"];if(this.hasAutoSize_=!s||s===v.auto||J(s),this.minMaxFitContent=s instanceof de&&(s.name==="min-content"||s.name==="max-content"||s.name==="fit-content")?s.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=Va(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()}},mv=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}},Dh=class extends ls{constructor(e,t,i,n,r,s){super(e,t,i,n,r),c(this,"fixedSize"),this.fixedSize=s}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()}},wv=class extends Pn{constructor(e,t){super(e,t),c(this,"borderBoxWidth",null),c(this,"borderBoxHeight",null),c(this,"contentBoxWidth",null),c(this,"contentBoxHeight",null),c(this,"marginTop",null),c(this,"marginRight",null),c(this,"marginBottom",null),c(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,r=e.start,s=e.end,o=e.extent,a=i[o].toExpr(n,null),h=be(n,t[o],a),l=be(n,t[`margin-${r}`],a),u=be(n,t[`margin-${s}`],a),d=yt(n,t[`padding-${r}`],a),p=yt(n,t[`padding-${s}`],a),f=Gt(n,t[`border-${r}-width`],t[`border-${r}-style`],a),g=Gt(n,t[`border-${s}-width`],t[`border-${s}-style`],a),m=ie(n,ie(n,f,d),ie(n,g,p)),w,b,x;return h?(this.borderBoxSizing?(b=h,x=ye(n,b,m)):(x=h,b=ie(n,x,m)),w=ye(n,a,b),!l&&!u?(l=Hr(n,w,new Ye(n,.5)),u=l):l?u=ye(n,w,l):l=ye(n,w,u)):(l||(l=n.zero),u||(u=n.zero),w=ie(n,l,u),b=ye(n,a,w),x=ye(n,b,m),h=this.borderBoxSizing?b:x),t[r]=new $(l),t[s]=new $(u),t[`margin-${r}`]=Ne,t[`margin-${s}`]=Ne,t[`border-${r}-width`]=new $(f),t[`border-${s}-width`]=new $(g),t[`padding-${r}`]=new $(d),t[`padding-${s}`]=new $(p),t[o]=new $(h),t[`max-${o}`]=new $(h),{borderBoxExtent:b,contentBoxExtent:x,marginStart:l,marginEnd:u}}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,r)}},yp=class extends Pn{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 $(this.parentInstance.contentBoxWidth),e["margin-left"]=new $(new rn(i,t.left.toExpr(i,null))),e["margin-right"]=new $(new rn(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 $(this.parentInstance.contentBoxHeight),e["margin-top"]=new $(new rn(i,t.top.toExpr(i,null))),e["margin-bottom"]=new $(new rn(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,r){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,r),e.pageAreaWidth=t.width,e.pageAreaHeight=t.height}},bp=class extends Pn{constructor(e,t){super(e,t),c(this,"boxInfo"),c(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=ul[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,r)}applyVerticalAlign(e,t){I(t,"display","flex"),I(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&&I(t,"justify-content",n);let r=this.getProp(e,"content");if(this.vertical||r instanceof ot||r instanceof $&&r.expr instanceof Ie&&r.expr.str.startsWith("running-element-")){let s="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?s=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(s=this.vertical||this.rtl?"end":"start")),I(t,"align-items",s)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,r=e.start,s=e.end,o=e.extent,a=r==="left",h=a?t.borderBoxWidth:t.borderBoxHeight,l=be(n,i[o],h),u=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[r]=new $(u);else if(l){let d=yt(n,i[`margin-${r}`],h),p=yt(n,i[`margin-${s}`],h),f=yt(n,i[`padding-${r}`],h),g=yt(n,i[`padding-${s}`],h),m=Gt(n,i[`border-${r}-width`],i[`border-${r}-style`],h),w=Gt(n,i[`border-${s}-width`],i[`border-${s}-style`],h),b=ie(n,l,ie(n,this.borderBoxSizing?n.zero:ie(n,ie(n,f,g),ie(n,m,w)),ie(n,d,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[r]=new $(ie(n,u,Po(n,ye(n,h,b),new Ye(n,2))));break;case"end":i[r]=new $(ye(n,ie(n,u,h),b));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,r=this.borderBoxSizing,s=e.inside,o=e.outside,a=e.extent,h=t[`margin${o.charAt(0).toUpperCase()}${o.substring(1)}`],l=Rh(n,i[`margin-${s}`],h),u=Rh(n,i[`margin-${o}`],h),d=yt(n,i[`padding-${s}`],h),p=yt(n,i[`padding-${o}`],h),f=Gt(n,i[`border-${s}-width`],i[`border-${s}-style`],h),g=Gt(n,i[`border-${o}-width`],i[`border-${o}-style`],h),m=be(n,i[a],h),w=null;function b(x){if(w)return w;w={extent:m?m.evaluate(x):null,marginInside:l?l.evaluate(x):null,marginOutside:u?u.evaluate(x):null};let y=h.evaluate(x),P=0;return r||[f,d,p,g].forEach(S=>{S&&(P+=S.evaluate(x))}),(w.marginInside===null||w.marginOutside===null)&&P+w.extent+w.marginInside+w.marginOutside>y&&(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=y-P-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=y-P-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=y-P-w.extent-w.marginInside:w.marginInside=w.marginOutside=(y-P-w.extent)/2),w}i[a]=new $(new Ie(n,function(){let x=b(this).extent;return x===null?"auto":x},a)),i[`margin-${s}`]=new $(new Ie(n,function(){let x=b(this).marginInside;return x===null?"auto":x},`margin-${s}`)),i[`margin-${o}`]=new $(new Ie(n,function(){let x=b(this).marginOutside;return x===null?"auto":x},`margin-${o}`)),s==="left"?i.left=new $(ie(n,t.marginLeft,t.borderBoxWidth)):s==="top"&&(i.top=new $(ie(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,r,s,o){super.finishContainer(e,t,i,n,r,s,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 u=this.parentInstance.pageAreaDimension,d=this.getProp(e,"width"),p=d instanceof de&&(d.name==="min-content"||d.name==="max-content"||d.name==="fit-content")?d.name:null,f=this.getPropAsNumber(e,"min-width"),g=this.getPropAsNumber(e,"max-width");if(p||f||g){p&&I(t.element,"width",p),f&&I(t.element,"min-width",`${f}px`),g&&I(t.element,"max-width",`${g}px`);let y=this.getProp(e,"margin-left"),P=this.getProp(e,"margin-right");if(l.isInLeftColumn){let S=u.borderBoxWidth.evaluate(e)+u.marginRight.evaluate(e);I(t.element,"right",`${S}px`),(y===v.auto||P!==v.auto)&&I(t.element,"margin-left","auto"),P===v.auto&&I(t.element,"margin-right","auto")}else l.isInRightColumn&&(I(t.element,"right","0"),(P===v.auto||y!==v.auto)&&I(t.element,"margin-right","auto"),y===v.auto&&I(t.element,"margin-left","auto"))}let m=this.getProp(e,"height"),w=m instanceof de&&(m.name==="min-content"||m.name==="max-content"||m.name==="fit-content")?m.name:null,b=this.getPropAsNumber(e,"min-height"),x=this.getPropAsNumber(e,"max-height");if(w||b||x){w&&I(t.element,"height",w),b&&I(t.element,"min-height",`${b}px`),x&&I(t.element,"max-height",`${x}px`);let y=this.getProp(e,"margin-top"),P=this.getProp(e,"margin-bottom");if(l.isInTopRow){let S=u.borderBoxHeight.evaluate(e)+u.marginBottom.evaluate(e);I(t.element,"bottom",`${S}px`),(y===v.auto||P!==v.auto)&&I(t.element,"margin-top","auto"),P===v.auto&&I(t.element,"margin-bottom","auto")}else l.isInBottomRow&&(I(t.element,"bottom","0"),(P===v.auto||y!==v.auto)&&I(t.element,"margin-bottom","auto"),y===v.auto&&I(t.element,"margin-top","auto"))}}},yv=class{constructor(e,t,i,n,r){this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=r,c(this,"pageMasterCache",{}),c(this,"pageCascadeInstance"),this.pageCascadeInstance=e,this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new je(e,"page-number"),r=new La(e,new ku(e,n,new Ye(e,2)),i?e.one:e.zero);e.defineName("recto-page",new mi(e,r)),e.defineName("verso-page",r),(t.pageProgression||gp(this.docElementStyle))==="ltr"?(e.defineName("left-page",r),e.defineName("right-page",new mi(e,r))):(e.defineName("left-page",new mi(e,r)),e.defineName("right-page",r))}getCascadedPageStyle(e){let t={};return this.pageCascadeInstance.pushRule([],e,t),this.pageCascadeInstance.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),r=this.pageMasterCache[n];return r||(i.pseudoName===al?r=this.generatePageRuleMaster(t):r=this.generateCascadedPageMaster(t,i),this.pageMasterCache[n]=r),r.pageBox.resetScope(),r}makeCacheKey(e,t){var i;let n=this.makeCascadeValueObjectKey(e),r=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${t.key}^${n}^${r}`}makeCascadeValueObjectKey(e){let t=[];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],r;n instanceof D?r=`${n.value}`:r=this.makeCascadeValueObjectKey(n),t.push(i+r+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new wp(this.pageScope,this.rootPageBoxInstance.pageBox,e).createInstance(this.rootPageBoxInstance);return t.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),t.resolveAutoSizing(this.context),t}generateCascadedPageMaster(e,t){let i=t.clone({pseudoName:cl}),n=i.specified,r=e.size;if(r&&!J(r.value)){let o=Rs(e),a=r.priority;Dt(n,"width",new D(o.width,a),this.context),Dt(n,"height",new D(o.height,a),this.context)}["counter-reset","counter-increment"].forEach(o=>{n[o]&&(e[o]=n[o])});let s=i.createInstance(this.rootPageBoxInstance);return s.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),s.resolveAutoSizing(this.context),s}},bv=class extends Se{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}},vv=class extends Se{constructor(e){super(),this.scope=e}apply(e){new je(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},xv=class extends Se{constructor(e){super(),this.scope=e}apply(e){new je(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},Sv=class extends Se{constructor(e){super(),this.scope=e}apply(e){new je(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Cv=class extends Se{constructor(e){super(),this.scope=e}apply(e){new je(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},kv=class extends Se{constructor(e){super(),this.scope=e}apply(e){new je(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Ev=class extends Se{constructor(e){super(),this.scope=e}apply(e){new je(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Pv=class extends Hi{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}},Nv=class extends Hi{constructor(e,t,i,n){super(t,i),this.scope=e,this.a=t,this.b=i,this.pageType=n}apply(e){let t=e.pageTypePageIndices[this.pageType];if(t){for(let i of t)if(this.matchANPlusB(i)){this.chained.apply(e);return}}}getPriority(){return 3}},Tv=class extends Za{constructor(e,t){super(e,t,null,null,null)}apply(e){Iv(e.context,e.currentStyle,this.style,this.specificity,e)}};function Iv(e,t,i,n,r){xs(e,t,i,n,null,null,null);let s=i[dr];if(s){let a=ei(t,dr);for(let h in s)if(s.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l),xs(e,l,s[h],n,null,null,null)}}let o=i[Fs];if(o){let a=ei(t,Fs);for(let h in o)if(o.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l);let u=o[h];for(let p in u)if(u.hasOwnProperty(p)&&p!=="_pseudos"){let f=u[p];f instanceof D&&Dt(l,p,f)}let d=bt(u,"_pseudos");if(d){let p=ei(l,"_pseudos");for(let f in d)if(d.hasOwnProperty(f)){let g=p[f];g||(g={},p[f]=g);let m=d[f];for(let w in m)if(m.hasOwnProperty(w)){let b=m[w];b instanceof D&&Dt(g,w,b)}}}}}}var Av=class extends ar{constructor(e,t,i,n,r){super(e,t,i?.condition,i,null,n,!1),this.pageProps=r,c(this,"currentPageSelectors",[]),c(this,"currentNamedPageSelector",""),c(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new bv(t)),this.specificity+=65536)}pseudoclassSelector(e,t){if(e=e.toLowerCase(),t)switch(e){case"nth":{let i=t[0],n=t[1];if(t.length===3&&typeof t[2]=="string"){let r=t[2];this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n} of ${r})`),this.chain.push(new Nv(this.scope,i,n,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new Pv(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 vv(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new xv(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new Sv(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new Cv(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new kv(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Ev(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(s=>s.selectors===null))return;super.simpleProperty(e,t,i);let n=ke(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(s=>{yi(r[s],e,n)});else if(e==="size"){let s=r[""];this.currentPageSelectors.forEach(o=>{let a=new D(n.value,n.priority+o.specificity),h=o.selectors?o.selectors.join(""):"",l=r[h];l?Dt(l,e,a):(l=r[h]={},yi(l,e,a),s&&["bleed","marks"].forEach(u=>{s[u]&&yi(l,u,s[u])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new Tv(this.elementStyle,e)}startFootnoteRule(e){let t=ei(this.elementStyle,Fs),i=t.area;if(i||(i={},t.area=i),e){let r=ei(i,"_pseudos"),s=r[e];s||(s={},r[e]=s),i=s}let n=new vp(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}startPageMarginBoxRule(e){let t=ei(this.elementStyle,dr),i=t[e];i||(i={},t[e]=i);let n=new Rv(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},Rv=class extends In{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(),r=new D(t,n);yi(this.boxStyle,e,r)}},vp=class extends In{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.areaStyle=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(),r=new D(t,n);yi(this.areaStyle,e,r)}},si=!0;function Fv(e){si=e}var _i=[];function zh(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function xp(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 dl(e,t,i){if(!si||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&xp(e.ownerDocument).includes(e))return N(!1);let n=e.textContent,r=e.src,s=e.type==="module",o=r&&r.includes("/MathJax.js");if(o){if(t.document.head.querySelector("script[src*='/MathJax.js']"))return N(!0);t.MathJax||(t.MathJax={MathML:{extensions:["content-mathml.js"]},showProcessingMessages:!1,messageStyle:"none",skipStartupTypeset:!0,CommonHTML:{linebreaks:{automatic:!0}},"fast-preview":{disabled:!0},AuthorInit:function(){t.MathJax.Hub.processSectionDelay=0}})}let a=(s||r)&&e.async&&!o,h=(s&&!a||r&&e.defer)&&!o,l=!(i!=null&&i.atEnd)&&(i?.forceDefer||h||a);if(Sp(t)||(t.onload=null),l)return _i.some(d=>zh(d,e))||_i.push(e),N(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&zh(d,e)&&t.document.head.removeChild(d);let u=t.document.createElement("script");u.textContent=n,r&&(u.src=r),u.async=a,u.defer=h,u.setAttribute("data-vivliostyle-scripting","true");for(let d of e.attributes)["src","async","defer"].includes(d.name)||u.setAttribute(d.name,d.value);if(W.debug("script:",r),r){let d=Ut(u);return t.document.head.appendChild(u),vn([d])}else return t.document.head.appendChild(u),N(!0)}function Lv(e,t){var i;let n={},r=o=>{var a;let h=(a=o["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let u of h.values)n[u.stringValue()]=!0;else n[h.stringValue()]=!0;let l=o._marginBoxes;if(l)for(let u of Object.values(l))r(u)},s=o=>{if(o instanceof Za)r(o.style);else if(o instanceof Rn||Array.isArray(o))for(let a of Object.values(o))s(a)};for(let o of Object.values(t.cascade.code))for(let a of Object.values(o??{}))s(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 Ov(e,t,i){var n;let r=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return r.style.position="fixed",r.style.fontSize="0",r.setAttribute("data-vivliostyle-textcontent","true"),r.setAttribute("aria-hidden","true"),r.style.fontFamily=Lv(e,i),r.textContent=e.documentElement.textContent,t.document.body.appendChild(r),r}function Bv(e,t,i){if(!si)return N(!1);let n=xp(e);if(n.length===0)return N(!1);let r=n.some(u=>!(u.async||u.defer||u.type==="module")),s=r?Ov(e,t,i):null,o=t.document.fonts,a=t.$,h=!1,l=M("loadScripts");return l.loop(()=>{if(n.length===0)return r?l.sleep(20).thenAsync(()=>{var d,p;return o.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(d=t.FontJSON)!=null&&d.Font&&(p=t.ret)!=null&&p.readyState&&t.ret.readyState<4?N(!0):N(!1)}):N(!1);let u=n.shift();return dl(u,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(_i.push(u),h=!0),n.length===0&&r&&(W.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),N(!0)))}).then(()=>{s&&s.remove(),l.finish(!0)}),l.result()}function Mv(e){if(!si)return N(!1);let t=M("loadScripts");return t.loop(()=>_i.length===0?N(!1):dl(_i.shift(),e,{atEnd:!0}).thenReturn(_i.length>0)).then(()=>{W.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),W.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Sp(e){return si?_i.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}function Ls(e,t){return!!(e&&e.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function dn(e){if(e.localName!=="aside")return!1;if(Ls(e.getAttribute("role"),"doc-footnote"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return Ls(t,"footnote")}function ir(e){if(e.localName!=="a")return!1;if(Ls(e.getAttribute("role"),"doc-noteref"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return Ls(t,"noteref")}function _v(e){let t=e.getElementsByTagName("a");for(let i=0;i<t.length;i++){let n=t.item(i);if(!ir(n)||!(n instanceof HTMLAnchorElement)||!n.hash||n.href!==n.baseURI.replace(/#.*$/,"")+n.hash)continue;let r=n.hash.substring(1),s=e.getElementById(r);s&&dn(s)&&s.setAttribute("data-vivliostyle-footnote-referenced","true")}}kt("PREPROCESS_SINGLE_DOCUMENT",_v);var Dv=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,r)=>`url("${i.transformURL(r,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,r)=>`url('${i.transformURL(r,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,r)=>`url(${i.transformURL(r,t)}`),zv={};function Vv(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 va=class Xn extends Ia{constructor(t,i,n,r,s,o,a,h,l,u,d,p,f,g,m,w=new Map,b={value:!1}){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=r,this.regionIds=s,this.xmldoc=o,this.docFaces=a,this.footnoteStyle=h,this.stylerProducer=l,this.page=u,this.customRenderer=d,this.fallbackMap=p,this.documentURLTransformer=f,this.pageProps=g,this.cascadedPageStyle=m,this.semanticFootnoteFirstRefOffsets=w,this.semanticFootnoteFirstRefOffsetsInitialized=b,c(this,"document"),c(this,"exprContentListener"),c(this,"nodeContext",null),c(this,"viewRoot",null),c(this,"isFootnote",!1),c(this,"sourceNode",null),c(this,"offsetInNode",0),c(this,"viewNode",null),this.document=n.document,this.exprContentListener=r.counterListener.getExprContentListener()}clone(){return new Xn(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,this.pageProps,this.cascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)}initializeSemanticFootnoteFirstRefOffsets(t){if(this.semanticFootnoteFirstRefOffsetsInitialized.value)return;let i=t.getElementsByTagName("a");for(let n=0;n<i.length;n++){let r=i.item(n);if(!ir(r))continue;let s=r.getAttribute("href")||r.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!s)continue;let o=Ar(s,this.xmldoc.url);o!=="#"&&(this.semanticFootnoteFirstRefOffsets.has(o)||this.semanticFootnoteFirstRefOffsets.set(o,this.xmldoc.getElementOffset(r)))}this.semanticFootnoteFirstRefOffsetsInitialized.value=!0}shouldGenerateSemanticFootnote(t){if(t.localName!=="a"||!ir(t))return!0;let i=t.getAttribute("href")||t.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!i)return!0;let n=Ar(i,this.xmldoc.url);if(n==="#")return!0;this.initializeSemanticFootnoteFirstRefOffsets(t.ownerDocument);let r=this.semanticFootnoteFirstRefOffsets.get(n);return r==null?!0:this.xmldoc.getElementOffset(t)===r}createPseudoelementShadow(t,i,n,r,s,o,a,h){var l;let u=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(!u)return h;let d=[],p=$n.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=p;for(let w of Jw){let b;if(w){if(!u[w]||w=="footnote-marker"&&!(i&&this.isFootnote)&&!((l=this.nodeContext)!=null&&l.pluginProps.nestedFootnoteDetached))continue;if(w.match(/^first-/)){let x=r.display;if(!x||x===v.inline)continue;let y=t.firstElementChild;if(y&&Me(y.previousSibling)){let P=s.getStyle(y,!1);if(P){let S=ke(P,"display");if(S!=null&&S.value&&S.value!==v.inline)continue}}}if(w==="before"||w==="after"||w==="footnote-marker"){let x=u[w].content;if(!x||!Rt(x.value))continue}d.push(w),b=$n.createElementNS("http://www.w3.org/1999/xhtml","span"),qr(b,w)}else b=$n.createElementNS("http://www.pyroxy.com/ns/shadow","content");f.appendChild(b),w.match(/^first-/)&&(f=b)}if(!d.length)return h;let g=new co(t,n,s,o,this.exprContentListener),m=new Wr(t,p,null,a,h,ht.ROOTLESS,g);return h||m}getPseudoMap(t,i,n,r,s){let o=bt(t,"_pseudos");if(!o)return null;let a={};for(let h in o){let l=a[h]={};Jn(l,o[h],s),Qo(l,s,o[h]),md(o[h],i,n,(u,d)=>{Jn(l,d,s),pd(d,p=>{Jn(l,p,s)})})}return a}createRefShadow(t,i,n,r,s){let o=M("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let h=a;if(h){let l=h.getElement(t);if(l){let u=this.stylerProducer.getStylerForDoc(h);s=new Wr(n,l,h,r,s,i,u)}}o.finish(s)}),o.result()}createShadows(t,i,n,r,s,o,a){let h=M("createShadows"),l=null,u=r.template,d;if(u instanceof ot||u===v.footnote)if(u!==v.footnote||this.shouldGenerateSemanticFootnote(t)){let p=u instanceof ot?u.url:Ee("user-agent.xml#footnote",fi);d=this.createRefShadow(p,ht.ROOTLESS,t,a,l)}else d=N(l);else d=N(l);return d.then(p=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let m=t.getAttribute("href"),w=null;m?w=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?m=a.owner.getAttribute("href"):m=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),w=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),m&&(m=Ar(m,w.url),f=this.createRefShadow(m,ht.ROOTED,t,a,p))}f==null&&(f=N(p));let g=null;f.then(m=>{if(r.display===v.table_cell){let w=Ee("user-agent.xml#table-cell",fi);g=this.createRefShadow(w,ht.ROOTLESS,t,a,m)}else g=N(m);g.then(w=>{w=this.createPseudoelementShadow(t,i,n,r,s,o,a,w),h.finish(w)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,r){var s;let o=this.context,a=ea(n,o,this.regionIds,this.isFootnote,this.nodeContext),h=!((s=this.nodeContext)!=null&&s.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=fd(a,o,t);let u=!h&&t!==l;i=gd(a,o,i);let d=(b,x)=>{let y;u&&(t?/^(min-|max-)?(height|inline-size)$/.test(b)&&(y=o.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(b)&&(y=o.pageAreaWidth));let P=x.evaluate(o,b,y,t);return b=="font-family"&&(P=this.docFaces.filterFontFamily(P)),P},p=!!new je(o.style.pageScope,"left-page").evaluate(o);if(wd(a,r,t,i,p,d),u){let b=r[t?"height":"width"];(!b||b===v.auto)&&(r[t?"height":"width"]=v.max_content)}if(bs(r.position))return r.position=v.fixed,r.visibility=v.hidden,t;let f=r.position,g=r.float,m=r.display||(this.sourceNode&&this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?v.inline:void 0),w=Mc(m,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(b=>{w[b]&&(r[b]=w[b])}),t}inheritFromSourceParent(t){var i,n;let r=this.nodeContext.sourceNode,s=[],o=null,a=r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content"),h=this.isFootnote&&(!((i=this.nodeContext)!=null&&i.parent)||a),l=this.nodeContext.shadowContext;if(r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content")){let w=l?.owner;if(w instanceof Element&&ir(w)){let b=w.getAttribute("href")||w.getAttributeNS("http://www.w3.org/1999/xlink","href");if(b){let x=Ar(b,this.xmldoc.url),y=this.xmldoc.getElement(x);y&&dn(y)&&((n=y.parentNode)==null?void 0:n.nodeType)===1&&(r=y.parentNode,l=null)}}}let u=-1;for(;r&&r.nodeType==1;){let w=l&&l.root==r,b=!!w&&l.type==ht.ROOTED&&dn(r);if(!w||l.type==ht.ROOTLESS||b){let x=(l?l.styler:this.styler).getStyle(r,!1);s.push(x),o=o||xo(r)}w&&!b?(r=l.owner,l=l.parentShadow):(r=r.parentNode,u++)}let d=new Set;if(s.length>0){let w=s[0],b=ea(w,this.context,this.regionIds,this.isFootnote,this.nodeContext);for(let x in b){if(!un(x))continue;let y=b[x].evaluate(this.context,x);y&&y!==v.inherit&&y!==v.unset&&y!==v.revert&&y!==Y&&d.add(x)}}let p=u===0,f=this.context.queryUnitSize("em",p),g={"font-size":new D(new F(f,"px"),0)};p&&(g["line-height"]=new D(new vt(this.context.pref.lineHeight),0));let m=new ow(g,this.context);for(let w=s.length-1;w>=0;--w){let b=s[w],x=[];for(let S in b)un(S)&&x.push(S);x.sort(Al);let y,P;for(let S of x){if(w>0&&h&&S.startsWith("--viv-marker-")||w>0&&d.has(S))continue;m.setPropName(S);let R=ke(b,S),A=R;if(R.value===v.initial)delete g[S];else if(!J(R.value)){if(S==="font-size"&&w===s.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)A=new D(new F(this.context.rootFontSize,"px"),R.priority);else if(S==="line-height"&&w===s.length-1&&this.context.rootLineHeight&&R.value instanceof F&&(R.value.unit==="lh"||R.value.unit==="rlh"))A=new D(new F(this.context.rootLineHeight,"px"),R.priority);else if(w===0&&R.value instanceof F&&R.value.unit==="lh"){let U=this.getLineHeightUnitSize(S,y,P);U!=null&&(A=new D(new F(R.value.num*U,"px"),R.priority))}else jt(S)||(A=R.filterValue(m));S==="font-size"?y=A.value:S==="line-height"&&(P=A.value),g[S]=A}}}for(let w in t)un(w)||(g[w]=t[w]);return{lang:o,elementStyle:g}}resolveURL(t){return t=Ee(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=xo(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=Zm().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let r in this.nodeContext.parent.inheritedProps)n[r]=this.nodeContext.parent.inheritedProps[r]}i.forEach(r=>{let s=t[r];if(s){if(J(s))s===v.initial&&(n[r]=void 0);else if(s instanceof Be)n[r]=s.num;else if(s instanceof de)n[r]=s.name;else if(s instanceof F){let o=s;switch(o.unit){case"dpi":case"dpcm":case"dppx":n[r]=o.num*_t[o.unit];break;default:n[r]=s}}else n[r]=s;["widows","orphans"].includes(r)||delete t[r]}})}}resolveFormattingContext(t,i,n,r,s,o){let a=Ft("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,r,s,o);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,r;let s=!0,o=M("createElementView"),a=this.sourceNode,h=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,l=h.getStyle(a,!1);if(!this.nodeContext.shadowContext){let y=this.xmldoc.getElementOffset(a);Ws.registerFragmentIndex(y,this.nodeContext.fragmentIndex,0)}let u={};if(!this.nodeContext.parent){let y=this.inheritFromSourceParent(l);l=y.elementStyle,this.nodeContext.lang=y.lang}let d=l.position,p=l.float,f=l["float-reference"],g=p&&!J(p.value)&&p.value!==v.none&&f&&!J(f.value)?Nm(f.value.toString()):null,m=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===ht.ROOTED&&dn(a);if(this.nodeContext.parent&&(bs(d?.value)||g&&wi(g)||m)){let y=this.inheritFromSourceParent(l);l=y.elementStyle,this.nodeContext.lang=y.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,u),g&&wi(g)&&u.display===v.block&&(u.display=v.flow_root),h.processContent(a,u,this.nodeContext),this.transferPolyfilledInheritedProps(u),this.inheritLangAttribute(),u.direction&&(this.nodeContext.direction=u.direction.toString());let w=u["flow-into"];if(w&&w.toString()!=this.flowName)return o.finish(!1),o.result();if(si&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return dl(a,this.viewport.window).thenFinish(o),o.result();let b=u.display;if(J(b)&&(b===v.initial||b===v.unset?b=v.inline:b===v.inherit?b=((n=this.nodeContext.parent)==null?void 0:n.display)&&B((r=this.nodeContext.parent)==null?void 0:r.display):b=null),b===v.none)return o.finish(!1),o.result();let x=this.nodeContext.parent==null;return this.nodeContext.flexContainer=b===v.flex,this.createShadows(a,x,l,u,h,this.context,this.nodeContext.shadowContext).then(y=>{var P;this.nodeContext.nodeShadow=y;let S=u.position,R=u.float,A=u.clear,U=this.nodeContext.vertical?v.vertical_rl:v.horizontal_tb,G=this.nodeContext.parent?this.nodeContext.parent.vertical?v.vertical_rl:v.horizontal_tb:U,Z=Om(a),fe=u["column-count"],ue=u["column-width"],C=fe&&fe!==v.auto&&!J(fe)||ue&&ue!==v.auto&&!J(ue);this.nodeContext.establishesBFC=Mm(b,S,R,u.overflow,U,G,C||Z),this.nodeContext.containingBlockForAbsolute=_m(S),this.nodeContext.isInsideBFC()&&R!==v.footnote&&!(g&&wi(g))&&(R=null,A=null);let _=null,k=!1,O=this.isFootnote&&(!((P=this.nodeContext)!=null&&P.parent)||this.nodeContext.pluginProps.nestedFootnoteDetached),E=R instanceof te||R===v.left||R===v.right||R===v.top||R===v.bottom||R===v.inline_start||R===v.inline_end||R===v.block_start||R===v.block_end||R===v.snap_block||R===v.snap_inline||R===v.inside||R===v.outside||R===v.footnote;if(R&&(delete u.float,R===v.footnote))if(_=u["footnote-display"],k=!!u["--viv-marker-content"],O){E=!1;let X=_?.toString();b=k?B("list-item"):X==="inline"?v.inline:v.block,u.display=b}else u.display=v.inline;A&&(A===v.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(A=B(this.nodeContext.parent.clearSide)),(A===v.left||A===v.right||A===v.top||A===v.bottom||A===v.inline_start||A===v.inline_end||A===v.block_start||A===v.block_end||A===v.inside||A===v.outside||A===v.both||A===v.all||A===v.same||A===v.column||A===v.region||A===v.page)&&(delete u.clear,(E||u.display&&u.display!=v.inline)&&(this.nodeContext.clearSide=A.toString())));let T=Hn(b)&&!!(u["ua-list-item-count"]||u["--viv-marker-content"]),L=u["break-inside"];(E||L&&!J(L)&&L!==v.auto)&&this.nodeContext.breakPenalty++,b&&b!==v.inline&&Mt(b)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!E&&!b||Mt(b)||Dc(b),this.nodeContext.display=b?b.toString():"inline",this.nodeContext.floatSide=E?R.toString():null,this.nodeContext.floatReference=g||Te.INLINE;let z=u["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=z&&!J(z)?z:null;let H=this.isInsideNonRootMultiColumn(),K=u["column-span"];if(this.nodeContext.columnSpan=!H&&K&&!J(K)?K:null,!this.nodeContext.inline){let X=u["break-after"];X&&!J(X)&&!(H&&X===v.column)&&(this.nodeContext.breakAfter=X.toString(),Oo[this.nodeContext.breakAfter]&&(u["break-after"]=v.column));let Et=u["break-before"];Et&&!J(Et)&&!(H&&Et===v.column)&&(this.nodeContext.breakBefore=Et.toString(),Oo[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete u["break-before"]:u["break-before"]=v.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let Bt=u.page,xt=Bt&&!J(Bt)&&Bt.toString();!xt&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||b===v.table_header_group||b===v.table_footer_group)&&(xt=this.styler.cascade.currentPageType),!xt||xt.toLowerCase()==="auto"?xt=this.nodeContext.pageType:this.nodeContext.pageType=xt,this.styler.cascade.currentPageType!==xt&&!(!xt&&u.position===v.fixed)&&(this.nodeContext.fragmentIndex===1&&!xn(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),xt!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=xt)}this.nodeContext.captionSide=u["caption-side"]&&u["caption-side"].toString()||"top";let ee=u["border-collapse"];if(!ee||ee===B("separate")){let X=u["border-spacing"],Et,Bt;X&&(X instanceof te?(Et=X.values[0],Bt=X.values[1]):Et=Bt=X,Et.isNumeric()&&(this.nodeContext.inlineBorderSpacing=nt(Et,this.context)),Bt.isNumeric()&&(this.nodeContext.blockBorderSpacing=nt(Bt,this.context)))}let Q=u["footnote-policy"];this.nodeContext.footnotePolicy=Q&&!J(Q)?Q:null;let ge=u["x-first-pseudo"];if(ge){let X=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Cm(X,ge.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,l,h,this.context);let re=u["white-space"];if(re){let X=kc(re.toString());X!==null&&(this.nodeContext.whitespace=X)}let se=u["hyphenate-character"];se&&se instanceof j&&(this.nodeContext.hyphenateCharacter=se.str);let _e=u["word-break"],De=u["line-break"],pe=u["overflow-wrap"];(_e===v.break_all||De===v.anywhere||pe===v.break_word||pe===v.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,b,S,R,x),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(t=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,t)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(u),this.findAndProcessRepeatingElements(a,h));let le=!1,me=null,we=[],oe=a.namespaceURI,q=a.localName,Ze=q;oe=="http://www.w3.org/1999/xhtml"?(q=="html"||q=="body"||q=="script"||q=="link"||q=="meta"?q="div":q=="vide_"?q="video":q=="audi_"?q="audio":q=="object"&&(le=!!this.customRenderer),a.hasAttribute(el)&&a.hasAttribute("src")&&u.content instanceof ot&&(q="img")):oe=="http://www.idpf.org/2007/ops"?(q="span",oe="http://www.w3.org/1999/xhtml"):oe=="http://www.pyroxy.com/ns/shadow"?(oe="http://www.w3.org/1999/xhtml",q=this.nodeContext.inline?"span":"div"):le=!!this.customRenderer,T?t?(q="li",u["--viv-marker-content"]&&(u["list-style-type"]=v.none,u["list-style-image"]=v.none)):(b=Mt(b)?v.inline:v.block,u.display=b,q="div"):q=="body"||q=="li"?q="div":q=="q"&&(q="span"),u.behavior&&u.behavior.toString()!="none"&&this.customRenderer&&(le=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(le=!0);let at;if(le){let X=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;at=this.customRenderer(a,X,u)}else at=N(null);at.then(X=>{var Et,Bt,xt;if(X)le&&(s=X.getAttribute("data-adapt-process-children")=="true");else if(u.display===v.none){o.finish(!1);return}else X=this.createElement(oe,q);if(!x&&C&&u["column-fill"]===v.auto){let Ke=this.nodeContext.vertical?u.width:u.height;(!Ke||Ke===v.auto||J(Ke))&&(X.setAttribute("data-viv-saved-column-fill","auto"),u["column-fill"]=v.balance)}q!=Ze&&(X.setAttribute("data-vivliostyle-original-tag",Ze),(Ze==="html"||Ze==="body")&&(X.role="presentation")),q=="a"&&X.addEventListener("click",this.page.hrefHandler,!1),me&&(this.applyPseudoelementStyle(this.nodeContext,"inner",me),X.appendChild(me)),X.localName=="iframe"&&X.namespaceURI=="http://www.w3.org/1999/xhtml"&&Vv(X);let kr=this.nodeContext.inheritedProps["image-resolution"],Ys=[],Zs=u.width,Ks=u.height,Bp=a.getAttribute("width"),Mp=a.getAttribute("height"),Js=Zs===v.auto||!Zs&&!Bp,Qs=Ks===v.auto||!Ks&&!Mp,gl=a.attributes,_p=gl.length,Er=null,ml=null;b===v.table_cell&&((xt=(Bt=(Et=this.nodeContext.parent)==null?void 0:Et.viewNode)==null?void 0:Bt.lastElementChild)==null?void 0:xt.localName)==="a"&&X.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let Ke=0;Ke<_p;Ke++){let pt=gl[Ke],ft=pt.namespaceURI,he=pt.localName,He=pt.nodeValue;if(ft){if(ft=="http://www.w3.org/2000/xmlns/")continue;ft=="http://www.w3.org/1999/xlink"&&he=="href"&&(He=this.documentURLTransformer.transformURL(this.resolveURL(He),this.xmldoc.url))}else{if(!si&&he.match(/^on/)||he=="style")continue;if((he=="id"||he=="name")&&t){let Je=this.documentURLTransformer.transformFragment(He,this.xmldoc.url);X.setAttribute(he,He),X.setAttribute("data-vivliostyle-id",Je);let Si=X.ownerDocument.createElement("a");Si.setAttribute(he,Je),Si.setAttribute(Cn,"1"),Si.style.position="absolute",X.appendChild(Si),this.page.registerElementWithId(X,Je);continue}if(he=="src"||he=="href"||he=="poster")He=this.resolveURL(He),he==="href"&&(He=this.documentURLTransformer.transformURL(He,this.xmldoc.url));else if(he=="srcset")He=He.split(",").map(Je=>this.resolveURL(Je.trim())).join(",");else if(he==="data"&&le&&q==="object"&&X.hasAttribute("data"))continue;if(he==="poster"&&q==="video"&&oe==="http://www.w3.org/1999/xhtml"&&Js&&Qs){let Je=new Image,Si=Ut(Je,He);we.push(Si),Ys.push({image:Je,element:X,fetcher:Si})}}if(oe=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(he)&&(he=he.toLowerCase()),this.isSVGUrlAttribute(he)&&(He=Dv(He,this.xmldoc.url,this.documentURLTransformer)),ft){let Je=zv[ft];Je&&(he=`${Je}:${he}`)}if(he=="src"&&!ft&&(q=="img"||q=="input")&&oe=="http://www.w3.org/1999/xhtml")Er=He;else if(he=="alt"&&!ft&&q=="img"&&oe=="http://www.w3.org/1999/xhtml")ml=He;else if(he=="href"&&q=="image"&&oe=="http://www.w3.org/2000/svg"&&ft=="http://www.w3.org/1999/xlink")this.page.fetchers.push(Ut(X,He));else if(ft)X.setAttributeNS(ft,he,He);else try{X.setAttribute(he,He)}catch(Je){W.warn(Je)}}if(Er){let Ke=q==="input"?new Image:X,pt=Ut(Ke,Er,ml);Ke!==X&&(X.src=Er);let ft=()=>{var he,He;if(u.position===v.fixed)return!0;for(let Je=(he=this.nodeContext.parent)==null?void 0:he.viewNode;Je&&Je!==this.viewRoot;Je=Je.parentElement)if(((He=Je.style)==null?void 0:He.position)==="fixed")return!0;return!1};!Js&&!Qs&&!(()=>{let he=this.nodeContext.vertical?Zs:Ks;return he instanceof F&&he.unit==="%"})()&&!ft()?this.page.fetchers.push(pt):(Js&&Qs&&kr&&kr!==1&&Ys.push({image:Ke,element:X,fetcher:pt}),we.push(pt))}delete u.content;let Pr=u["--viv-marker-content"];if(Pr){let Ke=Pr instanceof te?Pr.values:[Pr];for(let pt of Ke)pt instanceof ot&&pt.url&&we.push(Ut(new Image,pt.url))}if(this.preprocessElementStyle(u),this.applyComputedStyles(X,u),this.nodeContext.inline)t||(gt(X,"inline-start"),on(X)&&gt(X,"clone"));else if(t){if(!Vs(u.position)){let Ke=u["margin-break"],pt=this.getBreakTypeAt(this.nodeContext),ft=pt!==null,he=pt==="auto";(Ke===v.discard&&ft||Ke!==v.keep&&he&&!this.nodeContext.floatSide)&&oo(X,"block-start")}}else{let Ke=this.nodeContext.vertical?"width":"height";ci(X,Ke)&&I(X,Ke,this.nodeContext.display==="table-row"?"0.01px":""),gt(X,"block-start"),on(X)&&gt(X,"clone"),oo(X,"block-start")}T&&u["ua-list-item-count"]&&X.setAttribute("value",u["ua-list-item-count"].stringValue()),this.viewNode=X,we.length?vn(we).then(()=>{kr>0&&this.modifyElemDimensionWithImageResolution(Ys,kr,u,this.nodeContext.vertical),o.finish(s)}):o.timeSlice().then(()=>{o.finish(s)})})}),o.result()}isAtStartOfPage(){var t,i;for(let n=this.nodeContext;n!=null&&n.parent&&!n.after;n=n.parent){let r=n===this.nodeContext&&!n.viewNode?(t=n.parent.viewNode)==null?void 0:t.lastChild:(i=n.viewNode)==null?void 0:i.previousSibling;for(;r&&(Me(r,n.parent.whitespace)||hi(r));)r=r.previousSibling;if(r)return!1}return!0}isInsideNonRootMultiColumn(){var t;let i=(t=this.nodeContext.parent)==null?void 0:t.viewNode;return!!(i&&$s(i))}getBreakTypeAt(t){var i,n,r,s,o;if(this.isInsideTable(t))return null;for(let h=t;h&&!h.after;h=h.parent){if(Ge(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 u=this.viewport.window.getComputedStyle(l),d=parseFloat(u.paddingBlockStart),p=parseFloat(u.borderBlockStartWidth);if(d||p)return null;let f=l?.firstChild;for(;f&&(Me(f,h.parent.whitespace)||!h.floatSide&&hi(f));)f=f.nextSibling;if(f&&f!==h.viewNode)return null}}let a=(o=(s=(r=this.context)==null?void 0:r.currentLayoutPosition)==null?void 0:s.flowPositions[this.flowName])==null?void 0:o.startBreakType;return Ge(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,r){let s=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,r);if(s&&s["after-if-continues"]&&s["after-if-continues"].content){let o=new co(t,i,n,r,this.exprContentListener);this.nodeContext.afterIfContinues=new ey(t,o)}}isSVGUrlAttribute(t){return Xn.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,r){t.forEach(s=>{if(s.fetcher.get().get()==="load"){let o=s.image,a=o.width/i,h=o.height/i,l=s.element;if(a>0&&h>0){if(n["box-sizing"]===v.border_box&&(n["border-left-style"]!==v.none&&(a+=nt(n["border-left-width"],this.context)),n["border-right-style"]!==v.none&&(a+=nt(n["border-right-width"],this.context)),n["border-top-style"]!==v.none&&(h+=nt(n["border-top-width"],this.context)),n["border-bottom-style"]!==v.none&&(h+=nt(n["border-bottom-width"],this.context))),i>1){let u=n["max-width"]||v.none,d=n["max-height"]||v.none;if(u===v.none&&d===v.none)I(l,"max-width",`${a}px`);else if(u!==v.none&&d===v.none)I(l,"width",`${a}px`);else if(u===v.none&&d!==v.none)I(l,"height",`${h}px`);else{u.isNumeric(),d.isNumeric();let p=u,f=d;p.unit!=="%"?I(l,"max-width",`${Math.min(a,nt(p,this.context))}px`):f.unit!=="%"?I(l,"max-height",`${Math.min(h,nt(f,this.context))}px`):r?I(l,"height",`${h}px`):I(l,"width",`${a}px`)}}else if(i<1){let u=n["min-width"]||Ne,d=n["min-height"]||Ne;u.isNumeric(),u.isNumeric();let p=u,f=d;p.num===0&&f.num===0?I(l,"min-width",`${a}px`):p.num!==0&&f.num===0?I(l,"width",`${a}px`):p.num===0&&f.num!==0?I(l,"height",`${h}px`):p.unit!=="%"?I(l,"min-width",`${Math.max(a,nt(p,this.context))}px`):f.unit!=="%"?I(l,"min-height",`${Math.max(h,nt(f,this.context))}px`):r?I(l,"height",`${h}px`):I(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){Ft("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 r={},s=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",s,r),!this.processRepeatOnBreak(r))continue;if(this.nodeContext.formattingContext instanceof zi&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let o=this.nodeContext.parent,a=o&&o.formattingContext;this.nodeContext.formattingContext=new zi(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||J(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=M("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=Kl(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=M("preprocessTextContent"),r=Ft("PREPROCESS_TEXT_CONTENT"),s=0;return n.loop(()=>s>=r.length?N(!1):r[s++](this.nodeContext,i).thenAsync(o=>(i=o,N(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=cm(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=M("createNodeView"),r,s=!0;return this.sourceNode.nodeType==1?r=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,r=N(!0)):r=this.createTextNodeView(),r.then(o=>{var a;if(s=o,this.nodeContext.viewNode=this.viewNode,this.viewNode){let h=(d,p)=>d?.nodeType===1&&Kt(d)===p,l=this.nodeContext.parent,u=l?h(this.viewNode,"after")&&h(l.viewNode,"first-letter")&&(a=l.viewNode)!=null&&a.hasChildNodes()?l.parent.viewNode:l.viewNode:this.viewRoot;this.nodeContext.pluginProps.nestedFootnoteDetached&&(u=this.viewRoot),u&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&Me(this.viewNode))&&!u.hasChildNodes()&&vc(u).includes("block-start")&&gt(u,"text-start"),u.appendChild(this.viewNode),Vm(this.viewNode))}n.finish(s)}),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,r=t.parent,s,o,a=n.subShadow||n.parentShadow;n.subShadow?(s=n.subShadow.root,o=n.subShadow.type,o==ht.ROOTLESS&&(s=s.firstChild)):(s=n.owner.firstChild,o=ht.ROOTLESS);let h=t.sourceNode.nextSibling;if(h?(t.sourceNode=h,t.resetView()):t.shadowSibling?t=t.shadowSibling:s?t=null:(t=t.parent.modify(),t.after=!0),s){let l=new Qi(s,r,i);return l.shadowContext=a,l.shadowType=o,l.shadowSibling=t,this.processShadowContent(l)}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=ht.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 r=t.nodeShadow.root;if(t.nodeShadow.type==ht.ROOTLESS&&(r=r.firstChild),r){let s=new Qi(r,t,i);return s.shadowContext=t.nodeShadow,s.shadowType=t.nodeShadow.type,this.processShadowContent(s)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new Qi(n,t,i));if(t.sourceNode.nodeType!=1){let r=Kl(t.preprocessedTextContent);i+=r.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}findImmediateFootnoteCallSibling(t){let i=this.xmldoc.getElementOffset(t.sourceNode),n=t.viewNode;if(!n)return null;let r=n.previousSibling;for(;r;){if(r.nodeType===Node.TEXT_NODE){if(r.textContent.trim().length===0){r=r.previousSibling;continue}return null}if(r.nodeType===Node.ELEMENT_NODE){let s=r;return Kt(s)==="footnote-call"&&s.getAttribute(Xn.FOOTNOTE_CALL_OWNER_ATTR)===i.toString()?s:null}return null}return null}isSemanticFootnoteElement(t){let i=t.sourceNode;return i instanceof Element&&dn(i)}insertFootnoteCall(t){var i,n;let r=M("insertFootnoteCall"),s=$n.createElementNS("http://www.w3.org/1999/xhtml","span");qr(s,"footnote-call");let o=this.xmldoc.getElementOffset(t.sourceNode);s.setAttribute(Xn.FOOTNOTE_CALL_OWNER_ATTR,o.toString());let a=new Qi(s,t.parent,t.boxOffset);a.inline=!0;let h=new co(t.sourceNode,this.styler.getStyle(t.sourceNode,!1),this.styler,this.context,this.exprContentListener);return a.shadowContext=new Wr(t.sourceNode,s,null,((i=t.parent)==null?void 0:i.shadowContext)||null,null,ht.ROOTLESS,h),a.shadowSibling=t,t.boxOffset++,(n=t.viewNode)!=null&&n.parentNode&&t.viewNode.parentNode.removeChild(t.viewNode),this.setCurrent(a,!0,!1).then(l=>{if(l&&s.hasChildNodes())r.finish(a);else{let u=a.modify();u.after=!0,a.viewNode||(u.inline=!0),r.finish(u)}}),r.result()}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return N(n);let r=M("nextInTree");return this.setCurrent(n,!0,i).then(s=>{if((!n.viewNode||!s)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),n.floatSide==="footnote"&&!(this.isFootnote&&!n.parent)&&!n.after&&!n.pluginProps.footnoteCallProcessed&&!n.shadowContext&&!this.isSemanticFootnoteElement(n)){let o=this.findImmediateFootnoteCallSibling(n);o!=null&&o.parentNode&&o.parentNode.removeChild(o),this.isFootnote&&n.parent&&(n.pluginProps.nestedFootnoteDetached=1),n.pluginProps.footnoteCallProcessed=1,this.insertFootnoteCall(n).then(a=>{this.dispatchEvent({type:"nextInTree",nodeContext:a}),r.finish(a)});return}this.dispatchEvent({type:"nextInTree",nodeContext:n}),r.finish(n)}),r.result()}addImageFetchers(t){if(t instanceof tt){let i=t.values;for(let n=0;n<i.length;n++)this.addImageFetchers(i[n])}else if(t instanceof ot){let i=t.url;this.page.fetchers.push(Ut(new Image,i))}}applyComputedStyles(t,i){var n,r,s;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&&((r=this.sourceNode)==null?void 0:r.parentElement)===null&&!!((s=this.viewRoot)!=null&&s.parentElement),l=Object.keys(i);l.sort(Al);let u,d;for(let p of l){if(Hv[p])continue;let f=i[p];if(!(!f||f===Y&&!jt(p))){if(f=f.visit(new og(this.xmldoc.url,this.documentURLTransformer)),f instanceof F)if(f.unit==="em"){let g=this.getEmUnitSize(p,u);g!=null&&(f=new F(f.num*g,"px"))}else if(f.unit==="lh"){let g=this.getLineHeightUnitSize(p,u,d);g!=null&&(f=new F(f.num*g,"px"))}else wu(f.unit)&&(f=Bu(f,this.context));if((p==="font-size"||p==="line-height")&&(p==="font-size"?u=f:d=f,this.viewport.layoutUnitAdj&&f instanceof F&&f.unit!=="%"&&f.unit!=="em"&&f.unit!=="lh"&&(f=new Xi(`calc(${f.toString()} - var(--viv-layoutUnitAdj))`))),fm[p]||a&&gm[p]){this.page.delayedItems.push(new Ua(t,p,f));continue}h&&this.page.pageAreaElement&&un(p)?(I(this.page.pageAreaElement.parentElement.parentElement,p,f.toString()),p!=="writing-mode"&&p!=="direction"&&I(this.viewport.layoutBox,p,f.toString())):I(t,p,f.toString())}}}parsePlusLayoutUnitAdj(t){if(t.endsWith("px")){let i=parseFloat(t);if(!isNaN(i))return Math.round((i+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getLineHeightUnitSize(t,i,n){var r,s,o,a,h,l;let u=((o=(s=(r=this.nodeContext)==null?void 0:r.parent)==null?void 0:s.viewNode)==null?void 0:o.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,d=u?this.parsePlusLayoutUnitAdj(u.lineHeight):this.context.rootLineHeight;if(t==="line-height"||t==="font-size")return d;let p=null;if(n)if(n instanceof vt||n instanceof F&&(n.unit==="em"||n.unit==="%"))p=n instanceof F&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof F&&n.unit!=="lh"){let f=this.context.queryUnitSize(n.unit,!1);if(f!=null)return n.num*f}return null}if(p==null)for(let f=(h=(a=this.nodeContext)==null?void 0:a.parent)==null?void 0:h.viewNode;f&&f.nodeType===1;f=f.parentNode){let g=(l=f?.style)==null?void 0:l.lineHeight;if(g){/^[0-9.]+$/.test(g)&&(p=parseFloat(g));break}}if(p!=null){if(i&&!(i instanceof F))return null;let f=u?this.parsePlusLayoutUnitAdj(u.fontSize):this.context.rootFontSize;if(i instanceof F){let g=qo(i,f,this.context).num;return typeof g!="number"||isNaN(g)?null:p*g}else return f==null?null:p*f}return d}getEmUnitSize(t,i){var n,r,s;let o=((s=(r=(n=this.nodeContext)==null?void 0:n.parent)==null?void 0:r.viewNode)==null?void 0:s.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,a=o?this.parsePlusLayoutUnitAdj(o.fontSize):this.context.rootFontSize;if(t==="font-size"||i==null)return a;if(i instanceof F){let h=qo(i,a,this.context).num;if(typeof h=="number"&&!isNaN(h))return h}return null}applyPseudoelementStyle(t,i,n){if(t.after)return;let r=this.sourceNode,s=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(r,!1),o=bt(s,"_pseudos");if(!o||(s=o[i],!s))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",s,a);let h=a.content;Rt(h)&&(h.visit(new sr(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=M("peelOff"),r=t.firstPseudo,s=t.offsetInNode,o=t.after;if(i>0){let d=t.viewNode.textContent;t.viewNode.textContent=d.substr(0,i),s+=i}else if(!o&&t.viewNode&&s==0){let d=t.viewNode.parentNode;d&&d.removeChild(t.viewNode)}let a=t.boxOffset+i,h=[];for(;t.firstPseudo===r;)h.push(t),t=t.parent;let l=h.pop(),u=l.shadowSibling;return n.loop(()=>{for(;h.length>0;){l=h.pop(),t=new Qi(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=s,t.after=o),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.shadowSibling:u,u=null;let d=this.setCurrent(t,!1);if(d.isPending())return d}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){var r;let s={},o=[],a=this.footnoteStyle;if(this.cascadedPageStyle){let l=bt(this.cascadedPageStyle,Fs);l&&l.area&&(a=l.area)}let h=bt(a,"_pseudos");if(t=this.computeStyle(t,i,a,s),h&&h.before){let l=h.before,u=!!ke(l,"display"),d={},p=this.createElement("http://www.w3.org/1999/xhtml","span");qr(p,"before"),n.appendChild(p),this.computeStyle(t,i,l,d),u||(d.display=v.block);let f=ke(l,"content");if(f){let m=((r=this.sourceNode)==null?void 0:r.nodeType)===1?this.sourceNode:this.xmldoc.root;d.content=f.filterValue(new Cs(this.styler.cascade,m,this.styler.cascade.counterResolver,"before")).evaluate(this.context,"content")}let g=d.content;if(Rt(g)){g.visit(new sr(p,this.context,g,this.exprContentListener));let m=p.querySelectorAll("img[src]");for(let b=0;b<m.length;b++){let x=m[b],y=x.getAttribute("src");if(!y)continue;let P=Ut(x,y);o.push(P),this.page.fetchers.push(P)}let w=p.getAttribute("src");if(w){let b=p.querySelector("img");b||(b=this.document.createElement("img"),b.setAttribute("src",w),p.appendChild(b));let x=Ut(b,w);o.push(x),this.page.fetchers.push(x)}}delete d.content,this.applyComputedStyles(p,d)}return delete s.content,this.applyComputedStyles(n,s),o.length?vn(o).thenReturn(t):N(t)}processFragmentedBlockEdge(t){var i,n,r;let s=!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=ke(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();o=l&&!Mt(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=s;h;h=h.parent){if(((r=h.viewNode)==null?void 0:r.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(gt(l,"inline-end"),on(l)){let u=h.vertical?l.offsetWidth:l.offsetHeight;gt(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>u&&this.fixClonedBoxDecorationOverflow(l)}}else{let u=this.nodeContext.vertical?"width":"height";if(ci(l,u)&&I(l,u,""),gt(l,"block-end"),!a++&&h!==s){let{textAlign:d}=this.viewport.window.getComputedStyle(l);if(d==="justify"&&!o){let p=this.createChildAnonymousBlockIfNeeded(l);p?p!==l?xc(p,["block-start","text-start","block-end","text-end","justify"]):(gt(l,"text-end"),gt(l,"justify")):gt(l,"text-end")}else gt(l,"text-end")}on(l)&&gt(l,"clone"),oo(l,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),r=parseFloat(i.borderInlineEndWidth),s=-(n+r);isNaN(s)||(t.style.marginInlineEnd=`${s}px`)}createChildAnonymousBlockIfNeeded(t){let i=s=>{let{display:o,position:a,float:h}=this.viewport.window.getComputedStyle(s);if(s.localName==="ruby"||Oi[s.localName])return!1;if(s.localName==="br")return!0;if((o==="inline"||o==="contents")&&s.hasChildNodes()){let l=s.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===s.lastChild&&Me(l.nextSibling))){let u=i(l);if(u||u===null)return u}for(let u=l?.previousElementSibling;u;u=u.previousElementSibling){let d=i(u);if(d||d===null)return null}return!1}if(o==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||s.hasAttribute(Cn)){let l=s.previousElementSibling;return l&&(l.nextSibling===s||l.nextSibling===s.previousSibling&&Me(l.nextSibling))?i(l):!1}return!(!o||Mt(o))},n=null;for(let s=t.lastElementChild;s;s=s.previousElementSibling){let o=i(s);if(o){n=s;break}if(o===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&Me(n.nextSibling)))return null;let r=t.ownerDocument.createElement("span");r.className="viv-anonymous-block";for(let s=n.nextSibling,o=null;s;s=o)o=s.nextSibling,r.appendChild(s);return t.appendChild(r),r}convertLengthToPx(t,i,n){let r=t.num,s=t.unit;if(kf(s)){let o=i;for(;o&&o.nodeType!==1;)o=o.parentNode;let a=parseFloat(n.getElementComputedStyle(o)["font-size"]);return this.context,Ya(t,a,this.context).num}else{let o=this.context.queryUnitSize(s,!1);return o?r*o:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,r=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&Kt(n)===Kt(r)}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,r)=>{let s=i.steps[r];return this.isSameNodePositionStep(n,s)})}isPseudoelement(t){return!!Kt(t)}};c(va,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),c(va,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var Uv=va,Hv={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-display":!0,"footnote-policy":!0,"margin-break":!0,page:!0},$v=class{constructor(e){c(this,"layoutBox"),c(this,"window"),c(this,"pixelRatio"),c(this,"scaleRatio"),c(this,"layoutUnitPerPixel"),this.layoutBox=e.layoutBox,this.window=e.window,this.pixelRatio=e.pixelRatio,this.scaleRatio=e.scaleRatio,this.layoutUnitPerPixel=e.layoutUnitPerPixel}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.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.subtractOffsets(t,i)}getElementComputedStyle(e){return this.window.getComputedStyle(e,null)}adjustLengthValue(e){return this.layoutUnitPerPixel?Math.floor(e*this.layoutUnitPerPixel)/this.layoutUnitPerPixel:e}},Os=class{constructor(e,t,i,n,r,s){if(this.window=e,this.fontSize=t,this.pixelRatio=i,c(this,"document"),c(this,"root"),c(this,"outerZoomBox"),c(this,"contentContainer"),c(this,"layoutBox"),c(this,"width"),c(this,"height"),c(this,"scaleRatio",1),c(this,"layoutUnitPerPixel",64),c(this,"layoutUnitAdj",0),this.document=e.document,this.root=n||this.document.body,this.root.hasAttribute("data-vivliostyle-toc-box")){this.outerZoomBox=this.contentContainer=this.layoutBox=this.root,this.width=r||this.root.clientWidth,this.height=s||this.root.clientHeight;return}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;switch(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")&&(I(this.root,"--viv-outputPixelRatio",`${i}`),I(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio),Na){case"chromium":this.layoutUnitPerPixel=64*(this.pixelRatio||e.devicePixelRatio),this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"firefox":this.layoutUnitPerPixel=60,this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"webkit":default:this.layoutUnitPerPixel=64,this.layoutUnitAdj=0}this.layoutUnitAdj&&I(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);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=r||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=s||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let l={width:794,height:1056},u=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!r&&u)&&(this.width=l.width),(!this.height||!s&&u)&&(this.height=l.height)}resetZoom(){I(this.outerZoomBox,"width",""),I(this.outerZoomBox,"height",""),I(this.contentContainer,"width",""),I(this.contentContainer,"height",""),I(this.contentContainer,"transform","")}zoom(e,t,i){I(this.root,"--viv-outputScale",`${i}`),I(this.outerZoomBox,"width",`${e*i}px`),I(this.outerZoomBox,"height",`${t*i}px`),I(this.contentContainer,"width",`${e}px`),I(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}},Cp=class{constructor(e,t,i){this.store=e,this.url=t,this.document=i,c(this,"lang",null),c(this,"totalOffset",-1),c(this,"root"),c(this,"body"),c(this,"head"),c(this,"last"),c(this,"lastOffset",1),c(this,"idMap"),this.root=i.documentElement;let n=null,r=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let s=this.root.firstChild;s;s=s.nextSibling){if(s.nodeType!=1)continue;let o=s;if(o.namespaceURI=="http://www.w3.org/1999/xhtml")switch(o.localName){case"head":r=o;break;case"body":n=o;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=r,this.last=this.root,this.last.setAttribute($t,"0")}doc(){return new Ep([this.document])}getElementOffset(e){let t=e.getAttribute($t);if(t)return parseInt(t,10);let i=this.lastOffset,n=this.last;for(;n!=e;){let r=n.firstChild;if(!r){for(;r=n.nextSibling,!r;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=r,r.nodeType==1?(r.setAttribute($t,i.toString()),++i):i+=r.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,r=e,s=null;if(r.nodeType==1){if(!i)return this.getElementOffset(r)}else{if(n=t,s=r.previousSibling,!s)return r=r.parentNode,n+=1,this.getElementOffset(r)+n;r=s}for(;;){for(;r.lastChild;)r=r.lastChild;if(r.nodeType==1)break;if(n+=r.textContent.length,s=r.previousSibling,!s){r=r.parentNode;break}r=s}return n+=1,this.getElementOffset(r)+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=ni(a.length,l=>{let u=a[l];return this.getElementOffset(u)>e});if(h==0)break;i=a[h-1]}let n=t+1,r=i,s=r.firstChild||r.nextSibling,o=null;for(;;){if(s){if(s.nodeType==1||(r=s,o=r,n+=s.textContent.length,n>e&&!/^\s*$/.test(s.textContent)))break}else if(r=r.parentNode,!r)break;s=r.nextSibling}return s&&o&&/^\s*$/.test(o.textContent)&&(o=s),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}},xa=(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))(xa||{});function Dr(e,t,i){let n=i||new DOMParser,r;try{r=n.parseFromString(e,t)}catch{}if(r){let s=r.documentElement,o="parsererror";if(s.localName===o)return null;for(let a=s.firstElementChild;a;a=a.nextElementSibling)if(a.localName===o)return null}else return null;return r}function Wv(e){let t=e.contentType;if(t){let n=Object.keys(xa);for(let r=0;r<n.length;r++)if(xa[n[r]]===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 kp(e,t){let i=e.responseXML;if(!i){let r=new DOMParser,s=e.responseText;if(s){let o=Wv(e);if(i=Dr(s,o||"application/xml",r),i&&!o){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Dr(s,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Dr(s,"image/svg+xml",r))}i||(i=Dr(s,"text/html",r))}}let n=i?new Cp(t,e.url,i):null;return N(n)}function Gv(){return new _a(kp,"document")}var jv=class Sa{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new Sa(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new Sa(n=>{if(!this.check(n))return!1;let r=new Ep([n]);return r=r.child(t),i&&(r=r.predicate(i)),r.size()>0})}},Vh=new jv(e=>!0),Ep=class Ca{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 Ca(i)}forEachNode(t){let i=[],n=r=>{i.push(r)};for(let r=0;r<this.nodes.length;r++)t(this.nodes[r],n);return new Ca(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 r=t(this.nodes[n]);r!=null&&i.push(r)}return i}child(t){return this.forEachNode((i,n)=>{for(let r=i.firstChild;r;r=r.nextSibling)r.nodeType==1&&r.localName==t&&n(r)})}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)}},Xv=new yr(()=>{let e=M("uaStylesheetBase"),t=sp(),i=Ee("user-agent-base.css",fi),n=new ar(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),_w(n.cascade),za(sc,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function qv(){return Xv.get()}var Yv=class extends Xr{constructor(e,t,i,n,r,s){super(e,t,null,i,n,"counter-style"),this.counterStyleName=r,this.counterStyles=s}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||W.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},Zv=class{constructor(e,t,i,n,r,s,o,a,h,l,u){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=r,this.fontFaces=s,this.footnoteProps=o,this.flowProps=a,this.viewportProps=h,this.pageProps=l,this.counterStyleStore=u,c(this,"fontDeobfuscator"),c(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(d){d=d;let p=this,f=p.currentLayoutPosition,g=f.firstFlowChunkOfFlow(d);return p.matchPageSide(f.startSideOfFlow(d))&&f.hasContent(d,p.lookupOffset)&&!!g&&!p.flowChunkIsAfterParentFlowForcedBreak(g)}),this.pageScope.defineName("page-number",new Ie(this.pageScope,function(){let d=this;return d.pageNumberOffset+d.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new Ie(this.pageScope,function(){let d=this.currentLayoutPosition;return d?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let r=new ko(this.rootScope,e,t,i),s=sw(r,this.viewportProps),o=s.width,a=s.height,h=s["text-zoom"],l=1;if(o&&a||h){let u=_t.em;if((h?h.evaluate(r,"text-zoom"):null)===v.scale&&(l=u/i,i=u,e*=l,t*=l),o&&a){let d=nt(o.evaluate(r,"width"),r),p=nt(a.evaluate(r,"height"),r);if(d>0&&p>0)return{width:n&&n.spreadView?(d+n.pageBorder)*2:d,height:p,fontSize:i}}}}return{width:e,height:t,fontSize:i}}};function Uh(e){let t=new Map,i=n=>{n.formattingContext&&!t.has(n.formattingContext)&&t.set(n.formattingContext,n.formattingContext.saveState()),n.shadowSibling&&i(n.shadowSibling)};for(let n in e.flowPositions){let r=e.flowPositions[n];for(let s of r.positions){let o=s.chunkPosition.primary;for(let a of o.steps)i(a);if(s.chunkPosition.floats)for(let a of s.chunkPosition.floats)for(let h of a.steps)i(h)}}return t}function Hh(e){for(let[t,i]of e)i!==void 0&&t.restoreState(i)}var pl=class extends ko{constructor(e,t,i,n,r,s,o,a,h,l,u,d,p,f){super(e.rootScope,n.width,n.height,n.fontSize),this.style=e,this.xmldoc=t,this.viewport=n,this.clientLayout=r,this.fontMapper=s,this.customRenderer=o,this.fallbackMap=a,this.pageNumberOffset=h,this.documentURLTransformer=l,this.counterStore=u,this.cmykStore=d,c(this,"lang"),c(this,"primaryFlows",{body:!0}),c(this,"rootPageBoxInstance",null),c(this,"styler",null),c(this,"stylerMap",null),c(this,"currentLayoutPosition",null),c(this,"layoutPositionAtPageStart",null),c(this,"currentCascadedPageStyle",null),c(this,"lookupOffset",0),c(this,"faces"),c(this,"pageBoxInstances",{}),c(this,"pageManager",null),c(this,"rootPageFloatLayoutContext"),c(this,"pageBreaks",{}),c(this,"pageProgression",null),c(this,"isVersoFirstPage",!1),c(this,"blankPageAtStart",!1),c(this,"pageSheetSize",{}),c(this,"pageSheetHeight",0),c(this,"pageSheetWidth",0),c(this,"semanticFootnoteFirstRefOffsets",new Map),c(this,"semanticFootnoteFirstRefOffsetsInitialized",{value:!1}),c(this,"pageGroupPageCounts",Object.create(null)),c(this,"currentPageGroupDocument",null),this.lang=t.lang||i,this.faces=new Yb(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new en(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!f;for(let g in e.flowProps){let m=e.flowProps[g],w=ke(m,"flow-consume");w&&(w.evaluate(this,"flow-consume")==v.all?this.primaryFlows[g]=!0:delete this.primaryFlows[g])}}init(){let e=M("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 Ph(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,t,i,this.style.counterStyleStore,this.cmykStore),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=gp(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new tv(r);let s=this.style.cascade.createInstance(this,t,i,this.lang,this.style.counterStyleStore,this.cmykStore);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(s,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new yv(s,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=qb(h.properties,this),u=new op(l);o.push(u)}this.fontMapper.findOrLoadFonts(o,this.faces).then(()=>{Bv(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),this.styler.cascade.applyCmykFilter(l);let u=_h(Rs(l),this);this.pageSheetSize[h]={width:u.pageWidth+u.cropOffset*2,height:u.pageHeight+u.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 ko(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),r=this.counterStore.createCounterListener(e.url),s=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new Ph(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,r,s,i.counterStyleStore,this.cmykStore),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 Em,i.flowPositions[e.flowName]=n);let r=Sm(e.element),s=new xi(r),o=new km(s,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 r{unknownProperty(h,l){n=!1}invalidPropertyValue(h,l){n=!1}simpleProperty(h,l,u){}}let s=new r,o=vr(this.style.rootScope,new Xt(t,null),"");return o?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,o,!1,s),n):!1}evalSupportsSelector(e){let t=new Pp(null),i=new Xt(e+"{}",t);return new br(Le,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,r=n.steps[0].node,s=n.offsetInNode,o=n.after,a=0;for(;r.ownerDocument!=this.xmldoc.document;)a++,r=n.steps[a].node,o=!1,s=0;let h=this.xmldoc.getNodeOffset(r,s,o);h<t&&(t=h)}return t}getNodePositionOffset(e){let t=e.steps[0].node,i=e.offsetInNode,n=e.after,r=0;for(;t.ownerDocument!=this.xmldoc.document;)r++,t=e.steps[r].node,n=!1,i=0;return this.xmldoc.getNodeOffset(t,i,n)}getPageStartOffset(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r)for(let s=0;s<r.positions.length;s++){let o=r.positions[s].chunkPosition.primary,a=this.getNodePositionOffset(o);a<i&&(i=a)}}return i}getPageStartCounterOffsets(e){let t=this.getPageStartOffset(e);if(!isFinite(t))return{counterOffset:t,changeOffset:t};let i=this.xmldoc.body||this.xmldoc.root,n=i?this.getFirstInFlowElementAtOrAfter(i,t):null,r=i?this.xmldoc.getElementOffset(i):t,s=t<=r,o=n===i&&s?this.getFirstInFlowChildElement(i):n;if(!o)return{counterOffset:t,changeOffset:t};let a=this.xmldoc.getElementOffset(o),h=t;return s&&a!==t&&(h=a),a===t&&(this.isInlineLevelElement(o)?h=Math.max(0,t-1):h=this.getDeepestFirstInFlowChildOffset(o)),{counterOffset:h,changeOffset:a}}getPageStartElement(e,t=this.getPageStartOffset(e)){if(!isFinite(t))return null;let i=this.xmldoc.body||this.xmldoc.root;if(!i)return null;let n=this.getFirstInFlowElementAtOrAfter(i,t),r=this.xmldoc.getElementOffset(i),s=t<=r;return n===i&&s?this.getFirstInFlowChildElement(i):n}isForcedPageBreakValue(e){return Ge(e)&&e!=="column"&&e!=="region"}hasForcedPageBreakBefore(e){let t=ke(e,"break-before");if(!t)return!1;let i=t.evaluate(this,"break-before").toString();return this.isForcedPageBreakValue(i)}getExplicitPageType(e){let t=ke(e,"page");if(!t)return null;let i=t.evaluate(this,"page").toString();return!i||i.toLowerCase()==="auto"?null:i}getPageGroupPageType(e){let t=this.styler.getStyle(e,!1);return t?this.getExplicitPageType(t):null}getPreviousInFlowSibling(e){let t=e.previousElementSibling;for(;t;){if(this.isNormalFlowElement(t))return t;t=t.previousElementSibling}return null}getFirstDocumentFlowElement(){let e=this.xmldoc.body||this.xmldoc.root;if(!e)return null;let t=this.xmldoc.getElementOffset(e),i=this.getFirstInFlowElementAtOrAfter(e,t);return i===e?this.getFirstInFlowChildElement(e):i}resolveFirstPageType(){let e=this.getFirstDocumentFlowElement();return e?this.getPageGroupPageType(e):null}shouldStartPageGroup(e,t,i){let n=this.styler.getStyle(e,!1);if(!n)return!1;if(this.getFirstDocumentFlowElement()===e)return!0;let r=this.xmldoc.getElementOffset(e),s=this.xmldoc.body||this.xmldoc.root,o=this.xmldoc.getElementOffset(s);if(i<=o&&e===s||!this.getPreviousInFlowSibling(e)&&i===r)return!0;if(r!==i)return!1;if(this.hasForcedPageBreakBefore(n))return!0;let a=this.getPreviousInFlowSibling(e);if(!a)return!1;let h=this.styler.getStyle(a,!1);return h?this.getExplicitPageType(h)!==t:!1}updatePageGroupPageIndices(e){let t=this.pageManager.pageCascadeInstance;t.pageTypePageIndices=Object.create(null);let i=e.startSideOfFlow("body"),n=e.flowPositions.body,r=!!(n&&n.positions.length),s=xn(i)&&!this.matchPageSide(i)&&!r,o=!(this.blankPageAtStart&&e.page===1)&&!e.isBlankPage&&!s,a=this.getPageStartOffset(e),h=this.getPageStartElement(e,a);if(!h)return;let l=h.ownerDocument,u=this.currentPageGroupDocument!==l&&o;u&&(this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=l);let d=h;for(;d;){let p=this.getPageGroupPageType(d);if(p){let f=this.pageGroupPageCounts[p]||(this.pageGroupPageCounts[p]=new Map),g=f.get(d)||0;(g>0||o&&(u||this.shouldStartPageGroup(d,p,a)))&&(g+=1,f.set(d,g),(t.pageTypePageIndices[p]||(t.pageTypePageIndices[p]=[])).push(g))}if(d===this.xmldoc.root)break;d=d.parentElement}}getFirstInFlowElementAtOrAfter(e,t){if(this.isNormalFlowElement(e)&&this.xmldoc.getElementOffset(e)>=t)return e;let i=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:n=>{let r=n;return this.isNormalFlowElement(r)?this.xmldoc.getElementOffset(r)<t?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}}).firstChild();return i??null}getDeepestFirstInFlowChildOffset(e){let t=e;for(;;){let i=this.getFirstInFlowChildElement(t);if(!i)return this.xmldoc.getElementOffset(t);t=i}}getFirstInFlowChildElement(e){let t=e.firstChild;for(;t;){if(t.nodeType===Node.TEXT_NODE){if(!Me(t))return null;t=t.nextSibling;continue}if(t.nodeType!==Node.ELEMENT_NODE){t=t.nextSibling;continue}let i=t;if(this.isNormalFlowElement(i))return i;t=t.nextSibling}return null}isNormalFlowElement(e){var t,i;let n=this.styler.getStyle(e,!1);if(this.getDisplayValue(e)===v.none)return!1;let r=(t=n?.position)==null?void 0:t.evaluate(this.styler.context,"position"),s=r&&!J(r)?r:v.static;if(bs(s)||Vs(s))return!1;let o=(i=n?.float)==null?void 0:i.evaluate(this.styler.context,"float");return(o&&!J(o)?o:v.none)===v.none}isInlineLevelElement(e){return Mt(this.getDisplayValue(e))}getDisplayValue(e){var t;let i=this.styler.getStyle(e,!1),n=(t=i?.display)==null?void 0:t.evaluate(this.styler.context,"display");return n&&!J(n)?n:v.inline}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r){let s=this.getConsumedOffset(r);s<i&&(i=s)}}return i}dumpLocation(e){W.debug("Location - page",this.currentLayoutPosition.page),W.debug(" current:",e),W.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)W.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new je(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 r=i.positions[0].flowChunk.breakBefore,s=i.startBreakType;i.startBreakType=Zl(et(s,r))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,r;for(let s=0;s<n.length;s++){if(r=n[s],r.pageBox.pseudoName===cl)continue;let o=1;r.pageBox.pseudoName===al&&!(this.actualPageWidth&&this.actualPageHeight)&&(o=1/0);let a=r.getProp(this,"utilization");a&&a.isNum()&&(o=a.num);let h=this.queryUnitSize("em",!1),l=this.pageWidth()*this.pageHeight(),u=Math.ceil(o*l/(h*h)),d=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,u),this.styler.cascade.currentPageType=d,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let p=r.getProp(this,"enabled");if(!p||p===v._true){if(t.page===1&&this.blankPageAtStart){r.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(r,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,r=t[i].forcedBreakOffsets;if(!r.length||n<r[0])return!1;let s=ni(r.length,l=>r[l]>n)-1,o=r[s],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 Ga(null)),e.flowRootFormattingContext=i.formattingContext}beginIsolatedRootPageFloatLayoutContext(){let e=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=new en(null,null,null,null,null,null,null),e}endIsolatedRootPageFloatLayoutContext(e){this.rootPageFloatLayoutContext=e}hasActiveRootPageFloatLayoutContext(){return this.rootPageFloatLayoutContext.getDeferredPageFloatContinuations().length>0||this.rootPageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0||this.rootPageFloatLayoutContext.getFloatsDeferredToNextInChildContexts().length>0}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=this.counterStore.currentPageCountersStack.length>0,r=h=>{var l,u;if(!n||h.floatReference!==Te.PAGE)return!1;let d=((u=(l=this.layoutPositionAtPageStart)==null?void 0:l.flowPositions)==null?void 0:u.body)||null,p=d?this.getConsumedOffset(d):Number.NaN,f=isFinite(p)?p:this.getPageStartOffset(this.layoutPositionAtPageStart,!0),g=this.xmldoc.getNodeOffset(h.nodePosition.steps[0].node,0,!1);return g!=null&&isFinite(f)&&g>f},s=M("layoutDeferredPageFloats"),o=!1,a=0;return s.loopWithFrame(h=>{if(a===i.length){h.breakLoop();return}let l=i[a++],u=l.float;if(r(u)){h.breakLoop();return}let d=new Sn().findByFloat(u),p=d.findPageFloatFragment(u,t);if(p&&p.hasFloat(u)){h.continueLoop();return}else if(t.isForbidden(u)||t.hasPrecedingFloatsDeferredToNext(u)){t.deferPageFloat(l),h.breakLoop();return}e.layoutPageFloatInner(l,d,null,p).then(f=>{if(!f){h.breakLoop();return}let g=t.parent.isInvalidated();if(g){h.breakLoop();return}else t.isInvalidated()&&!g&&(o=!0,t.validate());h.continueLoop()})}).then(()=>{o&&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 xi(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=M("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let r=[],s=[],o=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-s.length>0;){let h=0;for(;s.includes(h);)h++;let l=i.positions[h];if(l.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(l.flowChunk))break;for(let p=h+1;p<i.positions.length;p++){if(s.includes(p))continue;let f=i.positions[p];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(l.flowChunk)&&(l=f,h=p)}let u=l.flowChunk,d=!0;if(e.layout(l.chunkPosition,o,i.breakAfter).then(p=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(o=!1,l.flowChunk.repeated&&(p===null||u.exclusive)&&r.push(h),u.exclusive){s.push(h),a.breakLoop();return}else{let f=!!p||!!e.pageBreakType,g=this.getLastAfterPositionIfDeferredFloatsExists(e,p);if(e.pageBreakType&&g?(l.chunkPosition=g,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(s.push(h),(p||g)&&(l.chunkPosition=p||g,r.push(h)),i.startBreakType=Zl(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,d?d=!1:a.continueLoop()}),d){d=!1;return}}a.breakLoop()}).then(()=>{if(!e.pageFloatLayoutContext.isInvalidated()){i.positions=i.positions.filter((h,l)=>r.includes(l)||!s.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 sy([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,r,s,o,a,h,l,u,d,p,f){let g=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,m=r.element,w=new en(a,Te.COLUMN,null,o,null,null,null),b=this.currentLayoutPosition.clone(),x=M("createAndLayoutColumn"),y;return x.loopWithFrame(P=>{let S=this.createLayoutConstraint(w);if(h>1){let R=this.viewport.document.createElement("div");if(I(R,"position","absolute"),m.appendChild(R),y=new Es(R,p,this.clientLayout,S,w),y.isNonFirstColumn=s>0,y.forceNonfitting=f,y.vertical=r.vertical,y.rtl=r.rtl,y.snapHeight=r.snapHeight,y.snapWidth=r.snapWidth,r.vertical){let A=(r.rtl?h-s-1:s)*(u+l)+r.paddingTop,U=parseFloat(m.style.width);y.setHorizontalPosition(r.paddingLeft+U-r.width,r.width),y.setVerticalPosition(A,u)}else{let A=(r.rtl?h-s-1:s)*(u+l)+r.paddingLeft;y.setVerticalPosition(r.paddingTop,r.height),y.setHorizontalPosition(A,u)}y.originX=t,y.originY=i}else y=new Es(m,p,this.clientLayout,S,w),y.isNonFirstColumn=!1,y.copyFrom(r);y.exclusions=g?[]:n.concat(),y.innerShape=d,w.setContainer(y),(y.vertical?y.height:y.width)>=0?this.layoutColumn(y,o).then(()=>{w.isInvalidated()||w.finish(),y.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(y.pageFloatLayoutContext.validate(),this.currentLayoutPosition=b.clone(),y.element!==m&&m.removeChild(y.element),P.continueLoop()):P.breakLoop()}):(w.finish(),P.breakLoop())}).then(()=>{x.finish(y)}),x.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof yp||t instanceof ll&&!(t instanceof yn))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof Pn;let r=t.getProp(this,"writing-mode")||null,s=t.getProp(this,"direction")||null;return new en(e,Te.REGION,i,n,null,r,s)}layoutFlowColumnsWithBalancing(e,t,i,n,r,s,o,a,h){let l=this.currentLayoutPosition.clone(),u=this.getRegionPageFloatLayoutContext(s,t,o,a),d=!0,p=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,r,s,u,o,a,h,d).thenAsync(f=>N(f?{columns:f,position:this.currentLayoutPosition}:null)));return p().thenAsync(f=>{if(!f)return N(null);if(h<=1)return N(f.columns);let g=t.getProp(this,"column-fill")||v.balance,m=this.currentLayoutPosition.flowPositions[a],w=Xy(h,g,p,u,o,f.columns,m);return w?(d=!1,s.lock(),u.lock(),w.balanceColumns(f).thenAsync(b=>(s.unlock(),s.validate(),u.unlock(),this.currentLayoutPosition=b.position,N(b.columns)))):N(f.columns)})}layoutFlowColumns(e,t,i,n,r,s,o,a,h,l,u){let d=M("layoutFlowColumns"),p=this.currentLayoutPosition.clone(),f=Uh(this.currentLayoutPosition),g=t.getPropAsNumber(this,"column-gap"),m=l>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,w=t.getActiveRegions(this),b=t.getProp(this,"shape-inside"),x=Yu(b,0,0,a.width,a.height,this),y=new Uv(h,this,this.viewport,this.styler,w,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.style.pageProps,this.currentCascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized),P=0,S=null,R=[];return d.loopWithFrame(A=>{this.createAndLayoutColumn(t,i,n,r,a,P++,h,o,l,g,m,x,y,u).then(U=>{if(s.isInvalidated()){R=null,A.breakLoop();return}if((U.pageBreakType&&U.pageBreakType!=="column"||P===l)&&!o.isInvalidated()&&o.finish(),o.isInvalidated()){P=0,this.currentLayoutPosition=p.clone(),Hh(f),o.validate(),o.isLocked()?(R=null,A.breakLoop()):A.continueLoop();return}S=U,R[P-1]=S,S.pageBreakType&&S.pageBreakType!="column"&&(P=l,S.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),P<l?A.continueLoop():A.breakLoop()})}).then(()=>{d.finish(R)}),d.result()}layoutContainer(e,t,i,n,r,s,o){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==v._true)return N(!0);let h=M("layoutContainer"),l=t.getProp(this,"wrap-flow")===v.auto,u=t.getProp(this,"flow-from"),d=this.viewport.document.createElement("div");d.role=t instanceof bp?"complementary":"presentation";let p=t.getProp(this,"position");I(d,"position",p?p.name:"absolute");let f=t instanceof yn;t instanceof Pn?i.appendChild(d):i.insertBefore(d,i.firstChild);let g=new Fc(d);g.vertical=t.vertical,g.rtl=t.rtl,g.borderBoxSizing=t.borderBoxSizing,g.exclusions=s,t.prepareContainer(this,g,e,this.faces,this.clientLayout),t instanceof yn&&(g.width<=0||g.height<=0)&&W.warn("Negative or zero page area size"),g.originX=n,g.originY=r,n+=g.left+g.marginLeft+g.borderLeft,r+=g.top+g.marginTop+g.borderTop,this.setPagePageFloatLayoutContextContainer(o,t,g);let m,w=!1;if(!u||!u.isIdent()){let b=[],x=t.getProp(this,"content");if(x instanceof $&&x.expr instanceof Ie&&x.expr.str.startsWith("running-element-"))x.visit(new sr(d,this,x,this.counterStore.getExprContentListener()));else if(Rt(x)){let y="span";x instanceof ot&&(y="img");let P=this.viewport.document.createElement(y);x.visit(new sr(P,this,x,this.counterStore.getExprContentListener())),d.appendChild(P),y=="img"&&t.transferSingleUriContentProps(this,P,this.faces),t.transferContentProps(this,g,e,this.faces);let S=P.querySelectorAll("img[src]");for(let A=0;A<S.length;A++){let U=S[A],G=U.getAttribute("src");if(!G)continue;let Z=Ut(U,G);b.push(Z),e.fetchers.push(Z)}let R=P.getAttribute("src");if(R){let A=P.querySelector("img");A||(A=P);let U=Ut(A,R);b.push(U),e.fetchers.push(U)}y=="span"&&Kw(P,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(d),w=!0);w||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=b.length?vn(b).thenReturn(!0):N(!0)}else if(this.pageBreaks[u.toString()])o.isInvalidated()||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=N(!0);else{let b=M("layoutContainer.inner"),x=u.toString(),y=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,r,s,o,g,x,y).then(P=>{if(!o.isInvalidated()){let S=P[0];S.element===d&&(g=S),g.computedBlockSize=Math.max.apply(null,P.map(A=>A.computedBlockSize)),t.finishContainer(this,g,e,S,y,this.clientLayout,this.faces);let R=this.currentLayoutPosition.flowPositions[x];R&&R.breakAfter==="region"&&(R.breakAfter=null)}b.finish(!0)}),m=b.result()}return m.then(()=>{if(o.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(g.computedBlockSize)>0){if(!w&&!l){let x=t.getProp(this,"shape-outside"),y=g.getOuterShape(x,this);s.push(y)}}else if(t.children.length==0){i.removeChild(d),h.finish(!0);return}let b=f?0:t.children.length-1;h.loop(()=>{for(;b>=0&&b<t.children.length;){let x=t.children[f?b++:b--],y=this.layoutContainer(e,x,d,n,r,s,o);if(y.isPending())return y.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 r=i.positions[n];r.flowChunk.startPage>=0&&r.flowChunk.startPage+r.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 r=i.positions[n];r.flowChunk.startPage<0&&r.flowChunk.startOffset<this.lookupOffset&&(r.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,n,r,s;let o=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new Pm,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let a=1e4;if(t.page>a)throw new Error(`Too many pages generated (over ${a} pages)`);let h=t.startSideOfFlow("body");t.isBlankPage=xn(h)&&this.matchPageSide(h),e.isBlankPage=t.isBlankPage,t.page++,e.pageType==null&&(e.pageType=(n=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:t.page===1?this.resolveFirstPageType():null)!=null?n:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.updatePageGroupPageIndices(t),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let l=Uh(t),u=o?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.currentCascadedPageStyle=u,this.styler.cascade.applyVarFilter([u],this.styler,null),this.styler.cascade.applyCalcFilter(u,this.styler.context),this.styler.cascade.applyCmykFilter(u),!o){let b=new je(this.style.pageScope,"left-page");e.side=b.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let d=this.selectPageMaster(u);if(!d)return N(null);let p=0;if(!o){e.setAutoPageWidth(d.pageBox.specified.width.value===mr),e.setAutoPageHeight(d.pageBox.specified.height.value===wr);let{counterOffset:b,changeOffset:x}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(b)||(b=this.lookupOffset,x=this.lookupOffset),isFinite(b)&&this.styler.styleUntil(b,0);let y=this.styler.getCounterSnapshotAtOffset(b),P=x===b?y:this.styler.getCounterSnapshotAtOffset(x);y||(y=this.styler.getLastCounterSnapshot()),P||(P=y),this.counterStore.setCurrentPageDocCounters((r=y?.counters)!=null?r:null,(s=P?.changes)!=null?s:null,P?.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(u,this);let S=_h(Rs(u),this);this.setPageSizeAndBleed(S,e),cv(u,S,e,this),p=S.bleedOffset+S.bleed}let f=!o&&d.getProp(this,"writing-mode")||v.horizontal_tb;this.pageVertical=f!=v.horizontal_tb;let g=d.getProp(this,"direction")||v.ltr,m=new en(this.rootPageFloatLayoutContext,Te.PAGE,null,null,null,f,g),w=M("layoutNextPage");return w.loopWithFrame(b=>{this.layoutContainer(e,d,e.bleedBox,p,p,[],m).then(()=>{if(m.isInvalidated()||m.finish(),m.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),Hh(l),m.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);b.continueLoop()}else b.breakLoop()})}).then(()=>{d.adjustPageLayout(this,e,this.clientLayout),o||(this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(x=>{let y=t.flowPositions[x],P=y.breakAfter;P&&(P==="page"||!this.matchPageSide(P))&&(y.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let b=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(b,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),w.finish(t)}),w.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.right=`${e.bleedOffset}px`,t.bleedBox.style.top=`${e.bleedOffset}px`,t.bleedBox.style.bottom=`${e.bleedOffset}px`,t.bleedBox.style.padding=`${e.bleed}px`}},Kv=class ka extends ar{constructor(t,i,n,r){super(t.rootScope,t,i,n,r,t.validatorSet,!n),this.masterHandler=t,c(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let r=new ap(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new rv(r.scope,this.masterHandler,r,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=At(this.scope,this.condition,i)),this.masterHandler.pushHandler(new ka(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new $w(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new Xr(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new Yv(this.scope,this.owner,{},this.masterHandler.validatorSet,t,this.masterHandler.counterStyles))}startFlowRule(t){let i=this.masterHandler.flowProps[t];i||(i={},this.masterHandler.flowProps[t]=i),this.masterHandler.pushHandler(new Xr(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new Xr(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=ei(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new vp(this.scope,this.owner,this.masterHandler.validatorSet,i))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new Av(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(ar.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 ka(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},Pp=class extends Yg{constructor(e){super(),this.validatorSet=e,c(this,"rootScope"),c(this,"pageScope"),c(this,"rootBox"),c(this,"cascadeParserHandler"),c(this,"regionCount",0),c(this,"fontFaces",[]),c(this,"counterStyles",new Tb),c(this,"footnoteProps",{}),c(this,"flowProps",{}),c(this,"viewportProps",[]),c(this,"pageProps",{}),this.rootScope=new Co(null),this.pageScope=new Co(this.rootScope),this.rootBox=new Jb(this.rootScope),this.cascadeParserHandler=new Kv(this,null,null,null),this.slave=this.cascadeParserHandler}};function Jv(e,t){return t.parseOPSResource(e)}var Qv=class extends _a{constructor(e){super(Jv,"document"),this.fontDeobfuscator=e,c(this,"styleByKey",{}),c(this,"styleFetcherByKey",{}),c(this,"styleByDocURL",{}),c(this,"triggersByDocURL",{}),c(this,"validatorSet",null),c(this,"styleSheets",[]),c(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=M("OPSDocStore.init");return this.validatorSet=sp(),qv().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=Ee(pn(t),Di)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ee(pn(t),Di)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=M("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return kp(e,this).then(r=>{var s;if(!r){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=Ft("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](r.document)}catch(g){W.warn("Error during single document preprocessing:",g)}}let o=[],a=r.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let p=0;p<a.length;p++){let f=a[p],g=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),m=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),w=f.getAttribute("action"),b=f.getAttribute("ref");g&&m&&w&&b&&o.push({observer:g,event:m,action:w,ref:b})}this.triggersByDocURL[i]=o;let h=[];if(h.push({url:Ee("user-agent-page.css",fi),text:rc,flavor:"UA",classes:null,media:null}),h.push({url:Ee("user-agent-counter-styles.css",fi),text:lc,flavor:"UA",classes:null,media:null}),n)h.push({url:Ee("user-agent-toc.css",fi),text:oc,flavor:"UA",classes:null,media:null});else{let p=r.document.querySelectorAll("style, link, meta");for(let f of p){let g=f.namespaceURI,m=f.localName;if(g=="http://www.w3.org/1999/xhtml")if(m=="style"){let w=f.getAttribute("class"),b=f.getAttribute("media"),x=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:x?w:null,media:b})}else if(m=="link"){let w=f.getAttribute("href"),b=(s=f.getAttribute("rel"))==null?void 0:s.split(/\s+/),x=f.getAttribute("class"),y=f.getAttribute("media");if(w&&b!=null&&b.includes("stylesheet")&&(!b.includes("alternate")||x)){let P=Ee(w,i),S=f.getAttribute("title");h.push({url:P,text:null,classes:S?x:null,media:y,flavor:"Author"})}}else m=="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 p=0;p<h.length;p++)l+=h[p].url,l+="^",h[p].text&&(l+=h[p].text),l+="^";let u=this.styleByKey[l];if(u){this.styleByDocURL[i]=u,t.finish(r);return}let d=this.styleFetcherByKey[l];d||(d=new yr(()=>{let p=M("fetchStylesheet"),f=0,g=new Pp(this.validatorSet);return p.loop(()=>{if(f<h.length){let m=h[f++];return g.startStylesheet(m.flavor),m.text!==null?za(m.text,g,m.url,m.classes,m.media).thenReturn(!0):fc(m.url,g,m.classes,m.media)}return N(!1)}).then(()=>{let m=g.cascadeParserHandler.finish();u=new Zv(this,g.rootScope,g.pageScope,m,g.rootBox,g.fontFaces,g.footnoteProps,g.flowProps,g.viewportProps,g.pageProps,g.counterStyles),this.styleByKey[l]=u,delete this.styleFetcherByKey[l],p.finish(u)}),p.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[l]=d,d.start()),d.get().then(p=>{this.styleByDocURL[i]=p,t.finish(r)})}),t.result()}processViewportMeta(e){return""}},nr="\u25B8",$h="\u25BE",e0="\u25B9";function fl(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(s=>s.contains(n)))continue;let r=n;/^h[1-6]$/.test(r.localName)&&(r.previousElementSibling?r=r.nextElementSibling:r=r.parentElement),r&&r.querySelector("li a[href]")&&t.push(r)}return t}function t0(e){let t=fl(e),i=[];for(let n of t)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var i0=class{constructor(e,t,i,n,r,s,o,a,h,l,u){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=r,this.rendererFactory=o,this.fallbackMap=a,this.documentURLTransformer=h,this.counterStore=l,this.cmykStore=u,c(this,"pref"),c(this,"page",null),c(this,"instance",null),this.pref=pu(s),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;ci(n,"height","auto")!="auto"&&(I(n,"height","auto"),this.setAutoHeight(n,t)),ci(n,"position","static")=="absolute"&&(I(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,r)=>{let s=r.behavior;if(s)switch(s.toString()){case"toc-node-anchor":r.color=v.inherit,r["text-decoration"]=v.none;break;case"toc-node":r.display=v.block,r.margin=Ne,r.padding=Ne,r["padding-inline-start"]=new F(1.25,"em");break;case"toc-node-first-child":r.display=v.inline_block,r.margin=new F(.2,"em"),r["vertical-align"]=v.top,r.color=v.inherit,r["text-decoration"]=v.none;break;case"toc-container":r.padding=Ne;break}if(!s||s.toString()!="toc-node"&&s.toString()!="toc-container")return t(i,n,r);let o=i.firstChild;o&&o.nodeType!==1&&Me(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!=nr&&(l.textContent=nr,I(l,"cursor","pointer"),l.addEventListener("click",n0,!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"),s.toString()=="toc-node"){let l=n.ownerDocument.createElement("div");if(l.textContent=e0,I(l,"margin","0.2em 0 0 -1em"),I(l,"margin-inline-start","-1em"),I(l,"margin-inline-end","0"),I(l,"display","inline-block"),I(l,"width","1em"),I(l,"text-align","center"),I(l,"vertical-align","top"),I(l,"cursor","default"),I(l,"font-family","Menlo,sans-serif"),h.appendChild(l),I(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){I(h,"height","0px");let u=i.firstElementChild;u&&u.localName==="a"&&(u.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,r){if(this.page)return N(this.page);let s=M("showTOC"),o=new Cc(e,e);this.page=o;let a=Wt(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of fl(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),u=l.sizeViewport(i,1e5,r);t=new Os(t.window,u.fontSize,0,e,u.width,u.height);let d=this.makeCustomRenderer(h),p=new pl(l,h,this.lang,t,this.clientLayout,this.fontMapper,d,this.fallbackMap,0,this.documentURLTransformer,this.counterStore,this.cmykStore);this.instance=p,p.pref=this.pref,p.init().then(()=>{p.layoutNextPage(o,null).then(()=>{this.setAutoHeight(e,2),s.finish(o)})})}),s.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 r=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(r).map(t)}function t(n){let r=new URL(n.href),[,s]=r.hash.match(/^#?(.*)$/),o=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=e(a);return{id:s,title:o,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function n0(e){let t=e.target,i=t.textContent==nr;t.textContent=i?$h:nr;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let r=n.firstChild;for(;r;){if(r.nodeType===1){let s=r,o=s.getAttribute("data-adapt-class");if(o==="toc-container"){if(s.setAttribute("aria-hidden",i?"false":"true"),s.firstChild){r=s.firstChild;continue}}else if(o==="toc-node"&&(s.style.height=i?"auto":"0px",s.children.length>=2&&(s.children[1].tabIndex=i?0:-1),s.children.length>=3&&(s.children[0].tabIndex=i?0:-1,!i))){let a=s.children[0];if(a.textContent==$h){a.textContent=nr,a.setAttribute("aria-expanded","false"),s.setAttribute("aria-expanded","false"),r=s.children[2];continue}}}for(;!r.nextSibling&&r.parentNode!==n;)r=r.parentNode;r=r.nextSibling}e.stopPropagation()}function zr(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function r0(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=new Map(e[i])}),t}var Wh=class extends Qv{constructor(){super(null),c(this,"plainXMLStore"),c(this,"jsonStore"),c(this,"opfByURL",{}),c(this,"primaryOPFByEPubURL",{}),c(this,"deobfuscators",{}),c(this,"documents",{}),this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=Gv(),this.jsonStore=Gg()}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)}loadWebPubManifest(e,t){this.loadAsJSON(e,!0).then(i=>{if(!i){this.reportLoadError(e),t.finish(null);return}let n=new hs(this,e);n.initWithWebPubManifest(i,void 0,e).then(()=>{t.finish(n)})})}loadPubDoc(e){let t=M("loadPubDoc");if(/\.opf(?:[#?]|$)/i.test(e)){let[,i,n]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(i,n).thenFinish(t)}else/\.json(?:ld)?(?:[#?]|$)/i.test(e)?this.loadWebPubManifest(e,t):/\.(x?html?|xht)(?:[#?]|$)/i.test(e)?this.loadWebPub(e).then(i=>{if(i){t.finish(i);return}this.reportLoadError(e),t.finish(null)}):zs(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}W.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"){let[,n,r]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,r).thenFinish(t)}else i.contentType=="application/ld+json"||i.contentType=="application/webpub+json"||i.contentType=="application/audiobook+json"||i.contentType=="application/json"?this.loadWebPubManifest(e,t):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(r=>{if(r){t.finish(r);return}this.reportLoadError(e),t.finish(null)})})});return t.result()}loadEPUBDoc(e){let t=M("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 r=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let s of r)if(s){this.loadOPF(e,s).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 r=M("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(s=>{s?(n=new hs(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(s,o).then(()=>{r.finish(n)})}):n.initWithXMLDoc(s,null).then(()=>{r.finish(n)})):this.reportLoadError(i)}),r.result()}loadWebPub(e){let t=M("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e),t.finish(null);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,r=new hs(this,e),s=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(s){let o=s.getAttribute("href");if(/^#/.test(o)){let a=Ta(n.getElementById(o.substr(1)).textContent);r.initWithWebPubManifest(a,n).then(()=>{t.finish(r)})}else{let a=Ee(s.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{r.initWithWebPubManifest(h,n,a).then(()=>{t.finish(r)})})}}else r.initWithWebPubManifest({},n).then(()=>{r.toc&&r.toc.src===i.url&&fl(n).length===0&&(r.toc=null),t.finish(r)})}}),t.result()}addDocument(e,t){let i=M("EPUBDocStore.load"),n=Wt(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(Di)||Object.keys(this.resources).find(r=>this.resources[r]&&t(r)===n)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?W.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&Di.startsWith("https:")?W.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?W.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):W.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Wt(e),i=this.documents[t];if(i)return i.isPending()?i:N(i.get());{let n=M("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(r=>{r?n.finish(r):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 r=i.width-0,s=i.height-0;if(r&&s){let o=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${r}px;height:${s}px;}`+(o?`@page{size:${r}px ${s}px;margin:0;}`:"@page{margin:0;}")}return""}},Gh=class{constructor(){c(this,"id",null),c(this,"src",""),c(this,"mediaType",null),c(this,"title",null),c(this,"itemRefElement",null),c(this,"spineIndex",-1),c(this,"compressedSize",0),c(this,"compressed",null),c(this,"epage",0),c(this,"epageCount",0),c(this,"startPage",null),c(this,"skipPagesBefore",null),c(this,"itemProperties"),this.itemProperties=cf}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Ee(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=yf(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 s0(e){return e.id}function o0(e){return t=>{let i=M("deobfuscator");return a0("SHA-1",e).then(n=>{let r=t.slice(0,1040),s=t.slice(1040,t.size);Hg(r).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(hc([a,s]))})}),i.result()}}function a0(e,t){let i=M("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(r=>{n.schedule(new Uint8Array(r))}),i.result()}var pi={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"},qn="http://idpf.org/epub/vocab/package/meta/#",Ve={language:`${pi.dcterms}language`,title:`${pi.dcterms}title`,creator:`${pi.dcterms}creator`,layout:`${pi.rendition}layout`,titleType:`${qn}title-type`,displaySeq:`${qn}display-seq`,alternateScript:`${qn}alternate-script`,role:`${qn}role`};function l0(e,t){let i={};return(n,r)=>{var s,o,a,h,l,u;let d,p,f=n.r||i,g=r.r||i;if(e==Ve.title&&(d=((s=f[Ve.titleType])==null?void 0:s[0].v)=="main",p=((o=g[Ve.titleType])==null?void 0:o[0].v)=="main",d!=p))return d?-1:1;let m=parseInt((a=f[Ve.displaySeq])==null?void 0:a[0].v,10);isNaN(m)&&(m=Number.MAX_VALUE);let w=parseInt((h=g[Ve.displaySeq])==null?void 0:h[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),m!=w?m-w:e!=Ve.language&&t&&(d=((l=f[Ve.language]||f[Ve.alternateScript])==null?void 0:l[0].v)==t,p=((u=g[Ve.language]||g[Ve.alternateScript])==null?void 0:u[0].v)==t,d!=p)?d?-1:1:n.o-r.o}}function h0(e,t){let i;if(!t)i=pi;else{i={};for(let p in pi)i[p]=pi[p];let d;for(;(d=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(d[0].length),i[d[1]]=d[2]}let n=d=>{if(d){let p=d.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(p){let f=p[2]?i[p[2]]:qn;if(f)return f+p[3]}}return null},r=1,s=e.childElements().forEachNonNull(d=>{if(d.localName=="meta"){let p=n(d.getAttribute("property"));if(p)return{name:p,value:d.textContent,id:d.getAttribute("id"),order:r++,refines:d.getAttribute("refines"),lang:null,scheme:n(d.getAttribute("scheme")),role:null}}else if(d.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:pi.dcterms+d.localName,order:r++,lang:d.getAttribute("xml:lang"),value:d.textContent,id:d.getAttribute("id"),refines:null,scheme:null,role:d.getAttribute("role")||d.getAttribute("opf:role")};return null}),o=to(s,d=>d.refines),a=d=>bf(d,(p,f)=>p.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let w=o[`#${g.id}`]||[];if(w.length||g.lang||g.role){g.lang&&w.push({name:Ve.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&w.push({name:Ve.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let b=to(w,x=>x.name);m.r=a(b)}return m})),h=a(to(s,d=>d.refines?null:d.name)),l=null;h[Ve.language]&&(l=h[Ve.language][0].v);let u=d=>{for(let p in d){let f=d[p];f.sort(l0(p,l));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(h),h}function u0(){let e=window.MathJax;return e?e.Hub:null}var jh={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},vo="viv-id-",hs=class{constructor(e,t){this.store=e,this.pubURL=t,c(this,"opfXML",null),c(this,"encXML",null),c(this,"items",null),c(this,"spine",null),c(this,"itemMap",null),c(this,"itemMapByPath",null),c(this,"uid",null),c(this,"bindings",{}),c(this,"lang",null),c(this,"epageCount",0),c(this,"prePaginated",!1),c(this,"epageIsRenderedPage",!0),c(this,"epageCountCallback",null),c(this,"metadata",{}),c(this,"toc",null),c(this,"cover",null),c(this,"fallbackMap",{}),c(this,"pageProgression",null),c(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,r){let s=r+(n?`#${n}`:"");return vo+uu(s,":")}transformURL(n,r){let s=n.match(/^([^#]*)#?(.*)$/);if(s){let o=s[1]||r.replace(/\?viv-toc-box$/,""),a=decodeURIComponent(s[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(vo)===0&&(n=n.substring(vo.length));let r=wf(n,":").match(/^([^#]*)#?(.*)$/);return r?[r[1],r[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=Ee("",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 r={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new Gh,u=h;l.initWithElement(u,e.url);let d=u.getAttribute("fallback");return d&&!jh[l.mediaType]&&(r[l.src]=d),!this.toc&&l.itemProperties.nav&&(this.toc=l),!this.cover&&l.itemProperties["cover-image"]&&(this.cover=l),l}),this.itemMap=kl(this.items,s0),this.itemMapByPath=kl(this.items,h=>this.getPathFromURL(h.src));for(let h in r){let l=h;for(;;){let u=this.itemMap[r[l]];if(!u)break;if(jh[u.mediaType]){this.fallbackMap[h]=u.src;break}l=u.src}}this.spine=i.child("spine").child("itemref").asArray().map((h,l)=>{let u=h,d=u.getAttribute("idref"),p=this.itemMap[d];return p&&(p.itemRefElement=u,p.spineIndex=l),p});let s=i.child("spine").attribute("page-progression-direction")[0];s&&(this.pageProgression=iu(s));let o=t?t.doc().child("encryption").child("EncryptedData").predicate(Vh.withChild("EncryptionMethod",Vh.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"),u=a[h].getAttribute("media-type");u&&l&&this.itemMap[l]&&(this.bindings[u]=this.itemMap[l].src)}if(this.metadata=h0(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[Ve.language]&&(this.lang=this.metadata[Ve.language][0].v),this.metadata[Ve.layout]&&(this.prePaginated=this.metadata[Ve.layout][0].v==="pre-paginated"),o.length>0&&this.uid){let h=o0(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=M("countEPages");return n.loopWithFrame(r=>{if(i===this.spine.length){r.breakLoop();return}let s=this.spine[i++];s.epage=t,this.store.load(s.src).then(o=>{let a=1800,h=o.lang||this.lang;h&&h.match(/^(ja|ko|zh)/)&&(a/=3),s.epageCount=Math.ceil(o.getTotalOffset()/a),t+=s.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),r.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new Cp(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let r=new Gh;r.initWithParam(n),r.id;let s=i.document.createElement("itemref");s.setAttribute("idref",r.id),i.root.appendChild(s),r.itemRefElement=s,this.itemMap[r.id]=r;let o=this.getPathFromURL(n.url);o==null&&(o=n.url),this.itemMapByPath[o]=r,this.items.push(r)}),t?this.store.addDocument(e[0].url,t):N(null)}initWithWebPubManifest(e,t,i){var n,r,s,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[Ve.title]=(Array.isArray(a)?a:[a]).map(m=>{var w;return{v:(w=m.value)!=null?w:m}}));let h=e.author||e.creator||((r=e.metadata)==null?void 0:r.author)||Array.from((s=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?s:[]).map(m=>m.content);h&&h.length!==0&&(this.metadata[Ve.creator]=(Array.isArray(h)?h:[h]).map(m=>{var w;return{v:(w=m.name)!=null?w:m}}));let l=e.inLanguage||((o=e.metadata)==null?void 0:o.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[Ve.language]=(Array.isArray(l)?l:[l]).map(m=>({v:m})));let u=this.getPathFromURL(this.pubURL);if(!e.readingOrder&&t&&u!==null){e.readingOrder=[encodeURI(u)];for(let m of t0(t)){let w=m.getAttribute("href");if(/^(https?:)?\/\//.test(w)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(w))continue;let b=Wt(Ee(w,this.pubURL)),x=this.getPathFromURL(b),y=x!==null?encodeURI(x):b;e.readingOrder.indexOf(y)==-1&&e.readingOrder.push(y)}}let d=[],p=0,f=-1;[e.readingOrder,e.resources].forEach(m=>{m instanceof Array&&m.forEach(w=>{let b=m===e.readingOrder,x=typeof w=="string"?w:w.url||w.href,y=typeof w=="string"?"":w.encodingFormat||w.href&&w.type||"";if(b||y==="text/html"||y==="application/xhtml+xml"||!y&&w.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(x)){let P=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,S={url:Ee(pn(x),P),index:p++,startPage:null,skipPagesBefore:null};w.rel==="contents"&&f===-1&&(f=S.index),d.push(S)}})});let g=M("initWithWebPubManifest");return this.initWithChapters(d).then(()=>{var m,w;f!==-1&&(this.toc=this.items[f]),this.toc||(this.toc=i?(m=this.items)==null?void 0:m[0]:this.itemMapByPath[u]);let b=(w=e.readingOrder)==null?void 0:w.length;b&&b<this.items.length&&this.items.splice(b),g.finish(!0)}),g.result()}getCFI(e,t){let i=this.spine[e],n=M("getCFI");return this.store.load(i.src).then(r=>{let s=r.getNodeByOffset(t),o=null;if(s){let a=r.getNodeOffset(s,0,!1),h=t-a,l=new _l;l.prependPathFromNode(s,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),o=l.toString()}n.finish(o)}),n.result()}resolveFragment(e){return bn("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new _l;i.fromString(e);let n;if(this.opfXML){let r=i.navigate(this.opfXML.document);if(r.node.nodeType!=1||r.after||!r.ref){t.finish(null);return}let s=r.node,o=s.getAttribute("idref");if(s.localName!="itemref"||!o||!this.itemMap[o]){t.finish(null);return}n=this.itemMap[o],i=r.ref}else n=this.spine[0];this.store.load(n.src).then(r=>{let s=i.navigate(r.document),o=r.getNodeOffset(s.node,s.offset,s.after);t.finish({spineIndex:n.spineIndex,offsetInItem:o,pageIndex:-1})})},(t,i)=>{W.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return bn("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let r=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);r==-1&&(r=this.spine.length-1);let s=this.spine[r];(!s||s.epageCount==0)&&(s=this.spine[--r]);let o=Math.floor(e-s.epage);t.finish({spineIndex:r,offsetInItem:-1,pageIndex:o});return}let i=ni(this.spine.length,r=>{let s=this.spine[r];return s.epage+s.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(r=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let s=0;if(e>0){let o=r.getTotalOffset();s=Math.round(o*e/n.epageCount),s==o&&s--}t.finish({spineIndex:i,offsetInItem:s,pageIndex:-1})})},(t,i)=>{W.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=M("getEPage");return this.store.load(t.src).then(n=>{let r=n.getTotalOffset(),s=Math.min(r,e.offsetInItem);i.finish(t.epage+s*t.epageCount/r)}),i.result()}},Vr=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),c0=class{constructor(e,t,i,n,r,s){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=r,c(this,"spineItems",[]),c(this,"spineItemLoadingContinuations",[]),c(this,"pref"),c(this,"clientLayout"),c(this,"counterStore"),c(this,"cmykStore"),c(this,"tocAutohide",!1),c(this,"tocVisible",!1),c(this,"tocView"),c(this,"paginationProgress",{totalOffsetsBySpine:[],renderedOffsetsBySpine:[],lastReportedPages:0,lastReportedFraction:0}),this.pref=pu(n),this.clientLayout=new $v(t),this.counterStore=new cg(e.documentURLTransformer),this.cmykStore=new Uu,s!=null&&s.length&&this.cmykStore.registerCmykReserveMap(s)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}waitForPreviousSpines(e,t){if(t||e===0)return N(!0);let i=M("waitForPreviousSpines");return i.loopWithFrame(n=>{let r=!0;for(let s=0;s<e;s++){let o=this.spineItems[s];if(!o||!o.complete){r=!1;break}}r?n.breakLoop():i.sleep(100).then(()=>{n.continueLoop()})}).then(()=>{i.finish(!0)}),i.result()}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 r=this.opf.spine[e.item.spineIndex-1];e.item.epage=r.epage+r.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((r,s)=>r+s.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 r=null;if(i>0)r=e.pages[i-1].container.nextElementSibling;else for(let s=e.item.spineIndex+1;s<this.spineItems.length;s++){let o=this.spineItems[s];if(o&&o.pages[0]){r=o.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,r)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}getRenderedPageCount(){let e=0;for(let t of this.spineItems)t&&(e+=t.pages.length);return e}markSpineItemCompleteIfReady(e){e.complete=e.layoutPositions.length===e.pages.length,e.complete&&e.instance.viewport.layoutBox.removeAttribute("style")}getTotalOffsetForViewItem(e){let t=e.item.spineIndex,i=this.paginationProgress.totalOffsetsBySpine[t];return i==null&&(i=e.xmldoc.getTotalOffset(),this.paginationProgress.totalOffsetsBySpine[t]=i),i}getTotalOffsetAll(){let e=0;for(let t of this.spineItems)t&&(e+=this.getTotalOffsetForViewItem(t));return e}getRenderedOffsetAll(){var e;let t=0,i=this.paginationProgress.totalOffsetsBySpine,n=this.paginationProgress.renderedOffsetsBySpine;for(let r=0;r<i.length;r++){let s=i[r];if(!s)continue;let o=(e=n[r])!=null?e:0;t+=Math.min(s,o)}return t}reportPaginationProgress(e,t){let i=Ft("PAGINATION_PROGRESS");if(!i.length)return;let n=e.item.spineIndex,r=this.getTotalOffsetForViewItem(e),s=r;t&&(s=e.instance.getPosition(t,!0)),s<0&&(s=0),s>r&&(s=r);let o=this.paginationProgress.renderedOffsetsBySpine[n];o!=null&&s<o&&(s=o),this.paginationProgress.renderedOffsetsBySpine[n]=s;let a=this.getRenderedPageCount(),h=this.getTotalOffsetAll(),l=this.getRenderedOffsetAll(),u=h>0?l/h:0;u<this.paginationProgress.lastReportedFraction?u=this.paginationProgress.lastReportedFraction:this.paginationProgress.lastReportedFraction=u,a>this.paginationProgress.lastReportedPages&&(this.paginationProgress.lastReportedPages=a);let d={fraction:u,pages:this.paginationProgress.lastReportedPages};for(let p of i)try{p(d)}catch(f){W.warn(f)}}isInCounterResolveScope(){return this.counterStore.currentPageCountersStack.length>0}hasNonEmptyPageType(e){return!!(e!=null&&e.pageType)&&e.pageType!==""}hasPageTypeBoundaryBetween(e,t){return e?.pageType!=null&&t?.pageType!=null&&e.pageType!==t.pageType}resolvePageTypeForRenderSlot(e,t,i,n,r,s,o){let a=!1;if(n){let h=this.hasPageTypeBoundaryBetween(r,n),l=s?.pageType===n.pageType,u=n.offset!==t.offset,d=o&&!u&&i>0&&h&&l;if(a=n.pageType!=null&&(d||i===0||n.pageType===r?.pageType),t.pageType=a?n.pageType:null,!o&&!a){let p=i>1&&h&&l?r.pageType:null;e.instance.styler.cascade.currentPageType=p,e.instance.pageManager.pageCascadeInstance.currentPageType=p}}!o&&this.hasNonEmptyPageType(r)&&this.hasNonEmptyPageType(s)&&r.pageType!==s.pageType&&(!n||n.pageType==null)&&(t.pageType=r.pageType)}evaluateNextPageRelayout(e,t,i,n,r){if(!e||t&&!i)return{needsRelayout:!1,shouldCascade:!1};let s=!!t&&(e.pageType===t.pageType||!t.pageType);return t&&n&&(!r||s)&&(t.pageType==null||e.pageType==null||e.pageType!==t.pageType)&&(t.pageType=null),{needsRelayout:!0,shouldCascade:!!t||!r}}preparePageCountersForRender(e,t){let i=e.pages[t],n=e.pageCounterStarts[t];i&&n&&(this.counterStore.currentPageCounters=zr(n));let r=zr(this.counterStore.currentPageCounters);return(!n||!i)&&(e.pageCounterStarts[t]=r),i}maybeRelayoutFollowingPage(e,t,i,n){if(!t)return N(!0);let r=e.layoutPositions[t.page];e.layoutPositions[t.page]=t;let s=e.pages[t.page],o=!!i&&n.offset!==i.offset,a=!r||!t.isSamePosition(r)||t.highestSeenOffset!==r.highestSeenOffset||o,h=this.isInCounterResolveScope(),l=this.evaluateNextPageRelayout(i,s,a,o,h);return l.needsRelayout?(e.complete=!1,l.shouldCascade?this.renderSinglePage(e,t):N(!0)):N(!0)}resolveUnresolvedReferencesForPage(e,t,i,n){let r=M("resolveUnresolvedReferencesForPage"),s=this.isInCounterResolveScope()?[]:this.counterStore.getUnresolvedRefsToPage(t),o=0,a=t;return r.loopWithFrame(h=>{if(o++,o>s.length){h.breakLoop();return}let l=s[o-1];if(l.refs=l.refs.filter(u=>!u.isResolved()),l.refs.length===0){h.continueLoop();return}this.getPageViewItem(l.spineIndex).then(u=>{if(!u){h.continueLoop();return}let d=u.instance.styler.cascade,p=u.instance.pageManager.pageCascadeInstance,f={currentPageType:d.currentPageType,previousPageType:d.previousPageType},g={currentPageType:p.currentPageType,previousPageType:p.previousPageType},m=r0(u.instance.pageGroupPageCounts),w=u.instance.currentPageGroupDocument,b=u.instance.scopes;u.instance.scopes={};let x=l.pageIndex<u.pages.length-1,y=!!u.pages[l.pageIndex]&&x,P=y?u.instance.beginIsolatedRootPageFloatLayoutContext():null;this.counterStore.pushPageCounters(l.pageCounters),this.counterStore.pushReferencesToSolve(l.refs);let S=u.layoutPositions[l.pageIndex];this.renderSinglePage(u,S).then(R=>{y&&u.instance.endIsolatedRootPageFloatLayoutContext(P);let A=d.currentPageType;d.currentPageType=f.currentPageType,d.previousPageType=f.previousPageType,p.currentPageType=g.currentPageType,p.previousPageType=g.previousPageType,u.instance.pageGroupPageCounts=m,u.instance.currentPageGroupDocument=w,u.instance.scopes=b;let U=zr(this.counterStore.currentPageCounters);this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve(),R.pageAndPosition.position.spineIndex===a.spineIndex&&R.pageAndPosition.position.pageIndex===i&&(a=R.pageAndPosition.page),a.pageType&&a.pageType!==f.currentPageType&&A!==R.pageAndPosition.page.pageType&&(d.currentPageType=a.pageType);let G=u!==e,Z=u.pages.length,fe=u.layoutPositions[Z],ue=u.instance.hasActiveRootPageFloatLayoutContext();if(fe&&!ue){let C=G?zr(this.counterStore.currentPageCounters):null;G&&(this.counterStore.currentPageCounters=U);let _=Z;this.renderSinglePage(u,fe).then(()=>{G&&this.markSpineItemCompleteIfReady(u);let k=u.pages.length-_;if(G&&k>0){this.counterStore.adjustPageCountersOfLaterSpines(u.item.spineIndex,k),this.counterStore.updateTargetCounterNodesInPages(u.pages);let O=u.item.spineIndex;for(let E=O+1;E<this.spineItems.length;E++){let T=this.spineItems[E];if(T){T.item.epage+=k;for(let L of T.pageCounterStarts)L!=null&&L.page&&(L.page=L.page.map(z=>z+k));this.counterStore.updatePageCounterNodesInPages(T.pages,T.pageCounterStarts)}}if(C){let E=C.page;E&&(C.page=E.map(T=>T+k))}}C&&(this.counterStore.currentPageCounters=C),h.continueLoop()});return}G&&this.markSpineItemCompleteIfReady(u),h.continueLoop()})})}).then(()=>{a.container.parentElement||(a=e.pages[i]),a.isLastPage=!n&&e.item.spineIndex===this.opf.spine.length-1,a.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),a.container.setAttribute("data-vivliostyle-page-index",i),a.container.setAttribute("data-vivliostyle-spine-index",a.spineIndex),r.finish(a)}),r.result()}renderSinglePage(e,t){let i=M("renderSinglePage"),n=t?Math.max(t.page,0):0,r=this.isInCounterResolveScope(),s=this.preparePageCountersForRender(e,n),o=n>0?e.pages[n-1]:null,a=e.pages[n+1],h=this.makePage(e,t);return this.resolvePageTypeForRenderSlot(e,h,n,s,o,a,r),e.instance.layoutNextPage(h,t).then(l=>{t=l;let u=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,h,u),this.counterStore.finishPage(h.spineIndex,u),this.reportPaginationProgress(e,t),this.maybeRelayoutFollowingPage(e,t,s,h).thenAsync(()=>this.resolveUnresolvedReferencesForPage(e,h,u,t)).then(d=>{i.finish({pageAndPosition:Vr(d,u),nextLayoutPosition:t})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let r=ni(t.layoutPositions.length,s=>t.instance.getPosition(t.layoutPositions[s],!0)>n);r===t.layoutPositions.length?t.complete?i=t.pages.length-1:i=Number.POSITIVE_INFINITY:i=r-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=M("findPage");return this.waitForPreviousSpines(e.spineIndex,t).then(()=>{this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let r=null,s;i.loopWithFrame(o=>{let a=this.normalizeSeekPosition(e,n);s=a.pageIndex,r=n.pages[s],r?o.breakLoop():n.complete?(s=n.pages.length-1,r=n.pages[s],o.breakLoop()):t?this.renderPage(a).then(h=>{h&&(r=h.page,s=h.position.pageIndex),o.breakLoop()}):s<n.layoutPositions.length&&!n.pages[s]?this.renderPage(a).then(h=>{h&&(r=h.page,s=h.position.pageIndex),o.breakLoop()}):i.sleep(100).then(()=>{o.continueLoop()})}).then(()=>{i.finish(Vr(r,s))})})}),i.result()}renderPage(e){let t=M("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),r=n.pageIndex,s=n.offsetInItem,o=i.pages[r];if(o){t.finish(Vr(o,r));return}t.loopWithFrame(a=>{if(r<i.layoutPositions.length){a.breakLoop();return}if(i.complete){r=i.pages.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let u=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(s>=0&&i.instance.getPosition(h)>s){o=u,r=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else o=u,r=l.pageAndPosition.position.pageIndex,this.markSpineItemCompleteIfReady(i),a.breakLoop()})}).then(()=>{o=o||i.pages[r];let a=i.layoutPositions[r];if(o){t.finish(Vr(o,r));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||this.markSpineItemCompleteIfReady(i),t.finish(h.pageAndPosition)})})}),t.result()}renderAllPages(){let e=M("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(r=>r?.fetchers.some(s=>!s.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=M("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,r=e.pageIndex,s=0;t&&(s=n);let o;return i.loopWithFrame(a=>{let h={spineIndex:s,pageIndex:s===n?r:Number.POSITIVE_INFINITY,offsetInItem:s===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{o=l,++s>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,r=M("nextPage");return this.getPageViewItem(i).then(s=>{if(!s){r.finish(null);return}if(s.complete&&n==s.pages.length-1){if(i>=this.opf.spine.length-1){r.finish(null);return}i++,n=0;let o=this.spineItems[i],a=o&&o.pages[0],h=s.pages[s.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(r)}),r.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=M("getSpread"),r=i.side==="left",s;return this.isRectoPage(i,e)?s=this.previousPage(e,t):s=this.nextPage(e,t),s.then(o=>{let a=this.getPage(e),h=o&&o.page;h&&h.side===a.side&&(h=null),r?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),r=this.nextPage(e,t);return n?r:r.thenAsync(s=>{if(s){if(s.page.side===i.side)return r;let o=this.nextPage(s.position,t);return o.thenAsync(a=>a?o:r)}else return N(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),r=this.previousPage(e,t),s=i.container.previousElementSibling;return n?r.thenAsync(o=>o?o.page.side===i.side||o.page.container!==s?r:this.previousPage(o.position,t):N(null)):r}navigateToEPage(e,t,i){let n=M("navigateToEPage");return this.opf.resolveEPage(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(e,t,i){let n=M("navigateToCFI");return this.opf.resolveFragment(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}resolveSemanticFootnoteNavigationOffset(e,t){if(!dn(t))return null;let i=t.getAttribute("id");if(!i)return null;let n=Ee(`#${i}`,e.xmldoc.url),r=e.xmldoc.document.getElementsByTagName("a");for(let s=0;s<r.length;s++){let o=r.item(s);if(!ir(o))continue;let a=o.getAttribute("href")||o.getAttributeNS("http://www.w3.org/1999/xlink","href");if(a&&Ee(a,e.xmldoc.url)===n)return e.xmldoc.getElementOffset(o)}return null}navigateTo(e,t,i){W.debug("Navigate to",e);let n=this.opf.getPathFromURL(Wt(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 r=this.opf.itemMapByPath[n];if(!r){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 s=M("navigateTo");return this.waitForPreviousSpines(r.spineIndex,i).then(()=>{this.getPageViewItem(r.spineIndex).then(o=>{if(!o){s.finish(null);return}let a=o.xmldoc.getElement(e),h=a&&this.resolveSemanticFootnoteNavigationOffset(o,a),l=h??(a?o.xmldoc.getElementOffset(a):0);this.findPage({spineIndex:r.spineIndex,pageIndex:-1,offsetInItem:l},i).thenFinish(s)})}),s.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",rr||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let r=i.document.createElement("div");r.setAttribute("data-vivliostyle-bleed-box","true"),r.role="presentation",n.appendChild(r);let s=new Cc(n,r);if(s.spineIndex=e.item.spineIndex,s.position=t,s.offset=e.instance.getPosition(t),s.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let o=this.opf.documentURLTransformer.transformFragment("",e.item.src);r.setAttribute("id",o),s.registerElementWithId(r,o)}if(i!==this.viewport){let o=fu(this.viewport.width,this.viewport.height,i.width,i.height),a=vr(null,new Xt(o,null),"");s.delayedItems.push(new Ua(n,"transform",a))}return s}makeObjectView(e,t,i,n){let r=t.getAttribute("data"),s=null;if(r){r=Ee(r,e.url);let o=t.getAttribute("media-type");if(!o){let a=this.opf.getPathFromURL(r);if(a){let h=this.opf.itemMapByPath[a];h&&(o=h.mediaType)}}if(o){let a=this.opf.bindings[o];if(a){s=this.viewport.document.createElement("iframe"),s.style.border="none";let h=Sl(r),l=Sl(o),u=new ii;u.append(a),u.append("?src="),u.append(h),u.append("&type="),u.append(l);for(let f=t.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let g=f;if(g.localName=="param"&&g.namespaceURI=="http://www.w3.org/1999/xhtml"){let m=g.getAttribute("name"),w=g.getAttribute("value");m&&w&&(u.append("&"),u.append(encodeURIComponent(m)),u.append("="),u.append(encodeURIComponent(w)))}}s.setAttribute("src",u.toString());let d=t.getAttribute("width");d&&s.setAttribute("width",d);let p=t.getAttribute("height");p&&s.setAttribute("height",p)}}}return s||(s=this.viewport.document.createElement("object"),r&&s.setAttribute("data",r),s.setAttribute("data-adapt-process-children","true")),N(s)}makeMathJaxView(e,t,i,n){let r=u0();if(r){let s=i.ownerDocument,o=s.createElement("span");i.appendChild(o);let a=s.importNode(t,!0);this.resolveURLsInMathML(a,e),o.appendChild(a);let h=r.queue;h.Push(["Typeset",r,o]);let l=M("makeMathJaxView"),u=l.suspend();return h.Push(()=>{u.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 r=Ee(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,r):e.setAttribute(n.name,r)}}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=M("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let o=i.suspend();return n.push(o),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let r=this.opf.spine[e],s=this.opf.store;return s.load(r.src).then(o=>{var a;let h=r.itemRefElement.getAttribute("properties");h&&o.root.setAttribute("data-vivliostyle-epub-spine-properties",h),r.title=o.document.title;let l=s.getStyleForDoc(o),u=this.makeCustomRenderer(o),d=this.viewport,p=l.sizeViewport(d.width,d.height,d.fontSize,this.pref);(p.width!=d.width||p.height!=d.height||p.fontSize!=d.fontSize)&&(d=new Os(d.window,p.fontSize,d.pixelRatio,d.root,p.width,p.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,g=this.spineItems[e-1],m,w;if(r.startPage!==null)m=r.startPage-1,w=m;else{if(e>0&&(!g||!g.complete))m=r.epage||e,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,w=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let y=g&&g.pageCounterStarts[g.pages.length-1],P=y&&y.page;if(P&&P.length)w=P[P.length-1]+1;else{let S=this.counterStore.currentPageCounters.page;w=!S||!S.length?m:S[S.length-1]}}r.skipPagesBefore!==null&&(m+=r.skipPagesBefore,w+=r.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let b=new pl(l,o,this.opf.lang,d,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,m,this.opf.documentURLTransformer,this.counterStore,this.cmykStore,this.opf.pageProgression,f);b.pref=this.pref;let x=this.opf.metadata&&this.opf.metadata[Ve.title];b.pubTitle=x&&x[0]&&x[0].v||"",b.docTitle=r.title||"",b.init().then(()=>{!this.opf.pageProgression&&b.pageProgression&&(this.opf.pageProgression=b.pageProgression),t={item:r,xmldoc:o,instance:b,layoutPositions:[null],pages:[],complete:!1,pageCounterStarts:[]},this.spineItems[e]=t,i.finish(t),n.forEach(y=>{y.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=M("showTOC");this.tocView||(this.tocView=new i0(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore,this.cmykStore));let r=this.viewport,s=Math.min(344,Math.round(.67*r.width)-16),o=r.height-6,a=r.document.createElement("div");return r.root.appendChild(a),rr||(a.style.visibility="hidden"),a.style.width=`${s+16}px`,a.style.maxHeight=`${o}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,r,s,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()}},Xh="data-vivliostyle-viewer-status",d0="data-vivliostyle-spread-view",Np=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(Np||{}),p0=class{constructor(e,t,i,n){this.window=e,this.viewportElement=t,this.instanceId=i,this.callbackFn=n,c(this,"fontMapper"),c(this,"kick"),c(this,"sendCommand"),c(this,"resizeListener"),c(this,"hyperlinkListener"),c(this,"pageRuleStyleElement"),c(this,"pageSheetSizeAlreadySet",!1),c(this,"renderTask",null),c(this,"actions"),c(this,"readyState"),c(this,"packageURL"),c(this,"opf"),c(this,"touchActive"),c(this,"touchX"),c(this,"touchY"),c(this,"needResize"),c(this,"resized"),c(this,"needRefresh"),c(this,"viewportSize"),c(this,"currentPage"),c(this,"currentSpread"),c(this,"pagePosition"),c(this,"fontSize"),c(this,"zoom"),c(this,"fitToScreen"),c(this,"pageViewMode"),c(this,"waitForLoading"),c(this,"renderAllPages"),c(this,"pref"),c(this,"pageSizes"),c(this,"pixelRatio"),c(this,"pixelRatioLimit"),c(this,"viewport"),c(this,"opfView"),c(this,"cmykReserveMap"),c(this,"cmykReserveMapUrl");let r=t.ownerDocument,s=(o,a)=>{let h=r.getElementById(o);return h||(h=r.createElement("style"),h.id=o,a&&(h.textContent=a),r.head.appendChild(h)),h};s("vivliostyle-viewport-screen-css",ec),s("vivliostyle-viewport-css",tc),s("vivliostyle-polyfill-css",ac),t.setAttribute("data-vivliostyle-viewer-viewport",!0),rr&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(Xh,"loading"),this.fontMapper=new Zb(r.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=s("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=du(),this.pageSizes=[],this.pixelRatioLimit=Na==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=su;W.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),W.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),W.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),W.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){if(this.readyState!==e){this.readyState=e,this.viewportElement.setAttribute(Xh,e);let t=this.getCurrentPageProgression();t&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",t),this.callback({t:"readystatechange"})}}loadPublication(e){wt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,r=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let s=M("loadPublication");return this.configure(e).then(()=>{let o=new Wh;o.init(n,r).then(()=>{let a=Ee(pn(t),this.window.location.href);this.packageURL=[a],o.loadPubDoc(a).then(h=>{h?(this.opf=h,this.loadCmykReserveMap(o).then(()=>{this.render(i).then(()=>{s.finish(!0)})})):s.finish(!1)})})}),s.result()}loadXML(e){wt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,r=e.authorStyleSheet,s=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let o=M("loadXML");return this.configure(e).then(()=>{let a=new Wh;a.init(r,s).then(()=>{let h=t.map((l,u)=>({url:Ee(pn(l.url),this.window.location.href),index:u,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new hs(a,""),this.opf.initWithChapters(h,i).then(()=>{this.loadCmykReserveMap(a).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(()=>(wt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let r=n[0];if(r==="em"||r==="rem")return t*this.fontSize;let s=_t[r];if(s)return t*s}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"&&(bl(e.userAgentRootURL.replace(/resources\/?$/,"")),vl(e.userAgentRootURL)),typeof e.rootURL=="string"&&(bl(e.rootURL),vl(`${Di}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!==si&&(Fv(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){Ft("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=>{I(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),I(e.container,"visibility","visible"),I(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=M("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?vn(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 Os(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new Os(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!=null&&(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(d0,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 r=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:!r&&t.width==this.viewport.width&&t.height==this.viewport.height||!r&&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,r;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((r=this.pageSizes[i-1])==null?void 0:r.height))){let o=function(g){let m=g*.75;return Math.ceil(m)};var s=o;let a=Math.max(...this.pageSizes.map(g=>g.width)),h=Math.max(...this.pageSizes.map(g=>g.height)),l=o(a),u=o(h),d=l*((this.pixelRatio||1)-1)+2,p=u*((this.pixelRatio||1)-1)+2,f=`@page {size: ${l}pt ${u}pt; margin: 0 ${-d}pt ${-p}pt 0;}`;this.pageRuleStyleElement.textContent=f,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}loadCmykReserveMap(e){if(!this.cmykReserveMapUrl)return this.cmykReserveMap=void 0,N(!0);let t=Ee(pn(this.cmykReserveMapUrl),Di),i=M("loadCmykReserveMap");return e.loadAsJSON(t).then(n=>{Vf(n)?this.cmykReserveMap=n:(W.warn("Invalid cmykReserveMap data, ignoring"),this.cmykReserveMap=void 0),i.finish(!0)}),i.result()}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 c0(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this),this.cmykReserveMap),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){var t;let i=this.getAdjustedZoomFactor(e.dimensions);(t=this.viewport)==null||t.zoom(e.dimensions.width,e.dimensions.height,i)}setSpreadZoom(e){var t;let i=this.getSpreadDimensions(e);(t=this.viewport)==null||t.zoom(i.width,i.height,this.getAdjustedZoomFactor(i))}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 qh),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return N(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Fo().getScheduler().run(()=>bn("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,wt.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 r={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.isLastPageForNotification(this.currentPage),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)&&(r.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(r)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():N(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),wt.registerEndTiming("render (resize)"),si&&Sp(this.window)?Mv(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 qh)wt.registerEndTiming("render (resize)"),W.debug(i.message);else throw i}));return N(!0)}sendLocationNotification(e,t){let i=M("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:this.isLastPageForNotification(e),metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(r=>{n.epage=r,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}isLastPageForNotification(e){if(!this.opfView||!this.pagePosition)return e.isLastPage;let t=this.opfView.spineItems[this.pagePosition.spineIndex];if(!t||!t.complete)return!1;let i=t.item.spineIndex===this.opf.spine.length-1,n=this.pagePosition.pageIndex===t.pages.length-1;return i&&n}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 r;switch(e.where){case"next":r=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":r=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":r=this.opfView.lastPage;break;case"first":r=this.opfView.firstPage;break;default:return N(!0)}r&&(i=()=>r.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let r=e.epage;i=()=>this.opfView.navigateToEPage(r,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let r=e.url;i=()=>this.opfView.navigateTo(r,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let r=e.position;i=()=>this.opfView.findPage(r,!this.renderAllPages)}else return N(!0);if(!this.opfView)return N(!0);let n=M("moveTo");return i.call(this.opfView).then(r=>{let s;if(r){this.pagePosition=r.position;let o=M("moveTo.showCurrent");s=o.result(),this.showCurrent(r.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(o)})}else s=N(!0);s.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(),r=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!r)return N(!0)}else if(i=="hide")return N(!0);if(n&&i!="show")return this.opfView.hideTOC(),N(!0);{let s=M("showTOC");return this.opfView.showTOC(t).then(o=>{if(o){if(r&&(o.listeners={}),t){let a=()=>{this.opfView.hideTOC()};o.addEventListener("hyperlink",a,!1)}o.addEventListener("hyperlink",this.hyperlinkListener,!1)}s.finish(!0)}),s.result()}}runCommand(e){let t=e.a||"";return bn("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(W.error("No such action:",t),i.finish(!0))},(i,n)=>{W.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=Yh(e),i=null,n=this;Mg(()=>{let r=M("commandLoop"),s=Fo().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};s.run(()=>(n.callback(l),N(!0)))}},r.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=M("waitForCommand");i=a.suspend(this),a.result().then(()=>{o.continueLoop()})}}).thenFinish(r),r.result()}),n.kick=()=>{let r=i;r&&(i=null,r.schedule(!0))},n.sendCommand=r=>t?!1:(t=Yh(r),n.kick(),!0),this.window.adapt_command=n.sendCommand}},Tp=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(Tp||{}),qh=class Ip extends Error{constructor(){super(),c(this,"name","RenderingCanceledError"),c(this,"message","Page rendering has been canceled"),c(this,"stack"),Object.setPrototypeOf(this,Ip.prototype),this.stack=new Error().stack}};function Yh(e){return typeof e=="string"?Ta(e):e}var Zh=Pa;function f0(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function Kh(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 Ap=class{constructor(e,t){this.settings=e,c(this,"initialized",!1),c(this,"adaptViewer_"),c(this,"options"),c(this,"eventTarget"),c(this,"readyState"),tu(e.debug),this.adaptViewer_=new p0(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=f0(),t&&this.setOptions(t),this.eventTarget=new Ia,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},Kh(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 r=i||{};function s(l){if(l)return l.map(u=>({url:u.url||null,text:u.text||null}))}let o=s(r.authorStyleSheet),a=s(r.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:g0(e)||t,document:r.documentObject,fragment:r.fragment,authorStyleSheet:o,userStyleSheet:a,cmykReserveMapUrl:r.cmykReserveMapUrl},Kh(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()===Zh.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Zh.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}getCmykMap(){var e;let t=(e=this.adaptViewer_)==null?void 0:e.opfView;return t!=null&&t.cmykStore?t.cmykStore.toJSON():{}}};function g0(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 Rp=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(Rp||{}),m0=Tp,w0=Np;wt.forceRegisterEndTiming("load_vivliostyle");var y0=class{constructor(e,{title:t="",printCallback:i=o=>o.print(),errorCallback:n=null,hideIframe:r=!0,removeIframe:s=!0}){c(this,"htmlDoc"),c(this,"title"),c(this,"printCallback"),c(this,"errorCallback"),c(this,"hideIframe"),c(this,"removeIframe"),c(this,"iframe"),c(this,"iframeWin"),c(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=r,this.removeIframe=s}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=`
1873
+ `),i.toString()}},f0=class{constructor(e){this.deobfuscator=e,c(this,"familyMap",{})}registerFamily(e,t){let i=e.family,n=this.familyMap[i],r=t.family;if(n){if(n!=r)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${e.family}`)}else this.familyMap[i]=r}filterFontFamily(e){if(e instanceof it){let t=e.values,i=[];for(let n of t){let r=this.familyMap[n.stringValue()];r&&i.push(M(r)),i.push(n)}return new it(i)}else{let t=this.familyMap[e.stringValue()];return t?new it([M(t),e]):e}}},g0=class{constructor(e,t,i){this.head=e,this.body=t,c(this,"srcURLMap",{}),c(this,"familyPrefix"),c(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=D("initFont"),r=e.src,o={};for(let l of Pl(e.properties))o[l]=e.properties[l];let s=this.getViewFontFamily(e,i);o["font-family"]=M(s);let a=new Yp(o),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(r,t),this.head.appendChild(h),j.debug("Load font:",r),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i+";"+e.fontTraitKey,r=this.srcURLMap[n];return r?r.piggyback(o=>{t.registerFamily(e,o),j.debug("Found already-loaded font:",i)}):(r=new Ar(()=>{let o=D("loadFont"),s=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(s):null;return a?es(s,"blob").then(h=>{if(!h.responseBlob){o.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(e,l,t).thenFinish(o)})}):this.initFont(e,null,t).thenFinish(o),o.result()},`loadFont ${i}`),this.srcURLMap[n]=r,r.start()),r}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){j.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return En(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(r=>{}))}),t===0)return T(!0);let i=D("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?T(!0):T(!1))).thenFinish(i),i.result()}},hi=!0;function m0(e){hi=e}var Vi=[];function iu(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Zp(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 Nl(e,t,i){if(!hi||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Zp(e.ownerDocument).includes(e))return T(!1);let n=e.textContent,r=e.src,o=e.type==="module",s=r&&r.includes("/MathJax.js");if(s){if(t.document.head.querySelector("script[src*='/MathJax.js']"))return T(!0);t.MathJax||(t.MathJax={MathML:{extensions:["content-mathml.js"]},showProcessingMessages:!1,messageStyle:"none",skipStartupTypeset:!0,CommonHTML:{linebreaks:{automatic:!0}},"fast-preview":{disabled:!0},AuthorInit:function(){t.MathJax.Hub.processSectionDelay=0}})}let a=(o||r)&&e.async&&!s,h=(o&&!a||r&&e.defer)&&!s,l=!(i!=null&&i.atEnd)&&(i?.forceDefer||h||a);if(Kp(t)||(t.onload=null),l)return Vi.some(d=>iu(d,e))||Vi.push(e),T(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&iu(d,e)&&t.document.head.removeChild(d);let u=t.document.createElement("script");u.textContent=n,r&&(u.src=r),u.async=a,u.defer=h,u.setAttribute("data-vivliostyle-scripting","true");for(let d of e.attributes)["src","async","defer"].includes(d.name)||u.setAttribute(d.name,d.value);if(j.debug("script:",r),r){let d=vt(u);return t.document.head.appendChild(u),En([d])}else return t.document.head.appendChild(u),T(!0)}function w0(e,t){var i;let n={},r=s=>{var a;let h=(a=s["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let u of h.values)n[u.stringValue()]=!0;else n[h.stringValue()]=!0;let l=s._marginBoxes;if(l)for(let u of Object.values(l))r(u)},o=s=>{if(s instanceof ml)r(s.style);else if(s instanceof Bn||Array.isArray(s))for(let a of Object.values(s))o(a)};for(let s of Object.values(t.cascade.code))for(let a of Object.values(s??{}))o(a);for(let s of e.querySelectorAll("[style]"))(i=s.style)!=null&&i.fontFamily&&(n[s.style.fontFamily]=!0);return Object.keys(n).join(",")}function y0(e,t,i){var n;let r=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return r.style.position="fixed",r.style.fontSize="0",r.setAttribute("data-vivliostyle-textcontent","true"),r.setAttribute("aria-hidden","true"),r.style.fontFamily=w0(e,i),r.textContent=e.documentElement.textContent,t.document.body.appendChild(r),r}function v0(e,t,i){if(!hi)return T(!1);let n=Zp(e);if(n.length===0)return T(!1);let r=n.some(u=>!(u.async||u.defer||u.type==="module")),o=r?y0(e,t,i):null,s=t.document.fonts,a=t.$,h=!1,l=D("loadScripts");return l.loop(()=>{if(n.length===0)return r?l.sleep(20).thenAsync(()=>{var d,p;return s.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(d=t.FontJSON)!=null&&d.Font&&(p=t.ret)!=null&&p.readyState&&t.ret.readyState<4?T(!0):T(!1)}):T(!1);let u=n.shift();return Nl(u,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(Vi.push(u),h=!0),n.length===0&&r&&(j.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),T(!0)))}).then(()=>{o&&o.remove(),l.finish(!0)}),l.result()}function b0(e){if(!hi)return T(!1);let t=D("loadScripts");return t.loop(()=>Vi.length===0?T(!1):Nl(Vi.shift(),e,{atEnd:!0}).thenReturn(Vi.length>0)).then(()=>{j.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),j.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Kp(e){return hi?Vi.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var x0=e=>String(e).replace(/[\u0000-\u001F"\\\u2028\u2029]/g,Xa),S0=e=>`"${x0(e)}"`,Bs=(e,t,i)=>S0(i.transformURL(pi(String(e)),t)),C0=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,r)=>`url(${Bs(r,t,i)}`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,r)=>`url(${Bs(r,t,i)}`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,r)=>`url(${Bs(r,t,i)}`),k0={},E0=new Set(["base","body","head","html","link","meta","script","style","title"]);function P0(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 Ma=class Qn extends qa{constructor(t,i,n,r,o,s,a,h,l,u,d,p,f,g,m,w=new Map,x={value:!1}){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=r,this.regionIds=o,this.xmldoc=s,this.docFaces=a,this.footnoteStyle=h,this.stylerProducer=l,this.page=u,this.customRenderer=d,this.fallbackMap=p,this.documentURLTransformer=f,this.pageProps=g,this.cascadedPageStyle=m,this.semanticFootnoteFirstRefOffsets=w,this.semanticFootnoteFirstRefOffsetsInitialized=x,c(this,"document"),c(this,"exprContentListener"),c(this,"computedStyleParentFontSizeOverride",null),c(this,"computedStyleParentLineHeightOverride",null),c(this,"nodeContext",null),c(this,"viewRoot",null),c(this,"isFootnote",!1),c(this,"sourceNode",null),c(this,"offsetInNode",0),c(this,"viewNode",null),this.document=n.document,this.exprContentListener=r.counterListener.getExprContentListener()}clone(){return new Qn(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,this.pageProps,this.cascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)}syncSemanticFootnoteCounterToTarget(t){if(t.localName!=="a"||!_t(t)||!Nh(t,this.xmldoc.url,r=>this.xmldoc.getElementOffset(r),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized))return;let i=t.getAttribute(rr);if(!i)return;let n=Td(t,this.xmldoc.url,r=>this.xmldoc.getElement(r));n&&n.setAttribute(rr,i)}createPseudoelementShadow(t,i,n,r,o,s,a,h){var l,u;let d=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,s);if(!d)return h;let p=[],f=qn.createElementNS("http://www.pyroxy.com/ns/shadow","root"),g=f,m=_t(t)&&!!d["footnote-call"]&&kt((l=d["footnote-call"].content)==null?void 0:l.value);for(let y of wv){let b;if(y){if(!d[y])continue;let S=bt(t),C=t.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&t.localName==="include"&&t.classList.contains("-vivliostyle-footnote-content");if(y=="footnote-call"&&!_t(t)||y=="footnote-marker"&&!(S||C||i&&this.isFootnote)&&!((u=this.nodeContext)!=null&&u.pluginProps.nestedFootnoteDetached))continue;if(y.match(/^first-/)){let N=r.display;if(!N||N===v.inline)continue;let F=t.firstElementChild;if(F&&Le(F.previousSibling)){let B=o.getStyle(F,!1);if(B){let U=me(B,"display");if(U!=null&&U.value&&U.value!==v.inline)continue}}}if(y==="before"||y==="after"||y==="footnote-call"||y==="footnote-marker"){let N=d[y].content,F=(y==="before"||y==="after")&&(r.float===v.footnote||S||C)&&!!N;if(!N||!kt(N.value)&&!F)continue}p.push(y),b=qn.createElementNS("http://www.w3.org/1999/xhtml","span"),sr(b,y)}else{if(m)continue;b=qn.createElementNS("http://www.pyroxy.com/ns/shadow","content")}g.appendChild(b),y.match(/^first-/)&&(g=b)}if(!p.length)return h;let w=new Ns(t,n,o,s,this.exprContentListener),x=new no(t,f,null,a,h,rt.ROOTLESS,w);return h||x}getPseudoMap(t,i,n,r,o){let s=gt(t,"_pseudos");if(!s)return null;let a={};for(let h in s){let l=a[h]={};or(l,s[h],o),wa(l,o,s[h]),np(s[h],i,n,(u,d)=>{or(l,d,o),ep(d,p=>{or(l,p,o)})})}return a}createRefShadow(t,i,n,r,o){let s=D("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let h=a;if(h){let l=h.getElement(t);if(l){let u=this.stylerProducer.getStylerForDoc(h);o=new no(n,l,h,r,o,i,u)}}s.finish(o)}),s.result()}createShadows(t,i,n,r,o,s,a){let h=D("createShadows"),l=null,u=r.template,d;if(u instanceof ut||u===v.footnote)if(u!==v.footnote||Nh(t,this.xmldoc.url,p=>this.xmldoc.getElementOffset(p),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)){let p=u instanceof ut?u.url:Ie("user-agent.xml#footnote",vi);d=this.createRefShadow(p,rt.ROOTLESS,t,a,l)}else d=T(l);else d=T(l);return d.then(p=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let m=t.getAttribute("href"),w=null;m?w=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?m=a.owner.getAttribute("href"):m=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),w=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),m&&(m=ko(m,w.url),f=this.createRefShadow(m,rt.ROOTED,t,a,p))}f==null&&(f=T(p));let g=null;f.then(m=>{if(r.display===v.table_cell){let w=Ie("user-agent.xml#table-cell",vi);g=this.createRefShadow(w,rt.ROOTLESS,t,a,m)}else g=T(m);g.then(w=>{w=this.createPseudoelementShadow(t,i,n,r,o,s,a,w),h.finish(w)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,r){var o;let s=this.context,a=ya(n,s,this.regionIds,this.isFootnote,this.nodeContext),h=!((o=this.nodeContext)!=null&&o.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=tp(a,s,t);let u=!h&&t!==l;i=ip(a,s,i);let d=(x,y)=>{let b;u&&(t?/^(min-|max-)?(height|inline-size)$/.test(x)&&(b=s.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(x)&&(b=s.pageAreaWidth));let S=y.evaluate(s,x,b,t);return x=="font-family"&&(S=this.docFaces.filterFontFamily(S)),S},p=!!new Ze(s.style.pageScope,"left-page").evaluate(s);if(rp(a,r,t,i,p,d),u){let x=r[t?"height":"width"];(!x||x===v.auto)&&(r[t?"height":"width"]=v.max_content)}if(To(r.position))return r.position=v.fixed,r.visibility=v.hidden,t;let f=r.position,g=r.float,m=r.display||(this.sourceNode&&this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?v.inline:void 0),w=Qc(m,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(x=>{w[x]&&(r[x]=w[x])}),t}inheritFromSourceParent(t){var i,n;let r=this.nodeContext.sourceNode,o=[],s=null,a=r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content"),h=this.isFootnote&&(!((i=this.nodeContext)!=null&&i.parent)||a),l=this.nodeContext.shadowContext;if(r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content")){let w=l?.owner;if(w instanceof Element&&_t(w)){let x=w.getAttribute("href")||w.getAttributeNS("http://www.w3.org/1999/xlink","href");if(x){let y=ko(x,this.xmldoc.url),b=this.xmldoc.getElement(y);b&&bt(b)&&((n=b.parentNode)==null?void 0:n.nodeType)===1&&(r=b.parentNode,l=null)}}}let u=-1;for(;r&&r.nodeType==1;){let w=l&&l.root==r,x=!!w&&l.type==rt.ROOTED&&bt(r);if(!w||l.type==rt.ROOTLESS||x){let y=(l?l.styler:this.styler).getStyle(r,!1);o.push(y),s=s||_s(r)}w&&!x?(r=l.owner,l=l.parentShadow):(r=r.parentNode,u++)}let d=new Set;if(o.length>0){let w=o[0],x=ya(w,this.context,this.regionIds,this.isFootnote,this.nodeContext);for(let y in x){if(!mn(y))continue;let b=x[y].evaluate(this.context,y);b&&b!==v.inherit&&b!==v.unset&&b!==v.revert&&b!==Y&&d.add(y)}}let p=u===0,f=this.context.queryUnitSize("em",p),g={"font-size":new V(new R(f,"px"),0)};p&&(g["line-height"]=new V(new Ct(this.context.pref.lineHeight),0));let m=new Ey(g,this.context);for(let w=o.length-1;w>=0;--w){let x=o[w],y=[];for(let C in x)mn(C)&&y.push(C);y.sort(Ql);let b,S;for(let C of y){if(w>0&&h&&C.startsWith("--viv-marker-")||w>0&&d.has(C))continue;m.setPropName(C);let N=me(x,C),F=N;if(N.value===v.initial)delete g[C];else if(!Z(N.value)){if(C==="font-size"&&w===o.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)F=new V(new R(this.context.rootFontSize,"px"),N.priority);else if(C==="line-height"&&w===o.length-1&&this.context.rootLineHeight&&N.value instanceof R&&(N.value.unit==="lh"||N.value.unit==="rlh"))F=new V(new R(this.context.rootLineHeight,"px"),N.priority);else if(w===0&&N.value instanceof R&&N.value.unit==="lh"){let B=this.getLineHeightUnitSize(C,b,S);B!=null&&(F=new V(new R(N.value.num*B,"px"),N.priority))}else Qt(C)||(F=N.filterValue(m));C==="font-size"?b=F.value:C==="line-height"&&(S=F.value),g[C]=F}}}for(let w in t)mn(w)||(g[w]=t[w]);return{lang:s,elementStyle:g}}resolveURL(t){return t=Ie(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=_s(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=fy().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let r in this.nodeContext.parent.inheritedProps)n[r]=this.nodeContext.parent.inheritedProps[r]}i.forEach(r=>{let o=t[r];if(o){if(Z(o))o===v.initial&&(n[r]=void 0);else if(o instanceof Ue)n[r]=o.num;else if(o instanceof de)n[r]=o.name;else if(o instanceof R){let s=o;switch(s.unit){case"dpi":case"dpcm":case"dppx":n[r]=s.num*Wt[s.unit];break;default:n[r]=o}}else n[r]=o;["widows","orphans"].includes(r)||delete t[r]}})}}resolveFormattingContext(t,i,n,r,o,s){let a=Dt("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,r,o,s);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,r;let o=!0,s=D("createElementView"),a=this.sourceNode,h=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,l=h.getStyle(a,!1);if(this.syncSemanticFootnoteCounterToTarget(a),!this.nodeContext.shadowContext){let S=this.xmldoc.getElementOffset(a);os.registerFragmentIndex(S,this.nodeContext.fragmentIndex,0)}let u={},d={getStyle:S=>this.styler.getStyle(S,!1),getProp:(S,C)=>S?me(S,C):null,getStyleMap:(S,C)=>gt(S,C),getMutableStyleMap:(S,C)=>ei(S,C),createCascadeValue:(S,C)=>new V(S,C),filterFootnoteMarkerContent:(S,C)=>S.filterValue(new mr(this.styler.cascade,C,this.styler.cascade.counterResolver,"footnote-marker")).value};if(!this.nodeContext.parent){let S=this.inheritFromSourceParent(l);l=S.elementStyle,this.nodeContext.lang=S.lang}let p=l.position,f=l.float,g=l["float-reference"],m=f&&!Z(f.value)&&f.value!==v.none&&g&&!Z(g.value)?Yw(g.value.toString()):null,w=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===rt.ROOTED&&bt(a);if(this.nodeContext.parent&&(To(p?.value)||m&&Si(m)||w)){let S=this.inheritFromSourceParent(l);l=S.elementStyle,this.nodeContext.lang=S.lang}l=Qw(a,l,this.nodeContext.shadowContext,this.xmldoc.url,S=>this.xmldoc.getElement(S),rr,d),l=ey(a,l,this.nodeContext.shadowContext,this.context,d),this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,u),m&&Si(m)&&u.display===v.block&&(u.display=v.flow_root),h.processContent(a,u,this.nodeContext),this.transferPolyfilledInheritedProps(u),this.inheritLangAttribute(),u.direction&&(this.nodeContext.direction=u.direction.toString());let x=u["flow-into"];if(x&&x.toString()!=this.flowName)return s.finish(!1),s.result();if(hi&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return Nl(a,this.viewport.window).thenFinish(s),s.result();let y=u.display;if(bt(a)&&!w&&a.hasAttribute(Nd)&&(y=u.display=v.none),Z(y)&&(y===v.initial||y===v.unset?y=v.inline:y===v.inherit?y=((n=this.nodeContext.parent)==null?void 0:n.display)&&M((r=this.nodeContext.parent)==null?void 0:r.display):y=null),y===v.none)return s.finish(!1),s.result();let b=this.nodeContext.parent==null;return this.nodeContext.flexContainer=y===v.flex,this.createShadows(a,b,l,u,h,this.context,this.nodeContext.shadowContext).then(S=>{var C;this.nodeContext.nodeShadow=S;let N=u.position,F=u.float,B=u.clear,U=this.nodeContext.vertical?v.vertical_rl:v.horizontal_tb,q=this.nodeContext.parent?this.nodeContext.parent.vertical?v.vertical_rl:v.horizontal_tb:U,he=dw(a),ae=u["column-count"],k=u["column-width"],_=ae&&ae!==v.auto&&!Z(ae)||k&&k!==v.auto&&!Z(k);this.nodeContext.establishesBFC=fw(y,N,F,u.overflow,U,q,_||he),this.nodeContext.containingBlockForAbsolute=gw(N),this.nodeContext.isInsideBFC()&&F!==v.footnote&&!(m&&Si(m))&&(F=null,B=null);let E=null,L=!1,P=this.isFootnote&&(!((C=this.nodeContext)!=null&&C.parent)||this.nodeContext.pluginProps.nestedFootnoteDetached||w),A=ty(a,this.nodeContext.shadowContext,d);iy(A.sourceStyle,u,this.context),E=A.footnoteDisplay;let O=F instanceof J||F===v.left||F===v.right||F===v.top||F===v.bottom||F===v.inline_start||F===v.inline_end||F===v.block_start||F===v.block_end||F===v.snap_block||F===v.snap_inline||F===v.inside||F===v.outside||F===v.footnote;if(F&&(delete u.float,F===v.footnote))if(E=u["footnote-display"]||E,L=!!u["--viv-marker-content"],P){O=!1;let H=E?.toString();H&&(u["--viv-footnote-display"]=M(H)),y=L?M("list-item"):H==="inline"||H==="compact"?v.inline:v.block,u.display=y}else u.display=v.inline;if(P&&bt(a)){L=L||!!u["--viv-marker-content"];let H=E?.toString();H&&(u["--viv-footnote-display"]=M(H)),L&&(y=u.display=M("list-item")),!L&&(H==="inline"||H==="compact")&&(y=u.display=v.inline)}B&&(B===v.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(B=M(this.nodeContext.parent.clearSide)),(B===v.left||B===v.right||B===v.top||B===v.bottom||B===v.inline_start||B===v.inline_end||B===v.block_start||B===v.block_end||B===v.inside||B===v.outside||B===v.both||B===v.all||B===v.same||B===v.column||B===v.region||B===v.page)&&(delete u.clear,(O||u.display&&u.display!=v.inline)&&(this.nodeContext.clearSide=B.toString())));let z=jn(y)&&!!(u["ua-list-item-count"]||u["--viv-marker-content"]),W=u["break-inside"];(O||W&&!Z(W)&&W!==v.auto)&&this.nodeContext.breakPenalty++,y&&y!==v.inline&&Ht(y)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!O&&!y||Ht(y)||td(y),this.nodeContext.display=y?y.toString():"inline",this.nodeContext.floatSide=O?F.toString():null,this.nodeContext.floatReference=m||Te.INLINE;let K=u["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=K&&!Z(K)?K:null;let Q=this.isInsideNonRootMultiColumn(),ee=u["column-span"];if(this.nodeContext.columnSpan=!Q&&ee&&!Z(ee)?ee:null,!this.nodeContext.inline){let H=u["break-after"];H&&!Z(H)&&!(Q&&H===v.column)&&(this.nodeContext.breakAfter=H.toString(),ta[this.nodeContext.breakAfter]&&(u["break-after"]=v.column));let Ft=u["break-before"];Ft&&!Z(Ft)&&!(Q&&Ft===v.column)&&(this.nodeContext.breakBefore=Ft.toString(),ta[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete u["break-before"]:u["break-before"]=v.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let $t=u.page,Et=$t&&!Z($t)&&$t.toString();!Et&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||y===v.table_header_group||y===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&&u.position===v.fixed)&&(this.nodeContext.fragmentIndex===1&&!Nn(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.captionSide=u["caption-side"]&&u["caption-side"].toString()||"top";let pe=u["border-collapse"];if(!pe||pe===M("separate")){let H=u["border-spacing"],Ft,$t;H&&(H instanceof J?(Ft=H.values[0],$t=H.values[1]):Ft=$t=H,Ft.isNumeric()&&(this.nodeContext.inlineBorderSpacing=at(Ft,this.context)),$t.isNumeric()&&(this.nodeContext.blockBorderSpacing=at($t,this.context)))}let re=u["footnote-policy"]||A.footnotePolicy;re&&!Z(re)&&(u["--viv-footnote-policy"]=re),this.nodeContext.footnotePolicy=re&&!Z(re)?re:null;let se=u["x-first-pseudo"];if(se){let H=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Ww(H,se.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,l,h,this.context);let Me=u["white-space"];if(Me){let H=gd(Me.toString());H!==null&&(this.nodeContext.whitespace=H)}let Oe=u["hyphenate-character"];Oe&&Oe instanceof X&&(this.nodeContext.hyphenateCharacter=Oe.str);let fe=u["word-break"],Ee=u["line-break"],we=u["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,y,N,F,b),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(t=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,t)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(u),this.findAndProcessRepeatingElements(a,h));let ue=!1,Pe=null,ye=[],Se=a.namespaceURI,ne=a.localName,_r=ne;Se=="http://www.w3.org/1999/xhtml"?(E0.has(ne)?ne="div":ne=="vide_"?ne="video":ne=="audi_"?ne="audio":ne=="object"&&(ue=!!this.customRenderer),a.hasAttribute(bl)&&a.hasAttribute("src")&&u.content instanceof ut&&(ne="img")):Se=="http://www.idpf.org/2007/ops"?(ne="span",Se="http://www.w3.org/1999/xhtml"):Se=="http://www.pyroxy.com/ns/shadow"?(Se="http://www.w3.org/1999/xhtml",ne=this.nodeContext.inline?"span":"div"):ue=!!this.customRenderer,z?t?(ne="li",u["--viv-marker-content"]&&(u["list-style-type"]=v.none,u["list-style-image"]=v.none)):(y=Ht(y)?v.inline:v.block,u.display=y,ne="div"):ne=="body"||ne=="li"?ne="div":ne=="q"&&(ne="span"),u.behavior&&u.behavior.toString()!="none"&&this.customRenderer&&(ue=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(ue=!0);let us;if(ue){let H=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;us=this.customRenderer(a,H,u)}else us=T(null);us.then(H=>{var Ft,$t,Et,Bl,Ml;if(H)ue&&(o=H.getAttribute("data-adapt-process-children")=="true");else if(u.display===v.none){s.finish(!1);return}else H=this.createElement(Se,ne);if(!b&&_&&u["column-fill"]===v.auto){let $e=this.nodeContext.vertical?u.width:u.height;(!$e||$e===v.auto||Z($e))&&(H.setAttribute("data-viv-saved-column-fill","auto"),u["column-fill"]=v.balance)}ne!=_r&&(H.setAttribute("data-vivliostyle-original-tag",_r),(_r==="html"||_r==="body")&&(H.role="presentation")),ne=="a"&&H.addEventListener("click",this.page.hrefHandler,!1),Pe&&(this.applyPseudoelementStyle(this.nodeContext,"inner",Pe),H.appendChild(Pe)),H.localName=="iframe"&&H.namespaceURI=="http://www.w3.org/1999/xhtml"&&P0(H);let Dr=this.nodeContext.inheritedProps["image-resolution"],cs=[],ds=u.width,ps=u.height,Ef=a.getAttribute("width"),Pf=a.getAttribute("height"),fs=ds===v.auto||!ds&&!Ef,gs=ps===v.auto||!ps&&!Pf,_l=a.attributes,Nf=_l.length,_n=null,Dl=null;y===v.table_cell&&((Et=($t=(Ft=this.nodeContext.parent)==null?void 0:Ft.viewNode)==null?void 0:$t.lastElementChild)==null?void 0:Et.localName)==="a"&&H.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let $e=0;$e<Nf;$e++){let mt=_l[$e],st=mt.namespaceURI,oe=mt.localName,Ce=mt.nodeValue;if(st){if(st=="http://www.w3.org/2000/xmlns/")continue;st=="http://www.w3.org/1999/xlink"&&oe=="href"&&(Ce=this.documentURLTransformer.transformURL(this.resolveURL(Ce),this.xmldoc.url))}else{if(!hi&&oe.match(/^on/)||oe=="style")continue;if(oe==="media"&&ne==="source"&&Se==="http://www.w3.org/1999/xhtml"&&((Bl=a.parentElement)==null?void 0:Bl.localName)==="picture")try{let He=this.context.rootScope,ct=new ts(He),Vr=new Vt(Ce,ct),zl=Jc(Vr,ct,"");if(zl){if(zl.toExpr().evaluate(this.context))continue;Ce="not all"}}catch{}if((oe=="id"||oe=="name")&&t){let He=this.documentURLTransformer.transformFragment(Ce,this.xmldoc.url);H.setAttribute(oe,Ce),H.setAttribute("data-vivliostyle-id",He);let ct=H.ownerDocument.createElement("a");ct.setAttribute(oe,He),ct.setAttribute(Pn,"1"),ct.style.position="absolute",H.appendChild(ct),this.page.registerElementWithId(H,He);continue}if(oe=="src"||oe=="href"||oe=="poster")Ce=this.resolveURL(Ce),oe==="href"?Ce=this.documentURLTransformer.transformURL(Ce,this.xmldoc.url):Ce=pr(Ce),oe==="src"&&(Ce=Bu(Ce));else if(oe=="srcset")Ce=Ce.split(",").map(He=>{let ct=He.trim().split(/\s+/),Vr=pr(this.resolveURL(ct[0]));return ct.length>1?`${Vr} ${ct.slice(1).join(" ")}`:Vr}).join(",");else if(oe==="data"&&ue&&ne==="object"&&H.hasAttribute("data"))continue;if(oe==="poster"&&ne==="video"&&Se==="http://www.w3.org/1999/xhtml"){let He=new Image,ct=vt(He,Ce);fs&&gs?(ye.push(ct),cs.push({image:He,element:H,fetcher:ct})):this.page.fetchers.push(ct)}}if(Se=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(oe)&&(oe=oe.toLowerCase()),this.isSVGUrlAttribute(oe)&&(Ce=C0(Ce,this.xmldoc.url,this.documentURLTransformer)),st){let He=k0[st];He&&(oe=`${He}:${oe}`)}if(oe=="src"&&!st&&(ne=="img"||ne=="input")&&Se=="http://www.w3.org/1999/xhtml")_n=Ce;else if(oe=="alt"&&!st&&ne=="img"&&Se=="http://www.w3.org/1999/xhtml")Dl=Ce;else if(oe=="href"&&ne=="image"&&Se=="http://www.w3.org/2000/svg"&&(st=="http://www.w3.org/1999/xlink"||!st))st||H.setAttribute(oe,Ce),this.page.fetchers.push(vt(H,Ce));else if(st)H.setAttributeNS(st,oe,Ce);else try{H.setAttribute(oe,Ce)}catch(He){j.warn(He)}}if(_n){let $e=ne==="input"?new Image:H,mt=vt($e,_n,Dl);$e!==H&&(H.src=_n);let st=()=>{var oe,Ce;if(u.position===v.fixed)return!0;for(let He=(oe=this.nodeContext.parent)==null?void 0:oe.viewNode;He&&He!==this.viewRoot;He=He.parentElement)if(((Ce=He.style)==null?void 0:Ce.position)==="fixed")return!0;return!1};!fs&&!gs&&!(()=>{let oe=this.nodeContext.vertical?ds:ps;return oe instanceof R&&oe.unit==="%"})()&&!st()?this.page.fetchers.push(mt):(fs&&gs&&Dr&&Dr!==1&&cs.push({image:$e,element:H,fetcher:mt}),ye.push(mt))}else!_n&&ne==="img"&&Se==="http://www.w3.org/1999/xhtml"&&(H.srcset||((Ml=a.parentElement)==null?void 0:Ml.localName)==="picture")&&this.page.fetchers.push(vt(H));delete u.content;let zr=u["--viv-marker-content"];if(zr){let $e=zr instanceof J?zr.values:[zr];for(let mt of $e)mt instanceof ut&&mt.url&&ye.push(vt(new Image,mt.url))}if(H.localName==="object"&&H.namespaceURI==="http://www.w3.org/1999/xhtml"&&H.hasAttribute("data")&&this.page.fetchers.push(vt(H)),H.localName==="embed"&&H.namespaceURI==="http://www.w3.org/1999/xhtml"&&H.hasAttribute("src")&&this.page.fetchers.push(vt(H)),H.localName==="iframe"&&H.namespaceURI==="http://www.w3.org/1999/xhtml"&&H.hasAttribute("src")){let $e=H;$e.loading==="lazy"&&($e.loading="eager"),this.page.fetchers.push(vt(H))}if(this.preprocessElementStyle(u),this.applyComputedStyles(H,u),this.nodeContext.inline)t||(wt(H,"inline-start"),fn(H)&&wt(H,"clone"));else if(t){if(!is(u.position)){let $e=u["margin-break"],mt=this.getBreakTypeAt(this.nodeContext),st=mt!==null,oe=mt==="auto";($e===v.discard&&st||$e!==v.keep&&oe&&!this.nodeContext.floatSide)&&Ss(H,"block-start")}}else{let $e=this.nodeContext.vertical?"width":"height";mi(H,$e)&&I(H,$e,this.nodeContext.display==="table-row"?"0.01px":""),wt(H,"block-start"),fn(H)&&wt(H,"clone"),Ss(H,"block-start")}z&&u["ua-list-item-count"]&&H.setAttribute("value",u["ua-list-item-count"].stringValue()),this.viewNode=H,ye.length?En(ye).then(()=>{Dr>0&&this.modifyElemDimensionWithImageResolution(cs,Dr,u,this.nodeContext.vertical),s.finish(o)}):s.timeSlice().then(()=>{s.finish(o)})})}),s.result()}isAtStartOfPage(){var t,i;for(let n=this.nodeContext;n!=null&&n.parent&&!n.after;n=n.parent){let r=n===this.nodeContext&&!n.viewNode?(t=n.parent.viewNode)==null?void 0:t.lastChild:(i=n.viewNode)==null?void 0:i.previousSibling;for(;r&&(Le(r,n.parent.whitespace)||Nt(r));)r=r.previousSibling;if(r)return!1}return!0}isInsideNonRootMultiColumn(){var t;let i=(t=this.nodeContext.parent)==null?void 0:t.viewNode;return!!(i&&Lr(i))}getBreakTypeAt(t){var i,n,r,o,s;if(this.isInsideTable(t))return null;for(let h=t;h&&!h.after;h=h.parent){if(qe(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 u=this.viewport.window.getComputedStyle(l),d=parseFloat(u.paddingBlockStart),p=parseFloat(u.borderBlockStartWidth);if(d||p)return null;let f=l?.firstChild;for(;f&&(Le(f,h.parent.whitespace)||!h.floatSide&&Nt(f));)f=f.nextSibling;if(f&&f!==h.viewNode)return null}}let a=(s=(o=(r=this.context)==null?void 0:r.currentLayoutPosition)==null?void 0:o.flowPositions[this.flowName])==null?void 0:s.startBreakType;return qe(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,r){let o=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,r);if(o&&o["after-if-continues"]&&o["after-if-continues"].content){let s=new Ns(t,i,n,r,this.exprContentListener);this.nodeContext.afterIfContinues=new vv(t,s)}}isSVGUrlAttribute(t){return Qn.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,r){t.forEach(o=>{if(o.fetcher.get().get()==="load"){let s=o.image,a=s.width/i,h=s.height/i,l=o.element;if(a>0&&h>0){if(n["box-sizing"]===v.border_box&&(n["border-left-style"]!==v.none&&(a+=at(n["border-left-width"],this.context)),n["border-right-style"]!==v.none&&(a+=at(n["border-right-width"],this.context)),n["border-top-style"]!==v.none&&(h+=at(n["border-top-width"],this.context)),n["border-bottom-style"]!==v.none&&(h+=at(n["border-bottom-width"],this.context))),i>1){let u=n["max-width"]||v.none,d=n["max-height"]||v.none;if(u===v.none&&d===v.none)I(l,"max-width",`${a}px`);else if(u!==v.none&&d===v.none)I(l,"width",`${a}px`);else if(u===v.none&&d!==v.none)I(l,"height",`${h}px`);else{u.isNumeric(),d.isNumeric();let p=u,f=d;p.unit!=="%"?I(l,"max-width",`${Math.min(a,at(p,this.context))}px`):f.unit!=="%"?I(l,"max-height",`${Math.min(h,at(f,this.context))}px`):r?I(l,"height",`${h}px`):I(l,"width",`${a}px`)}}else if(i<1){let u=n["min-width"]||Fe,d=n["min-height"]||Fe;u.isNumeric(),u.isNumeric();let p=u,f=d;p.num===0&&f.num===0?I(l,"min-width",`${a}px`):p.num!==0&&f.num===0?I(l,"width",`${a}px`):p.num===0&&f.num!==0?I(l,"height",`${h}px`):p.unit!=="%"?I(l,"min-width",`${Math.max(a,at(p,this.context))}px`):f.unit!=="%"?I(l,"min-height",`${Math.max(h,at(f,this.context))}px`):r?I(l,"height",`${h}px`):I(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){Dt("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 r={},o=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",o,r),!this.processRepeatOnBreak(r))continue;if(this.nodeContext.formattingContext instanceof Wi&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let s=this.nodeContext.parent,a=s&&s.formattingContext;this.nodeContext.formattingContext=new Wi(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||Z(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=D("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=Eh(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return T(!0);let t,i=t=this.sourceNode.textContent,n=D("preprocessTextContent"),r=Dt("PREPROCESS_TEXT_CONTENT"),o=0;return n.loop(()=>o>=r.length?T(!1):r[o++](this.nodeContext,i).thenAsync(s=>(i=s,T(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Rw(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=D("createNodeView"),r,o=!0;return this.sourceNode.nodeType==1?r=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,r=T(!0)):r=this.createTextNodeView(),r.then(s=>{var a;if(o=s,this.nodeContext.viewNode=this.viewNode,this.viewNode){let h=(d,p)=>d?.nodeType===1&&Kt(d)===p,l=this.nodeContext.parent,u=l?h(this.viewNode,"after")&&h(l.viewNode,"first-letter")&&(a=l.viewNode)!=null&&a.hasChildNodes()?l.parent.viewNode:l.viewNode:this.viewRoot;this.nodeContext.pluginProps.nestedFootnoteDetached&&(u=this.viewRoot),u&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&Le(this.viewNode))&&!u.hasChildNodes()&&cd(u).includes("block-start")&&wt(u,"text-start"),u.appendChild(this.viewNode),vw(this.viewNode))}n.finish(o)}),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):T(!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,r=t.parent,o,s,a=n.subShadow||n.parentShadow;n.subShadow?(o=n.subShadow.root,s=n.subShadow.type,s==rt.ROOTLESS&&(o=o.firstChild)):(o=n.owner.firstChild,s=rt.ROOTLESS);let h=t.sourceNode.nextSibling;if(h?(t.sourceNode=h,t.resetView()):t.shadowSibling?t=t.shadowSibling:o?t=null:(t=t.parent.modify(),t.after=!0),o){let l=new an(o,r,i);return l.shadowContext=a,l.shadowType=s,l.shadowSibling=t,this.processShadowContent(l)}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=rt.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 r=t.nodeShadow.root;if(t.nodeShadow.type==rt.ROOTLESS&&(r=r.firstChild),r){let o=new an(r,t,i);return o.shadowContext=t.nodeShadow,o.shadowType=t.nodeShadow.type,this.processShadowContent(o)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new an(n,t,i));if(t.sourceNode.nodeType!=1){let r=Eh(t.preprocessedTextContent);i+=r.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}findImmediateFootnoteCallSibling(t){let i=this.xmldoc.getElementOffset(t.sourceNode),n=t.viewNode;if(!n)return null;let r=n.previousSibling;for(;r;){if(r.nodeType===Node.TEXT_NODE){if(r.textContent.trim().length===0){r=r.previousSibling;continue}return null}if(r.nodeType===Node.ELEMENT_NODE){let o=r;return Kt(o)==="footnote-call"&&o.getAttribute(Qn.FOOTNOTE_CALL_OWNER_ATTR)===i.toString()?o:null}return null}return null}isSemanticFootnoteElement(t){let i=t.sourceNode;return i instanceof Element&&bt(i)}insertFootnoteCall(t){var i,n;let r=D("insertFootnoteCall"),o=qn.createElementNS("http://www.w3.org/1999/xhtml","span");sr(o,"footnote-call");let s=this.xmldoc.getElementOffset(t.sourceNode);o.setAttribute(Qn.FOOTNOTE_CALL_OWNER_ATTR,s.toString());let a=new an(o,t.parent,t.boxOffset);a.inline=!0;let h=new Ns(t.sourceNode,this.styler.getStyle(t.sourceNode,!1),this.styler,this.context,this.exprContentListener);return a.shadowContext=new no(t.sourceNode,o,null,((i=t.parent)==null?void 0:i.shadowContext)||null,null,rt.ROOTLESS,h),a.shadowSibling=t,t.boxOffset++,(n=t.viewNode)!=null&&n.parentNode&&t.viewNode.parentNode.removeChild(t.viewNode),this.setCurrent(a,!0,!1).then(l=>{if(l&&o.hasChildNodes())r.finish(a);else{let u=a.modify();u.after=!0,a.viewNode||(u.inline=!0),r.finish(u)}}),r.result()}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return T(n);let r=D("nextInTree");return this.setCurrent(n,!0,i).then(o=>{if((!n.viewNode||!o)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),n.floatSide==="footnote"&&!(this.isFootnote&&!n.parent)&&!n.after&&!n.pluginProps.footnoteCallProcessed&&!n.shadowContext&&!this.isSemanticFootnoteElement(n)){let s=this.findImmediateFootnoteCallSibling(n);s!=null&&s.parentNode&&s.parentNode.removeChild(s),this.isFootnote&&n.parent&&(n.pluginProps.nestedFootnoteDetached=1),n.pluginProps.footnoteCallProcessed=1,this.insertFootnoteCall(n).then(a=>{this.dispatchEvent({type:"nextInTree",nodeContext:a}),r.finish(a)});return}this.dispatchEvent({type:"nextInTree",nodeContext:n}),r.finish(n)}),r.result()}addImageFetchers(t){hr(t,this.page)}applyComputedStyles(t,i){var n,r,o;let s=i["background-image"];s&&this.addImageFetchers(s);let a=i["border-image-source"];a&&this.addImageFetchers(a);let h=i["list-style-image"];h&&this.addImageFetchers(h);let l=i["mask-image"];l&&this.addImageFetchers(l);let u=i["clip-path"];u&&this.addImageFetchers(u);let d=i.filter;d&&this.addImageFetchers(d);let p=i["shape-outside"];p&&this.addImageFetchers(p);let f=i["--viv-marker-content"];f&&this.addImageFetchers(f);let g=i.position===v.relative,m=((n=this.nodeContext)==null?void 0:n.parent)===null&&((r=this.sourceNode)==null?void 0:r.parentElement)===null&&!!((o=this.viewRoot)!=null&&o.parentElement),w=Object.keys(i);w.sort(Ql);let x,y;for(let b of w){if(T0[b])continue;let S=i[b];if(!(!S||S===Y&&!Qt(b))){if(S=S.visit(new Yg(this.xmldoc.url,this.documentURLTransformer)),S instanceof R)if(S.unit==="em"){let C=this.getEmUnitSize(b,x);C!=null&&(S=new R(S.num*C,"px"))}else if(S.unit==="lh"){let C=this.getLineHeightUnitSize(b,x,y);C!=null&&(S=new R(S.num*C,"px"))}else Wu(S.unit)&&(S=lc(S,this.context));if((b==="font-size"||b==="line-height")&&(b==="font-size"?x=S:y=S,this.viewport.layoutUnitAdj&&S instanceof R&&S.unit!=="%"&&S.unit!=="em"&&S.unit!=="lh"&&(S=new Qi(`calc(${S.toString()} - var(--viv-layoutUnitAdj))`))),Bw[b]||g&&Mw[b]){this.page.delayedItems.push(new al(t,b,S));continue}m&&this.page.pageAreaElement&&mn(b)?(I(this.page.pageAreaElement.parentElement.parentElement,b,S.toString()),b!=="writing-mode"&&b!=="direction"&&I(this.viewport.layoutBox,b,S.toString())):I(t,b,S.toString())}}}parsePlusLayoutUnitAdj(t){if(t.endsWith("px")){let i=parseFloat(t);if(!isNaN(i))return Math.round((i+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getFootnoteAreaInheritedMetrics(){var t,i;let n=(i=(t=this.page.pageAreaElement)==null?void 0:t.parentElement)==null?void 0:i.parentElement,r=n?this.viewport.window.getComputedStyle(n):null,o=r&&this.parsePlusLayoutUnitAdj(r.fontSize)||this.context.rootFontSize||this.context.initialFontSize,s=r&&this.parsePlusLayoutUnitAdj(r.lineHeight)||this.context.rootLineHeight||o*this.context.pref.lineHeight;return{fontSize:o,lineHeight:s}}getComputedFontMetrics(t,i){var n,r,o;let s=this.viewport.window.getComputedStyle(t),a=(n=this.parsePlusLayoutUnitAdj(s.fontSize))!=null?n:i.fontSize,h=(o=(r=this.parsePlusLayoutUnitAdj(s.lineHeight))!=null?r:i.lineHeight)!=null?o:a!=null?a*this.context.pref.lineHeight:null;return{fontSize:a,lineHeight:h}}getParentViewStyle(){var t,i,n;return((n=(i=(t=this.nodeContext)==null?void 0:t.parent)==null?void 0:i.viewNode)==null?void 0:n.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null}getParentComputedMetrics(t){var i,n;return{fontSize:(i=this.computedStyleParentFontSizeOverride)!=null?i:t?this.parsePlusLayoutUnitAdj(t.fontSize):this.context.rootFontSize,lineHeight:(n=this.computedStyleParentLineHeightOverride)!=null?n:t?this.parsePlusLayoutUnitAdj(t.lineHeight):this.context.rootLineHeight}}getLineHeightUnitSize(t,i,n){var r,o,s;let a=this.getParentViewStyle(),h=this.getParentComputedMetrics(a),l=h.lineHeight;if(t==="line-height"||t==="font-size")return l;let u=null;if(n)if(n instanceof Ct||n instanceof R&&(n.unit==="em"||n.unit==="%"))u=n instanceof R&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof R&&n.unit!=="lh"){let d=this.context.queryUnitSize(n.unit,!1);if(d!=null)return n.num*d}return null}if(u==null)for(let d=(o=(r=this.nodeContext)==null?void 0:r.parent)==null?void 0:o.viewNode;d&&d.nodeType===1;d=d.parentNode){let p=(s=d?.style)==null?void 0:s.lineHeight;if(p){/^[0-9.]+$/.test(p)&&(u=parseFloat(p));break}}if(u!=null){if(i&&!(i instanceof R))return null;let d=h.fontSize;if(i instanceof R){let p=da(i,d,this.context).num;return typeof p!="number"||isNaN(p)?null:u*p}else return d==null?null:u*d}return l}getEmUnitSize(t,i){let n=this.getParentViewStyle(),r=this.getParentComputedMetrics(n).fontSize;if(t==="font-size"||i==null)return r;if(i instanceof R){let o=da(i,r,this.context).num;if(typeof o=="number"&&!isNaN(o))return o}return null}applyPseudoelementStyle(t,i,n){if(t.after)return;let r=this.sourceNode,o=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(r,!1),s=gt(o,"_pseudos");if(!s||(o=s[i],!o))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",o,a);let h=a.content;kt(h)&&(h.visit(new gr(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=D("peelOff"),r=t.firstPseudo,o=t.offsetInNode,s=t.after;if(i>0){let d=t.viewNode.textContent;t.viewNode.textContent=d.substr(0,i),o+=i}else if(!s&&t.viewNode&&o==0){let d=t.viewNode.parentNode;d&&d.removeChild(t.viewNode)}let a=t.boxOffset+i,h=[];for(;t&&t.firstPseudo===r;)h.push(t),t=t.parent;let l=h.pop(),u=l.shadowSibling;return n.loop(()=>{for(;h.length>0;){l=h.pop(),t=new an(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=o,t.after=s),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.shadowSibling:u,u=null;let d=this.setCurrent(t,!1);if(d.isPending())return d}return T(!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){var r;let o={},s=[],a=this.footnoteStyle;if(this.cascadedPageStyle){let p=gt(this.cascadedPageStyle,qo);p&&p.area&&(a=p.area)}let h=gt(a,"_pseudos");t=this.computeStyle(t,i,a,o);let l=this.getFootnoteAreaInheritedMetrics();!o["font-size"]&&l.fontSize!=null&&(o["font-size"]=new R(l.fontSize,"px")),delete o.content;let u=this.computedStyleParentFontSizeOverride,d=this.computedStyleParentLineHeightOverride;this.computedStyleParentFontSizeOverride=l.fontSize,this.computedStyleParentLineHeightOverride=l.lineHeight;try{this.applyComputedStyles(n,o);let p=this.getComputedFontMetrics(n,l);if(this.computedStyleParentFontSizeOverride=p.fontSize,this.computedStyleParentLineHeightOverride=p.lineHeight,h&&h.before){let f=h.before,g=!!me(f,"display"),m={},w=this.createElement("http://www.w3.org/1999/xhtml","span");sr(w,"before"),n.appendChild(w),this.computeStyle(t,i,f,m),g||(m.display=v.block);let x=me(f,"content");if(x){let b=((r=this.sourceNode)==null?void 0:r.nodeType)===1?this.sourceNode:this.xmldoc.root;m.content=x.filterValue(new mr(this.styler.cascade,b,this.styler.cascade.counterResolver,"before")).evaluate(this.context,"content")}let y=m.content;if(kt(y)){y.visit(new gr(w,this.context,y,this.exprContentListener));let b=w.querySelectorAll("img[src]");for(let C=0;C<b.length;C++){let N=b[C],F=N.getAttribute("src");if(!F)continue;let B=vt(N,F);s.push(B),this.page.fetchers.push(B)}let S=w.getAttribute("src");if(S){let C=w.querySelector("img");C||(C=this.document.createElement("img"),C.setAttribute("src",S),w.appendChild(C));let N=vt(C,S);s.push(N),this.page.fetchers.push(N)}}delete m.content,this.applyComputedStyles(w,m)}}finally{this.computedStyleParentFontSizeOverride=u,this.computedStyleParentLineHeightOverride=d}return s.length?En(s).thenReturn(t):T(t)}processFragmentedBlockEdge(t){var i,n,r;let o=!t.inline&&t.after?t.parent:t,s=!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=me(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();s=l&&!Ht(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=o;h;h=h.parent){if(((r=h.viewNode)==null?void 0:r.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(wt(l,"inline-end"),fn(l)){let u=h.vertical?l.offsetWidth:l.offsetHeight;wt(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>u&&this.fixClonedBoxDecorationOverflow(l)}}else{let u=this.nodeContext.vertical?"width":"height";if(mi(l,u)&&I(l,u,""),wt(l,"block-end"),!a++&&h!==o){let{textAlign:d}=this.viewport.window.getComputedStyle(l);if(d==="justify"&&!s){let p=this.createChildAnonymousBlockIfNeeded(l);p?p!==l?dd(p,["block-start","text-start","block-end","text-end","justify"]):(wt(l,"text-end"),wt(l,"justify")):wt(l,"text-end")}else wt(l,"text-end")}fn(l)&&wt(l,"clone"),Ss(l,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),r=parseFloat(i.borderInlineEndWidth),o=-(n+r);isNaN(o)||(t.style.marginInlineEnd=`${o}px`)}createChildAnonymousBlockIfNeeded(t){let i=o=>{let{display:s,position:a,float:h}=this.viewport.window.getComputedStyle(o);if(o.localName==="ruby"||_i[o.localName])return!1;if(o.localName==="br")return!0;if((s==="inline"||s==="contents")&&o.hasChildNodes()){let l=o.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===o.lastChild&&Le(l.nextSibling))){let u=i(l);if(u||u===null)return u}for(let u=l?.previousElementSibling;u;u=u.previousElementSibling){let d=i(u);if(d||d===null)return null}return!1}if(s==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||o.hasAttribute(Pn)){let l=o.previousElementSibling;return l&&(l.nextSibling===o||l.nextSibling===o.previousSibling&&Le(l.nextSibling))?i(l):!1}return!(!s||Ht(s))},n=null;for(let o=t.lastElementChild;o;o=o.previousElementSibling){let s=i(o);if(s){n=o;break}if(s===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&Le(n.nextSibling)))return null;let r=t.ownerDocument.createElement("span");r.className="viv-anonymous-block";for(let o=n.nextSibling,s=null;o;o=s)s=o.nextSibling,r.appendChild(o);return t.appendChild(r),r}convertLengthToPx(t,i,n){let r=t.num,o=t.unit;if(pg(o)){let s=i;for(;s&&s.nodeType!==1;)s=s.parentNode;let a=parseFloat(n.getElementComputedStyle(s)["font-size"]);return this.context,gl(t,a,this.context).num}else{let s=this.context.queryUnitSize(o,!1);return s?r*s:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,r=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&Kt(n)===Kt(r)}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,r)=>{let o=i.steps[r];return this.isSameNodePositionStep(n,o)})}isPseudoelement(t){return!!Kt(t)}};c(Ma,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),c(Ma,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var N0=Ma,T0={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-display":!0,"footnote-policy":!0,"margin-break":!0,page:!0},I0=class{constructor(e){c(this,"layoutBox"),c(this,"window"),c(this,"pixelRatio"),c(this,"scaleRatio"),c(this,"layoutUnitPerPixel"),this.layoutBox=e.layoutBox,this.window=e.window,this.pixelRatio=e.pixelRatio,this.scaleRatio=e.scaleRatio,this.layoutUnitPerPixel=e.layoutUnitPerPixel}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.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.subtractOffsets(t,i)}getElementComputedStyle(e){return this.window.getComputedStyle(e,null)}adjustLengthValue(e){return this.layoutUnitPerPixel?Math.floor(e*this.layoutUnitPerPixel)/this.layoutUnitPerPixel:e}},jo=class{constructor(e,t,i,n,r,o){if(this.window=e,this.fontSize=t,this.pixelRatio=i,c(this,"document"),c(this,"root"),c(this,"outerZoomBox"),c(this,"contentContainer"),c(this,"layoutBox"),c(this,"width"),c(this,"height"),c(this,"scaleRatio",1),c(this,"layoutUnitPerPixel",64),c(this,"layoutUnitAdj",0),this.document=e.document,this.root=n||this.document.body,this.root.hasAttribute("data-vivliostyle-toc-box")){this.outerZoomBox=this.contentContainer=this.layoutBox=this.root,this.width=r||this.root.clientWidth,this.height=o||this.root.clientHeight;return}let s=this.root.firstElementChild;s||(s=this.document.createElement("div"),s.setAttribute("data-vivliostyle-outer-zoom-box","true"),s.role="presentation",this.root.appendChild(s));let a=s.firstElementChild;switch(a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),a.role="presentation",s.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(I(this.root,"--viv-outputPixelRatio",`${i}`),I(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio),Ga){case"chromium":this.layoutUnitPerPixel=64*(this.pixelRatio||e.devicePixelRatio),this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"firefox":this.layoutUnitPerPixel=60,this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"webkit":default:this.layoutUnitPerPixel=64,this.layoutUnitAdj=0}this.layoutUnitAdj&&I(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let h=s.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),h.role="presentation",this.root.appendChild(h)),this.outerZoomBox=s,this.contentContainer=a,this.layoutBox=h,this.width=r||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=o||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let l={width:794,height:1056},u=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!r&&u)&&(this.width=l.width),(!this.height||!o&&u)&&(this.height=l.height)}resetZoom(){I(this.outerZoomBox,"width",""),I(this.outerZoomBox,"height",""),I(this.contentContainer,"width",""),I(this.contentContainer,"height",""),I(this.contentContainer,"transform","")}zoom(e,t,i){I(this.root,"--viv-outputScale",`${i}`),I(this.outerZoomBox,"width",`${e*i}px`),I(this.outerZoomBox,"height",`${t*i}px`),I(this.contentContainer,"width",`${e}px`),I(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}};function hr(e,t){if(e instanceof it)for(let i of e.values)hr(i,t);else if(e instanceof ut){let i=pr(e.url);t.fetchers.push(vt(new Image,i))}else if(e instanceof ci)for(let i of e.values)hr(i,t);else if(e instanceof J)for(let i of e.values)hr(i,t)}var A0=1,ls=class{constructor(e,t,i,n,r){this.name=t,this.pseudoName=i,this.classes=n,this.parent=r,c(this,"specified",{}),c(this,"children",[]),c(this,"pageMaster",null),c(this,"index",0),c(this,"key"),c(this,"_scope"),this._scope=e,this.key=`p${A0++}`,r&&(this.index=r.children.length,r.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})}},F0=class extends ls{constructor(e){super(e,null,null,[],null),this.specified.width=new V(Pr,0),this.specified.height=new V(Nr,0)}},nu=class extends zs{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(r,o){let s=r.match(/^([^.]+)\.([^.]+)$/);if(s){let a=i.pageMaster.keyMap[s[1]];if(a){let h=this.lookupInstance(a);if(h)return o?h.resolveFunc(s[2]):h.resolveName(s[2])}}return null}}},Jp=class Qp extends ls{constructor(t,i,n,r,o,s,a){super(t,i,n,r,o),this.condition=s,this.specificity=a,c(this,"keyMap",{}),t instanceof nu||(this._scope=new nu(t,this)),this.pageMaster=this,this.specified.width=new V(Pr,0),this.specified.height=new V(Nr,0),this.specified["wrap-flow"]=new V(v.auto,0),this.specified.position=new V(v.relative,0),this.specified.overflow=new V(v.visible,0)}createInstance(t){return new Il(t,this)}clone(t){let i=new Qp(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}},ef=class tf extends ls{constructor(t,i,n,r,o){super(t,i,n,r,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new V(v.auto,0)}createInstance(t){return new M0(t,this)}clone(t){let i=new tf(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},Mr=class nf extends ls{constructor(t,i,n,r,o){super(t,i,n,r,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new Fn(t,this)}clone(t){let i=new nf(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function R0(e,t,i){return!t||Z(t)?new Qe(e,i):t.toExpr(e,e.zero)}function ve(e,t,i){return!t||t===v.auto||Z(t)?null:t.toExpr(e,i)}function L0(e,t,i){return!t||t===v.normal||Z(t)?null:t.toExpr(e,i)}function St(e,t,i){return!t||t===v.auto||Z(t)?e.zero:t.toExpr(e,i)}function ru(e,t,i){return!t||Z(t)?e.zero:t===v.auto?null:t.toExpr(e,i)}function Jt(e,t,i,n){return!t||i===v.none||Z(t)?e.zero:t.toExpr(e,n)}function rf(e,t,i){return!t||Z(t)?i:t===v._true?e._true:t===v._false?e._false:t.toExpr(e,e.zero)}var hs=class{constructor(e,t){this.parentInstance=e,this.pageBox=t,c(this,"cascaded",{}),c(this,"style",{}),c(this,"autoWidth",null),c(this,"autoHeight",null),c(this,"children",[]),c(this,"isAutoWidth",!1),c(this,"isAutoHeight",!1),c(this,"isTopDependentOnAutoHeight",!1),c(this,"isRightDependentOnAutoWidth",!1),c(this,"calculatedWidth",0),c(this,"calculatedHeight",0),c(this,"pageMasterInstance",null),c(this,"namedValues",{}),c(this,"namedFuncs",{}),c(this,"vertical",!1),c(this,"rtl",!1),c(this,"suppressEmptyBoxGeneration",!1),c(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 te(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 r=this.vertical?Od:Bd;n=e;for(let o in r)n=n.replace(o,r[o])}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 tc(i,0),r=this.resolveName("column-count"),o=this.resolveName("column-width"),s=this.resolveName("column-gap");t=ge(i,to(i,new tr(i,"min",[n,r]),te(i,o,s)),s);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=rf(e,t.enabled,e._true),n=ve(e,t.page,e.zero);if(n){let s=new Ze(e,"page-number");i=Mt(e,i,new Ja(e,n,s))}let r=ve(e,t["min-page-width"],e.zero);r&&(i=Mt(e,i,new Us(e,new Ze(e,"page-width"),r)));let o=ve(e,t["min-page-height"],e.zero);o&&(i=Mt(e,i,new Us(e,new Ze(e,"page-height"),o))),i=this.boxSpecificEnabled(i),t.enabled=new G(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=ve(e,t.left,i),r=ve(e,t["margin-left"],i),o=Jt(e,t["border-left-width"],t["border-left-style"],i),s=St(e,t["padding-left"],i),a=ve(e,t.width,i),h=ve(e,t["max-width"],i),l=St(e,t["padding-right"],i),u=Jt(e,t["border-right-width"],t["border-right-style"],i),d=ve(e,t["margin-right"],i),p=ve(e,t.right,i),f=te(e,o,s),g=te(e,o,l);if(n&&p&&a){let x=ge(e,i,te(e,a,te(e,te(e,n,f),g)));r?d?p=ge(e,x,d):d=ge(e,x,te(e,p,r)):(x=ge(e,x,p),d?r=ge(e,x,d):(r=to(e,x,new Qe(e,.5)),d=r))}else{r||(r=e.zero),d||(d=e.zero),!n&&!p&&!a&&(n=e.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!p?n=e.zero:!a&&!p&&(a=this.autoWidth,this.isAutoWidth=!0);let x=ge(e,i,te(e,te(e,r,f),te(e,d,g)));this.isAutoWidth&&(h||(h=ge(e,x,n||p)),!this.vertical&&(ve(e,t["column-width"],null)||ve(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?p||(p=ge(e,x,te(e,n,a))):a=ge(e,x,te(e,n,p)):n=ge(e,x,te(e,p,a))}let m=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=St(e,m,i);t.left=new G(n),t["margin-left"]=new G(r),t["border-left-width"]=new G(o),t["padding-left"]=new G(s),t.width=new G(a),t["max-width"]=new G(h||a),t["padding-right"]=new G(l),t["border-right-width"]=new G(u),t["margin-right"]=new G(d),t.right=new G(p),t["snap-width"]=new G(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,r=ve(e,t.top,n),o=ve(e,t["margin-top"],i),s=Jt(e,t["border-top-width"],t["border-top-style"],i),a=St(e,t["padding-top"],i),h=ve(e,t.height,n),l=ve(e,t["max-height"],n),u=St(e,t["padding-bottom"],i),d=Jt(e,t["border-bottom-width"],t["border-bottom-style"],i),p=ve(e,t["margin-bottom"],i),f=ve(e,t.bottom,n),g=te(e,s,a),m=te(e,d,u);if(r&&f&&h){let y=ge(e,n,te(e,h,te(e,te(e,r,g),m)));o?p?f=ge(e,y,o):p=ge(e,y,te(e,f,o)):(y=ge(e,y,f),p?o=ge(e,y,p):(o=to(e,y,new Qe(e,.5)),p=o))}else{o||(o=e.zero),p||(p=e.zero),!r&&!f&&!h&&(r=e.zero),!r&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!r&&!f?r=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let y=ge(e,n,te(e,te(e,o,g),te(e,p,m)));this.isAutoHeight&&(l||(l=ge(e,y,r||f)),this.vertical&&(ve(e,t["column-width"],null)||ve(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),r?h?f||(f=ge(e,y,te(e,r,h))):h=ge(e,y,te(e,f,r)):r=ge(e,y,te(e,f,h))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),x=St(e,w,i);t.top=new G(r),t["margin-top"]=new G(o),t["border-top-width"]=new G(s),t["padding-top"]=new G(a),t.height=new G(h),t["max-height"]=new G(l||h),t["padding-bottom"]=new G(u),t["border-bottom-width"]=new G(d),t["margin-bottom"]=new G(p),t.bottom=new G(f),t["snap-height"]=new G(x)}initColumns(){let e=this.pageBox.scope,t=this.style,i=ve(e,t[this.vertical?"height":"width"],null),n=ve(e,t["column-width"],i),r=ve(e,t["column-count"],null),o=L0(e,t["column-gap"],null);o||(o=new Er(e,1,"em")),n&&!r&&(r=new tr(e,"floor",[$s(e,te(e,i,o),te(e,n,o))]),r=new tr(e,"max",[e.one,r])),r||(r=e.one),n=ge(e,$s(e,te(e,i,o),r),o),t["column-width"]=new G(n),t["column-count"]=new G(r),t["column-gap"]=new G(o)}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,r=this.parentInstance?this.parentInstance.getActiveRegions(e):null,o=ya(this.cascaded,e,r,!1,null);this.vertical=tp(o,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=ip(o,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=o["box-sizing"])==null?void 0:t.value)===v.border_box;let s=!!(e instanceof Ll&&e.currentLayoutPosition&&new Ze(i,"left-page").evaluate(e));rp(o,n,this.vertical,this.rtl,s,(a,h)=>h.value),this.autoWidth=new Re(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new Re(i,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(e,t){var i,n;let r=this.style[t];return!r&&mn(t)&&this.pageMasterInstance instanceof Cn&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?r=new R(e.rootFontSize,"px"):r=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),r&&(r=zo(e,r,t)),r}getPropAsNumber(e,t){var i,n;let r=this.style[t];if(r){let o=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();r=zo(e,r,t,o)}return at(r,e)}getSpecial(e,t){let i=zd(this.cascaded,t);if(i){let n=[];for(let r=0;r<i.length;r++){let o=i[r].evaluate(e,"");o&&o!==Y&&n.push(o)}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 r=this.getProp(e,i);r&&(r.isNumeric()&&Wu(r.unit)&&(r=lc(r,e)),i==="font-family"&&(r=n.filterFontFamily(r)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),I(t,i,r.toString()))}propagateDelayedProperty(e,t,i,n){let r=this.getProp(e,i);r&&n.push(new al(t.element,i,r))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),r=this.getPropAsNumber(e,"padding-left"),o=this.getPropAsNumber(e,"border-left-width"),s=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,s),I(t.element,"margin-left",`${n}px`),I(t.element,"padding-left",`${r}px`),I(t.element,"border-left-width",`${o}px`),t.marginLeft=n,t.borderLeft=o,t.paddingLeft=r}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),r=this.getPropAsNumber(e,"margin-right"),o=this.getPropAsNumber(e,"padding-right"),s=this.getPropAsNumber(e,"border-right-width");if(I(t.element,"margin-right",`${r}px`),I(t.element,"padding-right",`${o}px`),I(t.element,"border-right-width",`${s}px`),t.marginRight=r,t.borderRight=s,this.vertical&&n>0){let a=i+t.getInsetRight(),h=a-Math.floor(a/n)*n;h>0&&(t.snapOffsetX=n-h,o+=t.snapOffsetX)}t.paddingRight=o,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),r=this.getPropAsNumber(e,"margin-top"),o=this.getPropAsNumber(e,"padding-top"),s=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=r,t.borderTop=s,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,o+=t.snapOffsetY)}t.paddingTop=o,I(t.element,"top",`${n}px`),I(t.element,"margin-top",`${r}px`),I(t.element,"padding-top",`${o}px`),I(t.element,"border-top-width",`${s}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),r=this.getPropAsNumber(e,"border-bottom-width"),o=this.getPropAsNumber(e,"height")-t.snapOffsetY;I(t.element,"height",`${o}px`),I(t.element,"margin-bottom",`${i}px`),I(t.element,"padding-bottom",`${n}px`),I(t.element,"border-bottom-width",`${r}px`),t.height=o-t.snapOffsetY,t.marginBottom=i,t.borderBottom=r,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){I(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,I(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){I(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");I(t.element,"right",`${n}px`),I(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,r){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&I(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&I(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 o=0;o<ou.length;o++)this.propagateProperty(e,t,ou[o],n)}transferContentProps(e,t,i,n){for(let r=0;r<au.length;r++)this.propagateProperty(e,t,au[r],n);if(this.style["text-overflow"]){let r=t.element.firstElementChild;I(r,"text-overflow","inherit"),I(r,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var o,s;let a=(s=(o=this.cascaded.width)!=null?o:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:s.value;return!!a&&a!==v.auto&&!Z(a)},r=()=>{var o,s;let a=(s=(o=this.cascaded.height)!=null?o:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:s.value;return!!a&&a!==v.auto&&!Z(a)};for(let o=0;o<lu.length;o++){let s=lu[o];if(s==="width"||s==="height"){if(s==="width"&&!n()||s==="height"&&!r())continue;I(t,s,"100%");continue}this.propagatePropertyToElement(e,t,s,i)}}finishContainer(e,t,i,n,r,o,s){var a,h,l,u,d,p,f,g,m,w;this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let x=(this.vertical||!n)&&this.isAutoHeight,y=(!this.vertical||!n)&&this.isAutoWidth,b=null;if(y||x){y&&I(t.element,"width","auto"),x&&I(t.element,"height","auto");let S=n&&Io(n);S&&rs(n),b=o.getElementClientRect(n?n.element:t.element),S&&rl(n),y&&(this.calculatedWidth=Math.ceil(b.right-b.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),x&&(this.calculatedHeight=b.bottom-b.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)),r>1){let S=this.getPropAsNumber(e,"column-rule-width"),C=this.getProp(e,"column-rule-style"),N=this.getProp(e,"column-rule-color");if(S>0&&C&&C!=v.none&&N!=v.transparent){let F=this.getPropAsNumber(e,"column-gap"),B=this.vertical?t.height:t.width,U=parseFloat(this.vertical?(a=n?.element.style.left)!=null?a:"":(h=n?.element.style.top)!=null?h:""),q=t.getPaddingRect(),he=n,ae=this.vertical?"border-top":"border-left";for(let k=1;k<r;k++){let _=this.vertical?(B+F)*k/r-F/2+t.paddingTop-S/2:(B+F)*k/r-F/2+t.paddingLeft-S/2,E=this.vertical?q.y1+_+S/2:q.x1+_+S/2,L=(d=(u=(l=he.pageFloatLayoutContext)==null?void 0:l.parent)==null?void 0:u.getBlockEndEdgeOfBlockStartFloats)==null?void 0:d.call(u,E),P=(g=(f=(p=he.pageFloatLayoutContext)==null?void 0:p.parent)==null?void 0:f.getBlockStartEdgeOfBlockEndFloats)==null?void 0:g.call(f,E),A=isFinite(L)?this.vertical?L-q.x1:L-q.y1:NaN,O=isFinite(P)?this.vertical?P-q.x1:P-q.y1:NaN,z=parseFloat(this.vertical?(m=n?.element.style.width)!=null?m:"":(w=n?.element.style.height)!=null?w:""),W=z>0?z:this.vertical?n.width:n.height,K=Math.max(U>0?U:0,0),Q=K+W,ee=Math.max(K,isFinite(this.vertical?O:A)?Math.max(0,this.vertical?O:A):0),pe=Math.min(Q,isFinite(this.vertical?A:O)?Math.max(0,this.vertical?A:O):Q),re=Math.max(0,pe-ee),se=t.element.ownerDocument.createElement("div");I(se,"position","absolute"),I(se,this.vertical?"left":"top",`${ee}px`),I(se,this.vertical?"top":"left",`${_}px`),I(se,this.vertical?"height":"width","0px"),I(se,this.vertical?"width":"height",`${re}px`),I(se,ae,`${S}px ${C.toString()}${N?` ${N.toString()}`:""}`),t.element.insertBefore(se,t.element.firstChild)}}}for(let S=0;S<su.length;S++)this.propagateProperty(e,t,su[S],s);for(let S of O0){let C=this.getProp(e,S);C&&hr(C,i)}for(let S=0;S<hu.length;S++)this.propagateDelayedProperty(e,t,hu[S],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let o in n)this instanceof Cn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(o==="writing-mode"||o==="direction")||Di(o)&&Ci(i,o,me(n,o));if(this.pageBox.pseudoName==Tl)for(let o in t)(o.match(/^background-/)||o=="writing-mode")&&(i[o]=t[o]);if(this.pageBox.pseudoName=="layout-host")for(let o in t)!o.match(/^background-/)&&o!="writing-mode"&&(i[o]=t[o]);e.pushRule(this.pageBox.classes,null,i);let r=i.content;r&&(i.content=r.filterValue(new mr(e,null,e.counterResolver))),this.init(e.context);for(let o of this.pageBox.children)o.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)}},ou=["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"],su=["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"],O0=["background-image","border-image-source","filter"],au=["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"],lu=["width","height","image-resolution","object-fit","object-position"],hu=["transform","transform-origin"],Tl="background-host",B0=class extends hs{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)}},Il=class extends hs{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=Mt(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},M0=class extends hs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},Fn=class extends hs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof de&&(n=[t]),t instanceof it&&(n=t.values),n){let r=this.pageBox.scope;for(let o=0;o<n.length;o++)if(n[o]instanceof de){let s=Ds(n[o].name,"enabled"),a=new Ze(r,s);i&&(a=new xi(r,a)),e=Mt(r,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=rf(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let r=R0(t,i["flow-from"],"body"),o=new tr(t,"has-content",[r]);e=Mt(t,e,o)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let r=this.pageMasterInstance.style.enabled,o=r?r.toExpr(t,null):t._true;o=Mt(t,o,e),this.pageMasterInstance.style.enabled=new G(o)}return e}prepareContainer(e,t,i,n,r){var o;this.pageBox.pageMaster instanceof hf||(I(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(o=this.pageBox.name)!=null?o:"")),super.prepareContainer(e,t,i,n,r)}},Al=class extends Xi{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 V(t,i?Xc:qc)}},of=class extends Al{constructor(e,t,i,n){super(e,t,i,n)}},_0=class sf extends Al{constructor(t,i,n,r){super(t,i,n,r),n.specified.width=new V(Kl,0),n.specified.height=new V(Kl,0)}startPartitionRule(t,i,n){let r=new Mr(this.scope,t,i,n,this.target),o=new of(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,i,n){let r=new ef(this.scope,t,i,n,this.target),o=new sf(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}},D0=class extends Al{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new Mr(this.scope,e,t,i,this.target),r=new of(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(e,t,i){let n=new ef(this.scope,e,t,i,this.target),r=new _0(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}};function af(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,r=(i=e.direction)==null?void 0:i.value;return n===v.vertical_lr||n!==v.vertical_rl&&r!==v.rtl?"ltr":"rtl"}var z0={a10:{width:new R(26,"mm"),height:new R(37,"mm")},a9:{width:new R(37,"mm"),height:new R(52,"mm")},a8:{width:new R(52,"mm"),height:new R(74,"mm")},a7:{width:new R(74,"mm"),height:new R(105,"mm")},a6:{width:new R(105,"mm"),height:new R(148,"mm")},a5:{width:new R(148,"mm"),height:new R(210,"mm")},a4:{width:new R(210,"mm"),height:new R(297,"mm")},a3:{width:new R(297,"mm"),height:new R(420,"mm")},a2:{width:new R(420,"mm"),height:new R(594,"mm")},a1:{width:new R(594,"mm"),height:new R(841,"mm")},a0:{width:new R(841,"mm"),height:new R(1189,"mm")},b10:{width:new R(31,"mm"),height:new R(44,"mm")},b9:{width:new R(44,"mm"),height:new R(62,"mm")},b8:{width:new R(62,"mm"),height:new R(88,"mm")},b7:{width:new R(88,"mm"),height:new R(125,"mm")},b6:{width:new R(125,"mm"),height:new R(176,"mm")},b5:{width:new R(176,"mm"),height:new R(250,"mm")},b4:{width:new R(250,"mm"),height:new R(353,"mm")},b3:{width:new R(353,"mm"),height:new R(500,"mm")},b2:{width:new R(500,"mm"),height:new R(707,"mm")},b1:{width:new R(707,"mm"),height:new R(1e3,"mm")},b0:{width:new R(1e3,"mm"),height:new R(1414,"mm")},c10:{width:new R(28,"mm"),height:new R(40,"mm")},c9:{width:new R(40,"mm"),height:new R(57,"mm")},c8:{width:new R(57,"mm"),height:new R(81,"mm")},c7:{width:new R(81,"mm"),height:new R(114,"mm")},c6:{width:new R(114,"mm"),height:new R(162,"mm")},c5:{width:new R(162,"mm"),height:new R(229,"mm")},c4:{width:new R(229,"mm"),height:new R(324,"mm")},c3:{width:new R(324,"mm"),height:new R(458,"mm")},c2:{width:new R(458,"mm"),height:new R(648,"mm")},c1:{width:new R(648,"mm"),height:new R(917,"mm")},c0:{width:new R(917,"mm"),height:new R(1297,"mm")},"jis-b10":{width:new R(32,"mm"),height:new R(45,"mm")},"jis-b9":{width:new R(45,"mm"),height:new R(64,"mm")},"jis-b8":{width:new R(64,"mm"),height:new R(91,"mm")},"jis-b7":{width:new R(91,"mm"),height:new R(128,"mm")},"jis-b6":{width:new R(128,"mm"),height:new R(182,"mm")},"jis-b5":{width:new R(182,"mm"),height:new R(257,"mm")},"jis-b4":{width:new R(257,"mm"),height:new R(364,"mm")},"jis-b3":{width:new R(364,"mm"),height:new R(515,"mm")},"jis-b2":{width:new R(515,"mm"),height:new R(728,"mm")},"jis-b1":{width:new R(728,"mm"),height:new R(1030,"mm")},"jis-b0":{width:new R(1030,"mm"),height:new R(1456,"mm")},letter:{width:new R(8.5,"in"),height:new R(11,"in")},legal:{width:new R(8.5,"in"),height:new R(14,"in")},ledger:{width:new R(11,"in"),height:new R(17,"in")}},V0=new R(.24,"pt"),eS=new R(3,"mm"),U0=new R(10,"mm"),$0=new R(13,"mm");function Xo(e){let t={width:Pr,height:Nr,bleed:Fe,bleedOffset:Fe,cropOffset:Fe},i=e.size;if(!(!i||i.value===v.auto)){let l=i.value,u,d;if(l.isSpaceList()?(u=l.values[0],d=l.values[1]):(u=l,d=null),u.isNumeric())t.width=u,t.height=d||u;else{let p=u.name&&z0[u.name.toLowerCase()];p&&(d&&d===v.landscape?(t.width=p.height,t.height=p.width):(t.width=p.width,t.height=p.height))}}let n=e.marks,r=e.bleed,o=n&&!Z(n.value)?n.value:v.none,s=r&&!Z(r.value)?r.value:v.auto;if(s===v.auto){if(o!==v.none){let l=!1;o.isSpaceList()?l=o.values.some(u=>u===v.crop):l=o===v.crop,l&&(t.bleed=new R(6,"pt"))}}else s.isNumeric()&&(t.bleed=s);let a=e["crop-offset"],h=a&&!Z(a.value)?a.value:v.auto;return h===v.auto?o!==v.none&&(t.bleedOffset=$0):h.isNumeric()&&(t.cropOffset=h),t}function uu(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),r=!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),o=n+r,s=e.width;s===Pr?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)-o*2:i.pageWidth=s.num*t.queryUnitSize(s.unit,!1);let a=e.height;return a===Nr?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-o*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=r,i.cropOffset=o,i}function lf(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 ur(e,t,i,n){n=n||"polyline";let r=e.createElementNS("http://www.w3.org/2000/svg",n);return r.setAttribute("stroke",i===v.auto?"#010101":i.toString()),r.setAttribute("stroke-width",t),r.setAttribute("fill","none"),r}var _a=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(_a||{});function H0(e,t,i,n,r,o,s){let a=r;a<=o+2*Wt.mm&&(a=o+r/2);let h=Math.max(r,a),l=o+h+i/2,u=lf(e,l,l),d=[[0,o+r],[r,o+r],[r,o+r-a]],p=d.map(m=>[m[1],m[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(m=>[o+h-m[0],m[1]]),p=p.map(m=>[o+h-m[0],m[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(m=>[m[0],o+h-m[1]]),p=p.map(m=>[m[0],o+h-m[1]]));let f=ur(e,i,n);f.setAttribute("points",d.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=ur(e,i,n);return g.setAttribute("points",p.map(m=>m.join(",")).join(" ")),u.appendChild(g),t.split(" ").forEach(m=>{u.style[m]=`${s}px`}),u}var xr=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(xr||{});function W0(e,t,i,n,r,o){let s=r*2,a,h;t==="top"||t==="bottom"?(a=s,h=r):(a=r,h=s);let l=lf(e,a,h),u=ur(e,i,n);u.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(u);let d=ur(e,i,n);d.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(d);let p=ur(e,i,n,"circle");p.setAttribute("cx",a/2),p.setAttribute("cy",h/2),p.setAttribute("r",r/4),l.appendChild(p);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(xr).forEach(g=>{let m=xr[g];m===t?l.style[m]=`${o}px`:m!==f&&(l.style[m]="0",l.style[`margin-${m}`]="auto")}),l}function G0(e,t,i,n){let r=!1,o=!1,s=e.marks;if(s){let m=s.value;m instanceof J?m.values.forEach(w=>{w===v.crop?r=!0:w===v.cross&&(o=!0)}):m===v.crop?r=!0:m===v.cross&&(o=!0)}let a=t.bleed;if(!r&&!o)return;let h=i.container,l=h.ownerDocument,u=at(V0,n),d=Math.max(0,t.bleedOffset-at(U0,n)),p=t.bleedOffset-d,f=e["crop-marks-line-color"],g=f&&!Z(f.value)?f.value:v.auto;r&&Object.keys(_a).forEach(m=>{let w=_a[m],x=H0(l,w,u,g,p,a,d);h.appendChild(x)}),o&&Object.keys(xr).forEach(m=>{let w=xr[m],x=W0(l,w,u,g,p,d);h.appendChild(x)})}var Da=(()=>{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})(),Fl={"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"}},j0=(()=>{let e=Fl;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),Rl="vivliostyle-page-rule-master",Sr="_marginBoxes",qo="_footnoteArea",hf=class extends Jp{constructor(e,t,i){super(e,null,Rl,[],t,null,0),c(this,"pageMarginBoxes",{});let n=Xo(i),r=new X0(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[Sr];t&&j0.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new Y0(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new V(v.relative,0),this.specified.width=new V(t.width,0),this.specified.height=new V(t.height,0);for(let i in e)!Da[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new Cn(e,this)}},X0=class extends Mr{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let r=new q0(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new V(v.auto,0),this.specified["z-index"]=new V(new Ue(0),0),this.specified.position=new V(v.absolute,0),this.specified.overflow=new V(v.visible,0);for(let t in Da)Da.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new K0(e,this)}},q0=class extends Mr{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new V(M("body"),0)}createInstance(e){return new uf(e,this)}},Y0=class extends Mr{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[Sr][this.marginBoxName];for(let i in e){let n=e[i],r=t[i];(Ld[i]||r&&r.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!==Y&&n.value!==v.inherit&&n.value!==v.unset&&n.value!==v.revert&&(this.specified[i]=n)}}createInstance(e){return new cf(e,this)}},Cn=class extends Il{constructor(e,t){super(e,t),c(this,"pageAreaDimension",null),c(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=Fe,e["margin-left"]=Fe,e["border-left-width"]=Fe,e["padding-left"]=Fe,e["padding-right"]=Fe,e["border-right-width"]=Fe,e["margin-right"]=Fe,e.right=Fe}initVertical(){let e=this.style;e.top=Fe,e["margin-top"]=Fe,e["border-top-width"]=Fe,e["padding-top"]=Fe,e["padding-bottom"]=Fe,e["border-bottom-width"]=Fe,e["margin-bottom"]=Fe,e.bottom=Fe}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new G(e.borderBoxWidth),t.height=new G(e.borderBoxHeight),t["padding-left"]=new G(e.marginLeft),t["padding-right"]=new G(e.marginRight),t["padding-top"]=new G(e.marginTop),t["padding-bottom"]=new G(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,r={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},o={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,o,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,o,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,r){let o="start",s="center",a="end",h=this.pageBox.scope,l={},u={},d={};for(let b in e){let S=Fl[b];if(S){let C=e[b],N=this.pageMarginBoxInstances[b],F=new bo(C,N.style,t,h,r);l[S.positionAlongVariableDimension]=C,u[S.positionAlongVariableDimension]=N,d[S.positionAlongVariableDimension]=F}}let p={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),g=!1,m={};Object.keys(l).forEach(b=>{let S=b,C=ve(h,u[S].style[t?"max-width":"max-height"],i.extent);if(C){let N=C.evaluate(n);if(f[S]>N){let F=d[S]=new cu(l[S],u[S].style,t,h,r,N);m[S]=F.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),g=!1,[o,s,a].forEach(b=>{var S;f[b]=(S=m[b])!=null?S:f[b]}));let w={};Object.keys(l).forEach(b=>{let S=b,C=ve(h,u[S].style[t?"min-width":"min-height"],i.extent);if(C){let N=C.evaluate(n);if(f[S]<N){let F=d[S]=new cu(l[S],u[S].style,t,h,r,N);w[S]=F.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),[o,s,a].forEach(b=>{f[b]=w[b]||f[b]}));let x=p.start+p.extent,y=p.start+(p.start+p.extent);[o,s,a].forEach(b=>{let S=f[b];if(S!=null){let C=l[b],N=0;switch(b){case o:N=t?C.left:C.top;break;case s:N=(y-S)/2;break;case a:N=x-S;break}t?C.setHorizontalPosition(N,S-C.getInsetLeft()-C.getInsetRight()):C.setVerticalPosition(N,S-C.getInsetTop()-C.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,r=e.center,o=e.end,s={};if(r){let a=[n,o],h=new Z0(a),l=this.distributeAutoMarginBoxSizes(r,h,t);l.xSize!=null&&(s.center=l.xSize);let u=(i=l.xSize)!=null?i:r.getOuterSize(),d=Math.max((t-u)/2,0);n&&(s.start=n.hasAutoSize()?d:n.getOuterSize()),o&&(s.end=o.hasAutoSize()?d:o.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,o,t);a.xSize!=null&&(s.start=a.xSize),a.ySize!=null&&(s.end=a.ySize)}return s}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e instanceof bo&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof bo&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let r=e.getOuterMaxContentSize(),o=t.getOuterMaxContentSize();if(r>0&&o>0){let s=r+o;if(s<i)n.xSize=i*r/s;else{let a=e.getOuterMinContentSize(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(r-a)/(s-l):l>0&&(n.xSize=i*a/l)}n.xSize>0&&(n.ySize=i-n.xSize)}else r>0?n.xSize=i:o>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,r){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,r)}},bo=class{constructor(e,t,i,n,r){this.container=e,this.isHorizontal=i,this.clientLayout=r,c(this,"hasAutoSize_"),c(this,"size",null),c(this,"minMaxFitContent",null);let o=t[i?"width":"height"];if(this.hasAutoSize_=!o||o===v.auto||Z(o),this.minMaxFitContent=o instanceof de&&(o.name==="min-content"||o.name==="max-content"||o.name==="fit-content")?o.name:null,this.minMaxFitContent){let s=this.getSize();if(this.isHorizontal){let a=s[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=s[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=sl(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()}},Z0=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}},cu=class extends bo{constructor(e,t,i,n,r,o){super(e,t,i,n,r),c(this,"fixedSize"),this.fixedSize=o}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()}},K0=class extends Fn{constructor(e,t){super(e,t),c(this,"borderBoxWidth",null),c(this,"borderBoxHeight",null),c(this,"contentBoxWidth",null),c(this,"contentBoxHeight",null),c(this,"marginTop",null),c(this,"marginRight",null),c(this,"marginBottom",null),c(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,r=e.start,o=e.end,s=e.extent,a=i[s].toExpr(n,null),h=ve(n,t[s],a),l=ve(n,t[`margin-${r}`],a),u=ve(n,t[`margin-${o}`],a),d=St(n,t[`padding-${r}`],a),p=St(n,t[`padding-${o}`],a),f=Jt(n,t[`border-${r}-width`],t[`border-${r}-style`],a),g=Jt(n,t[`border-${o}-width`],t[`border-${o}-style`],a),m=te(n,te(n,f,d),te(n,g,p)),w,x,y;return h?(this.borderBoxSizing?(x=h,y=ge(n,x,m)):(y=h,x=te(n,y,m)),w=ge(n,a,x),!l&&!u?(l=to(n,w,new Qe(n,.5)),u=l):l?u=ge(n,w,l):l=ge(n,w,u)):(l||(l=n.zero),u||(u=n.zero),w=te(n,l,u),x=ge(n,a,w),y=ge(n,x,m),h=this.borderBoxSizing?x:y),t[r]=new G(l),t[o]=new G(u),t[`margin-${r}`]=Fe,t[`margin-${o}`]=Fe,t[`border-${r}-width`]=new G(f),t[`border-${o}-width`]=new G(g),t[`padding-${r}`]=new G(d),t[`padding-${o}`]=new G(p),t[s]=new G(h),t[`max-${s}`]=new G(h),{borderBoxExtent:x,contentBoxExtent:y,marginStart:l,marginEnd:u}}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,r)}},uf=class extends Fn{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 G(this.parentInstance.contentBoxWidth),e["margin-left"]=new G(new un(i,t.left.toExpr(i,null))),e["margin-right"]=new G(new un(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 G(this.parentInstance.contentBoxHeight),e["margin-top"]=new G(new un(i,t.top.toExpr(i,null))),e["margin-bottom"]=new G(new un(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,r){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,r),e.pageAreaWidth=t.width,e.pageAreaHeight=t.height}},cf=class extends Fn{constructor(e,t){super(e,t),c(this,"boxInfo"),c(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=Fl[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,r)}applyVerticalAlign(e,t){I(t,"display","flex"),I(t,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let i=this.getProp(e,"vertical-align"),n=null;i===M("middle")?n="center":i===M("top")?n="flex-start":i===M("bottom")&&(n="flex-end"),n&&I(t,"justify-content",n);let r=this.getProp(e,"content");if(this.vertical||r instanceof ut||r instanceof G&&r.expr instanceof Re&&r.expr.str.startsWith("running-element-")){let o="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?o=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(o=this.vertical||this.rtl?"end":"start")),I(t,"align-items",o)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,r=e.start,o=e.end,s=e.extent,a=r==="left",h=a?t.borderBoxWidth:t.borderBoxHeight,l=ve(n,i[s],h),u=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[r]=new G(u);else if(l){let d=St(n,i[`margin-${r}`],h),p=St(n,i[`margin-${o}`],h),f=St(n,i[`padding-${r}`],h),g=St(n,i[`padding-${o}`],h),m=Jt(n,i[`border-${r}-width`],i[`border-${r}-style`],h),w=Jt(n,i[`border-${o}-width`],i[`border-${o}-style`],h),x=te(n,l,te(n,this.borderBoxSizing?n.zero:te(n,te(n,f,g),te(n,m,w)),te(n,d,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[r]=new G(te(n,u,$s(n,ge(n,h,x),new Qe(n,2))));break;case"end":i[r]=new G(ge(n,te(n,u,h),x));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,r=this.borderBoxSizing,o=e.inside,s=e.outside,a=e.extent,h=t[`margin${s.charAt(0).toUpperCase()}${s.substring(1)}`],l=ru(n,i[`margin-${o}`],h),u=ru(n,i[`margin-${s}`],h),d=St(n,i[`padding-${o}`],h),p=St(n,i[`padding-${s}`],h),f=Jt(n,i[`border-${o}-width`],i[`border-${o}-style`],h),g=Jt(n,i[`border-${s}-width`],i[`border-${s}-style`],h),m=ve(n,i[a],h),w=null;function x(y){if(w)return w;w={extent:m?m.evaluate(y):null,marginInside:l?l.evaluate(y):null,marginOutside:u?u.evaluate(y):null};let b=h.evaluate(y),S=0;return r||[f,d,p,g].forEach(C=>{C&&(S+=C.evaluate(y))}),(w.marginInside===null||w.marginOutside===null)&&S+w.extent+w.marginInside+w.marginOutside>b&&(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=b-S-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=b-S-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=b-S-w.extent-w.marginInside:w.marginInside=w.marginOutside=(b-S-w.extent)/2),w}i[a]=new G(new Re(n,function(){let y=x(this).extent;return y===null?"auto":y},a)),i[`margin-${o}`]=new G(new Re(n,function(){let y=x(this).marginInside;return y===null?"auto":y},`margin-${o}`)),i[`margin-${s}`]=new G(new Re(n,function(){let y=x(this).marginOutside;return y===null?"auto":y},`margin-${s}`)),o==="left"?i.left=new G(te(n,t.marginLeft,t.borderBoxWidth)):o==="top"&&(i.top=new G(te(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,r,o,s){super.finishContainer(e,t,i,n,r,o,s);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 u=this.parentInstance.pageAreaDimension,d=this.getProp(e,"width"),p=d instanceof de&&(d.name==="min-content"||d.name==="max-content"||d.name==="fit-content")?d.name:null,f=this.getPropAsNumber(e,"min-width"),g=this.getPropAsNumber(e,"max-width");if(p||f||g){p&&I(t.element,"width",p),f&&I(t.element,"min-width",`${f}px`),g&&I(t.element,"max-width",`${g}px`);let b=this.getProp(e,"margin-left"),S=this.getProp(e,"margin-right");if(l.isInLeftColumn){let C=u.borderBoxWidth.evaluate(e)+u.marginRight.evaluate(e);I(t.element,"right",`${C}px`),(b===v.auto||S!==v.auto)&&I(t.element,"margin-left","auto"),S===v.auto&&I(t.element,"margin-right","auto")}else l.isInRightColumn&&(I(t.element,"right","0"),(S===v.auto||b!==v.auto)&&I(t.element,"margin-right","auto"),b===v.auto&&I(t.element,"margin-left","auto"))}let m=this.getProp(e,"height"),w=m instanceof de&&(m.name==="min-content"||m.name==="max-content"||m.name==="fit-content")?m.name:null,x=this.getPropAsNumber(e,"min-height"),y=this.getPropAsNumber(e,"max-height");if(w||x||y){w&&I(t.element,"height",w),x&&I(t.element,"min-height",`${x}px`),y&&I(t.element,"max-height",`${y}px`);let b=this.getProp(e,"margin-top"),S=this.getProp(e,"margin-bottom");if(l.isInTopRow){let C=u.borderBoxHeight.evaluate(e)+u.marginBottom.evaluate(e);I(t.element,"bottom",`${C}px`),(b===v.auto||S!==v.auto)&&I(t.element,"margin-top","auto"),S===v.auto&&I(t.element,"margin-bottom","auto")}else l.isInBottomRow&&(I(t.element,"bottom","0"),(S===v.auto||b!==v.auto)&&I(t.element,"margin-bottom","auto"),b===v.auto&&I(t.element,"margin-top","auto"))}}},J0=class{constructor(e,t,i,n,r){this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=r,c(this,"pageMasterCache",{}),c(this,"pageCascadeInstance"),this.pageCascadeInstance=e,this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new Ze(e,"page-number"),r=new Ja(e,new Ku(e,n,new Qe(e,2)),i?e.one:e.zero);e.defineName("recto-page",new xi(e,r)),e.defineName("verso-page",r),(t.pageProgression||af(this.docElementStyle))==="ltr"?(e.defineName("left-page",r),e.defineName("right-page",new xi(e,r))):(e.defineName("left-page",new xi(e,r)),e.defineName("right-page",r))}getCascadedPageStyle(e){let t={};return this.pageCascadeInstance.pushRule([],e,t),this.pageCascadeInstance.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),r=this.pageMasterCache[n];return r||(i.pseudoName===Tl?r=this.generatePageRuleMaster(t):r=this.generateCascadedPageMaster(t,i),this.pageMasterCache[n]=r),r.pageBox.resetScope(),r}makeCacheKey(e,t){var i;let n=this.makeCascadeValueObjectKey(e),r=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${t.key}^${n}^${r}`}makeCascadeValueObjectKey(e){let t=[];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],r;n instanceof V?r=`${n.value}`:r=this.makeCascadeValueObjectKey(n),t.push(i+r+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new hf(this.pageScope,this.rootPageBoxInstance.pageBox,e).createInstance(this.rootPageBoxInstance);return t.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),t.resolveAutoSizing(this.context),t}generateCascadedPageMaster(e,t){let i=t.clone({pseudoName:Rl}),n=i.specified,r=e.size;if(r&&!Z(r.value)){let s=Xo(e),a=r.priority;Gt(n,"width",new V(s.width,a),this.context),Gt(n,"height",new V(s.height,a),this.context)}["counter-reset","counter-increment"].forEach(s=>{n[s]&&(e[s]=n[s])});let o=i.createInstance(this.rootPageBoxInstance);return o.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),o.resolveAutoSizing(this.context),o}},Q0=class extends ke{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}},ex=class extends ke{constructor(e){super(),this.scope=e}apply(e){new Ze(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},tx=class extends ke{constructor(e){super(),this.scope=e}apply(e){new Ze(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},ix=class extends ke{constructor(e){super(),this.scope=e}apply(e){new Ze(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},nx=class extends ke{constructor(e){super(),this.scope=e}apply(e){new Ze(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},rx=class extends ke{constructor(e){super(),this.scope=e}apply(e){new Ze(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},ox=class extends ke{constructor(e){super(),this.scope=e}apply(e){new Ze(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},sx=class extends qi{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}},ax=class extends qi{constructor(e,t,i,n){super(t,i),this.scope=e,this.a=t,this.b=i,this.pageType=n}apply(e){let t=e.pageTypePageIndices[this.pageType];if(t){for(let i of t)if(this.matchANPlusB(i)){this.chained.apply(e);return}}}getPriority(){return 3}},lx=class extends ml{constructor(e,t){super(e,t,null,null,null)}apply(e){hx(e.context,e.currentStyle,this.style,this.specificity,e)}};function hx(e,t,i,n,r){_o(e,t,i,n,null,null,null);let o=i[Sr];if(o){let a=ei(t,Sr);for(let h in o)if(o.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l),_o(e,l,o[h],n,null,null,null)}}let s=i[qo];if(s){let a=ei(t,qo);for(let h in s)if(s.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l);let u=s[h];for(let p in u)if(u.hasOwnProperty(p)&&p!=="_pseudos"){let f=u[p];f instanceof V&&Gt(l,p,f)}let d=gt(u,"_pseudos");if(d){let p=ei(l,"_pseudos");for(let f in d)if(d.hasOwnProperty(f)){let g=p[f];g||(g={},p[f]=g);let m=d[f];for(let w in m)if(m.hasOwnProperty(w)){let x=m[w];x instanceof V&&Gt(g,w,x)}}}}}}var ux=class extends wr{constructor(e,t,i,n,r){super(e,t,i?.condition,i,null,n,!1),this.pageProps=r,c(this,"currentPageSelectors",[]),c(this,"currentNamedPageSelector",""),c(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new Q0(t)),this.specificity+=65536)}pseudoclassSelector(e,t){if(e=e.toLowerCase(),t)switch(e){case"nth":{let i=t[0],n=t[1];if(t.length===3&&typeof t[2]=="string"){let r=t[2];this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n} of ${r})`),this.chain.push(new ax(this.scope,i,n,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new sx(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 ex(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new tx(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new ix(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new nx(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new rx(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new ox(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(o=>o.selectors===null))return;super.simpleProperty(e,t,i);let n=me(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(o=>{Ci(r[o],e,n)});else if(e==="size"){let o=r[""];this.currentPageSelectors.forEach(s=>{let a=new V(n.value,n.priority+s.specificity),h=s.selectors?s.selectors.join(""):"",l=r[h];l?Gt(l,e,a):(l=r[h]={},Ci(l,e,a),o&&["bleed","marks"].forEach(u=>{o[u]&&Ci(l,u,o[u])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new lx(this.elementStyle,e)}startFootnoteRule(e){let t=ei(this.elementStyle,qo),i=t.area;if(i||(i={},t.area=i),e){let r=ei(i,"_pseudos"),o=r[e];o||(o={},r[e]=o),i=o}let n=new df(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}startPageMarginBoxRule(e){let t=ei(this.elementStyle,Sr),i=t[e];i||(i={},t[e]=i);let n=new cx(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},cx=class extends Xi{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(),r=new V(t,n);Ci(this.boxStyle,e,r)}},df=class extends Xi{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.areaStyle=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(),r=new V(t,n);Ci(this.areaStyle,e,r)}},pf=class{constructor(e,t,i){this.store=e,this.url=t,this.document=i,c(this,"lang",null),c(this,"totalOffset",-1),c(this,"root"),c(this,"body"),c(this,"head"),c(this,"last"),c(this,"lastOffset",1),c(this,"idMap"),this.root=i.documentElement;let n=null,r=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let o=this.root.firstChild;o;o=o.nextSibling){if(o.nodeType!=1)continue;let s=o;if(s.namespaceURI=="http://www.w3.org/1999/xhtml")switch(s.localName){case"head":r=s;break;case"body":n=s;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=r,this.last=this.root,this.last.setAttribute(Zt,"0")}doc(){return new gf([this.document])}getElementOffset(e){let t=e.getAttribute(Zt);if(t)return parseInt(t,10);let i=this.lastOffset,n=this.last;for(;n!=e;){let r=n.firstChild;if(!r){for(;r=n.nextSibling,!r;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=r,r.nodeType==1?(r.setAttribute(Zt,i.toString()),++i):i+=r.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,r=e,o=null;if(r.nodeType==1){if(!i)return this.getElementOffset(r)}else{if(n=t,o=r.previousSibling,!o)return r=r.parentNode,n+=1,this.getElementOffset(r)+n;r=o}for(;;){for(;r.lastChild;)r=r.lastChild;if(r.nodeType==1)break;if(n+=r.textContent.length,o=r.previousSibling,!o){r=r.parentNode;break}r=o}return n+=1,this.getElementOffset(r)+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=ai(a.length,l=>{let u=a[l];return this.getElementOffset(u)>e});if(h==0)break;i=a[h-1]}let n=t+1,r=i,o=r.firstChild||r.nextSibling,s=null;for(;;){if(o){if(o.nodeType==1||(r=o,s=r,n+=o.textContent.length,n>e&&!/^\s*$/.test(o.textContent)))break}else if(r=r.parentNode,!r)break;o=r.nextSibling}return o&&s&&/^\s*$/.test(s.textContent)&&(s=o),s||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}},za=(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))(za||{});function Kr(e,t,i){let n=i||new DOMParser,r;try{r=n.parseFromString(e,t)}catch{}if(r){let o=r.documentElement,s="parsererror";if(o.localName===s)return null;for(let a=o.firstElementChild;a;a=a.nextElementSibling)if(a.localName===s)return null}else return null;return r}function dx(e){let t=e.contentType;if(t){let n=Object.keys(za);for(let r=0;r<n.length;r++)if(za[n[r]]===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 ff(e,t){let i=e.responseXML;if(!i){let r=new DOMParser,o=e.responseText;if(o!=null){let s=dx(e);if(i=Kr(o,s||"application/xml",r),i&&!s){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Kr(o,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Kr(o,"image/svg+xml",r))}i||(i=Kr(o,"text/html",r))}}let n=i?new pf(t,e.url,i):null;return T(n)}function px(){return new il(ff,"document")}var fx=class Va{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new Va(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new Va(n=>{if(!this.check(n))return!1;let r=new gf([n]);return r=r.child(t),i&&(r=r.predicate(i)),r.size()>0})}},du=new fx(e=>!0),gf=class Ua{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 Ua(i)}forEachNode(t){let i=[],n=r=>{i.push(r)};for(let r=0;r<this.nodes.length;r++)t(this.nodes[r],n);return new Ua(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 r=t(this.nodes[n]);r!=null&&i.push(r)}return i}child(t){return this.forEachNode((i,n)=>{for(let r=i.firstChild;r;r=r.nextSibling)r.nodeType==1&&r.localName==t&&n(r)})}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)}},gx=new Ar(()=>{let e=D("uaStylesheetBase"),t=qp(),i=Ie("user-agent-base.css",vi),n=new wr(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),iv(n.cascade),nl(Uc,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function mx(){return gx.get()}var wx=class extends so{constructor(e,t,i,n,r,o){super(e,t,null,i,n,"counter-style"),this.counterStyleName=r,this.counterStyles=o}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||j.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},yx=class{constructor(e,t,i,n,r,o,s,a,h,l,u){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=r,this.fontFaces=o,this.footnoteProps=s,this.flowProps=a,this.viewportProps=h,this.pageProps=l,this.counterStyleStore=u,c(this,"fontDeobfuscator"),c(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(d){d=d;let p=this,f=p.currentLayoutPosition,g=f.firstFlowChunkOfFlow(d);return p.matchPageSide(f.startSideOfFlow(d))&&f.hasContent(d,p.lookupOffset)&&!!g&&!p.flowChunkIsAfterParentFlowForcedBreak(g)}),this.pageScope.defineName("page-number",new Re(this.pageScope,function(){let d=this;return d.pageNumberOffset+d.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new Re(this.pageScope,function(){let d=this.currentLayoutPosition;return d?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let r=new Vs(this.rootScope,e,t,i),o=ky(r,this.viewportProps),s=o.width,a=o.height,h=o["text-zoom"],l=1;if(s&&a||h){let u=Wt.em;if((h?h.evaluate(r,"text-zoom"):null)===v.scale&&(l=u/i,i=u,e*=l,t*=l),s&&a){let d=at(s.evaluate(r,"width"),r),p=at(a.evaluate(r,"height"),r);if(d>0&&p>0)return{width:n&&n.spreadView?(d+n.pageBorder)*2:d,height:p,fontSize:i}}}}return{width:e,height:t,fontSize:i}}};function pu(e){let t=new Map,i=n=>{n.formattingContext&&!t.has(n.formattingContext)&&t.set(n.formattingContext,n.formattingContext.saveState()),n.shadowSibling&&i(n.shadowSibling)};for(let n in e.flowPositions){let r=e.flowPositions[n];for(let o of r.positions){let s=o.chunkPosition.primary;for(let a of s.steps)i(a);if(o.chunkPosition.floats)for(let a of o.chunkPosition.floats)for(let h of a.steps)i(h)}}return t}function fu(e){for(let[t,i]of e)i!==void 0&&t.restoreState(i)}var Ll=class extends Vs{constructor(e,t,i,n,r,o,s,a,h,l,u,d,p,f){super(e.rootScope,n.width,n.height,n.fontSize),this.style=e,this.xmldoc=t,this.viewport=n,this.clientLayout=r,this.fontMapper=o,this.customRenderer=s,this.fallbackMap=a,this.pageNumberOffset=h,this.documentURLTransformer=l,this.counterStore=u,this.cmykStore=d,c(this,"lang"),c(this,"primaryFlows",{body:!0}),c(this,"rootPageBoxInstance",null),c(this,"styler",null),c(this,"stylerMap",null),c(this,"currentLayoutPosition",null),c(this,"layoutPositionAtPageStart",null),c(this,"currentCascadedPageStyle",null),c(this,"lookupOffset",0),c(this,"faces"),c(this,"pageBoxInstances",{}),c(this,"pageManager",null),c(this,"rootPageFloatLayoutContext"),c(this,"pageBreaks",{}),c(this,"pageProgression",null),c(this,"isVersoFirstPage",!1),c(this,"blankPageAtStart",!1),c(this,"pageSheetSize",{}),c(this,"pageSheetHeight",0),c(this,"pageSheetWidth",0),c(this,"semanticFootnoteFirstRefOffsets",new Map),c(this,"semanticFootnoteFirstRefOffsetsInitialized",{value:!1}),c(this,"pageGroupPageCounts",Object.create(null)),c(this,"currentPageGroupDocument",null),this.lang=t.lang||i,this.faces=new f0(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new ln(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!f;for(let g in e.flowProps){let m=e.flowProps[g],w=me(m,"flow-consume");w&&(w.evaluate(this,"flow-consume")==v.all?this.primaryFlows[g]=!0:delete this.primaryFlows[g])}}init(){let e=D("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 Jh(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,t,i,this.style.counterStyleStore,this.cmykStore),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=af(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new B0(r);let o=this.style.cascade.createInstance(this,t,i,this.lang,this.style.counterStyleStore,this.cmykStore);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(o,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new J0(o,this.style.pageScope,this.rootPageBoxInstance,this,n);let s=[];for(let h of this.style.fontFaces){if(h.condition&&!h.condition.evaluate(this))continue;let l=p0(h.properties,this),u=new Yp(l);s.push(u)}this.fontMapper.findOrLoadFonts(s,this.faces).then(()=>{v0(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),this.styler.cascade.applyCmykFilter(l);let u=uu(Xo(l),this);this.pageSheetSize[h]={width:u.pageWidth+u.cropOffset*2,height:u.pageHeight+u.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 Vs(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),r=this.counterStore.createCounterListener(e.url),o=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new Jh(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,r,o,i.counterStyleStore,this.cmykStore),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 jw,i.flowPositions[e.flowName]=n);let r=Hw(e.element),o=new Ei(r),s=new Gw(o,e);n.positions.push(s)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;let n=!0;class r{unknownProperty(h,l){n=!1}invalidPropertyValue(h,l){n=!1}simpleProperty(h,l,u){}}let o=new r,s=Rr(this.style.rootScope,new Vt(t,null),"");return s?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,s,!1,o),n):!1}evalSupportsSelector(e){class t extends mf{errorMsg(...s){}}let i=new t(null),n=Pc(e),r=new Vt(n+"{}",i);return new Fr(ze,r,i,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!i.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,r=n.steps[0].node,o=n.offsetInNode,s=n.after,a=0;for(;r.ownerDocument!=this.xmldoc.document;)a++,r=n.steps[a].node,s=!1,o=0;let h=this.xmldoc.getNodeOffset(r,o,s);h<t&&(t=h)}return t}getNodePositionOffset(e){let t=e.steps[0].node,i=e.offsetInNode,n=e.after,r=0;for(;t.ownerDocument!=this.xmldoc.document;)r++,t=e.steps[r].node,n=!1,i=0;return this.xmldoc.getNodeOffset(t,i,n)}getPageStartOffset(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r)for(let o=0;o<r.positions.length;o++){let s=r.positions[o].chunkPosition.primary,a=this.getNodePositionOffset(s);a<i&&(i=a)}}return i}getPageStartCounterOffsets(e){let t=this.getPageStartOffset(e);if(!isFinite(t))return{counterOffset:t,changeOffset:t};let i=this.xmldoc.body||this.xmldoc.root,n=i?this.getFirstInFlowElementAtOrAfter(i,t):null,r=i?this.xmldoc.getElementOffset(i):t,o=t<=r,s=n===i&&o?this.getFirstInFlowChildElement(i):n;if(!s)return{counterOffset:t,changeOffset:t};let a=this.xmldoc.getElementOffset(s),h=t;return o&&a!==t&&(h=a),a===t&&(this.isInlineLevelElement(s)?h=Math.max(0,t-1):h=this.getDeepestFirstInFlowChildOffset(s)),{counterOffset:h,changeOffset:a}}getPageStartElement(e,t=this.getPageStartOffset(e)){if(!isFinite(t))return null;let i=this.xmldoc.body||this.xmldoc.root;if(!i)return null;let n=this.getFirstInFlowElementAtOrAfter(i,t),r=this.xmldoc.getElementOffset(i),o=t<=r;return n===i&&o?this.getFirstInFlowChildElement(i):n}isForcedPageBreakValue(e){return qe(e)&&e!=="column"&&e!=="region"}hasForcedPageBreakBefore(e){let t=me(e,"break-before");if(!t)return!1;let i=t.evaluate(this,"break-before").toString();return this.isForcedPageBreakValue(i)}getExplicitPageType(e){let t=me(e,"page");if(!t)return null;let i=t.evaluate(this,"page").toString();return!i||i.toLowerCase()==="auto"?null:i}getPageGroupPageType(e){let t=this.styler.getStyle(e,!1);return t?this.getExplicitPageType(t):null}getPreviousInFlowSibling(e){let t=e.previousElementSibling;for(;t;){if(this.isNormalFlowElement(t))return t;t=t.previousElementSibling}return null}getFirstDocumentFlowElement(){let e=this.xmldoc.body||this.xmldoc.root;if(!e)return null;let t=this.xmldoc.getElementOffset(e),i=this.getFirstInFlowElementAtOrAfter(e,t);return i===e?this.getFirstInFlowChildElement(e):i}resolveFirstPageType(){let e=this.getFirstDocumentFlowElement();return e?this.getPageGroupPageType(e):null}shouldStartPageGroup(e,t,i){let n=this.styler.getStyle(e,!1);if(!n)return!1;if(this.getFirstDocumentFlowElement()===e)return!0;let r=this.xmldoc.getElementOffset(e),o=this.xmldoc.body||this.xmldoc.root,s=this.xmldoc.getElementOffset(o);if(i<=s&&e===o||!this.getPreviousInFlowSibling(e)&&i===r)return!0;if(r!==i)return!1;if(this.hasForcedPageBreakBefore(n))return!0;let a=this.getPreviousInFlowSibling(e);if(!a)return!1;let h=this.styler.getStyle(a,!1);return h?this.getExplicitPageType(h)!==t:!1}updatePageGroupPageIndices(e){let t=this.pageManager.pageCascadeInstance;t.pageTypePageIndices=Object.create(null);let i=e.startSideOfFlow("body"),n=e.flowPositions.body,r=!!(n&&n.positions.length),o=Nn(i)&&!this.matchPageSide(i)&&!r,s=!(this.blankPageAtStart&&e.page===1)&&!e.isBlankPage&&!o,a=this.getPageStartOffset(e),h=this.getPageStartElement(e,a);if(!h)return;let l=h.ownerDocument,u=this.currentPageGroupDocument!==l&&s;u&&(this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=l);let d=h;for(;d;){let p=this.getPageGroupPageType(d);if(p){let f=this.pageGroupPageCounts[p]||(this.pageGroupPageCounts[p]=new Map),g=f.get(d)||0;(g>0||s&&(u||this.shouldStartPageGroup(d,p,a)))&&(g+=1,f.set(d,g),(t.pageTypePageIndices[p]||(t.pageTypePageIndices[p]=[])).push(g))}if(d===this.xmldoc.root)break;d=d.parentElement}}getFirstInFlowElementAtOrAfter(e,t){if(this.isNormalFlowElement(e)&&this.xmldoc.getElementOffset(e)>=t)return e;let i=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:n=>{let r=n;return this.isNormalFlowElement(r)?this.xmldoc.getElementOffset(r)<t?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}}).firstChild();return i??null}getDeepestFirstInFlowChildOffset(e){let t=e;for(;;){let i=this.getFirstInFlowChildElement(t);if(!i)return this.xmldoc.getElementOffset(t);t=i}}getFirstInFlowChildElement(e){let t=e.firstChild;for(;t;){if(t.nodeType===Node.TEXT_NODE){if(!Le(t))return null;t=t.nextSibling;continue}if(t.nodeType!==Node.ELEMENT_NODE){t=t.nextSibling;continue}let i=t;if(this.isNormalFlowElement(i))return i;t=t.nextSibling}return null}isNormalFlowElement(e){var t,i;let n=this.styler.getStyle(e,!1);if(this.getDisplayValue(e)===v.none)return!1;let r=(t=n?.position)==null?void 0:t.evaluate(this.styler.context,"position"),o=r&&!Z(r)?r:v.static;if(To(o)||is(o))return!1;let s=(i=n?.float)==null?void 0:i.evaluate(this.styler.context,"float");return(s&&!Z(s)?s:v.none)===v.none}isInlineLevelElement(e){return Ht(this.getDisplayValue(e))}getDisplayValue(e){var t;let i=this.styler.getStyle(e,!1),n=(t=i?.display)==null?void 0:t.evaluate(this.styler.context,"display");return n&&!Z(n)?n:v.inline}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r){let o=this.getConsumedOffset(r);o<i&&(i=o)}}return i}dumpLocation(e){j.debug("Location - page",this.currentLayoutPosition.page),j.debug(" current:",e),j.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)j.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new Ze(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 r=i.positions[0].flowChunk.breakBefore,o=i.startBreakType;i.startBreakType=kh(tt(o,r))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,r;for(let o=0;o<n.length;o++){if(r=n[o],r.pageBox.pseudoName===Rl)continue;let s=1;r.pageBox.pseudoName===Tl&&!(this.actualPageWidth&&this.actualPageHeight)&&(s=1/0);let a=r.getProp(this,"utilization");a&&a.isNum()&&(s=a.num);let h=this.queryUnitSize("em",!1),l=this.pageWidth()*this.pageHeight(),u=Math.ceil(s*l/(h*h)),d=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,u),this.styler.cascade.currentPageType=d,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let p=r.getProp(this,"enabled");if(!p||p===v._true){if(t.page===1&&this.blankPageAtStart){r.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(r,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,r=t[i].forcedBreakOffsets;if(!r.length||n<r[0])return!1;let o=ai(r.length,l=>r[l]>n)-1,s=r[o],a=this.layoutPositionAtPageStart.flowPositions[i],h=this.getConsumedOffset(a);return s<h?!1:h<s?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new cl(null)),e.flowRootFormattingContext=i.formattingContext}beginIsolatedRootPageFloatLayoutContext(){let e=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=new ln(null,null,null,null,null,null,null),e}endIsolatedRootPageFloatLayoutContext(e){this.rootPageFloatLayoutContext=e}hasActiveRootPageFloatLayoutContext(){return this.rootPageFloatLayoutContext.getDeferredPageFloatContinuations().length>0||this.rootPageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0||this.rootPageFloatLayoutContext.getFloatsDeferredToNextInChildContexts().length>0}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=this.counterStore.currentPageCountersStack.length>0,r=h=>{var l,u;if(!n||h.floatReference!==Te.PAGE)return!1;let d=((u=(l=this.layoutPositionAtPageStart)==null?void 0:l.flowPositions)==null?void 0:u.body)||null,p=d?this.getConsumedOffset(d):Number.NaN,f=isFinite(p)?p:this.getPageStartOffset(this.layoutPositionAtPageStart,!0),g=this.xmldoc.getNodeOffset(h.nodePosition.steps[0].node,0,!1);return g!=null&&isFinite(f)&&g>f},o=D("layoutDeferredPageFloats"),s=!1,a=0;return o.loopWithFrame(h=>{if(a===i.length){h.breakLoop();return}let l=i[a++],u=l.float;if(r(u)){h.breakLoop();return}let d=new Tn().findByFloat(u),p=d.findPageFloatFragment(u,t);if(p&&p.hasFloat(u)){h.continueLoop();return}else if(t.isForbidden(u)||t.hasPrecedingFloatsDeferredToNext(u)){t.deferPageFloat(l),h.breakLoop();return}e.layoutPageFloatInner(l,d,null,p).then(f=>{if(!f){h.breakLoop();return}let g=t.parent.isInvalidated();if(g){h.breakLoop();return}else t.isInvalidated()&&!g&&(s=!0,t.validate());h.continueLoop()})}).then(()=>{s&&t.invalidate(),o.finish(!0)}),o.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 Ei(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 i?(this.setFormattingContextToColumn(e,t),e.init(),this.layoutDeferredPageFloats(e)):T(!0);this.setFormattingContextToColumn(e,t),e.init(),this.primaryFlows[t]&&e.bands.length>0&&(e.forceNonfitting=!1);let n=D("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let r=[],o=[],s=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-o.length>0;){let h=0;for(;o.includes(h);)h++;let l=i.positions[h];if(l.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(l.flowChunk))break;for(let p=h+1;p<i.positions.length;p++){if(o.includes(p))continue;let f=i.positions[p];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(l.flowChunk)&&(l=f,h=p)}let u=l.flowChunk,d=!0;if(e.layout(l.chunkPosition,s,i.breakAfter).then(p=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(s=!1,l.flowChunk.repeated&&(p===null||u.exclusive)&&r.push(h),u.exclusive){o.push(h),a.breakLoop();return}else{let f=!!p||!!e.pageBreakType,g=this.getLastAfterPositionIfDeferredFloatsExists(e,p);if(!p&&e.pageBreakType&&i.positions.length-o.length-1<=0&&(e.pageBreakType=null),e.pageBreakType&&g?(l.chunkPosition=g,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(o.push(h),(p||g)&&(l.chunkPosition=p||g,r.push(h)),i.startBreakType=kh(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,d?d=!1:a.continueLoop()}),d){d=!1;return}}a.breakLoop()}).then(()=>{var a;if(!e.pageFloatLayoutContext.isInvalidated()){i.positions=i.positions.filter((l,u)=>r.includes(u)||!o.includes(u)),i.breakAfter==="column"&&(i.breakAfter=null),e.saveDistanceToBlockEndFloats();let h=e.pageFloatLayoutContext.getMaxReachedAfterEdge();if(e.updateMaxReachedAfterEdge(h),e.computedBlockSize===0){let l=e.pageFloatLayoutContext,u=l;for(;u;){let d=u.floatFragments.filter(p=>"isFootnote"in p.area&&p.area.isFootnote);if(d.length>0&&!u.ignoreFootnoteAreaMaxHeight&&d.some(p=>{let f=getComputedStyle(p.area.element),g=m=>m!==""&&m!=="none";return g(f.getPropertyValue("max-block-size"))||g(p.area.vertical?f.maxWidth:f.maxHeight)})){u.ignoreFootnoteAreaMaxHeight=!0;for(let p of d){l.removePageFloatFragment(p,!0);let f=(a=p.continuations[0])==null?void 0:a.float;f&&u.removeFloatDeferredToNext(f)}l.invalidate();break}u=u.parent}}}n.finish(!0)})}),n.result()}createLayoutConstraint(e){let t=this.currentLayoutPosition.page-1,i=this.counterStore.createLayoutConstraint(t);return new kv([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,r,o,s,a,h,l,u,d,p,f){let g=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth||e.isAutoHeight:e.isAutoHeight&&e.isTopDependentOnAutoHeight||e.isAutoWidth,m=r.element,w=new ln(a,Te.COLUMN,null,s,null,null,null),x=this.currentLayoutPosition.clone(),y=D("createAndLayoutColumn"),b;return y.loopWithFrame(S=>{let C=this.createLayoutConstraint(w);if(h>1){let N=this.viewport.document.createElement("div");if(I(N,"position","absolute"),m.appendChild(N),b=new Vo(N,p,this.clientLayout,C,w),b.isNonFirstColumn=o>0,b.forceNonfitting=f,b.vertical=r.vertical,b.rtl=r.rtl,b.snapHeight=r.snapHeight,b.snapWidth=r.snapWidth,r.vertical){let F=(r.rtl?h-o-1:o)*(u+l)+r.paddingTop,B=parseFloat(m.style.width);b.setHorizontalPosition(r.paddingLeft+B-r.width,r.width),b.setVerticalPosition(F,u)}else{let F=(r.rtl?h-o-1:o)*(u+l)+r.paddingLeft;b.setVerticalPosition(r.paddingTop,r.height),b.setHorizontalPosition(F,u)}b.originX=t,b.originY=i}else b=new Vo(m,p,this.clientLayout,C,w),b.isNonFirstColumn=!1,b.copyFrom(r);b.exclusions=g?[]:n.concat(),b.innerShape=d,w.setContainer(b),(b.vertical?b.height:b.width)>=0?this.layoutColumn(b,s).then(()=>{w.isInvalidated()||w.finish(),b.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(b.pageFloatLayoutContext.validate(),this.currentLayoutPosition=x.clone(),b.element!==m&&m.removeChild(b.element),S.continueLoop()):S.breakLoop()}):(w.finish(),S.breakLoop())}).then(()=>{y.finish(b)}),y.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof uf||t instanceof Il&&!(t instanceof Cn))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof Fn;let r=t.getProp(this,"writing-mode")||null,o=t.getProp(this,"direction")||null;return new ln(e,Te.REGION,i,n,null,r,o)}layoutFlowColumnsWithBalancing(e,t,i,n,r,o,s,a,h){let l=this.currentLayoutPosition.clone(),u=this.getRegionPageFloatLayoutContext(o,t,s,a),d=!0,p=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,r,o,u,s,a,h,d).thenAsync(f=>T(f?{columns:f,position:this.currentLayoutPosition}:null)));return p().thenAsync(f=>{if(!f)return T(null);if(h<=1)return T(f.columns);let g=t.getProp(this,"column-fill")||v.balance,m=this.currentLayoutPosition.flowPositions[a],w=db(h,g,p,u,s,f.columns,m);return w?(d=!1,o.lock(),u.lock(),w.balanceColumns(f).thenAsync(x=>(o.unlock(),o.validate(),u.unlock(),this.currentLayoutPosition=x.position,T(x.columns)))):T(f.columns)})}layoutFlowColumns(e,t,i,n,r,o,s,a,h,l,u){let d=D("layoutFlowColumns"),p=this.currentLayoutPosition.clone(),f=pu(this.currentLayoutPosition),g=t.getPropAsNumber(this,"column-gap"),m=l>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,w=t.getActiveRegions(this),x=t.getProp(this,"shape-inside"),y=Sc(x,0,0,a.width,a.height,this),b=new N0(h,this,this.viewport,this.styler,w,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.style.pageProps,this.currentCascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized),S=0,C=null,N=[];return d.loopWithFrame(F=>{this.createAndLayoutColumn(t,i,n,r,a,S++,h,s,l,g,m,y,b,u).then(B=>{if(o.isInvalidated()){N=null,F.breakLoop();return}if((B.pageBreakType&&B.pageBreakType!=="column"||S===l)&&!s.isInvalidated()&&s.finish(),s.isInvalidated()){S=0,this.currentLayoutPosition=p.clone(),fu(f),s.validate(),s.isLocked()?(N=null,F.breakLoop()):F.continueLoop();return}C=B,N[S-1]=C,C.pageBreakType&&C.pageBreakType!="column"&&(S=l,C.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),S<l?F.continueLoop():F.breakLoop()})}).then(()=>{d.finish(N)}),d.result()}layoutContainer(e,t,i,n,r,o,s){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==v._true)return T(!0);let h=D("layoutContainer"),l=t.getProp(this,"wrap-flow")===v.auto,u=t.getProp(this,"flow-from"),d=this.viewport.document.createElement("div");d.role=t instanceof cf?"complementary":"presentation";let p=t.getProp(this,"position");I(d,"position",p?p.name:"absolute");let f=t instanceof Cn;t instanceof Fn?i.appendChild(d):i.insertBefore(d,i.firstChild);let g=new Cd(d);g.vertical=t.vertical,g.rtl=t.rtl,g.borderBoxSizing=t.borderBoxSizing,g.exclusions=o,t.prepareContainer(this,g,e,this.faces,this.clientLayout),t instanceof Cn&&(g.width<=0||g.height<=0)&&j.warn("Negative or zero page area size"),g.originX=n,g.originY=r,n+=g.left+g.marginLeft+g.borderLeft,r+=g.top+g.marginTop+g.borderTop,this.setPagePageFloatLayoutContextContainer(s,t,g);let m,w=!1;if(!u||!u.isIdent()){let x=[],y=t.getProp(this,"content");if(y instanceof G&&y.expr instanceof Re&&y.expr.str.startsWith("running-element-"))y.visit(new gr(d,this,y,this.counterStore.getExprContentListener()));else if(kt(y)){let b="span";y instanceof ut&&(b="img");let S=this.viewport.document.createElement(b);y.visit(new gr(S,this,y,this.counterStore.getExprContentListener())),d.appendChild(S),b=="img"&&t.transferSingleUriContentProps(this,S,this.faces),t.transferContentProps(this,g,e,this.faces);let C=S.querySelectorAll("img[src]");for(let F=0;F<C.length;F++){let B=C[F],U=B.getAttribute("src");if(!U)continue;let q=vt(B,U);x.push(q),e.fetchers.push(q)}let N=S.getAttribute("src");if(N){let F=S.querySelector("img");F||(F=S);let B=vt(F,N);x.push(B),e.fetchers.push(B)}b=="span"&&mv(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(d),w=!0);w||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=x.length?En(x).thenReturn(!0):T(!0)}else if(this.pageBreaks[u.toString()])s.isInvalidated()||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=T(!0);else{let x=D("layoutContainer.inner"),y=u.toString(),b=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,r,o,s,g,y,b).then(S=>{if(!s.isInvalidated()){let C=S[0];C.element===d&&(g=C),g.computedBlockSize=Math.max.apply(null,S.map(F=>F.computedBlockSize)),t.finishContainer(this,g,e,C,b,this.clientLayout,this.faces);let N=this.currentLayoutPosition.flowPositions[y];N&&N.breakAfter==="region"&&(N.breakAfter=null)}x.finish(!0)}),m=x.result()}return m.then(()=>{if(s.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(g.computedBlockSize)>0){if(!w&&!l){let y=t.getProp(this,"shape-outside"),b=g.getOuterShape(y,this);o.push(b)}}else if(t.children.length==0){i.removeChild(d),h.finish(!0);return}let x=f?0:t.children.length-1;h.loop(()=>{for(;x>=0&&x<t.children.length;){let y=t.children[f?x++:x--],b=this.layoutContainer(e,y,d,n,r,o,s);if(b.isPending())return b.thenAsync(()=>T(!s.isInvalidated()));if(s.isInvalidated())break}return T(!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 r=i.positions[n];r.flowChunk.startPage>=0&&r.flowChunk.startPage+r.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 r=i.positions[n];r.flowChunk.startPage<0&&r.flowChunk.startOffset<this.lookupOffset&&(r.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,n,r,o;let s=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new Xw,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let a=1e4;if(t.page>a)throw new Error(`Too many pages generated (over ${a} pages)`);let h=t.startSideOfFlow("body");t.isBlankPage=Nn(h)&&this.matchPageSide(h),e.isBlankPage=t.isBlankPage,t.page++,e.pageType==null&&(e.pageType=(n=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:t.page===1?this.resolveFirstPageType():null)!=null?n:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.updatePageGroupPageIndices(t),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let l=pu(t),u=s?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.currentCascadedPageStyle=u,this.styler.cascade.applyVarFilter([u],this.styler,null),this.styler.cascade.applyCalcFilter(u,this.styler.context),this.styler.cascade.applyCmykFilter(u),!s){let x=new Ze(this.style.pageScope,"left-page");e.side=x.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let d=this.selectPageMaster(u);if(!d)return T(null);let p=0;if(!s){e.setAutoPageWidth(d.pageBox.specified.width.value===Pr),e.setAutoPageHeight(d.pageBox.specified.height.value===Nr);let{counterOffset:x,changeOffset:y}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(x)||(x=this.lookupOffset,y=this.lookupOffset),isFinite(x)&&this.styler.styleUntil(x,0);let b=this.styler.getCounterSnapshotAtOffset(x),S=y===x?b:this.styler.getCounterSnapshotAtOffset(y);b||(b=this.styler.getLastCounterSnapshot()),S||(S=b),this.counterStore.setCurrentPageDocCounters((r=b?.counters)!=null?r:null,(o=S?.changes)!=null?o:null,S?.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(u,this);let C=uu(Xo(u),this);this.setPageSizeAndBleed(C,e),G0(u,C,e,this),p=C.bleedOffset+C.bleed}let f=!s&&d.getProp(this,"writing-mode")||v.horizontal_tb;this.pageVertical=f!=v.horizontal_tb;let g=d.getProp(this,"direction")||v.ltr,m=new ln(this.rootPageFloatLayoutContext,Te.PAGE,null,null,null,f,g),w=D("layoutNextPage");return w.loopWithFrame(x=>{this.layoutContainer(e,d,e.bleedBox,p,p,[],m).then(()=>{if(m.isInvalidated()||m.finish(),m.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),fu(l),m.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);x.continueLoop()}else x.breakLoop()})}).then(()=>{d.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(y=>{let b=t.flowPositions[y],S=b.breakAfter;S&&(S==="page"||!this.matchPageSide(S))&&(b.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let x=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(x,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),w.finish(t)}),w.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.right=`${e.bleedOffset}px`,t.bleedBox.style.top=`${e.bleedOffset}px`,t.bleedBox.style.bottom=`${e.bleedOffset}px`,t.bleedBox.style.padding=`${e.bleed}px`}},vx=class $a extends wr{constructor(t,i,n,r){super(t.rootScope,t,i,n,r,t.validatorSet,!n),this.masterHandler=t,c(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let r=new Jp(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new D0(r.scope,this.masterHandler,r,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=Mt(this.scope,this.condition,i)),this.masterHandler.pushHandler(new $a(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new lv(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new so(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new wx(this.scope,this.owner,{},this.masterHandler.validatorSet,t,this.masterHandler.counterStyles))}startFlowRule(t){let i=this.masterHandler.flowProps[t];i||(i={},this.masterHandler.flowProps[t]=i),this.masterHandler.pushHandler(new so(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new so(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=ei(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new df(this.scope,this.owner,this.masterHandler.validatorSet,i))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new ux(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(wr.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let t=`R${this.masterHandler.regionCount++}`;this.special("region-id",M(t)),this.endRule();let i=new $a(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},mf=class extends Ks{constructor(e){super(),this.validatorSet=e,c(this,"rootScope"),c(this,"pageScope"),c(this,"rootBox"),c(this,"cascadeParserHandler"),c(this,"regionCount",0),c(this,"fontFaces",[]),c(this,"counterStyles",new Xb),c(this,"footnoteProps",{}),c(this,"flowProps",{}),c(this,"viewportProps",[]),c(this,"pageProps",{}),this.rootScope=new zs(null),this.pageScope=new zs(this.rootScope),this.rootBox=new F0(this.rootScope),this.cascadeParserHandler=new vx(this,null,null,null),this.slave=this.cascadeParserHandler}};function bx(e,t){return t.parseOPSResource(e)}var xx=class extends il{constructor(e){super(bx,"document"),this.fontDeobfuscator=e,c(this,"styleByKey",{}),c(this,"styleFetcherByKey",{}),c(this,"styleByDocURL",{}),c(this,"triggersByDocURL",{}),c(this,"validatorSet",null),c(this,"styleSheets",[]),c(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=D("OPSDocStore.init");return this.validatorSet=qp(),mx().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=Ie(yn(t),Ui)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ie(yn(t),Ui)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=D("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return ff(e,this).then(r=>{var o;if(!r){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=Dt("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](r.document)}catch(g){j.warn("Error during single document preprocessing:",g)}}let s=[],a=r.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let p=0;p<a.length;p++){let f=a[p],g=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),m=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),w=f.getAttribute("action"),x=f.getAttribute("ref");g&&m&&w&&x&&s.push({observer:g,event:m,action:w,ref:x})}this.triggersByDocURL[i]=s;let h=[];if(h.push({url:Ie("user-agent-page.css",vi),text:Vc,flavor:"UA",classes:null,media:null}),h.push({url:Ie("user-agent-counter-styles.css",vi),text:Wc,flavor:"UA",classes:null,media:null}),n)h.push({url:Ie("user-agent-toc.css",vi),text:$c,flavor:"UA",classes:null,media:null});else{let p=r.document.querySelectorAll("style, link, meta");for(let f of p){let g=f.namespaceURI,m=f.localName;if(g=="http://www.w3.org/1999/xhtml")if(m=="style"){let w=f.getAttribute("class"),x=f.getAttribute("media"),y=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:y?w:null,media:x})}else if(m=="link"){let w=f.getAttribute("href"),x=(o=f.getAttribute("rel"))==null?void 0:o.split(/\s+/),y=f.getAttribute("class"),b=f.getAttribute("media");if(w&&x!=null&&x.includes("stylesheet")&&(!x.includes("alternate")||y)){let S=Ie(w,i),C=f.getAttribute("title");h.push({url:S,text:null,classes:C?y:null,media:b,flavor:"Author"})}}else m=="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 p=0;p<h.length;p++)l+=h[p].url,l+="^",h[p].text&&(l+=h[p].text),l+="^";let u=this.styleByKey[l];if(u){this.styleByDocURL[i]=u,t.finish(r);return}let d=this.styleFetcherByKey[l];d||(d=new Ar(()=>{let p=D("fetchStylesheet"),f=0,g=new mf(this.validatorSet);return p.loop(()=>{if(f<h.length){let m=h[f++];return g.startStylesheet(m.flavor),m.text!==null?nl(m.text,g,m.url,m.classes,m.media).thenReturn(!0):Kc(m.url,g,m.classes,m.media)}return T(!1)}).then(()=>{let m=g.cascadeParserHandler.finish();u=new yx(this,g.rootScope,g.pageScope,m,g.rootBox,g.fontFaces,g.footnoteProps,g.flowProps,g.viewportProps,g.pageProps,g.counterStyles),this.styleByKey[l]=u,delete this.styleFetcherByKey[l],p.finish(u)}),p.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[l]=d,d.start()),d.get().then(p=>{this.styleByDocURL[i]=p,t.finish(r)})}),t.result()}processViewportMeta(e){return""}},cr="\u25B8",gu="\u25BE",Sx="\u25B9";function Ol(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(o=>o.contains(n)))continue;let r=n;/^h[1-6]$/.test(r.localName)&&(r.previousElementSibling?r=r.nextElementSibling:r=r.parentElement),r&&r.querySelector("li a[href]")&&t.push(r)}return t}function Cx(e){let t=Ol(e),i=[];for(let n of t)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var kx=class{constructor(e,t,i,n,r,o,s,a,h,l,u){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=r,this.rendererFactory=s,this.fallbackMap=a,this.documentURLTransformer=h,this.counterStore=l,this.cmykStore=u,c(this,"pref"),c(this,"page",null),c(this,"instance",null),this.pref=Vu(o),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;mi(n,"height","auto")!="auto"&&(I(n,"height","auto"),this.setAutoHeight(n,t)),mi(n,"position","static")=="absolute"&&(I(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,r)=>{let o=r.behavior;if(o)switch(o.toString()){case"toc-node-anchor":r.color=v.inherit,r["text-decoration"]=v.none;break;case"toc-node":r.display=v.block,r.margin=Fe,r.padding=Fe,r["padding-inline-start"]=new R(1.25,"em");break;case"toc-node-first-child":r.display=v.inline_block,r.margin=new R(.2,"em"),r["vertical-align"]=v.top,r.color=v.inherit,r["text-decoration"]=v.none;break;case"toc-container":r.padding=Fe;break}if(!o||o.toString()!="toc-node"&&o.toString()!="toc-container")return t(i,n,r);let s=i.firstChild;s&&s.nodeType!==1&&Le(s)&&i.replaceChild(i.ownerDocument.createComment(s.textContent),s);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=cr&&(l.textContent=cr,I(l,"cursor","pointer"),l.addEventListener("click",Ex,!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"),o.toString()=="toc-node"){let l=n.ownerDocument.createElement("div");if(l.textContent=Sx,I(l,"margin","0.2em 0 0 -1em"),I(l,"margin-inline-start","-1em"),I(l,"margin-inline-end","0"),I(l,"display","inline-block"),I(l,"width","1em"),I(l,"text-align","center"),I(l,"vertical-align","top"),I(l,"cursor","default"),I(l,"font-family","Menlo,sans-serif"),h.appendChild(l),I(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){I(h,"height","0px");let u=i.firstElementChild;u&&u.localName==="a"&&(u.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 T(h)}}showTOC(e,t,i,n,r){if(this.page)return T(this.page);let o=D("showTOC"),s=new fd(e,e);this.page=s;let a=Bt(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of Ol(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),u=l.sizeViewport(i,1e5,r);t=new jo(t.window,u.fontSize,0,e,u.width,u.height);let d=this.makeCustomRenderer(h),p=new Ll(l,h,this.lang,t,this.clientLayout,this.fontMapper,d,this.fallbackMap,0,this.documentURLTransformer,this.counterStore,this.cmykStore);this.instance=p,p.pref=this.pref,p.init().then(()=>{p.layoutNextPage(s,null).then(()=>{this.setAutoHeight(e,2),o.finish(s)})})}),o.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 r=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(r).map(t)}function t(n){let r=new URL(n.href),[,o]=r.hash.match(/^#?(.*)$/),s=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=e(a);return{id:o,title:s,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function Ex(e){let t=e.target,i=t.textContent==cr;t.textContent=i?gu:cr;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let r=n.firstChild;for(;r;){if(r.nodeType===1){let o=r,s=o.getAttribute("data-adapt-class");if(s==="toc-container"){if(o.setAttribute("aria-hidden",i?"false":"true"),o.firstChild){r=o.firstChild;continue}}else if(s==="toc-node"&&(o.style.height=i?"auto":"0px",o.children.length>=2&&(o.children[1].tabIndex=i?0:-1),o.children.length>=3&&(o.children[0].tabIndex=i?0:-1,!i))){let a=o.children[0];if(a.textContent==gu){a.textContent=cr,a.setAttribute("aria-expanded","false"),o.setAttribute("aria-expanded","false"),r=o.children[2];continue}}}for(;!r.nextSibling&&r.parentNode!==n;)r=r.parentNode;r=r.nextSibling}e.stopPropagation()}function Jr(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function Px(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=new Map(e[i])}),t}function Nx(e){return/\.(x?html?|xht|svg)(?:[#?]|$)/i.test(e)||/^(?:about:|data:|blob:)/i.test(Bt(e))}var mu=class extends xx{constructor(){super(null),c(this,"plainXMLStore"),c(this,"jsonStore"),c(this,"opfByURL",{}),c(this,"primaryOPFByEPubURL",{}),c(this,"deobfuscators",{}),c(this,"documents",{}),this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=px(),this.jsonStore=iw()}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)}loadWebPubManifest(e,t){this.loadAsJSON(e,!0).then(i=>{if(!i){this.reportLoadError(e),t.finish(null);return}let n=new xo(this,e);n.initWithWebPubManifest(i,void 0,e).then(()=>{t.finish(n)})})}loadPubDoc(e){let t=D("loadPubDoc");if(/\.opf(?:[#?]|$)/i.test(e)){let[,i,n]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(i,n).thenFinish(t)}else/\.json(?:ld)?(?:[#?]|$)/i.test(e)?this.loadWebPubManifest(e,t):Nx(e)?this.loadWebPub(e).then(i=>{if(i){t.finish(i);return}this.reportLoadError(e),t.finish(null)}):es(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}j.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"){let[,n,r]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,r).thenFinish(t)}else i.contentType=="application/ld+json"||i.contentType=="application/webpub+json"||i.contentType=="application/audiobook+json"||i.contentType=="application/json"?this.loadWebPubManifest(e,t):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(r=>{if(r){t.finish(r);return}this.reportLoadError(e),t.finish(null)})})});return t.result()}loadEPUBDoc(e){let t=D("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 r=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let o of r)if(o){this.loadOPF(e,o).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return T(n);let r=D("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(o=>{o?(n=new xo(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(s=>{n.initWithXMLDoc(o,s).then(()=>{r.finish(n)})}):n.initWithXMLDoc(o,null).then(()=>{r.finish(n)})):this.reportLoadError(i)}),r.result()}loadWebPub(e){let t=D("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e),t.finish(null);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,r=new xo(this,e),o=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(o){let s=o.getAttribute("href");if(/^#/.test(s)){let a=ja(n.getElementById(s.substr(1)).textContent);r.initWithWebPubManifest(a,n).then(()=>{t.finish(r)})}else{let a=Ie(o.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{r.initWithWebPubManifest(h,n,a).then(()=>{t.finish(r)})})}}else r.initWithWebPubManifest({},n).then(()=>{r.toc&&r.toc.src===i.url&&Ol(n).length===0&&(r.toc=null),t.finish(r)})}}),t.result()}addDocument(e,t){let i=D("EPUBDocStore.load"),n=Bt(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(Ui)||Object.keys(this.resources).find(r=>this.resources[r]&&t(r)===n)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?j.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&Ui.startsWith("https:")&&!/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(?:[/?#]|$)/.test(e)?j.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?j.error(`Failed to load ${e}. This may be caused by network error, incorrect URL, or the server not allowing cross-origin resource sharing (CORS).`):j.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Bt(e),i=this.documents[t];if(i)return i.isPending()?i:T(i.get());{let n=D("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(r=>{r?n.finish(r):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 r=i.width-0,o=i.height-0;if(r&&o){let s=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${r}px;height:${o}px;}`+(s?`@page{size:${r}px ${o}px;margin:0;}`:"@page{margin:0;}")}return""}},wu=class{constructor(){c(this,"id",null),c(this,"src",""),c(this,"mediaType",null),c(this,"title",null),c(this,"itemRefElement",null),c(this,"spineIndex",-1),c(this,"compressedSize",0),c(this,"compressed",null),c(this,"epage",0),c(this,"epageCount",0),c(this,"startPage",null),c(this,"skipPagesBefore",null),c(this,"itemProperties"),this.itemProperties=eg}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Ie(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=ag(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 Tx(e){return e.id}function Ix(e){return t=>{let i=D("deobfuscator");return Ax("SHA-1",e).then(n=>{let r=t.slice(0,1040),o=t.slice(1040,t.size);Qm(r).then(s=>{let a=new DataView(s);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(Gc([a,o]))})}),i.result()}}function Ax(e,t){let i=D("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(r=>{n.schedule(new Uint8Array(r))}),i.result()}var yi={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"},er="http://idpf.org/epub/vocab/package/meta/#",je={language:`${yi.dcterms}language`,title:`${yi.dcterms}title`,creator:`${yi.dcterms}creator`,layout:`${yi.rendition}layout`,titleType:`${er}title-type`,displaySeq:`${er}display-seq`,alternateScript:`${er}alternate-script`,role:`${er}role`};function Fx(e,t){let i={};return(n,r)=>{var o,s,a,h,l,u;let d,p,f=n.r||i,g=r.r||i;if(e==je.title&&(d=((o=f[je.titleType])==null?void 0:o[0].v)=="main",p=((s=g[je.titleType])==null?void 0:s[0].v)=="main",d!=p))return d?-1:1;let m=parseInt((a=f[je.displaySeq])==null?void 0:a[0].v,10);isNaN(m)&&(m=Number.MAX_VALUE);let w=parseInt((h=g[je.displaySeq])==null?void 0:h[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),m!=w?m-w:e!=je.language&&t&&(d=((l=f[je.language]||f[je.alternateScript])==null?void 0:l[0].v)==t,p=((u=g[je.language]||g[je.alternateScript])==null?void 0:u[0].v)==t,d!=p)?d?-1:1:n.o-r.o}}function Rx(e,t){let i;if(!t)i=yi;else{i={};for(let p in yi)i[p]=yi[p];let d;for(;(d=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(d[0].length),i[d[1]]=d[2]}let n=d=>{if(d){let p=d.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(p){let f=p[2]?i[p[2]]:er;if(f)return f+p[3]}}return null},r=1,o=e.childElements().forEachNonNull(d=>{if(d.localName=="meta"){let p=n(d.getAttribute("property"));if(p)return{name:p,value:d.textContent,id:d.getAttribute("id"),order:r++,refines:d.getAttribute("refines"),lang:null,scheme:n(d.getAttribute("scheme")),role:null}}else if(d.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:yi.dcterms+d.localName,order:r++,lang:d.getAttribute("xml:lang"),value:d.textContent,id:d.getAttribute("id"),refines:null,scheme:null,role:d.getAttribute("role")||d.getAttribute("opf:role")};return null}),s=ws(o,d=>d.refines),a=d=>lg(d,(p,f)=>p.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let w=s[`#${g.id}`]||[];if(w.length||g.lang||g.role){g.lang&&w.push({name:je.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&w.push({name:je.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let x=ws(w,y=>y.name);m.r=a(x)}return m})),h=a(ws(o,d=>d.refines?null:d.name)),l=null;h[je.language]&&(l=h[je.language][0].v);let u=d=>{for(let p in d){let f=d[p];f.sort(Fx(p,l));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(h),h}function Lx(){let e=window.MathJax;return e?e.Hub:null}var yu={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Ms="viv-id-",xo=class{constructor(e,t){this.store=e,this.pubURL=t,c(this,"opfXML",null),c(this,"encXML",null),c(this,"items",null),c(this,"spine",null),c(this,"itemMap",null),c(this,"itemMapByPath",null),c(this,"uid",null),c(this,"bindings",{}),c(this,"lang",null),c(this,"epageCount",0),c(this,"prePaginated",!1),c(this,"epageIsRenderedPage",!0),c(this,"epageCountCallback",null),c(this,"metadata",{}),c(this,"toc",null),c(this,"cover",null),c(this,"fallbackMap",{}),c(this,"pageProgression",null),c(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,r){let o=r+(n?`#${n}`:"");return Ms+_u(o,":")}transformURL(n,r){let o=n.match(/^([^#]*)#?(.*)$/);if(o){let s=o[1]||r.replace(/\?viv-toc-box$/,""),a=decodeURIComponent(o[2]);if(s&&e.spine.some(h=>h.src===s))return`#${this.transformFragment(a,s)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(Ms)===0&&(n=n.substring(Ms.length));let r=sg(n,":").match(/^([^#]*)#?(.*)$/);return r?[r[1],r[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=Ie("",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 r={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new wu,u=h;l.initWithElement(u,e.url);let d=u.getAttribute("fallback");return d&&!yu[l.mediaType]&&(r[l.src]=d),!this.toc&&l.itemProperties.nav&&(this.toc=l),!this.cover&&l.itemProperties["cover-image"]&&(this.cover=l),l}),this.itemMap=Xl(this.items,Tx),this.itemMapByPath=Xl(this.items,h=>this.getPathFromURL(h.src));for(let h in r){let l=h;for(;;){let u=this.itemMap[r[l]];if(!u)break;if(yu[u.mediaType]){this.fallbackMap[h]=u.src;break}l=u.src}}this.spine=i.child("spine").child("itemref").asArray().map((h,l)=>{let u=h,d=u.getAttribute("idref"),p=this.itemMap[d];return p&&(p.itemRefElement=u,p.spineIndex=l),p});let o=i.child("spine").attribute("page-progression-direction")[0];o&&(this.pageProgression=Tu(o));let s=t?t.doc().child("encryption").child("EncryptedData").predicate(du.withChild("EncryptionMethod",du.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"),u=a[h].getAttribute("media-type");u&&l&&this.itemMap[l]&&(this.bindings[u]=this.itemMap[l].src)}if(this.metadata=Rx(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[je.language]&&(this.lang=this.metadata[je.language][0].v),this.metadata[je.layout]&&(this.prePaginated=this.metadata[je.layout][0].v==="pre-paginated"),s.length>0&&this.uid){let h=Ix(this.uid);for(let l=0;l<s.length;l++)this.store.deobfuscators[this.pubURL+s[l]]=h}return this.prePaginated&&this.assignAutoPages(),T(!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(),T(!0);let t=0,i=0,n=D("countEPages");return n.loopWithFrame(r=>{if(i===this.spine.length){r.breakLoop();return}let o=this.spine[i++];o.epage=t,this.store.load(o.src).then(s=>{let a=1800,h=s.lang||this.lang;h&&h.match(/^(ja|ko|zh)/)&&(a/=3),o.epageCount=Math.ceil(s.getTotalOffset()/a),t+=o.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),r.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new pf(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let r=new wu;r.initWithParam(n),r.id;let o=i.document.createElement("itemref");o.setAttribute("idref",r.id),i.root.appendChild(o),r.itemRefElement=o,this.itemMap[r.id]=r;let s=this.getPathFromURL(n.url);s==null&&(s=n.url),this.itemMapByPath[s]=r,this.items.push(r)}),t?this.store.addDocument(e[0].url,t):T(null)}initWithWebPubManifest(e,t,i){var n,r,o,s;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[je.title]=(Array.isArray(a)?a:[a]).map(x=>{var y;return{v:(y=x.value)!=null?y:x}}));let h=e.author||e.creator||((r=e.metadata)==null?void 0:r.author)||Array.from((o=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?o:[]).map(x=>x.content);h&&h.length!==0&&(this.metadata[je.creator]=(Array.isArray(h)?h:[h]).map(x=>{var y;return{v:(y=x.name)!=null?y:x}}));let l=e.inLanguage||((s=e.metadata)==null?void 0:s.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[je.language]=(Array.isArray(l)?l:[l]).map(x=>({v:x})));let u=Bt(this.pubURL),d=this.getPathFromURL(u),p=d!==null?encodeURI(d):/^(?:about:|blob:)/i.test(u)?u:null;if(!e.readingOrder&&t&&p!==null){e.readingOrder=[p];for(let x of Cx(t)){let y=x.getAttribute("href");if(/^(https?:)?\/\//.test(y)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(y))continue;let b=Bt(Ie(y,this.pubURL)),S=this.getPathFromURL(b),C=S!==null?encodeURI(S):b;e.readingOrder.indexOf(C)==-1&&e.readingOrder.push(C)}}let f=[],g=0,m=-1;[e.readingOrder,e.resources].forEach(x=>{x instanceof Array&&x.forEach(y=>{let b=x===e.readingOrder,S=typeof y=="string"?y:y.url||y.href,C=typeof y=="string"?"":y.encodingFormat||y.href&&y.type||"";if(b||C==="text/html"||C==="application/xhtml+xml"||!C&&y.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(S)){let N=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,F={url:Ie(yn(S),N),index:g++,startPage:null,skipPagesBefore:null};y.rel==="contents"&&m===-1&&(m=F.index),f.push(F)}})});let w=D("initWithWebPubManifest");return this.initWithChapters(f).then(()=>{var x,y;m!==-1&&(this.toc=this.items[m]),this.toc||(this.toc=i?(x=this.items)==null?void 0:x[0]:this.itemMapByPath[d]);let b=(y=e.readingOrder)==null?void 0:y.length;b&&b<this.items.length&&this.items.splice(b),w.finish(!0)}),w.result()}getCFI(e,t){let i=this.spine[e],n=D("getCFI");return this.store.load(i.src).then(r=>{let o=r.getNodeByOffset(t),s=null;if(o){let a=r.getNodeOffset(o,0,!1),h=t-a,l=new sh;l.prependPathFromNode(o,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),s=l.toString()}n.finish(s)}),n.result()}resolveFragment(e){return kn("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new sh;i.fromString(e);let n;if(this.opfXML){let r=i.navigate(this.opfXML.document);if(r.node.nodeType!=1||r.after||!r.ref){t.finish(null);return}let o=r.node,s=o.getAttribute("idref");if(o.localName!="itemref"||!s||!this.itemMap[s]){t.finish(null);return}n=this.itemMap[s],i=r.ref}else n=this.spine[0];this.store.load(n.src).then(r=>{let o=i.navigate(r.document),s=r.getNodeOffset(o.node,o.offset,o.after);t.finish({spineIndex:n.spineIndex,offsetInItem:s,pageIndex:-1})})},(t,i)=>{j.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return kn("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let r=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);r==-1&&(r=this.spine.length-1);let o=this.spine[r];(!o||o.epageCount==0)&&(o=this.spine[--r]);let s=Math.floor(e-o.epage);t.finish({spineIndex:r,offsetInItem:-1,pageIndex:s});return}let i=ai(this.spine.length,r=>{let o=this.spine[r];return o.epage+o.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(r=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let o=0;if(e>0){let s=r.getTotalOffset();o=Math.round(s*e/n.epageCount),o==s&&o--}t.finish({spineIndex:i,offsetInItem:o,pageIndex:-1})})},(t,i)=>{j.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 T(n)}if(e.offsetInItem<=0)return T(t.epage);let i=D("getEPage");return this.store.load(t.src).then(n=>{let r=n.getTotalOffset(),o=Math.min(r,e.offsetInItem);i.finish(t.epage+o*t.epageCount/r)}),i.result()}},Qr=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),Ox=class{constructor(e,t,i,n,r,o){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=r,c(this,"spineItems",[]),c(this,"spineItemLoadingContinuations",[]),c(this,"pref"),c(this,"clientLayout"),c(this,"counterStore"),c(this,"cmykStore"),c(this,"tocAutohide",!1),c(this,"tocVisible",!1),c(this,"tocView"),c(this,"paginationProgress",{totalOffsetsBySpine:[],renderedOffsetsBySpine:[],lastReportedPages:0,lastReportedFraction:0}),this.pref=Vu(n),this.clientLayout=new I0(t),this.counterStore=new em(e.documentURLTransformer),this.cmykStore=new fc,o!=null&&o.length&&this.cmykStore.registerCmykReserveMap(o)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}waitForPreviousSpines(e,t){if(t||e===0)return T(!0);let i=D("waitForPreviousSpines");return i.loopWithFrame(n=>{let r=!0;for(let o=0;o<e;o++){let s=this.spineItems[o];if(!s||!s.complete){r=!1;break}}r?n.breakLoop():i.sleep(100).then(()=>{n.continueLoop()})}).then(()=>{i.finish(!0)}),i.result()}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 r=this.opf.spine[e.item.spineIndex-1];e.item.epage=r.epage+r.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((r,o)=>r+o.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 r=null;if(i>0)r=e.pages[i-1].container.nextElementSibling;else for(let o=e.item.spineIndex+1;o<this.spineItems.length;o++){let s=this.spineItems[o];if(s&&s.pages[0]){r=s.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,r)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}getRenderedPageCount(){let e=0;for(let t of this.spineItems)t&&(e+=t.pages.length);return e}markSpineItemCompleteIfReady(e){e.complete=e.layoutPositions.length===e.pages.length,e.complete&&e.instance.viewport.layoutBox.removeAttribute("style")}getTotalOffsetForViewItem(e){let t=e.item.spineIndex,i=this.paginationProgress.totalOffsetsBySpine[t];return i==null&&(i=e.xmldoc.getTotalOffset(),this.paginationProgress.totalOffsetsBySpine[t]=i),i}getTotalOffsetAll(){let e=0;for(let t of this.spineItems)t&&(e+=this.getTotalOffsetForViewItem(t));return e}getRenderedOffsetAll(){var e;let t=0,i=this.paginationProgress.totalOffsetsBySpine,n=this.paginationProgress.renderedOffsetsBySpine;for(let r=0;r<i.length;r++){let o=i[r];if(!o)continue;let s=(e=n[r])!=null?e:0;t+=Math.min(o,s)}return t}reportPaginationProgress(e,t){let i=Dt("PAGINATION_PROGRESS");if(!i.length)return;let n=e.item.spineIndex,r=this.getTotalOffsetForViewItem(e),o=r;t&&(o=e.instance.getPosition(t,!0)),o<0&&(o=0),o>r&&(o=r);let s=this.paginationProgress.renderedOffsetsBySpine[n];s!=null&&o<s&&(o=s),this.paginationProgress.renderedOffsetsBySpine[n]=o;let a=this.getRenderedPageCount(),h=this.getTotalOffsetAll(),l=this.getRenderedOffsetAll(),u=h>0?l/h:0;u<this.paginationProgress.lastReportedFraction?u=this.paginationProgress.lastReportedFraction:this.paginationProgress.lastReportedFraction=u,a>this.paginationProgress.lastReportedPages&&(this.paginationProgress.lastReportedPages=a);let d={fraction:u,pages:this.paginationProgress.lastReportedPages};for(let p of i)try{p(d)}catch(f){j.warn(f)}}isInCounterResolveScope(){return this.counterStore.currentPageCountersStack.length>0}hasNonEmptyPageType(e){return!!(e!=null&&e.pageType)&&e.pageType!==""}hasPageTypeBoundaryBetween(e,t){return e?.pageType!=null&&t?.pageType!=null&&e.pageType!==t.pageType}resolvePageTypeForRenderSlot(e,t,i,n,r,o,s){let a=!1;if(n){let h=this.hasPageTypeBoundaryBetween(r,n),l=o?.pageType===n.pageType,u=n.offset!==t.offset,d=s&&!u&&i>0&&h&&l;if(a=n.pageType!=null&&(d||i===0||n.pageType===r?.pageType),t.pageType=a?n.pageType:null,!s&&!a){let p=i>1&&h&&l?r.pageType:null;e.instance.styler.cascade.currentPageType=p,e.instance.pageManager.pageCascadeInstance.currentPageType=p}}!s&&this.hasNonEmptyPageType(r)&&this.hasNonEmptyPageType(o)&&r.pageType!==o.pageType&&(!n||n.pageType==null)&&(t.pageType=r.pageType)}evaluateNextPageRelayout(e,t,i,n,r){if(!e||t&&!i)return{needsRelayout:!1,shouldCascade:!1};let o=!!t&&(e.pageType===t.pageType||!t.pageType);return t&&n&&(!r||o)&&(t.pageType==null||e.pageType==null||e.pageType!==t.pageType)&&(t.pageType=null),{needsRelayout:!0,shouldCascade:!!t||!r}}preparePageCountersForRender(e,t){let i=e.pages[t],n=e.pageCounterStarts[t];i&&n&&(this.counterStore.currentPageCounters=Jr(n));let r=Jr(this.counterStore.currentPageCounters);return(!n||!i)&&(e.pageCounterStarts[t]=r),i}maybeRelayoutFollowingPage(e,t,i,n){if(!t)return T(!0);let r=e.layoutPositions[t.page];e.layoutPositions[t.page]=t;let o=e.pages[t.page],s=!!i&&n.offset!==i.offset,a=!r||!t.isSamePosition(r)||t.highestSeenOffset!==r.highestSeenOffset||s,h=this.isInCounterResolveScope(),l=this.evaluateNextPageRelayout(i,o,a,s,h);return l.needsRelayout?(e.complete=!1,l.shouldCascade?this.renderSinglePage(e,t):T(!0)):T(!0)}resolveUnresolvedReferencesForPage(e,t,i,n){let r=D("resolveUnresolvedReferencesForPage"),o=this.isInCounterResolveScope()?[]:this.counterStore.getUnresolvedRefsToPage(t),s=0,a=t;return r.loopWithFrame(h=>{if(s++,s>o.length){h.breakLoop();return}let l=o[s-1];if(l.refs=l.refs.filter(u=>!u.isResolved()),l.refs.length===0){h.continueLoop();return}this.getPageViewItem(l.spineIndex).then(u=>{if(!u){h.continueLoop();return}let d=u.instance.styler.cascade,p=u.instance.pageManager.pageCascadeInstance,f={currentPageType:d.currentPageType,previousPageType:d.previousPageType},g={currentPageType:p.currentPageType,previousPageType:p.previousPageType},m=Px(u.instance.pageGroupPageCounts),w=u.instance.currentPageGroupDocument,x=u.instance.scopes;u.instance.scopes={};let y=l.pageIndex<u.pages.length-1,b=!!u.pages[l.pageIndex]&&y,S=b?u.instance.beginIsolatedRootPageFloatLayoutContext():null;this.counterStore.pushPageCounters(l.pageCounters),this.counterStore.pushReferencesToSolve(l.refs);let C=u.layoutPositions[l.pageIndex];this.renderSinglePage(u,C).then(N=>{b&&u.instance.endIsolatedRootPageFloatLayoutContext(S);let F=d.currentPageType;d.currentPageType=f.currentPageType,d.previousPageType=f.previousPageType,p.currentPageType=g.currentPageType,p.previousPageType=g.previousPageType,u.instance.pageGroupPageCounts=m,u.instance.currentPageGroupDocument=w,u.instance.scopes=x;let B=Jr(this.counterStore.currentPageCounters);this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve(),N.pageAndPosition.position.spineIndex===a.spineIndex&&N.pageAndPosition.position.pageIndex===i&&(a=N.pageAndPosition.page),a.pageType&&a.pageType!==f.currentPageType&&F!==N.pageAndPosition.page.pageType&&(d.currentPageType=a.pageType);let U=u!==e,q=u.pages.length,he=u.layoutPositions[q],ae=u.instance.hasActiveRootPageFloatLayoutContext();if(he&&!ae){let k=U?Jr(this.counterStore.currentPageCounters):null;U&&(this.counterStore.currentPageCounters=B);let _=q;this.renderSinglePage(u,he).then(()=>{U&&this.markSpineItemCompleteIfReady(u);let E=u.pages.length-_;if(U&&E>0){this.counterStore.adjustPageCountersOfLaterSpines(u.item.spineIndex,E),this.counterStore.updateTargetCounterNodesInPages(u.pages);let L=u.item.spineIndex;for(let P=L+1;P<this.spineItems.length;P++){let A=this.spineItems[P];if(A){A.item.epage+=E;for(let O of A.pageCounterStarts)O!=null&&O.page&&(O.page=O.page.map(z=>z+E));this.counterStore.updatePageCounterNodesInPages(A.pages,A.pageCounterStarts)}}if(k){let P=k.page;P&&(k.page=P.map(A=>A+E))}}k&&(this.counterStore.currentPageCounters=k),h.continueLoop()});return}U&&this.markSpineItemCompleteIfReady(u),h.continueLoop()})})}).then(()=>{a.container.parentElement||(a=e.pages[i]),a.isLastPage=!n&&e.item.spineIndex===this.opf.spine.length-1,a.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),a.container.setAttribute("data-vivliostyle-page-index",i),a.container.setAttribute("data-vivliostyle-spine-index",a.spineIndex),r.finish(a)}),r.result()}renderSinglePage(e,t){let i=D("renderSinglePage"),n=t?Math.max(t.page,0):0,r=this.isInCounterResolveScope(),o=this.preparePageCountersForRender(e,n),s=n>0?e.pages[n-1]:null,a=e.pages[n+1],h=this.makePage(e,t);return this.resolvePageTypeForRenderSlot(e,h,n,o,s,a,r),e.instance.layoutNextPage(h,t).then(l=>{t=l;let u=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,h,u),this.counterStore.finishPage(h.spineIndex,u),this.reportPaginationProgress(e,t),this.maybeRelayoutFollowingPage(e,t,o,h).thenAsync(()=>this.resolveUnresolvedReferencesForPage(e,h,u,t)).then(d=>{i.finish({pageAndPosition:Qr(d,u),nextLayoutPosition:t})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let r=ai(t.layoutPositions.length,o=>t.instance.getPosition(t.layoutPositions[o],!0)>n);r===t.layoutPositions.length?t.complete?i=t.pages.length-1:i=Number.POSITIVE_INFINITY:i=r-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=D("findPage");return this.waitForPreviousSpines(e.spineIndex,t).then(()=>{this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let r=null,o;i.loopWithFrame(s=>{let a=this.normalizeSeekPosition(e,n);o=a.pageIndex,r=n.pages[o],r?s.breakLoop():n.complete?(o=n.pages.length-1,r=n.pages[o],s.breakLoop()):t?this.renderPage(a).then(h=>{h&&(r=h.page,o=h.position.pageIndex),s.breakLoop()}):o<n.layoutPositions.length&&!n.pages[o]?this.renderPage(a).then(h=>{h&&(r=h.page,o=h.position.pageIndex),s.breakLoop()}):i.sleep(100).then(()=>{s.continueLoop()})}).then(()=>{i.finish(Qr(r,o))})})}),i.result()}renderPage(e){let t=D("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),r=n.pageIndex,o=n.offsetInItem,s=i.pages[r];if(s){t.finish(Qr(s,r));return}t.loopWithFrame(a=>{if(r<i.layoutPositions.length){a.breakLoop();return}if(i.complete){r=i.pages.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let u=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(o>=0&&i.instance.getPosition(h)>o){s=u,r=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else s=u,r=l.pageAndPosition.position.pageIndex,this.markSpineItemCompleteIfReady(i),a.breakLoop()})}).then(()=>{s=s||i.pages[r];let a=i.layoutPositions[r];if(s){t.finish(Qr(s,r));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||this.markSpineItemCompleteIfReady(i),t.finish(h.pageAndPosition)})})}),t.result()}renderAllPages(){let e=D("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(r=>r?.fetchers.some(o=>!o.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=D("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,r=e.pageIndex,o=0;t&&(o=n);let s;return i.loopWithFrame(a=>{let h={spineIndex:o,pageIndex:o===n?r:Number.POSITIVE_INFINITY,offsetInItem:o===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{s=l,++o>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(s)}),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,r=D("nextPage");return this.getPageViewItem(i).then(o=>{if(!o){r.finish(null);return}if(o.complete&&n==o.pages.length-1){if(i>=this.opf.spine.length-1){r.finish(null);return}i++,n=0;let s=this.spineItems[i],a=s&&s.pages[0],h=o.pages[o.pages.length-1];a&&h&&a.side==h.side&&(s.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(r)}),r.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return T(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 T({left:null,right:null});let n=D("getSpread"),r=i.side==="left",o;return this.isRectoPage(i,e)?o=this.previousPage(e,t):o=this.nextPage(e,t),o.then(s=>{let a=this.getPage(e),h=s&&s.page;h&&h.side===a.side&&(h=null),r?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 T(null);let n=this.isRectoPage(i,e),r=this.nextPage(e,t);return n?r:r.thenAsync(o=>{if(o){if(o.page.side===i.side)return r;let s=this.nextPage(o.position,t);return s.thenAsync(a=>a?s:r)}else return T(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return T(null);let n=this.isRectoPage(i,e),r=this.previousPage(e,t),o=i.container.previousElementSibling;return n?r.thenAsync(s=>s?s.page.side===i.side||s.page.container!==o?r:this.previousPage(s.position,t):T(null)):r}navigateToEPage(e,t,i){let n=D("navigateToEPage");return this.opf.resolveEPage(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(e,t,i){let n=D("navigateToCFI");return this.opf.resolveFragment(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}resolveSemanticFootnoteNavigationOffset(e,t){if(!bt(t))return null;let i=t.getAttribute("id");if(!i)return null;let n=Ie(`#${i}`,e.xmldoc.url),r=e.xmldoc.document.getElementsByTagName("a");for(let o=0;o<r.length;o++){let s=r.item(o);if(!_t(s))continue;let a=s.getAttribute("href")||s.getAttributeNS("http://www.w3.org/1999/xlink","href");if(a&&Ie(a,e.xmldoc.url)===n)return e.xmldoc.getElementOffset(s)}return null}navigateTo(e,t,i){j.debug("Navigate to",e);let n=this.opf.getPathFromURL(Bt(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let s=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(s[0]),n==null&&(n=s[0])):n=s[0],e=s[0]+(s[1]?`#${s[1]}`:"")}if(n==null)return T(null)}let r=this.opf.itemMapByPath[n];if(!r){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let s=e.indexOf("#");if(s>=0)return this.navigateToFragment(e.substr(s+1),t,i)}return T(null)}let o=D("navigateTo");return this.waitForPreviousSpines(r.spineIndex,i).then(()=>{this.getPageViewItem(r.spineIndex).then(s=>{if(!s){o.finish(null);return}let a=s.xmldoc.getElement(e),h=a&&this.resolveSemanticFootnoteNavigationOffset(s,a),l=h??(a?s.xmldoc.getElementOffset(a):0);this.findPage({spineIndex:r.spineIndex,pageIndex:-1,offsetInItem:l},i).thenFinish(o)})}),o.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",dr||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let r=i.document.createElement("div");r.setAttribute("data-vivliostyle-bleed-box","true"),r.role="presentation",n.appendChild(r);let o=new fd(n,r);if(o.spineIndex=e.item.spineIndex,o.position=t,o.offset=e.instance.getPosition(t),o.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let s=this.opf.documentURLTransformer.transformFragment("",e.item.src);r.setAttribute("id",s),o.registerElementWithId(r,s)}if(i!==this.viewport){let s=Uu(this.viewport.width,this.viewport.height,i.width,i.height),a=Rr(null,new Vt(s,null),"");o.delayedItems.push(new al(n,"transform",a))}return o}makeObjectView(e,t,i,n){let r=t.getAttribute("data"),o=null;if(r){r=Ie(r,e.url);let s=t.getAttribute("media-type");if(!s){let a=this.opf.getPathFromURL(r);if(a){let h=this.opf.itemMapByPath[a];h&&(s=h.mediaType)}}if(s){let a=this.opf.bindings[s];if(a){o=this.viewport.document.createElement("iframe"),o.style.border="none";let h=Gl(r),l=Gl(s),u=new si;u.append(a),u.append("?src="),u.append(h),u.append("&type="),u.append(l);for(let f=t.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let g=f;if(g.localName=="param"&&g.namespaceURI=="http://www.w3.org/1999/xhtml"){let m=g.getAttribute("name"),w=g.getAttribute("value");m&&w&&(u.append("&"),u.append(encodeURIComponent(m)),u.append("="),u.append(encodeURIComponent(w)))}}o.setAttribute("src",u.toString());let d=t.getAttribute("width");d&&o.setAttribute("width",d);let p=t.getAttribute("height");p&&o.setAttribute("height",p)}}}return o||(o=this.viewport.document.createElement("object"),r&&o.setAttribute("data",pr(r)),o.setAttribute("data-adapt-process-children","true")),T(o)}makeMathJaxView(e,t,i,n){let r=Lx();if(r){let o=i.ownerDocument,s=o.createElement("span");i.appendChild(s);let a=o.importNode(t,!0);this.resolveURLsInMathML(a,e),s.appendChild(a);let h=r.queue;h.Push(["Typeset",r,s]);let l=D("makeMathJaxView"),u=l.suspend();return h.Push(()=>{u.schedule(s)}),l.result()}return T(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 r=Ie(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,r):e.setAttribute(n.name,r)}}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):T(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return T(null);let t=this.spineItems[e];if(t)return T(t);let i=D("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let s=i.suspend();return n.push(s),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let r=this.opf.spine[e],o=this.opf.store;return o.load(r.src).then(s=>{var a;let h=r.itemRefElement.getAttribute("properties");h&&s.root.setAttribute("data-vivliostyle-epub-spine-properties",h),r.title=s.document.title;let l=o.getStyleForDoc(s),u=this.makeCustomRenderer(s),d=this.viewport,p=l.sizeViewport(d.width,d.height,d.fontSize,this.pref);(p.width!=d.width||p.height!=d.height||p.fontSize!=d.fontSize)&&(d=new jo(d.window,p.fontSize,d.pixelRatio,d.root,p.width,p.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,g=this.spineItems[e-1],m,w;if(r.startPage!==null)m=r.startPage-1,w=m;else{if(e>0&&(!g||!g.complete))m=r.epage||e,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,w=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let b=g&&g.pageCounterStarts[g.pages.length-1],S=b&&b.page;if(S&&S.length)w=S[S.length-1]+1;else{let C=this.counterStore.currentPageCounters.page;w=!C||!C.length?m:C[C.length-1]}}r.skipPagesBefore!==null&&(m+=r.skipPagesBefore,w+=r.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let x=new Ll(l,s,this.opf.lang,d,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,m,this.opf.documentURLTransformer,this.counterStore,this.cmykStore,this.opf.pageProgression,f);x.pref=this.pref;let y=this.opf.metadata&&this.opf.metadata[je.title];x.pubTitle=y&&y[0]&&y[0].v||"",x.docTitle=r.title||"",x.init().then(()=>{!this.opf.pageProgression&&x.pageProgression&&(this.opf.pageProgression=x.pageProgression),t={item:r,xmldoc:s,instance:x,layoutPositions:[null],pages:[],complete:!1,pageCounterStarts:[]},this.spineItems[e]=t,i.finish(t),n.forEach(b=>{b.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 T(null);if(this.tocVisible=!0,this.tocView&&this.tocView.page)return this.tocView.page.container.style.visibility="visible",this.tocView.page.container.setAttribute("aria-hidden","false"),T(this.tocView.page);let n=D("showTOC");this.tocView||(this.tocView=new kx(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore,this.cmykStore));let r=this.viewport,o=Math.min(344,Math.round(.67*r.width)-16),s=r.height-6,a=r.document.createElement("div");return r.root.appendChild(a),dr||(a.style.visibility="hidden"),a.style.width=`${o+16}px`,a.style.maxHeight=`${s}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,r,o,s,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()}},vu="data-vivliostyle-viewer-status",Bx="data-vivliostyle-spread-view",wf=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(wf||{}),Mx=class{constructor(e,t,i,n){this.window=e,this.viewportElement=t,this.instanceId=i,this.callbackFn=n,c(this,"fontMapper"),c(this,"kick"),c(this,"sendCommand"),c(this,"resizeListener"),c(this,"hyperlinkListener"),c(this,"pageRuleStyleElement"),c(this,"pageSheetSizeAlreadySet",!1),c(this,"renderTask",null),c(this,"actions"),c(this,"readyState"),c(this,"packageURL"),c(this,"opf"),c(this,"touchActive"),c(this,"touchX"),c(this,"touchY"),c(this,"needResize"),c(this,"resized"),c(this,"needRefresh"),c(this,"viewportSize"),c(this,"currentPage"),c(this,"currentSpread"),c(this,"pagePosition"),c(this,"fontSize"),c(this,"zoom"),c(this,"fitToScreen"),c(this,"pageViewMode"),c(this,"waitForLoading"),c(this,"renderAllPages"),c(this,"pref"),c(this,"pageSizes"),c(this,"pixelRatio"),c(this,"pixelRatioLimit"),c(this,"viewport"),c(this,"opfView"),c(this,"cmykReserveMap"),c(this,"cmykReserveMapUrl");let r=t.ownerDocument,o=(s,a)=>{let h=r.getElementById(s);return h||(h=r.createElement("style"),h.id=s,a&&(h.textContent=a),r.head.appendChild(h)),h};o("vivliostyle-viewport-screen-css",Mc),o("vivliostyle-viewport-css",_c),o("vivliostyle-polyfill-css",Hc),t.setAttribute("data-vivliostyle-viewer-viewport",!0),dr&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(vu,"loading"),this.fontMapper=new g0(r.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=s=>{},this.pageRuleStyleElement=o("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=zu(),this.pageSizes=[],this.pixelRatioLimit=Ga==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=Fu;j.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),j.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),j.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),j.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){if(this.readyState!==e){this.readyState=e,this.viewportElement.setAttribute(vu,e);let t=this.getCurrentPageProgression();t&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",t),this.callback({t:"readystatechange"})}}loadPublication(e){xt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,r=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let o=D("loadPublication");return this.configure(e).then(()=>{let s=new mu;s.init(n,r).then(()=>{let a=Ie(yn(t),this.window.location.href);this.packageURL=[a],s.loadPubDoc(a).then(h=>{h?(this.opf=h,this.loadCmykReserveMap(s).then(()=>{this.render(i).then(()=>{o.finish(!0)})})):o.finish(!1)})})}),o.result()}loadXML(e){xt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,r=e.authorStyleSheet,o=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let s=D("loadXML");return this.configure(e).then(()=>{let a=new mu;a.init(r,o).then(()=>{let h=t.map((l,u)=>({url:Ie(yn(l.url),this.window.location.href),index:u,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new xo(a,""),this.opf.initWithChapters(h,i).then(()=>{this.loadCmykReserveMap(a).then(()=>{this.render(n).then(()=>{s.finish(!0)})})})})}),s.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,T(!0))):t=T(!0),t.thenAsync(()=>(xt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let r=n[0];if(r==="em"||r==="rem")return t*this.fontSize;let o=Wt[r];if(o)return t*o}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"&&($l(e.userAgentRootURL.replace(/resources\/?$/,"")),Hl(e.userAgentRootURL)),typeof e.rootURL=="string"&&($l(e.rootURL),Hl(`${Ui}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!==hi&&(m0(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),T(!0)}configurePlugins(e){Dt("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=>{I(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),I(e.container,"visibility","visible"),I(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=D("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?En(i.fetchers):T(!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 jo(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new jo(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!=null&&(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(Bx,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 r=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:!r&&t.width==this.viewport.width&&t.height==this.viewport.height||!r&&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,r;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((r=this.pageSizes[i-1])==null?void 0:r.height))){let s=function(g){let m=g*.75;return Math.ceil(m)};var o=s;let a=Math.max(...this.pageSizes.map(g=>g.width)),h=Math.max(...this.pageSizes.map(g=>g.height)),l=s(a),u=s(h),d=l*((this.pixelRatio||1)-1)+2,p=u*((this.pixelRatio||1)-1)+2,f=`@page {size: ${l}pt ${u}pt; margin: 0 ${-d}pt ${-p}pt 0;}`;this.pageRuleStyleElement.textContent=f,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}loadCmykReserveMap(e){if(!this.cmykReserveMapUrl)return this.cmykReserveMap=void 0,T(!0);let t=Ie(yn(this.cmykReserveMapUrl),Ui),i=D("loadCmykReserveMap");return e.loadAsJSON(t).then(n=>{Ig(n)?this.cmykReserveMap=n:(j.warn("Invalid cmykReserveMap data, ignoring"),this.cmykReserveMap=void 0),i.finish(!0)}),i.result()}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 Ox(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this),this.cmykReserveMap),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?T(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,T(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,T(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,T(null))}setPageZoom(e){var t;let i=this.getAdjustedZoomFactor(e.dimensions);(t=this.viewport)==null||t.zoom(e.dimensions.width,e.dimensions.height,i)}setSpreadZoom(e){var t;let i=this.getSpreadDimensions(e);(t=this.viewport)==null||t.zoom(i.width,i.height,this.getAdjustedZoomFactor(i))}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 bu),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return T(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Ys().getScheduler().run(()=>kn("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,xt.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 r={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.isLastPageForNotification(this.currentPage),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)&&(r.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(r)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():T(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),xt.registerEndTiming("render (resize)"),hi&&Kp(this.window)?b0(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 bu)xt.registerEndTiming("render (resize)"),j.debug(i.message);else throw i}));return T(!0)}sendLocationNotification(e,t){let i=D("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:this.isLastPageForNotification(e),metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(r=>{n.epage=r,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}isLastPageForNotification(e){if(!this.opfView||!this.pagePosition)return e.isLastPage;let t=this.opfView.spineItems[this.pagePosition.spineIndex];if(!t||!t.complete)return!1;let i=t.item.spineIndex===this.opf.spine.length-1,n=this.pagePosition.pageIndex===t.pages.length-1;return i&&n}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 r;switch(e.where){case"next":r=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":r=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":r=this.opfView.lastPage;break;case"first":r=this.opfView.firstPage;break;default:return T(!0)}r&&(i=()=>r.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let r=e.epage;i=()=>this.opfView.navigateToEPage(r,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let r=e.url;i=()=>this.opfView.navigateTo(r,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let r=e.position;i=()=>this.opfView.findPage(r,!this.renderAllPages)}else return T(!0);if(!this.opfView)return T(!0);let n=D("moveTo");return i.call(this.opfView).then(r=>{let o;if(r){this.pagePosition=r.position;let s=D("moveTo.showCurrent");o=s.result(),this.showCurrent(r.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(s)})}else o=T(!0);o.then(s=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(s)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),r=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!r)return T(!0)}else if(i=="hide")return T(!0);if(n&&i!="show")return this.opfView.hideTOC(),T(!0);{let o=D("showTOC");return this.opfView.showTOC(t).then(s=>{if(s){if(r&&(s.listeners={}),t){let a=()=>{this.opfView.hideTOC()};s.addEventListener("hyperlink",a,!1)}s.addEventListener("hyperlink",this.hyperlinkListener,!1)}o.finish(!0)}),o.result()}}runCommand(e){let t=e.a||"";return kn("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(j.error("No such action:",t),i.finish(!0))},(i,n)=>{j.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=xu(e),i=null,n=this;Xm(()=>{let r=D("commandLoop"),o=Ys().getScheduler();return n.hyperlinkListener=s=>{let a=s,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){s.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};o.run(()=>(n.callback(l),T(!0)))}},r.loopWithFrame(s=>{if(n.needResize)n.resize().then(()=>{s.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{s.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{s.continueLoop()})}else{let a=D("waitForCommand");i=a.suspend(this),a.result().then(()=>{s.continueLoop()})}}).thenFinish(r),r.result()}),n.kick=()=>{let r=i;r&&(i=null,r.schedule(!0))},n.sendCommand=r=>t?!1:(t=xu(r),n.kick(),!0),this.window.adapt_command=n.sendCommand}},yf=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(yf||{}),bu=class vf extends Error{constructor(){super(),c(this,"name","RenderingCanceledError"),c(this,"message","Page rendering has been canceled"),c(this,"stack"),Object.setPrototypeOf(this,vf.prototype),this.stack=new Error().stack}};function xu(e){return typeof e=="string"?ja(e):e}var Su=Wa;function _x(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function Cu(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 bf=class{constructor(e,t){this.settings=e,c(this,"initialized",!1),c(this,"adaptViewer_"),c(this,"options"),c(this,"eventTarget"),c(this,"readyState"),Nu(e.debug),this.adaptViewer_=new Mx(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=_x(),t&&this.setOptions(t),this.eventTarget=new qa,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},Cu(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 r=i||{};function o(l){if(l)return l.map(u=>({url:u.url||null,text:u.text||null}))}let s=o(r.authorStyleSheet),a=o(r.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:Dx(e)||t,document:r.documentObject,fragment:r.fragment,authorStyleSheet:s,userStyleSheet:a,cmykReserveMapUrl:r.cmykReserveMapUrl},Cu(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()===Su.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Su.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}getCmykMap(){var e;let t=(e=this.adaptViewer_)==null?void 0:e.opfView;return t!=null&&t.cmykStore?t.cmykStore.toJSON():{}}};function Dx(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 xf=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(xf||{}),zx=yf,Vx=wf;xt.forceRegisterEndTiming("load_vivliostyle");var Ux=class{constructor(e,{title:t="",printCallback:i=s=>s.print(),errorCallback:n=null,hideIframe:r=!0,removeIframe:o=!0}){c(this,"htmlDoc"),c(this,"title"),c(this,"printCallback"),c(this,"errorCallback"),c(this,"hideIframe"),c(this,"removeIframe"),c(this,"iframe"),c(this,"iframeWin"),c(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=r,this.removeIframe=o}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=`
1853
1874
  <!DOCTYPE html>
1854
1875
  <html data-vivliostyle-paginated="true">
1855
1876
  <head>
@@ -1877,6 +1898,6 @@ span[data-viv-leader] {
1877
1898
  <body onload='parent.printInstance.runInIframe(window)'>
1878
1899
  <div id="vivliostyle-viewer-viewport"></div>
1879
1900
  </body>
1880
- </html>`,document.body.appendChild(this.iframe)}runInIframe(e){return this.iframeWin=e,this.preparePrint().then(()=>this.browserPrint()).then(()=>this.cleanUp())}preparePrint(){this.iframeWin.document.title=this.title;let e=new Blob([this.htmlDoc],{type:"text/html"}),t=URL.createObjectURL(e),i=new Ap({viewportElement:this.iframeWin.document.body.firstElementChild,window:this.iframeWin,debug:!0});return new Promise(n=>{i.addListener("readystatechange",()=>{i.readyState==="complete"&&n()}),this.errorCallback&&i.addListener("error",r=>{var s,o;let a=(o=(s=r.content.error)==null?void 0:s.toString())!=null?o:r.content.messages.join(`
1881
- `);this.errorCallback(a)}),i.loadDocument({url:t})})}browserPrint(){this.printCallback(this.iframeWin)}cleanUp(){delete this.window.printInstance,this.removeIframe&&this.iframe.parentElement.removeChild(this.iframe)}};function b0(e,t){new y0(e,t).init()}});var v0={};Wp(v0,{printHTML:()=>Op.printHTML});module.exports=jp(v0);var Op=Gp(Lp());
1901
+ </html>`,document.body.appendChild(this.iframe)}runInIframe(e){return this.iframeWin=e,this.preparePrint().then(()=>this.browserPrint()).then(()=>this.cleanUp())}preparePrint(){this.iframeWin.document.title=this.title;let e=new Blob([this.htmlDoc],{type:"text/html"}),t=URL.createObjectURL(e),i=new bf({viewportElement:this.iframeWin.document.body.firstElementChild,window:this.iframeWin,debug:!0});return new Promise(n=>{i.addListener("readystatechange",()=>{i.readyState==="complete"&&n()}),this.errorCallback&&i.addListener("error",r=>{var o,s;let a=(s=(o=r.content.error)==null?void 0:o.toString())!=null?s:r.content.messages.join(`
1902
+ `);this.errorCallback(a)}),i.loadDocument({url:t})})}browserPrint(){this.printCallback(this.iframeWin)}cleanUp(){delete this.window.printInstance,this.removeIframe&&this.iframe.parentElement.removeChild(this.iframe)}};function $x(e,t){new Ux(e,t).init()}});var Hx={};Of(Hx,{printHTML:()=>kf.printHTML});module.exports=Mf(Hx);var kf=Bf(Cf());
1882
1903
  //# sourceMappingURL=index.cjs.js.map