@vivliostyle/print 2.40.0 → 2.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es6.js CHANGED
@@ -1,10 +1,12 @@
1
- var gp=Object.create;var tl=Object.defineProperty;var mp=Object.getOwnPropertyDescriptor;var wp=Object.getOwnPropertyNames;var yp=Object.getPrototypeOf,bp=Object.prototype.hasOwnProperty;var vp=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var xp=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of wp(t))!bp.call(e,r)&&r!==i&&tl(e,r,{get:()=>t[r],enumerable:!(n=mp(t,r))||n.enumerable});return e};var Sp=(e,t,i)=>(i=e!=null?gp(yp(e)):{},xp(t||!e||!e.__esModule?tl(i,"default",{value:e,enumerable:!0}):i,e));var cp=vp((ev,up)=>{"use strict";var Cp=Object.create,tr=Object.defineProperty,kp=Object.getOwnPropertyDescriptor,Ep=Object.getOwnPropertyNames,Np=Object.getPrototypeOf,Pp=Object.prototype.hasOwnProperty,Bh=e=>{throw TypeError(e)},Tp=(e,t,i)=>t in e?tr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Ip=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ap=(e,t)=>{for(var i in t)tr(e,i,{get:t[i],enumerable:!0})},Mh=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ep(t))!Pp.call(e,r)&&r!==i&&tr(e,r,{get:()=>t[r],enumerable:!(n=kp(t,r))||n.enumerable});return e},Rp=(e,t,i)=>(i=e!=null?Cp(Np(e)):{},Mh(t||!e||!e.__esModule?tr(i,"default",{value:e,enumerable:!0}):i,e)),Fp=e=>Mh(tr({},"__esModule",{value:!0}),e),c=(e,t,i)=>Tp(e,typeof t!="symbol"?t+"":t,i),oa=(e,t,i)=>t.has(e)||Bh("Cannot "+i),M=(e,t,i)=>(oa(e,t,"read from private field"),i?i.call(e):t.get(e)),Z=(e,t,i)=>t.has(e)?Bh("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),Fe=(e,t,i,n)=>(oa(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),Se=(e,t,i)=>(oa(e,t,"access private method"),i),Lp=Ip((e,t)=>{var i=-1,n=1,r=0;function s(x,B,S,P,k){if(x===B)return x?[[r,x]]:[];if(S!=null){var R=ht(x,B,S);if(R)return R}var L=h(x,B),D=x.substring(0,L);x=x.substring(L),B=B.substring(L),L=d(x,B);var W=x.substring(x.length-L);x=x.substring(0,x.length-L),B=B.substring(0,B.length-L);var q=o(x,B);return D&&q.unshift([r,D]),W&&q.push([r,W]),E(q,k),P&&f(q),q}function o(x,B){var S;if(!x)return[[n,B]];if(!B)return[[i,x]];var P=x.length>B.length?x:B,k=x.length>B.length?B:x,R=P.indexOf(k);if(R!==-1)return S=[[n,P.substring(0,R)],[r,k],[n,P.substring(R+k.length)]],x.length>B.length&&(S[0][0]=S[2][0]=i),S;if(k.length===1)return[[i,x],[n,B]];var L=p(x,B);if(L){var D=L[0],W=L[1],q=L[2],Q=L[3],ee=L[4],we=s(D,q),te=s(W,Q);return we.concat([[r,ee]],te)}return a(x,B)}function a(x,B){for(var S=x.length,P=B.length,k=Math.ceil((S+P)/2),R=k,L=2*k,D=new Array(L),W=new Array(L),q=0;q<L;q++)D[q]=-1,W[q]=-1;D[R+1]=0,W[R+1]=0;for(var Q=S-P,ee=Q%2!==0,we=0,te=0,ye=0,Ce=0,he=0;he<k;he++){for(var G=-he+we;G<=he-te;G+=2){var ce=R+G,de;G===-he||G!==he&&D[ce-1]<D[ce+1]?de=D[ce+1]:de=D[ce-1]+1;for(var z=de-G;de<S&&z<P&&x.charAt(de)===B.charAt(z);)de++,z++;if(D[ce]=de,de>S)te+=2;else if(z>P)we+=2;else if(ee){var re=R+Q-G;if(re>=0&&re<L&&W[re]!==-1){var se=S-W[re];if(de>=se)return l(x,B,de,z)}}}for(var be=-he+ye;be<=he-Ce;be+=2){var re=R+be,se;be===-he||be!==he&&W[re-1]<W[re+1]?se=W[re+1]:se=W[re-1]+1;for(var ut=se-be;se<S&&ut<P&&x.charAt(S-se-1)===B.charAt(P-ut-1);)se++,ut++;if(W[re]=se,se>S)Ce+=2;else if(ut>P)ye+=2;else if(!ee){var ce=R+Q-be;if(ce>=0&&ce<L&&D[ce]!==-1){var de=D[ce],z=R+de-ce;if(se=S-se,de>=se)return l(x,B,de,z)}}}}return[[i,x],[n,B]]}function l(x,B,S,P){var k=x.substring(0,S),R=B.substring(0,P),L=x.substring(S),D=B.substring(P),W=s(k,R),q=s(L,D);return W.concat(q)}function h(x,B){if(!x||!B||x.charAt(0)!==B.charAt(0))return 0;for(var S=0,P=Math.min(x.length,B.length),k=P,R=0;S<k;)x.substring(R,k)==B.substring(R,k)?(S=k,R=S):P=k,k=Math.floor((P-S)/2+S);return A(x.charCodeAt(k-1))&&k--,k}function u(x,B){var S=x.length,P=B.length;if(S==0||P==0)return 0;S>P?x=x.substring(S-P):S<P&&(B=B.substring(0,S));var k=Math.min(S,P);if(x==B)return k;for(var R=0,L=1;;){var D=x.substring(k-L),W=B.indexOf(D);if(W==-1)return R;L+=W,(W==0||x.substring(k-L)==B.substring(0,L))&&(R=L,L++)}}function d(x,B){if(!x||!B||x.slice(-1)!==B.slice(-1))return 0;for(var S=0,P=Math.min(x.length,B.length),k=P,R=0;S<k;)x.substring(x.length-k,x.length-R)==B.substring(B.length-k,B.length-R)?(S=k,R=S):P=k,k=Math.floor((P-S)/2+S);return H(x.charCodeAt(x.length-k))&&k--,k}function p(x,B){var S=x.length>B.length?x:B,P=x.length>B.length?B:x;if(S.length<4||P.length*2<S.length)return null;function k(te,ye,Ce){for(var he=te.substring(Ce,Ce+Math.floor(te.length/4)),G=-1,ce="",de,z,re,se;(G=ye.indexOf(he,G+1))!==-1;){var be=h(te.substring(Ce),ye.substring(G)),ut=d(te.substring(0,Ce),ye.substring(0,G));ce.length<ut+be&&(ce=ye.substring(G-ut,G)+ye.substring(G,G+be),de=te.substring(0,Ce-ut),z=te.substring(Ce+be),re=ye.substring(0,G-ut),se=ye.substring(G+be))}return ce.length*2>=te.length?[de,z,re,se,ce]:null}var R=k(S,P,Math.ceil(S.length/4)),L=k(S,P,Math.ceil(S.length/2)),D;if(!R&&!L)return null;L?R?D=R[4].length>L[4].length?R:L:D=L:D=R;var W,q,Q,ee;x.length>B.length?(W=D[0],q=D[1],Q=D[2],ee=D[3]):(Q=D[0],ee=D[1],W=D[2],q=D[3]);var we=D[4];return[W,q,Q,ee,we]}function f(x){for(var B=!1,S=[],P=0,k=null,R=0,L=0,D=0,W=0,q=0;R<x.length;)x[R][0]==r?(S[P++]=R,L=W,D=q,W=0,q=0,k=x[R][1]):(x[R][0]==n?W+=x[R][1].length:q+=x[R][1].length,k&&k.length<=Math.max(L,D)&&k.length<=Math.max(W,q)&&(x.splice(S[P-1],0,[i,k]),x[S[P-1]+1][0]=n,P--,P--,R=P>0?S[P-1]:-1,L=0,D=0,W=0,q=0,k=null,B=!0)),R++;for(B&&E(x),C(x),R=1;R<x.length;){if(x[R-1][0]==i&&x[R][0]==n){var Q=x[R-1][1],ee=x[R][1],we=u(Q,ee),te=u(ee,Q);we>=te?(we>=Q.length/2||we>=ee.length/2)&&(x.splice(R,0,[r,ee.substring(0,we)]),x[R-1][1]=Q.substring(0,Q.length-we),x[R+1][1]=ee.substring(we),R++):(te>=Q.length/2||te>=ee.length/2)&&(x.splice(R,0,[r,Q.substring(0,te)]),x[R-1][0]=n,x[R-1][1]=ee.substring(0,ee.length-te),x[R+1][0]=i,x[R+1][1]=Q.substring(te),R++),R++}R++}}var m=/[^a-zA-Z0-9]/,g=/\s/,w=/[\r\n]/,v=/\n\r?\n$/,y=/^\r?\n\r?\n/;function C(x){function B(te,ye){if(!te||!ye)return 6;var Ce=te.charAt(te.length-1),he=ye.charAt(0),G=Ce.match(m),ce=he.match(m),de=G&&Ce.match(g),z=ce&&he.match(g),re=de&&Ce.match(w),se=z&&he.match(w),be=re&&te.match(v),ut=se&&ye.match(y);return be||ut?5:re||se?4:G&&!de&&z?3:de||z?2:G||ce?1:0}for(var S=1;S<x.length-1;){if(x[S-1][0]==r&&x[S+1][0]==r){var P=x[S-1][1],k=x[S][1],R=x[S+1][1],L=d(P,k);if(L){var D=k.substring(k.length-L);P=P.substring(0,P.length-L),k=D+k.substring(0,k.length-L),R=D+R}for(var W=P,q=k,Q=R,ee=B(P,k)+B(k,R);k.charAt(0)===R.charAt(0);){P+=k.charAt(0),k=k.substring(1)+R.charAt(0),R=R.substring(1);var we=B(P,k)+B(k,R);we>=ee&&(ee=we,W=P,q=k,Q=R)}x[S-1][1]!=W&&(W?x[S-1][1]=W:(x.splice(S-1,1),S--),x[S][1]=q,Q?x[S+1][1]=Q:(x.splice(S+1,1),S--))}S++}}function E(x,B){x.push([r,""]);for(var S=0,P=0,k=0,R="",L="",D;S<x.length;){if(S<x.length-1&&!x[S][1]){x.splice(S,1);continue}switch(x[S][0]){case n:k++,L+=x[S][1],S++;break;case i:P++,R+=x[S][1],S++;break;case r:var W=S-k-P-1;if(B){if(W>=0&&ie(x[W][1])){var q=x[W][1].slice(-1);if(x[W][1]=x[W][1].slice(0,-1),R=q+R,L=q+L,!x[W][1]){x.splice(W,1),S--;var Q=W-1;x[Q]&&x[Q][0]===n&&(k++,L=x[Q][1]+L,Q--),x[Q]&&x[Q][0]===i&&(P++,R=x[Q][1]+R,Q--),W=Q}}if(V(x[S][1])){var q=x[S][1].charAt(0);x[S][1]=x[S][1].slice(1),R+=q,L+=q}}if(S<x.length-1&&!x[S][1]){x.splice(S,1);break}if(R.length>0||L.length>0){R.length>0&&L.length>0&&(D=h(L,R),D!==0&&(W>=0?x[W][1]+=L.substring(0,D):(x.splice(0,0,[r,L.substring(0,D)]),S++),L=L.substring(D),R=R.substring(D)),D=d(L,R),D!==0&&(x[S][1]=L.substring(L.length-D)+x[S][1],L=L.substring(0,L.length-D),R=R.substring(0,R.length-D)));var ee=k+P;R.length===0&&L.length===0?(x.splice(S-ee,ee),S=S-ee):R.length===0?(x.splice(S-ee,ee,[n,L]),S=S-ee+1):L.length===0?(x.splice(S-ee,ee,[i,R]),S=S-ee+1):(x.splice(S-ee,ee,[i,R],[n,L]),S=S-ee+2)}S!==0&&x[S-1][0]===r?(x[S-1][1]+=x[S][1],x.splice(S,1)):S++,k=0,P=0,R="",L="";break}}x[x.length-1][1]===""&&x.pop();var we=!1;for(S=1;S<x.length-1;)x[S-1][0]===r&&x[S+1][0]===r&&(x[S][1].substring(x[S][1].length-x[S-1][1].length)===x[S-1][1]?(x[S][1]=x[S-1][1]+x[S][1].substring(0,x[S][1].length-x[S-1][1].length),x[S+1][1]=x[S-1][1]+x[S+1][1],x.splice(S-1,1),we=!0):x[S][1].substring(0,x[S+1][1].length)==x[S+1][1]&&(x[S-1][1]+=x[S+1][1],x[S][1]=x[S][1].substring(x[S+1][1].length)+x[S+1][1],x.splice(S+1,1),we=!0)),S++;we&&E(x,B)}function A(x){return x>=55296&&x<=56319}function H(x){return x>=56320&&x<=57343}function V(x){return H(x.charCodeAt(0))}function ie(x){return A(x.charCodeAt(x.length-1))}function ne(x){for(var B=[],S=0;S<x.length;S++)x[S][1].length>0&&B.push(x[S]);return B}function Xe(x,B,S,P){return ie(x)||V(P)?null:ne([[r,x],[i,B],[n,S],[r,P]])}function ht(x,B,S){var P=typeof S=="number"?{index:S,length:0}:S.oldRange,k=typeof S=="number"?null:S.newRange,R=x.length,L=B.length;if(P.length===0&&(k===null||k.length===0)){var D=P.index,W=x.slice(0,D),q=x.slice(D),Q=k?k.index:null;e:{var ee=D+L-R;if(Q!==null&&Q!==ee||ee<0||ee>L)break e;var we=B.slice(0,ee),te=B.slice(ee);if(te!==q)break e;var ye=Math.min(D,ee),Ce=W.slice(0,ye),he=we.slice(0,ye);if(Ce!==he)break e;var G=W.slice(ye),ce=we.slice(ye);return Xe(Ce,G,ce,q)}e:{if(Q!==null&&Q!==D)break e;var de=D,we=B.slice(0,de),te=B.slice(de);if(we!==W)break e;var z=Math.min(R-de,L-de),re=q.slice(q.length-z),se=te.slice(te.length-z);if(re!==se)break e;var G=q.slice(0,q.length-z),ce=te.slice(0,te.length-z);return Xe(W,G,ce,re)}}if(P.length>0&&k&&k.length===0)e:{var Ce=x.slice(0,P.index),re=x.slice(P.index+P.length),ye=Ce.length,z=re.length;if(L<ye+z)break e;var he=B.slice(0,ye),se=B.slice(L-z);if(Ce!==he||re!==se)break e;var G=x.slice(ye,R-z),ce=B.slice(ye,L-z);return Xe(Ce,G,ce,re)}return null}function xe(x,B,S,P){return s(x,B,S,P,!0)}xe.INSERT=n,xe.DELETE=i,xe.EQUAL=r,t.exports=xe}),_h={};Ap(_h,{CoreViewer:()=>lp,HOOKS:()=>ds,Navigation:()=>hp,PageProgression:()=>aa,PageSide:()=>Vh,PageViewMode:()=>D0,Profiler:()=>Wh,ReadyState:()=>Hh,UserAgentBaseCss:()=>Uu,UserAgentCounterStylesCss:()=>Gu,UserAgentPageCss:()=>Hu,UserAgentTocCss:()=>$u,UserAgentXml:()=>Vu,ValidationTxt:()=>Du,VivliostylePolyfillCss:()=>Wu,VivliostyleViewportCss:()=>zu,VivliostyleViewportScreenCss:()=>_u,ZoomType:()=>z0,getHooksForName:()=>Rt,isDebug:()=>Gn,pageProgressionOf:()=>Dh,plugin:()=>Bp,printHTML:()=>H0,profile:()=>Dp,profiler:()=>pt,registerHook:()=>Nt,removeHook:()=>$h,setDebug:()=>zh});up.exports=Fp(_h);var Gn=!1;function zh(e){Gn=e}var aa=(e=>(e.LTR="ltr",e.RTL="rtl",e))(aa||{});function Dh(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var Vh=(e=>(e.LEFT="left",e.RIGHT="right",e))(Vh||{}),Hh=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(Hh||{}),Uh=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(Uh||{}),Op=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=gr(arguments);this.consoleDebug(mr(t)),this.triggerListeners(1,t)}info(...e){let t=gr(arguments);this.consoleInfo(mr(t)),this.triggerListeners(2,t)}warn(...e){let t=gr(arguments);this.consoleWarn(mr(t)),this.triggerListeners(3,t)}error(...e){let t=gr(arguments);this.consoleError(mr(t)),this.triggerListeners(4,t)}};function gr(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function mr(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 gf=Object.create;var Al=Object.defineProperty;var mf=Object.getOwnPropertyDescriptor;var wf=Object.getOwnPropertyNames;var yf=Object.getPrototypeOf,vf=Object.prototype.hasOwnProperty;var bf=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var xf=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of wf(t))!vf.call(e,r)&&r!==i&&Al(e,r,{get:()=>t[r],enumerable:!(n=mf(t,r))||n.enumerable});return e};var Sf=(e,t,i)=>(i=e!=null?gf(yf(e)):{},xf(t||!e||!e.__esModule?Al(i,"default",{value:e,enumerable:!0}):i,e));var cf=bf((Ox,uf)=>{"use strict";var Cf=Object.create,yr=Object.defineProperty,kf=Object.getOwnPropertyDescriptor,Ef=Object.getOwnPropertyNames,Pf=Object.getPrototypeOf,Nf=Object.prototype.hasOwnProperty,pu=e=>{throw TypeError(e)},Tf=(e,t,i)=>t in e?yr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,If=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Af=(e,t)=>{for(var i in t)yr(e,i,{get:t[i],enumerable:!0})},fu=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ef(t))!Nf.call(e,r)&&r!==i&&yr(e,r,{get:()=>t[r],enumerable:!(n=kf(t,r))||n.enumerable});return e},Ff=(e,t,i)=>(i=e!=null?Cf(Pf(e)):{},fu(t||!e||!e.__esModule?yr(i,"default",{value:e,enumerable:!0}):i,e)),Rf=e=>fu(yr({},"__esModule",{value:!0}),e),d=(e,t,i)=>Tf(e,typeof t!="symbol"?t+"":t,i),Ma=(e,t,i)=>t.has(e)||pu("Cannot "+i),U=(e,t,i)=>(Ma(e,t,"read from private field"),i?i.call(e):t.get(e)),ne=(e,t,i)=>t.has(e)?pu("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),De=(e,t,i,n)=>(Ma(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),Ee=(e,t,i)=>(Ma(e,t,"access private method"),i),Lf=If((e,t)=>{var i=-1,n=1,r=0;function o(k,M,E,L,P){if(k===M)return k?[[r,k]]:[];if(E!=null){var I=Se(k,M,E);if(I)return I}var O=l(k,M),z=k.substring(0,O);k=k.substring(O),M=M.substring(O),O=c(k,M);var $=k.substring(k.length-O);k=k.substring(0,k.length-O),M=M.substring(0,M.length-O);var K=s(k,M);return z&&K.unshift([r,z]),$&&K.push([r,$]),C(K,P),L&&f(K),K}function s(k,M){var E;if(!k)return[[n,M]];if(!M)return[[i,k]];var L=k.length>M.length?k:M,P=k.length>M.length?M:k,I=L.indexOf(P);if(I!==-1)return E=[[n,L.substring(0,I)],[r,P],[n,L.substring(I+P.length)]],k.length>M.length&&(E[0][0]=E[2][0]=i),E;if(P.length===1)return[[i,k],[n,M]];var O=p(k,M);if(O){var z=O[0],$=O[1],K=O[2],J=O[3],Q=O[4],de=o(z,K),re=o($,J);return de.concat([[r,Q]],re)}return a(k,M)}function a(k,M){for(var E=k.length,L=M.length,P=Math.ceil((E+L)/2),I=P,O=2*P,z=new Array(O),$=new Array(O),K=0;K<O;K++)z[K]=-1,$[K]=-1;z[I+1]=0,$[I+1]=0;for(var J=E-L,Q=J%2!==0,de=0,re=0,oe=0,Oe=0,Re=0;Re<P;Re++){for(var pe=-Re+de;pe<=Re-re;pe+=2){var Ce=I+pe,me;pe===-Re||pe!==Re&&z[Ce-1]<z[Ce+1]?me=z[Ce+1]:me=z[Ce-1]+1;for(var he=me-pe;me<E&&he<L&&k.charAt(me)===M.charAt(he);)me++,he++;if(z[Ce]=me,me>E)re+=2;else if(he>L)de+=2;else if(Q){var ke=I+J-pe;if(ke>=0&&ke<O&&$[ke]!==-1){var we=E-$[ke];if(me>=we)return h(k,M,me,he)}}}for(var Te=-Re+oe;Te<=Re-Oe;Te+=2){var ke=I+Te,we;Te===-Re||Te!==Re&&$[ke-1]<$[ke+1]?we=$[ke+1]:we=$[ke-1]+1;for(var te=we-Te;we<E&&te<L&&k.charAt(E-we-1)===M.charAt(L-te-1);)we++,te++;if($[ke]=we,we>E)Oe+=2;else if(te>L)oe+=2;else if(!Q){var Ce=I+J-Te;if(Ce>=0&&Ce<O&&z[Ce]!==-1){var me=z[Ce],he=I+me-Ce;if(we=E-we,me>=we)return h(k,M,me,he)}}}}return[[i,k],[n,M]]}function h(k,M,E,L){var P=k.substring(0,E),I=M.substring(0,L),O=k.substring(E),z=M.substring(L),$=o(P,I),K=o(O,z);return $.concat(K)}function l(k,M){if(!k||!M||k.charAt(0)!==M.charAt(0))return 0;for(var E=0,L=Math.min(k.length,M.length),P=L,I=0;E<P;)k.substring(I,P)==M.substring(I,P)?(E=P,I=E):L=P,P=Math.floor((L-E)/2+E);return S(k.charCodeAt(P-1))&&P--,P}function u(k,M){var E=k.length,L=M.length;if(E==0||L==0)return 0;E>L?k=k.substring(E-L):E<L&&(M=M.substring(0,E));var P=Math.min(E,L);if(k==M)return P;for(var I=0,O=1;;){var z=k.substring(P-O),$=M.indexOf(z);if($==-1)return I;O+=$,($==0||k.substring(P-O)==M.substring(0,O))&&(I=O,O++)}}function c(k,M){if(!k||!M||k.slice(-1)!==M.slice(-1))return 0;for(var E=0,L=Math.min(k.length,M.length),P=L,I=0;E<P;)k.substring(k.length-P,k.length-I)==M.substring(M.length-P,M.length-I)?(E=P,I=E):L=P,P=Math.floor((L-E)/2+E);return F(k.charCodeAt(k.length-P))&&P--,P}function p(k,M){var E=k.length>M.length?k:M,L=k.length>M.length?M:k;if(E.length<4||L.length*2<E.length)return null;function P(re,oe,Oe){for(var Re=re.substring(Oe,Oe+Math.floor(re.length/4)),pe=-1,Ce="",me,he,ke,we;(pe=oe.indexOf(Re,pe+1))!==-1;){var Te=l(re.substring(Oe),oe.substring(pe)),te=c(re.substring(0,Oe),oe.substring(0,pe));Ce.length<te+Te&&(Ce=oe.substring(pe-te,pe)+oe.substring(pe,pe+Te),me=re.substring(0,Oe-te),he=re.substring(Oe+Te),ke=oe.substring(0,pe-te),we=oe.substring(pe+Te))}return Ce.length*2>=re.length?[me,he,ke,we,Ce]:null}var I=P(E,L,Math.ceil(E.length/4)),O=P(E,L,Math.ceil(E.length/2)),z;if(!I&&!O)return null;O?I?z=I[4].length>O[4].length?I:O:z=O:z=I;var $,K,J,Q;k.length>M.length?($=z[0],K=z[1],J=z[2],Q=z[3]):(J=z[0],Q=z[1],$=z[2],K=z[3]);var de=z[4];return[$,K,J,Q,de]}function f(k){for(var M=!1,E=[],L=0,P=null,I=0,O=0,z=0,$=0,K=0;I<k.length;)k[I][0]==r?(E[L++]=I,O=$,z=K,$=0,K=0,P=k[I][1]):(k[I][0]==n?$+=k[I][1].length:K+=k[I][1].length,P&&P.length<=Math.max(O,z)&&P.length<=Math.max($,K)&&(k.splice(E[L-1],0,[i,P]),k[E[L-1]+1][0]=n,L--,L--,I=L>0?E[L-1]:-1,O=0,z=0,$=0,K=0,P=null,M=!0)),I++;for(M&&C(k),v(k),I=1;I<k.length;){if(k[I-1][0]==i&&k[I][0]==n){var J=k[I-1][1],Q=k[I][1],de=u(J,Q),re=u(Q,J);de>=re?(de>=J.length/2||de>=Q.length/2)&&(k.splice(I,0,[r,Q.substring(0,de)]),k[I-1][1]=J.substring(0,J.length-de),k[I+1][1]=Q.substring(de),I++):(re>=J.length/2||re>=Q.length/2)&&(k.splice(I,0,[r,J.substring(0,re)]),k[I-1][0]=n,k[I-1][1]=Q.substring(0,Q.length-re),k[I+1][0]=i,k[I+1][1]=J.substring(re),I++),I++}I++}}var g=/[^a-zA-Z0-9]/,m=/\s/,w=/[\r\n]/,x=/\n\r?\n$/,b=/^\r?\n\r?\n/;function v(k){function M(re,oe){if(!re||!oe)return 6;var Oe=re.charAt(re.length-1),Re=oe.charAt(0),pe=Oe.match(g),Ce=Re.match(g),me=pe&&Oe.match(m),he=Ce&&Re.match(m),ke=me&&Oe.match(w),we=he&&Re.match(w),Te=ke&&re.match(x),te=we&&oe.match(b);return Te||te?5:ke||we?4:pe&&!me&&he?3:me||he?2:pe||Ce?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],I=k[E+1][1],O=c(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),I=z+I}for(var $=L,K=P,J=I,Q=M(L,P)+M(P,I);P.charAt(0)===I.charAt(0);){L+=P.charAt(0),P=P.substring(1)+I.charAt(0),I=I.substring(1);var de=M(L,P)+M(P,I);de>=Q&&(Q=de,$=L,K=P,J=I)}k[E-1][1]!=$&&($?k[E-1][1]=$:(k.splice(E-1,1),E--),k[E][1]=K,J?k[E+1][1]=J:(k.splice(E+1,1),E--))}E++}}function C(k,M){k.push([r,""]);for(var E=0,L=0,P=0,I="",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++,I+=k[E][1],E++;break;case r:var $=E-P-L-1;if(M){if($>=0&&D(k[$][1])){var K=k[$][1].slice(-1);if(k[$][1]=k[$][1].slice(0,-1),I=K+I,O=K+O,!k[$][1]){k.splice($,1),E--;var J=$-1;k[J]&&k[J][0]===n&&(P++,O=k[J][1]+O,J--),k[J]&&k[J][0]===i&&(L++,I=k[J][1]+I,J--),$=J}}if(A(k[E][1])){var K=k[E][1].charAt(0);k[E][1]=k[E][1].slice(1),I+=K,O+=K}}if(E<k.length-1&&!k[E][1]){k.splice(E,1);break}if(I.length>0||O.length>0){I.length>0&&O.length>0&&(z=l(O,I),z!==0&&($>=0?k[$][1]+=O.substring(0,z):(k.splice(0,0,[r,O.substring(0,z)]),E++),O=O.substring(z),I=I.substring(z)),z=c(O,I),z!==0&&(k[E][1]=O.substring(O.length-z)+k[E][1],O=O.substring(0,O.length-z),I=I.substring(0,I.length-z)));var Q=P+L;I.length===0&&O.length===0?(k.splice(E-Q,Q),E=E-Q):I.length===0?(k.splice(E-Q,Q,[n,O]),E=E-Q+1):O.length===0?(k.splice(E-Q,Q,[i,I]),E=E-Q+1):(k.splice(E-Q,Q,[i,I],[n,O]),E=E-Q+2)}E!==0&&k[E-1][0]===r?(k[E-1][1]+=k[E][1],k.splice(E,1)):E++,P=0,L=0,I="",O="";break}}k[k.length-1][1]===""&&k.pop();var de=!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),de=!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),de=!0)),E++;de&&C(k,M)}function S(k){return k>=55296&&k<=56319}function F(k){return k>=56320&&k<=57343}function A(k){return F(k.charCodeAt(0))}function D(k){return S(k.charCodeAt(k.length-1))}function H(k){for(var M=[],E=0;E<k.length;E++)k[E][1].length>0&&M.push(k[E]);return M}function q(k,M,E,L){return D(k)||A(L)?null:H([[r,k],[i,M],[n,E],[r,L]])}function Se(k,M,E){var L=typeof E=="number"?{index:E,length:0}:E.oldRange,P=typeof E=="number"?null:E.newRange,I=k.length,O=M.length;if(L.length===0&&(P===null||P.length===0)){var z=L.index,$=k.slice(0,z),K=k.slice(z),J=P?P.index:null;e:{var Q=z+O-I;if(J!==null&&J!==Q||Q<0||Q>O)break e;var de=M.slice(0,Q),re=M.slice(Q);if(re!==K)break e;var oe=Math.min(z,Q),Oe=$.slice(0,oe),Re=de.slice(0,oe);if(Oe!==Re)break e;var pe=$.slice(oe),Ce=de.slice(oe);return q(Oe,pe,Ce,K)}e:{if(J!==null&&J!==z)break e;var me=z,de=M.slice(0,me),re=M.slice(me);if(de!==$)break e;var he=Math.min(I-me,O-me),ke=K.slice(K.length-he),we=re.slice(re.length-he);if(ke!==we)break e;var pe=K.slice(0,K.length-he),Ce=re.slice(0,re.length-he);return q($,pe,Ce,ke)}}if(L.length>0&&P&&P.length===0)e:{var Oe=k.slice(0,L.index),ke=k.slice(L.index+L.length),oe=Oe.length,he=ke.length;if(O<oe+he)break e;var Re=M.slice(0,oe),we=M.slice(O-he);if(Oe!==Re||ke!==we)break e;var pe=k.slice(oe,I-he),Ce=M.slice(oe,O-he);return q(Oe,pe,Ce,ke)}return null}function se(k,M,E,L){return o(k,M,E,L,!0)}se.INSERT=n,se.DELETE=i,se.EQUAL=r,t.exports=se}),gu={};Af(gu,{CoreViewer:()=>lf,HOOKS:()=>$o,Navigation:()=>hf,PageProgression:()=>_a,PageSide:()=>yu,PageViewMode:()=>vx,Profiler:()=>Su,ReadyState:()=>vu,UserAgentBaseCss:()=>Fc,UserAgentCounterStylesCss:()=>Oc,UserAgentPageCss:()=>Ac,UserAgentTocCss:()=>Rc,UserAgentXml:()=>Ic,ValidationTxt:()=>Tc,VivliostylePolyfillCss:()=>Lc,VivliostyleViewportCss:()=>Nc,VivliostyleViewportScreenCss:()=>Pc,ZoomType:()=>yx,getHooksForName:()=>Ot,isDebug:()=>lr,pageProgressionOf:()=>wu,plugin:()=>Bf,printHTML:()=>xx,profile:()=>zf,profiler:()=>vt,registerHook:()=>Nt,removeHook:()=>xu,setDebug:()=>mu});uf.exports=Rf(gu);var lr=!1;function mu(e){lr=e}var _a=(e=>(e.LTR="ltr",e.RTL="rtl",e))(_a||{});function wu(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var yu=(e=>(e.LEFT="left",e.RIGHT="right",e))(yu||{}),vu=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(vu||{}),bu=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(bu||{}),Of=class{constructor(e){this.opt_console=e,d(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=Br(arguments);this.consoleDebug(Mr(t)),this.triggerListeners(1,t)}info(...e){let t=Br(arguments);this.consoleInfo(Mr(t)),this.triggerListeners(2,t)}warn(...e){let t=Br(arguments);this.consoleWarn(Mr(t)),this.triggerListeners(3,t)}error(...e){let t=Br(arguments);this.consoleError(Mr(t)),this.triggerListeners(4,t)}};function Br(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function Mr(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 $=new Op,ds=(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))(ds||{}),jr={};function Nt(e,t,i){if(!ds[e])$.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=jr[e];n||(n=jr[e]=[]),i?n.unshift(t):n.push(t)}}function $h(e,t){if(!ds[e])$.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=jr[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function Rt(e){return jr[e]||[]}var Bp={registerHook:Nt,removeHook:$h},Wh=class{constructor(e){this.performanceInstance=e,c(this,"timestamps",{}),c(this,"registerTiming"),c(this,"registerStartTiming"),c(this,"registerEndTiming"),this.registerTiming=Li,this.registerStartTiming=this.registerStartTiming=Li,this.registerEndTiming=this.registerEndTiming=Li}forceRegisterStartTiming(e,t){As.call(this,e,"start",t)}forceRegisterEndTiming(e,t){As.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
- `}}),$.info(t)}disable(){this.registerTiming=Li,this.registerStartTiming=this.registerStartTiming=Li,this.registerEndTiming=this.registerEndTiming=Li}enable(){this.registerTiming=As,this.registerStartTiming=this.registerStartTiming=il,this.registerEndTiming=this.registerEndTiming=Mp}isEnabled(){return this.registerStartTiming===il}};function Li(){}function As(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 il(e,t){this.registerTiming(e,"start",t)}function Mp(e,t){this.registerTiming(e,"end",t)}var _p={now:Date.now},zp=window&&window.performance,pt=new Wh(zp||_p);pt.forceRegisterStartTiming("load_vivliostyle");var Dp={profiler:{registerStartTiming:pt.registerStartTiming,registerEndTiming:pt.registerEndTiming,printTimings:pt.printTimings,disable:pt.disable,enable:pt.enable}},Gh=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",Xr=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,Ut="data-adapt-eloff",Vp={};function la(e){return JSON.parse(e)}function Wt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function Hp(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var on=window.location.href;function nl(e){on=e}var ni=window.location.href;function rl(e){ni=e}function Pe(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=Hp(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 jn(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 sl(e){return e==null?e:e.toString()}var Up=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}},jh=["","-webkit-","-moz-"],Mi={};function Er(e,t){return CSS.supports(e+t,"unset")}function $p(e){let t=Mi[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return Mi[e]=null,null;case"text-combine-upright":if(Er("-webkit-","text-combine")&&!Er("","text-combine-upright"))return Mi[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of jh)if(Er(i,e))return t=[i+e],Mi[e]=t,t;return $.warn("Property not supported by the browser: ",e),Mi[e]=null,null}function T(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let r=$p(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 ei(e,t,i){try{let n=Mi[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function Js(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 oi=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 Xh(e){return`\\${e.charCodeAt(0).toString(16)} `}function ri(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Xh)}function ir(e){return e.replace(/[\u0000-\u001F"\\]/g,Xh)}function ol(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function al(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function Wp(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function qh(e,t){function i(n){return Wp(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function Zt(e){return qh(e)}function Gp(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function jp(e,t){t=typeof t=="string"?t:"\\u";function i(r){return Gp(r,t)}let n=new RegExp(`${Zt(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 Yh(e,t){return e-t}function ll(e,t){let i={};for(let n of e){let r=t(n);r&&!i[r]&&(i[r]=n)}return i}function Xp(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function Rs(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 qp(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var ha=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)}}},Ci={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function Kh(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function Yp(e){return`^${e}`}function hl(e){return e.replace(/[\[\]\(\),=;^]/g,Yp)}function Kp(e){return e.substr(1)}function Qs(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,Kp)}function Zp(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=Qs(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function ul(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=Zp(i[2]),e=e.substr(i[0].length)}return t}var cl=class{appendTo(e){e.append("!")}applyTo(e){return!1}},dl=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!=Kh(e.node))){let o=t.ownerDocument.getElementById(this.id);o?e.node=o:$.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},pl=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(hl(this.textBefore)),e.append(","),this.textAfter&&e.append(hl(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},fl=class Zh{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),l=i[3];o=ul(i[4]),s.push(new dl(a,l,sl(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),l=i[4];l&&(l=Qs(l));let h=i[7];h&&(h=Qs(h)),o=ul(i[10]),s.push(new pl(a,l,h,sl(o.s)));break}case"!":r++,s.push(new cl);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 Zh,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="",l="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let h=t.textContent,u=h.length;n?(i+=u,a||(a=h)):(i>u&&(i=u),n=!0,a=h.substr(0,i),l=h.substr(i)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((i>0||a||l)&&(a=this.trim(a,!1),l=this.trim(l,!0),s.push(new pl(i,a,l,r)),r=null);o&&!(!o||o.nodeType==9);){let h=n?null:Kh(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;s.push(new dl(u,h,r)),r=null,t=o,o=o.parentNode,n=!1}s.reverse(),this.steps?(s.push(new cl),this.steps=s.concat(this.steps)):this.steps=s}toString(){if(!this.steps)return"";let t=new oi;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")}};function Jh(){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 Qh(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 Jp=Jh(),gl={PENDING:{}};function eu(e,t,i,n){let r=Math.min((e-0)/i,(t-0)/n);return`matrix(${r},0,0,${r},0,0)`}function Fs(e){return`"${ir(`${e}`)}"`}function Qp(e){return ri(`${e}`)}function eo(e,t){return e?`${ri(e)}.${ri(t)}`:ri(t)}var tu=0,to=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${tu++}`,this.zero=new We(this,0),this.one=new We(this,1),this._true=new We(this,!0),this._false=new We(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=eu,i["css-string"]=Fs,i["css-name"]=Qp,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 Fs(this.pubTitle?this.pubTitle:"")}),this.defineBuiltInName("doc-title",function(){return Fs(this.docTitle?this.docTitle:"")})}}defineBuiltInName(e,t){this.values[e]=new ze(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 ef(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function iu(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 tf(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function nf(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var At={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 nu(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 io=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=Jp}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(iu(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:At[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 We(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}},Tt=class{constructor(e){this.scope=e,c(this,"key"),this.scope=e,this.key=`_${tu++}`}toString(){let e=new oi;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===gl.PENDING?!1:n;{i[this.key]=gl.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}},ru=class extends Tt{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)}},ps=class extends Tt{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)}},su=class extends ps{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},pn=class extends ps{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},ou=class extends ps{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},ua=class extends ps{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},si=class extends ru{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},rf=class extends si{constructor(e,t){super(e,t)}getOp(){return"not "}},ji=class extends ru{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},ca=class extends su{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},sf=class extends ca{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},da=class extends su{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},of=class extends da{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},af=class extends da{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},lf=class extends pn{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},hf=class extends pn{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},uf=class extends pn{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},no=class extends pn{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},pa=class extends pn{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},cf=class extends pn{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},au=class extends ou{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},lu=class extends ou{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},fa=class extends ua{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},hu=class extends ua{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},uu=class extends ua{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},nr=class extends Tt{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(ri(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},De=class extends Tt{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)}},ml=class extends Tt{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(ri(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},ze=class extends Tt{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 df(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function pf(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 On=class cu extends Tt{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),df(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=pf(t,this.params,i);return n===this.params?this:new cu(this.scope,this.qualifiedName,n)}},ff=class du extends Tt{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 du(this.scope,n,r,s)}},We=class extends Tt{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(ir(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},wl=class pu extends Tt{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(ir(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 pu(this.scope,this.name,n)}},gf=class extends Tt{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)}},fu=class extends Tt{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 Et(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 ca(e,t,i)}function Y(e,t,i){return t===e.zero?i:i===e.zero?t:new au(e,t,i)}function pe(e,t,i){return t===e.zero?new ji(e,i):i===e.zero?t:new lu(e,t,i)}function Nr(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new fa(e,t,i)}function ro(e,t,i){return t===e.zero?e.zero:i===e.one?t:new hu(e,t,i)}var Kt=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}},Ai=class extends Kt{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?X:t===e.values?e:new J(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?X:t===e.values?e:new Ze(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?X:t===e.values?e:new Ri(e.name,t)}visitExpr(e){return e}},Je=class{toString(){let e=new oi;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new oi;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}},gu=class mu extends Je{static get instance(){return this.empty||(this.empty=new mu),this.empty}constructor(){super()}toExpr(t,i){return new We(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};c(gu,"empty");var mf=gu,X=mf.instance,wu=class yu extends Je{static get instance(){return this.slash||(this.slash=new yu),this.slash}constructor(){super()}toExpr(t,i){return new We(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};c(wu,"slash");var wf=wu,fn=wf.instance,j=class extends Je{constructor(e){super(),this.str=e}toExpr(e,t){return new We(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(ir(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},so={},le=class extends Je{constructor(e){if(super(),this.name=e,so[e])throw new Error("E_INVALID_CALL");so[e]=this}toExpr(e,t){return new We(e,this.name)}appendTo(e,t){t?e.append(ri(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function F(e){let t=so[e];return t||(t=new le(e)),t}var I=class extends Je{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 fa(e,t,new We(e,this.num/100)):new nr(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}},gt=class extends Je{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new We(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},Le=class extends gt{constructor(e){super(e)}visit(e){return e.visitInt(this)}},bu=class extends Je{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},Qe=class extends Je{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(ir(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},vu=class extends Je{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function ga(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 J=class extends Je{constructor(e){super(),this.values=e}appendTo(e,t){ga(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},Ze=class extends Je{constructor(e){super(),this.values=e}appendTo(e,t){ga(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},Ri=class extends Je{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(ri(this.name)),e.append("("),ga(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},U=class extends Je{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof We||this.expr instanceof nr?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}},_i=class extends Je{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function et(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 xu(e,t){return new I(et(e,t),"px")}var b={absolute:F("absolute"),all:F("all"),always:F("always"),anywhere:F("anywhere"),auto:F("auto"),avoid:F("avoid"),balance:F("balance"),balance_all:F("balance-all"),block:F("block"),block_end:F("block-end"),block_start:F("block-start"),both:F("both"),bottom:F("bottom"),border_box:F("border-box"),break_all:F("break-all"),break_word:F("break-word"),clip:F("clip"),crop:F("crop"),cross:F("cross"),column:F("column"),discard:F("discard"),exclusive:F("exclusive"),_false:F("false"),fixed:F("fixed"),flex:F("flex"),flow_root:F("flow-root"),footnote:F("footnote"),footer:F("footer"),grid:F("grid"),header:F("header"),hidden:F("hidden"),horizontal_tb:F("horizontal-tb"),inherit:F("inherit"),initial:F("initial"),inline:F("inline"),inline_block:F("inline-block"),inline_end:F("inline-end"),inline_start:F("inline-start"),inside:F("inside"),keep:F("keep"),landscape:F("landscape"),left:F("left"),line:F("line"),list_item:F("list-item"),ltr:F("ltr"),manual:F("manual"),max_content:F("max-content"),min_content:F("min-content"),none:F("none"),normal:F("normal"),oeb_page_foot:F("oeb-page-foot"),oeb_page_head:F("oeb-page-head"),outside:F("outside"),padding_box:F("padding-box"),page:F("page"),relative:F("relative"),revert:F("revert"),right:F("right"),same:F("same"),scale:F("scale"),snap_block:F("snap-block"),snap_inline:F("snap-inline"),solid:F("solid"),spread:F("spread"),_static:F("static"),rtl:F("rtl"),table:F("table"),table_caption:F("table-caption"),table_cell:F("table-cell"),table_footer_group:F("table-footer-group"),table_header_group:F("table-header-group"),table_row:F("table-row"),top:F("top"),transparent:F("transparent"),unset:F("unset"),vertical_lr:F("vertical-lr"),vertical_rl:F("vertical-rl"),visible:F("visible"),_true:F("true")},yl=new I(100,"%"),rr=new I(100,"pvw"),sr=new I(100,"pvh"),Ee=new I(0,"px"),W0=new vu("U+0-10FFFF"),bl={"font-size":1,"line-height":2,color:3};function K(e){return e===b.inherit||e===b.initial||e===b.revert||e===b.unset}function vl(e,t){let i=bl[e]||Number.MAX_VALUE,n=bl[t]||Number.MAX_VALUE;return i-n}function zt(e){return e?.length>2&&e.startsWith("--")}var zi,Di,Vi,Su=class Vt{constructor(t,i,n){Z(this,zi),Z(this,Di),Z(this,Vi),Fe(this,zi,Math.round(Math.max(0,Math.min(t,Vt.MAX)))),Fe(this,Di,Math.round(Math.max(0,Math.min(i,Vt.MAX)))),Fe(this,Vi,Math.round(Math.max(0,Math.min(n,Vt.MAX))))}static fromInt(t,i,n){return new Vt(t,i,n)}offset(t,i,n){return new Vt(M(this,zi)+t,M(this,Di)+i,M(this,Vi)+n)}toKey(){return JSON.stringify([M(this,zi),M(this,Di),M(this,Vi)])}toColorFunc(t){return new Ri("color",[new J([F("srgb"),new gt(M(this,zi)/Vt.MAX),new gt(M(this,Di)/Vt.MAX),new gt(M(this,Vi)/Vt.MAX),...t!==null?[fn,new gt(t)]:[]])])}};zi=new WeakMap,Di=new WeakMap,Vi=new WeakMap,c(Su,"MAX",1e4);var Jt=Su,mi,wi,yi,Lt,Cu=class st{constructor(t,i,n,r){Z(this,mi),Z(this,wi),Z(this,yi),Z(this,Lt),Fe(this,mi,Math.round(Math.max(0,Math.min(t,st.MAX)))),Fe(this,wi,Math.round(Math.max(0,Math.min(i,st.MAX)))),Fe(this,yi,Math.round(Math.max(0,Math.min(n,st.MAX)))),Fe(this,Lt,Math.round(Math.max(0,Math.min(r,st.MAX))))}static fromInt(t,i,n,r){return new st(t,i,n,r)}static fromNumber(t,i,n,r){return new st(t*st.MAX,i*st.MAX,n*st.MAX,r*st.MAX)}toSRGB(){let t=st.MAX-M(this,Lt);return Jt.fromInt(Jt.MAX-Math.min(Jt.MAX,Math.round(M(this,mi)*t/st.MAX)+M(this,Lt)),Jt.MAX-Math.min(Jt.MAX,Math.round(M(this,wi)*t/st.MAX)+M(this,Lt)),Jt.MAX-Math.min(Jt.MAX,Math.round(M(this,yi)*t/st.MAX)+M(this,Lt)))}equals(t){return M(this,mi)===M(t,mi)&&M(this,wi)===M(t,wi)&&M(this,yi)===M(t,yi)&&M(this,Lt)===M(t,Lt)}toJSON(){return{c:M(this,mi),m:M(this,wi),y:M(this,yi),k:M(this,Lt)}}};mi=new WeakMap,wi=new WeakMap,yi=new WeakMap,Lt=new WeakMap,c(Cu,"MAX",1e4);var yf=Cu;function Oi(e){return e instanceof gt?Math.max(0,Math.min(1,e.num)):e instanceof I&&e.unit==="%"?Math.max(0,Math.min(1,e.num/100)):null}function ku(e){if(e.name!=="device-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=Oi(t[0]),n=Oi(t[1]),r=Oi(t[2]),s=Oi(t[3]);if(i===null||n===null||r===null||s===null)return null;let o=null;if(t.length>=5){if(t[4]===fn){if(t.length!==6)return null;o=Oi(t[5])}else{if(t.length!==5)return null;o=Oi(t[4])}if(o===null)return null}return{cmyk:yf.fromNumber(i,n,r,s),alpha:o}}function*bf(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 Si,qr,Eu,xl,Nu=class{constructor(){Z(this,qr),Z(this,Si,new Map)}registerDeviceCmyk(e){let t=ku(e);return t?Se(this,qr,Eu).call(this,t.cmyk).toColorFunc(t.alpha):null}toJSON(){let e={};return M(this,Si).forEach((t,i)=>{e[i]=t.toJSON()}),e}};Si=new WeakMap,qr=new WeakSet,Eu=function(e){let t=e.toSRGB(),i=t.toKey(),n=M(this,Si).get(i);return n?n.equals(e)?t:Se(this,qr,xl).call(this,e,t):(M(this,Si).set(i,e),t)},xl=function(e,t){for(let i=1;i<=Jt.MAX;i++)for(let[n,r,s]of bf(i)){let o=t.offset(n,r,s),a=o.toKey();if(!M(this,Si).has(a))return M(this,Si).set(a,e),o}return $.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(e.toJSON())}`),t};var Pr,Cn,kn,Pu=class extends Ai{constructor(e){super(),Z(this,Pr),Z(this,Cn,new Map),Z(this,kn,!1),Fe(this,Pr,e??new Nu)}reset(){Fe(this,kn,!1)}hadDeviceCmyk(){return M(this,kn)}recordConversion(e,t){M(this,Cn).set(e,t)}getConversions(){if(M(this,Cn).size===0)return null;let e={};return M(this,Cn).forEach((t,i)=>{e[i]=t}),e}visitFunc(e){let t=M(this,Pr).registerDeviceCmyk(e);return t?(Fe(this,kn,!0),t):super.visitFunc(e)}};Pr=new WeakMap,Cn=new WeakMap,kn=new WeakMap;var bt=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},ti=class{constructor(e,t){this.x=e,this.y=t}},Ls=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},Sl=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},Gt=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 vf(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var fs=class Tu{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],l;s.y<a.y?l=new Sl(s,a,1,i):l=new Sl(a,s,-1,i),t.push(l),s=a}}withOffset(t,i){let n=[];for(let r of this.points)n.push(new ti(r.x+t,r.y+i));return new Tu(n)}};function Cl(e,t,i,n){let r=[];for(let s=0;s<20;s++){let o=s*2*Math.PI/20;r.push(new ti(e+i*Math.sin(o),t+n*Math.cos(o)))}return new fs(r)}function ma(e,t,i,n){return new fs([new ti(e,t),new ti(i,t),new ti(i,n),new ti(e,n)])}var wr=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function kl(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 xf(e,t,i,n){let r,s,o,a;t.high.y<i&&$.warn("Error: inconsistent segment (1)"),t.low.y<=i?(r=kl(t,i),s=t.winding):(r=t.low.x,s=0),t.high.y>=n?(o=kl(t,n),a=t.winding):(o=t.high.x,a=0),r<o?(e.push(new wr(r,s,t.shapeId,-1)),e.push(new wr(o,a,t.shapeId,1))):(e.push(new wr(o,a,t.shapeId,-1)),e.push(new wr(r,s,t.shapeId,1)))}function Sf(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=[],l=!1,h=e.length;for(let u=0;u<h;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}}l!=p&&(a.push(d.x),l=p)}return a}function Cf(e,t){return t?Math.ceil(e/t)*t:e}function El(e,t){return t?Math.floor(e/t)*t:e}function kf(e){return new ti(e.y,-e.x)}function Yr(e){return new bt(e.y1,-e.x2,e.y2,-e.x1)}function Iu(e){return new bt(-e.y2,e.x1,-e.y1,e.x2)}function Nl(e){return new fs(e.points.map(t=>kf(t)))}function Ef(e,t,i,n,r,s){s&&(e=Yr(e),t=t.map(y=>Nl(y)),i=i.map(y=>Nl(y)));let o=t.length,a=i?i.length:0,l=[],h=[],u,d,p;for(u=0;u<o;u++)t[u].addSegments(h,u);for(u=0;u<a;u++)i[u].addSegments(h,u+o);let f=h.length;h.sort(vf);let m=0;for(;h[m].shapeId>=o;)m++;let g=h[m].low.y;g>e.y1&&l.push(new Gt(e.y1,g,e.x2,e.x2));let w=0,v=[];for(;w<f&&(p=h[w]).low.y<g;)p.high.y>g&&v.push(p),w++;for(;w<f||v.length>0;){let y=e.y2,C=Math.min(Cf(Math.ceil(g+n),r),e.y2);for(d=0;d<v.length&&y>C;d++)p=v[d],p.low.x==p.high.x?p.high.y<y&&(y=Math.max(El(p.high.y,r),C)):p.low.x!=p.high.x&&(y=C);for(y>e.y2&&(y=e.y2);w<f&&(p=h[w]).low.y<y;){if(p.high.y<g){w++;continue}if(p.low.y<C)p.low.y==p.high.y&&p.low.y==g||(v.push(p),y=C),w++;else{let H=El(p.low.y,r);H<y&&(y=H);break}}let E=[];for(d=0;d<v.length;d++)xf(E,v[d],g,y);E.sort((H,V)=>H.x-V.x||H.lowOrHigh-V.lowOrHigh);let A=Sf(E,o,a);if(A.length==0)l.push(new Gt(g,y,e.x2,e.x2));else{let H=0,V=e.x1;for(d=0;d<A.length;d+=2){let ie=Math.max(e.x1,A[d]),ne=Math.min(e.x2,A[d+1])-ie;ne>H&&(H=ne,V=ie)}H==0?l.push(new Gt(g,y,e.x2,e.x2)):l.push(new Gt(g,y,Math.max(V,e.x1),Math.min(V+H,e.x2)))}if(y==e.y2)break;for(g=y,d=v.length-1;d>=0;d--)v[d].high.y<=y&&v.splice(d,1)}return Au(e,l),l}function Au(e,t){let i=t.length-1,n=new Gt(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 Ru(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 Nf(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 bt(t.x1,i,t.x2,s)}function Pf(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 bt(t.x1,s,t.x2,i)}function Tf(e,t,i,n){let r=i.y1,s=i.x2-i.x1,o=i.y2-i.y1,a=Ru(t,r);for(;;){let l=r+o;if(l>e.y2)return!1;let h=e.x1,u=e.x2;for(let d=a;d<t.length&&t[d].y1<l;d++){let p=t[d];p.x1>h&&(h=p.x1),p.x2<u&&(u=p.x2)}if(h+s<=u||a>=t.length)return n=="left"?(i.x1=h,i.x2=h+s):(i.x1=u-s,i.x2=u),i.y2+=r-i.y1,i.y1=r,!0;r=t[a].y2,a++}}function If(e,t,i,n,r){for(n||(n=[new Gt(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 Gt(o,e.y2,e.x1,e.x2));let a=Ru(t,n[0].y1);for(let l of n){if(a==t.length)break;for(t[a].y1<l.y1&&(s=t[a],a++,t.splice(a,0,new Gt(l.y1,s.y2,s.x1,s.x2)),s.y2=l.y1);a<t.length&&(s=t[a++],s.y2>l.y2&&(t.splice(a,0,new Gt(l.y2,s.y2,s.x1,s.x2)),s.y2=l.y2),l.x1!=l.x2&&(r=="left"?s.x1=Math.min(l.x2,e.x2):s.x2=Math.max(l.x1,e.x1)),s.y2!=l.y2););}Au(e,t)}var Af=class extends Kt{constructor(){super(),c(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Rf(e){if(e){let t=new Af;try{return e.visit(t),t.propSet}catch(i){$.warn(i,"toSet:")}}return{}}var Ff=class extends Kt{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function Pl(e,t){if(e){let i=new Ff(t);try{return e.visit(i),i.value}catch(n){$.warn(n,"toInt: ")}}return t}var Lf=class extends Kt{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 I(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 l=a%2==0?i:n;a==3&&this.name=="circle"&&(l=Math.sqrt((i*i+n*n)/2)),s.push(o.num*l/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 ti(e+s[a],t+s[a+1]));return new fs(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 Cl(e+s[0],t+s[1],s[2],s[3]);break;case"circle":if(s.length==3)return Cl(e+s[0],t+s[1],s[2],s[2]);break}}return null}};function Fu(e,t,i,n,r,s){if(e){let o=new Lf;try{return e.visit(o),o.getShape(t,i,n,r,s)}catch(a){$.warn(a,"toShape:")}}return ma(t,i,t+n,i+r)}var Of=class extends Kt{constructor(e){super(),this.reset=e,c(this,"counters",{}),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)+1,e}visitInt(e){return this.name&&(this.counters[this.name]+=e.num-(this.reset?0:1)),e}visitSpaceList(e){return this.visitValues(e.values),e}};function Bn(e,t){let i=new Of(t);try{e.visit(i)}catch(n){$.warn(n,"toCounters:")}return i.counters}var Bf=class extends Ai{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new Qe(this.transformer.transformURL(e.url,this.baseUrl))}};function Os(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function Xi(e,t){if(t==="content"){let i=e.cloneNode(!0);return i.querySelectorAll("[data-adapt-pseudo]").forEach(n=>n.remove()),i.textContent||""}else{let i=e.querySelector(`[data-adapt-pseudo="${t}"]`);return i&&i.textContent||""}}var Mf=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}},_f=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()}},zf=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",{}),c(this,"runningElements",{})}setStyler(e){this.styler=e}getFragment(e){let t=e.match(/^[^#]*#(.*)$/);return t?t[1]:null}getTransformedId(e){let t=this.counterStore.documentURLTransformer.transformURL(Pe(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 ze(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 ze(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}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"?Xi(n,t):Xi(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=this.getTargetCounters(n,r,!1);if(s&&s[t]){let a=s[t];return new We(this.rootScope,i(a[a.length-1]||null))}let o=new ze(this.pageScope,()=>{if(s=this.getTargetCounters(n,r,!0),s)if(s[t]){let a=s[t];return i(a[a.length-1]||null)}else{let a=this.getTargetPageCounters(r);if(a)if(this.counterStore.resolveReference(r),a[t]){let l=a[t];return i(l[l.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 ze(this.pageScope,()=>{let s=this.getTargetPageCounters(r);if(s){this.counterStore.resolveReference(r);let o=s[t]||[],a=this.getTargetCounters(n,r,!0)[t]||[];return i(o.concat(a))}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counters-${t}-of-${e}`)}getTargetTextVal(e,t){let i=this.getTransformedId(e),n=new ze(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 l=(s??"")+(o??"")+(a??"");this.counterStore.resolveReference(i);let h=l.match(Xr);return h?h[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 ze(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new ze(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(Yh),s=this.counterStore.currentPage,o=s.isBlankPage?s.offset-1:s.offset,a=s.isBlankPage?o:Math.max(o,...Array.from(s.container.querySelectorAll(`[${Ut}]`)).map(p=>parseInt(p.getAttribute(Ut),10))),l=-1,h=-1,u=-1,d=-1;for(let p=0;p<r.length;p++){let f=r[p],m=p>0?r[p-1]:-1,g=p<r.length-1?r[p+1]:-1;if(f>a)break;if(f>=o){if(l<0&&(l=f,d=-1),h<0)if(f===o)h=f;else{m<l&&(h=m);let w=s.container.querySelector(`[${Ut}="${f}"]`);if(!w)h<0&&(h=f);else{let v=s.container.querySelector(`[${Ut}="${o}"]`);if(v||(v=s.container.querySelector(`[${Ut}="0"]`)),v){for(let y=v;y;y=y.firstElementChild)if(y===w){h=f;break}}}}u=f}else(g>a||g<0)&&(l=h=u=d=f)}return n[{first:l,start:h,last:u,"first-except":d}[i]]||""}setNamedString(e,t,i){let n=this.namedStringValues[e]||(this.namedStringValues[e]={});n[i]=t}setRunningElement(e,t){let i=this.runningElements[e]||(this.runningElements[e]={});i[t]=String(t)}},Df=class{constructor(e){this.documentURLTransformer=e,c(this,"countersById",{}),c(this,"pageCountersById",{}),c(this,"pageTextById",{}),c(this,"currentPageCounters",{}),c(this,"previousPageCounters",{}),c(this,"currentPageCountersStack",[]),c(this,"pageIndicesById",{}),c(this,"currentPage",null),c(this,"newReferencesOfCurrentPage",[]),c(this,"referencesToSolve",[]),c(this,"referencesToSolveStack",[]),c(this,"unresolvedReferences",{}),c(this,"resolvedReferences",{}),c(this,"pagesCounterExprs",[]),c(this,"pageCounterExprs",[]),c(this,"targetCounterExprs",[]),c(this,"targetTextExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new _f(this,e)}createCounterResolver(e,t,i){return new zf(this,e,t,i)}setCurrentPage(e){this.currentPage=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=Os(this.currentPageCounters);let i,n=e["counter-reset"];if(n){let o=n.evaluate(t);o&&(i=Bn(o,!0))}if(i)for(let o in i)this.definePageCounter(o,i[o]);let r,s=e["counter-increment"];if(s){let o=s.evaluate(t);o&&(r=Bn(o,!1))}r?"page"in r||(r.page=1):(r={},r.page=1);for(let o in r){this.currentPageCounters[o]||this.definePageCounter(o,0);let a=this.currentPageCounters[o];a[a.length-1]+=r[o]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=Os(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 Mf(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let s=Os(this.currentPageCounters);i.forEach(o=>{this.pageCountersById[o]=s;let a=this.currentPage.elementsById[o];if(a&&a.length>0){let h=a[0];this.pageTextById[o]={content:Xi(h,"content"),before:Xi(h,"before"),after:Xi(h,"after"),marker:Xi(h,"marker")}}let l=this.pageIndicesById[o];if(l&&l.pageIndex<t){let h=this.resolvedReferences[o];if(h){let u=this.unresolvedReferences[o];u||(u=this.unresolvedReferences[o]=[]);let d;for(;d=h.shift();)d.unresolve(),u.push(d)}}this.pageIndicesById[o]={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}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 ze){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(`[${Ut}="${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(_s,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(zs,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?Bs:Ms,e.key),s}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${Ms}]`);for(let r of t){let s=r.getAttribute(Ms),o=this.pageCounterExprs.find(u=>u.expr.key===s),a=(o?.expr).str,l=a?.replace(/^page-counters?-/,""),h=this.currentPageCounters[l];h&&(r.textContent=o.format(h))}let i=e.querySelectorAll(`[${_s}]`);for(let r of i)r.setAttribute(Tl,!0);let n=e.querySelectorAll(`[${zs}]`);for(let r of n)r.setAttribute(Il,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${Bs}]`),n=e.contentContainer.childElementCount;for(let o of i){let a=o.getAttribute(Bs),l=this.pagesCounterExprs.findIndex(h=>h.expr.key===a);l>=0,o.textContent=this.pagesCounterExprs[l].format([n])}let r=e.root.querySelectorAll(`[${Tl}]`);for(let o of r){let a=o.getAttribute(_s),l=this.targetCounterExprs.find(h=>h.expr.key===a);if(l&&l.transformedId){let h=this.pageCountersById[l.transformedId];if(h){let u=h[l.name];u&&(o.textContent=l.format(u[u.length-1]))}}}let s=e.root.querySelectorAll(`[${Il}]`);for(let o of s){let a=o.getAttribute(zs),l=this.targetTextExprs.find(h=>h.expr.key===a);if(l&&l.transformedId){let h=this.pageTextById[l.transformedId];h&&(o.textContent=(t=h[l.pseudoElement])!=null?t:"")}}}createLayoutConstraint(e){return new Vf(this,e)}},Bs="data-vivliostyle-pages-counter",Ms="data-vivliostyle-page-counter",_s="data-vivliostyle-target-counter",zs="data-vivliostyle-target-text",Tl="data-vivliostyle-target-counter-in-running",Il="data-vivliostyle-target-text-in-running",Vf=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 Hf(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 di(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,Hf)}var Uf=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 Ge(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 Ht=[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];Ht[NaN]=80;var Ot=[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];Ot[NaN]=43;var $f=[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];Ot[NaN]=43;var Lu=[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];Lu[NaN]=35;var Ou=[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];Ou[NaN]=45;var oo=[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];oo[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 pi=Ge(35,[61,36]),Wf=Ge(35,[58,77]),Gf=Ge(35,[61,36,124,50]),jf=Ge(35,[38,51]),Xf=Ge(35,[42,54]),qf=Ge(39,[42,55]),Yf=Ge(54,[42,55,47,56]),Kf=Ge(62,[62,82]),Zf=Ge(35,[61,36,33,70]),Jf=Ge(62,[45,71]),Qf=Ge(63,[45,81]),Ds=Ge(76,[10,72,13,72]),eg=Ge(39,[39,46,10,72,13,72,92,48]),tg=Ge(39,[34,46,10,72,13,72,92,49]),ig=Ge(39,[39,47,10,74,13,74,92,48]),ng=Ge(39,[34,47,10,74,13,74,92,49]),Al=Ge(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),rg=Ge(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]),sg=Ge(39,[39,68,10,74,13,74,92,75,NaN,67]),og=Ge(39,[34,68,10,74,13,74,92,75,NaN,67]),ag=Ge(72,[9,39,10,39,13,39,32,39,41,69]),lg=15,Ft=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=lg,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new Uf}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=Ht,r=this.input,s=this.position,o=this.buffer,a=0,l=0,h="",u=0,d=!1,p=o[e],f=-9;for(;;){let m=r.charCodeAt(s);switch(n[m]||n[65]){case 72:h=r.substring(l,s),isNaN(m)?a=0:a=54,n=Ht;break;case 1:s++,d=!0;continue;case 2:l=s++,n=oo;continue;case 3:a=1,l=s++,n=Ot;continue;case 4:l=s++,a=31,n=pi;continue;case 33:a=2,l=++s,n=eg;continue;case 34:a=2,l=++s,n=tg;continue;case 6:l=++s,a=7,n=Ot;continue;case 7:l=s++,a=32,n=pi;continue;case 8:l=s++,a=21;break;case 9:l=s++,a=32,n=jf;continue;case 10:l=s++,a=10;break;case 11:l=s++,a=11;break;case 12:l=s++,a=36,n=pi;continue;case 13:l=s++,a=23;break;case 14:l=s++,a=16;break;case 15:a=24,l=s++,n=Lu;continue;case 16:l=s++,n=$f;continue;case 78:l=s++,a=9,n=Ot;continue;case 17:l=s++,a=19,n=Xf;continue;case 18:l=s++,a=18,n=Wf;continue;case 77:s++,a=50;break;case 19:l=s++,a=17;break;case 20:l=s++,a=38,n=Zf;continue;case 21:l=s++,a=39,n=pi;continue;case 22:l=s++,a=37,n=pi;continue;case 23:l=s++,a=22;break;case 24:l=++s,a=20,n=Ot;continue;case 25:l=s++,a=14;break;case 26:l=s++,a=15;break;case 27:l=s++,a=12;break;case 28:l=s++,a=13;break;case 29:l=s++,f=l,a=1,n=Ds;continue;case 30:l=s++,a=33,n=pi;continue;case 31:l=s++,a=34,n=Gf;continue;case 32:l=s++,a=35,n=pi;continue;case 35:break;case 36:s++,a=a+41-31;break;case 37:a=5,u=parseInt(r.substring(l,s),10);break;case 38:a=4,u=parseFloat(r.substring(l,s));break;case 39:s++;continue;case 40:a=3,u=parseFloat(r.substring(l,s)),l=s++,n=Ot;continue;case 41:a=3,u=parseFloat(r.substring(l,s)),h="%",l=s++;break;case 42:s++,n=ao;continue;case 43:if(h=di(r.substring(l,s)),a===27&&m===63||a===1&&h.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=Ds;continue;case 45:h=di(r.substring(l,s));break;case 46:h=r.substring(l,s),s++;break;case 47:h=di(r.substring(l,s)),s++;break;case 48:f=s,s+=2,n=ig;continue;case 49:f=s,s+=2,n=ng;continue;case 50:s++,a=25;break;case 51:s++,a=26;break;case 52:if(h=r.substring(l,s),a==1){if(s++,h.toLowerCase()=="url"){n=Al;continue}a=6}break;case 53:if(h=di(r.substring(l,s)),a==1){if(s++,h.toLowerCase()=="url"){n=Al;continue}a=6}break;case 54:n=qf,s++;continue;case 55:n=Yf,s++;continue;case 56:n=Ht,s++;continue;case 57:n=Kf,s++,r[s]!==">"&&(a=1,n=Ot);continue;case 81:a=51,h=r.substring(l,++s),n=Ht;break;case 82:a=52,h=r.substring(l,++s),n=Ht;break;case 58:a=5,n=oo,s++;continue;case 59:a=4,n=ao,s++;continue;case 60:a=1,n=Ot,s++;continue;case 61:a=1,n=Ds,f=s++;continue;case 62:s--;break;case 63:s-=2;break;case 64:l=s++,n=rg;continue;case 65:l=++s,n=sg;continue;case 66:l=++s,n=og;continue;case 67:a=8,h=di(r.substring(l,s)),s++;break;case 69:s++;break;case 70:n=Jf,s++;continue;case 71:n=Qf,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,h=di(r.substring(l,s)),s++,n=ag;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,h="E_CSS_UNEXPECTED_NEWLINE",n=Ht;break;case 73:if(s-f<9&&r.substring(f+1,s+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){s++,n=Ot;continue}h=di(r.substring(l,s));break;case 75:f=s++;continue;case 76:s++,n=Ou;continue;default:if(n!==Ht){a=54,h="E_CSS_UNEXPECTED_STATE";break}l=s,a=0}if(p.type=a,p.precededBySpace=d,p.num=u,p.text=h,p.position=l,e++,e>=t)break;n=Ht,d=!1,p=o[e&i]}this.position=s,this.tail=e&i}},_e=null,lo=null;function ho(){return _e}function O(e){if(!_e)throw new Error("E_TASK_NO_CONTEXT");_e.name||(_e.name=e);let t=_e,i=new gs(t,t.top,e);return t.top=i,i.state=1,i}function hg(e){return new dg(e||new cg)}function N(e){return new uo(e)}function an(e,t,i){let n=O(e);n.handler=i;try{t(n)}catch(r){n.task.raise(r,n)}return n.result()}function ug(e,t){return(_e?_e.getScheduler():lo||hg()).run(e,t)}var cg=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 Up,lo||(lo=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){$.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new pg(this,t||"");i.top=new gs(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){$.error(o)}};try{e().then(s=>{i.result=s,r()})}catch(s){i.raise(s),r()}});let n=_e;return _e=i,this.schedule(i.top.suspend("bootstrap")),_e=n,i}},Bu=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=_e;return _e=e,e.top.finish(this.result),_e=t,!0}return!1}cancel(){this.canceled=!0}},pg=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!==_e&&this.continuation){this.continuation.cancel();let t=new Bu(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=O("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&&$.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 G=new Of,$o=(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))($o||{}),mo={};function Nt(e,t,i){if(!$o[e])G.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=mo[e];n||(n=mo[e]=[]),i?n.unshift(t):n.push(t)}}function xu(e,t){if(!$o[e])G.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=mo[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function Ot(e){return mo[e]||[]}var Bf={registerHook:Nt,removeHook:xu},Su=class{constructor(e){this.performanceInstance=e,d(this,"timestamps",{}),d(this,"registerTiming"),d(this,"registerStartTiming"),d(this,"registerEndTiming"),this.registerTiming=Xi,this.registerStartTiming=this.registerStartTiming=Xi,this.registerEndTiming=this.registerEndTiming=Xi}forceRegisterStartTiming(e,t){us.call(this,e,"start",t)}forceRegisterEndTiming(e,t){us.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
+ `}}),G.info(t)}disable(){this.registerTiming=Xi,this.registerStartTiming=this.registerStartTiming=Xi,this.registerEndTiming=this.registerEndTiming=Xi}enable(){this.registerTiming=us,this.registerStartTiming=this.registerStartTiming=Fl,this.registerEndTiming=this.registerEndTiming=Mf}isEnabled(){return this.registerStartTiming===Fl}};function Xi(){}function us(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 Fl(e,t){this.registerTiming(e,"start",t)}function Mf(e,t){this.registerTiming(e,"end",t)}var _f={now:Date.now},Df=window&&window.performance,vt=new Su(Df||_f);vt.forceRegisterStartTiming("load_vivliostyle");var zf={profiler:{registerStartTiming:vt.registerStartTiming,registerEndTiming:vt.registerEndTiming,printTimings:vt.printTimings,disable:vt.disable,enable:vt.enable}},Da=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",wo=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,jt="data-adapt-eloff",Vf={};function za(e){return JSON.parse(e)}function qt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function Cu(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var zi=window.location.href;function Rl(e){zi=e}var mi=window.location.href;function Ll(e){mi=e}function Uf(e){let t=Cu(e).match(/^(https?:\/\/raw\.githubusercontent\.com\/web-platform-tests\/wpt\/master)(?:\/|$)/);return t?t[1]:null}function Ne(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=Uf(t);return s?s+e:(i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e)}if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=Cu(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 yo(e,t){return e.match(/^#/)&&t?qt(t)+e:Ne(e,t)}function mn(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?:)\/\/wpt\.live\/(.*)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.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 Ol(e){return e==null?e:e.toString()}var Hf=class{constructor(){d(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}},ku=["","-webkit-","-moz-"],Zi={};function Xr(e,t){return CSS.supports(e+t,"unset")}function $f(e){let t=Zi[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return Zi[e]=null,null;case"text-combine-upright":if(Xr("-webkit-","text-combine")&&!Xr("","text-combine-upright"))return Zi[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of ku)if(Xr(i,e))return t=[i+e],Zi[e]=t,t;return G.warn("Property not supported by the browser: ",e),Zi[e]=null,null}function N(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let r=$f(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 pi(e,t,i){try{let n=Zi[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function As(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 ri=class{constructor(){d(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 Eu(e){return`\\${e.charCodeAt(0).toString(16)} `}function wi(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Eu)}function vr(e){return e.replace(/[\u0000-\u001F"\\]/g,Eu)}function Bl(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Ml(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function Wf(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function Pu(e,t){function i(n){return Wf(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function hi(e){return Pu(e)}function Gf(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function jf(e,t){t=typeof t=="string"?t:"\\u";function i(r){return Gf(r,t)}let n=new RegExp(`${hi(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function oi(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 Nu(e,t){return e-t}function _l(e,t){let i={};for(let n of e){let r=t(n);r&&!i[r]&&(i[r]=n)}return i}function Xf(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function cs(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 qf(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var Va=class{constructor(){d(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)}}},Bi={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function Tu(){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 Iu(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 Yf=Tu(),Dl={PENDING:{}};function Au(e,t,i,n){let r=Math.min((e-0)/i,(t-0)/n);return`matrix(${r},0,0,${r},0,0)`}function Zf(e){return`"${vr(`${e}`)}"`}function Kf(e){return wi(`${e}`)}function Fs(e,t){return e?`${wi(e)}.${wi(t)}`:wi(t)}var Fu=0,Rs=class{constructor(e,t){if(this.parent=e,this.resolver=t,d(this,"scopeKey"),d(this,"children",[]),d(this,"zero"),d(this,"one"),d(this,"_true"),d(this,"_false"),d(this,"values",{}),d(this,"funcs",{}),d(this,"builtIns",{}),this.scopeKey=`S${Fu++}`,this.zero=new Ke(this,0),this.one=new Ke(this,1),this._true=new Ke(this,!0),this._false=new Ke(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=Au,i["css-string"]=Zf,i["css-name"]=Kf,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 Fe(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 Jf(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function Ru(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 Qf(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function eg(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var zt={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 Lu(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 Ls=class{constructor(e,t,i,n){this.rootScope=e,this.viewportWidth=t,this.viewportHeight=i,d(this,"actualPageWidth",null),d(this,"pageWidth"),d(this,"actualPageHeight",null),d(this,"pageHeight"),d(this,"initialFontSize"),d(this,"rootFontSize",null),d(this,"isRelativeRootFontSize",null),d(this,"fontSize"),d(this,"rootLineHeight",null),d(this,"pref"),d(this,"scopes",{}),d(this,"pageAreaWidth",null),d(this,"pageAreaHeight",null),d(this,"pageVertical",null),d(this,"pubTitle",null),d(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=Yf}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(Ru(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:zt[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 Ke(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}},Mt=class{constructor(e){this.scope=e,d(this,"key"),this.scope=e,this.key=`_${Fu++}`}toString(){let e=new ri;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===Dl.PENDING?!1:n;{i[this.key]=Dl.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}},Ou=class extends Mt{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)}},Wo=class extends Mt{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 Wo{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},An=class extends Wo{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},Mu=class extends Wo{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},Ua=class extends Wo{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},yi=class extends Ou{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},tg=class extends yi{constructor(e,t){super(e,t)}getOp(){return"not "}},ln=class extends Ou{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},Ha=class extends Bu{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},ig=class extends Ha{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},$a=class extends Bu{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},ng=class extends $a{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},rg=class extends $a{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},og=class extends An{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},sg=class extends An{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},ag=class extends An{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},Os=class extends An{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Wa=class extends An{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},lg=class extends An{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},_u=class extends Mu{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},Du=class extends Mu{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},Ga=class extends Ua{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},zu=class extends Ua{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},Vu=class extends Ua{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},br=class extends Mt{constructor(e,t,i){var n;super(e),this.num=t,d(this,"unit"),this.unit=(n=i?.toLowerCase())!=null?n:""}appendTo(e,t){e.append(this.num.toString()),e.append(wi(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},qe=class extends Mt{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)}},zl=class extends Mt{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(wi(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},Fe=class extends Mt{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 hg(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function ug(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 Kn=class Uu extends Mt{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),hg(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=ug(t,this.params,i);return n===this.params?this:new Uu(this.scope,this.qualifiedName,n)}},cg=class Hu extends Mt{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 Hu(this.scope,n,r,o)}},Ke=class extends Mt{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(vr(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Vl=class $u extends Mt{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(vr(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 $u(this.scope,this.name,n)}},dg=class extends Mt{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)}},Wu=class extends Mt{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 Rt(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 Ha(e,t,i)}function ie(e,t,i){return t===e.zero?i:i===e.zero?t:new _u(e,t,i)}function fe(e,t,i){return t===e.zero?new ln(e,i):i===e.zero?t:new Du(e,t,i)}function qr(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new Ga(e,t,i)}function Bs(e,t,i){return t===e.zero?e.zero:i===e.one?t:new zu(e,t,i)}var li=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}},Hi=class extends li{constructor(){super(),d(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 ee(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 $i(e.name,t)}visitExpr(e){return e}},nt=class{toString(){let e=new ri;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new ri;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}},Gu=class ju extends nt{static get instance(){return this.empty||(this.empty=new ju),this.empty}constructor(){super()}toExpr(t,i){return new Ke(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};d(Gu,"empty");var pg=Gu,Y=pg.instance,Xu=class qu extends nt{static get instance(){return this.slash||(this.slash=new qu),this.slash}constructor(){super()}toExpr(t,i){return new Ke(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};d(Xu,"slash");var fg=Xu,Fn=fg.instance,X=class extends nt{constructor(e){super(),this.str=e}toExpr(e,t){return new Ke(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(vr(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},Ms=Object.create(null),ce=class extends nt{constructor(e){if(super(),this.name=e,Ms[e])throw new Error("E_INVALID_CALL");Ms[e]=this}toExpr(e,t){return new Ke(e,this.name)}appendTo(e,t){t?e.append(wi(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function B(e){let t=Ms[e];return t||(t=new ce(e)),t}var R=class extends nt{constructor(e,t){var i;super(),this.num=e,d(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 Ga(e,t,new Ke(e,this.num/100)):new br(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}},xt=class extends nt{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new Ke(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},ze=class extends xt{constructor(e){super(e)}visit(e){return e.visitInt(this)}},Yu=class extends nt{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},ht=class extends nt{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(vr(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},Zu=class extends nt{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function ja(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 ee=class extends nt{constructor(e){super(),this.values=e}appendTo(e,t){ja(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){ja(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},$i=class extends nt{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(wi(this.name)),e.append("("),ja(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},W=class extends nt{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof Ke||this.expr instanceof br?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}},Ki=class extends nt{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function st(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 Ku(e,t){return new R(st(e,t),"px")}var y={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")},Ul=new R(100,"%"),xr=new R(100,"pvw"),Sr=new R(100,"pvh"),Ae=new R(0,"px"),kx=new Zu("U+0-10FFFF"),Hl={"font-size":1,"line-height":2,color:3};function Z(e){return e===y.inherit||e===y.initial||e===y.revert||e===y.unset}function $l(e,t){let i=Hl[e]||Number.MAX_VALUE,n=Hl[t]||Number.MAX_VALUE;return i-n}function Zt(e){return e?.length>2&&e.startsWith("--")}var Ji,Qi,en,Ju=class Jt{constructor(t,i,n){ne(this,Ji),ne(this,Qi),ne(this,en),De(this,Ji,Math.round(Math.max(0,Math.min(t,Jt.MAX)))),De(this,Qi,Math.round(Math.max(0,Math.min(i,Jt.MAX)))),De(this,en,Math.round(Math.max(0,Math.min(n,Jt.MAX))))}static fromInt(t,i,n){return new Jt(t,i,n)}offset(t,i,n){return new Jt(U(this,Ji)+t,U(this,Qi)+i,U(this,en)+n)}toKey(){return JSON.stringify([U(this,Ji),U(this,Qi),U(this,en)])}toColorFunc(t){return new $i("color",[new ee([B("srgb"),new xt(U(this,Ji)/Jt.MAX),new xt(U(this,Qi)/Jt.MAX),new xt(U(this,en)/Jt.MAX),...t!==null?[Fn,new xt(t)]:[]])])}};Ji=new WeakMap,Qi=new WeakMap,en=new WeakMap,d(Ju,"MAX",1e4);var ei=Ju;function gg(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 Ii,Ai,Fi,Ht,Qu=class ut{constructor(t,i,n,r){ne(this,Ii),ne(this,Ai),ne(this,Fi),ne(this,Ht),De(this,Ii,Math.round(Math.max(0,Math.min(t,ut.MAX)))),De(this,Ai,Math.round(Math.max(0,Math.min(i,ut.MAX)))),De(this,Fi,Math.round(Math.max(0,Math.min(n,ut.MAX)))),De(this,Ht,Math.round(Math.max(0,Math.min(r,ut.MAX))))}static fromInt(t,i,n,r){return new ut(t,i,n,r)}static fromNumber(t,i,n,r){return new ut(t*ut.MAX,i*ut.MAX,n*ut.MAX,r*ut.MAX)}toSRGB(){let t=ut.MAX-U(this,Ht);return ei.fromInt(ei.MAX-Math.min(ei.MAX,Math.round(U(this,Ii)*t/ut.MAX)+U(this,Ht)),ei.MAX-Math.min(ei.MAX,Math.round(U(this,Ai)*t/ut.MAX)+U(this,Ht)),ei.MAX-Math.min(ei.MAX,Math.round(U(this,Fi)*t/ut.MAX)+U(this,Ht)))}equals(t){return U(this,Ii)===U(t,Ii)&&U(this,Ai)===U(t,Ai)&&U(this,Fi)===U(t,Fi)&&U(this,Ht)===U(t,Ht)}toJSON(){return{c:U(this,Ii),m:U(this,Ai),y:U(this,Fi),k:U(this,Ht)}}};Ii=new WeakMap,Ai=new WeakMap,Fi=new WeakMap,Ht=new WeakMap,d(Qu,"MAX",1e4);var ec=Qu;function qi(e){return e instanceof xt?Math.max(0,Math.min(1,e.num)):e instanceof R&&e.unit==="%"?Math.max(0,Math.min(1,e.num/100)):null}function tc(e){if(e.name!=="device-cmyk"&&e.name!=="cmyk")return null;let t=e.values.length===1&&e.values[0]instanceof ee?e.values[0].values:e.values;if(t.length<4||t.length>6)return null;let i=qi(t[0]),n=qi(t[1]),r=qi(t[2]),o=qi(t[3]);if(i===null||n===null||r===null||o===null)return null;let s=null;if(t.length>=5){if(t[4]===Fn){if(t.length!==6)return null;s=qi(t[5])}else{if(t.length!==5)return null;s=qi(t[4])}if(s===null)return null}return{cmyk:ec.fromNumber(i,n,r,o),alpha:s}}function*mg(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 di,vo,ic,Wl,nc=class{constructor(){ne(this,vo),ne(this,di,new Map)}registerDeviceCmyk(e){let t=tc(e);return t?Ee(this,vo,ic).call(this,t.cmyk).toColorFunc(t.alpha):null}registerCmykReserveMap(e){for(let[t,i]of e){let n=ei.fromInt(t.r,t.g,t.b),r=ec.fromInt(i.c,i.m,i.y,i.k);U(this,di).set(n.toKey(),r)}}toJSON(){let e={};return U(this,di).forEach((t,i)=>{e[i]=t.toJSON()}),e}};di=new WeakMap,vo=new WeakSet,ic=function(e){let t=e.toSRGB(),i=t.toKey(),n=U(this,di).get(i);return n?n.equals(e)?t:Ee(this,vo,Wl).call(this,e,t):(U(this,di).set(i,e),t)},Wl=function(e,t){for(let i=1;i<=ei.MAX;i++)for(let[n,r,o]of mg(i)){let s=t.offset(n,r,o),a=s.toKey();if(!U(this,di).has(a))return U(this,di).set(a,e),s}return G.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(e.toJSON())}`),t};var Yr,Un,Hn,rc=class extends Hi{constructor(e){super(),ne(this,Yr),ne(this,Un,new Map),ne(this,Hn,!1),De(this,Yr,e??new nc)}reset(){De(this,Hn,!1)}hadDeviceCmyk(){return U(this,Hn)}recordConversion(e,t){U(this,Un).set(e,t)}getConversions(){if(U(this,Un).size===0)return null;let e={};return U(this,Un).forEach((t,i)=>{e[i]=t}),e}visitFunc(e){let t=U(this,Yr).registerDeviceCmyk(e);return t?(De(this,Hn,!0),t):super.visitFunc(e)}};Yr=new WeakMap,Un=new WeakMap,Hn=new WeakMap;function oc(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function wg(e){return`^${e}`}function Gl(e){return e.replace(/[\[\]\(\),=;^]/g,wg)}function yg(e){return e.substr(1)}function _s(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,yg)}function vg(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=_s(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function jl(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=vg(i[2]),e=e.substr(i[0].length)}return t}var Xl=class{appendTo(e){e.append("!")}applyTo(e){return!1}},ql=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!=oc(e.node))){let s=t.ownerDocument.getElementById(this.id);s?e.node=s:G.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},Yl=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(Gl(this.textBefore)),e.append(","),this.textAfter&&e.append(Gl(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Zl=class sc{constructor(){d(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=jl(i[4]),o.push(new ql(a,h,Ol(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=_s(h));let l=i[7];l&&(l=_s(l)),s=jl(i[10]),o.push(new Yl(a,h,l,Ol(s.s)));break}case"!":r++,o.push(new Xl);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 sc,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 Yl(i,a,h,r)),r=null);s&&!(!s||s.nodeType==9);){let l=n?null:oc(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;o.push(new ql(u,l,r)),r=null,t=s,s=s.parentNode,n=!1}o.reverse(),this.steps?(o.push(new Xl),this.steps=o.concat(this.steps)):this.steps=o}toString(){if(!this.steps)return"";let t=new ri;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")}},Pt=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},fi=class{constructor(e,t){this.x=e,this.y=t}},ds=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},Kl=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},ii=class{constructor(e,t,i,n){this.y1=e,this.y2=t,this.x1=i,this.x2=n,d(this,"left",null),d(this,"right",null)}};function bg(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var Go=class ac{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 Kl(o,a,1,i):h=new Kl(a,o,-1,i),t.push(h),o=a}}withOffset(t,i){let n=[];for(let r of this.points)n.push(new fi(r.x+t,r.y+i));return new ac(n)}};function Jl(e,t,i,n){let r=[];for(let o=0;o<20;o++){let s=o*2*Math.PI/20;r.push(new fi(e+i*Math.sin(s),t+n*Math.cos(s)))}return new Go(r)}function Xa(e,t,i,n){return new Go([new fi(e,t),new fi(i,t),new fi(i,n),new fi(e,n)])}var _r=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function Ql(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 xg(e,t,i,n){let r,o,s,a;t.high.y<i&&G.warn("Error: inconsistent segment (1)"),t.low.y<=i?(r=Ql(t,i),o=t.winding):(r=t.low.x,o=0),t.high.y>=n?(s=Ql(t,n),a=t.winding):(s=t.high.x,a=0),r<s?(e.push(new _r(r,o,t.shapeId,-1)),e.push(new _r(s,a,t.shapeId,1))):(e.push(new _r(s,a,t.shapeId,-1)),e.push(new _r(r,o,t.shapeId,1)))}function Sg(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 c=e[u];r[c.shapeId]+=c.winding,o[c.shapeId]+=c.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(c.x),h=p)}return a}function Cg(e,t){return t?Math.ceil(e/t)*t:e}function eh(e,t){return t?Math.floor(e/t)*t:e}function kg(e){return new fi(e.y,-e.x)}function bo(e){return new Pt(e.y1,-e.x2,e.y2,-e.x1)}function lc(e){return new Pt(-e.y2,e.x1,-e.y1,e.x2)}function th(e){return new Go(e.points.map(t=>kg(t)))}function Eg(e,t,i,n,r,o){o&&(e=bo(e),t=t.map(b=>th(b)),i=i.map(b=>th(b)));let s=t.length,a=i?i.length:0,h=[],l=[],u,c,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(bg);let g=0;for(;l[g].shapeId>=s;)g++;let m=l[g].low.y;m>e.y1&&h.push(new ii(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 b=e.y2,v=Math.min(Cg(Math.ceil(m+n),r),e.y2);for(c=0;c<x.length&&b>v;c++)p=x[c],p.low.x==p.high.x?p.high.y<b&&(b=Math.max(eh(p.high.y,r),v)):p.low.x!=p.high.x&&(b=v);for(b>e.y2&&(b=e.y2);w<f&&(p=l[w]).low.y<b;){if(p.high.y<m){w++;continue}if(p.low.y<v)p.low.y==p.high.y&&p.low.y==m||(x.push(p),b=v),w++;else{let F=eh(p.low.y,r);F<b&&(b=F);break}}let C=[];for(c=0;c<x.length;c++)xg(C,x[c],m,b);C.sort((F,A)=>F.x-A.x||F.lowOrHigh-A.lowOrHigh);let S=Sg(C,s,a);if(S.length==0)h.push(new ii(m,b,e.x2,e.x2));else{let F=0,A=e.x1;for(c=0;c<S.length;c+=2){let D=Math.max(e.x1,S[c]),H=Math.min(e.x2,S[c+1])-D;H>F&&(F=H,A=D)}F==0?h.push(new ii(m,b,e.x2,e.x2)):h.push(new ii(m,b,Math.max(A,e.x1),Math.min(A+F,e.x2)))}if(b==e.y2)break;for(m=b,c=x.length-1;c>=0;c--)x[c].high.y<=b&&x.splice(c,1)}return hc(e,h),h}function hc(e,t){let i=t.length-1,n=new ii(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 uc(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 Pg(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 Pt(t.x1,i,t.x2,o)}function Ng(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 Pt(t.x1,o,t.x2,i)}function Tg(e,t,i,n){let r=i.y1,o=i.x2-i.x1,s=i.y2-i.y1,a=uc(t,r);for(;;){let h=r+s;if(h>e.y2)return!1;let l=e.x1,u=e.x2;for(let c=a;c<t.length&&t[c].y1<h;c++){let p=t[c];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 Ig(e,t,i,n,r){for(n||(n=[new ii(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 ii(s,e.y2,e.x1,e.x2));let a=uc(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 ii(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 ii(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););}hc(e,t)}var Ag=class extends li{constructor(){super(),d(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Fg(e){if(e){let t=new Ag;try{return e.visit(t),t.propSet}catch(i){G.warn(i,"toSet:")}}return{}}var Rg=class extends li{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function ih(e,t){if(e){let i=new Rg(t);try{return e.visit(i),i.value}catch(n){G.warn(n,"toInt: ")}}return t}var Lg=class extends li{constructor(){super(),d(this,"collect",!1),d(this,"coords",[]),d(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 fi(e+o[a],t+o[a+1]));return new Go(s)}break;case"rectangle":if(o.length==4)return Xa(e+o[0],t+o[1],e+o[0]+o[2],t+o[1]+o[3]);break;case"ellipse":if(o.length==4)return Jl(e+o[0],t+o[1],o[2],o[3]);break;case"circle":if(o.length==3)return Jl(e+o[0],t+o[1],o[2],o[2]);break}}return null}};function cc(e,t,i,n,r,o){if(e){let s=new Lg;try{return e.visit(s),s.getShape(t,i,n,r,o)}catch(a){G.warn(a,"toShape:")}}return Xa(t,i,t+n,i+r)}var Og=class extends li{constructor(e,t){super(),this.reset=e,this.defaultValue=t,d(this,"counters",Object.create(null)),d(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 wn(e,t){var i,n;let r=(i=t?.reset)!=null?i:!1,o=(n=t?.defaultValue)!=null?n:r?0:1,s=new Og(r,o);try{e.visit(s)}catch(a){G.warn(a,"toCounters:")}return s.counters}var Bg=class extends Hi{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new ht(this.transformer.transformURL(e.url,this.baseUrl))}};function ki(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function Mg(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(t,i,n)=>i?String.fromCodePoint(parseInt(i,16)):n)}function hn(e,t){var i,n;if(t==="content"){let r=e.cloneNode(!0);return r.querySelectorAll("[data-adapt-pseudo]").forEach(o=>o.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 o=(n=(i=e.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(e))==null?void 0:n.getPropertyValue("--viv-marker-content");if(o){let s=o.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(s&&s.length>0)return s.map(a=>Mg(a.substring(1,a.length-1))).join("")}return""}else{let r=e.querySelector(`[data-adapt-pseudo="${t}"]`);return r&&r.textContent||""}}var _g=class{constructor(e,t){this.targetId=e,this.resolved=t,d(this,"pageCounters",null),d(this,"spineIndex",-1),d(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}},Dg=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()}},zg=class{constructor(e,t,i,n){this.counterStore=e,this.baseURL=t,this.rootScope=i,this.pageScope=n,d(this,"styler",null),d(this,"namedStringValues",Object.create(null)),d(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(Ne(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 Fe(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 Fe(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"?hn(n,t):hn(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 Fe(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 Fe(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 Fe(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(wo);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 Fe(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new Fe(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(Nu),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(`[${jt}]`)).map(p=>parseInt(p.getAttribute(jt),10))),h=-1,l=-1,u=-1,c=-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,c=-1),l<0)if(f===s)l=f;else{g<h&&(l=g);let w=o.container.querySelector(`[${jt}="${f}"]`);if(!w)l<0&&(l=f);else{let x=o.container.querySelector(`[${jt}="${s}"]`);if(x||(x=o.container.querySelector(`[${jt}="0"]`)),x){for(let b=x;b;b=b.firstElementChild)if(b===w){l=f;break}}}}u=f}else(m>a||m<0)&&(h=l=u=c=f)}return n[{first:h,start:l,last:u,"first-except":c}[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)}},Vg=class{constructor(e){this.documentURLTransformer=e,d(this,"countersById",Object.create(null)),d(this,"pageCountersById",Object.create(null)),d(this,"pageDocCountersById",Object.create(null)),d(this,"pageTextById",Object.create(null)),d(this,"currentPageDocCounters",null),d(this,"previousPageDocCounters",null),d(this,"currentPageDocCounterChanges",Object.create(null)),d(this,"currentPageDocCounterChangeTypes",Object.create(null)),d(this,"currentPageCounters",Object.create(null)),d(this,"previousPageCounters",Object.create(null)),d(this,"currentPageCountersStack",[]),d(this,"pageIndicesById",Object.create(null)),d(this,"currentPage",null),d(this,"newReferencesOfCurrentPage",[]),d(this,"referencesToSolve",[]),d(this,"referencesToSolveStack",[]),d(this,"unresolvedReferences",Object.create(null)),d(this,"resolvedReferences",Object.create(null)),d(this,"pageControlledCounterNames",Object.assign(Object.create(null),{page:!0})),d(this,"pagesCounterExprs",[]),d(this,"pageCounterExprs",[]),d(this,"targetCounterExprs",[]),d(this,"targetTextExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new Dg(this,e)}createCounterResolver(e,t,i){return new zg(this,e,t,i)}setCurrentPage(e){this.currentPage=e}setCurrentPageDocCounters(e,t,i){this.previousPageDocCounters=this.currentPageDocCounters?ki(this.currentPageDocCounters):null,this.currentPageDocCounters=e?ki(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=ki(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,b=g[m]||[],v=b.length?b[b.length-1]:0,C=x-v,S=n[m],F=S==="reset"||S==="set";r[m]={delta:C,reset:F,value:x}}}let o=Object.create(null),s,a=e["counter-reset"];if(a){let g=a.evaluate(t);g&&(s=wn(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=wn(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 c,p=e["counter-increment"];if(p){let g=p.evaluate(t);g&&(c=wn(g))}c&&"pages"in c&&delete c.pages,c?!("page"in c)&&!(r.page&&r.page.reset)&&(c.page=1):(c=Object.create(null),r.page&&r.page.reset||(c.page=1));for(let g in c)u.push(g);this.setPageControlledCounterNames(u);let f=ki(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 c){if(o[g])continue;this.currentPageCounters[g]||this.definePageCounter(g,0);let m=this.currentPageCounters[g];m[m.length-1]+=c[g]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=ki(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 _g(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let o=ki(this.currentPageCounters),s=this.currentPageDocCounters?ki(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:hn(u,"content"),before:hn(u,"before"),after:hn(u,"after"),marker:hn(u,"marker")}}let l=this.pageIndicesById[a];if(l&&l.pageIndex<t){let u=this.resolvedReferences[a];if(u){let c=this.unresolvedReferences[a];c||(c=this.unresolvedReferences[a]=[]);let p;for(;p=u.shift();)p.unresolve(),c.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(`[${Mn}]`);for(let n of i){let r=n.getAttribute(Mn),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(`[${Bn}]`);for(let a of s){let h=a.getAttribute(Bn),l=this.pageCounterExprs.find(f=>f.expr.key===h);if(!l)continue;let u=(i=l.expr)==null?void 0:i.str,c=u?.replace(/^page-counters?-/,""),p=o[c];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 Fe){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(`[${jt}="${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(Mn,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(fs,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?ps:Bn,e.key),o}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${Bn}]`);for(let r of t){let o=r.getAttribute(Bn),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(`[${Mn}]`);for(let r of i)r.setAttribute(nh,!0);let n=e.querySelectorAll(`[${fs}]`);for(let r of n)r.setAttribute(rh,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${ps}]`),n=e.contentContainer.childElementCount;for(let s of i){let a=s.getAttribute(ps),h=this.pagesCounterExprs.findIndex(l=>l.expr.key===a);h>=0,s.textContent=this.pagesCounterExprs[h].format([n])}let r=e.root.querySelectorAll(`[${nh}]`);for(let s of r){let a=s.getAttribute(Mn),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(`[${rh}]`);for(let s of o){let a=s.getAttribute(fs),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 Ug(this,e)}},ps="data-vivliostyle-pages-counter",Bn="data-vivliostyle-page-counter",Mn="data-vivliostyle-target-counter",fs="data-vivliostyle-target-text",nh="data-vivliostyle-target-counter-in-running",rh="data-vivliostyle-target-text-in-running",Ug=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}},Hg=new Set(["before","after","first-line","first-letter"]),$g=new Set(["media","supports","-epubx-when"]),dc=new Set([";","}"]),pc=new Set(["{",";","}"]),Wg=new Set([";","{","}"]),Gg=":where(:scope)",jg=":where(:not(*))";function Xg(e){let{statements:t,changed:i}=Ds(e,0,e.length,null);return i?t.join(`
5
+ `):e}function Ds(e,t,i,n){let r=[],o=[],s=!1,a=t,h=()=>{o.length!==0&&(n?r.push(qg(n,o)):r.push(fc(o)),o.length=0)};for(;a<i&&(a=vc(e,a,i),!(a>=i||e[a]==="}"));){if(e[a]==="@"){h();let c=rm(e,a,i);if(!c)break;if(c.hasBlock&&$g.has(c.name)){let p=Ds(e,c.blockStart,c.blockEnd,n);s||(s=p.changed||n!=null),r.push(`${c.header} {${Yg(p.statements)}}`)}else r.push(Jn(e.slice(a,c.end)));a=c.end;continue}if(n&&em(e,a,i)){let c=im(e,a,i);if(!c)break;o.push(Jn(c.text)),a=c.end;continue}h();let l=nm(e,a,i);if(!l){let c=om(e,a,i);r.push(Jn(c.text)),a=c.end;continue}let u=n?Zg(n,l.prelude):gc(l.prelude);if(u){s||(s=n!=null);let c=Ds(e,l.blockStart,l.blockEnd,u);s||(s=c.changed),c.statements.length===0?r.push(`${u} {}`):r.push(...c.statements)}a=l.end}return h(),{statements:r,changed:s}}function qg(e,t){return`${e} { ${fc(t)} }`}function fc(e){return e.map(t=>t.endsWith(";")?t:`${t};`).join(" ")}function Yg(e){return e.length===0?"":` ${e.join(" ")} `}function Zg(e,t){let i=Kg(e);if(!i)return null;let n=wc(t,",").map(r=>r.trim()).filter(Boolean).map(r=>{let o=mc(r,i);return o.found?o.text:`${i} ${r}`}).filter(Boolean);return n.length===0?null:n.join(", ")}function gc(e){return mc(e.trim(),Gg).text}function Kg(e){let t=wc(e,",").map(i=>i.trim()).filter(Boolean).filter(i=>!Jg(i));return t.length===0?null:`:is(${t.join(", ")})`}function Jg(e){let t=0;for(;t<e.length;){let i=jo(e,t);if(i!=null){t=i;continue}let n=Wi(e,t,e.length);if(n!=null){t=n;continue}if(e[t]===":"){if(e[t+1]===":")return!0;let r=t+1,o=Cr(e,r,e.length),s=e.slice(r,o).toLowerCase();if(Hg.has(s))return!0;t=o;continue}t++}return!1}function mc(e,t){let i=0,n=!1,r="",o=[],s=Qg(t);for(;i<e.length;){let a=jo(e,i);if(a!=null){r+=e.slice(i,a),i=a;continue}let h=Wi(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,c=Cr(e,u,e.length);if(c>u&&e[c]==="("){o.push(e.slice(u,c).toLowerCase()),r+=e.slice(i,c+1),i=c+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")?jg:t,n=!0,i++;continue}r+=l,i++}return{text:r,found:n}}function Qg(e){let t=0;for(;t<e.length;){let i=jo(e,t);if(i!=null){t=i;continue}let n=Wi(e,t,e.length);if(n!=null){t=n;continue}if(e[t]===":"&&e[t+1]!==":"){let r=t+1,o=Cr(e,r,e.length);if(o>r&&e.slice(r,o).toLowerCase()==="has"&&e[o]==="(")return!0;t=o;continue}t++}return!1}function wc(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=Wi(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 em(e,t,i){let n=t,r=tm(e,n,i);if(r<=n)return!1;let o=vc(e,r,i);if(o>=i||e[o]!==":")return!1;if(e[t]==="-"&&e[t+1]==="-")return!0;let s=kr(e,o+1,i,Wg);return!s||s.char!=="{"}function tm(e,t,i){let n=t;return e[n]==="-"&&(n++,n<i&&e[n]==="-"&&n++),Cr(e,n,i)}function Cr(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 im(e,t,i){let n=kr(e,t,i,dc);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 nm(e,t,i){let n=kr(e,t,i,pc);if(!n||n.char!=="{")return null;let r=yc(e,n.index,i);return r<0?null:{prelude:Jn(e.slice(t,n.index)),blockStart:n.index+1,blockEnd:r,end:r+1}}function rm(e,t,i){let n=kr(e,t,i,pc);if(!n)return null;let r=Cr(e,t+1,i),o=e.slice(t+1,r).toLowerCase(),s=Jn(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=yc(e,n.index,i);return a<0?null:{name:o,header:s,hasBlock:!0,blockStart:n.index+1,blockEnd:a,end:a+1}}function om(e,t,i){let n=kr(e,t,i,dc);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 kr(e,t,i,n){let r=t,o=0,s=0,a=0;for(;r<i;){let h=Wi(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 yc(e,t,i){let n=t+1,r=1;for(;n<i;){let o=Wi(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 vc(e,t,i){let n=t;for(;n<i;){let r=e[n];if(xc(r)){n++;continue}if(r==="/"&&e[n+1]==="*"){n=bc(e,n,i);continue}break}return n}function bc(e,t,i){let n=e.indexOf("*/",t+2);return n<0||n+2>i?i:n+2}function Wi(e,t,i){let n=e[t];return n==='"'||n==="'"?sm(e,t):n==="/"&&e[t+1]==="*"?bc(e,t,i):null}function jo(e,t){return e[t]!=="\\"?null:t+1>=e.length?e.length:t+2}function sm(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 xc(e){return e===" "||e===`
6
+ `||e==="\r"||e===" "||e==="\f"}function Jn(e){let t="",i=0,n=!1;for(;i<e.length;){let r=Wi(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(xc(o)){n=t.length>0,i++;continue}n&&t.length>0&&(t+=" ",n=!1),t+=o,i++}return t}function am(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 Ei(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,am)}var lm=class{constructor(){d(this,"type"),d(this,"precededBySpace",!1),d(this,"num",0),d(this,"text",""),d(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 Ye(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 Qt=[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];Qt[NaN]=80;var $t=[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];$t[NaN]=43;var hm=[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];$t[NaN]=43;var Sc=[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];Sc[NaN]=35;var Cc=[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];Cc[NaN]=45;var zs=[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];zs[NaN]=37;var Vs=[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];Vs[NaN]=38;var Pi=Ye(35,[61,36]),um=Ye(35,[58,77]),cm=Ye(35,[61,36,124,50]),dm=Ye(35,[38,51]),pm=Ye(35,[42,54]),fm=Ye(39,[42,55]),gm=Ye(54,[42,55,47,56]),mm=Ye(62,[62,82]),wm=Ye(35,[61,36,33,70]),ym=Ye(62,[45,71]),vm=Ye(63,[45,81]),gs=Ye(76,[10,72,13,72]),bm=Ye(39,[39,46,10,72,13,72,92,48]),xm=Ye(39,[34,46,10,72,13,72,92,49]),Sm=Ye(39,[39,47,10,74,13,74,92,48]),Cm=Ye(39,[34,47,10,74,13,74,92,49]),oh=Ye(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),km=Ye(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]),Em=Ye(39,[39,68,10,74,13,74,92,75,NaN,67]),Pm=Ye(39,[34,68,10,74,13,74,92,75,NaN,67]),Nm=Ye(72,[9,39,10,39,13,39,32,39,41,69]),Tm=15,Vt=class{constructor(e,t){this.input=e,this.handler=t,d(this,"indexMask"),d(this,"buffer"),d(this,"tail",0),d(this,"curr",0),d(this,"position",0),this.indexMask=Tm,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new lm}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=Qt,r=this.input,o=this.position,s=this.buffer,a=0,h=0,l="",u=0,c=!1,p=s[e],f=-9;for(;;){let g=r.charCodeAt(o);switch(n[g]||n[65]){case 72:l=r.substring(h,o),isNaN(g)?a=0:a=54,n=Qt;break;case 1:o++,c=!0;continue;case 2:h=o++,n=zs;continue;case 3:a=1,h=o++,n=$t;continue;case 4:h=o++,a=31,n=Pi;continue;case 33:a=2,h=++o,n=bm;continue;case 34:a=2,h=++o,n=xm;continue;case 6:h=++o,a=7,n=$t;continue;case 7:h=o++,a=32,n=Pi;continue;case 8:h=o++,a=21;break;case 9:h=o++,a=32,n=dm;continue;case 10:h=o++,a=10;break;case 11:h=o++,a=11;break;case 12:h=o++,a=36,n=Pi;continue;case 13:h=o++,a=23;break;case 14:h=o++,a=16;break;case 15:a=24,h=o++,n=Sc;continue;case 16:h=o++,n=hm;continue;case 78:h=o++,a=9,n=$t;continue;case 17:h=o++,a=19,n=pm;continue;case 18:h=o++,a=18,n=um;continue;case 77:o++,a=50;break;case 19:h=o++,a=17;break;case 20:h=o++,a=38,n=wm;continue;case 21:h=o++,a=39,n=Pi;continue;case 22:h=o++,a=37,n=Pi;continue;case 23:h=o++,a=22;break;case 24:h=++o,a=20,n=$t;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=gs;continue;case 30:h=o++,a=33,n=Pi;continue;case 31:h=o++,a=34,n=cm;continue;case 32:h=o++,a=35,n=Pi;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=$t;continue;case 41:a=3,u=parseFloat(r.substring(h,o)),l="%",h=o++;break;case 42:o++,n=Vs;continue;case 43:if(l=Ei(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=gs;continue;case 45:l=Ei(r.substring(h,o));break;case 46:l=r.substring(h,o),o++;break;case 47:l=Ei(r.substring(h,o)),o++;break;case 48:f=o,o+=2,n=Sm;continue;case 49:f=o,o+=2,n=Cm;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=oh;continue}a=6}break;case 53:if(l=Ei(r.substring(h,o)),a==1){if(o++,l.toLowerCase()=="url"){n=oh;continue}a=6}break;case 54:n=fm,o++;continue;case 55:n=gm,o++;continue;case 56:n=Qt,o++;continue;case 57:n=mm,o++,r[o]!==">"&&(a=1,n=$t);continue;case 81:a=51,l=r.substring(h,++o),n=Qt;break;case 82:a=52,l=r.substring(h,++o),n=Qt;break;case 58:a=5,n=zs,o++;continue;case 59:a=4,n=Vs,o++;continue;case 60:a=1,n=$t,o++;continue;case 61:a=1,n=gs,f=o++;continue;case 62:o--;break;case 63:o-=2;break;case 64:h=o++,n=km;continue;case 65:h=++o,n=Em;continue;case 66:h=++o,n=Pm;continue;case 67:a=8,l=Ei(r.substring(h,o)),o++;break;case 69:o++;break;case 70:n=ym,o++;continue;case 71:n=vm,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=Ei(r.substring(h,o)),o++,n=Nm;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=Qt;break;case 73:if(o-f<9&&r.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){o++,n=$t;continue}l=Ei(r.substring(h,o));break;case 75:f=o++;continue;case 76:o++,n=Cc;continue;default:if(n!==Qt){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=o,a=0}if(p.type=a,p.precededBySpace=c,p.num=u,p.text=l,p.position=h,e++,e>=t)break;n=Qt,c=!1,p=s[e&i]}this.position=o,this.tail=e&i}},We=null,Us=null;function Hs(){return We}function _(e){if(!We)throw new Error("E_TASK_NO_CONTEXT");We.name||(We.name=e);let t=We,i=new Xo(t,t.top,e);return t.top=i,i.state=1,i}function Im(e){return new Rm(e||new Fm)}function T(e){return new $s(e)}function Sn(e,t,i){let n=_(e);n.handler=i;try{t(n)}catch(r){n.task.raise(r,n)}return n.result()}function Am(e,t){return(We?We.getScheduler():Us||Im()).run(e,t)}var Fm=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Rm=class{constructor(e){this.timer=e,d(this,"timeout",1),d(this,"slice",25),d(this,"sliceOverTime",0),d(this,"queue"),d(this,"wakeupTime",null),d(this,"timeoutToken",null),d(this,"inTimeSlice",!1),d(this,"order",0),this.queue=new Hf,Us||(Us=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){G.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new Lm(this,t||"");i.top=new Xo(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){G.error(s)}};try{e().then(o=>{i.result=o,r()})}catch(o){i.raise(o),r()}});let n=We;return We=i,this.schedule(i.top.suspend("bootstrap")),We=n,i}},kc=class{constructor(e){this.task=e,d(this,"scheduledTime",0),d(this,"order",0),d(this,"result",null),d(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=We;return We=e,e.top.finish(this.result),We=t,!0}return!1}cancel(){this.canceled=!0}},Lm=class{constructor(e,t){this.scheduler=e,this.name=t,d(this,"callbacks",[]),d(this,"exception",null),d(this,"running",!0),d(this,"result",null),d(this,"waitTarget",null),d(this,"top",null),d(this,"continuation",null)}getName(){return this.name}interrupt(e){if(this.raise(e||new Error("E_TASK_INTERRUPT")),this!==We&&this.continuation){this.continuation.cancel();let t=new kc(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=_("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&&G.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}}},uo=class Mu{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new Mu(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},fg=class{constructor(e){this.frame=e}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new gs(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 uo(e)):new uo(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}},gs=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(!_e)throw new Error("F_TASK_NO_CONTEXT");if(this!==_e.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new fg(this)}finish(e){this.checkEnvironment(),_e&&!_e.exception&&(this.res=e),this.state=2;let t=this.parent;if(_e&&(_e.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=O("Frame.timeSlice");return e.getScheduler().isTimeSliceOver()?($.debug("-- time slice --"),e.suspend().schedule(!0)):e.finish(!0),e.result()}sleep(e){let t=O("Frame.sleep");return t.suspend().schedule(!0,e),t.result()}loop(e){let t=O("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=_e;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new gg(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 Bu(this.task);return this.task.continuation=t,_e=null,this.task.waitTarget=e||null,t}},gg=class extends gs{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},or=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=ho().getScheduler().run(()=>{let e=O("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){$.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}},ms=e=>{if(e.length==0)return N(!0);if(e.length==1)return e[0].get().thenReturn(!0);let t=O("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()},_u=`
9
+ `;e.frameTrace=t}}},$s=class Ec{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new Ec(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},Om=class{constructor(e){this.frame=e}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new Xo(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 $s(e)):new $s(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}},Xo=class{constructor(e,t,i){this.task=e,this.parent=t,this.name=i,d(this,"res",null),d(this,"state"),d(this,"callback",null),d(this,"handler",null),this.state=0}checkEnvironment(){if(!We)throw new Error("F_TASK_NO_CONTEXT");if(this!==We.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new Om(this)}finish(e){this.checkEnvironment(),We&&!We.exception&&(this.res=e),this.state=2;let t=this.parent;if(We&&(We.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=_("Frame.timeSlice");return e.getScheduler().isTimeSliceOver()?(G.debug("-- time slice --"),e.suspend().schedule(!0)):e.finish(!0),e.result()}sleep(e){let t=_("Frame.sleep");return t.suspend().schedule(!0,e),t.result()}loop(e){let t=_("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=We;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new Bm(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 kc(this.task);return this.task.continuation=t,We=null,this.task.waitTarget=e||null,t}},Bm=class extends Xo{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},Er=class{constructor(e,t){this.fetch=e,d(this,"name"),d(this,"arrived",!1),d(this,"resource",null),d(this,"task",null),d(this,"piggybacks",[]),this.name=t}start(){this.task||(this.task=Hs().getScheduler().run(()=>{let e=_("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){G.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}},Cn=e=>{if(e.length==0)return T(!0);if(e.length==1)return e[0].get().thenReturn(!0);let t=_("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()},Pc=`
8
10
  @media screen {
9
11
  [data-vivliostyle-viewer-viewport] {
10
12
  background: #aaaaaa;
@@ -73,7 +75,7 @@ var gp=Object.create;var tl=Object.defineProperty;var mp=Object.getOwnPropertyDe
73
75
  transform-origin: center top;
74
76
  }
75
77
  }
76
- `,zu=`
78
+ `,Nc=`
77
79
  [data-vivliostyle-layout-box] {
78
80
  position: absolute;
79
81
  left: 0;
@@ -86,7 +88,10 @@ var gp=Object.create;var tl=Object.defineProperty;var mp=Object.getOwnPropertyDe
86
88
  }
87
89
 
88
90
  [data-vivliostyle-debug] [data-vivliostyle-layout-box] {
91
+ right: auto;
92
+ bottom: auto;
89
93
  z-index: auto;
94
+ overflow: visible;
90
95
  }
91
96
 
92
97
  [data-vivliostyle-layout-box] [data-vivliostyle-page-container] {
@@ -192,22 +197,8 @@ var gp=Object.create;var tl=Object.defineProperty;var mp=Object.getOwnPropertyDe
192
197
  [data-vivliostyle-spread-container] [data-vivliostyle-page-container]:not(:last-child) {
193
198
  break-after: page;
194
199
  }
195
-
196
- /* Gecko-only hack, see https://bugzilla.mozilla.org/show_bug.cgi?id=267029#c17 */
197
- @-moz-document url-prefix() {
198
- [data-vivliostyle-spread-container] [data-vivliostyle-page-container]:nth-last-child(n + 2) {
199
- top: -1px;
200
- margin-top: 1px;
201
- margin-bottom: -1px;
202
- }
203
- /* Workaround Gecko problem on page break */
204
- [data-vivliostyle-spread-container] [data-vivliostyle-page-container] {
205
- break-after: auto !important;
206
- height: 100% !important;
207
- }
208
- }
209
200
  }
210
- `,Du=`
201
+ `,Tc=`
211
202
  /*
212
203
  * Copyright 2013 Google, Inc.
213
204
  * Copyright 2015 Daishinsha Inc.
@@ -643,6 +634,7 @@ background-blend-mode = COMMA( BLEND_MODE+ );
643
634
 
644
635
  /* CSS GCPM */
645
636
  string-set = COMMA( SPACE( IDENT CONTENT_LIST )+ | none );
637
+ footnote-display = block | inline | compact;
646
638
  footnote-policy = auto | line;
647
639
 
648
640
  /* CSS Repeated Headers and Footers */
@@ -839,7 +831,7 @@ word-wrap = overflow-wrap;
839
831
  [adapt,webkit]start = inline-start;
840
832
  [adapt,webkit]end = inline-end;
841
833
 
842
- `,Vu=`
834
+ `,Ic=`
843
835
  <!DOCTYPE html>
844
836
  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://www.pyroxy.com/ns/shadow">
845
837
  <head>
@@ -847,6 +839,7 @@ word-wrap = overflow-wrap;
847
839
 
848
840
  .-vivliostyle-footnote-content {
849
841
  float: footnote;
842
+ --viv-semantic-footnote-content: 1;
850
843
  }
851
844
 
852
845
  .-vivliostyle-table-cell-container {
@@ -862,7 +855,7 @@ word-wrap = overflow-wrap;
862
855
  <s:template id="table-cell"><div data-vivliostyle-flow-root="true" class="-vivliostyle-table-cell-container"><s:content/></div></s:template>
863
856
 
864
857
  </body>
865
- </html>`,Hu=`
858
+ </html>`,Ac=`
866
859
  @namespace "http://www.w3.org/1999/xhtml";
867
860
 
868
861
  :root {
@@ -875,14 +868,10 @@ word-wrap = overflow-wrap;
875
868
  break-before: right;
876
869
  }
877
870
 
878
- @-adapt-footnote-area {
879
- display: block;
871
+ @footnote {
880
872
  margin-block-start: 0.5em;
881
- margin-block-end: 0.5em;
882
873
  }
883
-
884
- @-adapt-footnote-area ::before {
885
- display: block;
874
+ @footnote ::before {
886
875
  border-block-start-width: 1px;
887
876
  border-block-start-style: solid;
888
877
  border-block-start-color: black;
@@ -989,7 +978,7 @@ word-wrap = overflow-wrap;
989
978
  margin: 10%;
990
979
  }
991
980
  }
992
- `,Uu=`
981
+ `,Fc=String.raw`
993
982
  @namespace "http://www.w3.org/1999/xhtml";
994
983
  @namespace m "http://www.w3.org/1998/Math/MathML";
995
984
  @namespace epub "http://www.idpf.org/2007/ops";
@@ -1186,6 +1175,10 @@ sub {
1186
1175
  sup {
1187
1176
  vertical-align: super;
1188
1177
  }
1178
+ sub,
1179
+ sup {
1180
+ line-height: 1;
1181
+ }
1189
1182
  table {
1190
1183
  box-sizing: border-box;
1191
1184
  border-spacing: 2px;
@@ -1331,34 +1324,64 @@ m|math[display="block"] {
1331
1324
  display: block math;
1332
1325
  }
1333
1326
 
1334
- /*------------------ epub-specific ---------------------*/
1327
+ /* CSS GCPM footnotes */
1328
+ ::footnote-marker {
1329
+ list-style-position: inside;
1330
+ }
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 {
1336
+ content: counter(footnote);
1337
+ font-size: 0.75em;
1338
+ vertical-align: super;
1339
+ line-height: 0;
1340
+ }
1341
+
1342
+ /* EPUB/DPUB footnotes */
1335
1343
 
1336
- a[epub|type="noteref"],
1337
- a[epub\\:type="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)) {
1338
1347
  font-size: 0.75em;
1339
1348
  vertical-align: super;
1340
- line-height: 0.01;
1349
+ line-height: 0;
1350
+ }
1351
+
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;
1341
1356
  }
1342
1357
 
1343
1358
  a[epub|type="noteref"]:href-epub-type(footnote, aside),
1344
- a[epub\\:type="noteref"]:href-epub-type(footnote, aside) {
1359
+ a[epub\:type="noteref"]:href-epub-type(footnote, aside),
1360
+ a[role="doc-noteref"]:href-role-type(doc-footnote, aside) {
1345
1361
  -adapt-template: footnote;
1346
1362
  text-decoration: none;
1347
1363
  }
1348
1364
 
1349
- aside[epub|type="footnote"],
1350
- aside[epub\\:type="footnote"] {
1365
+ aside[epub|type="footnote"][data-vivliostyle-footnote-referenced],
1366
+ aside[epub\:type="footnote"][data-vivliostyle-footnote-referenced],
1367
+ aside[role="doc-footnote"][data-vivliostyle-footnote-referenced] {
1351
1368
  display: none;
1352
1369
  }
1353
1370
 
1354
1371
  aside[epub|type="footnote"]:footnote-content,
1355
- aside[epub\\:type="footnote"]:footnote-content {
1372
+ aside[epub\:type="footnote"]:footnote-content,
1373
+ aside[role="doc-footnote"]:footnote-content {
1356
1374
  display: block;
1357
- margin: 0.25em;
1358
- font-size: 1.2em;
1359
- line-height: 1.2;
1375
+ font-size: 0.9em;
1360
1376
  }
1361
1377
 
1378
+ aside[epub|type="footnote"]:footnote-content a[epub|type="backlink"],
1379
+ aside[epub\:type="footnote"]:footnote-content a[epub\:type="backlink"],
1380
+ aside[role="doc-footnote"]:footnote-content a[role="doc-backlink"] {
1381
+ text-decoration: none;
1382
+ }
1383
+
1384
+ /* EPUB-specific */
1362
1385
  epub|trigger {
1363
1386
  display: none;
1364
1387
  }
@@ -1386,7 +1409,7 @@ epub|case[required-namespace::supported] ~ epub|case {
1386
1409
  epub|case[required-namespace::supported] ~ epub|default {
1387
1410
  display: none;
1388
1411
  }
1389
- `,$u=`
1412
+ `,Rc=`
1390
1413
  @namespace "http://www.w3.org/1999/xhtml";
1391
1414
 
1392
1415
  *:not([data-vivliostyle-role=doc-toc],
@@ -1416,7 +1439,7 @@ epub|case[required-namespace::supported] ~ epub|default {
1416
1439
  [data-vivliostyle-role=doc-toc]:is(ol,ul) {
1417
1440
  -adapt-behavior: toc-container;
1418
1441
  }
1419
- `,Wu=`
1442
+ `,Lc=`
1420
1443
  [data-viv-margin-discard~="block-start"] {
1421
1444
  margin-block-start: 0 !important;
1422
1445
  }
@@ -1537,29 +1560,56 @@ span[data-viv-leader] {
1537
1560
  }
1538
1561
 
1539
1562
  /* ::marker */
1540
- /* Mozilla Bullet font (https://github.com/mozilla/gecko-dev/blob/master/layout/style/res/Mozilla_Bullet.woff2) */
1541
- @font-face {
1542
- font-family: "-viv-moz-bullet";
1543
- src: url("data:font/woff2;base64,d09GMgABAAAAAAScAAsAAAAACfAAAARNAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAABmAAhBIRCAqGMIRJATYCJAMsCxgABCAFhF4HaBsuCMgehXEsLOlXaXd7sgbPQ172fjLwdhYFM92mABaiTuRVdO5/mx9I5UJiJom3phLRQw/TSF2M/vo25+pNyWkNws81NrUDAAf0QOdfcf7nmPEyBPZtCbbZEDuosskKZG922ZhBenh05qcSXktf6s3Oy9dAkWsyDzMoM5QTKcwKNjFayUPSREGFhUMrdE8MJsH052qGcYNO3pbEaYIBoDTItIKGAqhDdKHRD0kkKg6QGSCWEfueTNr3P6OvYaIbDH/8ULEAbjQtUt+hT/qmX/SH/twwMLDqN4jxzXjy4PHtltSA6lINqkpRd7N7onVBP20y7YBWyDIHFEBjqKBFMmECfQcTZtD3MmEB/SATVtCPM2ED/TQTdtCfS0/pEsN4ySin3r8q8xHE+0D0XMg8gJi4YrNpNv3qetXuDyeo6OBNZrq5gi7ouC1zcmB2Fd+FewIhcUIfszpF1hzXhrmMCwxaznRyZjig6Y2W7+bBn2DL8fJu/2oHbWc6X80+LUTXcVzv8O3IOy4qKVyFw/DHaMtfzNQEi5gbFT/EDpiofbpkYq2dQui6WcpfxrVBEJ/KxbLA4ZroZoVx+iE+QeTIiI7oKuoUIk/a1ekEOoNFjozm0suYYUelq13/88K1c3PTH9O9Q0d5LZbu7+J2aT7XP23KyQs+34WTU7r8d/k0l6dLl98Dn+/BSUZc7U0mm7FqhSMO9EHV/j5FB4qYX4aXNaKwz/4RRfAWsW8xGW+hvr8PTAf6IP9mRpkDwwv7QFz9HRuOeGWfd8rkyYsWTVy4vpG/pgVNWzBx0aTeIgeq58XFVfZXVduwuOq51a77aT0XLVw4v1PBFjRsQzO+tVeVp3KIwqfKbd6sdjzGvFSuPMquGpMT29lkrhwbE5uz6cGHhIETB06oUk+6tHLJgfnu/3nVnJzYxiXNjQNjYqsu+vCgYKDla5uUOzTNDZg46eCBd3d3gSk9Kz/bFiv8hvOzCT5eqyjBGerT+EiG/JGqwbC+UQ6Bv9bmKGWMj8Yn+fPVRJxKBGqTFXQyM9DhHSlvEHmLVxyYjY/Fdd3hACfLyP3VVZLvVR7B0pxSsGIBqHhwT5sSMOMkRG0BJhpsWMkEO24KwE0pqp3tIYTWCIjJjuBiGNTKTj8JoBLKAn4TmPFnj9oywZwFGx4egp1g3oObeLHdwUO2pFcYTITZCa2c1GQbNg6RCsu9bpikThhAWnLaBi3LM8+5VbMU6rUn30owOC83ULcfBlClb5BBre46BinaWRal85SUvlCbUx1Nbyj2HWCxBTkEgWScQKzsTioJW0IanAYRZqET4mZLSKU2JABII9np01lQ7lOt3srtM1KAeqgQPhYJSMCZJRuAukRZB1CF35gB1MJBr4ilIPZchNyIlDkpRt+3s96cz9K8XKQvCdZfcqWxgtLoXZ2AoKAyVSRRxSRmsYjVOriP089q3z6gdMjE5KI7kzumWzpnAwAAAA==") format("woff2");
1563
+ [style*="--viv-marker-content"]::marker {
1564
+ content: var(--viv-marker-content);
1565
+ unicode-bidi: isolate;
1566
+ font-variant-numeric: tabular-nums;
1567
+ white-space: pre;
1568
+ text-transform: none;
1544
1569
  }
1545
- [data-adapt-pseudo="marker"] {
1570
+ /* ::footnote-marker inherits --viv-marker-content from the footnote element */
1571
+ .-vivliostyle-footnote-content::marker {
1572
+ content: var(--viv-marker-content);
1546
1573
  unicode-bidi: isolate;
1547
1574
  font-variant-numeric: tabular-nums;
1548
1575
  white-space: pre;
1549
1576
  text-transform: none;
1550
1577
  }
1551
- [data-adapt-pseudo="marker"]._viv-marker-bullet {
1552
- font-family: "-viv-moz-bullet";
1553
- font-style: normal;
1554
- font-weight: normal;
1578
+ [style*="--viv-footnote-white-space"] {
1579
+ white-space: var(--viv-footnote-white-space);
1555
1580
  }
1556
- [data-adapt-pseudo="marker"]._viv-marker-outside {
1557
- position: absolute;
1558
- text-indent: 0;
1581
+ [style*="--viv-marker-color"]::marker {
1582
+ color: var(--viv-marker-color);
1559
1583
  }
1560
- [data-adapt-pseudo="marker"] > ._viv-marker-outside-content {
1561
- position: absolute;
1562
- inset-inline-end: 0;
1584
+ [style*="--viv-marker-font-size"]::marker {
1585
+ font-size: var(--viv-marker-font-size);
1586
+ }
1587
+ [style*="--viv-marker-font-family"]::marker {
1588
+ font-family: var(--viv-marker-font-family);
1589
+ }
1590
+ [style*="--viv-marker-font-style"]::marker {
1591
+ font-style: var(--viv-marker-font-style);
1592
+ }
1593
+ [style*="--viv-marker-font-weight"]::marker {
1594
+ font-weight: var(--viv-marker-font-weight);
1595
+ }
1596
+ [style*="--viv-marker-font-variant"]::marker {
1597
+ font-variant: var(--viv-marker-font-variant);
1598
+ }
1599
+ [style*="--viv-marker-unicode-bidi"]::marker {
1600
+ unicode-bidi: var(--viv-marker-unicode-bidi);
1601
+ }
1602
+ [style*="--viv-marker-direction"]::marker {
1603
+ direction: var(--viv-marker-direction);
1604
+ }
1605
+ [style*="--viv-marker-white-space"]::marker {
1606
+ white-space: var(--viv-marker-white-space);
1607
+ }
1608
+ [style*="--viv-marker-text-transform"]::marker {
1609
+ text-transform: var(--viv-marker-text-transform);
1610
+ }
1611
+ [style*="--viv-marker-text-combine-upright"]::marker {
1612
+ text-combine-upright: var(--viv-marker-text-combine-upright);
1563
1613
  }
1564
1614
 
1565
1615
  /* initial-letter */
@@ -1567,7 +1617,7 @@ span[data-viv-leader] {
1567
1617
  -webkit-initial-letter: var(--viv-initialLetter);
1568
1618
  initial-letter: var(--viv-initialLetter);
1569
1619
  }
1570
- `,Gu=String.raw`
1620
+ `,Oc=String.raw`
1571
1621
  @counter-style decimal-leading-zero {
1572
1622
  system: extends decimal;
1573
1623
  pad: 2 '0';
@@ -1791,12 +1841,12 @@ span[data-viv-leader] {
1791
1841
  @counter-style upper-russian {
1792
1842
  system: alphabetic;
1793
1843
  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;
1794
- }`;function ws(e,t,i){let n=O("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 l;return o.status=a.status,o.url=a.url,o.statusText=a.statusText,o.contentType=(l=a.headers.get("Content-Type"))==null?void 0:l.replace(/;.*$/,"").toLowerCase(),a.ok?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(h=>new TextDecoder("Shift_JIS").decode(h))):(/^data:,(<|%3c)/i.test(e)&&(o.contentType="text/html"),a.text()):a.text()}).then(a=>{t==="blob"&&a instanceof Blob?o.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?o.responseBlob=ju([a]):t==="json"?o.responseText=JSON.stringify(a):typeof a=="string"&&(o.responseText=a),s.schedule(o)}).catch(a=>{$.warn(a,`Error fetching ${e}`),s.schedule(o)}),n.result()}function ju(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function mg(e){let t=O("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function wg(e){return URL.createObjectURL(e)}var wa=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=O("fetch"),r=e.endsWith("?viv-toc-box");r&&(e=e.replace("?viv-toc-box",""));let s=Pe("user-agent.xml",ni),o=!r&&e===s;return o&&(e=`data:application/xml,${encodeURIComponent(Vu)}`),ws(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(l=>{delete this.fetchers[e],this.resources[e]=l,n.finish(l)})}),n.result()}fetch(e,t,i){if(e=Wt(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new or(()=>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 yg(e,t){let i=e.responseText;return N(i?la(i):null)}function bg(){return new wa(yg,"text")}function Hi(e,t,i){let n=new or(()=>{let r=O("loadElement"),s=r.suspend(e),o=!1,a=null,l=h=>{o||(o=!0,a!==null&&(clearTimeout(a),a=null),s.schedule(h?h.type:"timeout"))};if(e.addEventListener("load",l,!1),e.addEventListener("error",l,!1),e.addEventListener("abort",l,!1),e.namespaceURI=="http://www.w3.org/2000/svg")t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(l,300);else if(e.localName==="script")a=setTimeout(l,3e3);else if(t)if(e.localName==="img"){let h=e;h.loading==="lazy"&&(h.loading="eager"),h.src=t,i&&(h.alt=i),h.complete?setTimeout(()=>l(new Event("load")),0):a=setTimeout(l,3e4)}else e.src=t,i&&(e.alt=i);return r.result()},`loadElement ${t||e.localName}`);return n.start(),n}var Rl=0,vg=16777216,Xu=33554432,qu=50331648,Yu=67108864,xg=83886080,Sg=100663296,ya=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 Rl;case"User":return Sg;default:return xg}}getBaseSpecificity(){switch(this.flavor){case"UA":return Rl;case"User":return vg;default:return Xu}}},Cg=class extends ya{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;$.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)}},Fl=class extends ya{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()}},ar=class extends Fl{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new Fl(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())}},Ae=[],Kr=[],me=[],Ne=[],St=[],at=[],Ie=[],Ue=[],ge=[],je=[],tt=[],He=[],Te=[],Ui=55,$i=56,yr=57;Ae[1]=28,Ae[36]=29,Ae[7]=29,Ae[9]=29,Ae[14]=29,Ae[18]=29,Ae[50]=29,Ae[20]=30,Ae[13]=27,Ae[0]=200,Kr[1]=46,Kr[0]=200,at[1]=2,at[36]=4,at[7]=6,at[9]=8,at[14]=10,at[18]=14,at[50]=42,me[37]=11,me[23]=12,me[35]=56,me[1]=1,me[36]=3,me[7]=5,me[9]=7,me[14]=9,me[12]=13,me[18]=55,me[50]=58,me[16]=41,Ne[37]=11,Ne[23]=12,Ne[35]=56,Ne[1]=1,Ne[36]=3,Ne[7]=5,Ne[9]=7,Ne[14]=9,Ne[18]=55,St[1]=2,St[36]=4,St[7]=6,St[9]=8,St[18]=14,St[50]=42,St[14]=10,St[12]=13,Ie[1]=15,Ie[7]=16,Ie[4]=17,Ie[5]=18,Ie[3]=19,Ie[2]=20,Ie[8]=21,Ie[27]=57,Ie[16]=22,Ie[19]=23,Ie[6]=24,Ie[11]=25,Ie[17]=26,Ie[13]=48,Ie[31]=47,Ie[23]=54,Ie[0]=44,Ue[1]=31,Ue[4]=32,Ue[5]=32,Ue[3]=33,Ue[2]=34,Ue[10]=40,Ue[6]=38,Ue[31]=36,Ue[24]=36,Ue[32]=35,ge[1]=45,ge[16]=37,ge[37]=37,ge[38]=37,ge[47]=37,ge[48]=37,ge[39]=37,ge[49]=37,ge[41]=37,ge[26]=37,ge[25]=37,ge[23]=37,ge[24]=37,ge[19]=37,ge[21]=37,ge[36]=37,ge[18]=37,ge[22]=37,ge[11]=39,ge[12]=43,ge[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,tt[0]=200,tt[12]=50,tt[13]=52,tt[14]=50,tt[15]=51,tt[10]=50,tt[11]=51,tt[17]=53,He[0]=200,He[12]=50,He[13]=51,He[14]=50,He[15]=51,He[10]=50,He[11]=51,Te[11]=0,Te[16]=0,Te[22]=1,Te[18]=1,Te[26]=2,Te[25]=2,Te[38]=3,Te[37]=3,Te[48]=3,Te[47]=3,Te[39]=3,Te[49]=3,Te[41]=3,Te[23]=4,Te[24]=4,Te[36]=5,Te[19]=5,Te[21]=5,Te[0]=6,Te[Ui]=2,Te[$i]=2;var lr=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(X)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,r=0,s;do if(s=i[--n],e===")"&&s instanceof _i){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 J(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=tt);let l=new Ri(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,o+2,l),l.name==="var"){let h=l.values[0]instanceof le&&l.values[0].name;(!zt(h)||h===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${l.toString()}`,t),this.actions=tt)}return l}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=tt,null;if(o>1)return new Ze(this.extractVals(",",n+1));let a=i[0];return a instanceof Je?a:a?new _i(a.toString()):X}exprError(e,t){this.actions=this.propName?tt:je,$.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 l=a.shift(),h=a.shift(),u=new of(n.getScope(),l,h);a.unshift(u)}return i.push(new U(a[0])),!0}else if(o=="("){let l=i.pop(),h=i.pop();r=new On(n.getScope(),eo(h,l),a),e=0;continue}}if(o==10){r.isMediaName()&&(r=new wl(n.getScope(),r,null)),e=0;continue}}else if(typeof o=="string"){i.push(o);break}if(o<0)if(o==-31)r=new si(n.getScope(),r);else if(o==-24)r=new ji(n.getScope(),r);else if(o==-yr)r=new rf(n.getScope(),r);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(Te[e]>Te[o]){i.push(o);break}switch(s=i.pop(),o){case 26:r=new ca(n.getScope(),s,r);break;case Ui:r=new sf(n.getScope(),s,r);break;case $i:r=new af(n.getScope(),s,r);break;case 25:r=new da(n.getScope(),s,r);break;case 38:r=new lf(n.getScope(),s,r);break;case 37:r=new uf(n.getScope(),s,r);break;case 48:r=new hf(n.getScope(),s,r);break;case 47:r=new no(n.getScope(),s,r);break;case 39:case 49:r=new pa(n.getScope(),s,r);break;case 41:r=new cf(n.getScope(),s,r);break;case 23:r=new au(n.getScope(),s,r);break;case 24:r=new lu(n.getScope(),s,r);break;case 36:r=new fa(n.getScope(),s,r);break;case 19:r=new hu(n.getScope(),s,r);break;case 21:r=new uu(n.getScope(),s,r);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),r=new ff(n.getScope(),i.pop(),s,r);break;case 10:if(s.isMediaName())r=new wl(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 l=o.position,h=t&&r==="selector"&&a>0?"":i.input.substring(n,l).trim();return new gf(this.handler.getScope(),r,h,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=Et(i,t,new si(i,new De(i,"pref-horizontal")));break;case"horizontal":t=Et(i,t,new De(i,"pref-horizontal"));break;case"day":t=Et(i,t,new si(i,new De(i,"pref-night-mode")));break;case"night":t=Et(i,t,new De(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new U(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":return!0}return!1}runParser(e,t,i,n,r,s){let o=this.handler,a=this.tokenizer,l=this.valStack,h,u,d,p,f,m,g,w=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(h=a.token(),r&&w===null&&(w=h.position-1,a.input[w]==="("&&w++),this.actions===Ie&&this.errorBrackets.length>0&&(h.type===this.errorBrackets[this.errorBrackets.length-1]||h.type===17||h.type===31)){if(h.type===this.errorBrackets[this.errorBrackets.length-1]&&(this.errorBrackets.pop(),h.type===11&&this.valStackReduce(")",h))){a.consume();continue}l.push(new _i(h.toString())),a.consume();continue}switch(this.actions[h.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(o.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=tt):(this.actions=at,o.startSelectorRule());continue}this.propName=h.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Ie,l.splice(0,l.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=tt,o.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=h.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Ie,l.splice(0,l.length);continue;case 29:this.actions=at,o.startSelectorRule();continue;case 1:if(!h.precededBySpace){this.actions=He,o.error("E_CSS_SPACE_EXPECTED",h);continue}o.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),d=this.namespacePrefixToURI[h.text],d!=null)switch(h=a.token(),h.type){case 1:o.tagSelector(d,h.text),r?this.actions=Ne:this.actions=me,a.consume();break;case 36:o.tagSelector(d,null),r?this.actions=Ne:this.actions=me,a.consume();break;default:this.actions=je,o.error("E_CSS_NAMESPACE",h)}else this.actions=je,o.error("E_CSS_UNDECLARED_PREFIX",h);else o.tagSelector(this.defaultNamespaceURI,h.text),r?this.actions=Ne:this.actions=me,a.consume();continue;case 3:if(!h.precededBySpace){this.actions=He,o.error("E_CSS_SPACE_EXPECTED",h);continue}o.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),h=a.token(),h.type){case 1:o.tagSelector(null,h.text),r?this.actions=Ne:this.actions=me,a.consume();break;case 36:o.tagSelector(null,null),r?this.actions=Ne:this.actions=me,a.consume();break;default:this.actions=je,o.error("E_CSS_NAMESPACE",h)}else o.tagSelector(this.defaultNamespaceURI,null),r?this.actions=Ne:this.actions=me,a.consume();continue;case 5:h.precededBySpace&&o.descendantSelector();case 6:if(!h.text){o.error("E_CSS_SYNTAX",h),a.consume();continue}o.idSelector(h.text),r?this.actions=Ne:this.actions=me,a.consume();continue;case 7:h.precededBySpace&&o.descendantSelector();case 8:o.classSelector(h.text),r?this.actions=Ne:this.actions=me,a.consume();continue;case 55:h.precededBySpace&&o.descendantSelector();case 14:a.consume(),h=a.token();e:switch(h.type){case 1:o.pseudoclassSelector(h.text,null),a.consume(),r?this.actions=Ne:this.actions=me;continue;case 6:switch(p=h.text,a.consume(),p){case"is":case"not":case"where":case"has":this.actions=at,o.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=me:this.actions=He;continue;case"lang":case"href-epub-type":if(h=a.token(),h.type===1){g=[h.text],a.consume(),p==="href-epub-type"&&a.token().type===16&&(a.consume(),h=a.token(),h.type===1&&(g.push(h.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(g=this.readNthPseudoParams(),g)if(p==="nth-child"||p==="nth-last-child"){if(u=a.nthToken(0),u.type===1&&u.text==="of"){a.consume(),this.actions=at,o.startFuncWithSelector(p,g),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?r?this.actions=Ne:this.actions=me:this.actions=He;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)g.push(u.text),a.consume();else break e;break}else break;else break e;default:g=this.readPseudoParams()}if(h=a.token(),h.type==11){o.pseudoclassSelector(p,g),a.consume(),r?this.actions=Ne:this.actions=me;continue}break}o.error("E_CSS_PSEUDOCLASS_SYNTAX",h),this.actions=je;continue;case 58:h.precededBySpace&&o.descendantSelector();case 42:switch(a.consume(),h=a.token(),h.type){case 1:o.pseudoelementSelector(h.text,null),r?this.actions=Ne:this.actions=me,a.consume();continue;case 6:if(p=h.text,a.consume(),p=="nth-fragment"){if(g=this.readNthPseudoParams(),g===null)break}else g=this.readPseudoParams();if(h=a.token(),h.type==11){o.pseudoelementSelector(p,g),r?this.actions=Ne:this.actions=me,a.consume();continue}break}o.error("E_CSS_PSEUDOELEM_SYNTAX",h),this.actions=je;continue;case 9:h.precededBySpace&&o.descendantSelector();case 10:if(a.consume(),h=a.token(),h.type==1)p=h.text,a.consume();else if(h.type==36)p=null,a.consume();else if(h.type==34)p="";else{this.actions=He,o.error("E_CSS_ATTR",h),a.consume();continue}if(h=a.token(),h.type==34){if(d=p&&this.namespacePrefixToURI[p],d===void 0){this.actions=He,o.error("E_CSS_UNDECLARED_PREFIX",h),a.consume();continue}if(a.consume(),h=a.token(),h.type!=1){this.actions=He,o.error("E_CSS_ATTR_NAME_EXPECTED",h);continue}p=h.text,a.consume(),h=a.token()}else d="";switch(h.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=h.type,a.consume(),h=a.token();break;case 15:o.attributeSelector(d,p,0,null),r?this.actions=Ne:this.actions=me,a.consume();continue;default:this.actions=He,o.error("E_CSS_ATTR_OP_EXPECTED",h);continue}switch(h.type){case 1:case 2:o.attributeSelector(d,p,f,h.text),a.consume(),h=a.token();break;default:this.actions=He,o.error("E_CSS_ATTR_VAL_EXPECTED",h);continue}if(h.type!=15){this.actions=He,o.error("E_CSS_ATTR",h);continue}r?this.actions=Ne:this.actions=me,a.consume();continue;case 11:o.childSelector(),this.actions=St,a.consume();continue;case 12:o.adjacentSiblingSelector(),this.actions=St,a.consume();continue;case 56:o.followingSiblingSelector(),this.actions=St,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=Ae,a.consume();continue;case 41:o.nextSelector(),this.actions=at,a.consume();continue;case 15:l.push(F(h.text)),a.consume();continue;case 16:f=parseInt(h.text,16),l.push(new bu(h.text)),a.consume();continue;case 17:l.push(new gt(h.num)),a.consume();continue;case 18:l.push(new Le(h.num)),a.consume();continue;case 19:l.push(new I(h.num,h.text)),a.consume();continue;case 20:l.push(new j(h.text)),a.consume();continue;case 21:l.push(new Qe(Pe(h.text,this.baseURL))),a.consume();continue;case 57:l.push(new vu(h.text)),a.consume();continue;case 22:this.valStackReduce(",",h),l.push(","),a.consume();continue;case 23:l.push(fn),a.consume();continue;case 24:p=h.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=Ue,this.exprContext=0,l.push("{")):(l.push(p),l.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),a.consume();continue;case 25:this.valStackReduce(")",h),a.consume();continue;case 47:if(a.consume(),h=a.token(),u=a.nthToken(1),h.type==1&&h.text.toLowerCase()=="important"&&(u.type==17||u.type==0||u.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",h);continue;case 54:switch(u=a.nthToken(1),u.type){case 4:case 3:case 5:if(!u.precededBySpace){a.consume();continue}}l.push(new _i("+")),a.consume();continue;case 26:a.consume();case 48:m=this.valStackReduce(";",h),m&&this.propName&&o.property(this.propName,m,this.propImportant),this.actions=i?Kr:Ae;continue;case 44:for(a.consume();l.length>0;){let v=l.length;if(m=this.valStackReduce(";",h),!m||l.length===v)break}return t?(this.result=m,!0):(this.propName&&m&&o.property(this.propName,m,this.propImportant),!0);case 31:if(u=a.nthToken(1),u.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(l.push(h.text,u.text,"("),a.consume()):(l.push(new De(o.getScope(),eo(h.text,u.text))),this.actions=ge),a.consume();else{if(this.exprContext==2||this.exprContext==3)h.text.toLowerCase()=="not"?(a.consume(),l.push(new ml(o.getScope(),!0,u.text))):(h.text.toLowerCase()=="only"&&(a.consume(),h=u),l.push(new ml(o.getScope(),!1,h.text)));else if(this.exprContext===4&&h.text.toLowerCase()==="not"&&l[l.length-1]!==Ui&&l[l.length-1]!==$i&&(u.type===10||u.type===6)){l.push(-yr),a.consume();continue}else l.push(new De(o.getScope(),h.text));this.actions=ge}a.consume();continue;case 38:if(this.exprContext===4){l.push(this.readSupportsTest(h)),this.actions=ge;continue}l.push(null,h.text,"("),a.consume();continue;case 32:l.push(new We(o.getScope(),h.num)),a.consume(),this.actions=ge;continue;case 33:p=h.text,p=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?p="vh":p="vw"),l.push(new nr(o.getScope(),h.num,p)),a.consume(),this.actions=ge;continue;case 34:l.push(new We(o.getScope(),h.text)),a.consume(),this.actions=ge;continue;case 35:a.consume(),h=a.token(),h.type!=5||h.precededBySpace?this.exprError("E_CSS_SYNTAX",h):(l.push(new fu(o.getScope(),h.num)),a.consume(),this.actions=ge);continue;case 36:l.push(-h.type),a.consume();continue;case 37:this.actions=Ue,this.exprStackReduce(h.type,h),l.push(h.type),a.consume();continue;case 45:h.text.toLowerCase()==="and"&&l[l.length-2]!==$i&&l[l.length-2]!==-yr?(this.actions=Ue,this.exprStackReduce(Ui,h),l.push(Ui),a.consume()):h.text.toLowerCase()==="or"&&l[l.length-2]!==Ui&&l[l.length-2]!==-yr?(this.actions=Ue,this.exprStackReduce($i,h),l.push($i),a.consume()):this.exprError("E_CSS_SYNTAX",h);continue;case 39:this.exprStackReduce(h.type,h)&&(this.actions=Ie),a.consume();continue;case 43:this.exprStackReduce(11,h)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",h):(this.exprContext==1?o.startWhenRule(l.pop()):o.startMediaRule(l.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Ae)),a.consume();continue;case 49:if(this.exprStackReduce(11,h))return this.propName||this.exprContext!=3?(this.exprError("E_CSS_UNEXPECTED_SEMICOL",h),this.actions=Ae,a.consume(),!1):(this.importCondition=l.pop(),this.importReady=!0,this.actions=Ae,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let v=this.readSupportsTest(h);if(v){l.push(v),this.actions=ge;continue}}l.push(h.type),a.consume();continue;case 27:if(this.actions=Ae,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=h.text.toLowerCase(),p){case"import":if(a.consume(),h=a.token(),h.type==2||h.type==8){if(this.importURL=h.text,a.consume(),h=a.token(),h.type==17||h.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Ue,l.push("{");continue}o.error("E_CSS_IMPORT_SYNTAX",h),this.actions=je;continue;case"namespace":switch(a.consume(),h=a.token(),h.type){case 1:if(p=h.text,a.consume(),h=a.token(),(h.type==2||h.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[p]=h.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=h.text,a.consume(),a.consume();continue}break}o.error("E_CSS_NAMESPACE_SYNTAX",h),this.actions=je;continue;case"charset":if(a.consume(),h=a.token(),h.type==2&&a.nthToken(1).type==17){p=h.text.toLowerCase(),p!="utf-8"&&p!="utf-16"&&o.error(`E_CSS_UNEXPECTED_CHARSET ${p}`,h),a.consume(),a.consume();continue}o.error("E_CSS_CHARSET_SYNTAX",h),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":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"-adapt-footnote-area":switch(a.consume(),h=a.token(),h.type){case 12:a.consume(),o.startFootnoteRule(null),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),h=a.token(),h.type==1&&a.nthToken(1).type==12){p=h.text,a.consume(),a.consume(),o.startFootnoteRule(p),this.ruleStack.push("-adapt-footnote-area"),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"-epubx-region":a.consume(),o.startRegionRule(),this.regionRule=!0,this.actions=at;continue;case"page":a.consume(),o.startPageRule(),this.pageRule=!0,this.actions=St;continue;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(),h=a.token(),h.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=Ue,l.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Ue,l.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Ue,l.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(),h=a.token();let v=null,y=null,C=[];for(h.type==1&&(v=h.text,a.consume(),h=a.token()),h.type==18&&a.nthToken(1).type==1&&(y=a.nthToken(1).text,a.consume(),a.consume(),h=a.token());h.type==6&&h.text.toLowerCase()=="class"&&a.nthToken(1).type==1&&a.nthToken(2).type==11;)C.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),h=a.token();if(h.type==12){switch(a.consume(),p){case"-epubx-page-master":o.startPageMasterRule(v,y,C);break;case"-epubx-partition":o.startPartitionRule(v,y,C);break;case"-epubx-partition-group":o.startPartitionGroupRule(v,y,C);break}this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":o.error(`E_CSS_UNEXPECTED_AT${p}`,h),this.actions=He;continue;default:o.error(`E_CSS_AT_UNKNOWN ${p}`,h),this.actions=je;continue}o.error(`E_CSS_AT_SYNTAX ${p}`,h),this.actions=je;continue;case 50:this.errorBrackets.push(h.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Ae;continue}case 51:if(r&&this.errorBrackets.length==0&&h.type==11)return a.consume(),o.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==h.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&h.type==13&&(this.actions=Ae),a.consume();continue;case 53:this.errorBrackets.length==0&&(this.actions=Ae),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,h)?(this.result=l.pop(),!0):!1;if(r){switch(h.type){case 16:case 11:if(this.actions===at)o.error("E_CSS_SYNTAX",h);else{let v=a.input.substring(w,h.position);o.pushSelectorText(v),w=h.position+1}if(h.type===16){o.nextSelector(),this.actions=at,a.consume();continue}else return o.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(s){this.actions=me;continue}break;case 12:case 14:case 10:this.errorBrackets.push(h.type+1);break}o.error("E_CSS_SYNTAX",h),a.consume(),this.actions=He;continue}if(this.actions!==je&&this.actions!==He&&this.actions!==tt){if(h.type==54)o.error("E_CSS_SYNTAX",h);else if(this.actions===Ie){switch(h.type){case 10:case 12:case 14:this.errorBrackets.push(h.type+1);break}l.push(new _i(h.toString())),a.consume();continue}else if(h.type===12&&this.actions==Ue&&l.length>0){o.startMediaRule(l.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Ae,a.consume();continue}else{if(h.type===17&&this.actions==Ue)return this.actions=Ae,a.consume(),!1;o.error("E_CSS_SYNTAX",h)}this.isInsidePropertyOnlyRule()?this.actions=tt:this.actions=He;continue}a.consume();continue}}return!1}},Ku=class extends ya{constructor(e){super(null),this.scope=e}error(e,t){$.warn(e,t.toString())}getScope(){return this.scope}};function kg(e,t,i,n,r){let s=O("parseStylesheet"),o=new lr(Ae,e,t,i),a=null;return r&&(a=Ng(new Ft(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 h=Pe(o.importURL,i);o.importCondition&&(t.startMediaRule(o.importCondition),t.startRuleBody());let u=O("parseStylesheet.import");return Zu(h,t,null,null).then(()=>{o.importCondition&&t.endRule(),o.importReady=!1,o.importURL=null,o.importCondition=null,u.finish(!0)}),u.result()}let l=s.timeSlice();if(l.isPending)return l}return N(!1)}).then(()=>{a&&t.endRule(),s.finish(!0)}),s.result()}function ba(e,t,i,n,r){return an("parseStylesheetFromText",s=>{let o=new Ft(e,t);kg(o,t,i,n,r).thenFinish(s)},(s,o)=>{$.warn(o,`Failed to parse stylesheet text: ${e}`),s.finish(!1)})}function Zu(e,t,i,n){return an("parseStylesheetFromURL",r=>{ws(e).then(s=>{s.responseText?ba(s.responseText,t,e,i,n).then(o=>{o||$.warn(`Failed to parse stylesheet from ${e}`),r.finish(!0)}):r.finish(!0)})},(r,s)=>{$.warn(s,"Exception while fetching and parsing:",e),r.finish(!0)})}function gn(e,t,i){let n=new lr(Ie,t,new Ku(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function Eg(e,t,i){new lr(Kr,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Ng(e,t,i){let n=new lr(Ue,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var Pg={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function Tg(e){return!!Pg[e]}function Ig(e,t,i){if(t instanceof ze&&t.str==="viv-leader")return new U(t);let n=t.evaluate(e);switch(typeof n){case"number":return Tg(i)?n==Math.round(n)?new Le(n):new gt(n):new I(n,"px");case"string":return n?gn(t.scope,new Ft(n,null),""):X;case"boolean":return n?b._true:b._false;case"undefined":return X}throw new Error("E_UNEXPECTED")}function Ju(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 l=t?a.logical:a.physical,h=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${l}(-?)`),to:`$1${h}$2`}})})}),i}function Qu(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 ec={"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"}]}},Ag=Ju(ec,!0);function tc(e,t,i){return Qu(e,t,i||null,Ag)}var Rg=Ju(ec,!1);function ic(e,t,i){return Qu(e,t,i||null,Rg)}var Fg={"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 Lg(e,t){let i=Fg[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",l=a?"height":"width",h=a?"width":"height";function u(p,f){r.style[p]=f;let m=o(p);return r.style[p]=s[p],m}let d={};for(let p of i){let f;switch(p){case"max-content inline size":f=u(l,"max-content");break;case"min-content inline size":f=u(l,"min-content");break;case"fit-content inline size":f=u(l,"fit-content");break;case"max-content block size":f=u(h,"max-content");break;case"min-content block size":f=u(h,"min-content");break;case"fit-content block size":f=u(h,"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 En(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 nc(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function rc(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function wt(e,t){let i=nc(e);i.includes(t)||(i.push(t),rc(e,i))}function Og(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function Bg(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function Vs(e,t){let i=Og(e);i.includes(t)||(i.push(t),Bg(e,i))}function Mg(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===b.always?b.page:i,important:e.important};default:return e}}var co={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function it(e){return!!co[e]}var _g={left:!0,right:!0,recto:!0,verso:!0};function Xn(e){return!!_g[e]}var zg={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Zr(e){return!!zg[e]}function rt(e,t){if(e)if(t){if(Xn(t))return t;if(Xn(e))return e;{let i=it(e),n=it(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:Zr(t)?t:Zr(e)?e:t}}else return e;else return t}function Ll(e){return it(e)?e:"auto"}Nt("SIMPLE_PROPERTY",Mg);var Mn=Rp(Lp());function Dg(e,t){return(0,Mn.default)(e,t,0)}function Ol(e){return e.reduce((t,i)=>i[0]===Mn.default.DELETE?t:t+i[1],"")}function Vg(e,t){return sc(e,t,1)}function Hg(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 Mn.default.INSERT:n++;break;case Mn.default.DELETE:n--,r++;break;case Mn.default.EQUAL:r++;break}if(r>t)return!0}return!1}),Math.max(Math.min(t,r-1)+n,0)}var po;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(po||(po={}));var en;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(en||(en={}));var Jr;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Jr||(Jr={}));var Ni;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||li.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||li.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(Ni||(Ni={}));var li;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(li||(li={}));var Xt;(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={}))})(Xt||(Xt={}));var Ug={transform:!0,"transform-origin":!0},$g={top:!0,bottom:!0,left:!0,right:!0},xa=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},Wg={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 Gg(e,t){let i=Wg[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var fo=class Nn extends ha{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(Nn.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Nn.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(Nn.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Nn.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||T(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],l=this.elementsById[o.observer];if(a&&l){let h=Gg(a,o.action);if(h)for(let u=0;u<l.length;u++)l[u].addEventListener(o.event,h,!1)}}}};c(fo,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),c(fo,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var oc=fo,lt=Xt.Whitespace;function ac(e){switch(e){case"normal":case"nowrap":return lt.IGNORE;case"pre-line":return lt.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return lt.PRESERVE;default:return null}}function $e(e,t){if(!e)return!0;if(e.nodeType==1)return!1;let i=e.textContent;switch(t){case lt.PRESERVE:return i.length==0;case lt.NEWLINE:return!!i.match(/^[ \t]*$/);case lt.IGNORE:default:return!!i.match(/^[ \t\r\n\f]*$/)}}var jg=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,c(this,"forcedBreakOffsets",[]),c(this,"formattingContext",null)}},Xg=class{constructor(e,t,i,n,r,s,o,a,l){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=l,c(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function qg(e,t){return e.top-t.top}function Yg(e,t){return t.right-e.right}function lc(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===Xt.ShadowType.ROOTLESS&&t.shadowType===Xt.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&mo(e.shadowContext,t.shadowContext)&&mo(e.nodeShadow,t.nodeShadow)&&lc(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(!lc(e.steps[i],t.steps[i]))return!1;return!0}function Kg(e){return{steps:[{node:e,shadowType:xt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function Qr(e,t){return{steps:[{node:e.sourceNode,shadowType:xt.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function es(e,t){let i=new Pn(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?es(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var xt=Xt.ShadowType,go=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&&mo(this.parentShadow,e.parentShadow):!1}};function mo(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Zg=class{constructor(e,t){this.outer=e,this.count=t}},Pn=class hc{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,"verticalAlign","baseline"),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=xt.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=en.FloatReference.INLINE,this.whitespace=i?i.whitespace:lt.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=en.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.verticalAlign="baseline",this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:lt.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 hc(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.verticalAlign=this.verticalAlign,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===Xt.ShadowType.ROOTLESS&&(r.floatReference!==en.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?Hg(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}},ui=class uc{constructor(t){this.primary=t,c(this,"floats",null)}clone(){let t=new uc(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}},Jg=class cc{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new cc(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Qg=class dc{constructor(){c(this,"positions",[]),c(this,"startBreakType",null),c(this,"breakAfter",null)}clone(){let t=new dc,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}},em=class pc{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 pc;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,T(this.element,"top",`${e}px`),T(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,T(this.element,"left",`${e}px`),T(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 bt(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 bt(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return Fu(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 bt(e,t,e+i,t+n)}},ts=class extends Kt{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 Qe)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"){t instanceof De&&(i=gn(t.scope,new Ft(i,null),"").stringValue()),this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof ze&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function Dt(e){return e!=null&&e!==X&&e!==b.normal&&e!==b.none&&!K(e)}var Oe=en.FloatReference;function tm(e){switch(e){case"inline":return Oe.INLINE;case"column":return Oe.COLUMN;case"region":return Oe.REGION;case"page":return Oe.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function tn(e){switch(e){case Oe.INLINE:return!1;case Oe.COLUMN:case Oe.REGION:case Oe.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function Bl(e,t,i,n){let r=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=ic(e,r,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let s=tc(e,r,i),o=Lg(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"&&($.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var gc=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)}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())}isAllowedToPrecede(e){return!1}},im=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(i=>hi(i.nodePosition,e));return t>=0?this.floats[t]:null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},mc=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}},Ml=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}},Tn=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),e&&e.children.push(this),this.writingMode=s||e&&e.writingMode||b.horizontal_tb,this.direction=o||e&&e.direction||b.ltr,this.floatStore=e?e.floatStore:new im;let a=this.getPreviousSibling();this.floatsDeferredFromPrevious=a?[].concat(a.floatsDeferredToNext):[]}getParent(e){if(!this.parent)throw new Error(`No PageFloatLayoutContext for ${e}`);return this.parent}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&&hi(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 ln().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===Oe.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 ic(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return tc(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(l=>l.includes("block"))?(n.push("snap-block"),r=!0):n.push(a)):a.includes("inline")&&(s||(i.slice(o+1).some(l=>l.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){this.container;let s=this.toLogical(e),o=this.toPhysical(e),a=t&&this.toLogical(t),l=t&&this.toPhysical(t),h=this.getLimitValueInner(s,a,i,n,r);if(this.parent&&this.parent.container){let u=this.parent.getLimitValue(o,l,i,n,r);switch(o){case"top":return Math.max(h,u);case"left":return Math.max(h,u);case"bottom":return Math.min(h,u);case"right":return Math.min(h,u);default:}}return h}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){this.container;let s=this.container.originX,o=this.container.originY,a=this.container.getPaddingRect(),l={top:a.y1-o,left:a.x1-s,bottom:a.y2-o,right:a.x2-s,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};function h(d,p,f){return d.unit==="%"?f*d.num/100:e.convertLengthToPx(d,p,t)}let u=this.floatFragments;return u.length>0&&(l=u.reduce((d,p)=>{if(i&&!i(p,this))return d;let[f,m]=this.toLogicalFloatSides(p.floatSide);if(m&&(n&&m.includes("block")===n.includes("block")&&m!==n||r&&m.includes("block")===r.includes("block")&&m!==r))return d;let g=p.area,w=p.continuations[0].float.floatMinWrapBlock,v=d.top,y=d.left,C=d.bottom,E=d.right,A=d.floatMinWrapBlockStart,H=d.floatMinWrapBlockEnd;switch(f){case"inline-start":g.vertical?v=Math.max(v,g.top+g.height):y=Math.max(y,g.left+g.width);break;case"block-start":g.vertical?(w&&g.left<E&&(A=h(w,g.rootViewNodes[0],a.x2-a.x1)),E=Math.min(E,g.left)):(w&&g.top+g.height>v&&(A=h(w,g.rootViewNodes[0],a.y2-a.y1)),v=Math.max(v,g.top+g.height));break;case"inline-end":g.vertical?C=Math.min(C,g.top):E=Math.min(E,g.left);break;case"block-end":g.vertical?(w&&g.left+g.width>y&&(H=h(w,g.rootViewNodes[0],a.x2-a.x1)),y=Math.max(y,g.left+g.width)):(w&&g.top<C&&(H=h(w,g.rootViewNodes[0],a.y2-a.y1)),C=Math.min(C,g.top));break;default:throw new Error(`Unknown logical float side: ${f}`)}return{top:v,left:y,bottom:C,right:E,floatMinWrapBlockStart:A,floatMinWrapBlockEnd:H}},l)),l.left+=s,l.right+=s,l.top+=o,l.bottom+=o,l}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 l=a.find(A=>A.includes("inline")&&o[A==="inline-start"?"inline-end":"inline-start"]),h=a.find(A=>A.includes("block")),u=this.getLimitValue("block-start",l,e.layoutContext,e.clientLayout),d=this.getLimitValue("block-end",l,e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-start",h,e.layoutContext,e.clientLayout),f=this.getLimitValue("inline-end",h,e.layoutContext,e.clientLayout),m=e.vertical?e.originX:e.originY,g=e.vertical?e.originY:e.originX;u=e.vertical?Math.min(u,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+m):Math.max(u,e.top+m),d=e.vertical?Math.max(d,e.left+m):Math.min(d,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+m);function w(A,H){let V=A(e.bands,H);return V?(e.vertical&&(V=Iu(V)),u=e.vertical?Math.min(u,V.x2):Math.max(u,V.y1),d=e.vertical?Math.max(d,V.x1):Math.min(d,V.y2),!0):s}let v,y,C,E;if(r){let A=e.vertical?Yr(new bt(d,p,u,f)):new bt(p,u,f,d);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!w(Nf,A)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(Pf,A)||(C=(d-u)*e.getBoxDir(),v=C-e.getInsetBefore()-e.getInsetAfter(),E=(f-p)*e.getInlineDir(),y=E-e.getInsetStart()-e.getInsetEnd(),!s&&(v<=0||y<=0)))return null}else{v=e.computedBlockSize,C=v+e.getInsetBefore()+e.getInsetAfter();let A=(d-u)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let V=this.container.getPaddingRect(),ie=this.container.getBoxDir()*(n-(this.container.vertical?V.x2:V.y1)),ne=this.container.getBoxDir()*((this.container.vertical?V.x1:V.y2)-n-C);ie<=ne?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&&A<C)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?y=va(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?y=e.getContentInlineSize():y=e.vertical?e.height:e.width,E=y+e.getInsetStart()+e.getInsetEnd();let H=(f-p)*e.getInlineDir();if(!s&&H<E)return null}return u-=m,d-=m,p-=g,f-=g,a.some(A=>A==="inline-start"||A==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(p,y):(a.some(A=>A==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-E*e.getInlineDir(),y),a.some(A=>A==="block-start"||A==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(u,v):(a.some(A=>A==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(d-C*e.getBoxDir(),v),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)}getBlockStartEdgeOfBlockEndFloats(){let e=this.getContainer().vertical;return this.floatFragments.filter(t=>t.floatSide==="block-end").reduce((t,i)=>{let n=i.getOuterRect();return e?Math.max(t,n.x2):Math.min(t,n.y1)},e?0:1/0)}getPageFloatClearEdge(e,t){function i(h){return u=>h.isAnchorAlreadyAppeared(u.float.getId())}function n(h,u){return e==="inline-start"&&(h.floatSide.includes("inline-end")||h.floatSide==="block-end")||e==="inline-end"&&(h.floatSide.includes("inline-start")||h.floatSide==="block-start")?!1:h.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(h){return h.floatFragments.some(u=>n(u,h))||h.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 l=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:l}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 l(d){return p=>(!d||p.floatSide.includes(d))&&p.getOrder()<a}function h(d,p){return d.children.some(f=>f.floatFragments.some(l(p))||h(f,p))}function u(d,p){let f=d.parent;return!!f&&(f.floatFragments.some(l(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(l(null))||h(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]=!h(this,d);break;case"block-end":n[d]=!u(this,d);break;case"inline-start":case"inline-end":n[d]=!this.floatFragments.some(l(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=[],ln=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}`)}},nm=class{appliesToNodeContext(e){return tn(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let r=e.floatSide,s=e.toNodePosition();return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(o=>{n=o,t.flowName;let a=new gc(s,n,r,e.clearSide,t.flowName,e.floatMinWrapBlock);return t.addPageFloat(a),N(a)})}createPageFloatFragment(e,t,i,n,r){let s=e[0].float;return new mc(s.floatReference,t,i,e,n,r)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){}forbid(e,t){}};ln.register(new nm);var rm=mc,wo=class wc extends gc{constructor(t,i,n,r,s){super(t,i,"block-end",null,n,s),this.footnotePolicy=r}isAllowedToPrecede(t){return!(t instanceof wc)}},_l=class extends rm{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof wo?!0:this.getOrder()<e.getOrder()}},sm=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.toNodePosition();return!hi(t,this.footnote.nodePosition)}},om=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof wo}createPageFloat(e,t,i){let n=Oe.REGION,r=t.getPageFloatLayoutContext(n);t.getPageFloatLayoutContext(Oe.PAGE).hasSameContainerAs(r)&&(n=Oe.PAGE);let s=e.toNodePosition();t.flowName;let o=new wo(s,n,t.flowName,e.footnotePolicy,e.floatMinWrapBlock);return t.addPageFloat(o),N(o)}createPageFloatFragment(e,t,i,n,r){let s=e[0].float;return new _l(s.floatReference,e,n,r)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof _l);return i.length<=1,i[0]||null}adjustPageFloatArea(e,t,i){e.isFootnote=!0,e.adjustContentRelativeSize=!1;let n=e.element;e.vertical=i.layoutContext.applyFootnoteStyle(t.vertical,i.layoutContext.nodeContext&&i.layoutContext.nodeContext.direction==="rtl",n),e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e)}forbid(e,t){let i=e;switch(i.footnotePolicy){case b.line:{let n=new sm(i);t.addLayoutConstraint(n,i.floatReference);break}}}};ln.register(new om);var am="data-vivliostyle-flow-root";function lm(e){return e.getAttribute(am)==="true"}function zl(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"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 F(i)}function Sa(e){return e===b.absolute||e===b.fixed}function yo(e){return e instanceof Ri&&e.name==="running"}function yc(e,t,i,n){return e===b.none||(Sa(t)?(i=b.none,e=zl(e)):(i&&i!==b.none&&!K(i)||n)&&(e=zl(e))),{display:e,position:t,float:i}}function bc(e,t,i,n){return yc(e,t,i,n).display===b.block}function ys(e){return e instanceof le||e instanceof J||typeof e=="string"}function Mt(e){if(!ys(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 ki(e){return ys(e)?e.toString().includes("list-item"):!1}function hm(e){if(!ys(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 vc(e){if(!ys(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 um(e,t,i,n,r,s,o){return r=r||s||b.horizontal_tb,!!o||!!i&&i!==b.none&&!K(i)||Sa(t)||e===b.inline_block||e===b.table_cell||e===b.table_caption||e==b.flex||e==b.grid||e==b.flow_root||(e===b.block||e===b.list_item)&&!!n&&n!==b.visible&&n!==b.clip&&!K(n)||!!s&&r!==s}function cm(e){return e===b.relative||e===b.absolute||e===b.fixed}var Bt=1e5;function Ca(e){let t=e.element.style;t.columnGap=`${Bt-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function ka(e){let t=e.element.style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function xc(e){return e.element.style.columnCount==="1"}function dm(e){e.element.setAttribute("data-vivliostyle-column","true")}function Dl(e){return e.element.hasAttribute("data-vivliostyle-column")}function qn(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/Bt)}function bo(e,t){let i=qn(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/Bt),s=r*Bt,o=i*Bt;return t?(e.top-=s,e.bottom-=o,e.bottom<e.top&&(e.bottom+=Bt),e.right-=s,e.left-=o):e.left<-Bt/2?(e.right+=s,e.left+=o,e.left>e.right&&(e.left-=Bt),e.top+=s,e.bottom+=o):(e.left-=s,e.right-=o,e.right<e.left&&(e.right+=Bt),e.top+=s,e.bottom+=o),e.width=e.right-e.left,e.height=e.bottom-e.top,r}function Sc(e,t){for(let i=0;i<e.length;i++)bo(e[i],t)}function It(e,t,i){var n;let r=e.getElementClientRect(t),s=bo(r,i);if(s===1){let o=e.getElementComputedStyle(t);if(o.display==="table-cell"||t.className==="-vivliostyle-table-cell-container"&&(n=t.parentElement)!=null&&n.parentElement&&(o=e.getElementComputedStyle(t.parentElement.parentElement)).display==="table-cell"){let a=t.closest("[data-vivliostyle-column]"),l=a?.style,h=i?"width":"height",u=l&&parseFloat(l[h]);if(u){let d=u,p=s,f=parseFloat(o.paddingBlockEnd),m=parseFloat(o.borderBlockEndWidth),g=Math.ceil(f+m);for(;g-- >0&&p===s&&--d>0;){l[h]=`${d}px`;let w=e.getElementClientRect(t);if(p=bo(w,i),p<s||p===s&&(i?w.right>r.right:w.top<r.top))return a.setAttribute("data-vivliostyle-column-height-adjusted","true"),w}l[h]=`${u}px`}}}return r}function pm(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 Ea(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 fm(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=Ea(i);if(!a)return;let l=a.ownerDocument.defaultView.getComputedStyle(a),{writingMode:h,direction:u,columnGap:d,fontSize:p}=l,f=h==="vertical-rl"||h==="vertical-lr",m=u==="rtl",g=(parseFloat(d)||parseFloat(p)||16)/2,w=a.getBoundingClientRect(),v=i.getBoundingClientRect();(f?v.top>w.bottom+g:m?v.right<w.left-g:v.left>w.right+g)&&(r&&(n.breakBefore=""),o&&s&&(s.style.breakAfter=""),n.marginBlockStart=`${Bt}px`)}function Wi(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==="br"||s.localName==="wbr"||o&&Mt(o.display)&&/^([\d\.]|super|(text-)?top)/.test(o.verticalAlign))return NaN}if(r===s){if(e.after||!e.inline){if(e.after&&!e.inline&&s.querySelector("ruby")){let a=s.parentNode,l=s.nextSibling;a.removeChild(s),a.insertBefore(s,l)}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(),l=r.textContent.length;if(!l)return NaN;e.after&&(i+=l),i>=l&&(i=l-1),a.setStart(r,i),a.setEnd(r,i+1);let h=t.getRangeClientRects(a);return Sc(h,n),h=h.filter(u=>u.right>u.left&&u.bottom>u.top),h.length?(n?o=Math.min.apply(null,h.map(u=>u.left)):o=Math.max.apply(null,h.map(u=>u.bottom)),o):NaN}}function vo(e,t,i){let n=xc(t);n&&ka(t);let r=t.clientLayout.getElementClientRect(e);n&&Ca(t);let s=t.getComputedMargin(e);return i?r.width+s.left+s.right:r.height+s.top+s.bottom}function qi(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function Cc(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 hn="data-adapt-spec";function Na(e){return!!e.getAttribute(hn)}function Yi(e){var t;if(e?.nodeType!==1)return!1;let i=e;if(Na(i))return!0;let n=(t=i.style)==null?void 0:t.position;return n==="absolute"||n==="fixed"}function Ki(e){let t=e?.viewNode;return t?.nodeType===1&&Na(t)}function gm(e){return e!=="inline"&&(Mt(e)||vc(e))}function Vl(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}var Pa=class{calculateOffset(e){return nn(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function nn(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var hr=class extends Pa{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(Zr(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=Wi(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 l=n;l;l=l.parentElement){let h=e.clientLayout.getElementComputedStyle(l);if((l===n||l===r&&!s)&&(o+=e.parseComputedLength(h.paddingBlockEnd)),l===r&&!s&&(o+=e.parseComputedLength(h.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),s?a=Math.max(a,e.parseComputedLength(h.borderBlockEndWidth)):(l===n||l===r)&&(a+=e.parseComputedLength(h.borderBlockEndWidth)),l===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(!Ni.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},vn=class{find(e){let t=Rt("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()}`)}},Zi=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 hr(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===Xt.ShadowType.ROOTLESS&&Ki(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;Cc(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)}},Ta=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){}},Ia=new Zi,mm=po.isInstanceOfBlockFormattingContext;Nt("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&&bc(i,n,r,s)?new Ta(o?o.formattingContext:null):null});Nt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Ta?Ia:null);var Aa=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=O("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)}},wm=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){}},xo=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=O("LayoutIterator");return n.loopWithFrame(r=>{let s;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?$e(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()}},_n=class extends wm{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&&it(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=rt(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=rt(e.breakAtTheEdge,e.nodeContext.breakAfter)),N(!0)))}},So=[];function ym(){So=[]}function kc(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var bm=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},vm=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},Ec=class Tr{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let r=Tr.fragmentIndices;(!r[t]||r[t].priority<=n)&&(r[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){Tr.fragmentIndices={}}matches(){let t=Tr.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&kc(t.fragmentIndex,this.a,this.b)}};c(Ec,"fragmentIndices",{});var bs=Ec,br=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new bs(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new vm(e)}static buildAnyMatcher(e){return new bm(e)}},Nc={"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},xm=["image-resolution","orphans","widows"];function Sm(){return Rt("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(xm))}var Cm={"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},Co=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],km=["max-%","min-%","%"],Hl=(()=>{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<Co.length;i++)for(let n=0;n<e.length;n++){let r=Co[i].replace("%",e[n]);t[r]=!0}return t})();function mn(e,t){let i={};for(let n of Co)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 km)for(let r in t){let s=n.replace("%",r),o=n.replace("%",t[r]);i[s]=o,i[o]=s}return i}var Pc=mn({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),Tc=mn({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),Em=mn({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),Nm=mn({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),Pm=mn({inside:"right",outside:"left"},{}),Tm=mn({inside:"left",outside:"right"},{}),_=class ko{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 ko(i,this.priority)}increaseSpecificity(t){return t==0?this:new ko(this.value,this.priority+t)}evaluate(t,i,n,r){return i&&zt(i)?this.value:ns(t,this.value,i,n,r)}isEnabled(t){return!0}},Eo=class No extends _{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new _(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new No(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new No(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){$.warn(i)}return!1}};function Po(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function qt(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 Ic={"region-id":!0,"fragment-selector-id":!0};function Im(e){return!!Ic[e]}function Ir(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Ei(e){return e.charAt(0)!=="_"&&!Ic[e]}function zn(e){return!!Nc[e]||zt(e)}function Re(e,t){return e[t]}function Pi(e,t,i){i?e[t]=i:delete e[t]}function kt(e,t){return e[t]}function ur(e,t){let i=e[t];return i||(i={},e[t]=i),i}var Ac=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function Rc(e,t){return e[t]}function Fc(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function is(e,t,i,n,r,s,o){var a,l;if([{id:r,styleKey:"_pseudos"},{id:s,styleKey:"_regions"}].forEach(h=>{if(h.id){let u=ur(t,h.styleKey);t=u[h.id],t||(t={},u[h.id]=t)}}),o){let h=Ac(t);t={},h.push({styles:t,matcher:o})}for(let h in i)if(!Ir(h))if(Im(h)){let u=Rc(i,h),d=Fc(t,h);Array.prototype.push.apply(d,u)}else{let u=Re(i,h);if(!u.isEnabled(e))continue;let d=u.increaseSpecificity(n);qt(t,h,d,e);let p=(l=(a=e.style)==null?void 0:a.validatorSet.shorthands[h])==null?void 0:l.propList;if(p)for(let f of p){let m=new _(X,d.priority);qt(t,f,m,e)}}}function Am(e,t){let i={};for(let n=0;n<t.length;n++)is(e,i,t[n],0,null,null,null);return i}function Ra(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 Rm=class extends Ai{constructor(e,t){super(),this.props=e,this.context=t,c(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=Re(this.props,"font-size");if(!e.value.isNumeric())return At.em;let t=e.value;if(!ef(t.unit))throw new Error("Unexpected state");return t.num*At[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?To(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?Fa(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?ns(this.context,e,this.propName).visit(this):e}};function Fa(e,t,i){let n=e.unit,r=e.num;return n==="em"?new I(r*t,"px"):n==="rem"?new I(r*i.fontSize(),"px"):n==="rlh"?new I(r*i.rootLineHeight,"px"):e}function To(e,t,i){e=Fa(e,t,i);let n=e.unit,r=e.num;return n==="px"?e:n==="%"?new I(r/100*t,"px"):new I(r*i.queryUnitSize(n,!1),"px")}var wn=class{apply(e){}mergeWith(e){return new Fm([this,e])}clone(){return this}},vr=class extends wn{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},Fm=class Lc extends wn{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 Lc([].concat(this.list))}},La=class extends wn{constructor(e,t,i,n,r){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=r}apply(e){is(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},ve=class extends wn{constructor(){super(),c(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Lm=class extends ve{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}},Om=class extends ve{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}},Ul=class extends ve{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}},Bm=class extends ve{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}},Mm=class extends ve{constructor(e,t){super(),this.epubTypePatt=e,this.targetLocalName=t}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=n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");r&&r.match(this.epubTypePatt)&&this.chained.apply(e)}}}},_m=class extends ve{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function vs(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 $l=class extends ve{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){vs(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},zm=class extends ve{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){vs(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}},Dm=class extends ve{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){vs(e.currentElement,this.ns,this.name,(t,i,n)=>!!Cm[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},xn=class extends ve{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){vs(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)}},Vm=class extends ve{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Wl=class extends ve{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},Hm=class extends ve{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},Fi=class extends ve{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return kc(e,this.a,this.b)}},Um=class extends Fi{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},Io=class extends Fi{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}},Ao=class extends Fi{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}},Ro=class extends Fi{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}},$m=class extends ve{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}},Wm=class extends ve{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},Gm=class extends ve{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},jm=class extends ve{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},Ke=class extends ve{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}},Oc=class Bc extends wn{constructor(){super(),c(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new Bc;return t.applied=this.applied,t}},Oa=class extends ve{constructor(e){super(),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new Oc;for(let t of e)this.firstActions.push(Ra(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 ve?e.getPriority():0))}positive(){return!0}relational(){return!1}},Xm=class extends Oa{positive(){return!1}},qm=class extends Oa{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}},Mc=class extends Fi{constructor(e,t,i){super(e,t),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new Oc;for(let n of i)this.firstActions.push(Ra(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 l=1,h=e.previousElementSibling;for(;h;)l++,h=h.previousElementSibling;t.currentSiblingOrder=l;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}},Ym=class extends Mc{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}},xs=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)}},Km=class _c extends xs{constructor(t,i,n){super(t,i,n)}fresh(t){return new _c(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}},Zm=class zc extends xs{constructor(t,i,n){super(t,i,n)}fresh(t){return new zc(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)}},Jm=class Dc extends xs{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new Dc(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)}},Qm=class Vc extends xs{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new Vc(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}},ew=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}},tw=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}},iw=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}},nw=class extends Ai{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new Qe(e):new Qe("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 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 Dn(e){if(Dt(e)){if(e instanceof j)return e.stringValue();if(e instanceof J)return e.values.map(t=>Dn(t)).join("")}return""}var Fo=class extends Ai{constructor(e,t,i){super(),this.cascade=e,this.element=t,this.counterResolver=i}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)}visitFuncCounter(e){let t=e[0].toString(),i=e.length>1?e[1].stringValue():"decimal",n=this.cascade.counters[t];if(n&&n.length){let r=n&&n.length&&n[n.length-1]||0;return new j(this.format(r,i))}else{let r=new U(this.counterResolver.getPageCounterVal(t,s=>this.format(s||0,i)));return new J([r])}}visitFuncCounters(e){let t=e[0].toString(),i=e[1].stringValue(),n=e.length>2?e[2].stringValue():"decimal",r=this.cascade.counters[t],s=new oi;if(r&&r.length)for(let a=0;a<r.length;a++)a>0&&s.append(i),s.append(this.format(r[a],n));let o=new U(this.counterResolver.getPageCountersVal(t,a=>{let l=[];if(a.length)for(let u=0;u<a.length;u++)l.push(this.format(a[u],n));let h=s.toString();return h.length&&l.push(h),l.length?l.join(i):this.format(0,n)}));return new J([o])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof Qe?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",s=new U(this.counterResolver.getTargetCounterVal(i,n,o=>this.format(o||0,r)));return new J([s])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof Qe?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 U(this.counterResolver.getTargetCountersVal(i,n,a=>{let l=a.map(h=>this.format(h,s));return l.length?l.join(r):this.format(0,s)}));return new J([o])}visitFuncTargetText(e){let t=e[0],i;t instanceof Qe?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",r=new U(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 U(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 U(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,r,s,o;let a=e.length>0?e[0].stringValue():"text",l="";switch(a){case"text":l=this.element.textContent;break;case"before":case"after":case"marker":{let h=kt(this.cascade.currentStyle,"_pseudos"),u=(i=(t=h?.[a])==null?void 0:t.content)==null?void 0:i.value;l=Dn(u)}break;case"first-letter":{let h=kt(this.cascade.currentStyle,"_pseudos"),u=(Dn((r=(n=h?.before)==null?void 0:n.content)==null?void 0:r.value)||this.element.textContent||Dn((o=(s=h?.after)==null?void 0:s.content)==null?void 0:o.value)).match(Xr);l=u?u[0]:""}break}return new j(l)}visitFuncLeader(e){let t="";if(e[0]instanceof le)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 U(new ze(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 Hs(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 rw=(e,t,i)=>{let n=t.filter(l=>l.after&&l.viewNode.nodeType===1&&l.viewNode.getAttribute("data-viv-leader"));for(let l of n){let h=function(k){C==="rtl"?m.textContent=(k.startsWith("\u200F")?"":"\u200F")+k+(k.endsWith("\u200F")?"":"\u200F"):m.textContent=k},u=function(){let k=i.clientLayout.getElementClientRect(g);return y==="vertical-rl"||y==="vertical-lr"?C==="rtl"?k.top-=x:k.bottom+=x:C==="rtl"?k.left-=x:k.right+=x,V.left>k.left||V.right<k.right||V.top>k.top||V.bottom<k.bottom},d=function(){let k,R,L=v.repeat(1e4);if(h(L),u())k=1,R=1e4;else return;for(let D=0;D<16;D++){let W="",q=Math.floor((k+R)/2);for(let Q=0;Q<q;Q++)W+=v;if(h(W),u())R=q;else{if(k==q)return;k=q}}h(v)},p=function(k){let R=0,L=g.parentElement;for(;L&&L!==f.viewNode;)R+=i.getComputedInsets(L)[k],L=L.parentElement;return R};var r=h,s=u,o=d,a=p;let f=l.parent;for(;f&&f.inline;)f=f.parent;let m=l.viewNode,g=m.parentElement,w=g.getAttribute("data-adapt-pseudo"),v=m.getAttribute("data-viv-leader-value"),{writingMode:y,direction:C,marginInlineEnd:E}=i.clientLayout.getElementComputedStyle(g);m.style.marginInlineStart="1px",h(v),g.style.display="inline-block",g.style.textIndent="0";let A=Ea(f.viewNode),H=A?.style.columnFill||null;A&&(A.style.columnFill="auto");let V=i.clientLayout.getElementClientRect(f.viewNode),ie=i.clientLayout.getElementClientRect(g),ne=i.parseComputedLength(E),Xe=[],ht=g.parentElement;for(;ht.parentElement&&ht.parentElement!==f.viewNode;)ht=ht.parentElement;let xe=ht.nextSibling;for(;xe;){if(xe.nodeType===1){let k=xe,{display:R,float:L,position:D}=i.clientLayout.getElementComputedStyle(k);if(L!=="none"||D==="absolute"||D==="fixed"){xe=xe.nextSibling;continue}if(Mt(R))Xe.push(k);else if(hm(R))break}else if(xe.nodeType===3){let k=xe;k.length>0&&Xe.push(k)}xe=xe.nextSibling}let x=Xe.reduce((k,R)=>k+Hs(R,i.clientLayout,y),0);if(w!=="after"){let k=Hs(ht,i.clientLayout,y),R=Hs(g,i.clientLayout,y);x+=k-R}y==="vertical-rl"||y==="vertical-lr"?(C==="rtl"?V.top+=ne:V.bottom-=ne,V.top=Math.min(ie.top,V.top),V.bottom=Math.max(ie.bottom,V.bottom)):(C==="rtl"?V.left+=ne:V.right-=ne,V.left=Math.min(ie.left,V.left),V.right=Math.max(ie.right,V.right)),d();let B=i.clientLayout.getElementClientRect(g);C=="rtl"?g.style.float="left":g.style.float="right";let S=i.clientLayout.getElementClientRect(g),P=0;C=="rtl"?y=="vertical-rl"||y=="vertical-lr"?P=B.top-S.top-p("top"):P=B.left-S.left-p("left"):y=="vertical-rl"||y=="vertical-lr"?P=S.bottom-B.bottom-p("bottom"):P=S.right-B.right-p("right"),P-=x,P=Math.max(0,P-.1),g.style.float="",m.style.marginInlineStart=`${P}px`,A&&(H?A.style.columnFill=H:A.style.removeProperty("column-fill"))}};Nt("POST_LAYOUT_BLOCK",rw);var Ba=1/1048576;function Bi(e,t){for(let i in e)t[i]=e[i].clone()}var sw=class Hc{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 Hc;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return Bi(this.tags,t.tags),Bi(this.nstags,t.nstags),Bi(this.epubtypes,t.epubtypes),Bi(this.classes,t.classes),Bi(this.ids,t.ids),Bi(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 ow(this,t,i,n,r,s,o)}nextOrder(){return this.order+=Ba}},ow=class{constructor(e,t,i,n,r,s,o){this.context=t,this.counterListener=i,this.counterResolver=n,this.counterStyleStore=s,this.cmykStore=o,c(this,"code"),c(this,"stack",[[],[]]),c(this,"conditions",{}),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,"pageTypePageCounts",{}),c(this,"isFirst",!0),c(this,"isRoot",!0),c(this,"counters",{}),c(this,"counterScoping",[{}]),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",{}),c(this,"dependentConditions",[]),c(this,"elementStack"),this.code=e,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(e){this.stack[this.stack.length-1].push(e)}increment(e,t){this.conditions[e]=(this.conditions[e]||0)+1,t&&(this.viewConditions[e]?this.viewConditions[e].push(t):this.viewConditions[e]=[t])}decrement(e,t){this.conditions[e]--,this.viewConditions[e]&&(this.viewConditions[e]=this.viewConditions[e].filter(i=>i!==t),this.viewConditions[e].length===0&&delete this.viewConditions[e])}buildViewConditionMatcher(e){let t=null;e&&(this.currentElementOffset,t=br.buildViewConditionMatcher(this.currentElementOffset,e));let i=this.dependentConditions.map(n=>{let r=this.viewConditions[n];return r&&r.length>0?r.length===1?r[0]:br.buildAnyMatcher([].concat(r)):null}).filter(n=>n);return i.length<=0?t:t===null?i.length===1?i[0]:br.buildAllMatcher(i):br.buildAllMatcher([t].concat(i))}applyAction(e,t){let i=e[t];i&&i.apply(this)}pushRule(e,t,i){this.currentElement=null,this.currentElementOffset=null,this.currentStyle=i,this.currentNamespace="",this.currentLocalName="",this.currentId="",this.currentXmlId="",this.currentClassNames=e,this.currentNSTag="",this.currentEpubTypes=Us,this.currentPageType=t,this.applyActions()}defineCounter(e,t){let i=this.counterScoping[this.counterScoping.length-1];i||(i={},this.counterScoping[this.counterScoping.length-1]=i),this.counters[e]?(i[e]&&this.counters[e].pop(),this.counters[e].push(t)):this.counters[e]=[t],i[e]=!0}pushCounters(e){var t,i,n,r,s,o,a;let l=b.inline,h=e.display;if(h&&(l=h.evaluate(this.context)),l===b.none){this.currentElement.setAttribute("data-viv-display-none","true"),this.counterScoping.push(null);return}else if(this.currentElement.closest("[data-viv-display-none]")){this.counterScoping.push(null);return}let u=b.inline,d=e.float;d&&(u=d.evaluate(this.context));let p=null,f=null,m=null,g=e["counter-reset"];if(g){let y=g.evaluate(this.context);y&&(p=Bn(y,!0))}let w=e["counter-set"];if(w){let y=w.evaluate(this.context);y&&(m=Bn(y,!1))}let v=e["counter-increment"];if(v){let y=v.evaluate(this.context);y&&(f=Bn(y,!1))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(p||(p={}),p["list-item"]=((i=(t=this.currentElement)==null?void 0:t.start)!=null?i:1)-1),ki(l)&&(f||(f={}),f["list-item"]=(n=f["list-item"])!=null?n:1,/^\s*[-+]?\d/.test((s=(r=this.currentElement)==null?void 0:r.getAttribute("value"))!=null?s:"")&&(m||(m={}),m["list-item"]=this.currentElement.value)),((o=this.currentElement)==null?void 0:o.parentNode.nodeType)===Node.DOCUMENT_NODE&&(p||(p={}),p.footnote===void 0&&(p.footnote=0)),u===b.footnote&&(f||(f={}),f.footnote===void 0)){let y=(a=this.currentStyle["counter-increment"])==null?void 0:a.value;(!y||!(y===b.footnote||y instanceof J&&y.values.includes(b.footnote)))&&(f.footnote=1)}if(p)for(let y in p)this.defineCounter(y,p[y]);if(f)for(let y in f){this.counters[y]||this.defineCounter(y,0);let C=this.counters[y];C[C.length-1]+=f[y]}if(m)for(let y in m)if(!this.counters[y])this.defineCounter(y,m[y]);else{let C=this.counters[y];C[C.length-1]=m[y]}if(ki(l)){let y=this.counters["list-item"],C=y[y.length-1];e["ua-list-item-count"]=new _(new gt(C),0);let E=ur(e,"_pseudos");E.marker||(E.marker={})}this.counterScoping.push(null)}popCounters(){let e=this.counterScoping.pop();if(e)for(let t in e){let i=this.counters[t];i&&(i.length==1?delete this.counters[t]:i.pop())}}setNamedStrings(e){let t=e["string-set"];if(!t)return;t=t.filterValue(new Fo(this,this.currentElement,this.counterResolver));let i=t.value instanceof Ze?t.value.values:[t.value];for(let n of i)if(n instanceof J){let r=n.values[0].stringValue(),s=n.values.slice(1).map(o=>Dn(o)).join("");this.counterResolver.setNamedString(r,s,this.currentElementOffset)}delete e["string-set"]}setRunningElement(e){let t=e.position;if(t?.value instanceof Ri&&t.value.name==="running"){let i=t.value.values[0].stringValue();this.counterResolver.setRunningElement(i,this.currentElementOffset)}}processPseudoelementProps(e,t){this.pushCounters(e);let i=e.content;i&&(e.content=i.filterValue(new Fo(this,t,this.counterResolver))),this.popCounters()}pushElement(e,t,i,n){var r,s,o;this.currentPageType=null,this.currentElement=t,this.currentElementOffset=n,this.currentStyle=i,this.currentNamespace=t.namespaceURI,this.currentLocalName=t.localName;let a=this.code.nsPrefix[this.currentNamespace];a?this.currentNSTag=a+this.currentLocalName:this.currentNSTag="",this.currentId=t.getAttribute("id"),this.currentXmlId=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let l=t.getAttribute("class");l?this.currentClassNames=l.split(/\s+/):this.currentClassNames=Us;let h=t.getAttributeNS("http://www.idpf.org/2007/ops","type");h?this.currentEpubTypes=h.split(/\s+/):this.currentEpubTypes=Us;let u=Js(t);u&&(this.stack[this.stack.length-1].push(new tw(this.lang)),this.lang=u.toLowerCase());let d=this.isRoot,p=this.siblingOrderStack;this.currentSiblingOrder=++p[p.length-1],p.push(0);let f=this.siblingTypeCountsStack,m=this.currentSiblingTypeCounts=f[f.length-1],g=m[this.currentNamespace];g||(g=m[this.currentNamespace]={}),g[this.currentLocalName]=(g[this.currentLocalName]||0)+1,f.push({});let w=this.followingSiblingOrderStack;w[w.length-1]!==null?this.currentFollowingSiblingOrder=--w[w.length-1]:this.currentFollowingSiblingOrder=null,w.push(null);let v=this.followingSiblingTypeCountsStack,y=this.currentFollowingSiblingTypeCounts=v[v.length-1];y&&y[this.currentNamespace]&&y[this.currentNamespace][this.currentLocalName]--,v.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],e,t),this.applyCalcFilter(this.currentStyle,this.context),this.applyCmykFilter(this.currentStyle,this.currentElement),this.applyAttrFilter(t);let C=i.quotes,E=null;if(C){let V=C.evaluate(this.context);V&&(E=new iw(this.quotes),V===b.none?this.quotes=[new j(""),new j("")]:V===b.auto||V===b.initial?this.quotes=[new j("\u201C"),new j("\u201D"),new j("\u2018"),new j("\u2019")]:V instanceof J&&(this.quotes=V.values))}this.pushCounters(this.currentStyle);let A=this.currentId||this.currentXmlId||t.getAttribute("name")||"";if(d||A){let V={};Object.keys(this.counters).forEach(ie=>{V[ie]=Array.from(this.counters[ie])}),this.counterListener.countersOfId(A,V)}let H=kt(this.currentStyle,"_pseudos");if(H){let V=!0;for(let ie of aw){ie||(V=!1);let ne=H[ie];if(ne)if((ie==="before"||ie==="after")&&!Dt((r=ne.content)==null?void 0:r.value)||ie==="marker"&&!ki((s=Re(this.currentStyle,"display"))==null?void 0:s.value)||(ie==="footnote-call"||ie==="footnote-marker")&&((o=Re(this.currentStyle,"float"))==null?void 0:o.value)!==b.footnote)delete H[ie];else if(V){if(this.processPseudoelementProps(ne,t),ie==="marker")this.processMarkerPseudoelementProps(ne,t,e);else if(ie==="first-letter"&&ne["initial-letter"]){let Xe=ne["initial-letter"].evaluate(this.context);Xe!==b.normal&&!K(Xe)&&(this.currentStyle["--viv-initialLetter"]=new _(Xe,0)),delete ne["initial-letter"]}}else this.stack[this.stack.length-2].push(new ew(ne,t))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),E&&this.stack[this.stack.length-2].push(E)}processMarkerPseudoelementProps(e,t,i){var n,r,s,o,a;if(!Dt((n=e.content)==null?void 0:n.value)&&ki((r=this.currentStyle.display)==null?void 0:r.value)){let l=this.getInheritedPropertyValue("list-style-type",i,t),h=this.getInheritedPropertyValue("list-style-image",i,t);if(h instanceof Qe)e.content=new _(new J([h,new j(" ")]),0);else if(l instanceof j)e.content=new _(l,0);else if(l instanceof le&&l!==b.none){let u=(o=(s=this.currentStyle["ua-list-item-count"])==null?void 0:s.value)==null?void 0:o.num;u!=null&&(e.content=new _(new j(this.counterStyleStore.formatMarker(l.name,u)),0)),e["list-style-type"]=new _(l,0)}}if(!Mt((a=Re(this.currentStyle,"display"))==null?void 0:a.value)){let l=this.getInheritedPropertyValue("list-style-position",i,t);l&&(e["list-style-position"]=new _(l,0))}}getInheritedPropertyValue(e,t,i){var n;for(let s=i;s;s=s.parentElement){let o=(s===this.currentElement?this.currentStyle:t.getStyle(s,!1))[e];if(o){let a=o.evaluate(this.context,e);if(a===b.inherit||a===b.unset||a===b.revert)continue;if(a===b.initial)break;return a}}let r=t.validatorSet;return(n=r?.defaultValues[e])!=null?n:null}applyAttrFilterInner(e,t){for(let i in t)Ei(i)&&!zt(i)&&(t[i]=t[i].filterValue(e))}applyAttrFilter(e){let t=new nw(e),i=this.currentStyle,n=kt(i,"_pseudos");for(let r in n)this.applyAttrFilterInner(t,n[r]);this.applyAttrFilterInner(t,i)}applyVarFilter(e,t,i){var n,r,s;let o=e[0],a=new ww(e,t,i),l=32,h={};for(let u in o)if(Ir(u)){let d=kt(o,u);for(let p in d)this.applyVarFilter([d[p],...e],t,i)}else if(Ei(u)){let d=Re(o,u),p=d.value;for(let f=0;;f++){if(f>=l){p=X;break}let m=p.visit(a);if(a.error){p=X,a.error=!1;break}if(m===p)break;p=m}if(p!==d.value){let f=t.validatorSet,m=(n=f?.shorthands[u])==null?void 0:n.clone();if(m)if(K(p)){for(let g of m.propList){let w=new _(p,d.priority),v=Re(o,g);Pi(h,g,Po(this.context,v,w))}delete o[u]}else{let g=gn(t.scope,new Ft(p.toString(),null),"");if(g&&(g.visit(m),!m.error)){for(let w of m.propList){let v=new _((s=(r=m.values[w])!=null?r:f.defaultValues[w])!=null?s:b.initial,d.priority),y=Re(o,w);Pi(h,w,Po(this.context,y,v))}delete o[u]}}else o[u]=new _(p,d.priority)}if(h[u]){let f=Re(o,u);f&&f.value!==X&&qt(h,u,f,this.context)}}for(let u in h)o[u]=h[u]}applyCalcFilter(e,t){let i=new Kc(t);for(let n in e)if(Ir(n)){let r=kt(e,n);for(let s in r)this.applyCalcFilter(r[s],t)}else if(Ei(n)&&!zt(n)){let r=Re(e,n),s=r.value.visit(i);s!==r.value&&(e[n]=new _(s,r.priority))}}applyCmykFilter(e,t){let i=new Pu(this.cmykStore);if(this.applyCmykFilterInternal(e,i,""),t){let n=i.getConversions();n&&t.setAttribute("data-viv-device-cmyk",JSON.stringify(n))}}applyCmykFilterInternal(e,t,i){for(let n in e)if(Ir(n)){let r=kt(e,n);for(let s in r)this.applyCmykFilterInternal(r[s],t,`::${s}:`)}else if(Ei(n)&&!zt(n)){let r=Re(e,n),s=r.value.toString();t.reset();let o=r.value.visit(t);o!==r.value&&(t.hadDeviceCmyk()&&t.recordConversion(i+n,s),e[n]=new _(o,r.priority))}}applyActions(){let e;for(e=0;e<this.currentClassNames.length;e++)this.applyAction(this.code.classes,this.currentClassNames[e]);for(e=0;e<this.currentEpubTypes.length;e++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[e]);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 t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2];for(e=0;e<i.length;)i[e].push(this,t)?i.splice(e,1):e++}this.isFirst=!0,this.isRoot=!1}pop(){for(let e=1;e>=-1;--e){let t=this.stack[this.stack.length-e-2],i=0;for(;i<t.length;)t[i].pop(this,e)?t.splice(i,1):i++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(e){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}},Us=[],aw=["before","transclusion-before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","transclusion-after","after"],Lo=null;function lw(e){Lo=e}var Yn=class extends ar{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:Lo?Lo.clone():new sw,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=Ra(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 Bm(e,t.toLowerCase())):t?this.chain.push(new Ul(t.toLowerCase())):this.chain.push(new _m(e)))}invalidSelector(e){$.warn(e),this.chain.push(new Ke("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof un;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 Lm(e))}pseudoclassSelector(e,t){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new Wm);break;case"disabled":this.chain.push(new Gm);break;case"checked":this.chain.push(new jm);break;case"root":case"scope":this.chain.push(new Hm);break;case"link":this.chain.push(new Ul("a")),this.chain.push(new $l("","href"));break;case"-adapt-href-epub-type":case"href-epub-type":if(t&&t.length>=1&&typeof t[0]=="string"){let i=t[0],n=new RegExp(`(^|\\s)${Zt(i)}($|\\s)`),r=t[1];this.chain.push(new Mm(n,r))}else this.chain.push(new Ke(""));break;case"-adapt-footnote-content":case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new Ke(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new Vm(new RegExp(`^${Zt(i.toLowerCase())}($|-)`)))}else this.chain.push(new Ke(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=hw[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new Ke(""));break}case"first-child":this.chain.push(new Wl);break;case"last-child":this.chain.push(new Ao(0,1));break;case"first-of-type":this.chain.push(new Io(0,1));break;case"last-of-type":this.chain.push(new Ro(0,1));break;case"only-child":this.chain.push(new Wl),this.chain.push(new Ao(0,1));break;case"only-of-type":this.chain.push(new Io(0,1)),this.chain.push(new Ro(0,1));break;case"empty":this.chain.push(new $m);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 Ke(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new Ke(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}idSelector(e){this.specificity+=65536,this.chain.push(new Om(e))}attributeSelector(e,t,i,n){this.specificity+=256,t=t.toLowerCase(),n=n||"";let r;switch(i){case 0:r=new $l(e,t);break;case 39:r=new zm(e,t,n);break;case 45:!n||n.match(/\s/)?r=new Ke(""):r=new xn(e,t,new RegExp(`(^|\\s)${Zt(n)}($|\\s)`));break;case 44:r=new xn(e,t,new RegExp(`^${Zt(n)}($|-)`));break;case 43:n?r=new xn(e,t,new RegExp(`^${Zt(n)}`)):r=new Ke("");break;case 42:n?r=new xn(e,t,new RegExp(`${Zt(n)}$`)):r=new Ke("");break;case 46:n?r=new xn(e,t,new RegExp(Zt(n))):r=new Ke("");break;case 50:if(n=="supported")r=new Dm(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${xr++}`;this.processChain(new vr(new Km(e,this.viewConditionId,null))),this.chain=[new Ke(e)],this.viewConditionId=null}childSelector(){let e=`c${xr++}`;this.processChain(new vr(new Zm(e,this.viewConditionId,null))),this.chain=[new Ke(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${xr++}`;this.processChain(new vr(new Jm(e,this.viewConditionId,null))),this.chain=[new Ke(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${xr++}`;this.processChain(new vr(new Qm(e,this.viewConditionId,null))),this.chain=[new Ke(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 La(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new Eo(t,0,this.condition):i=new _(t,0),Fc(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===b.oeb_page_head||t===b.oeb_page_foot)&&(this.simpleProperty("flow-options",new J([b.exclusive,b._static]),i),this.simpleProperty("flow-into",t,i),t=b.block),Rt("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 Eo(t,n,this.condition):new _(t,n);qt(this.elementStyle,e,r)}finish(){return this.cascade}startFuncWithSelector(e,t){let i;switch(e){case"is":i=new un(this);break;case"not":i=new uw(this);break;case"where":i=new cw(this);break;case"has":i=new dw(this);break;case"nth-child":t&&t.length>=2&&(i=new $c(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new pw(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},hw={"nth-child":Um,"nth-of-type":Io,"nth-last-child":Ao,"nth-last-of-type":Ro},xr=0,un=class Uc extends Yn{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 qm(this.selectorTexts):this.positive()?new Oa(this.chains):new Xm(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new Ke("")),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 Uc;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}},uw=class extends un{positive(){return!1}forgiving(){return!1}},cw=class extends un{increasingSpecificity(){return!1}},dw=class extends un{relational(){return!0}},$c=class extends un{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 Mc(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ke("")),this.owner.popHandler()}forgiving(){return!0}},pw=class extends $c{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Ym(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ke("")),this.owner.popHandler()}},fw=class extends ar{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 nr(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,r))}}},In=class extends ar{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?$.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){$.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){$.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=Ba;let r=this.condition?new Eo(t,n,this.condition):new _(t,n);qt(this.elementStyle,e,r)}},gw=class extends Ku{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){$.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){$.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?Yu:qu;n+=this.order,this.order+=Ba;let r=new _(t,n);qt(this.elementStyle,e,r)}};function Wc(e,t){let i=Ac(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function Oo(e,t,i){Wc(i,n=>{Vn(e,n,t)})}function mw(e,t,i,n){let r=new gw(e,t),s=new Ft(n,r);try{Eg(s,r,i)}catch(o){$.warn(o,"Style attribute parse error:")}return r.elementStyle}function Gc(e,t,i){let n=e["writing-mode"];if(n){let r=n.evaluate(t,"writing-mode");if(r&&r!==b.inherit&&r!==b.revert&&r!==b.unset)return r===b.vertical_rl}return i}function jc(e,t,i){let n=e.direction;if(n){let r=n.evaluate(t,"direction");if(r&&r!==b.inherit&&r!==b.revert&&r!==b.unset)return r===b.rtl}return i}function Xc(e,t,i,n,r){let s={};for(let o in e)Ei(o)&&(s[o]=Re(e,o));return Oo(s,t,e),qc(e,i,n,(o,a)=>{Vn(s,a,t),Oo(s,t,a)}),s}function qc(e,t,i,n){let r=kt(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 Vn(e,t,i){for(let n in t)if(Ei(n)){let r=Re(t,n),s=e[n];e[n]=Po(i,s,r)}}var Yc=(e,t,i,n,r,s)=>{var o,a;let l=i?n?Em:Pc:n?Nm:Tc,h=r?Pm:Tm;for(let u in e){let d=e[u];if(!d)continue;let p=(o=l[u])!=null?o:l[h[u]],f=(a=h[u])!=null?a:h[l[u]],m=p??f,g;if(m){let w=e[m];if(w&&w.priority>d.priority||p&&f&&p!==f&&(m=f,w=e[m],w&&w.priority>d.priority))continue;g=Hl[p]?p:Hl[f]?f:u}else g=u,u.startsWith("text-align")&&(d.value===b.inside||d.value===b.outside)&&(d=new _(r===(d.value===b.inside)?b.right:b.left,d.priority));t[g]=s(u,d)}},ww=class extends Ai{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 l=(n=a[e])==null?void 0:n.value;if(l)return l}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 le&&e.values[0].name;return!t||!zt(t)?(this.error=!0,X):this.getVarValue(t)||(e.values.length<2?(this.error=!0,X):e.values.length===2?e.values[1]:new Ze(e.values.slice(1)))}},Kc=class extends Ai{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=gn(this.context.rootScope,new Ft(i,null),"");if(n instanceof U)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 I(r,"px"):/\d[a-z]/i.test(i)||(t=new gt(r)))}catch(r){$.warn(r)}return t}visitNumeric(e){return this.resolveViewportUnit&&(iu(e.unit)||nf(e.unit))?new I(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new I(e.num*this.percentRef/100,"px"):e}};function ns(e,t,i,n,r){try{if(t instanceof U)return t.expr instanceof ze&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:Ig(e,t.expr,i);if(t instanceof I||t instanceof Ri||t instanceof J||t instanceof Ze)return t.visit(new Kc(e,!0,n,r))}catch(s){return $.warn(s),X}return t}var Gl={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function jl(e){let t=e instanceof Je?e:typeof e=="string"?F(e):b.none;if(t===b.none)return Gl;let i=t instanceof J?t.values:[t],n=Object.create(Gl);for(let r of i)if(r instanceof le)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 Xl(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var yw={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},ql={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},Yl={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Kl(e){let t=e instanceof Je?e:typeof e=="string"?F(e):b.normal;if(t===b.normal)return ql;if(t===b.auto)return Yl;let i=t instanceof J?t.values:[t],n=Object.create(ql);for(let r of i)if(r instanceof le)switch(r.name){case"trim-both":case"trim-auto":return Yl;case"space-all":return yw;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 $s={ideographAlpha:!1,ideographNumeric:!1},bw={ideographAlpha:!0,ideographNumeric:!0};function Zl(e){let t=e instanceof Je?e:typeof e=="string"?F(e):b.normal;if(t===b.normal||t===b.auto)return bw;if(t===b.none)return $s;let i=t instanceof J?t.values:[t],n=Object.create($s);for(let r of i)if(r instanceof le)switch(r.name){case"no-autospace":return $s;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Jl(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function Ql(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 vw=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=Ql(r);let o=Zl(t),a=Kl(i),l=jl(n);if(Xl(l)&&Jl(o,a))return;this.preprocessForTextSpacing(e);let h=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 m=!d,g=!d||/\n$/.test(d.textContent),w=!p||/^\n/.test(p.textContent),v=!p;this.processTextSpacing(f,m||g,m,g,w,v,d,p,o,a,l,r,s),d=f}e.style.whiteSpace=h}postLayoutBlock(e,t){var i,n,r,s,o,a,l;let h=!e||e.fragmentIndex===1&&p(),u=h||f();function d(v){var y;if(v?.nodeType!==1)return!1;let C=v;if(C.hasAttribute(hn))return!0;let{position:E,float:A}=(y=C.style)!=null?y:{};return E==="absolute"||E==="fixed"||A&&A!=="none"}function p(){let v=t[0];for(let y=v;;y=y.parent)if(!y||!y.inline){if(y?.fragmentIndex!==1)return!1;break}if(!v.inline)return!0;for(let y=v.viewNode.previousSibling;y;y=y.previousSibling)if(!$e(y,v.whitespace)&&!d(y))return!1;return!0}function f(){var v,y;let C=t[0],E;for(;C&&C.inline&&(E=(v=C.viewNode)==null?void 0:v.previousSibling,!(E&&(E.nodeType===3&&/^[ \t\r\n\f]*$/.test(E.textContent)&&C.whitespace!==lt.PRESERVE&&(E=E.previousSibling),E)));)C=C.parent;for(;E;){if(E.nodeType===1){if(E.localName==="br")return!0;let A=(y=E.style)==null?void 0:y.display;if(A&&A!=="inline")return!/^(inline|ruby)\b/.test(A)}else if(E.nodeType===3){if(C.whitespace===lt.PRESERVE){if(/\n$/.test(E.textContent))return!0}else if(C.whitespace===lt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(E.textContent))return!0}E=E.lastChild}return!1}let m=-1;for(let v=0;v<t.length;v++){let y=t[v];if(!y.after&&y.inline&&!y.display&&y.parent&&y.viewNode.parentNode&&y.viewNode.nodeType===Node.TEXT_NODE&&!$e(y.viewNode,y.whitespace)){let C=function(P){var k,R,L;if(((k=P.viewNode)==null?void 0:k.nodeType)===1)return P.viewNode.localName==="br";if(((R=P.viewNode)==null?void 0:R.nodeType)===3){if(P.whitespace===lt.PRESERVE){if(/\n$/.test(P.viewNode.textContent))return!0}else if(P.whitespace===lt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(P.viewNode.textContent))return!0;if(((L=P.viewNode.previousElementSibling)==null?void 0:L.localName)==="br")return $e(P.viewNode,P.whitespace)}return!1},E=function(P){var k,R,L;if(((k=P.viewNode)==null?void 0:k.nodeType)===1)return P.viewNode.localName==="br";if(((R=P.viewNode)==null?void 0:R.nodeType)===3){if(P.whitespace===lt.PRESERVE){if(/^\n/.test(P.viewNode.textContent))return!0}else if(P.whitespace===lt.NEWLINE&&/^[ \t\r\n\f]*\n/.test(P.viewNode.textContent))return!0;if(((L=P.viewNode.nextElementSibling)==null?void 0:L.localName)==="br")return $e(P.viewNode,P.whitespace)}return!1};var g=C,w=E;let A=Ql((s=(n=(i=y.lang)!=null?i:y.parent.lang)!=null?n:e?.lang)!=null?s:(r=e?.parent)==null?void 0:r.lang),H=Zl(y.inheritedProps["text-autospace"]),V=Kl(y.inheritedProps["text-spacing-trim"]),ie=jl(y.inheritedProps["hanging-punctuation"]);if(Xl(ie)&&Jl(H,V)||/\b(flex|grid)\b/.test(y.parent.display))continue;m<0&&(m=v);let ne=null,Xe=null,ht=v===m,xe=v===m&&h,x=v===m&&u,B=!1,S=!1;for(let P=v-1;P>=0;P--){let k=t[P];if(C(k)){x=!0;break}if(!k.display&&k.viewNode.nodeType===Node.TEXT_NODE&&k.viewNode.textContent.length>0){ne=k.viewNode;break}if(k.display&&!/^(inline|ruby)\b/.test(k.display)||((o=k.viewNode)==null?void 0:o.nodeType)===1&&(k.viewNode.localName==="br"||Ci[k.viewNode.localName]))break;P===0&&(ht=!0,h&&(xe=!0,x=!0))}for(let P=v+1;P<t.length;P++){let k=t[P];if(E(k)){B=!0;break}if(k.viewNode!==y.viewNode&&!k.display&&k.viewNode.nodeType===Node.TEXT_NODE&&k.viewNode.textContent.length>0){Xe=k.viewNode;break}if(k.display&&!/^(inline|ruby)\b/.test(k.display)||((a=k.viewNode)==null?void 0:a.nodeType)===1&&(k.viewNode.localName==="br"||Ci[k.viewNode.localName])){P===t.length-1&&d(k.viewNode)&&(S=!0);break}if(P===t.length-1){B=!0,S=!0;for(let R=k.viewNode.nextSibling;R;R=R.nextSibling)if(!d(R)){S=!1;break}}}if(((l=y.parent)==null?void 0:l.display)==="inline-block"){if(!xe){let P=y.parent.viewNode.firstChild;for(;$e(P,y.whitespace);)P=P.nextSibling;y.viewNode===P&&(xe=!0)}if(!S){let P=y.parent.viewNode.lastChild;for(;$e(P,y.whitespace);)P=P.previousSibling;y.viewNode===P&&(S=!0)}}if(this.processTextSpacing(y.viewNode,ht,xe,x,B,S,ne,Xe,H,V,ie,A,y.vertical)>0)break}}}processTextSpacing(e,t,i,n,r,s,o,a,l,h,u,d,p){let f=e.textContent,m=e.ownerDocument,g=0,w,v,y;function C(){if(t)return!0;if(!o)return!1;w||(w=m.createRange(),w.selectNode(e));let S=w.getClientRects()[0];if(!S)return!1;v||(v=m.createRange(),v.selectNode(o));let P=v.getClientRects(),k=P[P.length-1];return k?(g||(g=qn(k,p)),p?S.top<k.top+k.height-S.width||S.left+S.width<k.left+S.width/10||S.left>k.left+k.width-S.width/10:S.left<k.left+k.width-S.height||S.top>k.top+k.height-S.height/10||S.top+S.height<k.top+S.height/10):!1}function E(){if(!a)return!1;w||(w=m.createRange(),w.selectNode(e));let S=w.getClientRects()[0];if(!S)return!1;g||(g=qn(S,p)),y||(y=m.createRange(),y.selectNode(a));let P=y.getClientRects()[0];return P?p?S.top+S.height>P.top+S.width||S.left>P.left+P.width-S.width/10||S.left+S.width<P.left+S.width/10:S.left+S.width>P.left+S.height||S.top+S.height<P.top+S.height/10||S.top>P.top+P.height-S.height/10:!1}let A=!1,H=!1,V=!1,ie=!1,ne;if(i&&u.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(ne="viv-ts-open",A=!0,H=!0):s&&u.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(ne="viv-ts-close",A=!0,V=!0):(u.forceEnd||u.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(ne="viv-ts-close",A=!0,ie=!0):(h.trimStart||h.spaceFirst||h.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(ne="viv-ts-open",A=!0):(h.trimEnd||h.allowEnd||h.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||d==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||d!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(ne="viv-ts-close",A=!0),A){let S=function(D){let W=parseFloat(m.defaultView.getComputedStyle(D).fontSize)*.7;return(p?D.offsetHeight:D.offsetWidth)>W},P=function(){return p?k.offsetLeft:k.offsetTop};var Xe=S,ht=P;if(e.parentElement.localName==="viv-ts-inner")return 0;let k=m.createElement(ne),R=m.createElement("viv-ts-inner");k.appendChild(R),e.parentNode.insertBefore(k,e),R.appendChild(e);let L=S(R);if(L||H||V||ie){if(ne==="viv-ts-open"){if(H)k.className="viv-hang-first";else if(i||n)h.trimStart?k.className="viv-ts-trim":k.className="viv-ts-space";else if(!(h.trimStart||h.spaceFirst)&&C())k.className="viv-ts-space";else if(h.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"&&S(o.parentElement)))k.className="viv-ts-trim";else if((h.trimStart||h.spaceFirst)&&C()){let D=P();k.className="viv-ts-auto",D===P()&&!C()&&(k.className="viv-ts-trim")}}else if(ne==="viv-ts-close"){if(V)k.className=L?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(s||r){let D=P();ie?(k.className=L?u.allowEnd&&h.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",u.allowEnd&&D===P()&&(h.trimEnd?k.className="viv-ts-trim":h.allowEnd?(k.className="viv-hang-end",D===P()&&(k.className="")):k.className="viv-ts-space")):h.trimEnd?k.className="viv-ts-trim":h.allowEnd?(k.className="viv-ts-auto",D===P()&&(k.className="")):k.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))L&&h.trimAdjacent&&(k.className="viv-ts-trim");else if(ie){let D=E(),W=D&&u.allowEnd;W||(k.className=L?"viv-hang-end":"viv-hang-end viv-hang-hw"),L?W&&h.trimEnd?k.className="viv-ts-auto":!W&&!E()?k.className="":!D&&u.allowEnd&&(h.trimEnd?(k.className="viv-ts-auto",E()||(k.className="viv-hang-end")):(k.className="viv-ts-space",E()||(h.allowEnd?(k.className="viv-ts-auto",E()||(k.className="viv-hang-end")):k.className="viv-hang-end"))):!D&&!E()&&(k.className="")}else if(h.trimEnd||h.allowEnd)if(E())h.allowEnd?k.className="viv-ts-space":k.className="viv-ts-auto";else{let D=P();k.className="viv-ts-auto",D===P()&&(k.className="")}}}}let xe=!1;function x(S){var P;let k=(P=S?.ownerDocument.defaultView)==null?void 0:P.getComputedStyle(S);return!!k&&(k.textOrientation==="upright"||k.textCombineUpright==="all"||k["-webkit-text-combine"]==="horizontal")}function B(S,P){if(S.nodeType===1){let L=m.defaultView.getComputedStyle(S);if(parseFloat(L.marginInlineEnd)||parseFloat(L.borderInlineEndWidth)||parseFloat(L.paddingInlineEnd))return!0}let k=S.parentElement;if(k&&!k.contains(P))return B(k,P);if(P.nodeType===1){let L=m.defaultView.getComputedStyle(P);if(parseFloat(L.marginInlineStart)||parseFloat(L.borderInlineStartWidth)||parseFloat(L.paddingInlineStart))return!0}let R=P.parentElement;return R&&!R.contains(S)?B(S,R):!1}return(l.ideographAlpha||l.ideographNumeric)&&(o&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(l.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(o.textContent)||l.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(o.textContent))&&!(p&&x(o.parentElement))&&!B(o,e)&&(e.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),e),xe=!0),a&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(f)&&(l.ideographAlpha&&/^(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}/u.test(a.textContent)||l.ideographNumeric&&/^(?![\uFF01-\uFF60])\p{Nd}/u.test(a.textContent))&&!(p&&x(a.parentElement))&&!B(e,a)&&(e.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),e.nextSibling),xe=!0)),g}registerHooks(){Nt("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),Nt("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),Nt("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},Ma=new vw;Ma.registerHooks();function xw(e){Ma.preprocessForTextSpacing(e)}function Sw(e,t,i,n,r,s){Ma.processGeneratedContent(e,t,i,n,r,s)}var Ar=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),Cw=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],_a="data-adapt-pseudo";function Ji(e){return e.getAttribute(_a)||""}function Bo(e,t){e.setAttribute(_a,t)}var eh=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=Ji(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=kt(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 _(new Le(s),0)}return r}processContent(e,t,i){let n=Ji(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0,n==="marker"&&this.processMarker(e,t,i);let r=t.content;Dt(r)&&(r.visit(new ts(e.classList.contains("_viv-marker-outside")&&e.firstElementChild||e,this.context,r,this.exprContentListener)),xw(e))}}processMarker(e,t,i){let n=t.content,r=t["list-style-position"],s=t["list-style-type"];if(Dt(n)){if(n instanceof Qe)t.content=new J([n]);else if(n instanceof j&&s instanceof le){let o=s.name.toLowerCase();if((o==="disc"||o==="circle"||o==="square"||o==="disclosure-open"||o==="disclosure-closed")&&(e.classList.add("_viv-marker-bullet"),o==="disclosure-open"||o==="disclosure-closed")){let a=i.direction==="rtl",l=i.vertical;t.content=new j(o==="disclosure-open"?l?"\u25C2 ":"\u25BE ":l?a?"\u25B4 ":"\u25BE ":a?"\u25C2 ":"\u25B8 ")}}}if(r===b.outside){e.classList.add("_viv-marker-outside");let o=e.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","span");o.classList.add("_viv-marker-outside-content"),e.appendChild(o);let a=i.inheritedProps["text-spacing-trim"];a&&a!=="space-all"&&(t["text-spacing-trim"]=b.normal),i.inheritedProps["hanging-punctuation"]&&(t["hanging-punctuation"]=b.none)}delete t["list-style-position"],delete t["list-style-type"]}},G0=Jr.isInstanceOfAfterIfContinuesLayoutConstraint,kw=bs.registerFragmentIndex,j0=bs.clearFragmentIndices,Ew=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new za(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 T(s,"display","block"),N(s)})}createNodePositionForPseudoElement(){let e=Ar.createElementNS("http://www.w3.org/1999/xhtml","div");Bo(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 ui(i)}createShadowContext(e){return new go(this.sourceNode,e,null,null,null,Xt.ShadowType.ROOTED,this.styler)}},Nw=class Zc{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 Pw(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof Zc?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},Pw=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 Jc(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=Iw(e,t,n);return t.fragmentLayoutConstraints.push(new Nw(e,i,r)),N(e)})}function Qc(e,t){return e.thenAsync(i=>Jc(i,t))}function Tw(e,t){let i=O("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let r=Jc(n,t);return n=n.parent,r.thenReturn(!0)}else return N(!1)}).then(()=>{i.finish(!0)}),i.result()}function Iw(e,t,i){let n=e.viewNode;n.appendChild(i);let r=vo(i,t,e.vertical);return n.removeChild(i),r}var Aw=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},Rr=class extends Pa{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]}},rs=class ed extends fc{constructor(t,i,n,r,s){super(t),this.layoutContext=i,this.clientLayout=n,this.layoutConstraint=r,this.pageFloatLayoutContext=s,c(this,"last"),c(this,"viewDocument"),c(this,"flowRootFormattingContext",null),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,"breakAtTheEdgeBeforeFloat",null),new.target===ed&&dm(this),this.last=t.lastChild,this.viewDocument=t.ownerDocument,s.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(t){return!!t.floatSide&&(!this.isFloat||!!t.parent)}stopByOverflow(t){return this.stopAtOverflow&&!!t&&t.overflow}isOverflown(t){return this.vertical?t<this.footnoteEdge:t>this.footnoteEdge}getExclusions(){let t=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(t)}openAllViews(t){let i=O("openAllViews"),n=t.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let r=n.length-1,s=null;return i.loop(()=>{for(;r>=0;){let o=s,a=n[r];if(s=es(a,o),r===n.length-1&&!s.formattingContext&&(s.formattingContext=this.flowRootFormattingContext),r==0&&(s.offsetInNode=this.calculateOffsetInNodeForNodeContext(t),s.after=t.after,s.preprocessedTextContent=t.preprocessedTextContent,s.after))break;let l=this.layoutContext.setCurrent(s,r==0&&s.offsetInNode==0);if(r--,l.isPending())return l}return N(!1)}).then(()=>{i.finish(s)}),i.result()}calculateOffsetInNodeForNodeContext(t){return t.preprocessedTextContent?Vg(t.preprocessedTextContent,t.offsetInNode):t.offsetInNode}maybePeelOff(t,i){var n,r;if(t.firstPseudo&&t.inline&&!t.after&&t.firstPseudo.count==0&&t.viewNode.nodeType!=1){let s=t.viewNode.textContent,o=s.match(Xr),a=o?o[0].length:0;if(!o&&((n=t.sourceNode)==null?void 0:n.nodeType)===3&&((r=t.sourceNode.nextSibling)==null?void 0:r.nodeType)===3&&s===t.sourceNode.textContent){let l=s+t.sourceNode.nextSibling.textContent,h=l.match(Xr);if(h){let u=h[0];a=u.length,t.sourceNode.textContent=u,t.viewNode.textContent=u,t.sourceNode.nextSibling.textContent=l.substr(a)}}return this.layoutContext.peelOff(t,a)}return N(t)}buildViewToNextBlockEdge(t,i){let n=!1,r=O("buildViewToNextBlockEdge");return r.loopWithFrame(s=>{var o;if(t.viewNode&&!Ki(t)&&((o=t.viewNode.parentElement)==null?void 0:o.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(i.push(t.copy()),i.length>1e3)){let a=t.viewNode.nodeType===1?t.viewNode:t.viewNode.parentElement,l=this.clientLayout.getElementClientRect(a);if(qn(l,this.vertical)>=2){s.breakLoop();return}}this.maybePeelOff(t,0).then(a=>{let l=a;l!==t&&(t=l,Ki(t)||i.push(t.copy())),this.nextInTree(t).then(h=>{if(t=h,!t){s.breakLoop();return}(n||!this.layoutConstraint.allowLayout(t))&&(n=!0,t=t.modify(),t.overflow=!0),this.isFloatNodeContext(t)&&(tn(t.floatReference)||t.floatSide==="footnote")?this.layoutFloatOrFootnote(t).then(u=>{if(t=u,this.pageFloatLayoutContext.isInvalidated()&&(t=null),!t){s.breakLoop();return}s.continueLoop()}):t.inline?s.continueLoop():s.breakLoop()})})}).then(()=>{r.finish(t)}),r.result()}nextInTree(t,i){let n=this.layoutContext.nextInTree(t,i);return Qc(n,this)}buildDeepElementView(t){if(!t.viewNode)return N(t);let i=[],n=t.sourceNode,r=O("buildDeepElementView");return r.loopWithFrame(s=>{t.viewNode&&t.inline&&!Ki(t)?i.push(t.copy()):(i.length>0&&this.postLayoutBlock(t,i),i=[]),this.maybePeelOff(t,0).then(o=>{let a=o;if(a!==t){let l=a;for(;l&&l.sourceNode!=n;)l=l.parent;if(l==null){t=a,s.breakLoop();return}Ki(a)||i.push(a.copy())}this.nextInTree(a).then(l=>{t=l,!t||t.sourceNode==n?s.breakLoop():this.layoutConstraint.allowLayout(t)?s.continueLoop():(t=t.modify(),t.overflow=!0,this.stopAtOverflow?s.breakLoop():s.continueLoop())})})}).then(()=>{i.length>0&&this.postLayoutBlock(t,i),r.finish(t)}),r.result()}createFloat(t,i,n,r){let s=this.viewDocument.createElement("div");return this.vertical?(r>=this.height&&(r-=.1),r<1&&(r=0),T(s,"height",`${n}px`),T(s,"width",`${r}px`)):(n>=this.width&&(n-=.1),n<1&&(n=0),T(s,"width",`${n}px`),T(s,"height",`${r}px`)),T(s,"float",i),T(s,"clear",i),this.element.insertBefore(s,t),s}killFloats(){let t=this.element.firstChild;for(;t;){let i=t.nextSibling;if(t.nodeType==1){let n=t,r=n.style.cssFloat;if(r=="left"||r=="right"||r==="none")this.element.removeChild(n);else break}t=i}}createFloats(){let t=this.element.firstChild,i=this.bands,n=this.vertical?this.getTopEdge():this.getLeftEdge(),r=this.vertical?this.getBottomEdge():this.getRightEdge(),s=null;for(let o of i){let a=o.y2-o.y1;o.left=this.createFloat(t,"left",o.x1-n,a),o.right=this.createFloat(t,"right",r-o.x2,a),o.x1<r&&o.x2>n?s=o:s||T(o.right,"float","none")}if(s){let o=i[i.length-1],a=this.vertical?-this.getLeftEdge():this.getBottomEdge();s!==o&&o.y2>=a&&(this.footnoteEdge=this.vertical?-s.y2:s.y2)}}calculateEdge(t,i,n,r){let s;if(t&&qi(t.viewNode))return NaN;if(t&&t.after&&!t.inline&&(s=Wi(t,this.clientLayout,0,this.vertical),!isNaN(s)))return s;t=i[n];let o=r-t.boxOffset;for(;;){if(s=Wi(t,this.clientLayout,o,this.vertical),!isNaN(s))return s;if(o>0){o--;continue}if(n--,n<0)return this.beforeEdge;t=i[n],t.viewNode.nodeType!=1&&(o=t.viewNode.textContent.length)}}parseComputedLength(t){let i=t.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return i?this.clientLayout.adjustLengthValue(parseFloat(i[0])):0}getComputedMargin(t){let i=this.clientLayout.getElementComputedStyle(t),n=new Ls(0,0,0,0);return i&&(n.left=this.parseComputedLength(i.marginLeft),n.top=this.parseComputedLength(i.marginTop),n.right=this.parseComputedLength(i.marginRight),n.bottom=this.parseComputedLength(i.marginBottom)),n}getComputedPaddingBorder(t){let i=this.clientLayout.getElementComputedStyle(t),n=new Ls(0,0,0,0);return i&&(n.left=this.parseComputedLength(i.borderLeftWidth)+this.parseComputedLength(i.paddingLeft),n.top=this.parseComputedLength(i.borderTopWidth)+this.parseComputedLength(i.paddingTop),n.right=this.parseComputedLength(i.borderRightWidth)+this.parseComputedLength(i.paddingRight),n.bottom=this.parseComputedLength(i.borderBottomWidth)+this.parseComputedLength(i.paddingBottom)),n}getComputedInsets(t){let i=this.clientLayout.getElementComputedStyle(t),n=new Ls(0,0,0,0);if(i){if(i.boxSizing=="border-box")return this.getComputedMargin(t);n.left=this.parseComputedLength(i.marginLeft)+this.parseComputedLength(i.borderLeftWidth)+this.parseComputedLength(i.paddingLeft),n.top=this.parseComputedLength(i.marginTop)+this.parseComputedLength(i.borderTopWidth)+this.parseComputedLength(i.paddingTop),n.right=this.parseComputedLength(i.marginRight)+this.parseComputedLength(i.borderRightWidth)+this.parseComputedLength(i.paddingRight),n.bottom=this.parseComputedLength(i.marginBottom)+this.parseComputedLength(i.borderBottomWidth)+this.parseComputedLength(i.paddingBottom)}return n}setComputedInsets(t,i){let n=this.clientLayout.getElementComputedStyle(t);n&&(i.marginLeft=this.parseComputedLength(n.marginLeft),i.borderLeft=this.parseComputedLength(n.borderLeftWidth),i.paddingLeft=this.parseComputedLength(n.paddingLeft),i.marginTop=this.parseComputedLength(n.marginTop),i.borderTop=this.parseComputedLength(n.borderTopWidth),i.paddingTop=this.parseComputedLength(n.paddingTop),i.marginRight=this.parseComputedLength(n.marginRight),i.borderRight=this.parseComputedLength(n.borderRightWidth),i.paddingRight=this.parseComputedLength(n.paddingRight),i.marginBottom=this.parseComputedLength(n.marginBottom),i.borderBottom=this.parseComputedLength(n.borderBottomWidth),i.paddingBottom=this.parseComputedLength(n.paddingBottom))}setComputedWidthAndHeight(t,i){let n=this.clientLayout.getElementComputedStyle(t);n&&(i.width=this.parseComputedLength(n.width),i.height=this.parseComputedLength(n.height))}layoutUnbreakable(t){return this.buildDeepElementView(t)}layoutFloat(t){let i=O("layoutFloat"),n=t.viewNode,r=Bl(t.floatSide,t.vertical,t.direction,this.layoutContext.page.side);return T(n,"float","none"),T(n,"display","inline-block"),T(n,"vertical-align","top"),this.buildDeepElementView(t).then(s=>{let o=It(this.clientLayout,n,this.vertical),a=this.getComputedMargin(n),l=new bt(o.left-a.left,o.top-a.top,o.right+a.right,o.bottom+a.bottom),h=this.rtl?this.endEdge:this.startEdge,u=this.rtl?this.startEdge:this.endEdge,d=t.parent;for(;d&&d.inline;)d=d.parent;if(d){let E=d.viewNode.ownerDocument.createElement("div");E.style.left="0px",E.style.top="0px",this.vertical?(E.style.bottom="0px",E.style.width="1px"):(E.style.right="0px",E.style.height="1px"),d.viewNode.appendChild(E);let A=It(this.clientLayout,E,this.vertical);h=Math.max(this.rtl?this.getEndEdge(A):this.getStartEdge(A),h),u=Math.min(this.rtl?this.getStartEdge(A):this.getEndEdge(A),u),d.viewNode.removeChild(E);let H=this.vertical?l.y2-l.y1:l.x2-l.x1;r=="left"?u=Math.max(u,h+H):h=Math.min(h,u-H),d!==t.parent&&!t.firstPseudo&&(d.viewNode.appendChild(n),n.setAttribute("data-vivliostyle-float-box-moved","true"))}let p=new bt(h,this.getBoxDir()*this.beforeEdge,u,this.getBoxDir()*this.afterEdge),f=l;this.vertical&&(f=Yr(l));let m=this.getBoxDir();if(f.y1<this.bottommostFloatTop*m){let E=f.y2-f.y1;f.y1=this.bottommostFloatTop*m,f.y2=f.y1+E}Tf(p,this.bands,f,r),this.vertical&&(l=Iu(f));let g=this.getComputedInsets(n);T(n,"width",`${l.x2-l.x1-g.left-g.right}px`),T(n,"height",`${l.y2-l.y1-g.top-g.bottom}px`),T(n,"position","absolute"),t.display,T(n,"display",t.display);let w,v=null;if(d&&(d.containingBlockForAbsolute?v=d:v=d.getContainingBlockForAbsolute()),v){let E=v.viewNode.ownerDocument.createElement("div");E.style.position="absolute",v.vertical?E.style.right="0":E.style.left="0",E.style.top="0",v.viewNode.appendChild(E),w=It(this.clientLayout,E,this.vertical),v.viewNode.removeChild(E)}else w={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};(v?v.vertical:this.vertical)?T(n,"right",`${w.right-l.x2}px`):T(n,"left",`${l.x1-w.left}px`),T(n,"top",`${l.y1-w.top}px`),t.clearSpacer&&(t.clearSpacer.parentNode.removeChild(t.clearSpacer),t.clearSpacer=null);let y=this.vertical?l.x1:l.y2,C=this.vertical?l.x2:l.y1;!this.isOverflown(y)||this.breakPositions.length==0?(this.killFloats(),p=new bt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(p=Yr(p)),If(p,this.bands,f,null,r),this.createFloats(),r=="left"?this.leftFloatEdge=y:this.rightFloatEdge=y,this.bottommostFloatTop=C,this.updateMaxReachedAfterEdge(y),i.finish(s)):(t=t.modify(),t.overflow=!0,i.finish(t))}),i.result()}setupFloatArea(t,i,n,r,s,o){let a=this.pageFloatLayoutContext,l=a.getContainer(i),h=t.element;l.element.parentNode.appendChild(h),t.isFloat=!0,t.originX=l.originX,t.originY=l.originY,t.vertical=l.vertical,t.rtl=l.rtl,t.marginLeft=t.marginRight=t.marginTop=t.marginBottom=0,t.borderLeft=t.borderRight=t.borderTop=t.borderBottom=0,t.paddingLeft=t.paddingRight=t.paddingTop=t.paddingBottom=0,t.exclusions=(l.exclusions||[]).concat(),t.forceNonfitting=!a.hasFloatFragments(),t.innerShape=null;let u=l.getPaddingRect();t.setHorizontalPosition(u.x1-l.originX,u.x2-u.x1),t.setVerticalPosition(u.y1-l.originY,u.y2-u.y1),s.adjustPageFloatArea(t,l,this),t.init();let d=!!a.setFloatAreaDimensions(t,i,n,r,!0,!a.hasFloatFragments(),o);return d?(t.killFloats(),t.init()):l.element.parentNode.removeChild(h),d}createPageFloatArea(t,i,n,r,s){let o=this.element.ownerDocument.createElement("div");T(o,"position","absolute");let a=this.pageFloatLayoutContext.getPageFloatLayoutContext(t.floatReference),l=new Tn(null,Oe.COLUMN,null,this.pageFloatLayoutContext.flowName,t.nodePosition,null,null),h=a.getContainer(),u=new Lw(i,o,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,l,h);return l.setContainer(u),this.setupFloatArea(u,t.floatReference,i,n,r,s)?u:null}layoutSinglePageFloatFragment(t,i,n,r,s,o,a){let l=this.pageFloatLayoutContext;t=(a?a.continuations:[]).concat(t);let h=t[0].float,u=l.getPageFloatPlacementCondition(h,i,n),d=this.createPageFloatArea(h,i,o,s,u),p={floatArea:d,pageFloatFragment:null,newPosition:null};if(!d)return N(p);let f=O("layoutSinglePageFloatFragment"),m=!1,g=0;return f.loopWithFrame(w=>{if(g>=t.length){w.breakLoop();return}let v=t[g],y=new ui(v.nodePosition);d.layout(y,!0).then(C=>{p.newPosition=C,!C||r?(g++,w.continueLoop()):(m=!0,w.breakLoop())})}).then(()=>{if(!m){let w=l.setFloatAreaDimensions(d,h.floatReference,i,o,!1,r,u);if(!w)m=!0;else{let v=s.createPageFloatFragment(t,w,n,d,!!p.newPosition);l.addPageFloatFragment(v,!0),p.pageFloatFragment=v}}f.finish(p)}),f.result()}layoutPageFloatInner(t,i,n,r){let s=this.pageFloatLayoutContext,o=t.float;s.stashEndFloatFragments(o);function a(h,u){u?s.removePageFloatFragment(u,!0):h&&h.element.parentNode.removeChild(h.element),s.restoreStashedFragments(o.floatReference),s.deferPageFloat(t)}let l=O("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([t],o.floatSide,o.clearSide,!s.hasFloatFragments(),i,n,r).then(h=>{let u=h.floatArea,d=h.pageFloatFragment,p=h.newPosition;d?this.layoutStashedPageFloats(o.floatReference,[r]).then(f=>{if(f){if(s.addPageFloatFragment(d),s.discardStashedFragments(o.floatReference),p){let m=new Ml(o,p.primary);s.deferPageFloat(m)}l.finish(!0)}else a(u,d),l.finish(!1)}):(a(u,d),l.finish(!1))}),l.result()}layoutStashedPageFloats(t,i){let n=this.pageFloatLayoutContext,r=n.getStashedFloatFragments(t),s=[],o=[],a=!1,l=O("layoutStashedPageFloats"),h=0;return l.loopWithFrame(u=>{if(h>=r.length){u.breakLoop();return}let d=r[h];if(i.includes(d)){h++,u.continueLoop();return}let p=new ln().findByFloat(d.continuations[0].float);this.layoutSinglePageFloatFragment(d.continuations,d.floatSide,d.clearSide,!1,p,null).then(f=>{let m=f.floatArea;m&&s.push(m);let g=f.pageFloatFragment;g?(o.push(g),h++,u.continueLoop()):(a=!0,u.breakLoop())})}).then(()=>{a?(o.forEach(u=>{n.removePageFloatFragment(u,!0)}),s.forEach(u=>{let d=u.element;d&&d.parentNode&&d.parentNode.removeChild(d)})):r.forEach(u=>{let d=u.area.element;d&&d.parentNode&&d.parentNode.removeChild(d)}),l.finish(!a)}),l.result()}setFloatAnchorViewNode(t){let i=t.viewNode.parentNode,n=i.ownerDocument.createElement("span");n.setAttribute(hn,"1"),t.floatSide==="footnote"&&this.layoutContext.applyPseudoelementStyle(t,"footnote-call",n),i.appendChild(n),i.removeChild(t.viewNode);let r=t.modify();return r.after=!0,r.viewNode=n,r}resolveFloatReferenceFromColumnSpan(t,i,n){let r=O("resolveFloatReferenceFromColumnSpan"),s=this.pageFloatLayoutContext,o=s.getPageFloatLayoutContext(Oe.REGION);return s.getContainer().width<o.getContainer().width&&t===Oe.COLUMN?i===b.auto?this.buildDeepElementView(n.copy()).then(a=>{let l=a.viewNode,h=va(this.clientLayout,l,["min-content inline size"])["min-content inline size"],u=this.getComputedMargin(l);this.vertical?h+=u.top+u.bottom:h+=u.left+u.right,h>this.width?r.finish(Oe.REGION):r.finish(t)}):i===b.all?r.finish(Oe.REGION):r.finish(t):r.finish(t),r.result()}layoutPageFloat(t){let i=this.pageFloatLayoutContext,n=new ln().findByNodeContext(t),r,s=i.findPageFloatByNodePosition(t.toNodePosition());return s?r=N(s):r=n.createPageFloat(t,i,this),r.thenAsync(o=>{let a=Qr(t,0),l=this.setFloatAnchorViewNode(t),h=n.findPageFloatFragment(o,i),u=new Ml(o,a);if(h&&h.hasFloat(o))return i.registerPageFloatAnchor(o,l.viewNode),N(l);if(i.isForbidden(o)||i.hasPrecedingFloatsDeferredToNext(o))return i.deferPageFloat(u),i.registerPageFloatAnchor(o,l.viewNode),N(l);if(this.nodeContextOverflowingDueToRepetitiveElements)return N(null);{let d=Wi(l,this.clientLayout,0,this.vertical);return this.isOverflown(d)?N(l):this.layoutPageFloatInner(u,n,d,h).thenAsync(p=>p?N(null):(i.registerPageFloatAnchor(o,l.viewNode),N(l)))}})}processLineStyling(t,i,n){let r=O("processLineStyling"),s=n.concat([]);n.splice(0,n.length);let o=0,a=t.firstPseudo;return a.count==0&&(a=a.outer),r.loopWithFrame(l=>{if(!a){l.breakLoop();return}let h=this.findLinePositions(s),u=a.count-o;if(h.length<=u){l.breakLoop();return}let d=this.findAcceptableBreakInside(s,h[u-1],!0);if(d==null){l.breakLoop();return}this.finishBreak(d,!1,!1).then(()=>{o+=u,this.layoutContext.peelOff(d,0).then(p=>{t=p,a=t.firstPseudo,s=[],this.buildViewToNextBlockEdge(t,s).then(f=>{i=f,l.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(n,s),r.finish(i)}),r.result()}isLoneImage(t){return t.length!=2&&this.breakPositions.length>0?!1:t[0].sourceNode==t[1].sourceNode&&Ci[t[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(t){let i=0,n=0;for(let r=t.length-1;r>=0;r--){let s=t[r];if(!s.after||!s.viewNode||s.viewNode.nodeType!=1)break;let o=this.getComputedMargin(s.viewNode),a=this.vertical?-o.left:o.bottom;a>0?i=Math.max(i,a):n=Math.min(n,a)}return i+n}layoutBreakableBlock(t){let i=O("layoutBreakableBlock"),n=[];return this.buildViewToNextBlockEdge(t,n).then(r=>{let s=n.length-1;if(s<0){i.finish(r);return}this.postLayoutBlock(r,n);let o=this.calculateEdge(r,n,s,n[s].boxOffset),a=!1;if(!r||!qi(r.viewNode)){let h=nn(r,this.collectElementsOffset());a=this.isOverflown(o+(this.vertical?-1:1)*h.minimum),this.isOverflown(o+(this.vertical?-1:1)*h.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=r)}r==null&&(o+=this.getTrailingMarginEdgeAdjustment(n)),this.updateMaxReachedAfterEdge(o);let l;t.firstPseudo?l=this.processLineStyling(t,r,n):l=N(r),l.then(h=>{n.length>0&&(this.saveBoxBreakPosition(n),a&&!this.isLoneImage(n)&&h&&(h=h.modify(),h.overflow=!0)),i.finish(h)})}),i.result()}postLayoutBlock(t,i){Rt("POST_LAYOUT_BLOCK").forEach(n=>{n(t,i,this)})}findEndOfLine(t,i,n){let r=this.vertical?t-1:t+1,s=0,o=i[0].boxOffset,a=s,l=i.length-1,h=i[l].boxOffset,u;for(;o<h;){u=o+Math.ceil((h-o)/2),a=s;let d=l;for(;a<d;){let f=a+Math.ceil((d-a)/2);i[f].boxOffset>u?d=f-1:a=f}let p=this.calculateEdge(null,i,a,u);if(this.vertical?p<=r:p>=r){for(h=u-1;i[a].boxOffset==u;)a--;l=a}else n&&this.updateMaxReachedAfterEdge(p),o=u,s=a}return{nodeContext:i[a],index:o,checkPointIndex:a}}findAcceptableBreakInside(t,i,n){var r,s,o;let a=this.findEndOfLine(i,t,!0),l=a.nodeContext;if(a.checkPointIndex===0&&a.index===l.boxOffset)return null;let h=l.viewNode;if(h.nodeType!=1&&((r=h.parentElement)==null?void 0:r.localName)!=="viv-ts-inner"){let u=h;l=this.resolveTextNodeBreaker(l).breakTextNode(u,l,a.index,t,a.checkPointIndex,n)}else{let u=Vl(l);if(u){if(((s=this.breakPositions)==null?void 0:s[0])instanceof Rr&&u!=null&&u.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(l=u;!l.after&&l.inline&&l.parent;){let d=(o=l.viewNode)==null?void 0:o.previousSibling;for(;d&&($e(d,l.parent.whitespace)||Yi(d));)d=d.previousSibling;if(d)break;l=l.parent}}}return this.clearOverflownViewNodes(l,!1),l}resolveTextNodeBreaker(t){return Rt("RESOLVE_TEXT_NODE_BREAKER").reduce((i,n)=>n(t)||i,ss.instance)}getRangeBoxes(t,i){let n=[],r=t.ownerDocument.createRange(),s=!1,o=t,a=null,l=!1,h=!0;for(;h;){let u=!0;do{let d=null;o==i&&(i.nodeType===1?h=!(!i.firstChild||s):h=!1);let p=o.nodeType===1?o:null;p?s?s=!1:Na(p)?u=!l:!p.firstChild||Ci[p.localName]||/^r(uby|[bt]c?)$/.test(p.localName)||gm(this.clientLayout.getElementComputedStyle(p).display)?(u=!l,u?(p.localName==="ruby"&&o.firstChild&&(o=o.firstChild),r.setStartBefore(o),l=!0,a=o):/^r(uby|tc?)$/.test(p.localName)||(a=o),o.contains(i)&&(h=!1)):d=o.firstChild:(l||(o.parentNode==null?h=!1:(r.setStartBefore(o),l=!0)),a=o),d||(d=o.nextSibling,d||(s=!0,d=o.parentNode)),o=d}while(u&&h);if(l){r.setEndAfter(a);let d=this.clientLayout.getRangeClientRects(r);Sc(d,this.vertical);for(let p=0;p<d.length;p++)n.push(d[p]);l=!1}}return n}findLinePositions(t){let i=[],n=this.getRangeBoxes(t[0].viewNode,t[t.length-1].viewNode);n.sort(this.vertical?Yg:qg);let r=0,s=0,o=0,a=0,l=0,h=this.getBoxDir();for(;;){if(l<n.length){let u=n[l],d=1;if(a>0){let p=Math.max(this.getBoxSize(u),1);h*this.getBeforeEdge(u)<h*r?d=h*(this.getAfterEdge(u)-r)/p:h*this.getAfterEdge(u)>h*s?d=h*(s-this.getBeforeEdge(u))/p:d=1}if(a==0||d>=.6||d>=.2&&this.getStartEdge(u)>=o-1){o=this.getEndEdge(u),this.vertical?(r=a==0?u.right:Math.max(r,u.right),s=a==0?u.left:Math.min(s,u.left)):(r=a==0?u.top:Math.min(r,u.top),s=a==0?u.bottom:Math.max(s,u.bottom)),a++,l++;continue}}if(a>0&&(i.push(s),a=0),l>=n.length)break}return i.sort(Yh),this.vertical&&i.reverse(),i}calculateClonedPaddingBorder(t){let i=0;for(let n=t;n;n=n.parent)if(!n.inline&&En(n.viewNode)){let r=this.getComputedPaddingBorder(n.viewNode);i+=n.vertical?-r.left:r.bottom,n.display==="table"&&(i+=(n.vertical?-1:1)*n.blockBorderSpacing)}return i}getOffsetByRepetitiveElements(t){let i;return t?i=t.calculateOffset(this):i=nn(null,this.collectElementsOffset()),i.current}findBoxBreakPosition(t,i){let n=this.element.parentNode,r=this.element.nextSibling;n.removeChild(this.element),n.insertBefore(this.element,r);let s=t.checkPoints,o=s[0];for(;o.parent&&o.inline;)o=o.parent;let a,l;i?(a=1,l=1):(a=Math.max((o.inheritedProps.widows||2)-0,1),l=Math.max((o.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(o),u=this.findLinePositions(s),d=this.footnoteEdge-h,p=this.getBoxDir(),f=this.getOffsetByRepetitiveElements(t);d-=p*f;let m=this.findFirstOverflowingEdgeAndCheckPoint(s);isNaN(m.edge)&&(m.edge=p*(1/0));let g=ai(u.length,C=>{let E=u[C];return this.vertical?E<d||E<=m.edge:E>d||E>=m.edge}),w=g<=0;w&&(g=ai(u.length,C=>this.vertical?u[C]<d:u[C]>d));let v=s[s.length-1].viewNode;if(v?.parentElement.localName==="viv-ts-inner"&&(v=v.parentElement.parentElement),(g===u.length&&v.nextSibling||g>=u.length-1&&v.parentElement.querySelector(".MJXc-display"))&&(a=0),g=Math.min(u.length-a,g),g<l)return null;d=u[g-1];let y;if(w?y=m.checkPoint:y=this.findAcceptableBreakInside(t.checkPoints,d,i),y){let C=this.getAfterEdgeOfBlockContainer(y);!isNaN(C)&&p*(d-C)>0&&(d=C),this.computedBlockSize=p*(d-this.beforeEdge)+f}return y}getAfterEdgeOfBlockContainer(t){let i=t;do i=i.parent;while(i&&i.inline);return i?(i=i.copy().modify(),i.after=!0,Wi(i,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(t){let i=t.findIndex(r=>r.overflow);if(i<0)return{edge:NaN,checkPoint:null};let n=t[i];return{edge:this.calculateEdge(null,t,i,n.boxOffset),checkPoint:n}}findEdgeBreakPosition(t){return this.computedBlockSize=t.computedBlockSize+this.getOffsetByRepetitiveElements(t),t.position}finishBreak(t,i,n){t.formattingContext;let r=new vn().find(t.formattingContext).finishBreak(this,t,i,n);return r||(r=Ia.finishBreak(this,t,i,n)),r}findAcceptableBreakPosition(){let t=null,i=null,n=0,r=0;do{n=r,r=Number.MAX_VALUE;for(let s=this.breakPositions.length-1;s>=0&&!i;--s){t=this.breakPositions[s],i=t.findAcceptableBreak(this,n);let o=t.getMinBreakPenalty();o>n&&(r=Math.min(r,o))}}while(r>n&&!i&&this.forceNonfitting);return{breakPosition:i?t:null,nodeContext:i}}doFinishBreak(t,i,n,r){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!i)return N(t);let s=O("doFinishBreak"),o=!1;if(!t){if(this.forceNonfitting)return $.warn("Could not find any page breaks?!!"),this.skipTailEdges(i).then(a=>{a?(a=a.modify(),a.overflow=!1,this.finishBreak(a,o,!0).then(()=>{s.finish(a)})):s.finish(a)}),s.result();t=n,o=!0,this.computedBlockSize=r}return this.finishBreak(t,o,!0).then(()=>{s.finish(t)}),s.result()}isBreakable(t){for(let i=t;i;i=i.parent)if(Yi(i.viewNode))return!1;if(t.after)return!0;switch(t.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!t.flexContainer}zeroIndent(t){let i=t.toString();return i==""||i=="auto"||!!i.match(/^0+(.0*)?[^0-9]/)}checkOverflowAndSaveEdge(t,i){if(!t)return!1;for(let o=t;o;o=o.parent)if(Yi(o.viewNode))return!1;if(qi(t.viewNode))return!1;let n=Wi(t,this.clientLayout,0,this.vertical),r=nn(t,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=t;else if(i){let o=n+this.getTrailingMarginEdgeAdjustment(i),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(t,i,n,r){if(!t||qi(t.viewNode))return!1;let s=this.checkOverflowAndSaveEdge(t,i);return(n||!s)&&this.saveEdgeBreakPosition(t,r,s),s}applyClearance(t){if(!t.viewNode.parentNode||t.floatReference!==Oe.INLINE)return!1;let i=this.getComputedMargin(t.viewNode),n=t.viewNode.ownerDocument.createElement("div");this.vertical?(n.style.bottom="0px",n.style.width="1px",n.style.marginRight=`${i.right}px`):(n.style.right="0px",n.style.height="1px",n.style.marginTop=`${i.top}px`),t.viewNode.parentNode.insertBefore(n,t.viewNode);let r=It(this.clientLayout,n,this.vertical),s=this.getBeforeEdge(r),o=this.getBoxDir(),a=t.clearSide==="same"?t.floatSide:t.clearSide,l=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(a)?Bl(a,t.vertical,t.direction,this.layoutContext.page.side):a,h=l==="left"||l==="right"?t.direction==="rtl"==(l==="left")?"inline-end":"inline-start":l,u=this.pageFloatLayoutContext.getPageFloatClearEdge(h,this);switch(l){case"left":u=o*Math.max(u*o,this.leftFloatEdge*o);break;case"right":u=o*Math.max(u*o,this.rightFloatEdge*o);break;default:u=o*Math.max(u*o,Math.max(this.rightFloatEdge*o,this.leftFloatEdge*o))}let d=1/(this.clientLayout.pixelRatio||1);if(s*o+d>u*o)return t.viewNode.parentNode.removeChild(n),!1;{let p=Math.max(1,(u-s)*o);this.vertical?n.style.width=`${p}px`:n.style.height=`${p}px`,r=It(this.clientLayout,n,this.vertical);let f=this.getAfterEdge(r);if(!t.floatSide)if(this.vertical){let m=f-i.right-u;m>0==i.right>=0&&(m+=i.right),n.style.marginLeft=`${m}px`}else{let m=u-(f+i.top);m>0==i.top>=0&&(m+=i.top),n.style.marginBottom=`${m}px`}return t.clearSpacer=n,!0}}isBFC(t){return!!(mm(t)||Ni.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))}skipEdges(t,i,n){var r;let s=t.after?(r=t.parent)==null?void 0:r.formattingContext:t.formattingContext;if(s&&!this.isBFC(s))return N(t);let o=O("skipEdges"),a=!n&&i&&t&&t.after,l=n,h=null,u=[],d=[],p=!1;function f(){return!!n||!i&&it(l)&&!m()}function m(){var w;if(!h||t.floatSide)return!1;for(let v=h;v!=null&&v.parent;v=v.parent){let y=v.after?v.viewNode:(w=v.viewNode)==null?void 0:w.previousSibling;for(;y&&($e(y,v.parent.whitespace)||Yi(y));)y=y.previousSibling;if(y)return!1}return!0}let g=()=>{t=u[0]||t,t.viewNode.parentNode.removeChild(t.viewNode),this.pageBreakType=l};return o.loopWithFrame(w=>{for(var v;t;){t.formattingContext;let y=new vn().find(t.formattingContext);do{if(!t.viewNode)break;if(t.inline&&t.viewNode.nodeType!=1){if($e(t.viewNode,t.whitespace))break;if(!t.after){f()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,l)?(t=(this.stopAtOverflow&&h||t).modify(),t.overflow=!0):(t=t.modify(),t.breakBefore=l),w.breakLoop();return}}if(!t.after){if(t.floatSide&&(this.breakAtTheEdgeBeforeFloat=Zr(l)?l:null),y&&y.startNonInlineElementNode(t))break;if(t.clearSide&&this.applyClearance(t)&&i&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(t.copy(),l,!1),!t.inline&&!t.repeatOnBreak&&(h?Vl(h):this.breakPositions[this.breakPositions.length-1]instanceof Rr)&&this.saveEdgeBreakPosition(t.copy(),l,!1),!this.isBFC(t.formattingContext)||Ni.isInstanceOfRepetitiveElementsOwnerFormattingContext(t.formattingContext)||this.isFloatNodeContext(t)||t.flexContainer||!t.nodeShadow&&!t.sourceNode.firstElementChild&&$e(t.sourceNode.firstChild,t.whitespace)){u.push(t.copy()),l=rt(l,t.breakBefore),f()?g():(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,l)||!this.layoutConstraint.allowLayout(t))&&(t=(this.stopAtOverflow&&h||t).modify(),t.overflow=!0),w.breakLoop();return}}if(t.viewNode.nodeType!=1)break;let E=t.viewNode.style;if(t.after){t.floatSide&&(l=l??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let A=t.sourceNode;if(A.localName==="svg"||A.localName==="math"||A.getAttribute("data-math-typeset")==="true"){p=!1,h=t.copy(),d.push(h),l=rt(null,t.breakAfter),this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,l);break}if(t.inline||y&&y.afterNonInlineElementNode(t,this.stopAtOverflow))break;if(p){if(f()){g(),w.breakLoop();return}u=[],i=!1,a=!1,l=null}p=!1,h=t.copy(),d.push(h),l=rt(l,t.breakAfter),E&&!(this.zeroIndent(E.paddingBottom)&&this.zeroIndent(E.borderBottomWidth))&&(d=[h])}else{if(u.push(t.copy()),l=rt(l,t.breakBefore),h&&it(l)&&pm(h.viewNode,t.viewNode),(t.pageType!=((v=t.parent)==null?void 0:v.pageType)||!it(l))&&!this.layoutConstraint.allowLayout(t)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,l),t=t.modify(),t.overflow=!0,this.stopAtOverflow)){w.breakLoop();return}let A=t.viewNode.localName;if(Ci[A]){f()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,l)&&(t=(this.stopAtOverflow&&h||t).modify(),t.overflow=!0),w.breakLoop();return}E&&!(this.zeroIndent(E.paddingTop)&&this.zeroIndent(E.borderTopWidth))&&(a=!1,d=[]),p=!0}}while(!1);let C=this.nextInTree(t,a);if(C.isPending()){C.then(E=>{t=E,w.continueLoop()});return}else t=C.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(h,d,!this.stopAtOverflow,l)?h&&this.stopAtOverflow&&(t=h.modify(),t.overflow=!0):it(l)&&(this.pageBreakType=l),w.breakLoop()}).then(()=>{h&&(this.lastAfterPosition=h.toNodePosition()),o.finish(t)}),o.result()}skipTailEdges(t){let i=t.copy(),n=O("skipEdges"),r=null,s=!1;return n.loopWithFrame(o=>{for(;t;){do{if(!t.viewNode)break;if(t.inline&&t.viewNode.nodeType!=1){if($e(t.viewNode,t.whitespace))break;if(!t.after){it(r)&&(this.pageBreakType=r),o.breakLoop();return}}if(!t.after&&(this.isFloatNodeContext(t)||t.flexContainer)){r=rt(r,t.breakBefore),it(r)&&(this.pageBreakType=r),o.breakLoop();return}if(t.viewNode.nodeType!=1)break;let l=t.viewNode.style;if(t.after){if(s){if(it(r)){this.pageBreakType=r,o.breakLoop();return}r=null}s=!1,r=rt(r,t.breakAfter)}else{r=rt(r,t.breakBefore);let h=t.viewNode.localName;if(Ci[h]){it(r)&&(this.pageBreakType=r),o.breakLoop();return}if(l&&!(this.zeroIndent(l.paddingTop)&&this.zeroIndent(l.borderTopWidth))){o.breakLoop();return}}s=!0}while(!1);let a=this.layoutContext.nextInTree(t);if(a.isPending()){a.then(l=>{t=l,o.continueLoop()});return}else t=a.get()}i=null,o.breakLoop()}).then(()=>{n.finish(i)}),n.result()}layoutFloatOrFootnote(t){return tn(t.floatReference)||t.floatSide==="footnote"?this.layoutPageFloat(t):this.layoutFloat(t)}layoutNext(t,i,n){let r=O("layoutNext");return this.skipEdges(t,i,n||null).then(s=>{if(t=s,!t||this.pageBreakType||this.stopByOverflow(t))r.finish(t);else{let o=t.formattingContext;new vn().find(o).layout(t,this,i).thenFinish(r)}}),r.result()}clearOverflownViewNodes(t,i){if(t)for(let n=t.parent;t;t=n,n=n?n.parent:null){let r=(n||t).formattingContext;new vn().find(r).clearOverflownViewNodes(this,n,t,i),i=!1}}initGeom(){let t=this.element.ownerDocument.createElement("div");t.style.position="absolute",t.style.top=`${this.paddingTop}px`,t.style.right=`${this.paddingRight}px`,t.style.bottom=`${this.paddingBottom}px`,t.style.left=`${this.paddingLeft}px`,this.element.appendChild(t);let i=this.clientLayout.getElementClientRect(t);this.element.removeChild(t);let n=this.originX+this.left+this.getInsetLeft(),r=this.originY+this.top+this.getInsetTop();this.box=new bt(n,r,n+this.width,r+this.height),this.startEdge=i?this.vertical?this.rtl?i.bottom:i.top:this.rtl?i.right:i.left:0,this.endEdge=i?this.vertical?this.rtl?i.top:i.bottom:this.rtl?i.left:i.right:0,this.beforeEdge=i?this.vertical?i.right:i.top:0,this.afterEdge=i?this.vertical?i.left:i.bottom:0,this.leftFloatEdge=this.beforeEdge,this.rightFloatEdge=this.beforeEdge,this.bottommostFloatTop=this.beforeEdge,this.footnoteEdge=this.afterEdge,this.bands=Ef(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],T(this.element,"width",`${this.width}px`),T(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null}saveEdgeBreakPosition(t,i,n){t.formattingContext;let r=t.copy(),s=new vn().find(t.formattingContext),o=this.calculateClonedPaddingBorder(r),a=s.createEdgeBreakPosition(r,i,n,this.computedBlockSize+o);this.breakPositions.push(a)}saveBoxBreakPosition(t){let i=t[0].breakPenalty;if(i){let r=t[0];for(;r.parent&&r.inline;)r=r.parent;i=r.breakPenalty}let n=new Rr(t,i);this.breakPositions.push(n)}updateMaxReachedAfterEdge(t){if(!isNaN(t)){let i=this.getBoxDir()*(t-this.beforeEdge);this.computedBlockSize=Math.max(i,this.computedBlockSize)}}layout(t,i,n){if(this.chunkPositions.push(t),t.primary.after&&(this.lastAfterPosition=t.primary),this.stopAtOverflow&&this.overflown)return N(t);if(this.isFullWithPageFloats())return t.primary.after&&t.primary.steps.length===1?N(null):N(t);Dl(this)&&Ca(this);let r=O("layout");return this.openAllViews(t.primary).then(s=>{let o=null;if(s.viewNode)o=s.copy();else{let l=h=>{h.nodeContext.viewNode&&(o=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",l))};this.layoutContext.addEventListener("nextInTree",l)}let a=new Rw(i,n);a.layout(s,this).then(l=>{if(Dl(this)){let h=this.element.lastElementChild&&this.clientLayout.getElementClientRect(this.element.lastElementChild);h&&qn(h,this.vertical)&&ka(this)}this.doFinishBreak(l,a.context.overflownNodeContext,o,a.initialComputedBlockSize).then(h=>{let u=null;this.pseudoParent?u=N(null):u=this.doFinishBreakOfFragmentLayoutConstraints(h),u.then(()=>{if(this.pageFloatLayoutContext.isInvalidated()){r.finish(null);return}if(!h)r.finish(null);else{this.overflown=!0;let d=new ui(h.toNodePosition());r.finish(d)}})})})}),r.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(t){let i=O("doFinishBreakOfFragmentLayoutConstraints"),n=[].concat(this.fragmentLayoutConstraints);n.sort((s,o)=>s.getPriorityOfFinishBreak()-o.getPriorityOfFinishBreak());let r=0;return i.loop(()=>r<n.length?n[r++].finishBreak(t,this).thenReturn(!0):N(!1)).then(()=>{i.finish(!0)}),i.result()}doLayout(t,i,n){let r=O("doLayout"),s=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,r.loopWithFrame(o=>{for(;t;){let a=!0;if(this.layoutNext(t,i,n||null).then(l=>{if(i=!1,n=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,t=this.nodeContextOverflowingDueToRepetitiveElements,t.overflow=!0):t=l,this.pageFloatLayoutContext.isInvalidated())o.breakLoop();else if(this.pageBreakType)o.breakLoop();else if(t&&this.stopByOverflow(t)){s=t;let h=this.findAcceptableBreakPosition();t=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),o.breakLoop()}else a?a=!1:o.continueLoop()}),a){a=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),o.breakLoop()}).then(()=>{r.finish({nodeContext:t,overflownNodeContext:s})}),r.result()}redoLayout(){let t=this.chunkPositions,i=this.element.lastChild;for(;i!=this.last;){let a=i.previousSibling;this.element===i.parentNode&&this.layoutContext.isPseudoelement(i)||this.element.removeChild(i),i=a}this.killFloats(),this.init();let n=O("redoLayout"),r=0,s=null,o=!0;return n.loopWithFrame(a=>{if(r<t.length){let l=t[r++];this.layout(l,o).then(h=>{o=!1,h?(s=h,a.breakLoop()):a.continueLoop()});return}a.breakLoop()}).then(()=>{n.finish(s)}),n.result()}saveDistanceToBlockEndFloats(){let t=this.pageFloatLayoutContext.getBlockStartEdgeOfBlockEndFloats();t>0&&isFinite(t)&&(this.blockDistanceToBlockEndFloats=this.getBoxDir()*(t-this.beforeEdge-this.computedBlockSize))}collectElementsOffset(){let t=[];for(let i=this;i;i=i.pseudoParent)i.fragmentLayoutConstraints.forEach(n=>{if(Ni.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(n)){let r=n.getRepetitiveElements();t.push(r)}if(Jr.isInstanceOfAfterIfContinuesLayoutConstraint(n)){let r=n.getRepetitiveElements();t.push(r)}li.isInstanceOfTableRowLayoutConstraint(n)&&n.getElementsOffsetsForTableCell(this).forEach(r=>{t.push(r)})});return t}},za=class{constructor(e,t,i){c(this,"startNodeContexts",[]),c(this,"column"),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 rs.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 hr(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)}getColumnElement(){return this.column.element}getColumn(){return this.column}},ss=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+th(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&&al(r)&&al(s)?th(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};c(ss,"instance");ss.instance=new ss;function th(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var Rw=class extends Aa{constructor(e,t){super(),this.leadingEdge=e,c(this,"breakAfter"),c(this,"initialPageBreakType",null),c(this,"initialComputedBlockSize",0),c(this,"initialOverflown",!1),c(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new Fw(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||ym()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Cc(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}restoreState(e,t){super.restoreState(e,t),t.pageBreakType=this.initialPageBreakType,t.computedBlockSize=this.initialComputedBlockSize,t.overflown=this.initialOverflown}},Fw=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=O("DefaultLayoutMode.doLayout");return Tw(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}},Lw=class extends rs{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 l=ei(e,a);if(l&&l.charAt(l.length-1)==="%"){let h=parseFloat(l),u=o*h/100;T(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=>{ei(e,s)==="auto"&&T(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=ei(t,"height");n!==""&&n!=="auto"&&T(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=ei(t,"width");n!==""&&n!=="auto"&&T(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}))}},Ii=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||So.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new Ow(e,this.rootSourceNode),So.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},Ow=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=Qr(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=Qr(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 za(n,o,t),l=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new ui(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,s.removeChild(o),this.moveChildren(o,s,i),a.getColumn().pageBreakType=l,N(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(hn,"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}},td=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}},id=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},Bw=class extends td{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},Mw=class extends id{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new Da(e)),this.processor.doLayout(e,t)}},Da=class nd{constructor(t){c(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),c(this,"nodeContext");let i=$t(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||qi(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=$t(this.nodeContext.formattingContext),r=this.getRepetitiveElements();if(!r)return N(!0);let s=this.nodeContext;return Hw(n,s,i).thenAsync(()=>Uw(n,s,i).thenAsync(()=>(r.prepareLayoutFragment(),N(!0))))}getRepetitiveElements(){return $t(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof nd?$t(this.nodeContext.formattingContext)===$t(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},_w=class extends Aa{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 Bw(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new Mw(this.formattingContext,this.processor))}},zw=class extends _n{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 _n.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):_n.prototype.afterNonInlineElementNode.call(this,e)}},Dw=class extends Zi{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=$t(e.formattingContext);return n.getRootViewNode(e)?(i&&rd(e.parent,t),e.belongsTo(n)?Zi.prototype.layout.call(this,e,t,i):new _w(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=$w(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=$t(e.formattingContext),n=O("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=$t(e.formattingContext),n=new zw(i,t);return new xo(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=$t(e.formattingContext),n=O("doLayout"),r=t.layoutContext.nextInTree(e,!1);return Qc(r,t).then(s=>{let o=s;n.loopWithFrame(a=>{for(;o;){let l=!0;if(t.layoutNext(o,!1).then(h=>{o=h,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||o&&t.stopByOverflow(o)||o&&o.after&&o.sourceNode==i.rootSourceNode?a.breakLoop():l?l=!1:a.continueLoop()}),l){l=!1;return}}a.breakLoop()}).then(()=>{n.finish(o)})}),n.result()}finishBreak(e,t,i,n){return Zi.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){Zi.prototype.clearOverflownViewNodes(e,t,i,n)}};function Vw(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof Ii&&!i.belongsTo(n)&&t(n,i)}}function rd(e,t){e&&Vw(e.after?e.parent:e,(i,n)=>{li.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new Da(n))})}function Hw(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 Uw(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 $w(e){let t=e.formattingContext;return!t||!(t instanceof Ii)?null:t}function $t(e){return e instanceof Ii,e}var Ww=new Dw;Nt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Ii&&!li.isInstanceOfTableFormattingContext(e)?Ww:null);var sd=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,c(this,"cells",[])}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},Gw=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}},jw=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},Xw=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,c(this,"pseudoColumn"),c(this,"empty",!1),this.pseudoColumn=new za(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&T(e,"vertical-align","top"),i&&i!=="normal"&&T(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return T(e,"vertical-align",t),i&&i!=="normal"&&T(e,"align-content",i),n}},qw=class{constructor(e,t){this.viewNode=e,this.side=t}},Yw=class extends hr{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)?i:null}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)}},Kw=class extends Pa{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,l=s.nodeContext;return!a.isStartNodeContext(l)&&!a.isLastAfterNodeContext(l)});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 Rr&&n[o].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((s,o)=>{let a=s.breakPosition.getMinBreakPenalty();r&&s.breakPosition instanceof hr&&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)}},rn=class extends Ii{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){if(!t)return t;switch(e.display){case"table-row":return this.cellBreakPositions.length===0;case"table-cell":return!this.cellBreakPositions.some(i=>i.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 sd(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 jw(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 Zw(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(Ni.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}li.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=e}},Zw=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=nn(e,n);i=Math.max(i,t(r))}),i}};function Ct(e){return e instanceof rn,e}function Jw(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Qw(e){return e==="table"||e==="inline-table"}function ih(e){return Jw(e)||Qw(e)}function od(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 rn)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof rn){o=a.formattingContext===t;break}}return o||r==="table-row"&&!ih(s)||r==="table-cell"&&s!=="table-row"&&!ih(s)||n.formattingContext instanceof rn&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,N(!0))):null}var ey=class extends _n{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=od(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=e.nodeContext,r=n.display,s=t.getRepetitiveElements();switch(r){case"table":t.inlineBorderSpacing=n.inlineBorderSpacing;break;case"table-caption":{let o=new qw(n.viewNode,n.captionSide);t.captions.push(o);break}case"table-header-group":return s.isHeaderRegistered()||(this.inHeaderOrFooter=!0,s.setHeaderNodeContext(n)),N(!0);case"table-footer-group":return s.isFooterRegistered()||(this.inHeaderOrFooter=!0,s.setFooterNodeContext(n)),N(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,n.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new sd(this.rowIndex,n.sourceNode)),s.firstContentSourceNode||(s.firstContentSourceNode=n.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":this.inHeaderOrFooter||(t.lastRowViewNode=i.viewNode,this.inRow=!1);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 Gw(this.rowIndex,this.columnIndex,s)),this.columnIndex++}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&&!Ki(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},ad=class ld extends _n{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}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,l=i.verticalAlign;o>1&&(T(a,"box-sizing","border-box"),T(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let u=new Xw(this.column,h,i);return this.formattingContext.addCellFragment(r,s,u),n.primary.steps.length===1&&n.primary.after&&(u.empty=!0),u.pseudoColumn.layout(n,!0).thenReturn(!0)}hasBrokenCellAtSlot(t){let i=this.formattingContext.cellBreakPositions[0];return i?i.cell.anchorSlot.columnIndex===t:!1}extractRowSpanningCellBreakPositions(){let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[],n=0;do{let r=t[n],s=r.cell.rowIndex;if(s<this.currentRowIndex){let o=i[s];o||(o=i[s]=[]),o.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=O("layoutRowSpanningCellsFromPreviousFragment"),l=N(!0),h=0,u=[];return n.forEach(d=>{l=l.thenAsync(()=>{let p=es(d[0].cellNodePosition.steps[1],o.parent);return s.setCurrent(p,!1).thenAsync(()=>{let f=N(!0),m=0;function g(w){for(;m<w;){if(!u.includes(m)){let v=p.viewNode.ownerDocument.createElement("td");T(v,"padding","0"),p.viewNode.appendChild(v)}m++}}return d.forEach(w=>{f=f.thenAsync(()=>{let v=w.cell;g(v.anchorSlot.columnIndex);let y=w.cellNodePosition,C=es(y.steps[0],p);return C.offsetInNode=y.offsetInNode,C.after=y.after,C.fragmentIndex=y.steps[0].fragmentIndex+1,s.setCurrent(C,!1).thenAsync(()=>{let E=w.breakChunkPosition;for(let A=0;A<v.colSpan;A++)u.push(m+A);return m+=v.colSpan,this.layoutCell(v,C,E).thenAsync(()=>(C.viewNode.rowSpan=v.rowIndex+v.rowSpan-this.currentRowIndex+r-h,N(!0)))})})}),f.thenAsync(()=>(g(i.getColumnCount()),h++,N(!0)))})})}),l.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(()=>(this.registerCellFragmentIndex(),this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,t.breakAtTheEdge)&&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[t.columnIndex];if(i&&i.cell.anchorSlot.columnIndex==t.anchorSlot.columnIndex){let n=i.cellNodePosition.steps[0],r=this.column.layoutContext.xmldoc.getElementOffset(n.node);kw(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=O("startTableCell"),o;if(this.hasBrokenCellAtSlot(n.anchorSlot.columnIndex)){let a=this.formattingContext.cellBreakPositions.shift();i.fragmentIndex=a.cellNodePosition.steps[0].fragmentIndex+1,o=N(a.breakChunkPosition)}else o=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(a=>{a.viewNode&&i.viewNode.removeChild(a.viewNode);let l=Qr(a,0);return N(new ui(l))});return o.then(a=>{this.layoutCell(n,i,a).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,s.finish(!0)})}),s.result()}startNonInlineBox(t){let i=od(t,Ct(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 Kw(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)):T(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)):T(i.viewNode,"display","table-row-group")),r&&ld.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(ad,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var ty=ad,Kn=[];function iy(e){let t=Kn.findIndex(n=>n.root===e),i=Kn[t];return i?i.tableLayoutOption:null}function ny(e){let t=Kn.findIndex(i=>i.root===e);t>=0&&Kn.splice(t,1)}var hd=class{layoutEntireTable(e,t){let i=Ct(e.formattingContext),n=new ey(i,t);return new xo(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let r=e.ownerDocument,s=r.createElement("tr"),o=[];for(let l=0;l<t;l++){let h=r.createElement("td");s.appendChild(h),o.push(h)}e.parentNode.insertBefore(s,e.nextSibling);let a=o.map(l=>{let h=It(n,l,i),u=i?h.height:h.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),l=this.getColGroupElements(t),h=this.normalizeAndGetColElements(l);this.addMissingColElements(h,l,o,t),h.forEach((u,d)=>{T(u,n?"height":"width",`${a[d]}px`)}),l.forEach(u=>{s.appendChild(u.cloneNode(!0))}),e.colGroups=s}doInitialLayout(e,t){let i=Ct(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=iy(e.sourceNode);ny(e.sourceNode);let r=O("TableLayoutProcessor.doInitialLayout"),s=e.copy();return this.layoutEntireTable(e,t).then(o=>{let a=o.viewNode,l=It(t.clientLayout,a,t.vertical),h=t.vertical?l.left:l.bottom;if(h+=(t.vertical?-1:1)*nn(e,t.collectElementsOffset()).current,!t.isOverflown(h)&&(!n||!n.calculateBreakPositionsInside)){t.breakPositions.push(new ay(s)),r.finish(o);return}this.normalizeColGroups(i,a,t),i.updateCellSizes(t.clientLayout),r.finish(null)}),r.result()}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),T(t,"table-layout","fixed"),T(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=Ct(e.formattingContext),n=i.getRootViewNode(e),r=n.firstChild;this.addCaptions(i,n,r),this.addColGroups(i,n,r);let s=new ty(i,t),o=new xo(s,t.layoutContext),a=O("TableFormattingContext.doLayout");return o.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=Ct(e.formattingContext),r=n.getRootViewNode(e),s=O("TableFormattingContext.layout"),o;return r?(i&&rd(e.parent,t),o=new sy(n,this).layout(e,t)):o=t.buildDeepElementView(e),o.then(a=>{s.finish(a),t.element.hasAttribute("data-vivliostyle-column-height-adjusted")&&(T(t.element,"width",`${t.width}px`),T(t.element,"height",`${t.height}px`),t.element.removeAttribute("data-vivliostyle-column-height-adjusted"))}),s.result()}createEdgeBreakPosition(e,t,i,n){return new Yw(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return Ws(e),!1}finishBreak(e,t,i,n){let r=Ct(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let s=r.findRowIndexBySourceNode(t.sourceNode);r.cellBreakPositions=[];let o;if(t.after?o=r.getRowSpanningCellsOverflowingTheRow(s):o=r.getCellsFallingOnRow(s),o.length){let a=O("TableLayoutProcessor.finishBreak"),l=0;return a.loopWithFrame(h=>{if(l===o.length){h.breakLoop();return}let u=o[l++],d=r.getCellFragmentOfCell(u),p=d.findAcceptableBreakPosition().nodeContext,f=d.cellNodeContext,m=f.toNodePosition(),g=new ui(p.toNodePosition());r.cellBreakPositions.push({cellNodePosition:m,breakChunkPosition:g,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?h.continueLoop():d.pseudoColumn.finishBreak(p,!1,!0).then(()=>{ry(d,r,p),h.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),Ws(t),r.finishFragment(),a.finish(!0)}),a.result()}}return Ws(t),r.finishFragment(),Ia.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){Zi.prototype.clearOverflownViewNodes(e,t,i,n)}};function ry(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,l=It(s.clientLayout,a,r),h=s.getComputedPaddingBorder(a);if(r){let u=l.right-s.footnoteEdge-n.calculateOffset(i)-h.right;T(o,"max-width",`${u}px`)}else{let u=s.footnoteEdge-n.calculateOffset(i)-l.top-h.top;T(o,"max-height",`${u}px`)}}function Ws(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(),m=e.vertical?f.width:f.height;return d+m},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 l=a.getBoundingClientRect(),h=e.vertical?l.width:l.height,u=n+h;T(a,e.vertical?"width":"height",`${u}px`)}var sy=class extends Aa{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new oy(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new hy(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()}},oy=class extends td{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},ay=class extends hr{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 ly(this.position.sourceNode))}},ly=class ud{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,Kn.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return N(!0)}equalsTo(t){return t instanceof ud&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},hy=class extends id{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new uy(e);t.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},uy=class cd extends Da{constructor(t){super(t),c(this,"flagmentLayoutConstraintType","TableRow"),c(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||n.pseudoParent||qi(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=Ct(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=Ct(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 hd().removeColGroups(s,o),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,r)}finishBreak(t,i){let n=Ct(this.nodeContext.formattingContext),r=O("finishBreak"),s=this.cellFragmentLayoutConstraints.reduce((a,l)=>a.concat(l.constraints.map(h=>({constraint:h,breakPosition:l.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=Ct(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof cd?Ct(this.nodeContext.formattingContext)===Ct(t.nodeContext.formattingContext):!1}},cy=new hd;function dy(e,t,i,n,r,s){if(!t)return null;if(i===b.table){let o=e.parent;return new rn(o?o.formattingContext:null,e.sourceNode)}return null}function py(e){return e instanceof rn?cy:null}Nt("RESOLVE_FORMATTING_CONTEXT",dy);Nt("RESOLVE_LAYOUT_PROCESSOR",py);function nh(e){return e.reduce((t,i)=>t+i,0)/e.length}function fy(e){let t=nh(e);return nh(e.map(i=>{let n=i-t;return n*n}))}var gy=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function Zn(e){return e.vertical?e.width:e.height}function Jn(e,t){e.vertical?e.width=t:e.height=t}var dd=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,c(this,"originalContainerBlockSize"),this.originalContainerBlockSize=Zn(e)}balanceColumns(e){let t=O("ColumnBalancer#balanceColumns");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.restoreContents(n.layoutResult),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new gy(e,t)}preBalance(e){}postBalance(){Jn(this.layoutContainer,this.originalContainerBlockSize)}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)}},Mo=1;function pd(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+Mo}function fd(e,t){var i;let n=e[e.length-1].layoutResult.columns,r=Math.max.apply(null,n.map(s=>isNaN(s.blockDistanceToBlockEndFloats)?s.computedBlockSize:s.computedBlockSize-s.blockDistanceToBlockEndFloats+Mo))-Mo;if(r<Zn(t)?Jn(t,r):Jn(t,Zn(t)-1),t.vertical){let s=parseFloat((i=t.element.style)==null?void 0:i.width);t.originX=s-t.width}}var my=class extends dd{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);Jn(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 rh(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return pd(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!rh(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):Zn(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)fd(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,Zn(this.layoutContainer)+this.originalContainerBlockSize*.1);Jn(this.layoutContainer,t)}}};function rh(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize,i=e.slice(0,e.length-1),n=6;return i.every(r=>t>r.computedBlockSize+n)}var wy=class extends dd{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 fy(t)}hasNextCandidate(e){return pd(e)}updateCondition(e){fd(e,this.layoutContainer)}};function yy(e,t,i,n,r,s,o){if(t===b.auto)return null;{let a=o.positions.length===0,l=s[s.length-1],h=!!(l&&l.pageBreakType);return a||h?new my(i,n,r,e):t===b.balance_all?new wy(i,n,r):(b.balance,null)}}var by=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],vy=new Set(by);function xy(e){return!(e.toLowerCase()==="none"||vy.has(e))}var Sy=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],Cy=new Set(Sy),ky=["fixed","extends"],Ey=new Set(ky),X0=Symbol();function cr(e){return e instanceof le&&e.name.toLowerCase()!=="none"}function gd(e){return e.name}function Ny(e){if(e instanceof le)return Cy.has(e.name);if(e instanceof J&&e.values.length===2){let t=e.values[0],i=e.values[1];if(t instanceof le){let n=t.name;return Ey.has(n)&&(n==="fixed"&&i instanceof Le||n==="extends"&&cr(i))}}return!1}function Py(e){let t=nt(e,"system");return t instanceof le&&t.name==="cyclic"}function Ty(e){let t=nt(e,"system");if(t instanceof le&&t.name==="fixed")return!0;if(t instanceof J&&t.values.length===2){let[i,n]=t.values;return i instanceof le&&i.name==="fixed"&&n instanceof Le}return!1}function Iy(e){let t=nt(e,"system");return t instanceof le?1:t.values[1].num}function Ay(e){let t=nt(e,"system");return t instanceof le&&t.name==="alphabetic"}function Ry(e){let t=nt(e,"system");return t instanceof le&&t.name==="numeric"}function Fy(e){let t=nt(e,"system");return t instanceof le&&t.name==="additive"}function Ly(e){let t=nt(e,"system");if(t instanceof J&&t.values.length===2){let[i,n]=t.values;return i instanceof le&&i.name==="extends"&&cr(n)}return!1}function Oy(e){let t=nt(e,"system");return gd(t.values[1])}function Pt(e){return e instanceof j||e instanceof le}function jt(e){return e instanceof j?e.str:e.name}function md(e){if(Pt(e))return!0;if(e instanceof J&&e.values.length===2){let t=e.values[0],i=e.values[1];return Pt(t)&&Pt(i)}return!1}function By(e){if(Pt(e))return{prefix:jt(e),suffix:null};{let t=e.values[0],i=e.values[1];return{prefix:jt(t),suffix:jt(i)}}}function sh(e){return e instanceof Le||e instanceof le&&e.name==="infinite"}function os(e,t){return e instanceof Le?e.num:t?-1/0:1/0}var q0=Symbol();function _o(e){if(!(e instanceof J&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(sh(t)&&sh(i)))return!1;let n=os(t,!0),r=os(i,!1);return!(n>r)}function My(e){return{lower:os(e.values[0],!0),upper:os(e.values[1],!1)}}function wd(e){return e instanceof le&&e.name==="auto"||_o(e)||e instanceof Ze&&e.values.length>=1&&e.values.every(t=>_o(t))}function _y(e){return e instanceof le?null:(_o(e)?[e]:e.values).map(t=>My(t))}var Y0=Symbol();function as(e){if(!(e instanceof J&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];return t instanceof Le&&t.num>=0&&Pt(i)||Pt(t)&&i instanceof Le&&i.num>=0}function ls(e){let[t,i]=e.values;return t instanceof Le?[t.num,jt(i)]:[i.num,jt(t)]}function yd(e){return as(e)}function zy(e){let[t,i]=ls(e);return{minLength:t,symbol:i}}function bd(e){return Pt(e)||e instanceof J&&e.values.length>=1&&e.values.every(t=>Pt(t))}function Dy(e){return Pt(e)?[jt(e)]:e.values.map(t=>jt(t))}var K0=Symbol();function vd(e){if(as(e))return!0;if(e instanceof Ze&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!as(i))return!1;let[n]=ls(i);if(n>=t)return!1;t=n}return!0}return!1}function Vy(e){if(as(e)){let[t,i]=ls(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=ls(t);return{weight:i,symbol:n}})}var Hy=["auto","bullets","numbers","words","spell-out"],Uy=new Set(Hy);function $y(e){return e instanceof le&&Uy.has(e.name)||cr(e)}function Wy(e,t){switch(e){case"system":return Ny(t);case"negative":return md(t);case"prefix":case"suffix":return Pt(t);case"range":return wd(t);case"pad":return yd(t);case"fallback":return cr(t);case"symbols":return bd(t);case"additive-symbols":return vd(t);case"speak-as":return $y(t);default:return!0}}function nt(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function Gy(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function cn(e){let t=e.get("decimal");return t||(t=ue.createDecimal(e),e.set("decimal",t)),t}var Fr,Lr,Or,Br,Mr,_r,zr,Dr,zo,Do,Vo,Ho,Uo,$o,Wo,ot,Gs,xd,Sd,oh,ah,js,lh,An,Qt=class bi{constructor(t,i){Z(this,ot),c(this,"_store"),Z(this,Fr),Z(this,Lr),Z(this,Or),Z(this,Br),Z(this,Mr),Z(this,_r),Z(this,zr),Z(this,Dr),this._store=t;let n=nt(i,"negative");Fe(this,Fr,n&&md(n)?By(n):null);let r=nt(i,"prefix");Fe(this,Lr,r&&Pt(r)?jt(r):null);let s=nt(i,"suffix");Fe(this,Or,s&&Pt(s)?jt(s):null);let o=nt(i,"range");Fe(this,Br,o&&wd(o)?_y(o):null);let a=nt(i,"pad");Fe(this,Mr,a&&yd(a)?zy(a):null);let l=nt(i,"fallback");Fe(this,_r,l&&cr(l)?gd(l):null);let h=nt(i,"symbols");Fe(this,zr,h&&bd(h)?Dy(h):null);let u=nt(i,"additive-symbols");Fe(this,Dr,u&&vd(u)?Vy(u):null)}static create(t,i){return Py(i)?new fi(t,i):Ty(i)?new jy(t,i):Ay(i)?new qy(t,i):Ry(i)?new hh(t,i):Fy(i)?new Yy(t,i):Ly(i)?new Ky(t,i):new Xy(t,i)}static createDecimal(t){return new hh(t,M(bi,zo))}static createDisc(t){return new fi(t,M(bi,Do))}static createSquare(t){return new fi(t,M(bi,Vo))}static createCircle(t){return new fi(t,M(bi,Ho))}static createDisclosureOpen(t){return new fi(t,M(bi,Uo))}static createDisclosureClosed(t){return new fi(t,M(this,$o))}static createNone(t){return new fi(t,M(bi,Wo))}static get CHINESE_LONGHAND_NAMES(){return uh.NAMES}static createChineseLonghand(t,i){return new uh(t,i)}static createEthiopicNumeric(t){return new Jy(t)}_getNegative(){return M(this,Fr)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return M(this,Lr)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return M(this,Or)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return M(this,Br)}static _getRangeFrom(t){return t._getRange()}_getPad(){return M(this,Mr)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(M(this,_r)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return M(this,zr)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return M(this,Dr)}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 Se(this,ot,An).call(this,t,new Set)}formatMarker(t){return Se(this,ot,xd).call(this)+this.format(t)+Se(this,ot,Sd).call(this)}};Fr=new WeakMap,Lr=new WeakMap,Or=new WeakMap,Br=new WeakMap,Mr=new WeakMap,_r=new WeakMap,zr=new WeakMap,Dr=new WeakMap,zo=new WeakMap,Do=new WeakMap,Vo=new WeakMap,Ho=new WeakMap,Uo=new WeakMap,$o=new WeakMap,Wo=new WeakMap,ot=new WeakSet,Gs=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},xd=function(){var e;return(e=this._getPrefix())!=null?e:""},Sd=function(){var e;return(e=this._getSuffix())!=null?e:". "},oh=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},ah=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},js=function(){var e;return(e=this._getFallback())!=null?e:cn(this._store)},lh=function(e,t){let{minLength:i,symbol:n}=Se(this,ot,ah).call(this);if(i===0||n==="")return e;let{prefix:r,suffix:s}=Se(this,ot,Gs).call(this),o=t?[...r].length+(s?[...s].length:0):0,a=i-[...e].length-o;if(a<=0)return e;let l=[...n].length,h=Math.ceil(a/l);return n.repeat(h)+e},An=function(e,t){var i,n,r;if(t.has(this))return Se(i=cn(this._store),ot,An).call(i,e,new Set);if(t.add(this),!Gy(e,Se(this,ot,oh).call(this))){let h=Se(this,ot,js).call(this);return Se(n=h,ot,An).call(n,e,t)}let s=this._usesNegativeSign(e),o=s?Math.abs(e):e,a=this._generateInitialRepresentation(o);if(a===null){let h=Se(this,ot,js).call(this);return Se(r=h,ot,An).call(r,e,t)}let l=Se(this,ot,lh).call(this,a,s);if(s){let{prefix:h,suffix:u}=Se(this,ot,Gs).call(this);l=h+l+(u??"")}return l},Z(Qt,zo,{system:new _(F("numeric"),0),symbols:new _(new J([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)}),Z(Qt,Do,{system:new _(F("cyclic"),0),symbols:new _(new j("\u2022"),0),suffix:new _(new j(" "),0)}),Z(Qt,Vo,{system:new _(F("cyclic"),0),symbols:new _(new j("\u25AA"),0),suffix:new _(new j(" "),0)}),Z(Qt,Ho,{system:new _(F("cyclic"),0),symbols:new _(new j("\u25E6"),0),suffix:new _(new j(" "),0)}),Z(Qt,Uo,{system:new _(F("cyclic"),0),symbols:new _(new j("\u25BE"),0),suffix:new _(new j(" "),0)}),Z(Qt,$o,{system:new _(F("cyclic"),0),symbols:new _(new j("\u25B8"),0),suffix:new _(new j(" "),0)}),Z(Qt,Wo,{system:new _(F("cyclic"),0),symbols:new _(new j(""),0),suffix:new _(new j(""),0)});var ue=Qt,fi=class extends ue{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]}},Vr,jy=class extends ue{constructor(e,t){super(e,t),Z(this,Vr),Fe(this,Vr,Iy(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-M(this,Vr);return(t=i[n])!=null?t:null}};Vr=new WeakMap;var Xy=class extends ue{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)}},qy=class extends ue{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}},hh=class extends ue{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}},Yy=class extends ue{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}},Hn,dt,yt,Cd=class extends ue{constructor(t,i){super(t,i),Z(this,dt),Z(this,Hn);let n=Oy(i),r=n.toLowerCase();r==="disc"||r==="circle"||r==="square"||r==="disclosure-open"||r==="disclosure-closed"?Fe(this,Hn,r):Fe(this,Hn,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:ue._getNegativeFrom(Se(this,dt,yt).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:ue._getPrefixFrom(Se(this,dt,yt).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:ue._getSuffixFrom(Se(this,dt,yt).call(this))}_getAutoRange(){return ue._getAutoRangeFrom(Se(this,dt,yt).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:ue._getRangeFrom(Se(this,dt,yt).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:ue._getPadFrom(Se(this,dt,yt).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:ue._getFallbackFrom(Se(this,dt,yt).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:ue._getSymbolsFrom(Se(this,dt,yt).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:ue._getAdditiveSymbolsFrom(Se(this,dt,yt).call(this))}_usesNegativeSign(t){return ue._useNegativeSignFrom(Se(this,dt,yt).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:ue._generateInitialRepresentationFrom(Se(this,dt,yt).call(this),t)}};Hn=new WeakMap,dt=new WeakSet,yt=function(e=new Set){var t;if(e.has(this))return cn(this._store);e.add(this);let i=this._store.get(M(this,Hn));return i?i instanceof Cd?Se(t=i,dt,yt).call(t,e):i:cn(this._store)};var Ky=Cd,Zy=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],Xs,qs,Sr,Ys,Go,Hr,vt=class kd extends ue{constructor(t,i){let{chars:n,descriptors:r}=M(kd,Go).get(i);super(t,r),Z(this,Hr),Fe(this,Hr,n)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=M(this,Hr);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="",l=!1;for(let h=0;h<n.length;h++){let{digit:u,position:d}=n[h],p=h===n.length-1;u===0?!p&&!l&&(l=!0):(l&&(a+=i.digits[0],l=!1),o&&d===1?a+=i.markers[d]:(a+=i.digits[u],d>0&&(a+=i.markers[d])))}return a}};Xs=new WeakMap,qs=new WeakMap,Sr=new WeakMap,Ys=new WeakMap,Go=new WeakMap,Hr=new WeakMap,Z(vt,Xs,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new _(new j("\u3001"),0),fallback:new _(F("cjk-decimal"),0),range:new _(new J([new Le(-9999),new Le(9999)]),0),negative:new _(new j("\u8D1F"),0)}}),Z(vt,qs,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new _(new j("\u3001"),0),fallback:new _(F("cjk-decimal"),0),range:new _(new J([new Le(-9999),new Le(9999)]),0),negative:new _(new j("\u8D1F"),0)}}),Z(vt,Sr,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new _(new j("\u3001"),0),fallback:new _(F("cjk-decimal"),0),range:new _(new J([new Le(-9999),new Le(9999)]),0),negative:new _(new j("\u8CA0"),0)}}),Z(vt,Ys,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new _(new j("\u3001"),0),fallback:new _(F("cjk-decimal"),0),range:new _(new J([new Le(-9999),new Le(9999)]),0),negative:new _(new j("\u8CA0"),0)}}),c(vt,"NAMES",new Set(Zy)),Z(vt,Go,new Map([["simp-chinese-informal",M(vt,Xs)],["simp-chinese-formal",M(vt,qs)],["trad-chinese-informal",M(vt,Sr)],["trad-chinese-formal",M(vt,Ys)],["cjk-ideographic",M(vt,Sr)]]));var uh=vt,jo,Xo,hs,qo,Yo,Gi=class vi extends ue{constructor(t){super(t,M(vi,jo))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return M(vi,hs)[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],l=o%2===1,h=o===r-1;if(!(a===0||h&&a===1||l&&a===1)){let u=Math.floor(a/10),d=a%10;s+=M(vi,Xo)[u]+M(vi,hs)[d]}l?a!==0&&(s+=M(vi,qo)):o!==0&&(s+=M(vi,Yo))}return s}};jo=new WeakMap,Xo=new WeakMap,hs=new WeakMap,qo=new WeakMap,Yo=new WeakMap,Z(Gi,jo,{range:new _(new J([new Le(1),F("infinite")]),0),suffix:new _(new j("/ "),0)}),Z(Gi,Xo,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),Z(Gi,hs,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),Z(Gi,qo,"\u137B"),Z(Gi,Yo,"\u137C");var Jy=Gi,ke,Qy=class{constructor(){Z(this,ke),Fe(this,ke,new Map),M(this,ke).set("none",ue.createNone(M(this,ke))),M(this,ke).set("decimal",ue.createDecimal(M(this,ke))),M(this,ke).set("disc",ue.createDisc(M(this,ke))),M(this,ke).set("square",ue.createSquare(M(this,ke))),M(this,ke).set("circle",ue.createCircle(M(this,ke))),M(this,ke).set("disclosure-open",ue.createDisclosureOpen(M(this,ke))),M(this,ke).set("disclosure-closed",ue.createDisclosureClosed(M(this,ke)));for(let e of ue.CHINESE_LONGHAND_NAMES)M(this,ke).set(e,ue.createChineseLonghand(M(this,ke),e));M(this,ke).set("ethiopic-numeric",ue.createEthiopicNumeric(M(this,ke)))}define(e,t){if(!xy(e))return null;let i=ue.create(M(this,ke),t);return M(this,ke).set(e,i),i}getStyle(e){var t;return(t=M(this,ke).get(e))!=null?t:null}format(e,t){var i;return((i=this.getStyle(e))!=null?i:cn(M(this,ke))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:cn(M(this,ke))).formatMarker(t)}};ke=new WeakMap;var Ks=class{constructor(e,t,i){c(this,"endStuckFixed"),c(this,"endFixed"),c(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},eb=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 Ks(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 Ks(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new Ks(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)}},tb=class Ko{constructor(t,i,n,r,s,o,a,l){if(this.context=t,this.style=i,this.offset=n,this.isRoot=r,this.flowChunk=s,this.atBlockStart=o,this.atFlowStart=a,this.isParentBoxDisplayed=l,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 h=i._pseudos;if(h&&h.before){let u=new Ko(t,h.before,n,!1,s,this.isBlock(),a,!0),d=u.styleValue("content");Dt(d)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=rt(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&it(this.breakBefore)&&(s.breakBefore=rt(s.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let r=this.style._pseudos;if(r&&r.after){let s=new Ko(this.context,r.after,t,!1,this.flowChunk,i,n,!0),o=s.styleValue("content");Dt(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",b.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=bc(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==b.none&&!yo(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}},ib=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()!==b.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(),l=new tb(this.context,e,t,i,s,o||this.atBlockStart,o,a);return this.stack.push(l),this.atBlockStart=l.hasBox()?!l.beforeBox&&l.isBlock():this.atBlockStart,this.atFlowStart=l.hasBox()?!l.beforeBox&&o:this.atFlowStart,l}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",b.normal).toString(),n=ac(i);n&&!$e(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=rt(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!")}},ch=class{constructor(e,t,i,n,r,s,o,a,l,h){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,"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,l,h),this.offsetMap=new eb;let u=e.getElementOffset(this.root);this.lastOffset=u,this.boxStack=new ib(n),this.offsetMap.addStuckRange(u);let d=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,d,u),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 _(r,Xu))}}}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)zn(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&&!K(n)||r&&!K(r))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<dh.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,dh[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],r=!0;if(n&&!K(n.value)){let a=n.evaluate(this.context);if(a instanceof I){let l=a.num;switch(a.unit){case"em":case"rem":l*=this.context.initialFontSize;break;case"%":l*=this.context.initialFontSize/100;break;case"lh":case"rlh":l*=this.context.initialFontSize*At.lh/At.em;break;default:{let h=At[a.unit];h&&(l*=h),r=!1}}this.context.rootFontSize=l,this.context.isRelativeRootFontSize=r}}let s=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,o=e["line-height"];if(o&&!K(o.value)){let a=o.evaluate(this.context);if(a instanceof gt)this.context.rootLineHeight=a.num*s;else if(a instanceof I){let l=a.num;switch(a.unit){case"em":case"rem":l*=s;break;case"%":l*=s/100;break;case"lh":case"rlh":l*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let h=At[a.unit];h&&(l*=h)}}this.context.rootLineHeight=l}}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 mw(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}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),o=Re(s,"flow-into"),a=o?o.evaluate(t,"flow-into").toString():"body",l=this.encounteredFlowElement(a,s,this.root,i);this.boxStack.empty()&&this.boxStack.push(s,i,!0,l)}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),l=a["flow-into"];if(l){let h=l.evaluate(t,"flow-into").toString();this.encounteredFlowElement(h,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,l=!1,h=t["flow-options"];if(h){let g=Rf(h.evaluate(this.context,"flow-options"));o=!!g.exclusive,a=!!g.static,l=!!g.last}let u=t["flow-linger"];u&&(s=Pl(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let d=t["flow-priority"];d&&(r=Pl(d.evaluate(this.context,"flow-priority"),0));let p=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let g=this.boxStack.lastFlowName();f=this.flows[e]=new jg(e,g)}let m=new Xg(e,i,n,r,s,o,a,l,p);return this.flowChunks.push(m),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(m,f),m}registerForcedBreakOffset(e,t,i){if(it(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]=rt(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 l=o.afterBox.getBreakValue("before");this.registerForcedBreakOffset(l,o.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(o):o.afterBox.offset,o.flowName),a=o.afterBox.getBreakValue("after")}a=rt(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);let l=o.getAttribute("id")||o.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");l&&l===this.idToReach&&(this.idToReach=null),!this.bodyReached&&o.localName=="body"&&o.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let h,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],h=this.boxStack.push(a,this.lastOffset,o===this.root,f)}else h=this.boxStack.push(a,this.lastOffset,o===this.root),o===this.xmldoc.body&&(h.breakBefore=rt(h.flowChunk.breakBefore,h.breakBefore));let d=this.boxStack.nearestBlockStartOffset(h);if(d===0){let p=a.page,f=p&&!K(p.value)&&p.value.toString();f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(h.breakBefore,d,h.flowName),h.beforeBox){let p=h.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(p,h.beforeBox.atBlockStart?d:h.offset,h.flowName)}if(this.primary&&h.displayValue()===b.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){}},dh=["column-count","column-width","column-fill"],Qi=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)}},gi=class{constructor(e,t){this.where=e,this.success=t,c(this,"what",-1)}},Sn=class Ed{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 Ed;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],r=new Qi(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 gi(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 Qi(ph);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 gi(r,!0),a=new gi(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 Qi(ph);i.markAsStartAlternate(t),this.nodes.push(i);let n=new gi(0,!0),r=new gi(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 Qi(t));let n=new gi(i,!0),r=new gi(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 Be}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]}},nb=1,Nd=2,Pd=4,xi=8,Ur=16,Zo=32,$r=64,Td=128,Rn=256,Fn=512,Jo=1024,Id=2048,Ad=4096,Rd=8192,Fd=class extends Kt{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},Be=class Ld extends Fd{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&nb?t:null}visitSlash(t){return this.allowed&Id?t:null}visitStr(t){return this.allowed&Nd?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&Pd||this.allowed&$r&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&Fn)?t.unit=="%"&&this.allowed&Jo?t:null:t.num<0&&!(this.allowed&Rn)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&Fn?t:null:t.num<=0&&!(this.allowed&Rn)?null:this.allowed&Ur?t:null}visitInt(t){return t.num==0?this.allowed&Fn?t:null:t.num<=0&&!(this.allowed&Rn)?null:this.allowed&(Zo|Ur)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&$r&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&Td?t:null}visitURange(t){return this.allowed&Ad?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){if(this.allowed&$r){if(t.name==="device-cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&ku(t)!==null?t:null;if(CSS.supports("color",t.toString()))return t}if(this.allowed&Rd){let i=t.visit(new Pu);if(CSS.supports("background-image",i.toString()))return t}return t.name==="calc"&&this.allowed&(xi|Ur|Zo|Rn|Fn|Jo)?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 Ld(this.allowed|t.allowed,i,n)}},oe={},ph=new Be(0,oe,oe),Va=class extends Fd{constructor(e){super(),c(this,"successTerminal"),c(this,"failureTerminal"),c(this,"first"),this.successTerminal=new Qi(null),this.failureTerminal=new Qi(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 l=e[s],h=l;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 Un&&this instanceof Un){if(h=new J(e).visit(r.validator),h){s=e.length,r=r.success;continue}}else if(s==0&&!t&&r.validator instanceof Ha&&this instanceof Un){if(h=new Ze(e).visit(r.validator),h){s=e.length,r=r.success;continue}}else h=l.visit(r.validator);if(!h){r=r.failure;continue}if(h!==l&&e===n){n=[];for(let u=0;u<s;u++)n[u]=e[u]}e!==n&&(n[s-i]=h),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}},Un=class extends Va{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 Ha){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new Ze(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},Ha=class extends Va{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 Ze(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}},rb=class extends Va{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 Ri(e.name,t):null}},Od=class{tryParse(e,t,i){return t}success(e,t){}},Bd=class extends Od{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 J(n):n[0];return this.success(s,i),t+r}return t}success(e,t){t.values[this.name]=e}},sb=class extends Bd{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}},ob=class extends Od{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==fn){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}},Ua=class extends Kt{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 Bd(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:b.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)}},yn=class extends Ua{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}},Md=class extends Ua{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 sb(this.validatorSet,this.propList)}},ab=class extends Ua{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===fn){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}},lb=class extends yn{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:b.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 Ze?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 Ze(t[i]);return null}},hb=class extends yn{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]===fn){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 J(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 Ze(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}},ub=class extends yn{validateList(e){if(e.length===1&&e[0]instanceof le)switch(e[0].name.toLowerCase()){case"normal":e=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":e=[b.auto,b.auto];break;case"none":e=[F("no-autospace"),F("space-all")];break}return super.validateList(e)}},cb=["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","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],db=class extends yn{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)cb.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},fh={SIMPLE:yn,INSETS:Md,INSETS_SLASH:ab,COMMA:lb,FONT:hb,TEXT_SPACING:ub,ALL:db},pb=["initial-letter"],fb=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 I(t.num,t.text);else if(t.type==7)i=new bu(t.text);else if(t.type==1)i=F(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 Sn;if(e=="||"){for(let r=0;r<t.length;r++){let s=new Sn;s.startClause(r),s.addGroup(t[r],1),s.endClause(r),i.addGroup(s,r==0?1:4)}let n=new Sn;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 Sn;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 Sn;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new Ha(t);break;case"SPACE":i=new Un(t);break;default:i=new rb(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Be($r,oe,oe)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Be(Rd,oe,oe)),this.namedValidators.POS_INT=this.primitive(new Be(Zo,oe,oe)),this.namedValidators.POS_NUM=this.primitive(new Be(Ur,oe,oe)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Be(xi,oe,{"%":X})),this.namedValidators.NEGATIVE=this.primitive(new Be(Rn,oe,oe)),this.namedValidators.ZERO=this.primitive(new Be(Fn,oe,oe)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Be(Jo,oe,oe)),this.namedValidators.POS_LENGTH=this.primitive(new Be(xi,oe,{em:X,ex:X,ch:X,rem:X,lh:X,rlh:X,vw:X,vh:X,vi:X,vb:X,vmin:X,vmax:X,pvw:X,pvh:X,pvi:X,pvb:X,pvmin:X,pvmax:X,cm:X,mm:X,in:X,px:X,pt:X,pc:X,q:X})),this.namedValidators.POS_ANGLE=this.primitive(new Be(xi,oe,{deg:X,grad:X,rad:X,turn:X})),this.namedValidators.POS_TIME=this.primitive(new Be(xi,oe,{s:X,ms:X})),this.namedValidators.FREQUENCY=this.primitive(new Be(xi,oe,{Hz:X,kHz:X})),this.namedValidators.RESOLUTION=this.primitive(new Be(xi,oe,{dpi:X,dpcm:X,dppx:X})),this.namedValidators.URI=this.primitive(new Be(Td,oe,oe)),this.namedValidators.URANGE=this.primitive(new Be(Ad,oe,oe)),this.namedValidators.IDENT=this.primitive(new Be(Pd,oe,oe)),this.namedValidators.STRING=this.primitive(new Be(Nd,oe,oe)),this.namedValidators.SLASH=this.primitive(new Be(Id,oe,oe));let e={"font-family":F("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)},l=u=>{if(o)throw new Error(`'${u}': unexpected`);if(r&&r!=u)throw new Error(`mixed operators: '${u}' and '${r}'`);r=u,o=!0},h=null;for(;!h;){e.consume();let u=e.token();switch(u.type){case 1:if(o||l(" "),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()]=F(u.text),i.push(this.primitive(new Be(0,d,oe)))}o=!1;break;case 5:{let d={};d[`${u.num}`]=new Le(u.num),i.push(this.primitive(new Be(0,d,oe))),o=!1;break}case 34:l("|");break;case 25:l("||");break;case 14:o||l(" "),n.push({vals:i,op:r,b:"["}),r="",i=[],o=!0;break;case 6:o||l(" "),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(h=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]=h:h.isSimple()?this.validators[t]=h.nodes[0].validator:this.validators[t]=new Un(h)}}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(F(n.text));break;case 4:i.push(new gt(n.num));break;case 5:i.push(new Le(n.num));break;case 3:i.push(new I(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&&fh[i.text]?(n=new fh[i.text],e.consume()):n=new yn,n.setOwner(this);let r=!1,s=[],o=!1,a=[],l=[];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("_")||l.push(i.text);else if(this.shorthands[i.text]instanceof Md){let h=this.shorthands[i.text];s.push(h.createSyntaxNode()),l.push(...h.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 h=new ob(s,o),u=a.pop();s=u.syntax,o=u.slash,s.push(h);break}case 17:r=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(s,l),this.shorthands[t]=n}}parse(e){let t=new Ft(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:b.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){let r=n.ruleType;if(zt(e)||r==="font-face"||mb(t)){n.simpleProperty(e,t,i);return}if(r==="counter-style"){Wy(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 l=this.prefixes[e];if(!l||!l[s]){CSS.supports(o,t.toString())?n.simpleProperty(o,t,i):s&&!jh.includes(`-${s}-`)||n.unknownProperty(o,t);return}else if(pb.includes(e)&&!Object.keys(l).some(u=>Er(u?`-${u}-`:"",e))){n.unknownProperty(o,t);return}let h=this.validators[e];if(h){let u=K(t)||t.isExpr()?t:t.visit(h);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();K(t)?u.propagateDefaultingValue(t,i,n):(t.visit(u),u.finish(i,n)||n.invalidPropertyValue(o,t))}}};function _d(){let e=new fb;return e.initBuiltInValidators(),e.parse(Du),e}var gb=class extends Kt{constructor(){super(...arguments),c(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function mb(e){let t=new gb;return e.visit(t),t.varFound}var J0=`OTTO${new Date().valueOf()}`;function $a(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function wb(e){let t=new oi;for(let i of $a(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function yb(e,t){let i={};for(let n in e)i[n]=Re(e,n).evaluate(t,n);return i}var zd=class{constructor(e){this.properties=e,c(this,"fontTraitKey"),c(this,"src"),c(this,"blobURLs",[]),c(this,"blobs",[]),c(this,"family"),this.fontTraitKey=wb(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 oi;i.append(`@font-face {
1844
+ }`;function qo(e,t,i){let n=_("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=Bc([a]):t==="json"?s.responseText=JSON.stringify(a):typeof a=="string"&&(s.responseText=a),o.schedule(s)}).catch(a=>{s.status>=400?G.warn(`Error fetching ${e} (${s.status}${s.statusText?" "+s.statusText:""})`):G.warn(a,`Error fetching ${e}`),o.schedule(s)}),n.result()}function Bc(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Mm(e){let t=_("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function _m(e){return URL.createObjectURL(e)}var qa=class{constructor(e,t){this.parser=e,this.type=t,d(this,"resources",{}),d(this,"fetchers",{})}load(e,t,i){e=qt(e);let n=this.resources[e];return typeof n<"u"?T(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=_("fetch"),r=e.endsWith("?viv-toc-box");r&&(e=e.replace("?viv-toc-box",""));let o=Ne("user-agent.xml",mi),s=!r&&e===o;return s&&(e=`data:application/xml,${encodeURIComponent(Ic)}`),qo(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=qt(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new Er(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[qt(e)]}delete(e){delete this.resources[qt(e)]}};function Dm(e,t){let i=e.responseText;return T(i?za(i):null)}function zm(){return new qa(Dm,"text")}function Wt(e,t,i){let n=new Er(()=>{let r=_("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);return r.result()},`loadElement ${t||e.localName}`);return n.start(),n}var sh=0,Vm=16777216,Mc=33554432,_c=50331648,Dc=67108864,Um=83886080,Hm=100663296,Ya=class{constructor(e){this.scope=e,d(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 sh;case"User":return Hm;default:return Um}}getBaseSpecificity(){switch(this.flavor){case"UA":return sh;case"User":return Vm;default:return Mc}}},Ws=class extends Ya{constructor(){super(null),d(this,"stack",[]),d(this,"tokenizer",null),d(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;G.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)}},ah=class extends Ya{constructor(e,t,i){super(e),this.owner=t,this.topLevel=i,d(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()}},Gi=class extends ah{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new ah(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())}},_e=[],xo=[],be=[],Le=[],At=[],ot=[],Me=[],je=[],ve=[],Ze=[],at=[],He=[],Be=[],tn=55,nn=56,Dr=57;_e[1]=28,_e[36]=29,_e[7]=29,_e[9]=29,_e[14]=29,_e[18]=29,_e[50]=29,_e[20]=30,_e[13]=27,_e[0]=200,xo[1]=46,xo[0]=200,ot[1]=2,ot[36]=4,ot[7]=6,ot[9]=8,ot[14]=10,ot[18]=14,ot[50]=42,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[12]=13,be[18]=55,be[50]=58,be[16]=41,Le[37]=11,Le[23]=12,Le[35]=56,Le[1]=1,Le[36]=3,Le[7]=5,Le[9]=7,Le[14]=9,Le[18]=55,At[1]=2,At[36]=4,At[7]=6,At[9]=8,At[18]=14,At[50]=42,At[14]=10,At[12]=13,Me[1]=15,Me[7]=16,Me[4]=17,Me[5]=18,Me[3]=19,Me[2]=20,Me[8]=21,Me[27]=57,Me[16]=22,Me[19]=23,Me[6]=24,Me[11]=25,Me[17]=26,Me[13]=48,Me[31]=47,Me[23]=54,Me[0]=44,je[1]=31,je[4]=32,je[5]=32,je[3]=33,je[2]=34,je[10]=40,je[6]=38,je[31]=36,je[24]=36,je[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,Ze[0]=200,Ze[12]=50,Ze[13]=51,Ze[14]=50,Ze[15]=51,Ze[10]=50,Ze[11]=51,Ze[17]=53,at[0]=200,at[12]=50,at[13]=52,at[14]=50,at[15]=51,at[10]=50,at[11]=51,at[17]=53,He[0]=200,He[12]=50,He[13]=51,He[14]=50,He[15]=51,He[10]=50,He[11]=51,Be[11]=0,Be[16]=0,Be[22]=1,Be[18]=1,Be[26]=2,Be[25]=2,Be[38]=3,Be[37]=3,Be[48]=3,Be[47]=3,Be[39]=3,Be[49]=3,Be[41]=3,Be[23]=4,Be[24]=4,Be[36]=5,Be[19]=5,Be[21]=5,Be[0]=6,Be[tn]=2,Be[nn]=2;var Pr=class{constructor(e,t,i,n){this.actions=e,this.tokenizer=t,this.handler=i,this.baseURL=n,d(this,"valStack",[]),d(this,"namespacePrefixToURI",{}),d(this,"defaultNamespaceURI",null),d(this,"propName",null),d(this,"propImportant",!1),d(this,"exprContext"),d(this,"result",null),d(this,"importReady",!1),d(this,"importURL",null),d(this,"importCondition",null),d(this,"errorBrackets",[]),d(this,"ruleStack",[]),d(this,"regionRule",!1),d(this,"pageRule",!1),d(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 Ki){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 ee(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=at);let h=new $i(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,s+2,h),h.name==="var"){let l=h.values[0]instanceof ce&&h.values[0].name;(!Zt(l)||l===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${h.toString()}`,t),this.actions=at)}return h}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=at,null;if(s>1)return new it(this.extractVals(",",n+1));let a=i[0];return a instanceof nt?a:a?new Ki(a.toString()):Y}exprError(e,t){this.actions=this.propName?at:Ze,G.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 ng(n.getScope(),h,l);a.unshift(u)}return i.push(new W(a[0])),!0}else if(s=="("){let h=i.pop(),l=i.pop();r=new Kn(n.getScope(),Fs(l,h),a),e=0;continue}}if(s==10){r.isMediaName()&&(r=new Vl(n.getScope(),r,null)),e=0;continue}}else if(typeof s=="string"){i.push(s);break}if(s<0)if(s==-31)r=new yi(n.getScope(),r);else if(s==-24)r=new ln(n.getScope(),r);else if(s==-Dr)r=new tg(n.getScope(),r);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(Be[e]>Be[s]){i.push(s);break}switch(o=i.pop(),s){case 26:r=new Ha(n.getScope(),o,r);break;case tn:r=new ig(n.getScope(),o,r);break;case nn:r=new rg(n.getScope(),o,r);break;case 25:r=new $a(n.getScope(),o,r);break;case 38:r=new og(n.getScope(),o,r);break;case 37:r=new ag(n.getScope(),o,r);break;case 48:r=new sg(n.getScope(),o,r);break;case 47:r=new Os(n.getScope(),o,r);break;case 39:case 49:r=new Wa(n.getScope(),o,r);break;case 41:r=new lg(n.getScope(),o,r);break;case 23:r=new _u(n.getScope(),o,r);break;case 24:r=new Du(n.getScope(),o,r);break;case 36:r=new Ga(n.getScope(),o,r);break;case 19:r=new zu(n.getScope(),o,r);break;case 21:r=new Vu(n.getScope(),o,r);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),r=new cg(n.getScope(),i.pop(),o,r);break;case 10:if(o.isMediaName())r=new Vl(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),c=i.nthToken(2);if(u.type===1&&c.type===18)i.consume(),i.consume(),r=u.text,n=c.position+1;else{if(u.type===10||u.type===6||u.type===1&&u.text.toLowerCase()==="not"&&(c.type===10||c.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 dg(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=Rt(i,t,new yi(i,new qe(i,"pref-horizontal")));break;case"horizontal":t=Rt(i,t,new qe(i,"pref-horizontal"));break;case"day":t=Rt(i,t,new yi(i,new qe(i,"pref-night-mode")));break;case"night":t=Rt(i,t,new qe(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new W(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,c,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===Me&&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 Ki(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=at):(this.actions=ot,s.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Me,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=at,s.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Me,h.splice(0,h.length);continue;case 29:this.actions=ot,s.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=He,s.error("E_CSS_SPACE_EXPECTED",l);continue}s.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),c=this.namespacePrefixToURI[l.text],c!=null)switch(l=a.token(),l.type){case 1:s.tagSelector(c,l.text),r?this.actions=Le:this.actions=be,a.consume();break;case 36:s.tagSelector(c,null),r?this.actions=Le:this.actions=be,a.consume();break;default:this.actions=Ze,s.error("E_CSS_NAMESPACE",l)}else this.actions=Ze,s.error("E_CSS_UNDECLARED_PREFIX",l);else s.tagSelector(this.defaultNamespaceURI,l.text),r?this.actions=Le:this.actions=be,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=He,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=Le:this.actions=be,a.consume();break;case 36:s.tagSelector(null,null),r?this.actions=Le:this.actions=be,a.consume();break;default:this.actions=Ze,s.error("E_CSS_NAMESPACE",l)}else s.tagSelector(this.defaultNamespaceURI,null),r?this.actions=Le:this.actions=be,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=Le:this.actions=be,a.consume();continue;case 7:l.precededBySpace&&s.descendantSelector();case 8:s.classSelector(l.text),r?this.actions=Le:this.actions=be,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=Le:this.actions=be;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=be:this.actions=He;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=Le:this.actions=be:this.actions=He;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=Le:this.actions=be;continue}break}s.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=Ze;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=Le:this.actions=be,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=Le:this.actions=be,a.consume();continue}break}s.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=Ze;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=He,s.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(c=p&&this.namespacePrefixToURI[p],c===void 0){this.actions=He,s.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=He,s.error("E_CSS_ATTR_NAME_EXPECTED",l);continue}p=l.text,a.consume(),l=a.token()}else c="";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(c,p,0,null),r?this.actions=Le:this.actions=be,a.consume();continue;default:this.actions=He,s.error("E_CSS_ATTR_OP_EXPECTED",l);continue}switch(l.type){case 1:case 2:s.attributeSelector(c,p,f,l.text),a.consume(),l=a.token();break;default:this.actions=He,s.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=He,s.error("E_CSS_ATTR",l);continue}r?this.actions=Le:this.actions=be,a.consume();continue;case 11:s.childSelector(),this.actions=At,a.consume();continue;case 12:s.adjacentSiblingSelector(),this.actions=At,a.consume();continue;case 56:s.followingSiblingSelector(),this.actions=At,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=_e,a.consume();continue;case 41:s.nextSelector(),this.actions=ot,a.consume();continue;case 15:h.push(B(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new Yu(l.text)),a.consume();continue;case 17:h.push(new xt(l.num)),a.consume();continue;case 18:h.push(new ze(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 ht(Ne(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new Zu(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(Fn),a.consume();continue;case 24:p=l.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=je,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 Ki("+")),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?xo:_e;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 qe(s.getScope(),Fs(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 zl(s.getScope(),!0,u.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=u),h.push(new zl(s.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==tn&&h[h.length-1]!==nn&&(u.type===10||u.type===6)){h.push(-Dr),a.consume();continue}else h.push(new qe(s.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 Ke(s.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 br(s.getScope(),l.num,p)),a.consume(),this.actions=ve;continue;case 34:h.push(new Ke(s.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 Wu(s.getScope(),l.num)),a.consume(),this.actions=ve);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=je,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==nn&&h[h.length-2]!==-Dr?(this.actions=je,this.exprStackReduce(tn,l),h.push(tn),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==tn&&h[h.length-2]!==-Dr?(this.actions=je,this.exprStackReduce(nn,l),h.push(nn),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=Me),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=_e)),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=_e,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=_e,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let x=this.readSupportsTest(l);if(x){h.push(x),this.actions=ve;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=_e,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=je,h.push("{");continue}s.error("E_CSS_IMPORT_SYNTAX",l),this.actions=Ze;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=Ze;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=Ze;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=At;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=je,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=je,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=je,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,b=null,v=[];for(l.type==1&&(x=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(b=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;)v.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,b,v);break;case"-epubx-partition":s.startPartitionRule(x,b,v);break;case"-epubx-partition-group":s.startPartitionGroupRule(x,b,v);break}this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":s.error(`E_CSS_UNEXPECTED_AT${p}`,l),this.actions=He;continue;default:s.error(`E_CSS_AT_UNKNOWN ${p}`,l),this.actions=Ze;continue}s.error(`E_CSS_AT_SYNTAX ${p}`,l),this.actions=Ze;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=_e;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=_e),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=_e),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===He)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=be;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=He;continue}if(this.actions!==Ze&&this.actions!==He&&this.actions!==at){if(l.type==54)s.error("E_CSS_SYNTAX",l);else if(this.actions===Me){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new Ki(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==je&&h.length>0){s.startMediaRule(h.pop()),this.ruleStack.push("media"),s.startRuleBody(),this.actions=_e,a.consume();continue}else{if(l.type===17&&this.actions==je)return this.actions=_e,a.consume(),!1;s.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=at:this.actions=He;continue}a.consume();continue}}return!1}},zc=class extends Ya{constructor(e){super(null),this.scope=e}error(e,t){G.warn(e,t.toString())}getScope(){return this.scope}};function $m(e,t,i,n,r){let o=Vc(t),s=Xg(e.input);return s!==e.input?lh(new Vt(s,o),o,i,n,r):lh(e,o,i,n,r)}function lh(e,t,i,n,r){let o=_("parseStylesheet"),s=new Pr(_e,e,t,i),a=null;return r&&(a=Gm(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=Ne(s.importURL,i);s.importCondition&&(t.startMediaRule(s.importCondition),t.startRuleBody());let u=_("parseStylesheet.import");return Uc(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 Za(e,t,i,n,r){let o=Vc(t);return Sn("parseStylesheetFromText",s=>{let a=new Vt(e,o);$m(a,o,i,n,r).thenFinish(s)},(s,a)=>{G.warn(a,`Failed to parse stylesheet text: ${e}`),s.finish(!1)})}function Vc(e){if(e instanceof Ws)return e;if(e instanceof Gi){if(e.owner)return e.owner;let t=new Ws;return t.flavor=e.flavor,t.slave=e,e.owner=t,t}return e}function Uc(e,t,i,n){return Sn("parseStylesheetFromURL",r=>{qo(e).then(o=>{o.responseText?Za(o.responseText,t,e,i,n).then(s=>{s||G.warn(`Failed to parse stylesheet from ${e}`),r.finish(!0)}):r.finish(!0)})},(r,o)=>{G.warn(o,"Exception while fetching and parsing:",e),r.finish(!0)})}function Nr(e,t,i){let n=new Pr(Me,t,new zc(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function Wm(e,t,i){new Pr(xo,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Gm(e,t,i){let n=new Pr(je,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var jm={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function Xm(e){return!!jm[e]}function qm(e,t,i){if(t instanceof Fe&&t.str==="viv-leader")return new W(t);if(i==="content"&&t instanceof Fe)return new W(t);let n=t.evaluate(e);switch(typeof n){case"number":return Xm(i)?n==Math.round(n)?new ze(n):new xt(n):new R(n,"px");case"string":return n?i==="content"?new X(n):Nr(t.scope,new Vt(n,null),""):Y;case"boolean":return n?y._true:y._false;case"undefined":return Y}throw new Error("E_UNEXPECTED")}var Ym="data-vivliostyle-flow-root";function Zm(e){return e.getAttribute(Ym)==="true"}function hh(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 Yo(e){return e===y.absolute||e===y.fixed}function So(e){return e instanceof $i&&e.name==="running"}function Hc(e,t,i,n){return e===y.none||(Yo(t)?(i=y.none,e=hh(e)):(i&&i!==y.none&&!Z(i)||n)&&(e=hh(e))),{display:e,position:t,float:i}}function $c(e,t,i,n){return Hc(e,t,i,n).display===y.block}function Zo(e){return e instanceof ce||e instanceof ee||typeof e=="string"}function Dt(e){if(!Zo(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 $n(e){return Zo(e)?e.toString().includes("list-item"):!1}function Km(e){if(!Zo(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 Wc(e){if(!Zo(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 Jm(e,t,i,n,r,o,s){return r=r||o||y.horizontal_tb,!!s||!!i&&i!==y.none&&!Z(i)||Yo(t)||e===y.inline_block||e===y.table_cell||e===y.table_caption||e==y.flex||e==y.grid||e==y.flow_root||(e===y.block||e===y.list_item)&&!!n&&n!==y.visible&&n!==y.clip&&!Z(n)||!!o&&r!==o}function Qm(e){return e===y.relative||e===y.absolute||e===y.fixed}var Gt=1e5;function Ka(e){let t=e.element.style;t.columnGap=`${Gt-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function Ko(e){let t=("element"in e?e.element:e).style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function Co(e){return e.element.style.columnCount==="1"}function ew(e){e.element.setAttribute("data-vivliostyle-column","true")}function hr(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/Gt)}function Gc(e,t){let i=hr(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/Gt),o=r*Gt,s=i*Gt;return t?(e.top-=o,e.bottom-=s,e.bottom<e.top&&(e.bottom+=Gt),e.right-=o,e.left-=s):e.left<-Gt/2?(e.right+=o,e.left+=s,e.left>e.right&&(e.left-=Gt),e.top+=o,e.bottom+=s):(e.left-=o,e.right-=s,e.right<e.left&&(e.right+=Gt),e.top+=o,e.bottom+=s),e.width=e.right-e.left,e.height=e.bottom-e.top,r}function Gs(e,t){for(let i=0;i<e.length;i++)Gc(e[i],t)}function Et(e,t,i){let n=e.getElementClientRect(t);if(Gc(n,i)>0&&e.getElementComputedStyle(t).display.startsWith("table")&&!Jo(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return Ko(r),e.getElementClientRect(t)}return n}function tw(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 js(e){let t=e.style;return t?!isNaN(parseFloat(t.columnCount))||!isNaN(parseFloat(t.columnWidth)):!1}function iw(e){if(!e.hasAttribute("data-vivliostyle-column")&&js(e))return!0;for(let t of e.querySelectorAll("*"))if(!t.hasAttribute("data-vivliostyle-column")&&js(t))return!0;return!1}function Jo(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(js(t))return t;if(i.position==="absolute")break}return null}function nw(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=Jo(i);if(!a)return;let h=a.ownerDocument.defaultView.getComputedStyle(a),{writingMode:l,direction:u,columnGap:c,fontSize:p}=h,f=l==="vertical-rl"||l==="vertical-lr",g=u==="rtl",m=(parseFloat(c)||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=`${Gt}px`)}function zr(e){let t=e.element.lastElementChild,i=t&&e.clientLayout.getElementClientRect(t);return i?hr(i,e.vertical):0}function jc(e,t){if(e.getAttribute("data-viv-saved-column-fill")!=="auto"||zr(t))return;let i=t.clientLayout.getElementComputedStyle(e),n=parseFloat(i.blockSize);e.style.columnFill="auto";let r=parseFloat(i.blockSize),o=NaN;if(e.style.blockSize=`${r}px`,zr(t)){if(e.style.blockSize=`${n}px`,!zr(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`,zr(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 rw(e){let t=e.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let i of t)jc(i,e)}function rn(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&&Dt(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];Gs(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=Et(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);Gs(l,n);let u=l.filter(c=>c.right>c.left&&c.bottom>c.top);if(u.length>0)l=u;else{let c=o?t.getElementComputedStyle(o).whiteSpace:"";l=c==="pre"||c==="pre-wrap"||c==="pre-line"||c==="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(c=>c.left)):s=Math.max.apply(null,l.map(c=>c.bottom)),s):NaN}}function Xs(e,t,i){let n=Co(t);n&&Ko(t);let r=t.clientLayout.getElementClientRect(e);n&&Ka(t);let o=t.getComputedMargin(e);return i?r.width+o.left+o.right:r.height+o.top+o.bottom}function un(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function Xc(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 kn="data-adapt-spec";function Ja(e){return!!e.getAttribute(kn)}function ci(e){return e?.nodeType!==1?!1:Ja(e)?!0:qc(e)}function qc(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 uh(e){var t;return e?.nodeType!==1?!1:((t=e.style)==null?void 0:t.position)==="fixed"}function cn(e){let t=e?.viewNode;return t?.nodeType===1&&Ja(t)}function ow(e){return e!=="inline"&&(Dt(e)||Wc(e))}function ch(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))&&Dt(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 Yc(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 Zc(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 Kc={"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"}]}},aw=Yc(Kc,!0);function Jc(e,t,i){return Zc(e,t,i||null,aw)}var lw=Yc(Kc,!1);function Qc(e,t,i){return Zc(e,t,i||null,lw)}var hw={"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 uw(e,t){let i=hw[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 Qa(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 c={};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"),c[p]=parseFloat(f)}return c}function dn(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 ed(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function td(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function mt(e,t){let i=ed(e);i.includes(t)||(i.push(t),td(e,i))}function cw(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function dw(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function ms(e,t){let i=cw(e);i.includes(t)||(i.push(t),dw(e,i))}function pw(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===y.always?y.page:i,important:e.important};default:return e}}var qs={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Xe(e){return!!qs[e]}var fw={left:!0,right:!0,recto:!0,verso:!0};function En(e){return!!fw[e]}function dh(e){return Xe(e)&&e!=="column"&&e!=="region"}var gw={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function ko(e){return!!gw[e]}function tt(e,t){if(e)if(t){if(En(t))return t;if(En(e))return e;{let i=Xe(e),n=Xe(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:ko(t)?t:ko(e)?e:t}}else return e;else return t}function ph(e){return Xe(e)?e:"auto"}Nt("SIMPLE_PROPERTY",pw);var Qn=Ff(Lf());function mw(e,t){return(0,Qn.default)(e,t,0)}function fh(e){return e.reduce((t,i)=>i[0]===Qn.default.DELETE?t:t+i[1],"")}function ww(e,t){return id(e,t,1)}function yw(e,t){return id(e,t,-1)}function id(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 Qn.default.INSERT:n++;break;case Qn.default.DELETE:n--,r++;break;case Qn.default.EQUAL:r++;break}if(r>t)return!0}return!1}),Math.max(Math.min(t,r-1)+n,0)}var Ys;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(Ys||(Ys={}));var yn;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(yn||(yn={}));var Eo;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Eo||(Eo={}));var _i;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||xi.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||xi.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(_i||(_i={}));var xi;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(xi||(xi={}));var si;(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={}))})(si||(si={}));var vw={transform:!0,"transform-origin":!0},bw={top:!0,bottom:!0,left:!0,right:!0},el=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},xw={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 Sw(e,t){let i=xw[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Zs=class Wn extends Va{constructor(t,i){super(),this.container=t,this.bleedBox=i,d(this,"pageAreaElement",null),d(this,"delayedItems",[]),d(this,"hrefHandler"),d(this,"elementsById",{}),d(this,"dimensions",{width:0,height:0}),d(this,"isFirstPage",!1),d(this,"isLastPage",!1),d(this,"isBlankPage",!1),d(this,"isAutoPageWidth",!0),d(this,"isAutoPageHeight",!0),d(this,"spineIndex",0),d(this,"position",null),d(this,"offset",-1),d(this,"side",null),d(this,"fetchers",[]),d(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),d(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(Wn.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Wn.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(Wn.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Wn.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||N(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=Sw(a,s.action);if(l)for(let u=0;u<h.length;u++)h[u].addEventListener(s.event,l,!1)}}}};d(Zs,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),d(Zs,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var nd=Zs,dt=si.Whitespace;function rd(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 Ve(e,t){return e?e.nodeType==1?!1:od(e.textContent,t):!0}function od(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 Cw=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,d(this,"forcedBreakOffsets",[]),d(this,"formattingContext",null)}},kw=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,d(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function Ew(e,t){return e.top-t.top}function Pw(e,t){return t.right-e.right}function sd(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===si.ShadowType.ROOTLESS&&t.shadowType===si.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&Ks(e.shadowContext,t.shadowContext)&&Ks(e.nodeShadow,t.nodeShadow)&&sd(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(!sd(e.steps[i],t.steps[i]))return!1;return!0}function Nw(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 Po(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 No(e,t){let i=new on(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?No(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var rt=si.ShadowType,Zr=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,d(this,"subShadow",null),r&&(r.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&Ks(this.parentShadow,e.parentShadow):!1}};function Ks(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Tw=class{constructor(e,t){this.outer=e,this.count=t}},on=class ad{constructor(t,i,n){this.sourceNode=t,this.parent=i,this.boxOffset=n,d(this,"offsetInNode",0),d(this,"after",!1),d(this,"shadowType"),d(this,"shadowContext"),d(this,"nodeShadow",null),d(this,"shadowSibling",null),d(this,"shared",!1),d(this,"inline",!0),d(this,"overflow",!1),d(this,"breakPenalty"),d(this,"display",null),d(this,"floatReference"),d(this,"floatSide",null),d(this,"clearSide",null),d(this,"floatMinWrapBlock",null),d(this,"columnSpan",null),d(this,"captionSide","top"),d(this,"inlineBorderSpacing",0),d(this,"blockBorderSpacing",0),d(this,"flexContainer",!1),d(this,"whitespace"),d(this,"hyphenateCharacter"),d(this,"breakWord"),d(this,"establishesBFC",!1),d(this,"containingBlockForAbsolute",!1),d(this,"breakBefore",null),d(this,"breakAfter",null),d(this,"viewNode",null),d(this,"clearSpacer",null),d(this,"inheritedProps"),d(this,"vertical"),d(this,"direction"),d(this,"firstPseudo"),d(this,"lang",null),d(this,"preprocessedTextContent",null),d(this,"formattingContext"),d(this,"repeatOnBreak",null),d(this,"pluginProps",{}),d(this,"fragmentIndex",1),d(this,"afterIfContinues",null),d(this,"footnotePolicy",null),d(this,"pageType"),this.shadowType=rt.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=yn.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=yn.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 ad(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===si.ShadowType.ROOTLESS&&(r.floatReference!==yn.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?yw(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}},Si=class ld{constructor(t){this.primary=t,d(this,"floats",null)}clone(){let t=new ld(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}},Iw=class hd{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new hd(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Aw=class ud{constructor(){d(this,"positions",[]),d(this,"startBreakType",null),d(this,"breakAfter",null)}clone(){let t=new ud,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}},Fw=class cd{constructor(){d(this,"page",0),d(this,"flows",{}),d(this,"flowPositions",{}),d(this,"isBlankPage",!1),d(this,"highestSeenOffset",0),d(this,"highestSeenNode"),d(this,"lookupPositionOffset")}clone(){let t=new cd;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&&En(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},dd=class{constructor(e){this.element=e,d(this,"left",0),d(this,"top",0),d(this,"marginLeft",0),d(this,"marginRight",0),d(this,"marginTop",0),d(this,"marginBottom",0),d(this,"borderLeft",0),d(this,"borderRight",0),d(this,"borderTop",0),d(this,"borderBottom",0),d(this,"paddingLeft",0),d(this,"paddingRight",0),d(this,"paddingTop",0),d(this,"paddingBottom",0),d(this,"width",0),d(this,"height",0),d(this,"originX",0),d(this,"originY",0),d(this,"exclusions",null),d(this,"innerShape",null),d(this,"computedBlockSize",0),d(this,"snapWidth",0),d(this,"snapHeight",0),d(this,"snapOffsetX",0),d(this,"snapOffsetY",0),d(this,"vertical",!1),d(this,"rtl",!1),d(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,N(this.element,"top",`${e}px`),N(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,N(this.element,"left",`${e}px`),N(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):Xa(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 Pt(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 Pt(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return cc(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 Pt(e,t,e+i,t+n)}},ur=class extends li{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 ht)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 Fe&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function St(e){return e!=null&&e!==Y&&e!==y.normal&&e!==y.none&&!Z(e)}var Pe=yn.FloatReference,Rw=20;function Lw(e){switch(e){case"inline":return Pe.INLINE;case"column":return Pe.COLUMN;case"region":return Pe.REGION;case"page":return Pe.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function vi(e){switch(e){case Pe.INLINE:return!1;case Pe.COLUMN:case Pe.REGION:case Pe.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function ws(e,t,i,n){let r=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=Qc(e,r,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let o=Jc(e,r,i),s=uw(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"&&(G.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var pd=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,d(this,"order",null),d(this,"id",null),d(this,"insidePageFloatArea",!1),d(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}},Ow=class{constructor(){d(this,"floats",[]),d(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 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}},fd=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}},gh=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}},sn=class{constructor(e,t,i,n,r,o,s){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=r,d(this,"children",[]),d(this,"writingMode"),d(this,"direction"),d(this,"invalidated",!1),d(this,"floatStore"),d(this,"forbiddenFloats",[]),d(this,"floatFragments",[]),d(this,"stashedFloatFragments",[]),d(this,"floatAnchors",{}),d(this,"floatsDeferredToNext",[]),d(this,"floatsDeferredFromPrevious"),d(this,"layoutConstraints",[]),d(this,"locked",!1),d(this,"footnoteMaxBlockSize",null),d(this,"ignoreFootnoteAreaMaxHeight",!1),d(this,"footnoteAnchorsSeen",new Set),d(this,"outerContext",null),e&&e.children.push(this),this.writingMode=!Z(o)&&o||e&&e.writingMode||y.horizontal_tb,this.direction=!Z(s)&&s||e&&e.direction||y.ltr,this.floatStore=e?e.floatStore:new Ow;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&&Vi(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 Pn().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&&iw(n)}))}hasMultiColumnFootnoteContext(){return this.hasRootMultiColumnFootnoteContext()||this.hasNonRootMultiColumnFootnoteContext()}trySetFootnoteRetryMaxBlockSize(e){let t=this.footnoteMaxBlockSize!=null?this.footnoteMaxBlockSize/2:e/2;return t<Rw?!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===Pe.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;if(this.floatReference===Pe.PAGE&&"footnotePolicy"in t&&t.footnotePolicy===y.line&&this.footnoteAnchorsSeen.has(t.getId())){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 Qc(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return Jc(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 c=this.parent.getLimitValue(a,l,i,n,r,o);switch(a){case"top":return Math.max(u,c);case"left":return Math.max(u,c);case"bottom":return Math.min(u,c);case"right":return Math.min(u,c);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,c=this.container.getPaddingRect(),p={top:c.y1-u,left:c.x1-l,bottom:c.y2-u,right:c.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,b]=this.toLogicalFloatSides(w.floatSide);if(b&&(n&&b.includes("block")===n.includes("block")&&b!==n||r&&b.includes("block")===r.includes("block")&&b!==r))return m;let v=w.area,C=w.continuations[0].float.floatMinWrapBlock,S=v.vertical?v.left+v.getInsetLeft()+v.width+v.getInsetRight():v.top+v.getInsetTop()+v.height+v.getInsetBottom(),F=v.vertical?v.top+v.getInsetTop()+v.height+v.getInsetBottom():v.left+v.getInsetLeft()+v.width+v.getInsetRight(),A=m.top,D=m.left,H=m.bottom,q=m.right,Se=m.floatMinWrapBlockStart,se=m.floatMinWrapBlockEnd;switch(x){case"inline-start":v.vertical?A=Math.max(A,F):D=Math.max(D,F);break;case"block-start":v.vertical?(C&&v.left<q&&(Se=f(C,v.rootViewNodes[0],c.x2-c.x1)),q=Math.min(q,v.left)):(C&&S>A&&(Se=f(C,v.rootViewNodes[0],c.y2-c.y1)),A=Math.max(A,S));break;case"inline-end":v.vertical?H=Math.min(H,v.top):q=Math.min(q,v.left);break;case"block-end":v.vertical?(C&&S>D&&(se=f(C,v.rootViewNodes[0],c.x2-c.x1)),D=Math.max(D,S)):(C&&v.top<H&&(se=f(C,v.rootViewNodes[0],c.y2-c.y1)),H=Math.min(H,v.top));break;default:throw new Error(`Unknown logical float side: ${x}`)}return{top:A,left:D,bottom:H,right:q,floatMinWrapBlockStart:Se,floatMinWrapBlockEnd:se}},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(S=>S.includes("inline")&&s[S==="inline-start"?"inline-end":"inline-start"]),l=a.find(S=>S.includes("block")),u=this.getLimitValue("block-start",h,e.layoutContext,e.clientLayout),c=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),c=e.vertical?Math.max(c,e.left+g):Math.min(c,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+g));function w(S,F){let A=S(e.bands,F);return A?(e.vertical&&(A=lc(A)),u=e.vertical?Math.min(u,A.x2):Math.max(u,A.y1),c=e.vertical?Math.max(c,A.x1):Math.min(c,A.y2),!0):o}let x,b,v,C;if(r){let S=e.vertical?bo(new Pt(c,p,u,f)):new Pt(p,u,f,c);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!w(Pg,S)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(Ng,S)||(e.isFootnote&&n!==null&&isFinite(n)&&a[0]==="block-end"&&(e.vertical?u=Math.min(u,n):u=Math.max(u,n)),v=(c-u)*e.getBoxDir(),e.isFootnote&&this.footnoteMaxBlockSize!=null&&(v=Math.min(v,this.footnoteMaxBlockSize),e.vertical?u=c+v:u=c-v),x=Math.max(0,v-e.getInsetBefore()-e.getInsetAfter()),C=(f-p)*e.getInlineDir(),b=C-e.getInsetStart()-e.getInsetEnd(),!o&&(x<=0||b<=0)))return null}else{let S=e.getContentBlockMarginAfter();x=Math.max(0,e.computedBlockSize+Math.min(0,S)),v=x+e.getInsetBefore()+e.getInsetAfter();let F=(c-u)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let D=this.container.getPaddingRect(),H=this.container.getBoxDir()*(n-(this.container.vertical?D.x2:D.y1)),q=this.container.getBoxDir()*((this.container.vertical?D.x1:D.y2)-n-v);H<=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&&F<v)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?b=Qa(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?b=e.getContentInlineSize():b=e.vertical?e.height:e.width,C=b+e.getInsetStart()+e.getInsetEnd();let A=(f-p)*e.getInlineDir();if(!o&&A<C)return null}return u-=g,c-=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,b):(a.some(S=>S==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-C*e.getInlineDir(),b),a.some(S=>S==="block-start"||S==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(u,x):(a.some(S=>S==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(c-v*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(c){return p=>(!c||p.floatSide.includes(c))&&p.getOrder()<a}function l(c,p){return c.children.some(f=>f.floatFragments.some(h(p))||l(f,p))}function u(c,p){let f=c.parent;return!!f&&(f.floatFragments.some(h(p))||u(f,p))}if(i==="column"||i==="region"||i==="page"){for(let c=this;c;c=c.parent)if(c.floatReference===i){(c.floatFragments.some(h(null))||l(c,null))&&(n["block-start"]=!1,n["block-end"]=!1,n["inline-start"]=!1,n["inline-end"]=!1);break}return n}return s.forEach(c=>{switch(c){case"block-start":n[c]=!l(this,c);break;case"block-end":n[c]=!u(this,c);break;case"inline-start":case"inline-end":n[c]=!this.floatFragments.some(h(c));break;default:throw new Error(`Unexpected side: ${c}`)}}),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}},_n=[],Pn=class{static register(e){_n.push(e)}findByNodeContext(e){for(let t=_n.length-1;t>=0;t--){let i=_n[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=_n.length-1;t>=0;t--){let i=_n[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},Bw=class{appliesToNodeContext(e){return vi(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 pd(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 fd(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){}};Pn.register(new Bw);var gd="data-vivliostyle-footnote-first-ref",md="data-vivliostyle-footnote-referenced";function To(e,t){return!!(e&&e.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function yt(e){if(e.localName!=="aside")return!1;if(To(e.getAttribute("role"),"doc-footnote"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return To(t,"footnote")}function Lt(e){if(e.localName!=="a")return!1;if(To(e.getAttribute("role"),"doc-noteref"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return To(t,"noteref")}function tl(e,t){if(!Lt(e))return null;let i=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!i)return null;let n=yo(i,t);return n==="#"?null:n}function wd(e,t,i){let n=tl(e,t);if(!n)return null;let r=i(n);return r&&yt(r)?r:null}function Mw(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=tl(a,t);!h||n.has(h)||n.set(h,i(a))}r.value=!0}function mh(e,t,i,n,r){if(e.localName!=="a"||!Lt(e))return!0;let o=tl(e,t);if(!o)return!0;Mw(e.ownerDocument,t,i,n,r);let s=n.get(o);return s==null||i(e)===s}function il(e,t){let i=t.getProp(e,"footnote-display");if(i)return i;let n=t.getProp(e,"display");return n?.value===y.inline?t.createCascadeValue(y.inline,n.priority):null}function _w(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)||!Lt(a))return t;let h=wd(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 c={...t},p=il(u,s),f=s.getProp(u,"footnote-policy"),g=s.getStyleMap(u,"_pseudos"),m=g?.after;if(p&&(c["footnote-display"]=p),f&&(c["footnote-policy"]=f),m){let w=s.getMutableStyleMap(c,"_pseudos");w.after={...m}}return c}function Dw(e,t,i,n,r){var o;if(!(i?.type===rt.ROOTED&&yt(e)))return t;let s=r.getStyle(e);if(!s)return t;let a={...t},h=il(s,r),l=r.getProp(s,"footnote-policy"),u=r.getStyleMap(s,"_pseudos"),c=u?.["footnote-marker"],p=r.getProp(c,"content"),f=r.getProp(c,"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"))===y.outside){let g=r.filterFootnoteMarkerContent(p,e);a["--viv-marker-content"]=r.createCascadeValue(g,0),a.display=r.createCascadeValue(B("list-item"),0),a["list-style-position"]=r.createCascadeValue(y.outside,0),a["list-style-type"]=r.createCascadeValue(y.none,0),a["list-style-image"]=r.createCascadeValue(y.none,0)}return a}function zw(e,t,i){var n,r;let o=t?.type===rt.ROOTED&&yt(e)?i.getStyle(e):null;return{sourceStyle:o,footnoteDisplay:((n=il(o,i))==null?void 0:n.value)||null,footnotePolicy:((r=i.getProp(o,"footnote-policy"))==null?void 0:r.value)||null}}function yd(e,t){if(e instanceof W){let i=e.expr.evaluate(t);return typeof i=="string"?new X(i):typeof i=="number"?new X(String(i)):e}return e instanceof ee?new ee(e.values.map(i=>yd(i,t))):e}function Vw(e,t,i){let n=e?.["_footnote-marker-content"];n&&(t["--viv-marker-content"]=yd(n.value,i))}function Uw(e){let t=e.getElementsByTagName("a"),i=new Set;for(let n=0;n<t.length;n++){let r=t.item(n);if(!Lt(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&&yt(s)){let a=r.baseURI.replace(/#.*$/,"")+r.hash;i.has(a)||(i.add(a),r.setAttribute(gd,"true")),s.setAttribute(md,"true")}}}Nt("PREPROCESS_SINGLE_DOCUMENT",Uw);var Hw=fd,Io=class vd extends pd{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 vd)}};function $w(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 wh=class extends Hw{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof Io?!0:this.getOrder()<e.getOrder()}},Ww=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}},Gw=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof Io}createPageFloat(e,t,i){var n;let r=Pe.REGION,o=t.getPageFloatLayoutContext(r);t.getPageFloatLayoutContext(Pe.PAGE).hasSameContainerAs(o)&&(r=Pe.PAGE);let s=!!t.generatingNodePosition;s&&r!==Pe.PAGE&&(r=Pe.PAGE);let a=e.toNodePosition();t.flowName;let h=e.sourceNode,l=(n=e.shadowContext)==null?void 0:n.owner;l instanceof Element&&Lt(l)&&(h=l),h=$w(h);let u=new Io(a,r,t.flowName,e.footnotePolicy,e.floatMinWrapBlock,h);if(u.insidePageFloatArea=s,s){let c=t.generatingNodePosition;c&&(u.parentPageFloat=t.findPageFloatByNodePosition(c))}return t.addPageFloat(u),T(u)}createPageFloatFragment(e,t,i,n,r){let o=e[0].float;return new wh(o.floatReference,e,n,r)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof wh);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 c of l){let p=u.getPropertyValue(c);if(p&&p!=="none"){let f=parseFloat(p);isNaN(f)||N(n,c,`${Math.max(0,f-h)}px`)}}N(n,"box-sizing","content-box")}let a=i.pageFloatLayoutContext;for(;a;){if(a.ignoreFootnoteAreaMaxHeight){N(n,"max-block-size",""),N(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 y.line:{let n=new Ww(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Pn.register(new Gw);var nl=class{calculateOffset(e){return vn(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function vn(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var Tr=class extends nl{constructor(e,t,i,n){super(),this.position=e,this.breakOnEdge=t,this.overflows=i,this.computedBlockSize=n,d(this,"overflowIfRepetitiveElementsDropped"),d(this,"isEdgeUpdated",!1),d(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(ko(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=rn(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(!_i.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},Dn=class{find(e){let t=Ot("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()}`)}},pn=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 Tr(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===si.ShadowType.ROOTLESS&&cn(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;Xc(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)}},rl=class{constructor(e){this.parent=e,d(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},ol=new pn,jw=Ys.isInstanceOfBlockFormattingContext;Nt("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&&$c(i,n,r,o)?new rl(s?s.formattingContext:null):null});Nt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof rl?ol:null);var sl=class{constructor(){d(this,"initialBreakPositions",null),d(this,"initialStateOfFormattingContext",null),d(this,"initialPosition"),d(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=_("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)}},Xw=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){}},Js=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=_("LayoutIterator");return n.loopWithFrame(r=>{let o;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Ve(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()}},er=class extends Xw{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&&Xe(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)))}},Qs=[];function qw(){Qs=[]}function bd(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var Yw=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},Zw=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},xd=class Kr{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let r=Kr.fragmentIndices;(!r[t]||r[t].priority<=n)&&(r[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){Kr.fragmentIndices={}}matches(){let t=Kr.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&bd(t.fragmentIndex,this.a,this.b)}};d(xd,"fragmentIndices",{});var Qo=xd,Vr=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new Qo(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new Zw(e)}static buildAnyMatcher(e){return new Yw(e)}},Sd={"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},Kw=["image-resolution","orphans","widows"];function Jw(){return Ot("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(Kw))}var Qw={"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},ea=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],ey=["max-%","min-%","%"],yh=(()=>{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<ea.length;i++)for(let n=0;n<e.length;n++){let r=ea[i].replace("%",e[n]);t[r]=!0}return t})();function Rn(e,t){let i={};for(let n of ea)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 ey)for(let r in t){let o=n.replace("%",r),s=n.replace("%",t[r]);i[o]=s,i[s]=o}return i}var Cd=Rn({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),kd=Rn({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),ty=Rn({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),iy=Rn({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),ny=Rn({inside:"right",outside:"left"},{}),ry=Rn({inside:"left",outside:"right"},{}),V=class ta{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 ta(i,this.priority)}increaseSpecificity(t){return t==0?this:new ta(this.value,this.priority+t)}evaluate(t,i,n,r){return i&&Zt(i)?this.value:Lo(t,this.value,i,n,r)}isEnabled(t){return!0}},ia=class na 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 na(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new na(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){G.warn(i)}return!1}};function ra(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Ut(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 Ed={"region-id":!0,"fragment-selector-id":!0},tr="data-viv-footnote-counter";function Ao(e){let t=e.getAttribute(tr);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 Pd(e,t,i){let n=Ao(e);n[t]=i,e.setAttribute(tr,JSON.stringify(n))}function oy(e,t){var i,n;if(!Lt(e)||e.hasAttribute(gd))return null;let r=Ao(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=yo(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=Ao(l)[t];return u?(Pd(e,t,u),u):null}function sy(e){let t=ge(e,"content");return!!t&&St(t.value)}function ay(e){return!!Ed[e]}function Jr(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Mi(e){return e.charAt(0)!=="_"&&!Ed[e]}function fn(e){return!!Sd[e]||Zt(e)}function ge(e,t){return e[t]}function bi(e,t,i){i?e[t]=i:delete e[t]}function pt(e,t){return e[t]}function Kt(e,t){let i=e[t];return i||(i={},e[t]=i),i}var Nd=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function Td(e,t){return e[t]}function Id(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function Fo(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=Kt(t,l.styleKey);t=u[l.id],t||(t={},u[l.id]=t)}}),s){let l=Nd(t);t={},l.push({styles:t,matcher:s})}for(let l in i)if(!Jr(l))if(ay(l)){let u=Td(i,l),c=Id(t,l);Array.prototype.push.apply(c,u)}else{let u=ge(i,l);if(!u.isEnabled(e))continue;let c=u.increaseSpecificity(n);Ut(t,l,c,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,c.priority);Ut(t,f,g,e)}}}function ly(e,t){let i={};for(let n=0;n<t.length;n++)Fo(e,i,t[n],0,null,null,null);return i}function al(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 hy=class extends Hi{constructor(e,t){super(),this.props=e,this.context=t,d(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=ge(this.props,"font-size");if(!e.value.isNumeric())return zt.em;let t=e.value;if(!Jf(t.unit))throw new Error("Unexpected state");return t.num*zt[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?oa(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?ll(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Lo(this.context,e,this.propName).visit(this):e}};function ll(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 oa(e,t,i){e=ll(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 Ln=class{apply(e){}mergeWith(e){return new uy([this,e])}clone(){return this}},Ur=class extends Ln{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},uy=class Ad extends Ln{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 Ad([].concat(this.list))}},hl=class extends Ln{constructor(e,t,i,n,r){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=r}apply(e){Fo(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},xe=class extends Ln{constructor(){super(),d(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},cy=class extends xe{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}},dy=class extends xe{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}},vh=class extends xe{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}},py=class extends xe{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}},fy=class extends xe{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)}}}},gy=class extends xe{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function es(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 bh=class extends xe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){es(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},my=class extends xe{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){es(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}},wy=class extends xe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){es(e.currentElement,this.ns,this.name,(t,i,n)=>!!Qw[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},zn=class extends xe{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){es(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)}},yy=class extends xe{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},xh=class extends xe{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},vy=class extends xe{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},ji=class extends xe{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return bd(e,this.a,this.b)}},by=class extends ji{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},sa=class extends ji{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}},aa=class extends ji{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}},la=class extends ji{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}},xy=class extends xe{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}},Sy=class extends xe{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},Cy=class extends xe{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},ky=class extends xe{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},et=class extends xe{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}},Fd=class Rd extends Ln{constructor(){super(),d(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new Rd;return t.applied=this.applied,t}},ul=class extends xe{constructor(e){super(),d(this,"checkAppliedAction"),d(this,"firstActions",[]),this.checkAppliedAction=new Fd;for(let t of e)this.firstActions.push(al(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 xe?e.getPriority():0))}positive(){return!0}relational(){return!1}},Ey=class extends ul{positive(){return!1}},Py=class extends ul{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}},Ld=class extends ji{constructor(e,t,i){super(e,t),d(this,"checkAppliedAction"),d(this,"firstActions",[]),this.checkAppliedAction=new Fd;for(let n of i)this.firstActions.push(al(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 c of this.firstActions)if(c.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}},Ny=class extends Ld{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}},ts=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)}},Ty=class Od extends ts{constructor(t,i,n){super(t,i,n)}fresh(t){return new Od(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}},Iy=class Bd extends ts{constructor(t,i,n){super(t,i,n)}fresh(t){return new Bd(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)}},Ay=class Md extends ts{constructor(t,i,n){super(t,i,n),d(this,"fired",!1)}fresh(t){return new Md(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)}},Fy=class _d extends ts{constructor(t,i,n){super(t,i,n),d(this,"fired",!1)}fresh(t){return new _d(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}},Ry=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}},Ly=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}},Oy=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}},By=class extends Hi{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new ht(e):new ht("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 ee){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 Ro(e,t){if(St(e)){if(e instanceof X)return e.stringValue();if(e instanceof W&&t){let i=e.expr.evaluate(t);return typeof i=="string"?i:typeof i=="number"?String(i):""}if(e instanceof ee)return e.values.map(i=>Ro(i,t)).join("")}return""}var cr=class extends Hi{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=Ro(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 ri;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 c=typeof r=="string",p=w=>c?this.formatCounterList(w,r,i):this.formatLastValue(w,i),f=w=>{this.pseudoName==="footnote-call"&&this.element&&Pd(this.element,t,w)};if(this.pseudoName==="footnote-call"&&this.element){let w=oy(this.element,t);if(w)return p(w)}if(this.pseudoName==="footnote-marker"&&this.element){let w=Ao(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])||[],b=x.length?x[x.length-1]:0,v=w.length?w[0]:0,C=m.length?m[0]:0,S=b+(C-v);return g=m.length?[S,...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 Fe(h,()=>this.buildCounterText(o,i,n,r),a?`page-counter-${i}`:`counter-${i}`);if(a&&o!=null&&o.registerPageCounterExpr){let u=c=>this.formatLastValue(c,n);o.registerPageCounterExpr(i,u,l)}return new W(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 W(this.counterResolver.getPageCounterVal(i,h=>this.format(h||0,n)));return new ee([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)),c=this.getPageScope(),p=new Fe(c,()=>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 W(p)}let a=this.cascade.counters[i],h=new ri;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 W(this.counterResolver.getPageCountersVal(i,u=>{let c=[];if(u.length)for(let f=0;f<u.length;f++)c.push(this.format(u[f],r));let p=h.toString();return p.length&&c.push(p),c.length?c.join(n):this.format(0,r)}));return new ee([l])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof ht?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",o=new W(this.counterResolver.getTargetCounterVal(i,n,s=>this.format(s||0,r)));return new ee([o])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof ht?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 W(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 ee([s])}visitFuncTargetText(e){let t=e[0],i;t instanceof ht?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",r=new W(this.counterResolver.getTargetTextVal(i,n));return new ee([r])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new W(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 W(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 c=(t=this.element)==null?void 0:t.querySelectorAll(`[data-adapt-pseudo="${l}"]`),p=null;if(c&&this.element)for(let f=0;f<c.length;f++){let g=c[f];if(g.parentElement===this.element){p=g;break}}if(p)u=p.textContent||"";else{let f=pt(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=Ro(m,this.cascade.context)}}}break;case"first-letter":{let c=pt(this.cascade.currentStyle,"_pseudos"),p=(s=(o=c?.before)==null?void 0:o.content)==null?void 0:s.value,f=(h=(a=c?.after)==null?void 0:a.content)==null?void 0:h.value,g=(this.evaluateAndGetString(p)||this.element.textContent||this.evaluateAndGetString(f)).match(wo);u=g?g[0]:""}break}return new X(u)}visitFuncLeader(e){let t="";if(e[0]instanceof ce)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 W(new Fe(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 ys(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 My=(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){v==="rtl"?g.textContent=(P.startsWith("\u200F")?"":"\u200F")+P+(P.endsWith("\u200F")?"":"\u200F"):g.textContent=P},u=function(){let P=i.clientLayout.getElementClientRect(m);return b==="vertical-rl"||b==="vertical-lr"?v==="rtl"?P.top-=k:P.bottom+=k:v==="rtl"?P.left-=k:P.right+=k,A.left>P.left||A.right<P.right||A.top>P.top||A.bottom<P.bottom},c=function(){let P,I,O=x.repeat(1e4);if(l(O),u())P=1,I=1e4;else return;for(let z=0;z<16;z++){let $="",K=Math.floor((P+I)/2);for(let J=0;J<K;J++)$+=x;if(l($),u())I=K;else{if(P==K)return;P=K}}l(x)},p=function(P){let I=0,O=m.parentElement;for(;O&&O!==f.viewNode;)I+=i.getComputedInsets(O)[P],O=O.parentElement;return I};var r=l,o=u,s=c,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:b,direction:v,marginInlineEnd:C}=i.clientLayout.getElementComputedStyle(m);g.style.marginInlineStart="1px",l(x),m.style.display="inline-block",m.style.textIndent="0";let S=Jo(f.viewNode),F=S?.style.columnFill||null;S&&(S.style.columnFill="auto");let A=i.clientLayout.getElementClientRect(f.viewNode),D=i.clientLayout.getElementClientRect(m),H=i.parseComputedLength(C),q=[],Se=m.parentElement;for(;Se.parentElement&&Se.parentElement!==f.viewNode;)Se=Se.parentElement;let se=Se.nextSibling;for(;se;){if(se.nodeType===1){let P=se,{display:I,float:O,position:z}=i.clientLayout.getElementComputedStyle(P);if(O!=="none"||z==="absolute"||z==="fixed"){se=se.nextSibling;continue}if(Dt(I))q.push(P);else if(Km(I))break}else if(se.nodeType===3){let P=se;P.length>0&&q.push(P)}se=se.nextSibling}let k=q.reduce((P,I)=>P+ys(I,i.clientLayout,b),0);if(w!=="after"){let P=ys(Se,i.clientLayout,b),I=ys(m,i.clientLayout,b);k+=P-I}b==="vertical-rl"||b==="vertical-lr"?(v==="rtl"?A.top+=H:A.bottom-=H,A.top=Math.min(D.top,A.top),A.bottom=Math.max(D.bottom,A.bottom)):(v==="rtl"?A.left+=H:A.right-=H,A.left=Math.min(D.left,A.left),A.right=Math.max(D.right,A.right)),c();let M=i.clientLayout.getElementClientRect(m);v=="rtl"?m.style.float="left":m.style.float="right";let E=i.clientLayout.getElementClientRect(m),L=0;v=="rtl"?b=="vertical-rl"||b=="vertical-lr"?L=M.top-E.top-p("top"):L=M.left-E.left-p("left"):b=="vertical-rl"||b=="vertical-lr"?L=E.bottom-M.bottom-p("bottom"):L=E.right-M.right-p("right"),L-=k,L=Math.max(0,L-.1),m.style.float="",g.style.marginInlineStart=`${L}px`,S&&(F?S.style.columnFill=F:S.style.removeProperty("column-fill"))}};Nt("POST_LAYOUT_BLOCK",My);var cl=1/1048576;function Yi(e,t){for(let i in e)t[i]=e[i].clone()}var _y=class Dd{constructor(){d(this,"nsCount",0),d(this,"nsPrefix",{}),d(this,"tags",{}),d(this,"nstags",{}),d(this,"epubtypes",{}),d(this,"classes",{}),d(this,"ids",{}),d(this,"pagetypes",{}),d(this,"order",0)}clone(){let t=new Dd;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return Yi(this.tags,t.tags),Yi(this.nstags,t.nstags),Yi(this.epubtypes,t.epubtypes),Yi(this.classes,t.classes),Yi(this.ids,t.ids),Yi(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 Dy(this,t,i,n,r,o,s)}nextOrder(){return this.order+=cl}},zd=class Vd{constructor(t,i,n,r,o,s,a){this.context=i,this.counterListener=n,this.counterResolver=r,this.counterStyleStore=s,this.cmykStore=a,d(this,"code"),d(this,"stack",[[],[]]),d(this,"conditions",Object.create(null)),d(this,"currentElement",null),d(this,"currentElementOffset",null),d(this,"currentStyle",null),d(this,"currentClassNames",null),d(this,"currentLocalName",""),d(this,"currentNamespace",""),d(this,"currentId",""),d(this,"currentXmlId",""),d(this,"currentNSTag",""),d(this,"currentEpubTypes",null),d(this,"currentPageType",null),d(this,"previousPageType",null),d(this,"firstPageType",null),d(this,"pageTypePageIndices",Object.create(null)),d(this,"isFirst",!0),d(this,"isRoot",!0),d(this,"counters",Object.create(null)),d(this,"lastCounterChanges",[]),d(this,"lastCounterChangeTypes",Object.create(null)),d(this,"counterScoping",[Object.create(null)]),d(this,"quotes"),d(this,"quoteDepth",0),d(this,"lang",""),d(this,"siblingOrderStack",[0]),d(this,"currentSiblingOrder",0),d(this,"siblingTypeCountsStack",[{}]),d(this,"currentSiblingTypeCounts"),d(this,"currentFollowingSiblingOrder",null),d(this,"followingSiblingOrderStack"),d(this,"followingSiblingTypeCountsStack",[{}]),d(this,"currentFollowingSiblingTypeCounts"),d(this,"viewConditions",Object.create(null)),d(this,"dependentConditions",[]),d(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=Vr.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]:Vr.buildAnyMatcher([].concat(o)):null}).filter(r=>r);return n.length<=0?i:i===null?n.length===1?n[0]:Vr.buildAllMatcher(n):Vr.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=vs,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;let l=new Set,u=Object.create(null),c=y.inline,p=t.display;if(p&&(c=p.evaluate(this.context)),c===y.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=y.inline,g=t.float;g&&(f=g.evaluate(this.context));let m=null,w=null,x=null,b=t["counter-reset"];if(b){let S=b.evaluate(this.context);S&&(m=wn(S,{reset:!0}))}let v=t["counter-set"];if(v){let S=v.evaluate(this.context);S&&(x=wn(S,{defaultValue:0}))}let C=t["counter-increment"];if(C){let S=C.evaluate(this.context);S&&(w=wn(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),$n(c)&&(w||(w=Object.create(null)),w["list-item"]=(r=w["list-item"])!=null?r:1,/^\s*[-+]?\d/.test((s=(o=this.currentElement)==null?void 0:o.getAttribute("value"))!=null?s:"")&&(x||(x=Object.create(null)),x["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===y.footnote&&!this.currentStyle["--viv-semantic-footnote-content"]&&(w||(w=Object.create(null)),w.footnote===void 0)){let S=(h=this.currentStyle["counter-increment"])==null?void 0:h.value;(!S||!(S===y.footnote||S instanceof ee&&S.values.includes(y.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(x)for(let S in x)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 F=this.counters[S];F[F.length-1]+=w[S]}if(x)for(let S in x)if(!this.counters[S])this.defineCounter(S,x[S]);else{let F=this.counters[S];F[F.length-1]=x[S]}if($n(c)){let S=this.counters["list-item"],F=S[S.length-1];t["ua-list-item-count"]=new V(new xt(F),0);let A=Kt(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 cr(this,this.currentElement,this.counterResolver));let n=i.value instanceof it?i.value.values:[i.value];for(let r of n)if(r instanceof ee){let o=r.values[0].stringValue(),s=r.values.slice(1).map(a=>Ro(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 $i&&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 cr(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=vs;let u=i.getAttributeNS("http://www.idpf.org/2007/ops","type");u?this.currentEpubTypes=u.split(/\s+/):this.currentEpubTypes=vs;let c=As(i);c&&(this.stack[this.stack.length-1].push(new Ly(this.lang)),this.lang=c.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 b=this.followingSiblingTypeCountsStack,v=this.currentFollowingSiblingTypeCounts=b[b.length-1];v&&v[this.currentNamespace]&&v[this.currentNamespace][this.currentLocalName]--,b.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 C=n.quotes,S=null;if(C){let D=C.evaluate(this.context);D&&(S=new Oy(this.quotes),D===y.none?this.quotes=[new X(""),new X("")]:D===y.auto||D===y.initial?this.quotes=[new X("\u201C"),new X("\u201D"),new X("\u2018"),new X("\u2019")]:D instanceof ee&&(this.quotes=D.values))}this.pushCounters(this.currentStyle);let F=this.currentId||this.currentXmlId||i.getAttribute("name")||"";if(p||F){let D=Object.create(null);Object.keys(this.counters).forEach(H=>{D[H]=Array.from(this.counters[H])}),this.counterListener.countersOfId(F,D)}let A=pt(this.currentStyle,"_pseudos");if(A){let D=!0;for(let H of zy){H||(D=!1);let q=A[H];if(q){let Se=(o=ge(this.currentStyle,"float"))==null?void 0:o.value,se=i instanceof Element&&Lt(i),k=i instanceof Element&&yt(i),M=!!ge(this.currentStyle,"--viv-semantic-footnote-content"),E=Se===y.footnote,L=(H==="before"||H==="after")&&(E||k||M)&&!!q.content,P=sy(q),I=H==="footnote-call"&&se&&P,O=H==="footnote-marker"&&(k||M)&&P;if((H==="before"||H==="after")&&!(L||St((s=q.content)==null?void 0:s.value)||this.hasNonTrivialViewConditionalPseudoContent(q))||H==="marker"&&!$n((a=ge(this.currentStyle,"display"))==null?void 0:a.value)||(H==="footnote-call"||H==="footnote-marker")&&Se!==y.footnote&&!I&&!O||(H==="footnote-call"||H==="footnote-marker")&&M&&!P)delete A[H];else if(D){if(this.processPseudoelementProps(q,i,H),H==="marker")this.processMarkerPseudoelementProps(q,i,t),delete A[H];else if(H==="footnote-marker"){if(this.resolvePseudoelementInheritedPropertyValue(q,"list-style-position",t,i)===y.outside){this.processMarkerPseudoelementProps(q,i,t);let z=q.content;z&&(this.currentStyle["_footnote-marker-content"]=z),this.currentStyle.display=new V(B("list-item"),0),this.currentStyle["list-style-position"]=new V(y.outside,0),this.currentStyle["list-style-type"]=new V(y.none,0),this.currentStyle["list-style-image"]=new V(y.none,0),delete A[H]}}else if(H==="first-letter"&&q["initial-letter"]){let z=q["initial-letter"].evaluate(this.context);z!==y.normal&&!Z(z)&&(this.currentStyle["--viv-initialLetter"]=new V(z,0)),delete q["initial-letter"]}}else this.stack[this.stack.length-2].push(new Ry(q,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 St((r=n.styles.content)==null?void 0:r.value)})}processMarkerPseudoelementProps(t,i,n){var r,o,s,a,h;let l=$n((r=this.currentStyle.display)==null?void 0:r.value);if(!St((o=t.content)==null?void 0:o.value)&&l){let c=this.getInheritedPropertyValue("list-style-type",n,i),p=this.getInheritedPropertyValue("list-style-image",n,i);if(p instanceof ht)t.content=new V(new ee([p,new X(" ")]),0);else if(c instanceof X)t.content=new V(c,0);else if(c instanceof ce&&c!==y.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=c.name.toLowerCase();g==="disc"||g==="circle"||g==="square"||g==="disclosure-open"||g==="disclosure-closed"||(t.content=new V(new X(this.counterStyleStore.formatMarker(c.name,f)),0))}}}let u=t.content;if(u){let c=u.value;if(St(c)){let p=this.resolveMarkerContentVal(c);this.currentStyle["--viv-marker-content"]=new V(p,0)}}for(let c of Vd.markerAllowedProps){let p=t[c];if(p){let f=p.evaluate(this.context,c);f&&!Z(f)&&(this.currentStyle[`--viv-marker-${c}`]=new V(f,0))}}if(!Dt((h=ge(this.currentStyle,"display"))==null?void 0:h.value)){let c=this.getInheritedPropertyValue("list-style-position",n,i);c&&c!==y.outside&&!Z(c)&&(this.currentStyle["list-style-position"]=new V(c,0))}}resolveMarkerContentVal(t){if(t instanceof W){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 ee){let i=t.values.map(n=>this.resolveMarkerContentVal(n));return new ee(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===y.inherit||h===y.unset||h===y.revert)continue;if(h===y.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!==y.inherit&&a!==y.unset&&a!==y.revert){if(a===y.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)Mi(n)&&!Zt(n)&&(i[n]=i[n].filterValue(t))}applyAttrFilter(t){let i=new By(t),n=this.currentStyle,r=pt(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 Yy(t,i,n),l=32,u={};for(let c in a)if(Jr(c)){let p=pt(a,c);for(let f in p)this.applyVarFilter([p[f],...t],i,n)}else if(Mi(c)){let p=ge(a,c),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[c])==null?void 0:r.clone();if(m)if(Z(f)){for(let w of m.propList){let x=new V(f,p.priority),b=ge(a,w);bi(u,w,ra(this.context,b,x))}delete a[c]}else{let w=Nr(i.scope,new Vt(f.toString(),null),"");if(w&&(w.visit(m),!m.error)){for(let x of m.propList){let b=new V((s=(o=m.values[x])!=null?o:g.defaultValues[x])!=null?s:y.initial,p.priority),v=ge(a,x);bi(u,x,ra(this.context,v,b))}delete a[c]}}else a[c]=new V(f,p.priority)}if(u[c]){let g=ge(a,c);g&&g.value!==Y&&Ut(u,c,g,this.context)}}for(let c in u)a[c]=u[c]}applyCalcFilter(t,i){let n=new qd(i);for(let r in t)if(Jr(r)){let o=pt(t,r);for(let s in o)this.applyCalcFilter(o[s],i)}else if(Mi(r)&&!Zt(r)){let o=ge(t,r),s=o.value.visit(n);s!==o.value&&(t[r]=new V(s,o.priority))}}applyCmykFilter(t,i){let n=new rc(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 o=pt(t,r);for(let s in o)this.applyCmykFilterInternal(o[s],i,`::${s}:`)}else if(Mi(r)&&!Zt(r)){let o=ge(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()}};d(zd,"markerAllowedProps",["color","font-family","font-size","font-style","font-weight","font-variant","unicode-bidi","direction","white-space","text-transform","text-combine-upright"]);var Dy=zd,vs=[],zy=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"],ha=null;function Vy(e){ha=e}var dr=class extends Gi{constructor(e,t,i,n,r,o,s){super(e,t,s),this.condition=i,this.regionId=r,this.validatorSet=o,d(this,"chain",null),d(this,"specificity",0),d(this,"elementStyle",null),d(this,"conditionCount",0),d(this,"pseudoelement",null),d(this,"selectorFunctionContainsPseudoelement",!1),d(this,"footnoteContent",!1),d(this,"cascade"),d(this,"state"),d(this,"viewConditionId",null),d(this,"insideSelectorRule"),d(this,"invalid",!1),this.cascade=n?n.cascade:ha?ha.clone():new _y,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=al(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 py(e,t.toLowerCase())):t?this.chain.push(new vh(t.toLowerCase())):this.chain.push(new gy(e)))}invalidSelector(e){G.warn(e),this.chain.push(new et("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof Nn;e=e.parent)e.parent.invalid=!0}classSelector(e){this.invalidContinuationAfterPseudoelement(`.${e}`)||(this.specificity+=256,this.chain.push(new cy(e)))}pseudoclassSelector(e,t){if(!this.invalidContinuationAfterPseudoelement(`:${e}`)){switch(e.toLowerCase()){case"enabled":this.chain.push(new Sy);break;case"disabled":this.chain.push(new Cy);break;case"checked":this.chain.push(new ky);break;case"root":case"scope":this.chain.push(new vy);break;case"link":this.chain.push(new vh("a")),this.chain.push(new bh("","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)${hi(i)}($|\\s)`),r=t[1];this.chain.push(new fy(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 yy(new RegExp(`^${hi(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=Uy[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 xh);break;case"last-child":this.chain.push(new aa(0,1));break;case"first-of-type":this.chain.push(new sa(0,1));break;case"last-of-type":this.chain.push(new la(0,1));break;case"only-child":this.chain.push(new xh),this.chain.push(new aa(0,1));break;case"only-of-type":this.chain.push(new sa(0,1)),this.chain.push(new la(0,1));break;case"empty":this.chain.push(new xy);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 dy(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 bh(e,t);break;case 39:r=new my(e,t,n);break;case 45:!n||n.match(/\s/)?r=new et(""):r=new zn(e,t,new RegExp(`(^|\\s)${hi(n)}($|\\s)`));break;case 44:r=new zn(e,t,new RegExp(`^${hi(n)}($|-)`));break;case 43:n?r=new zn(e,t,new RegExp(`^${hi(n)}`)):r=new et("");break;case 42:n?r=new zn(e,t,new RegExp(`${hi(n)}$`)):r=new et("");break;case 46:n?r=new zn(e,t,new RegExp(hi(n))):r=new et("");break;case 50:if(n=="supported")r=new wy(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${Hr++}`;this.processChain(new Ur(new Ty(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}childSelector(){if(this.invalidContinuationAfterPseudoelement("child selector"))return;let e=`c${Hr++}`;this.processChain(new Ur(new Iy(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}adjacentSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("adjacent sibling selector"))return;let e=`a${Hr++}`;this.processChain(new Ur(new Ay(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}followingSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("following sibling selector"))return;let e=`f${Hr++}`;this.processChain(new Ur(new Fy(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 hl(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new ia(t,0,this.condition):i=new V(t,0),Id(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===y.oeb_page_head||t===y.oeb_page_foot)&&(this.simpleProperty("flow-options",new ee([y.exclusive,y._static]),i),this.simpleProperty("flow-into",t,i),t=y.block),Ot("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 ia(t,n,this.condition):new V(t,n);Ut(this.elementStyle,e,r)}finish(){return this.cascade}startFuncWithSelector(e,t){let i;switch(e){case"is":i=new Nn(this);break;case"not":i=new Hy(this);break;case"where":i=new $y(this);break;case"has":i=new Wy(this);break;case"nth-child":t&&t.length>=2&&(i=new Hd(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new Gy(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},Uy={"nth-child":by,"nth-of-type":sa,"nth-last-child":aa,"nth-last-of-type":la},Hr=0,Nn=class Ud extends dr{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),this.parent=t,d(this,"parentChain"),d(this,"chains",[]),d(this,"maxSpecificity",0),d(this,"selectorTexts",[]),d(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 Py(this.selectorTexts):this.positive()?new ul(this.chains):new Ey(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 Ud;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}},Hy=class extends Nn{positive(){return!1}forgiving(){return!1}},$y=class extends Nn{increasingSpecificity(){return!1}},Wy=class extends Nn{relational(){return!0}},Hd=class extends Nn{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 Ld(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new et("")),this.owner.popHandler()}forgiving(){return!0}},Gy=class extends Hd{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Ny(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new et("")),this.owner.popHandler()}},jy=class extends Gi{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 br(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,r))}}},Qr=class extends Gi{constructor(e,t,i,n,r,o){super(e,t,!1),this.condition=i,this.elementStyle=n,this.validatorSet=r,this.ruleType=o,d(this,"order"),this.order=0}property(e,t,i){i?G.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){G.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){G.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=cl;let r=this.condition?new ia(t,n,this.condition):new V(t,n);Ut(this.elementStyle,e,r)}},Xy=class extends zc{constructor(e,t){super(e),this.validatorSet=t,d(this,"elementStyle",{}),d(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){G.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){G.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?Dc:_c;n+=this.order,this.order+=cl;let r=new V(t,n);Ut(this.elementStyle,e,r)}};function $d(e,t){let i=Nd(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function ua(e,t,i){$d(i,n=>{ir(e,n,t)})}function qy(e,t,i,n){let r=new Xy(e,t),o=new Vt(n,r);try{Wm(o,r,i)}catch(s){G.warn(s,"Style attribute parse error:")}return r.elementStyle}function Wd(e,t,i){let n=e["writing-mode"];if(n){let r=n.evaluate(t,"writing-mode");if(r&&r!==y.inherit&&r!==y.revert&&r!==y.unset)return r===y.vertical_rl}return i}function Gd(e,t,i){let n=e.direction;if(n){let r=n.evaluate(t,"direction");if(r&&r!==y.inherit&&r!==y.revert&&r!==y.unset)return r===y.rtl}return i}function ca(e,t,i,n,r){let o={};for(let s in e)Mi(s)&&(o[s]=ge(e,s));return ua(o,t,e),jd(e,i,n,(s,a)=>{ir(o,a,t),ua(o,t,a)}),o}function jd(e,t,i,n){let r=pt(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 ir(e,t,i){for(let n in t)if(Mi(n)){let r=ge(t,n),o=e[n];e[n]=ra(i,o,r)}}var Xd=(e,t,i,n,r,o)=>{var s,a;let h=i?n?ty:Cd:n?iy:kd,l=r?ny:ry;for(let u in e){let c=e[u];if(!c)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>c.priority||p&&f&&p!==f&&(g=f,w=e[g],w&&w.priority>c.priority))continue;m=yh[p]?p:yh[f]?f:u}else m=u,u.startsWith("text-align")&&(c.value===y.inside||c.value===y.outside)&&(c=new V(r===(c.value===y.inside)?y.right:y.left,c.priority));t[m]=o(u,c)}},Yy=class extends Hi{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 ce&&e.values[0].name;return!t||!Zt(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)))}},qd=class extends Hi{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=Nr(this.context.rootScope,new Vt(i,null),"");if(n instanceof W)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 xt(r)))}catch(r){G.warn(r)}return t}visitNumeric(e){return this.resolveViewportUnit&&Ru(e.unit)||this.context.rootFontSize!=null&&eg(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 Lo(e,t,i,n,r){try{if(t instanceof W)return t.expr instanceof Fe&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:qm(e,t.expr,i);if(t instanceof R||t instanceof $i||t instanceof ee||t instanceof it)return t.visit(new qd(e,!0,n,r))}catch(o){return G.warn(o),Y}return t}var Sh={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Ch(e){let t=e instanceof nt?e:typeof e=="string"?B(e):y.none;if(t===y.none)return Sh;let i=t instanceof ee?t.values:[t],n=Object.create(Sh);for(let r of i)if(r instanceof ce)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 kh(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var Zy={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},Eh={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},Ph={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Nh(e){let t=e instanceof nt?e:typeof e=="string"?B(e):y.normal;if(t===y.normal)return Eh;if(t===y.auto)return Ph;let i=t instanceof ee?t.values:[t],n=Object.create(Eh);for(let r of i)if(r instanceof ce)switch(r.name){case"trim-both":case"trim-auto":return Ph;case"space-all":return Zy;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 bs={ideographAlpha:!1,ideographNumeric:!1},Ky={ideographAlpha:!0,ideographNumeric:!0};function Th(e){let t=e instanceof nt?e:typeof e=="string"?B(e):y.normal;if(t===y.normal||t===y.auto)return Ky;if(t===y.none)return bs;let i=t instanceof ee?t.values:[t],n=Object.create(bs);for(let r of i)if(r instanceof ce)switch(r.name){case"no-autospace":return bs;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Ih(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function Ah(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 Jy=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=Ah(r);let s=Th(t),a=Nh(i),h=Ch(n);if(kh(h)&&Ih(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),c=null,p=null;for(let f=u.nextNode();f;f=p){p=u.nextNode();let g=!c,m=!c||/\n$/.test(c.textContent),w=!p||/^\n/.test(p.textContent),x=!p;this.processTextSpacing(f,g||m,g,m,w,x,c,p,s,a,h,r,o),c=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,r,o,s,a,h,l;let u=!e||e.fragmentIndex===1&&f(),c=u||g();function p(b){var v;if(b?.nodeType!==1)return!1;let C=b;if(C.hasAttribute(kn))return!0;let{position:S,float:F}=(v=C.style)!=null?v:{};return S==="absolute"||S==="fixed"||F&&F!=="none"}function f(){let b=t[0];for(let v=b;;v=v.parent)if(!v||!v.inline){if(v?.fragmentIndex!==1)return!1;break}if(!b.inline)return!0;for(let v=b.viewNode.previousSibling;v;v=v.previousSibling)if(!Ve(v,b.whitespace)&&!p(v))return!1;return!0}function g(){var b,v;let C=t[0],S;for(;C&&C.inline&&(S=(b=C.viewNode)==null?void 0:b.previousSibling,!(S&&(S.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(S.textContent)&&C.whitespace!==dt.PRESERVE&&(S=S.previousSibling),S)));)C=C.parent;for(;S;){if(S.nodeType===Node.ELEMENT_NODE){if(S.localName==="br")return!0;let F=(v=S.style)==null?void 0:v.display;if(F&&F!=="inline")return!/^(inline|ruby)\b/.test(F)}else if(S.nodeType===Node.TEXT_NODE){if(C.whitespace===dt.PRESERVE){if(/\n$/.test(S.textContent))return!0}else if(C.whitespace===dt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(S.textContent))return!0}S=S.lastChild}return!1}let m=-1;for(let b=0;b<t.length;b++){let v=t[b];if(!v.after&&v.inline&&!v.display&&v.parent&&v.viewNode.parentNode&&v.viewNode.nodeType===Node.TEXT_NODE&&!Ve(v.viewNode,v.whitespace)){let C=function(P){var I,O,z;if(((I=P.viewNode)==null?void 0:I.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((O=P.viewNode)==null?void 0:O.nodeType)===Node.TEXT_NODE){let $=P.viewNode;if(P.whitespace===dt.PRESERVE){if(/\n$/.test($.textContent))return!0}else if(P.whitespace===dt.NEWLINE&&/\n[ \t\r\n\f]*$/.test($.textContent))return!0;if(((z=$.previousElementSibling)==null?void 0:z.localName)==="br")return Ve($,P.whitespace)}return!1},S=function(P){var I,O,z;if(((I=P.viewNode)==null?void 0:I.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((O=P.viewNode)==null?void 0:O.nodeType)===Node.TEXT_NODE){let $=P.viewNode;if(P.whitespace===dt.PRESERVE){if(/^\n/.test($.textContent))return!0}else if(P.whitespace===dt.NEWLINE&&/^[ \t\r\n\f]*\n/.test($.textContent))return!0;if(((z=$.nextElementSibling)==null?void 0:z.localName)==="br")return Ve($,P.whitespace)}return!1};var w=C,x=S;m<0&&(m=b);let F=Ah((o=(n=(i=v.lang)!=null?i:v.parent.lang)!=null?n:e?.lang)!=null?o:(r=e?.parent)==null?void 0:r.lang),A=Th(v.inheritedProps["text-autospace"]),D=Nh(v.inheritedProps["text-spacing-trim"]),H=Ch(v.inheritedProps["hanging-punctuation"]);if(kh(H)&&Ih(A,D)||/\b(flex|grid)\b/.test(v.parent.display))continue;let q=null,Se=null,se=b===m,k=b===m&&u,M=b===m&&c,E=!1,L=!1;for(let P=b-1;P>=0;P--){let I=t[P];if(C(I)){M=!0;break}if(!I.display&&I.viewNode.nodeType===Node.TEXT_NODE&&I.viewNode.textContent.length>0){q=I.viewNode;break}if(((s=I.viewNode)==null?void 0:s.nodeType)===Node.ELEMENT_NODE&&Xt(I.viewNode)==="footnote-call"){if(I.viewNode.contains(v.viewNode))continue;let O=sw(I.viewNode);if(O){q=O;break}}if(I.display&&!/^(inline|ruby)\b/.test(I.display)||((a=I.viewNode)==null?void 0:a.nodeType)===Node.ELEMENT_NODE&&(I.viewNode.localName==="br"||Bi[I.viewNode.localName]))break;P===0&&(se=!0,u&&(k=!0,M=!0))}for(let P=b+1;P<t.length;P++){let I=t[P];if(S(I)){E=!0;break}if(I.viewNode!==v.viewNode&&!I.display&&I.viewNode.nodeType===Node.TEXT_NODE&&I.viewNode.textContent.length>0){Se=I.viewNode;break}if(I.display&&!/^(inline|ruby)\b/.test(I.display)||((h=I.viewNode)==null?void 0:h.nodeType)===Node.ELEMENT_NODE&&(I.viewNode.localName==="br"||Bi[I.viewNode.localName])){P===t.length-1&&p(I.viewNode)&&(L=!0);break}if(P===t.length-1){E=!0,L=!0;for(let O=I.viewNode.nextSibling;O;O=O.nextSibling)if(!p(O)){L=!1;break}}}if(((l=v.parent)==null?void 0:l.display)==="inline-block"){if(!k){let P=v.parent.viewNode.firstChild;for(;Ve(P,v.whitespace);)P=P.nextSibling;v.viewNode===P&&(k=!0)}if(!L){let P=v.parent.viewNode.lastChild;for(;Ve(P,v.whitespace);)P=P.previousSibling;v.viewNode===P&&(L=!0)}}if(this.processTextSpacing(v.viewNode,se,k,M,E,L,q,Se,A,D,H,F,v.vertical)>0)break}}}processTextSpacing(e,t,i,n,r,o,s,a,h,l,u,c,p){let f=e.textContent,g=e.ownerDocument,m=0,w,x,b;function v(){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=hr(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 C(){if(!a)return!1;w||(w=g.createRange(),w.selectNode(e));let E=w.getClientRects()[0];if(!E)return!1;m||(m=hr(E,p)),b||(b=g.createRange(),b.selectNode(a));let L=b.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 S=!1,F=!1,A=!1,D=!1,H;if(i&&u.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(H="viv-ts-open",S=!0,F=!0):o&&u.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(H="viv-ts-close",S=!0,A=!0):(u.forceEnd||u.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(H="viv-ts-close",S=!0,D=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(H="viv-ts-open",S=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||c==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||c!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(H="viv-ts-close",S=!0),S){let E=function(z){let $=parseFloat(g.defaultView.getComputedStyle(z).fontSize)*.7;return(p?z.offsetHeight:z.offsetWidth)>$},L=function(){return p?P.offsetLeft:P.offsetTop};var q=E,Se=L;if(e.parentElement.localName==="viv-ts-inner")return 0;let P=g.createElement(H),I=g.createElement("viv-ts-inner");P.appendChild(I),e.parentNode.insertBefore(P,e),I.appendChild(e);let O=E(I);if(O||F||A||D){if(H==="viv-ts-open"){if(F)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)&&v())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)&&v()){let z=L();P.className="viv-ts-auto",z===L()&&!v()&&(P.className="viv-ts-trim")}}else if(H==="viv-ts-close"){if(A)P.className=O?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(o||r){let z=L();D?(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(D){let z=C(),$=z&&u.allowEnd;$||(P.className=O?"viv-hang-end":"viv-hang-end viv-hang-hw"),O?$&&l.trimEnd?P.className="viv-ts-auto":!$&&!C()?P.className="":!z&&u.allowEnd&&(l.trimEnd?(P.className="viv-ts-auto",C()||(P.className="viv-hang-end")):(P.className="viv-ts-space",C()||(l.allowEnd?(P.className="viv-ts-auto",C()||(P.className="viv-hang-end")):P.className="viv-hang-end"))):!z&&!C()&&(P.className="")}else if(l.trimEnd||l.allowEnd)if(C())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 se=!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 M(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 M(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 I=L.parentElement;return I&&!I.contains(E)?M(E,I):!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))&&!M(s,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),se=!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))&&!M(e,a)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e.nextSibling),se=!0)),m}registerHooks(){Nt("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),Nt("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),Nt("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},dl=new Jy;dl.registerHooks();function Qy(e){dl.preprocessForTextSpacing(e)}function ev(e,t,i,n,r,o){dl.processGeneratedContent(e,t,i,n,r,o)}var Gn=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),tv=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","footnote-call","","after"],pl="data-adapt-pseudo";function Xt(e){return e.getAttribute(pl)||""}function nr(e,t){e.setAttribute(pl,t)}var xs=class{constructor(e,t,i,n,r){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=r,d(this,"contentProcessed",{})}getStyle(e,t){let i=Xt(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=pt(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 ze(o),0)}return r}processContent(e,t,i){let n=Xt(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let r=t.content;St(r)&&(r.visit(new ur(e,this.context,r,this.exprContentListener)),Qy(e))}}},Ex=Eo.isInstanceOfAfterIfContinuesLayoutConstraint,iv=Qo.registerFragmentIndex,Px=Qo.clearFragmentIndices,nv=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new fl(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 N(o,"display","block"),T(o)})}createNodePositionForPseudoElement(){let e=Gn.createElementNS("http://www.w3.org/1999/xhtml","div");nr(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 Si(i)}createShadowContext(e){return new Zr(this.sourceNode,e,null,null,null,si.ShadowType.ROOTED,this.styler)}},rv=class Yd{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,d(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 ov(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof Yd?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},ov=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 Zd(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=av(e,t,n);return t.fragmentLayoutConstraints.push(new rv(e,i,r)),T(e)})}function Kd(e,t){return e.thenAsync(i=>Zd(i,t))}function sv(e,t){let i=_("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let r=Zd(n,t);return n=n.parent,r.thenReturn(!0)}else return T(!1)}).then(()=>{i.finish(!0)}),i.result()}function av(e,t,i){let n=e.viewNode;n.appendChild(i);let r=Xs(i,t,e.vertical);return n.removeChild(i),r}var lv=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},eo=class extends nl{constructor(e,t){super(),this.checkPoints=e,this.penalty=t,d(this,"alreadyEvaluated",!1),d(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]}},Oo=class extends dd{constructor(e,t,i,n,r){super(e),this.layoutContext=t,this.clientLayout=i,this.layoutConstraint=n,this.pageFloatLayoutContext=r,d(this,"last"),d(this,"viewDocument"),d(this,"flowRootFormattingContext",null),d(this,"isNonFirstColumn",!1),d(this,"isFloat",!1),d(this,"isFootnote",!1),d(this,"startEdge",0),d(this,"endEdge",0),d(this,"beforeEdge",0),d(this,"afterEdge",0),d(this,"footnoteEdge",0),d(this,"box",null),d(this,"chunkPositions",null),d(this,"bands",null),d(this,"overflown",!1),d(this,"breakPositions",null),d(this,"pageBreakType",null),d(this,"forceNonfitting",!0),d(this,"leftFloatEdge",0),d(this,"rightFloatEdge",0),d(this,"bottommostFloatTop",0),d(this,"stopAtOverflow",!0),d(this,"lastAfterPosition",null),d(this,"fragmentLayoutConstraints",[]),d(this,"pseudoParent",null),d(this,"nodeContextOverflowingDueToRepetitiveElements",null),d(this,"blockDistanceToBlockEndFloats",NaN),d(this,"lastLineStride",0),d(this,"breakAtTheEdgeBeforeFloat",null),ew(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=_("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=No(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?ww(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(wo),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(wo);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=_("buildViewToNextBlockEdge");return n.loopWithFrame(r=>{var o;if(e.viewNode&&!cn(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(hr(a,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(s=>{let a=s;a!==e&&(e=a,cn(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)&&(vi(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 Kd(i,this)}buildDeepElementView(e){if(!e.viewNode)return T(e);let t=[],i=e.sourceNode,n=_("buildDeepElementView");return n.loopWithFrame(r=>{e.viewNode&&e.inline&&!cn(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}cn(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)&&(vi(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),N(r,"height",`${i}px`),N(r,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),N(r,"width",`${i}px`),N(r,"height",`${n}px`)),N(r,"float",t),N(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;for(let c of t)this.almostEquals(c.x1,i)?c.x1=i:this.almostEquals(c.x1,n)&&(c.x1=n),this.almostEquals(c.x2,n)?c.x2=n:this.almostEquals(c.x2,i)&&(c.x2=i),this.almostEquals(c.y1,r)?c.y1=r:this.almostEquals(c.y1,o)&&(c.y1=o),this.almostEquals(c.y2,o)?c.y2=o:this.almostEquals(c.y2,r)&&(c.y2=r);let a=1/(this.clientLayout.pixelRatio||1),h=Da==="webkit"?Math.floor:Math.round,l=t.map(c=>(h(c.y2/a)-h(c.y1/a))*a),u=.01;for(let c=0;c<t.length;c++){let p=c<t.length-1?t[c+1].x1:i,f=c<t.length-1?t[c+1].x2:n,g=p-t[c].x1,m=t[c].x2-f,w=0,x=0;g>u?w=1:g<-u&&(w=-1),m>u?x=1:m<-u&&(x=-1);let b=w!==0&&x!==0?w===x?w:0:w||x;if(b!==0){let v=b*a;l[c]+v>=0&&(c>=t.length-1||l[c+1]-v>=0)&&(l[c]+=v,c<t.length-1&&(l[c+1]-=v))}}for(let c=0;c<t.length;c++){let p=t[c];p.left=this.createFloat(e,"left",p.x1-i,l[c]),p.right=this.createFloat(e,"right",n-p.x2,l[c]),p.x1<n&&p.x2>i?s=p:s||N(p.right,"float","none")}if(s){let c=t[t.length-1];if(s!==c&&c.y2>=o&&(this.footnoteEdge=this.vertical?-s.y2:s.y2,s.x1===i&&s.x2===n))for(let p=t.indexOf(s);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(N(this.element,n,`${i}px`),this.vertical){let r=this.left+(t-i);N(this.element,"left",`${r}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(e,t,i,n){let r;if(e&&un(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(r=rn(e,this.clientLayout,0,this.vertical),!isNaN(r)))return r;e=t[i];let o=n-e.boxOffset;for(;;){if(r=rn(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 ds(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 ds(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 ds(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=_("layoutFloat"),i=e.viewNode,n=ws(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return N(i,"float","none"),N(i,"display","inline-block"),N(i,"vertical-align","top"),this.buildDeepElementView(e).then(r=>{let o=Et(this.clientLayout,i,this.vertical),s=this.getComputedMargin(i),a=new Pt(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 C=u.viewNode.ownerDocument.createElement("div");C.style.left="0px",C.style.top="0px",this.vertical?(C.style.bottom="0px",C.style.width="1px"):(C.style.right="0px",C.style.height="1px"),u.viewNode.appendChild(C);let S=Et(this.clientLayout,C,this.vertical);h=Math.max(this.rtl?this.getEndEdge(S):this.getStartEdge(S),h),l=Math.min(this.rtl?this.getStartEdge(S):this.getEndEdge(S),l),u.viewNode.removeChild(C);let F=this.vertical?a.y2-a.y1:a.x2-a.x1;n=="left"?l=Math.max(l,h+F):h=Math.min(h,l-F),u!==e.parent&&!e.firstPseudo&&(u.viewNode.appendChild(i),i.setAttribute("data-vivliostyle-float-box-moved","true"))}let c=new Pt(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),p=a;this.vertical&&(p=bo(a));let f=this.getBoxDir();if(p.y1<this.bottommostFloatTop*f){let C=p.y2-p.y1;p.y1=this.bottommostFloatTop*f,p.y2=p.y1+C}if(e.clearSide){let C=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(e.clearSide)?ws(e.clearSide,e.vertical,e.direction,this.layoutContext.page.side):e.clearSide==="same"?n:e.clearSide,S=this.beforeEdge;C!=="right"&&(S=f*Math.max(S*f,this.leftFloatEdge*f)),C!=="left"&&(S=f*Math.max(S*f,this.rightFloatEdge*f));let F=S*f;if(p.y1<F){let A=p.y2-p.y1;p.y1=F,p.y2=p.y1+A}}c.y2+=1/(this.clientLayout.pixelRatio||1),Tg(c,this.bands,p,n),this.vertical&&(a=lc(p));let g=this.getComputedInsets(i);N(i,"width",`${a.x2-a.x1-g.left-g.right}px`),N(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),N(i,"position","absolute"),e.display,N(i,"display",e.display);let m,w=null;if(u&&(u.containingBlockForAbsolute?w=u:w=u.getContainingBlockForAbsolute()),w){let C=w.viewNode.ownerDocument.createElement("div");C.style.position="absolute",w.vertical?C.style.right="0":C.style.left="0",C.style.top="0",w.viewNode.appendChild(C),m=Et(this.clientLayout,C,this.vertical),w.viewNode.removeChild(C)}else m={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};if(w?w.vertical:this.vertical){let C=Math.max(0,m.right-a.x2);N(i,"right",`${C}px`)}else{let C=Math.max(0,a.x1-m.left);N(i,"left",`${C}px`)}let x=Math.max(0,a.y1-m.top);N(i,"top",`${x}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let b=this.vertical?a.x1:a.y2,v=this.vertical?a.x2:a.y1;!this.isOverflown(b)||this.breakPositions.length==0?(this.killFloats(),c=new Pt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(c=bo(c)),Ig(c,this.bands,p,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=b:this.rightFloatEdge=b,this.bottommostFloatTop=v,this.updateMaxReachedAfterEdge(b),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 c=getComputedStyle(e.element);if(e.vertical){let p=parseFloat(c.maxWidth);!isNaN(p)&&e.width>p&&(e.width=p,N(e.element,"width",`${p}px`))}else{let p=parseFloat(c.maxHeight);!isNaN(p)&&e.height>p&&(e.height=p,N(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");N(o,"position","absolute");let s=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new sn(null,Pe.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null);a.setOuterContext(this.pageFloatLayoutContext);let h=s.getContainer(),l=new cv(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},c=_("layoutSinglePageFloatFragment");return this.createPageFloatArea(h,t,o,r,l).then(p=>{if(u.floatArea=p,!p){c.finish(u);return}let f=!1,g=0;c.loopWithFrame(m=>{if(g>=e.length){m.breakLoop();return}let w=e[g],x=new Si(w.nodePosition);p.layout(x,!0).then(b=>{u.newPosition=b,!b||n?(g++,m.continueLoop()):(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=>{c.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}}c.finish(u)})}),c.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 c of u.floatFragments)c.continuations.some(p=>p.float.insidePageFloatArea)&&s.add(c);r.stashEndFloatFragments(o);function a(u,c){c?r.removePageFloatFragment(c,!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 Io,l=_("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],o.floatSide,o.clearSide,h||!r.hasFloatFragments(),t,i,n).then(u=>{let c=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 gh(o,f.primary);r.deferPageFloat(w)}l.finish(!0)}else a(c,p),l.finish(!1)}):(a(c,p),l.finish(!1))}),l.result()}layoutStashedPageFloats(e,t){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(e),r=[],o=[],s=!1,a=_("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 c=new Pn().findByFloat(u.continuations[0].float);this.layoutSinglePageFloatFragment(u.continuations,u.floatSide,u.clearSide,!1,c,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&&Xt(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(kn,"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=_("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,o=r.getPageFloatLayoutContext(Pe.REGION);return r.getContainer().width<o.getContainer().width&&e===Pe.COLUMN?t===y.auto?this.buildDeepElementView(i.copy()).then(s=>{let a=s.viewNode,h=Qa(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(Pe.REGION):n.finish(e)}):t===y.all?n.finish(Pe.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new Pn().findByNodeContext(e),n,r=t.findPageFloatByNodePosition(e.toNodePosition());return r?n=T(r):n=i.createPageFloat(e,t,this),n.thenAsync(o=>{let s=Po(e,0),a=this.setFloatAnchorViewNode(e);t.markPageFloatAnchorSeen(o);let h=i.findPageFloatFragment(o,t),l=new gh(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=rn(a,this.clientLayout,0,this.vertical);if(isNaN(u)&&e.floatSide==="footnote"){let c=a.viewNode;if(c&&c.nodeType===1){let p=Et(this.clientLayout,c,this.vertical);p.right>=p.left&&p.bottom>=p.top&&(u=this.vertical?p.left:p.bottom)}}return this.isOverflown(u)?T(a):this.layoutPageFloatInner(l,i,u,h).thenAsync(c=>c?e.floatSide==="footnote"||t.generatingNodePosition?T(a):T(null):(t.registerPageFloatAnchor(o,a.viewNode),T(a)))}})}processLineStyling(e,t,i){let n=_("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(c=>{e=c,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&&Bi[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=_("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||!un(n.viewNode)){let l=vn(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){Ot("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 c=this.calculateEdge(null,t,s,l);if(this.vertical?c<=n:c>=n){for(h=l-1;t[s].boxOffset==l;)s--;a=s}else i&&this.updateMaxReachedAfterEdge(c),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=ch(a);if(l){if(((r=this.breakPositions)==null?void 0:r[0])instanceof eo&&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&&(Ve(u,a.parent.whitespace)||ci(u));)u=u.previousSibling;if(u)break;a=a.parent}}}return this.clearOverflownViewNodes(a,!1),a}resolveTextNodeBreaker(e){return Ot("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,Bo.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 c=o.nodeType===1?o:null;c?r?r=!1:Ja(c)?l=!a:!c.firstChild||Bi[c.localName]||/^r(uby|[bt]c?)$/.test(c.localName)||ow(this.clientLayout.getElementComputedStyle(c).display)?(l=!a,l?(c.localName==="ruby"&&o.firstChild&&(o=o.firstChild),n.setStartBefore(o),a=!0,s=o):/^r(uby|tc?)$/.test(c.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);Gs(u,this.vertical);for(let c=0;c<u.length;c++)i.push(u[c]);a=!1}}return i}findLinePositions(e){let t=[],i=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);i.sort(this.vertical?Pw:Ew);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 c=Math.max(this.getBoxSize(l),1);h*this.getBeforeEdge(l)<h*n?u=h*(this.getAfterEdge(l)-n)/c:h*this.getAfterEdge(l)>h*r?u=h*(r-this.getBeforeEdge(l))/c: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(Nu),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&dn(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=vn(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,c=this.getBoxDir(),p=this.getOffsetByRepetitiveElements(e);u-=c*p;let f=this.findFirstOverflowingEdgeAndCheckPoint(r);isNaN(f.edge)&&(f.edge=c*(1/0));let g=oi(l.length,b=>{let v=l[b];return this.vertical?v<u||v<=f.edge:v>u||v>=f.edge}),m=g<=0;m&&(g=oi(l.length,b=>this.vertical?l[b]<u:l[b]>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 b=this.getAfterEdgeOfBlockContainer(x);if(!isNaN(b)&&c*(u-b)>0&&(u=b),this.computedBlockSize=c*(u-this.beforeEdge)+p,l.length>=2){let v=Math.max(1,Math.min(g-1,l.length-1));this.lastLineStride=Math.abs(l[v]-l[v-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,rn(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 Dn().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=ol.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=_("doFinishBreak"),o=!1;if(!e){if(this.forceNonfitting&&!this.isFootnote)return G.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(ci(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(!Co(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||dn(n))continue;let r=this.clientLayout.getElementComputedStyle(n);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let o=n.getAttribute("data-viv-box-break");mt(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(ci(s.viewNode))return!1;if(un(e.viewNode))return!1;let i=this.suppressOpenAncestorBlockEndInset(e),n=rn(e,this.clientLayout,0,this.vertical);i();let r=vn(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||un(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!==Pe.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=Et(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)?ws(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 c=1/(this.clientLayout.pixelRatio||1),p=l*o>u*o;l=o*(Math.ceil(l*o/c)+(p?1:0))*c;let f=c;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=Et(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!!(jw(e)||_i.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let t=e;t;t=t.parent)if(uh(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=_("skipEdges"),s=this,a=!i&&t&&e&&e.after,h=i,l=null,u=[],c=[],p=!1;function f(C){var S,F;if(!(!t||s.isNonFirstColumn||i||!dh(h))){for(let A=C;A;A=A.parent)if(A.breakBefore==="column"&&(A.breakBefore=null),((S=A.viewNode)==null?void 0:S.nodeType)===1){let D=A.viewNode;((F=D.style)==null?void 0:F.breakBefore)==="column"&&(D.style.breakBefore="")}}}function g(C){var S,F;if(!(!t||!s.isNonFirstColumn||i||h!=="column")){for(let A=C;A;A=A.parent)if(A.breakBefore==="column"&&(A.breakBefore=null),((S=A.viewNode)==null?void 0:S.nodeType)===1){let D=A.viewNode;((F=D.style)==null?void 0:F.breakBefore)==="column"&&(D.style.breakBefore="")}h=null}}function m(C){var S,F;if(!(i||!dh(h))){for(let A=C;A;A=A.parent)if(A.breakAfter==="column"&&(A.breakAfter=null),((S=A.viewNode)==null?void 0:S.nodeType)===1){let D=A.viewNode;((F=D.style)==null?void 0:F.breakAfter)==="column"&&(D.style.breakAfter="")}}}function w(C){h=tt(h,C)}function x(){return i?!0:Xe(h)?t?s.isNonFirstColumn&&h!=="column"&&h!=="region":!b():!1}function b(){var C;if(!l||!e||e.floatSide)return!1;for(let S=l;S!=null&&S.parent;S=S.parent){if(S.parent.viewNode&&ci(S.parent.viewNode))continue;let F=S.after?S.viewNode:(C=S.viewNode)==null?void 0:C.previousSibling;for(;F&&(Ve(F,S.parent.whitespace)||ci(F));)F=F.previousSibling;if(F)return!1}return!0}let v=()=>{e=u[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=h};return o.loopWithFrame(C=>{for(var S;e;){e.formattingContext;let F=new Dn().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ve(e.viewNode,e.whitespace)||this.hasFixedPositionAncestor(e))break;if(!e.after){x()?v():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=ko(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?ch(l):this.breakPositions[this.breakPositions.length-1]instanceof eo||!t&&u.length===0)&&this.saveEdgeBreakPosition(e.copy(),h,!1),!this.isBFC(e.formattingContext)||_i.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Ve(e.sourceNode.firstChild,e.whitespace)){u.push(e.copy()),w(e.breakBefore),f(e),g(e),x()?v():(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 D=e.viewNode,H=D.style;if(e.after){jc(D,this),e.floatSide&&(h=h??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let q=e.sourceNode;if(q.localName==="svg"||q.localName==="math"||q.getAttribute("data-math-typeset")==="true"){p=!1,l=e.copy(),c.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(uh(e.viewNode))break;if(x()){v(),C.breakLoop();return}u=[],t=!1,a=!1,h=null}p=!1,qc(e.viewNode)||(l=e.copy(),c.push(l)),w(e.breakAfter),m(e),H&&!ci(e.viewNode)&&this.hasNonZeroBlockEndInset(H)&&(c=l?[l]:[])}else{if(u.push(e.copy()),w(e.breakBefore),f(e),g(e),l&&Xe(h)&&tw(l.viewNode,e.viewNode),(e.pageType!=((S=e.parent)==null?void 0:S.pageType)||!Xe(h))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){C.breakLoop();return}let q=e.viewNode.localName;if(Bi[q]){x()?v():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}H&&this.hasNonZeroBlockStartInset(H)&&(a=!1,c=[]),p=!0}}while(!1);let A=this.nextInTree(e,a);if(A.isPending()){A.then(D=>{e=D,C.continueLoop()});return}else e=A.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(l,c,!this.stopAtOverflow,h)?l&&this.stopAtOverflow&&(e=l.modify(),e.overflow=!0):Xe(h)&&(this.pageBreakType=h),C.breakLoop()}).then(()=>{l&&(this.lastAfterPosition=l.toNodePosition()),o.finish(e)}),o.result()}skipTailEdges(e){let t=e.copy(),i=_("skipEdges"),n=null,r=!1;return i.loopWithFrame(o=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ve(e.viewNode,e.whitespace))break;if(!e.after){Xe(n)&&(this.pageBreakType=n),o.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=tt(n,e.breakBefore),Xe(n)&&(this.pageBreakType=n),o.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(r){if(Xe(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(Bi[h]){Xe(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(vi(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=Pe.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=_("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 Dn().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 Dn().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 Pt(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=Eg(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],N(this.element,"width",`${this.width}px`),N(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 Dn().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 eo(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);Ka(this);let n=_("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 hv(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(Co(this)&&(rw(this),Ko(this)),this.element.hasAttribute("data-vivliostyle-column-block-size-adjusted")&&(this.vertical?(N(this.element,"width",`${this.width}px`),N(this.element,"left",`${this.left}px`)):N(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 Si(h.toNodePosition());n.finish(u)}})})})}),n.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let t=_("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=_("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=_("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(_i.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(Eo.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}xi.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},fl=class{constructor(e,t,i){d(this,"startNodeContexts",[]),d(this,"column"),d(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 Oo.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 Tr(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 o=r.data.slice(e.offsetInNode);if(!od(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(!Ve(o,e.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},Bo=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+Fh(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&&Ml(r)&&Ml(o)?Fh(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};d(Bo,"instance");Bo.instance=new Bo;function Fh(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var hv=class extends sl{constructor(e,t){super(),this.leadingEdge=e,d(this,"breakAfter"),d(this,"initialPageBreakType",null),d(this,"initialComputedBlockSize",0),d(this,"initialOverflown",!1),d(this,"initialLastLineStride",0),d(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new uv(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||qw()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Xc(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}},uv=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=_("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}},cv=class extends Oo{constructor(e,t,i,n,r,o,s){super(t,i,n,r,o),this.floatSide=e,this.parentContainer=s,d(this,"rootViewNodes",[]),d(this,"floatMargins",[]),d(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=pi(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),u=s*l/100;N(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=>{pi(e,o)==="auto"&&N(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=pi(t,"height");n!==""&&n!=="auto"&&N(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=pi(t,"width");n!==""&&n!=="auto"&&N(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=Et(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,c,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(jt);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=(c=(u=ge(w,"footnote-display"))==null?void 0:u.value)==null?void 0:c.toString(),b=!!((p=ge(w,"--viv-marker-content"))!=null&&p.value);return x==="compact"&&!b});if(n.length===0){this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea();return}let r=this.element.getBoundingClientRect(),o=this.vertical?r.height:r.width;n.forEach(h=>{N(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);N(l,"display","inline-block"),N(l,"position","absolute"),N(l,"visibility","hidden"),N(l,"white-space","nowrap"),N(l,"max-width","none"),N(l,"left","0"),N(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&&(N(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=Et(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=>Xt(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&&yt(r)),n=i?this.getFootnoteAfterPseudo(i):null;return!!n&&!n.hasAttribute("data-vivliostyle-default-footnote-separator")}createDefaultFootnoteAfterPseudo(e){let t=e.ownerDocument.createElement("span");nr(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")),c=this.getFootnoteBreakOpportunity(r);if(o==="inline"&&a==="inline"){let p=!h&&!l;p&&this.createDefaultFootnoteAfterPseudo(r),!p&&!c?this.createFootnoteBreakOpportunity(r):p&&c?.remove()}else u&&h.remove(),c?.remove()})}},Ui=class{constructor(e,t){this.parent=e,this.rootSourceNode=t,d(this,"formattingContextType","RepetitiveElementsOwner"),d(this,"isRoot",!1),d(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||Qs.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new dv(e,this.rootSourceNode),Qs.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},dv=class{constructor(e,t){this.vertical=e,this.ownerSourceNode=t,d(this,"headerSourceNode",null),d(this,"footerSourceNode",null),d(this,"headerViewNode",null),d(this,"footerViewNode",null),d(this,"headerNodePosition",null),d(this,"footerNodePosition",null),d(this,"headerHeight",0),d(this,"footerHeight",0),d(this,"isSkipHeader",!1),d(this,"isSkipFooter",!1),d(this,"enableSkippingFooter",!0),d(this,"enableSkippingHeader",!0),d(this,"doneInitialLayout",!1),d(this,"firstContentSourceNode",null),d(this,"lastContentSourceNode",null),d(this,"affectedNodeCache",[]),d(this,"afterLastContentNodeCache",[]),d(this,"allowInsert",!1),d(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=Po(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=Po(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=Xs(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=Xs(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 fl(n,s,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new Si(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(kn,"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}},Jd=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}},Qd=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},pv=class extends Jd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},fv=class extends Qd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new gl(e)),this.processor.doLayout(e,t)}},gl=class ep{constructor(t){d(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),d(this,"nodeContext");let i=ti(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||un(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!ip(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=ti(this.nodeContext.formattingContext),r=this.getRepetitiveElements();if(!r)return T(!0);let o=this.nodeContext;return vv(n,o,i).thenAsync(()=>bv(n,o,i).thenAsync(()=>(r.prepareLayoutFragment(),T(!0))))}getRepetitiveElements(){return ti(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof ep?ti(this.nodeContext.formattingContext)===ti(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},gv=class extends sl{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 pv(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new fv(this.formattingContext,this.processor))}},mv=class extends er{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 er.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):er.prototype.afterNonInlineElementNode.call(this,e)}},wv=class extends pn{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=ti(e.formattingContext);return n.getRootViewNode(e)?(i&&tp(e.parent,t),e.belongsTo(n)?pn.prototype.layout.call(this,e,t,i):new gv(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=xv(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=ti(e.formattingContext),n=_("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=ti(e.formattingContext),n=new mv(i,t);return new Js(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=ti(e.formattingContext),n=_("doLayout"),r=t.layoutContext.nextInTree(e,!1);return Kd(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 pn.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){pn.prototype.clearOverflownViewNodes(e,t,i,n)}};function yv(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof Ui&&!i.belongsTo(n)&&t(n,i)}}function tp(e,t){e&&yv(e.after?e.parent:e,(i,n)=>{xi.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new gl(n))})}function vv(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 bv(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 ip(e,t,i){let n=i.ownerSourceNode,r=e||t;return!r||n.contains(r.sourceNode)}function xv(e){let t=e.formattingContext;return!t||!(t instanceof Ui)?null:t}function ti(e){return e instanceof Ui,e}var Sv=new wv;Nt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Ui&&!xi.isInstanceOfTableFormattingContext(e)?Sv:null);var np=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,d(this,"cells",[]),d(this,"breakBefore",null),d(this,"breakAfter",null)}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},Cv=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,d(this,"viewElement"),d(this,"colSpan"),d(this,"rowSpan"),d(this,"height",0),d(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}},kv=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},Ev=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,d(this,"pseudoColumn"),d(this,"empty",!1),this.pseudoColumn=new fl(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&N(e,"vertical-align","top"),i&&i!=="normal"&&N(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return N(e,"vertical-align",t),i&&i!=="normal"&&N(e,"align-content",i),n}},Pv=class{constructor(e,t){this.viewNode=e,this.side=t}},Nv=class extends Tr{constructor(e,t,i,n){super(e,t,i,n),d(this,"formattingContext"),d(this,"acceptableCellBreakPositions",null),d(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)}},Tv=class extends nl{constructor(e,t,i){super(),this.rowIndex=e,this.beforeNodeContext=t,this.formattingContext=i,d(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 eo&&n[s].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((o,s)=>{let a=o.breakPosition.getMinBreakPenalty();r&&o.breakPosition instanceof Tr&&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)}},bn=class extends Ui{constructor(e,t){super(e,t),this.tableSourceNode=t,d(this,"formattingContextType","Table"),d(this,"vertical",!1),d(this,"columnCount",-1),d(this,"tableWidth",0),d(this,"captions",[]),d(this,"colGroups",null),d(this,"colWidths",null),d(this,"inlineBorderSpacing",0),d(this,"rows",[]),d(this,"slots",[]),d(this,"cellFragments",[]),d(this,"lastRowViewNode",null),d(this,"cellBreakPositions",[]),d(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 np(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 kv(e,s,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=Et(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 Iv(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(_i.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}xi.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=[].concat(e)}},Iv=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=vn(e,n);i=Math.max(i,t(r))}),i}};function Ft(e){return e instanceof bn,e}function Av(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Fv(e){return e==="table"||e==="inline-table"}function Rh(e){return Av(e)||Fv(e)}function rp(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 bn)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof bn){s=a.formattingContext===t;break}}return s||r==="table-row"&&!Rh(o)||r==="table-cell"&&o!=="table-row"&&!Rh(o)||n.formattingContext instanceof bn&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,T(!0))):null}function op(e,t){let i=t.nodeContext;return!(i!=null&&i.floatSide)||!(vi(i.floatReference)||i.floatSide==="footnote")?null:e.layoutFloatOrFootnote(i).thenAsync(n=>(n&&(t.nodeContext=n),T(!0)))}var Rv=class extends er{constructor(e,t){super(),this.formattingContext=e,this.column=t,d(this,"rowIndex",-1),d(this,"columnIndex",0),d(this,"inRow",!1),d(this,"checkPoints",[]),d(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=rp(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=op(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 Pv(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 np(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 Cv(this.rowIndex,this.columnIndex,o)),this.columnIndex++;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&&!cn(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},sp=class ap extends er{constructor(t,i){super(!0),this.formattingContext=t,this.column=i,d(this,"inRow",!1),d(this,"currentRowIndex",-1),d(this,"currentColumnIndex",0),d(this,"originalStopAtOverflow"),d(this,"inHeader"),d(this,"inFooter"),this.originalStopAtOverflow=i.stopAtOverflow,i.stopAtOverflow=!1}startNonInlineElementNode(t){return op(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&&(N(a,"box-sizing","border-box"),N(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let l=new Ev(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).thenReturn(!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(){let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[],n=0;do{let r=t[n],o=r.cell,s=o.rowIndex;if(s<this.currentRowIndex&&s+o.rowSpan>this.currentRowIndex){let a=i[s];a||(a=i[s]=[]),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(c=>c+1,0);if(r===0)return T(!0);let o=this.column.layoutContext,s=t.nodeContext;s.viewNode.parentNode.removeChild(s.viewNode);let a=_("layoutRowSpanningCellsFromPreviousFragment"),h=T(!0),l=0,u=[];return n.forEach(c=>{h=h.thenAsync(()=>{let p=No(c[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");N(x,"padding","0"),p.viewNode.appendChild(x)}g++}}return c.forEach(w=>{f=f.thenAsync(()=>{let x=w.cell;m(x.anchorSlot.columnIndex);let b=w.cellNodePosition,v=No(b.steps[0],p);return v.offsetInNode=b.offsetInNode,v.after=b.after,v.fragmentIndex=b.steps[0].fragmentIndex+1,o.setCurrent(v,!1).thenAsync(()=>{let C=w.breakChunkPosition;for(let S=0;S<x.colSpan;S++)u.push(g+S);return g+=x.colSpan,this.layoutCell(x,v,C).thenAsync(()=>(v.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&&Xe(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);iv(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=_("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=Po(h,0);return T(new Si(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=rp(t,Ft(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 Tv(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)):N(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)):N(i.viewNode,"display","table-row-group")),r&&ap.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 T(!0)}};d(sp,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Lv=sp,pr=[];function Ov(e){let t=pr.findIndex(n=>n.root===e),i=pr[t];return i?i.tableLayoutOption:null}function Bv(e){let t=pr.findIndex(i=>i.root===e);t>=0&&pr.splice(t,1)}var lp=class{layoutEntireTable(e,t){let i=Ft(e.formattingContext),n=new Rv(i,t);return new Js(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=Et(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,c)=>{N(u,n?"height":"width",`${a[c]}px`)}),h.forEach(u=>{o.appendChild(u.cloneNode(!0))}),e.colGroups=o}doInitialLayout(e,t){let i=Ft(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=Ov(e.sourceNode);Bv(e.sourceNode);let r=_("TableLayoutProcessor.doInitialLayout"),o=e.copy();return this.layoutEntireTable(e,t).then(s=>{let a=s.viewNode,h=Et(t.clientLayout,a,t.vertical),l=t.vertical?h.left:h.bottom;if(l+=(t.vertical?-1:1)*vn(e,t.collectElementsOffset()).current,!t.isOverflown(l)&&(!n||!n.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(i)){t.breakPositions.push(new zv(o)),r.finish(s);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&&Xe(i.breakBefore)||t<e.rows.length-1&&Xe(i.breakAfter)))return!0}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),N(t,"table-layout","fixed"),N(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=Ft(e.formattingContext),n=i.getRootViewNode(e),r=n.firstChild;this.addCaptions(i,n,r),this.addColGroups(i,n,r);let o=new Lv(i,t),s=new Js(o,t.layoutContext),a=_("TableFormattingContext.doLayout");return s.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=Ft(e.formattingContext);return n.getRootViewNode(e)?(i&&tp(e.parent,t),new _v(n,this).layout(e,t)):t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new Nv(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return Ss(e),!1}finishBreak(e,t,i,n){let r=Ft(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=_("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===s.length){l.breakLoop();return}let u=s[h++],c=r.getCellFragmentOfCell(u),p=c.findAcceptableBreakPosition().nodeContext,f=c.cellNodeContext,g=f.toNodePosition(),m=new Si(p.toNodePosition());r.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:m,cell:u});let w=f.viewNode;c.column.layoutContext.processFragmentedBlockEdge(c.cellNodeContext),o<u.rowIndex+u.rowSpan-1&&(w.rowSpan=o-u.rowIndex+1),c.empty?l.continueLoop():c.pseudoColumn.finishBreak(p,!1,!0).then(()=>{Mv(c,r,p),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),Ss(t),r.finishFragment(),a.finish(!0)}),a.result()}}return Ss(t),r.finishFragment(),ol.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){pn.prototype.clearOverflownViewNodes(e,t,i,n)}};function Mv(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=Et(o.clientLayout,a,r),l=o.getComputedPaddingBorder(a);if(r){let u=h.right-o.footnoteEdge-n.calculateOffset(i)-l.right;N(s,"max-width",`${u}px`)}else{let u=o.footnoteEdge-n.calculateOffset(i)-h.top-l.top;N(s,"max-height",`${u}px`)}}function Ss(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((c,p)=>{let f=p.getBoundingClientRect(),g=e.vertical?f.width:f.height;return c+g},0),r=i[i.length-1],o=Array.from(t.children).indexOf(r),s=Array.from(r.children).reduce((c,p)=>{let f=p.rowSpan;return f>1&&o+f<t.childElementCount?Math.max(c,f):c},0),a=s?t.children[o+s-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let c=a;c&&c!==t.lastElementChild;c=c.nextElementSibling)if(c.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=c;break}}let h=a.getBoundingClientRect(),l=e.vertical?h.width:h.height,u=n+l;N(a,e.vertical?"width":"height",`${u}px`)}var _v=class extends sl{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new Dv(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new Uv(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()}},Dv=class extends Jd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},zv=class extends Tr{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 Vv(this.position.sourceNode))}},Vv=class hp{constructor(t){this.tableRootNode=t,d(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,r){i.sourceNode,pr.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return T(!0)}equalsTo(t){return t instanceof hp&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},Uv=class extends Qd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new Hv(e);t.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},Hv=class up extends gl{constructor(t){super(t),d(this,"flagmentLayoutConstraintType","TableRow"),d(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||n.pseudoParent||un(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!ip(t,i,r):!0}nextCandidate(t){let i=Ft(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=Ft(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 lp().removeColGroups(o,s),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,r)}finishBreak(t,i){let n=Ft(this.nodeContext.formattingContext),r=_("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=Ft(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof up?Ft(this.nodeContext.formattingContext)===Ft(t.nodeContext.formattingContext):!1}},$v=new lp;function Wv(e,t,i,n,r,o){if(!t)return null;if(i===y.table){let s=e.parent;return new bn(s?s.formattingContext:null,e.sourceNode)}return null}function Gv(e){return e instanceof bn?$v:null}Nt("RESOLVE_FORMATTING_CONTEXT",Wv);Nt("RESOLVE_LAYOUT_PROCESSOR",Gv);function Lh(e){return e.reduce((t,i)=>t+i,0)/e.length}function jv(e){let t=Lh(e);return Lh(e.map(i=>{let n=i-t;return n*n}))}var Xv=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function fr(e){return e.vertical?e.width:e.height}function gr(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,d(this,"originalContainerBlockSize"),this.originalContainerBlockSize=fr(e)}balanceColumns(e){let t=_("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 Xv(e,t)}preBalance(e){}postBalance(){gr(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;N(i.element,"width",`${t}px`),N(i.element,"left",`${o}px`),i.width=t,i.left=o}}else{let n=parseFloat(i.element.style.height);isFinite(n)&&n>t&&(N(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)}},da=1;function dp(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+da}function pp(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+da))-da;n<fr(t)?gr(t,n):gr(t,fr(t)-1)}var qv=class extends cp{constructor(e,t,i,n){super(i,e,t),this.columnCount=n,d(this,"originalPosition",null),d(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);gr(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 Oh(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return dp(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!Oh(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):fr(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)pp(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,fr(this.layoutContainer)+this.originalContainerBlockSize*.1);gr(this.layoutContainer,t)}}};function Oh(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 Yv=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 jv(t)}hasNextCandidate(e){return dp(e)}updateCondition(e){pp(e,this.layoutContainer)}};function Zv(e,t,i,n,r,o,s){if(t===y.auto)return null;{let a=s.positions.length===0,h=o[o.length-1],l=!!(h&&h.pageBreakType);return a||l?new qv(i,n,r,e):t===y.balance_all?new Yv(i,n,r):(y.balance,null)}}var Kv=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],Jv=new Set(Kv);function Qv(e){return!(e.toLowerCase()==="none"||Jv.has(e))}var eb=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],tb=new Set(eb),ib=["fixed","extends"],nb=new Set(ib),Nx=Symbol();function Ir(e){return e instanceof ce&&e.name.toLowerCase()!=="none"}function fp(e){return e.name}function rb(e){if(e instanceof ce)return tb.has(e.name);if(e instanceof ee&&e.values.length===2){let t=e.values[0],i=e.values[1];if(t instanceof ce){let n=t.name;return nb.has(n)&&(n==="fixed"&&i instanceof ze||n==="extends"&&Ir(i))}}return!1}function ob(e){let t=lt(e,"system");return t instanceof ce&&t.name==="cyclic"}function sb(e){let t=lt(e,"system");if(t instanceof ce&&t.name==="fixed")return!0;if(t instanceof ee&&t.values.length===2){let[i,n]=t.values;return i instanceof ce&&i.name==="fixed"&&n instanceof ze}return!1}function ab(e){let t=lt(e,"system");return t instanceof ce?1:t.values[1].num}function lb(e){let t=lt(e,"system");return t instanceof ce&&t.name==="alphabetic"}function hb(e){let t=lt(e,"system");return t instanceof ce&&t.name==="numeric"}function ub(e){let t=lt(e,"system");return t instanceof ce&&t.name==="additive"}function cb(e){let t=lt(e,"system");if(t instanceof ee&&t.values.length===2){let[i,n]=t.values;return i instanceof ce&&i.name==="extends"&&Ir(n)}return!1}function db(e){let t=lt(e,"system");return fp(t.values[1])}function Bt(e){return e instanceof X||e instanceof ce}function ni(e){return e instanceof X?e.str:e.name}function gp(e){if(Bt(e))return!0;if(e instanceof ee&&e.values.length===2){let t=e.values[0],i=e.values[1];return Bt(t)&&Bt(i)}return!1}function pb(e){if(Bt(e))return{prefix:ni(e),suffix:null};{let t=e.values[0],i=e.values[1];return{prefix:ni(t),suffix:ni(i)}}}function Bh(e){return e instanceof ze||e instanceof ce&&e.name==="infinite"}function Mo(e,t){return e instanceof ze?e.num:t?-1/0:1/0}var Tx=Symbol();function pa(e){if(!(e instanceof ee&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(Bh(t)&&Bh(i)))return!1;let n=Mo(t,!0),r=Mo(i,!1);return!(n>r)}function fb(e){return{lower:Mo(e.values[0],!0),upper:Mo(e.values[1],!1)}}function mp(e){return e instanceof ce&&e.name==="auto"||pa(e)||e instanceof it&&e.values.length>=1&&e.values.every(t=>pa(t))}function gb(e){return e instanceof ce?null:(pa(e)?[e]:e.values).map(t=>fb(t))}var Ix=Symbol();function _o(e){if(!(e instanceof ee&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];return t instanceof ze&&t.num>=0&&Bt(i)||Bt(t)&&i instanceof ze&&i.num>=0}function Do(e){let[t,i]=e.values;return t instanceof ze?[t.num,ni(i)]:[i.num,ni(t)]}function wp(e){return _o(e)}function mb(e){let[t,i]=Do(e);return{minLength:t,symbol:i}}function yp(e){return Bt(e)||e instanceof ee&&e.values.length>=1&&e.values.every(t=>Bt(t))}function wb(e){return Bt(e)?[ni(e)]:e.values.map(t=>ni(t))}var Ax=Symbol();function vp(e){if(_o(e))return!0;if(e instanceof it&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!_o(i))return!1;let[n]=Do(i);if(n>=t)return!1;t=n}return!0}return!1}function yb(e){if(_o(e)){let[t,i]=Do(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=Do(t);return{weight:i,symbol:n}})}var vb=["auto","bullets","numbers","words","spell-out"],bb=new Set(vb);function xb(e){return e instanceof ce&&bb.has(e.name)||Ir(e)}function Sb(e,t){switch(e){case"system":return rb(t);case"negative":return gp(t);case"prefix":case"suffix":return Bt(t);case"range":return mp(t);case"pad":return wp(t);case"fallback":return Ir(t);case"symbols":return yp(t);case"additive-symbols":return vp(t);case"speak-as":return xb(t);default:return!0}}function lt(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function Cb(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function Tn(e){let t=e.get("decimal");return t||(t=ue.createDecimal(e),e.set("decimal",t)),t}var to,io,no,ro,oo,so,ao,lo,fa,ga,ma,wa,ya,va,ba,ct,Cs,bp,xp,Mh,_h,ks,Dh,jn,ui=class Ri{constructor(t,i){ne(this,ct),d(this,"_store"),ne(this,to),ne(this,io),ne(this,no),ne(this,ro),ne(this,oo),ne(this,so),ne(this,ao),ne(this,lo),this._store=t;let n=lt(i,"negative");De(this,to,n&&gp(n)?pb(n):null);let r=lt(i,"prefix");De(this,io,r&&Bt(r)?ni(r):null);let o=lt(i,"suffix");De(this,no,o&&Bt(o)?ni(o):null);let s=lt(i,"range");De(this,ro,s&&mp(s)?gb(s):null);let a=lt(i,"pad");De(this,oo,a&&wp(a)?mb(a):null);let h=lt(i,"fallback");De(this,so,h&&Ir(h)?fp(h):null);let l=lt(i,"symbols");De(this,ao,l&&yp(l)?wb(l):null);let u=lt(i,"additive-symbols");De(this,lo,u&&vp(u)?yb(u):null)}static create(t,i){return ob(i)?new Ni(t,i):sb(i)?new kb(t,i):lb(i)?new Pb(t,i):hb(i)?new zh(t,i):ub(i)?new Nb(t,i):cb(i)?new Tb(t,i):new Eb(t,i)}static createDecimal(t){return new zh(t,U(Ri,fa))}static createDisc(t){return new Ni(t,U(Ri,ga))}static createSquare(t){return new Ni(t,U(Ri,ma))}static createCircle(t){return new Ni(t,U(Ri,wa))}static createDisclosureOpen(t){return new Ni(t,U(Ri,ya))}static createDisclosureClosed(t){return new Ni(t,U(this,va))}static createNone(t){return new Ni(t,U(Ri,ba))}static get CHINESE_LONGHAND_NAMES(){return Vh.NAMES}static createChineseLonghand(t,i){return new Vh(t,i)}static createEthiopicNumeric(t){return new Ab(t)}_getNegative(){return U(this,to)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return U(this,io)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return U(this,no)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return U(this,ro)}static _getRangeFrom(t){return t._getRange()}_getPad(){return U(this,oo)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(U(this,so)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return U(this,ao)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return U(this,lo)}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 Ee(this,ct,jn).call(this,t,new Set)}formatMarker(t){return Ee(this,ct,bp).call(this)+this.format(t)+Ee(this,ct,xp).call(this)}};to=new WeakMap,io=new WeakMap,no=new WeakMap,ro=new WeakMap,oo=new WeakMap,so=new WeakMap,ao=new WeakMap,lo=new WeakMap,fa=new WeakMap,ga=new WeakMap,ma=new WeakMap,wa=new WeakMap,ya=new WeakMap,va=new WeakMap,ba=new WeakMap,ct=new WeakSet,Cs=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},bp=function(){var e;return(e=this._getPrefix())!=null?e:""},xp=function(){var e;return(e=this._getSuffix())!=null?e:". "},Mh=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},_h=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},ks=function(){var e;return(e=this._getFallback())!=null?e:Tn(this._store)},Dh=function(e,t){let{minLength:i,symbol:n}=Ee(this,ct,_h).call(this);if(i===0||n==="")return e;let{prefix:r,suffix:o}=Ee(this,ct,Cs).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},jn=function(e,t){var i,n,r;if(t.has(this))return Ee(i=Tn(this._store),ct,jn).call(i,e,new Set);if(t.add(this),!Cb(e,Ee(this,ct,Mh).call(this))){let l=Ee(this,ct,ks).call(this);return Ee(n=l,ct,jn).call(n,e,t)}let o=this._usesNegativeSign(e),s=o?Math.abs(e):e,a=this._generateInitialRepresentation(s);if(a===null){let l=Ee(this,ct,ks).call(this);return Ee(r=l,ct,jn).call(r,e,t)}let h=Ee(this,ct,Dh).call(this,a,o);if(o){let{prefix:l,suffix:u}=Ee(this,ct,Cs).call(this);h=l+h+(u??"")}return h},ne(ui,fa,{system:new V(B("numeric"),0),symbols:new V(new ee([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)}),ne(ui,ga,{system:new V(B("cyclic"),0),symbols:new V(new X("\u2022"),0),suffix:new V(new X(" "),0)}),ne(ui,ma,{system:new V(B("cyclic"),0),symbols:new V(new X("\u25AA"),0),suffix:new V(new X(" "),0)}),ne(ui,wa,{system:new V(B("cyclic"),0),symbols:new V(new X("\u25E6"),0),suffix:new V(new X(" "),0)}),ne(ui,ya,{system:new V(B("cyclic"),0),symbols:new V(new X("\u25BE"),0),suffix:new V(new X(" "),0)}),ne(ui,va,{system:new V(B("cyclic"),0),symbols:new V(new X("\u25B8"),0),suffix:new V(new X(" "),0)}),ne(ui,ba,{system:new V(B("cyclic"),0),symbols:new V(new X(""),0),suffix:new V(new X(""),0)});var ue=ui,Ni=class extends ue{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]}},ho,kb=class extends ue{constructor(e,t){super(e,t),ne(this,ho),De(this,ho,ab(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-U(this,ho);return(t=i[n])!=null?t:null}};ho=new WeakMap;var Eb=class extends ue{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)}},Pb=class extends ue{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 ue{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}},Nb=class extends ue{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}},rr,wt,kt,Sp=class extends ue{constructor(t,i){super(t,i),ne(this,wt),ne(this,rr);let n=db(i),r=n.toLowerCase();r==="disc"||r==="circle"||r==="square"||r==="disclosure-open"||r==="disclosure-closed"?De(this,rr,r):De(this,rr,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:ue._getNegativeFrom(Ee(this,wt,kt).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:ue._getPrefixFrom(Ee(this,wt,kt).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:ue._getSuffixFrom(Ee(this,wt,kt).call(this))}_getAutoRange(){return ue._getAutoRangeFrom(Ee(this,wt,kt).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:ue._getRangeFrom(Ee(this,wt,kt).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:ue._getPadFrom(Ee(this,wt,kt).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:ue._getFallbackFrom(Ee(this,wt,kt).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:ue._getSymbolsFrom(Ee(this,wt,kt).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:ue._getAdditiveSymbolsFrom(Ee(this,wt,kt).call(this))}_usesNegativeSign(t){return ue._useNegativeSignFrom(Ee(this,wt,kt).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:ue._generateInitialRepresentationFrom(Ee(this,wt,kt).call(this),t)}};rr=new WeakMap,wt=new WeakSet,kt=function(e=new Set){var t;if(e.has(this))return Tn(this._store);e.add(this);let i=this._store.get(U(this,rr));return i?i instanceof Sp?Ee(t=i,wt,kt).call(t,e):i:Tn(this._store)};var Tb=Sp,Ib=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],Es,Ps,$r,Ns,xa,uo,It=class Cp extends ue{constructor(t,i){let{chars:n,descriptors:r}=U(Cp,xa).get(i);super(t,r),ne(this,uo),De(this,uo,n)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=U(this,uo);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:c}=n[l],p=l===n.length-1;u===0?!p&&!h&&(h=!0):(h&&(a+=i.digits[0],h=!1),s&&c===1?a+=i.markers[c]:(a+=i.digits[u],c>0&&(a+=i.markers[c])))}return a}};Es=new WeakMap,Ps=new WeakMap,$r=new WeakMap,Ns=new WeakMap,xa=new WeakMap,uo=new WeakMap,ne(It,Es,{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(B("cjk-decimal"),0),range:new V(new ee([new ze(-9999),new ze(9999)]),0),negative:new V(new X("\u8D1F"),0)}}),ne(It,Ps,{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(B("cjk-decimal"),0),range:new V(new ee([new ze(-9999),new ze(9999)]),0),negative:new V(new X("\u8D1F"),0)}}),ne(It,$r,{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(B("cjk-decimal"),0),range:new V(new ee([new ze(-9999),new ze(9999)]),0),negative:new V(new X("\u8CA0"),0)}}),ne(It,Ns,{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(B("cjk-decimal"),0),range:new V(new ee([new ze(-9999),new ze(9999)]),0),negative:new V(new X("\u8CA0"),0)}}),d(It,"NAMES",new Set(Ib)),ne(It,xa,new Map([["simp-chinese-informal",U(It,Es)],["simp-chinese-formal",U(It,Ps)],["trad-chinese-informal",U(It,$r)],["trad-chinese-formal",U(It,Ns)],["cjk-ideographic",U(It,$r)]]));var Vh=It,Sa,Ca,zo,ka,Ea,an=class Li extends ue{constructor(t){super(t,U(Li,Sa))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return U(Li,zo)[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),c=a%10;o+=U(Li,Ca)[u]+U(Li,zo)[c]}h?a!==0&&(o+=U(Li,ka)):s!==0&&(o+=U(Li,Ea))}return o}};Sa=new WeakMap,Ca=new WeakMap,zo=new WeakMap,ka=new WeakMap,Ea=new WeakMap,ne(an,Sa,{range:new V(new ee([new ze(1),B("infinite")]),0),suffix:new V(new X("/ "),0)}),ne(an,Ca,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ne(an,zo,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ne(an,ka,"\u137B"),ne(an,Ea,"\u137C");var Ab=an,Ie,Fb=class{constructor(){ne(this,Ie),De(this,Ie,new Map),U(this,Ie).set("none",ue.createNone(U(this,Ie))),U(this,Ie).set("decimal",ue.createDecimal(U(this,Ie))),U(this,Ie).set("disc",ue.createDisc(U(this,Ie))),U(this,Ie).set("square",ue.createSquare(U(this,Ie))),U(this,Ie).set("circle",ue.createCircle(U(this,Ie))),U(this,Ie).set("disclosure-open",ue.createDisclosureOpen(U(this,Ie))),U(this,Ie).set("disclosure-closed",ue.createDisclosureClosed(U(this,Ie)));for(let e of ue.CHINESE_LONGHAND_NAMES)U(this,Ie).set(e,ue.createChineseLonghand(U(this,Ie),e));U(this,Ie).set("ethiopic-numeric",ue.createEthiopicNumeric(U(this,Ie)))}define(e,t){if(!Qv(e))return null;let i=ue.create(U(this,Ie),t);return U(this,Ie).set(e,i),i}getStyle(e){var t;return(t=U(this,Ie).get(e))!=null?t:null}format(e,t){var i;return((i=this.getStyle(e))!=null?i:Tn(U(this,Ie))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:Tn(U(this,Ie))).formatMarker(t)}};Ie=new WeakMap;var Ts=class{constructor(e,t,i){d(this,"endStuckFixed"),d(this,"endFixed"),d(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},Rb=class{constructor(){d(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 Ts(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 Ts(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new Ts(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=oi(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=oi(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}};function Lb(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}var Ob=class Pa{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,d(this,"flowName"),d(this,"isBlockValue",null),d(this,"hasBoxValue",null),d(this,"styleValues",{}),d(this,"beforeBox",null),d(this,"afterBox",null),d(this,"breakBefore",null),this.flowName=o.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let u=new Pa(t,l.before,n,!1,o,this.isBlock(),a,!0),c=u.styleValue("content");St(c)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=tt(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Xe(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 Pa(this.context,r.after,t,!1,this.flowChunk,i,n,!0),s=o.styleValue("content");St(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",y.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()!==y.none&&!So(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}},Bb=class{constructor(e){this.context=e,d(this,"stack",[]),d(this,"atBlockStart",!0),d(this,"atFlowStart",!0),d(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()!==y.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 Ob(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",y.normal).toString(),n=rd(i);n&&!Ve(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!")}},Uh=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,d(this,"root"),d(this,"cascadeHolder"),d(this,"last"),d(this,"rootStyle",{}),d(this,"styleMap",{}),d(this,"counterSnapshots",[]),d(this,"flows",{}),d(this,"flowChunks",[]),d(this,"flowListener",null),d(this,"flowToReach",null),d(this,"idToReach",null),d(this,"cascade"),d(this,"offsetMap"),d(this,"primary",!0),d(this,"primaryStack",[]),d(this,"rootBackgroundAssigned",!1),d(this,"rootLayoutAssigned",!1),d(this,"lastOffset"),d(this,"breakBeforeValues",{}),d(this,"boxStack"),d(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 Rb;let u=e.getElementOffset(this.root);this.lastOffset=u,this.boxStack=new Bb(n),this.offsetMap.addStuckRange(u);let c=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,c,u),this.recordCounterSnapshot(u,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes),this.postprocessTopStyle(c,!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}`]=c,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,Mc))}}}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)fn(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<Hh.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,Hh[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*zt.lh/zt.em;break;default:{let l=zt[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 xt)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=zt[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 qy(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}recordCounterSnapshot(e,t,i=[],n){let r={offset:e,counters:Lb(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=oi(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=ge(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=Fg(l.evaluate(this.context,"flow-options"));s=!!m.exclusive,a=!!m.static,h=!!m.last}let u=t["flow-linger"];u&&(o=ih(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let c=t["flow-priority"];c&&(r=ih(c.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 Cw(e,m)}let g=new kw(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(Xe(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(;;){let o=this.last.firstChild;if(o==null)for(;;){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.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 c=this.boxStack.nearestBlockStartOffset(l);if(c===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,c,l.flowName),l.beforeBox){let p=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(p,l.beforeBox.atBlockStart?c:l.offset,l.flowName)}if(this.primary&&l.displayValue()===y.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&&c===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){}},Hh=["column-count","column-width","column-fill"],gn=class{constructor(e){this.validator=e,d(this,"success",null),d(this,"failure",null),d(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)}},Ti=class{constructor(e,t){this.where=e,this.success=t,d(this,"what",-1)}},Vn=class kp{constructor(){d(this,"nodes",[]),d(this,"connections",[]),d(this,"match",[]),d(this,"nomatch",[]),d(this,"error",[]),d(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 kp;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],r=new gn(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 Ti(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 gn($h);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 Ti(r,!0),a=new Ti(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 gn($h);i.markAsStartAlternate(t),this.nodes.push(i);let n=new Ti(0,!0),r=new Ti(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 gn(t));let n=new Ti(i,!0),r=new Ti(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 Ue}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]}},Mb=1,Ep=2,Pp=4,Oi=8,co=16,Na=32,po=64,Np=128,Xn=256,qn=512,Ta=1024,Tp=2048,Ip=4096,Ap=8192,Fp=class extends li{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},Ue=class Rp extends Fp{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&Mb?t:null}visitSlash(t){return this.allowed&Tp?t:null}visitStr(t){return this.allowed&Ep?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&Pp||this.allowed&po&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&qn)?t.unit=="%"&&this.allowed&Ta?t:null:t.num<0&&!(this.allowed&Xn)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&qn?t:null:t.num<=0&&!(this.allowed&Xn)?null:this.allowed&co?t:null}visitInt(t){return t.num==0?this.allowed&qn?t:null:t.num<=0&&!(this.allowed&Xn)?null:this.allowed&(Na|co)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&po&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&Np?t:null}visitURange(t){return this.allowed&Ip?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){if(this.allowed&po){if(t.name==="device-cmyk"||t.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&tc(t)!==null?t:null;if(CSS.supports("color",t.toString()))return t}if(this.allowed&Ap){let i=t.visit(new rc);if(CSS.supports("background-image",i.toString()))return t}return t.name==="calc"&&this.allowed&(Oi|co|Na|Xn|qn|Ta)?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 Rp(this.allowed|t.allowed,i,n)}},ae=Object.create(null),$h=new Ue(0,ae,ae),ml=class extends Fp{constructor(e){super(),d(this,"successTerminal"),d(this,"failureTerminal"),d(this,"first"),this.successTerminal=new gn(null),this.failureTerminal=new gn(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 or&&this instanceof or){if(l=new ee(e).visit(r.validator),l){o=e.length,r=r.success;continue}}else if(o==0&&!t&&r.validator instanceof wl&&this instanceof or){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=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}},or=class extends ml{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new ee(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof wl){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)}},wl=class extends ml{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}},_b=class extends ml{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 $i(e.name,t):null}},Lp=class{tryParse(e,t,i){return t}success(e,t){}},Op=class extends Lp{constructor(e,t){super(),this.name=t,d(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 ee(n):n[0];return this.success(o,i),t+r}return t}success(e,t){t.values[this.name]=e}},Db=class extends Op{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}},zb=class extends Lp{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==Fn){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}},yl=class extends li{constructor(){super(...arguments),d(this,"syntax",null),d(this,"propList",null),d(this,"error",!1),d(this,"values",{}),d(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new Op(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:y.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)}},On=class extends yl{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}},Bp=class extends yl{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 Db(this.validatorSet,this.propList)}},Vb=class extends yl{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===Fn){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}},Ub=class extends On{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:y.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}},Hb=class extends On{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]===Fn){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 ee(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}},$b=class extends On{validateList(e){if(e.length===1&&e[0]instanceof ce)switch(e[0].name.toLowerCase()){case"normal":e=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":e=[y.auto,y.auto];break;case"none":e=[B("no-autospace"),B("space-all")];break}return super.validateList(e)}},Wb=["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"],Gb=class extends On{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)Wb.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},Wh={SIMPLE:On,INSETS:Bp,INSETS_SLASH:Vb,COMMA:Ub,FONT:Hb,TEXT_SPACING:$b,ALL:Gb},jb=["initial-letter"],Xb=class{constructor(){d(this,"validators",{}),d(this,"prefixes",{}),d(this,"defaultValues",{}),d(this,"namedValidators",{}),d(this,"systemFonts",{}),d(this,"shorthands",{}),d(this,"layoutProps",{}),d(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 Yu(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 Vn;if(e=="||"){for(let r=0;r<t.length;r++){let o=new Vn;o.startClause(r),o.addGroup(t[r],1),o.endClause(r),i.addGroup(o,r==0?1:4)}let n=new Vn;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 Vn;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 Vn;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new wl(t);break;case"SPACE":i=new or(t);break;default:i=new _b(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Ue(po,ae,ae)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Ue(Ap,ae,ae)),this.namedValidators.POS_INT=this.primitive(new Ue(Na,ae,ae)),this.namedValidators.POS_NUM=this.primitive(new Ue(co,ae,ae)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Ue(Oi,ae,{"%":Y})),this.namedValidators.NEGATIVE=this.primitive(new Ue(Xn,ae,ae)),this.namedValidators.ZERO=this.primitive(new Ue(qn,ae,ae)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Ue(Ta,ae,ae)),this.namedValidators.POS_LENGTH=this.primitive(new Ue(Oi,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 Ue(Oi,ae,{deg:Y,grad:Y,rad:Y,turn:Y})),this.namedValidators.POS_TIME=this.primitive(new Ue(Oi,ae,{s:Y,ms:Y})),this.namedValidators.FREQUENCY=this.primitive(new Ue(Oi,ae,{Hz:Y,kHz:Y})),this.namedValidators.RESOLUTION=this.primitive(new Ue(Oi,ae,{dpi:Y,dpcm:Y,dppx:Y})),this.namedValidators.URI=this.primitive(new Ue(Np,ae,ae)),this.namedValidators.URANGE=this.primitive(new Ue(Ip,ae,ae)),this.namedValidators.IDENT=this.primitive(new Ue(Pp,ae,ae)),this.namedValidators.STRING=this.primitive(new Ue(Ep,ae,ae)),this.namedValidators.SLASH=this.primitive(new Ue(Tp,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="",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 c=this.namedValidators[u.text];if(!c)throw new Error(`'${u.text}' unexpected`);i.push(c.clone())}else{let c={};c[u.text.toLowerCase()]=B(u.text),i.push(this.primitive(new Ue(0,c,ae)))}s=!1;break;case 5:{let c={};c[`${u.num}`]=new ze(u.num),i.push(this.primitive(new Ue(0,c,ae))),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 c=n.pop();if(c.b!="[")throw new Error("']' unexpected");i=c.vals,i.push(o),r=c.op,s=!1;break}case 11:{o=a();let c=n.pop();if(c.b!="(")throw new Error("')' unexpected");i=c.vals,i.push(this.newFunc(c.fn,o)),r=c.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 c=u.num,p=c;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(),c,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 or(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 xt(n.num));break;case 5:i.push(new ze(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 ee(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&Wh[i.text]?(n=new Wh[i.text],e.consume()):n=new On,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 Bp){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 zb(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:y.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){let r=n.ruleType;if(Zt(e)||r==="font-face"||Yb(t)){n.simpleProperty(e,t,i);return}if(r==="counter-style"){Sb(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&&!ku.includes(`-${o}-`)||n.unknownProperty(s,t);return}else if(jb.includes(e)&&!Object.keys(h).some(u=>Xr(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 Mp(){let e=new Xb;return e.initBuiltInValidators(),e.parse(Tc),e}var qb=class extends li{constructor(){super(...arguments),d(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function Yb(e){let t=new qb;return e.visit(t),t.varFound}var Rx=`OTTO${new Date().valueOf()}`;function vl(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function Zb(e){let t=new ri;for(let i of vl(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function Kb(e,t){let i={};for(let n in e)i[n]=ge(e,n).evaluate(t,n);return i}var _p=class{constructor(e){this.properties=e,d(this,"fontTraitKey"),d(this,"src"),d(this,"blobURLs",[]),d(this,"blobs",[]),d(this,"family"),this.fontTraitKey=Zb(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 ri;i.append(`@font-face {
1795
1845
  font-family: `),i.append(this.family),i.append(`;
1796
- `);for(let n of $a(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
1797
- `);if(t){i.append('src: url("');let n=wg(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
1846
+ `);for(let n of vl(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
1847
+ `);if(t){i.append('src: url("');let n=_m(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
1798
1848
  }
1799
- `),i.toString()}},bb=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 Ze){let t=e.values,i=[];for(let n of t){let r=this.familyMap[n.stringValue()];r&&i.push(F(r)),i.push(n)}return new Ze(i)}else{let t=this.familyMap[e.stringValue()];return t?new Ze([F(t),e]):e}}},vb=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=O("initFont"),r=e.src,s={};for(let h of $a(e.properties))s[h]=e.properties[h];let o=this.getViewFontFamily(e,i);s["font-family"]=F(o);let a=new zd(s),l=this.head.ownerDocument.createElement("style");return l.textContent=a.makeAtRule(r,t),this.head.appendChild(l),$.debug("Load font:",r),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i,r=this.srcURLMap[n];return r?r.piggyback(s=>{let o=s;o.traitsEqual(e)?(t.registerFamily(e,o),$.debug("Found already-loaded font:",i)):$.warn("E_FONT_FACE_INCOMPATIBLE",e.src)}):(r=new or(()=>{let s=O("loadFont"),o=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(o):null;return a?ws(o,"blob").then(l=>{if(!l.responseBlob){s.finish(null);return}a(l.responseBlob).then(h=>{this.initFont(e,h,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){$.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return ms(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=O("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?N(!0):N(!1))).thenFinish(i),i.result()}},xb=1,Ss=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${xb++}`,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})}},Sb=class extends Ss{constructor(e){super(e,null,null,[],null),this.specified.width=new _(rr,0),this.specified.height=new _(sr,0)}},gh=class extends to{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 l=this.lookupInstance(a);if(l)return s?l.resolveFunc(o[2]):l.resolveName(o[2])}}return null}}},Dd=class Vd extends Ss{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 gh||(this._scope=new gh(t,this)),this.pageMaster=this,this.specified.width=new _(rr,0),this.specified.height=new _(sr,0),this.specified["wrap-flow"]=new _(b.auto,0),this.specified.position=new _(b.relative,0),this.specified.overflow=new _(b.visible,0)}createInstance(t){return new Ga(t,this)}clone(t){let i=new Vd(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}},Hd=class Ud extends Ss{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 _(b.auto,0)}createInstance(t){return new Nb(t,this)}clone(t){let i=new Ud(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},dr=class $d extends Ss{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 dn(t,this)}clone(t){let i=new $d(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function Cb(e,t,i){return!t||K(t)?new We(e,i):t.toExpr(e,e.zero)}function fe(e,t,i){return!t||t===b.auto||K(t)?null:t.toExpr(e,i)}function kb(e,t,i){return!t||t===b.normal||K(t)?null:t.toExpr(e,i)}function ft(e,t,i){return!t||t===b.auto||K(t)?e.zero:t.toExpr(e,i)}function mh(e,t,i){return!t||K(t)?e.zero:t===b.auto?null:t.toExpr(e,i)}function _t(e,t,i,n){return!t||i===b.none||K(t)?e.zero:t.toExpr(e,n)}function Wd(e,t,i){return!t||K(t)?i:t===b._true?e._true:t===b._false?e._false:t.toExpr(e,e.zero)}var Cs=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 Y(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?Pc:Tc;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 fu(i,0),r=this.resolveName("column-count"),s=this.resolveName("column-width"),o=this.resolveName("column-gap");t=pe(i,Nr(i,new On(i,"min",[n,r]),Y(i,s,o)),o);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=Wd(e,t.enabled,e._true),n=fe(e,t.page,e.zero);if(n){let o=new De(e,"page-number");i=Et(e,i,new pa(e,n,o))}let r=fe(e,t["min-page-width"],e.zero);r&&(i=Et(e,i,new no(e,new De(e,"page-width"),r)));let s=fe(e,t["min-page-height"],e.zero);s&&(i=Et(e,i,new no(e,new De(e,"page-height"),s))),i=this.boxSpecificEnabled(i),t.enabled=new U(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=fe(e,t.left,i),r=fe(e,t["margin-left"],i),s=_t(e,t["border-left-width"],t["border-left-style"],i),o=ft(e,t["padding-left"],i),a=fe(e,t.width,i),l=fe(e,t["max-width"],i),h=ft(e,t["padding-right"],i),u=_t(e,t["border-right-width"],t["border-right-style"],i),d=fe(e,t["margin-right"],i),p=fe(e,t.right,i),f=Y(e,s,o),m=Y(e,s,h);if(n&&p&&a){let v=pe(e,i,Y(e,a,Y(e,Y(e,n,f),m)));r?d?p=pe(e,v,d):d=pe(e,v,Y(e,p,r)):(v=pe(e,v,p),d?r=pe(e,v,d):(r=Nr(e,v,new We(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 v=pe(e,i,Y(e,Y(e,r,f),Y(e,d,m)));this.isAutoWidth&&(l||(l=pe(e,v,n||p)),!this.vertical&&(fe(e,t["column-width"],null)||fe(e,t["column-count"],null))&&(a=l,this.isAutoWidth=!1)),n?a?p||(p=pe(e,v,Y(e,n,a))):a=pe(e,v,Y(e,n,p)):n=pe(e,v,Y(e,p,a))}let g=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=ft(e,g,i);t.left=new U(n),t["margin-left"]=new U(r),t["border-left-width"]=new U(s),t["padding-left"]=new U(o),t.width=new U(a),t["max-width"]=new U(l||a),t["padding-right"]=new U(h),t["border-right-width"]=new U(u),t["margin-right"]=new U(d),t.right=new U(p),t["snap-width"]=new U(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=fe(e,t.top,n),s=fe(e,t["margin-top"],i),o=_t(e,t["border-top-width"],t["border-top-style"],i),a=ft(e,t["padding-top"],i),l=fe(e,t.height,n),h=fe(e,t["max-height"],n),u=ft(e,t["padding-bottom"],i),d=_t(e,t["border-bottom-width"],t["border-bottom-style"],i),p=fe(e,t["margin-bottom"],i),f=fe(e,t.bottom,n),m=Y(e,o,a),g=Y(e,d,u);if(r&&f&&l){let y=pe(e,n,Y(e,l,Y(e,Y(e,r,m),g)));s?p?f=pe(e,y,s):p=pe(e,y,Y(e,f,s)):(y=pe(e,y,f),p?s=pe(e,y,p):(s=Nr(e,y,new We(e,.5)),p=s))}else{s||(s=e.zero),p||(p=e.zero),!r&&!f&&!l&&(r=e.zero),!r&&!l?(l=this.autoHeight,this.isAutoHeight=!0):!r&&!f?r=e.zero:!l&&!f&&(l=this.autoHeight,this.isAutoHeight=!0);let y=pe(e,n,Y(e,Y(e,s,m),Y(e,p,g)));this.isAutoHeight&&(h||(h=pe(e,y,r||f)),this.vertical&&(fe(e,t["column-width"],null)||fe(e,t["column-count"],null))&&(l=h,this.isAutoHeight=!1)),r?l?f||(f=pe(e,y,Y(e,r,l))):l=pe(e,y,Y(e,f,r)):r=pe(e,y,Y(e,f,l))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),v=ft(e,w,i);t.top=new U(r),t["margin-top"]=new U(s),t["border-top-width"]=new U(o),t["padding-top"]=new U(a),t.height=new U(l),t["max-height"]=new U(h||l),t["padding-bottom"]=new U(u),t["border-bottom-width"]=new U(d),t["margin-bottom"]=new U(p),t.bottom=new U(f),t["snap-height"]=new U(v)}initColumns(){let e=this.pageBox.scope,t=this.style,i=fe(e,t[this.vertical?"height":"width"],null),n=fe(e,t["column-width"],i),r=fe(e,t["column-count"],null),s=kb(e,t["column-gap"],null);s||(s=new nr(e,1,"em")),n&&!r&&(r=new On(e,"floor",[ro(e,Y(e,i,s),Y(e,n,s))]),r=new On(e,"max",[e.one,r])),r||(r=e.one),n=pe(e,ro(e,Y(e,i,s),r),s),t["column-width"]=new U(n),t["column-count"]=new U(r),t["column-gap"]=new U(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=Xc(this.cascaded,e,r,!1,null);this.vertical=Gc(s,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=jc(s,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=s["box-sizing"])==null?void 0:t.value)===b.border_box;let o=!!(e instanceof Ka&&e.currentLayoutPosition&&new De(i,"left-page").evaluate(e));Yc(s,n,this.vertical,this.rtl,o,(a,l)=>l.value),this.autoWidth=new ze(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new ze(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&&zn(t)&&this.pageMasterInstance instanceof sn&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?r=new I(e.rootFontSize,"px"):r=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),r&&(r=ns(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=ns(e,r,t,s)}return et(r,e)}getSpecial(e,t){let i=Rc(this.cascaded,t);if(i){let n=[];for(let r=0;r<i.length;r++){let s=i[r].evaluate(e,"");s&&s!==X&&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()&&nu(r.unit)&&(r=xu(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),T(t,i,r.toString()))}propagateDelayedProperty(e,t,i,n){let r=this.getProp(e,i);r&&n.push(new xa(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),T(t.element,"margin-left",`${n}px`),T(t.element,"padding-left",`${r}px`),T(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(T(t.element,"margin-right",`${r}px`),T(t.element,"padding-right",`${s}px`),T(t.element,"border-right-width",`${o}px`),t.marginRight=r,t.borderRight=o,this.vertical&&n>0){let a=i+t.getInsetRight(),l=a-Math.floor(a/n)*n;l>0&&(t.snapOffsetX=n-l,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(),l=a-Math.floor(a/i)*i;l>0&&(t.snapOffsetY=i-l,s+=t.snapOffsetY)}t.paddingTop=s,T(t.element,"top",`${n}px`),T(t.element,"margin-top",`${r}px`),T(t.element,"padding-top",`${s}px`),T(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;T(t.element,"height",`${s}px`),T(t.element,"margin-bottom",`${i}px`),T(t.element,"padding-bottom",`${n}px`),T(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){T(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,T(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){T(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");T(t.element,"right",`${n}px`),T(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,r){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&T(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&T(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<wh.length;s++)this.propagateProperty(e,t,wh[s],n)}transferContentProps(e,t,i,n){for(let r=0;r<bh.length;r++)this.propagateProperty(e,t,bh[r],n);if(this.style["text-overflow"]){let r=t.element.firstElementChild;T(r,"text-overflow","inherit"),T(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!==b.auto&&!K(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!==b.auto&&!K(a)};for(let s=0;s<vh.length;s++){let o=vh[s];if(o==="width"||o==="height"){if(o==="width"&&!n()||o==="height"&&!r())continue;T(t,o,"100%");continue}this.propagatePropertyToElement(e,t,o,i)}}finishContainer(e,t,i,n,r,s,o){this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let a=(this.vertical||!n)&&this.isAutoHeight,l=(!this.vertical||!n)&&this.isAutoWidth,h=null;if(l||a){l&&T(t.element,"width","auto"),a&&T(t.element,"height","auto");let u=n&&xc(n);u&&ka(n),h=s.getElementClientRect(n?n.element:t.element),u&&Ca(n),l&&(this.calculatedWidth=Math.ceil(h.right-h.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),a&&(this.calculatedHeight=h.bottom-h.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 u=this.getPropAsNumber(e,"column-rule-width"),d=this.getProp(e,"column-rule-style"),p=this.getProp(e,"column-rule-color");if(u>0&&d&&d!=b.none&&p!=b.transparent){let f=this.getPropAsNumber(e,"column-gap"),m=this.vertical?t.height:t.width,g=this.vertical?"border-top":"border-left";for(let w=1;w<r;w++){let v=this.vertical?(m+f)*w/r-f/2+t.paddingTop-u/2:(m+f)*w/r-f/2+t.paddingLeft-u/2,y=this.vertical?t.width+t.paddingLeft+t.paddingRight:t.height+t.paddingTop+t.paddingBottom,C=t.element.ownerDocument.createElement("div");T(C,"position","absolute"),T(C,this.vertical?"left":"top","0px"),T(C,this.vertical?"top":"left",`${v}px`),T(C,this.vertical?"height":"width","0px"),T(C,this.vertical?"width":"height",`${y}px`),T(C,g,`${u}px ${d.toString()}${p?` ${p.toString()}`:""}`),t.element.insertBefore(C,t.element.firstChild)}}}for(let u=0;u<yh.length;u++)this.propagateProperty(e,t,yh[u],o);for(let u=0;u<xh.length;u++)this.propagateDelayedProperty(e,t,xh[u],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let s in n)this instanceof sn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(s==="writing-mode"||s==="direction")||Ei(s)&&Pi(i,s,Re(n,s));if(this.pageBox.pseudoName==Wa)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 Fo(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)}},wh=["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"],yh=["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"],bh=["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"],vh=["width","height","image-resolution","object-fit","object-position"],xh=["transform","transform-origin"],Wa="background-host",Eb=class extends Cs{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)}},Ga=class extends Cs{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=Et(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},Nb=class extends Cs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},dn=class extends Cs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof le&&(n=[t]),t instanceof Ze&&(n=t.values),n){let r=this.pageBox.scope;for(let s=0;s<n.length;s++)if(n[s]instanceof le){let o=eo(n[s].name,"enabled"),a=new De(r,o);i&&(a=new si(r,a)),e=Et(r,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=Wd(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let r=Cb(t,i["flow-from"],"body"),s=new On(t,"has-content",[r]);e=Et(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=Et(t,s,e),this.pageMasterInstance.style.enabled=new U(s)}return e}prepareContainer(e,t,i,n,r){var s;this.pageBox.pageMaster instanceof Yd||(T(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(s=this.pageBox.name)!=null?s:"")),super.prepareContainer(e,t,i,n,r)}},ja=class extends ar{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 _(t,i?qu:Yu)}},Gd=class extends ja{constructor(e,t,i,n){super(e,t,i,n)}},Pb=class jd extends ja{constructor(t,i,n,r){super(t,i,n,r),n.specified.width=new _(yl,0),n.specified.height=new _(yl,0)}startPartitionRule(t,i,n){let r=new dr(this.scope,t,i,n,this.target),s=new Gd(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(t,i,n){let r=new Hd(this.scope,t,i,n,this.target),s=new jd(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(s)}},Tb=class extends ja{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new dr(this.scope,e,t,i,this.target),r=new Gd(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(e,t,i){let n=new Hd(this.scope,e,t,i,this.target),r=new Pb(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}};function Xd(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===b.vertical_lr||n!==b.vertical_rl&&r!==b.rtl?"ltr":"rtl"}var Ib={a10:{width:new I(26,"mm"),height:new I(37,"mm")},a9:{width:new I(37,"mm"),height:new I(52,"mm")},a8:{width:new I(52,"mm"),height:new I(74,"mm")},a7:{width:new I(74,"mm"),height:new I(105,"mm")},a6:{width:new I(105,"mm"),height:new I(148,"mm")},a5:{width:new I(148,"mm"),height:new I(210,"mm")},a4:{width:new I(210,"mm"),height:new I(297,"mm")},a3:{width:new I(297,"mm"),height:new I(420,"mm")},a2:{width:new I(420,"mm"),height:new I(594,"mm")},a1:{width:new I(594,"mm"),height:new I(841,"mm")},a0:{width:new I(841,"mm"),height:new I(1189,"mm")},b10:{width:new I(31,"mm"),height:new I(44,"mm")},b9:{width:new I(44,"mm"),height:new I(62,"mm")},b8:{width:new I(62,"mm"),height:new I(88,"mm")},b7:{width:new I(88,"mm"),height:new I(125,"mm")},b6:{width:new I(125,"mm"),height:new I(176,"mm")},b5:{width:new I(176,"mm"),height:new I(250,"mm")},b4:{width:new I(250,"mm"),height:new I(353,"mm")},b3:{width:new I(353,"mm"),height:new I(500,"mm")},b2:{width:new I(500,"mm"),height:new I(707,"mm")},b1:{width:new I(707,"mm"),height:new I(1e3,"mm")},b0:{width:new I(1e3,"mm"),height:new I(1414,"mm")},c10:{width:new I(28,"mm"),height:new I(40,"mm")},c9:{width:new I(40,"mm"),height:new I(57,"mm")},c8:{width:new I(57,"mm"),height:new I(81,"mm")},c7:{width:new I(81,"mm"),height:new I(114,"mm")},c6:{width:new I(114,"mm"),height:new I(162,"mm")},c5:{width:new I(162,"mm"),height:new I(229,"mm")},c4:{width:new I(229,"mm"),height:new I(324,"mm")},c3:{width:new I(324,"mm"),height:new I(458,"mm")},c2:{width:new I(458,"mm"),height:new I(648,"mm")},c1:{width:new I(648,"mm"),height:new I(917,"mm")},c0:{width:new I(917,"mm"),height:new I(1297,"mm")},"jis-b10":{width:new I(32,"mm"),height:new I(45,"mm")},"jis-b9":{width:new I(45,"mm"),height:new I(64,"mm")},"jis-b8":{width:new I(64,"mm"),height:new I(91,"mm")},"jis-b7":{width:new I(91,"mm"),height:new I(128,"mm")},"jis-b6":{width:new I(128,"mm"),height:new I(182,"mm")},"jis-b5":{width:new I(182,"mm"),height:new I(257,"mm")},"jis-b4":{width:new I(257,"mm"),height:new I(364,"mm")},"jis-b3":{width:new I(364,"mm"),height:new I(515,"mm")},"jis-b2":{width:new I(515,"mm"),height:new I(728,"mm")},"jis-b1":{width:new I(728,"mm"),height:new I(1030,"mm")},"jis-b0":{width:new I(1030,"mm"),height:new I(1456,"mm")},letter:{width:new I(8.5,"in"),height:new I(11,"in")},legal:{width:new I(8.5,"in"),height:new I(14,"in")},ledger:{width:new I(11,"in"),height:new I(17,"in")}},Ab=new I(.24,"pt"),Q0=new I(3,"mm"),Rb=new I(10,"mm"),Fb=new I(13,"mm");function us(e){let t={width:rr,height:sr,bleed:Ee,bleedOffset:Ee,cropOffset:Ee},i=e.size;if(!(!i||i.value===b.auto)){let h=i.value,u,d;if(h.isSpaceList()?(u=h.values[0],d=h.values[1]):(u=h,d=null),u.isNumeric())t.width=u,t.height=d||u;else{let p=u.name&&Ib[u.name.toLowerCase()];p&&(d&&d===b.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&&!K(n.value)?n.value:b.none,o=r&&!K(r.value)?r.value:b.auto;if(o===b.auto){if(s!==b.none){let h=!1;s.isSpaceList()?h=s.values.some(u=>u===b.crop):h=s===b.crop,h&&(t.bleed=new I(6,"pt"))}}else o.isNumeric()&&(t.bleed=o);let a=e["crop-offset"],l=a&&!K(a.value)?a.value:b.auto;return l===b.auto?s!==b.none&&(t.bleedOffset=Fb):l.isNumeric()&&(t.cropOffset=l),t}function Sh(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===rr?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===sr?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 qd(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 $n(e,t,i,n){n=n||"polyline";let r=e.createElementNS("http://www.w3.org/2000/svg",n);return r.setAttribute("stroke",i===b.auto?"#010101":i.toString()),r.setAttribute("stroke-width",t),r.setAttribute("fill","none"),r}var Qo=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(Qo||{});function Lb(e,t,i,n,r,s,o){let a=r;a<=s+2*At.mm&&(a=s+r/2);let l=Math.max(r,a),h=s+l+i/2,u=qd(e,h,h),d=[[0,s+r],[r,s+r],[r,s+r-a]],p=d.map(g=>[g[1],g[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(g=>[s+l-g[0],g[1]]),p=p.map(g=>[s+l-g[0],g[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(g=>[g[0],s+l-g[1]]),p=p.map(g=>[g[0],s+l-g[1]]));let f=$n(e,i,n);f.setAttribute("points",d.map(g=>g.join(",")).join(" ")),u.appendChild(f);let m=$n(e,i,n);return m.setAttribute("points",p.map(g=>g.join(",")).join(" ")),u.appendChild(m),t.split(" ").forEach(g=>{u.style[g]=`${o}px`}),u}var Qn=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(Qn||{});function Ob(e,t,i,n,r,s){let o=r*2,a,l;t==="top"||t==="bottom"?(a=o,l=r):(a=r,l=o);let h=qd(e,a,l),u=$n(e,i,n);u.setAttribute("points",`0,${l/2} ${a},${l/2}`),h.appendChild(u);let d=$n(e,i,n);d.setAttribute("points",`${a/2},0 ${a/2},${l}`),h.appendChild(d);let p=$n(e,i,n,"circle");p.setAttribute("cx",a/2),p.setAttribute("cy",l/2),p.setAttribute("r",r/4),h.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(Qn).forEach(m=>{let g=Qn[m];g===t?h.style[g]=`${s}px`:g!==f&&(h.style[g]="0",h.style[`margin-${g}`]="auto")}),h}function Bb(e,t,i,n){let r=!1,s=!1,o=e.marks;if(o){let g=o.value;g instanceof J?g.values.forEach(w=>{w===b.crop?r=!0:w===b.cross&&(s=!0)}):g===b.crop?r=!0:g===b.cross&&(s=!0)}let a=t.bleed;if(!r&&!s)return;let l=i.container,h=l.ownerDocument,u=et(Ab,n),d=Math.max(0,t.bleedOffset-et(Rb,n)),p=t.bleedOffset-d,f=e["crop-marks-line-color"],m=f&&!K(f.value)?f.value:b.auto;r&&Object.keys(Qo).forEach(g=>{let w=Qo[g],v=Lb(h,w,u,m,p,a,d);l.appendChild(v)}),s&&Object.keys(Qn).forEach(g=>{let w=Qn[g],v=Ob(h,w,u,m,p,d);l.appendChild(v)})}var ea=(()=>{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})(),Xa={"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"}},Mb=(()=>{let e=Xa;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),qa="vivliostyle-page-rule-master",er="_marginBoxes",Yd=class extends Dd{constructor(e,t,i){super(e,null,qa,[],t,null,0),c(this,"pageMarginBoxes",{});let n=us(i),r=new _b(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[er];t&&Mb.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new Db(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new _(b.relative,0),this.specified.width=new _(t.width,0),this.specified.height=new _(t.height,0);for(let i in e)!ea[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new sn(e,this)}},_b=class extends dr{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let r=new zb(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new _(b.auto,0),this.specified["z-index"]=new _(new Le(0),0),this.specified.position=new _(b.absolute,0),this.specified.overflow=new _(b.visible,0);for(let t in ea)ea.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new Hb(e,this)}},zb=class extends dr{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new _(F("body"),0)}createInstance(e){return new Kd(e,this)}},Db=class extends dr{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[er][this.marginBoxName];for(let i in e){let n=e[i],r=t[i];(Nc[i]||r&&r.value===b.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==X&&n.value!==b.inherit&&n.value!==b.unset&&n.value!==b.revert&&(this.specified[i]=n)}}createInstance(e){return new Zd(e,this)}},sn=class extends Ga{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=Ee,e["margin-left"]=Ee,e["border-left-width"]=Ee,e["padding-left"]=Ee,e["padding-right"]=Ee,e["border-right-width"]=Ee,e["margin-right"]=Ee,e.right=Ee}initVertical(){let e=this.style;e.top=Ee,e["margin-top"]=Ee,e["border-top-width"]=Ee,e["padding-top"]=Ee,e["padding-bottom"]=Ee,e["border-bottom-width"]=Ee,e["margin-bottom"]=Ee,e.bottom=Ee}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new U(e.borderBoxWidth),t.height=new U(e.borderBoxHeight),t["padding-left"]=new U(e.marginLeft),t["padding-right"]=new U(e.marginRight),t["padding-top"]=new U(e.marginTop),t["padding-bottom"]=new U(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",l=this.pageBox.scope,h={},u={},d={};for(let C in e){let E=Xa[C];if(E){let A=e[C],H=this.pageMarginBoxInstances[C],V=new Wr(A,H.style,t,l,r);h[E.positionAlongVariableDimension]=A,u[E.positionAlongVariableDimension]=H,d[E.positionAlongVariableDimension]=V}}let p={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),m=!1,g={};Object.keys(h).forEach(C=>{let E=C,A=fe(l,u[E].style[t?"max-width":"max-height"],i.extent);if(A){let H=A.evaluate(n);if(f[E]>H){let V=d[E]=new Ch(h[E],u[E].style,t,l,r,H);g[E]=V.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),m=!1,[s,o,a].forEach(C=>{var E;f[C]=(E=g[C])!=null?E:f[C]}));let w={};Object.keys(h).forEach(C=>{let E=C,A=fe(l,u[E].style[t?"min-width":"min-height"],i.extent);if(A){let H=A.evaluate(n);if(f[E]<H){let V=d[E]=new Ch(h[E],u[E].style,t,l,r,H);w[E]=V.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),[s,o,a].forEach(C=>{f[C]=w[C]||f[C]}));let v=p.start+p.extent,y=p.start+(p.start+p.extent);[s,o,a].forEach(C=>{let E=f[C];if(E!=null){let A=h[C],H=0;switch(C){case s:H=t?A.left:A.top;break;case o:H=(y-E)/2;break;case a:H=v-E;break}t?A.setHorizontalPosition(H,E-A.getInsetLeft()-A.getInsetRight()):A.setVerticalPosition(H,E-A.getInsetTop()-A.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,r=e.center,s=e.end,o={};if(r){let a=[n,s],l=new Vb(a),h=this.distributeAutoMarginBoxSizes(r,l,t);h.xSize!=null&&(o.center=h.xSize);let u=(i=h.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 Wr&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof Wr&&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(),l=t.getOuterMinContentSize(),h=a+l;h<i?n.xSize=a+(i-h)*(r-a)/(o-h):h>0&&(n.xSize=i*a/h)}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)}},Wr=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===b.auto||K(s),this.minMaxFitContent=s instanceof le&&(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()}},Vb=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}},Ch=class extends Wr{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()}},Hb=class extends dn{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),l=fe(n,t[o],a),h=fe(n,t[`margin-${r}`],a),u=fe(n,t[`margin-${s}`],a),d=ft(n,t[`padding-${r}`],a),p=ft(n,t[`padding-${s}`],a),f=_t(n,t[`border-${r}-width`],t[`border-${r}-style`],a),m=_t(n,t[`border-${s}-width`],t[`border-${s}-style`],a),g=Y(n,Y(n,f,d),Y(n,m,p)),w,v,y;return l?(this.borderBoxSizing?(v=l,y=pe(n,v,g)):(y=l,v=Y(n,y,g)),w=pe(n,a,v),!h&&!u?(h=Nr(n,w,new We(n,.5)),u=h):h?u=pe(n,w,h):h=pe(n,w,u)):(h||(h=n.zero),u||(u=n.zero),w=Y(n,h,u),v=pe(n,a,w),y=pe(n,v,g),l=this.borderBoxSizing?v:y),t[r]=new U(h),t[s]=new U(u),t[`margin-${r}`]=Ee,t[`margin-${s}`]=Ee,t[`border-${r}-width`]=new U(f),t[`border-${s}-width`]=new U(m),t[`padding-${r}`]=new U(d),t[`padding-${s}`]=new U(p),t[o]=new U(l),t[`max-${o}`]=new U(l),{borderBoxExtent:v,contentBoxExtent:y,marginStart:h,marginEnd:u}}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,r)}},Kd=class extends dn{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 U(this.parentInstance.contentBoxWidth),e["margin-left"]=new U(new ji(i,t.left.toExpr(i,null))),e["margin-right"]=new U(new ji(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=b.solid,e["border-right-style"]=b.solid,e["border-left-color"]=b.transparent,e["border-right-color"]=b.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new U(this.parentInstance.contentBoxHeight),e["margin-top"]=new U(new ji(i,t.top.toExpr(i,null))),e["margin-bottom"]=new U(new ji(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=b.solid,e["border-bottom-style"]=b.solid,e["border-top-color"]=b.transparent,e["border-bottom-color"]=b.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}},Zd=class extends dn{constructor(e,t){super(e,t),c(this,"boxInfo"),c(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=Xa[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){T(t,"display","flex"),T(t,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let i=this.getProp(e,"vertical-align"),n=null;i===F("middle")?n="center":i===F("top")?n="flex-start":i===F("bottom")&&(n="flex-end"),n&&T(t,"justify-content",n);let r=this.getProp(e,"content");if(this.vertical||r instanceof Qe||r instanceof U&&r.expr instanceof ze&&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")),T(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",l=a?t.borderBoxWidth:t.borderBoxHeight,h=fe(n,i[o],l),u=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[r]=new U(u);else if(h){let d=ft(n,i[`margin-${r}`],l),p=ft(n,i[`margin-${s}`],l),f=ft(n,i[`padding-${r}`],l),m=ft(n,i[`padding-${s}`],l),g=_t(n,i[`border-${r}-width`],i[`border-${r}-style`],l),w=_t(n,i[`border-${s}-width`],i[`border-${s}-style`],l),v=Y(n,h,Y(n,this.borderBoxSizing?n.zero:Y(n,Y(n,f,m),Y(n,g,w)),Y(n,d,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[r]=new U(Y(n,u,ro(n,pe(n,l,v),new We(n,2))));break;case"end":i[r]=new U(pe(n,Y(n,u,l),v));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,r=this.borderBoxSizing,s=e.inside,o=e.outside,a=e.extent,l=t[`margin${o.charAt(0).toUpperCase()}${o.substring(1)}`],h=mh(n,i[`margin-${s}`],l),u=mh(n,i[`margin-${o}`],l),d=ft(n,i[`padding-${s}`],l),p=ft(n,i[`padding-${o}`],l),f=_t(n,i[`border-${s}-width`],i[`border-${s}-style`],l),m=_t(n,i[`border-${o}-width`],i[`border-${o}-style`],l),g=fe(n,i[a],l),w=null;function v(y){if(w)return w;w={extent:g?g.evaluate(y):null,marginInside:h?h.evaluate(y):null,marginOutside:u?u.evaluate(y):null};let C=l.evaluate(y),E=0;return r||[f,d,p,m].forEach(A=>{A&&(E+=A.evaluate(y))}),(w.marginInside===null||w.marginOutside===null)&&E+w.extent+w.marginInside+w.marginOutside>C&&(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=C-E-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=C-E-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=C-E-w.extent-w.marginInside:w.marginInside=w.marginOutside=(C-E-w.extent)/2),w}i[a]=new U(new ze(n,function(){let y=v(this).extent;return y===null?"auto":y},a)),i[`margin-${s}`]=new U(new ze(n,function(){let y=v(this).marginInside;return y===null?"auto":y},`margin-${s}`)),i[`margin-${o}`]=new U(new ze(n,function(){let y=v(this).marginOutside;return y===null?"auto":y},`margin-${o}`)),s==="left"?i.left=new U(Y(n,t.marginLeft,t.borderBoxWidth)):s==="top"&&(i.top=new U(Y(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,l=this.pageBox.marginBoxName,h=this.boxInfo;!h.isInLeftColumn&&!h.isInRightColumn?h.isInTopRow?a.top[l]=t:h.isInBottomRow&&(a.bottom[l]=t):!h.isInTopRow&&!h.isInBottomRow&&(h.isInLeftColumn?a.left[l]=t:h.isInRightColumn&&(a.right[l]=t));let u=this.parentInstance.pageAreaDimension,d=this.getProp(e,"width"),p=d instanceof le&&(d.name==="min-content"||d.name==="max-content"||d.name==="fit-content")?d.name:null,f=this.getPropAsNumber(e,"min-width"),m=this.getPropAsNumber(e,"max-width");if(p||f||m){p&&T(t.element,"width",p),f&&T(t.element,"min-width",`${f}px`),m&&T(t.element,"max-width",`${m}px`);let C=this.getProp(e,"margin-left"),E=this.getProp(e,"margin-right");if(h.isInLeftColumn){let A=u.borderBoxWidth.evaluate(e)+u.marginRight.evaluate(e);T(t.element,"right",`${A}px`),(C===b.auto||E!==b.auto)&&T(t.element,"margin-left","auto"),E===b.auto&&T(t.element,"margin-right","auto")}else h.isInRightColumn&&(T(t.element,"right","0"),(E===b.auto||C!==b.auto)&&T(t.element,"margin-right","auto"),C===b.auto&&T(t.element,"margin-left","auto"))}let g=this.getProp(e,"height"),w=g instanceof le&&(g.name==="min-content"||g.name==="max-content"||g.name==="fit-content")?g.name:null,v=this.getPropAsNumber(e,"min-height"),y=this.getPropAsNumber(e,"max-height");if(w||v||y){w&&T(t.element,"height",w),v&&T(t.element,"min-height",`${v}px`),y&&T(t.element,"max-height",`${y}px`);let C=this.getProp(e,"margin-top"),E=this.getProp(e,"margin-bottom");if(h.isInTopRow){let A=u.borderBoxHeight.evaluate(e)+u.marginBottom.evaluate(e);T(t.element,"bottom",`${A}px`),(C===b.auto||E!==b.auto)&&T(t.element,"margin-top","auto"),E===b.auto&&T(t.element,"margin-bottom","auto")}else h.isInBottomRow&&(T(t.element,"bottom","0"),(E===b.auto||C!==b.auto)&&T(t.element,"margin-bottom","auto"),C===b.auto&&T(t.element,"margin-top","auto"))}}},Ub=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 De(e,"page-number"),r=new pa(e,new uu(e,n,new We(e,2)),i?e.one:e.zero);e.defineName("recto-page",new si(e,r)),e.defineName("verso-page",r),(t.pageProgression||Xd(this.docElementStyle))==="ltr"?(e.defineName("left-page",r),e.defineName("right-page",new si(e,r))):(e.defineName("left-page",new si(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===Wa?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 _?r=`${n.value}`:r=this.makeCascadeValueObjectKey(n),t.push(i+r+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new Yd(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:qa}),n=i.specified,r=e.size;if(r&&!K(r.value)){let o=us(e),a=r.priority;qt(n,"width",new _(o.width,a),this.context),qt(n,"height",new _(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}},$b=class extends ve{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}},Wb=class extends ve{constructor(e){super(),this.scope=e}apply(e){new De(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},Gb=class extends ve{constructor(e){super(),this.scope=e}apply(e){new De(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},jb=class extends ve{constructor(e){super(),this.scope=e}apply(e){new De(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Xb=class extends ve{constructor(e){super(),this.scope=e}apply(e){new De(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},qb=class extends ve{constructor(e){super(),this.scope=e}apply(e){new De(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Yb=class extends ve{constructor(e){super(),this.scope=e}apply(e){new De(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Kb=class extends Fi{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}},Zb=class extends Fi{constructor(e,t,i,n){super(t,i),this.scope=e,this.a=t,this.b=i,this.pageType=n}apply(e){if(e.currentPageType!==this.pageType)return;let t=e.pageTypePageCounts[this.pageType]||0;this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 3}},Jb=class extends La{constructor(e,t){super(e,t,null,null,null)}apply(e){Qb(e.context,e.currentStyle,this.style,this.specificity,e)}};function Qb(e,t,i,n,r){is(e,t,i,n,null,null,null);let s=i[er];if(s){let o=ur(t,er);for(let a in s)if(s.hasOwnProperty(a)){let l=o[a];l||(l={},o[a]=l),is(e,l,s[a],n,null,null,null)}}}var e0=class extends Yn{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 $b(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 Zb(this.scope,i,n,r)),this.specificity+=256}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new Kb(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 Wb(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new Gb(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new jb(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new Xb(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new qb(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Yb(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=Re(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(s=>{Pi(r[s],e,n)});else if(e==="size"){let s=r[""];this.currentPageSelectors.forEach(o=>{let a=new _(n.value,n.priority+o.specificity),l=o.selectors?o.selectors.join(""):"",h=r[l];h?qt(h,e,a):(h=r[l]={},Pi(h,e,a),s&&["bleed","marks"].forEach(u=>{s[u]&&Pi(h,u,s[u])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new Jb(this.elementStyle,e)}startPageMarginBoxRule(e){let t=ur(this.elementStyle,er),i=t[e];i||(i={},t[e]=i);let n=new t0(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},t0=class extends ar{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 _(t,n);Pi(this.boxStyle,e,r)}},Yt=!0;function i0(e){Yt=e}var Ti=[];function kh(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Jd(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 Ya(e,t,i){if(!Yt||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Jd(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,l=(s&&!a||r&&e.defer)&&!o,h=!(i!=null&&i.atEnd)&&(i?.forceDefer||l||a);if(Qd(t)||(t.onload=null),h)return Ti.some(d=>kh(d,e))||Ti.push(e),N(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&kh(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=l,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($.debug("script:",r),r){let d=Hi(u);return t.document.head.appendChild(u),ms([d])}else return t.document.head.appendChild(u),N(!0)}function n0(e,t){var i;let n={},r=o=>{var a;let l=(a=o["font-family"])==null?void 0:a.value;if(l)if(l.values)for(let u of l.values)n[u.stringValue()]=!0;else n[l.stringValue()]=!0;let h=o._marginBoxes;if(h)for(let u of Object.values(h))r(u)},s=o=>{if(o instanceof La)r(o.style);else if(o instanceof wn||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 r0(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=n0(e,i),r.textContent=e.documentElement.textContent,t.document.body.appendChild(r),r}function s0(e,t,i){if(!Yt)return N(!1);let n=Jd(e);if(n.length===0)return N(!1);let r=n.some(u=>!(u.async||u.defer||u.type==="module")),s=r?r0(e,t,i):null,o=t.document.fonts,a=t.$,l=!1,h=O("loadScripts");return h.loop(()=>{if(n.length===0)return r?h.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 Ya(u,t,{inHead:!0,forceDefer:l}).thenAsync(()=>(!l&&t.$!==a&&(Ti.push(u),l=!0),n.length===0&&r&&($.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),N(!0)))}).then(()=>{s&&s.remove(),h.finish(!0)}),h.result()}function o0(e){if(!Yt)return N(!1);let t=O("loadScripts");return t.loop(()=>Ti.length===0?N(!1):Ya(Ti.shift(),e,{atEnd:!0}).thenReturn(Ti.length>0)).then(()=>{$.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),$.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Qd(e){return Yt?Ti.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var a0=(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)}`),l0={};function h0(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 ep=class ta extends ha{constructor(t,i,n,r,s,o,a,l,h,u,d,p,f){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=r,this.regionIds=s,this.xmldoc=o,this.docFaces=a,this.footnoteStyle=l,this.stylerProducer=h,this.page=u,this.customRenderer=d,this.fallbackMap=p,this.documentURLTransformer=f,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 ta(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer)}createPseudoelementShadow(t,i,n,r,s,o,a,l){var h;let u=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(!u)return l;let d=[],p=Ar.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=p;for(let g of Cw){let w;if(g){if(!u[g]||g=="footnote-marker"&&!(i&&this.isFootnote))continue;if(g.match(/^first-/)){let v=r.display;if(!v||v===b.inline)continue;let y=t.firstElementChild;if(y&&$e(y.previousSibling)){let C=s.getStyle(y,!1);if(C){let E=Re(C,"display");if(E!=null&&E.value&&E.value!==b.inline)continue}}}if(g==="before"||g==="after"||g==="marker"){let v=u[g].content;if(!v||!Dt(v.value)||g==="marker"&&(!ki(r.display)||((h=Re(n,"behavior"))==null?void 0:h.value)===F("toc-node")))continue}d.push(g),w=Ar.createElementNS("http://www.w3.org/1999/xhtml","span"),Bo(w,g)}else w=Ar.createElementNS("http://www.pyroxy.com/ns/shadow","content");f.appendChild(w),g.match(/^first-/)&&(f=w)}if(!d.length)return l;let m=new eh(t,n,s,o,this.exprContentListener);return new go(t,p,null,a,l,xt.ROOTLESS,m)}getPseudoMap(t,i,n,r,s){let o=kt(t,"_pseudos");if(!o)return null;let a={};for(let l in o){let h=a[l]={};Vn(h,o[l],s),Oo(h,s,o[l]),qc(o[l],i,n,(u,d)=>{Vn(h,d,s),Wc(d,p=>{Vn(h,p,s)})})}return a}createRefShadow(t,i,n,r,s){let o=O("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let l=a;if(l){let h=l.getElement(t);if(h){let u=this.stylerProducer.getStylerForDoc(l);s=new go(n,h,l,r,s,i,u)}}o.finish(s)}),o.result()}createShadows(t,i,n,r,s,o,a){let l=O("createShadows"),h=null,u=r.template,d;if(u instanceof Qe||u===b.footnote){let p=u instanceof Qe?u.url:Pe("user-agent.xml#footnote",ni);d=this.createRefShadow(p,xt.ROOTLESS,t,a,h)}else d=N(h);return d.then(p=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let g=t.getAttribute("href"),w=null;g?w=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?g=a.owner.getAttribute("href"):g=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),w=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),g&&(g=Pe(g,w.url),f=this.createRefShadow(g,xt.ROOTED,t,a,p))}f==null&&(f=N(p));let m=null;f.then(g=>{if(r.display===b.table_cell){let w=Pe("user-agent.xml#table-cell",ni);m=this.createRefShadow(w,xt.ROOTLESS,t,a,g)}else m=N(g);m.then(w=>{w=this.createPseudoelementShadow(t,i,n,r,s,o,a,w),l.finish(w)})})}),l.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,r){var s;let o=this.context,a=Xc(n,o,this.regionIds,this.isFootnote,this.nodeContext),l=!((s=this.nodeContext)!=null&&s.parent);l&&(!a["writing-mode"]&&this.styler.rootStyle["writing-mode"]&&(a["writing-mode"]=this.styler.rootStyle["writing-mode"]),!a.direction&&this.styler.rootStyle.direction&&(a.direction=this.styler.rootStyle.direction));let h=t;t=Gc(a,o,t);let u=!l&&t!==h;i=jc(a,o,i);let d=(v,y)=>{let C;u&&(t?/^(min-|max-)?(height|inline-size)$/.test(v)&&(C=o.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(v)&&(C=o.pageAreaWidth));let E=y.evaluate(o,v,C,t);return v=="font-family"&&(E=this.docFaces.filterFontFamily(E)),E},p=!!new De(o.style.pageScope,"left-page").evaluate(o);if(Yc(a,r,t,i,p,d),u){let v=r[t?"height":"width"];(!v||v===b.auto)&&(r[t?"height":"width"]=b.max_content)}if(yo(r.position))return r.position=b.fixed,r.visibility=b.hidden,t;let f=r.position,m=r.float,g=r.display||(this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?b.inline:void 0),w=yc(g,f,m,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(v=>{w[v]&&(r[v]=w[v])}),t}inheritFromSourceParent(t){let i=this.nodeContext.sourceNode,n=[],r=null,s=this.nodeContext.shadowContext,o=-1;for(;i&&i.nodeType==1;){let d=s&&s.root==i;if(!d||s.type==xt.ROOTLESS){let p=(s?s.styler:this.styler).getStyle(i,!1);n.push(p),r=r||Js(i)}d?(i=s.owner,s=s.parentShadow):(i=i.parentNode,o++)}let a=o===0,l=this.context.queryUnitSize("em",a),h={"font-size":new _(new I(l,"px"),0)};a&&(h["line-height"]=new _(new gt(this.context.pref.lineHeight),0));let u=new Rm(h,this.context);for(let d=n.length-1;d>=0;--d){let p=n[d],f=[];for(let w in p)zn(w)&&f.push(w);f.sort(vl);let m,g;for(let w of f){u.setPropName(w);let v=Re(p,w),y=v;if(!K(v.value)){if(w==="font-size"&&d===n.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)y=new _(new I(this.context.rootFontSize,"px"),v.priority);else if(w==="line-height"&&d===n.length-1&&this.context.rootLineHeight&&v.value instanceof I&&(v.value.unit==="lh"||v.value.unit==="rlh"))y=new _(new I(this.context.rootLineHeight,"px"),v.priority);else if(d===0&&v.value instanceof I&&v.value.unit==="lh"){let C=this.getLineHeightUnitSize(w,m,g);C!=null&&(y=new _(new I(v.value.num*C,"px"),v.priority))}else zt(w)||(y=v.filterValue(u));w==="font-size"?m=y.value:w==="line-height"&&(g=y.value),h[w]=y}}}for(let d in t)zn(d)||(h[d]=t[d]);return{lang:r,elementStyle:h}}resolveURL(t){return t=Pe(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=Js(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=Sm().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(K(s))s===b.initial&&(n[r]=void 0);else if(s instanceof Le)n[r]=s.num;else if(s instanceof le)n[r]=s.name;else if(s instanceof I){let o=s;switch(o.unit){case"dpi":case"dpcm":case"dppx":n[r]=o.num*At[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=Rt("RESOLVE_FORMATTING_CONTEXT");for(let l=0;l<a.length;l++){let h=a[l](t,i,n,r,s,o);if(h){t.formattingContext=h;return}}}createElementView(t,i){var n,r;let s=!0,o=O("createElementView"),a=this.sourceNode,l=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,h=l.getStyle(a,!1);if(!this.nodeContext.shadowContext){let y=this.xmldoc.getElementOffset(a);bs.registerFragmentIndex(y,this.nodeContext.fragmentIndex,0)}let u={};if(!this.nodeContext.parent){let y=this.inheritFromSourceParent(h);h=y.elementStyle,this.nodeContext.lang=y.lang}let d=h.position,p=h.float,f=h["float-reference"],m=p&&!K(p.value)&&p.value!==b.none&&f&&!K(f.value)?tm(f.value.toString()):null;if(this.nodeContext.parent&&(yo(d?.value)||m&&tn(m))){let y=this.inheritFromSourceParent(h);h=y.elementStyle,this.nodeContext.lang=y.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",h,u),m&&tn(m)&&u.display===b.block&&(u.display=b.flow_root),l.processContent(a,u,this.nodeContext),this.transferPolyfilledInheritedProps(u),this.inheritLangAttribute(),u.direction&&(this.nodeContext.direction=u.direction.toString());let g=u["flow-into"];if(g&&g.toString()!=this.flowName)return o.finish(!1),o.result();if(Yt&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return Ya(a,this.viewport.window).thenFinish(o),o.result();let w=u.display;if(K(w)&&(w===b.initial||w===b.unset?w=b.inline:w===b.inherit?w=((n=this.nodeContext.parent)==null?void 0:n.display)&&F((r=this.nodeContext.parent)==null?void 0:r.display):w=null),w===b.none)return o.finish(!1),o.result();let v=this.nodeContext.parent==null;return this.nodeContext.flexContainer=w===b.flex,this.createShadows(a,v,h,u,l,this.context,this.nodeContext.shadowContext).then(y=>{this.nodeContext.nodeShadow=y;let C=u.position,E=u.float,A=u.clear,H=this.nodeContext.vertical?b.vertical_rl:b.horizontal_tb,V=this.nodeContext.parent?this.nodeContext.parent.vertical?b.vertical_rl:b.horizontal_tb:H,ie=lm(a),ne=u["column-count"],Xe=u["column-width"],ht=ne&&ne!==b.auto&&!K(ne)||Xe&&Xe!==b.auto&&!K(Xe);this.nodeContext.establishesBFC=um(w,C,E,u.overflow,H,V,ht||ie),this.nodeContext.containingBlockForAbsolute=cm(C),this.nodeContext.isInsideBFC()&&E!==b.footnote&&!(m&&tn(m))&&(E=null,A=null);let xe=E instanceof J||E===b.left||E===b.right||E===b.top||E===b.bottom||E===b.inline_start||E===b.inline_end||E===b.block_start||E===b.block_end||E===b.snap_block||E===b.snap_inline||E===b.inside||E===b.outside||E===b.footnote;E&&(delete u.float,E===b.footnote&&(this.isFootnote?(xe=!1,u.display=b.block):u.display=b.inline)),A&&(A===b.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(A=F(this.nodeContext.parent.clearSide)),(A===b.left||A===b.right||A===b.top||A===b.bottom||A===b.inline_start||A===b.inline_end||A===b.block_start||A===b.block_end||A===b.inside||A===b.outside||A===b.both||A===b.all||A===b.same||A===b.column||A===b.region||A===b.page)&&(delete u.clear,u.display&&u.display!=b.inline&&(this.nodeContext.clearSide=A.toString())));let x=ki(w)&&!!u["ua-list-item-count"],B=u["break-inside"];(xe||B&&!K(B)&&B!==b.auto)&&this.nodeContext.breakPenalty++,w&&w!==b.inline&&Mt(w)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!xe&&!w||Mt(w)||vc(w),this.nodeContext.display=w?w.toString():"inline",this.nodeContext.floatSide=xe?E.toString():null,this.nodeContext.floatReference=m||Oe.INLINE;let S=u["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=S&&!K(S)?S:null;let P=this.isInsideNonRootMultiColumn(),k=u["column-span"];if(this.nodeContext.columnSpan=!P&&k&&!K(k)?k:null,!this.nodeContext.inline){let z=u["break-after"];z&&!K(z)&&!(P&&z===b.column)&&(this.nodeContext.breakAfter=z.toString(),co[this.nodeContext.breakAfter]&&(u["break-after"]=b.column));let re=u["break-before"];re&&!K(re)&&!(P&&re===b.column)&&(this.nodeContext.breakBefore=re.toString(),co[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete u["break-before"]:u["break-before"]=b.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let se=u.page,be=se&&!K(se)&&se.toString();!be&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||w===b.table_header_group||w===b.table_footer_group)&&(be=this.styler.cascade.currentPageType),!be||be.toLowerCase()==="auto"?be=this.nodeContext.pageType:this.nodeContext.pageType=be,this.styler.cascade.currentPageType!==be&&!(!be&&u.position===b.fixed)&&(this.nodeContext.fragmentIndex===1&&!Xn(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),be!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=be)}this.nodeContext.verticalAlign=u["vertical-align"]&&u["vertical-align"].toString()||"baseline",this.nodeContext.captionSide=u["caption-side"]&&u["caption-side"].toString()||"top";let R=u["border-collapse"];if(!R||R===F("separate")){let z=u["border-spacing"],re,se;z&&(z instanceof J?(re=z.values[0],se=z.values[1]):re=se=z,re.isNumeric()&&(this.nodeContext.inlineBorderSpacing=et(re,this.context)),se.isNumeric()&&(this.nodeContext.blockBorderSpacing=et(se,this.context)))}let L=u["footnote-policy"];this.nodeContext.footnotePolicy=L&&!K(L)?L:null;let D=u["x-first-pseudo"];if(D){let z=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Zg(z,D.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,h,l,this.context);let W=u["white-space"];if(W){let z=ac(W.toString());z!==null&&(this.nodeContext.whitespace=z)}let q=u["hyphenate-character"];q&&q instanceof j&&(this.nodeContext.hyphenateCharacter=q.str);let Q=u["word-break"],ee=u["line-break"],we=u["overflow-wrap"];(Q===b.break_all||ee===b.anywhere||we===b.break_word||we===b.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,w,C,E,v),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,l));let te=!1,ye=null,Ce=[],he=a.namespaceURI,G=a.localName,ce=G;if(he=="http://www.w3.org/1999/xhtml"?(G=="html"||G=="body"||G=="script"||G=="link"||G=="meta"?G="div":G=="vide_"?G="video":G=="audi_"?G="audio":G=="object"&&(te=!!this.customRenderer),a.hasAttribute(_a)&&a.hasAttribute("src")&&u.content instanceof Qe&&(G="img")):he=="http://www.idpf.org/2007/ops"?(G="span",he="http://www.w3.org/1999/xhtml"):he=="http://www.pyroxy.com/ns/shadow"?(he="http://www.w3.org/1999/xhtml",G=this.nodeContext.inline?"span":"div"):te=!!this.customRenderer,x)w=Mt(w)?b.inline:b.block,u.display=w,t?G="li":G="div";else if(G=="body"||G=="li")G="div";else if(G=="q")G="span";else if(G=="a"){let z=u["hyperlink-processing"];z&&z.toString()!="normal"&&(G="span")}u.behavior&&u.behavior.toString()!="none"&&this.customRenderer&&(te=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(te=!0);let de;if(te){let z=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;de=this.customRenderer(a,z,u)}else de=N(null);de.then(z=>{var re,se,be,ut,Ja;if(z)te&&(s=z.getAttribute("data-adapt-process-children")=="true");else if(u.display===b.none){o.finish(!1);return}else z=this.createElement(he,G);G!=ce&&(z.setAttribute("data-vivliostyle-original-tag",ce),(ce==="html"||ce==="body")&&(z.role="presentation")),G=="a"&&z.addEventListener("click",this.page.hrefHandler,!1),ye&&(this.applyPseudoelementStyle(this.nodeContext,"inner",ye),z.appendChild(ye)),z.localName=="iframe"&&z.namespaceURI=="http://www.w3.org/1999/xhtml"&&h0(z);let pr=this.nodeContext.inheritedProps["image-resolution"],ks=[],Es=u.width,Ns=u.height,dp=a.getAttribute("width"),pp=a.getAttribute("height"),Ps=Es===b.auto||!Es&&!dp,Ts=Ns===b.auto||!Ns&&!pp,Qa=a.attributes,fp=Qa.length,fr=null,el=null;w===b.table_cell&&((be=(se=(re=this.nodeContext.parent)==null?void 0:re.viewNode)==null?void 0:se.lastElementChild)==null?void 0:be.localName)==="a"&&z.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let qe=0;qe<fp;qe++){let mt=Qa[qe],ct=mt.namespaceURI,ae=mt.localName,Ve=mt.nodeValue;if(ct){if(ct=="http://www.w3.org/2000/xmlns/")continue;ct=="http://www.w3.org/1999/xlink"&&ae=="href"&&(Ve=this.documentURLTransformer.transformURL(this.resolveURL(Ve),this.xmldoc.url))}else{if(!Yt&&ae.match(/^on/)||ae=="style")continue;if((ae=="id"||ae=="name")&&t){let Ye=this.documentURLTransformer.transformFragment(Ve,this.xmldoc.url);z.setAttribute(ae,Ve),z.setAttribute("data-vivliostyle-id",Ye);let ci=z.ownerDocument.createElement("a");ci.setAttribute(ae,Ye),ci.setAttribute(hn,"1"),ci.style.position="absolute",z.appendChild(ci),this.page.registerElementWithId(z,Ye);continue}if(ae=="src"||ae=="href"||ae=="poster")Ve=this.resolveURL(Ve),ae==="href"&&(Ve=this.documentURLTransformer.transformURL(Ve,this.xmldoc.url));else if(ae=="srcset")Ve=Ve.split(",").map(Ye=>this.resolveURL(Ye.trim())).join(",");else if(ae==="data"&&te&&G==="object"&&z.hasAttribute("data"))continue;if(ae==="poster"&&G==="video"&&he==="http://www.w3.org/1999/xhtml"&&Ps&&Ts){let Ye=new Image,ci=Hi(Ye,Ve);Ce.push(ci),ks.push({image:Ye,element:z,fetcher:ci})}}if(he=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ae)&&(ae=ae.toLowerCase()),this.isSVGUrlAttribute(ae)&&(Ve=a0(Ve,this.xmldoc.url,this.documentURLTransformer)),ct){let Ye=l0[ct];Ye&&(ae=`${Ye}:${ae}`)}if(ae=="src"&&!ct&&(G=="img"||G=="input")&&he=="http://www.w3.org/1999/xhtml")fr=Ve;else if(ae=="alt"&&!ct&&G=="img"&&he=="http://www.w3.org/1999/xhtml")el=Ve;else if(ae=="href"&&G=="image"&&he=="http://www.w3.org/2000/svg"&&ct=="http://www.w3.org/1999/xlink")this.page.fetchers.push(Hi(z,Ve));else if(ct)z.setAttributeNS(ct,ae,Ve);else try{z.setAttribute(ae,Ve)}catch(Ye){$.warn(Ye)}}if(fr){let qe=G==="input"?new Image:z,mt=Hi(qe,fr,el);qe!==z&&(z.src=fr);let ct=()=>{var ae,Ve;if(u.position===b.fixed)return!0;for(let Ye=(ae=this.nodeContext.parent)==null?void 0:ae.viewNode;Ye&&Ye!==this.viewRoot;Ye=Ye.parentElement)if(((Ve=Ye.style)==null?void 0:Ve.position)==="fixed")return!0;return!1};!Ps&&!Ts&&!(()=>{let ae=this.nodeContext.vertical?Es:Ns;return ae instanceof I&&ae.unit==="%"})()&&!ct()?this.page.fetchers.push(mt):(Ps&&Ts&&pr&&pr!==1&&ks.push({image:qe,element:z,fetcher:mt}),Ce.push(mt))}delete u.content;let Is=u["list-style-image"];if(Is&&Is instanceof Qe){let qe=Is.url;Ce.push(Hi(new Image,qe))}if(this.preprocessElementStyle(u),this.applyComputedStyles(z,u),this.nodeContext.inline)t||(wt(z,"inline-start"),En(z)&&wt(z,"clone"));else if(t){if(!Sa(u.position)){let qe=u["margin-break"],mt=this.getBreakTypeAt(this.nodeContext),ct=mt!==null,ae=mt==="auto";(qe===b.discard&&ct||qe!==b.keep&&ae&&!this.nodeContext.floatSide)&&Vs(z,"block-start")}}else{let qe=this.nodeContext.vertical?"width":"height";ei(z,qe)&&T(z,qe,this.nodeContext.display==="table-row"?"0.01px":""),wt(z,"block-start"),En(z)&&wt(z,"clone"),Vs(z,"block-start")}if(x&&z.setAttribute("value",u["ua-list-item-count"].stringValue()),z.classList.contains("_viv-marker-outside-content")&&ki((Ja=(ut=this.nodeContext.parent)==null?void 0:ut.parent)==null?void 0:Ja.display)){let qe=this.viewport.window.getComputedStyle(this.nodeContext.parent.parent.viewNode),mt=parseFloat(qe.borderInlineStartWidth)+parseFloat(qe.paddingInlineStart)+parseFloat(qe.textIndent);mt&&(z.style.insetInlineEnd=`${mt}px`)}this.viewNode=z,Ce.length?ms(Ce).then(()=>{pr>0&&this.modifyElemDimensionWithImageResolution(ks,pr,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&&($e(r,n.parent.whitespace)||Yi(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&&Ea(i))}getBreakTypeAt(t){var i,n,r,s,o;if(this.isInsideTable(t))return null;for(let l=t;l&&!l.after;l=l.parent){if(it(l.breakBefore))return l.breakBefore;if(l.fragmentIndex===1&&!l.parent)return l.sourceNode===l.sourceNode.ownerDocument.documentElement?"page":null;if((i=l.parent)!=null&&i.floatSide)return null;let h=(n=l.parent)==null?void 0:n.viewNode;if(h){let u=this.viewport.window.getComputedStyle(h),d=parseFloat(u.paddingBlockStart),p=parseFloat(u.borderBlockStartWidth);if(d||p)return null;let f=h?.firstChild;for(;f&&($e(f,l.parent.whitespace)||!l.floatSide&&Yi(f));)f=f.nextSibling;if(f&&f!==l.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 it(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 eh(t,i,n,r,this.exprContentListener);this.nodeContext.afterIfContinues=new Ew(t,o)}}isSVGUrlAttribute(t){return ta.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,l=o.height/i,h=s.element;if(a>0&&l>0){if(n["box-sizing"]===b.border_box&&(n["border-left-style"]!==b.none&&(a+=et(n["border-left-width"],this.context)),n["border-right-style"]!==b.none&&(a+=et(n["border-right-width"],this.context)),n["border-top-style"]!==b.none&&(l+=et(n["border-top-width"],this.context)),n["border-bottom-style"]!==b.none&&(l+=et(n["border-bottom-width"],this.context))),i>1){let u=n["max-width"]||b.none,d=n["max-height"]||b.none;if(u===b.none&&d===b.none)T(h,"max-width",`${a}px`);else if(u!==b.none&&d===b.none)T(h,"width",`${a}px`);else if(u===b.none&&d!==b.none)T(h,"height",`${l}px`);else{u.isNumeric(),d.isNumeric();let p=u,f=d;p.unit!=="%"?T(h,"max-width",`${Math.min(a,et(p,this.context))}px`):f.unit!=="%"?T(h,"max-height",`${Math.min(l,et(f,this.context))}px`):r?T(h,"height",`${l}px`):T(h,"width",`${a}px`)}}else if(i<1){let u=n["min-width"]||Ee,d=n["min-height"]||Ee;u.isNumeric(),u.isNumeric();let p=u,f=d;p.num===0&&f.num===0?T(h,"min-width",`${a}px`):p.num!==0&&f.num===0?T(h,"width",`${a}px`):p.num===0&&f.num!==0?T(h,"height",`${l}px`):p.unit!=="%"?T(h,"min-width",`${Math.max(a,et(p,this.context))}px`):f.unit!=="%"?T(h,"min-height",`${Math.max(l,et(f,this.context))}px`):r?T(h,"height",`${l}px`):T(h,"width",`${a}px`)}}}})}preprocessElementStyle(t){Rt("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 Ii&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let o=this.nodeContext.parent,a=o&&o.formattingContext;this.nodeContext.formattingContext=new Ii(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==b.none&&((i===b.auto||K(i))&&(t.display===b.table_header_group?i=b.header:t.display===b.table_footer_group?i=b.footer:i=b.none),i&&i!==b.none)?i.toString():null}createTextNodeView(){let t=O("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=Ol(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=O("preprocessTextContent"),r=Rt("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=Dg(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=O("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 l=(d,p)=>d?.nodeType===1&&Ji(d)===p,h=this.nodeContext.parent,u=h?l(this.viewNode,"after")&&l(h.viewNode,"first-letter")&&(a=h.viewNode)!=null&&a.hasChildNodes()?h.parent.viewNode:h.viewNode:this.viewRoot;u&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&$e(this.viewNode))&&!u.hasChildNodes()&&nc(u).includes("block-start")&&wt(u,"text-start"),u.appendChild(this.viewNode),fm(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.root,o=n.type,o==xt.ROOTLESS&&(s=s.firstChild)):(s=n.owner.firstChild,o=xt.ROOTLESS);let l=t.sourceNode.nextSibling;if(l?(t.sourceNode=l,t.resetView()):t.shadowSibling?t=t.shadowSibling:s?t=null:(t=t.parent.modify(),t.after=!0),s){let h=new Pn(s,r,i);return h.shadowContext=a,h.shadowType=o,h.shadowSibling=t,h}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=xt.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==xt.ROOTLESS&&(r=r.firstChild),r){let s=new Pn(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 Pn(n,t,i));if(t.sourceNode.nodeType!=1){let r=Ol(t.preprocessedTextContent);i+=r.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}isTransclusion(t,i,n){let r=Re(i,"hyperlink-processing");if(!r)return!1;let s=r.evaluate(this.context,"hyperlink-processing");return s?s.toString()==n:!1}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return N(n);let r=O("nextInTree");return this.setCurrent(n,!0,i).then(s=>{(!n.viewNode||!s)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),this.dispatchEvent({type:"nextInTree",nodeContext:n}),r.finish(n)}),r.result()}addImageFetchers(t){if(t instanceof Ze){let i=t.values;for(let n=0;n<i.length;n++)this.addImageFetchers(i[n])}else if(t instanceof Qe){let i=t.url;this.page.fetchers.push(Hi(new Image,i))}}applyComputedStyles(t,i){var n,r,s;let o=i["background-image"];o&&this.addImageFetchers(o);let a=i.position===b.relative,l=((n=this.nodeContext)==null?void 0:n.parent)===null&&((r=this.sourceNode)==null?void 0:r.parentElement)===null&&!!((s=this.viewRoot)!=null&&s.parentElement),h=Object.keys(i);h.sort(vl);let u,d;for(let p of h){if(c0[p])continue;let f=i[p];if(!(!f||f===X&&!zt(p))){if(f=f.visit(new Bf(this.xmldoc.url,this.documentURLTransformer)),f instanceof I)if(f.unit==="em"){let m=this.getEmUnitSize(p,u);m!=null&&(f=new I(f.num*m,"px"))}else if(f.unit==="lh"){let m=this.getLineHeightUnitSize(p,u,d);m!=null&&(f=new I(f.num*m,"px"))}else nu(f.unit)&&(f=xu(f,this.context));if((p==="font-size"||p==="line-height")&&(p==="font-size"?u=f:d=f,this.viewport.layoutUnitAdj&&f instanceof I&&f.unit!=="%"&&f.unit!=="em"&&f.unit!=="lh"&&(f=new _i(`calc(${f.toString()} - var(--viv-layoutUnitAdj))`))),Ug[p]||a&&$g[p]){this.page.delayedItems.push(new xa(t,p,f));continue}l&&this.page.pageAreaElement&&zn(p)?T(this.page.pageAreaElement.parentElement.parentElement,p,f.toString()):T(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,l,h;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 gt||n instanceof I&&(n.unit==="em"||n.unit==="%"))p=n instanceof I&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof I&&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=(l=(a=this.nodeContext)==null?void 0:a.parent)==null?void 0:l.viewNode;f&&f.nodeType===1;f=f.parentNode){let m=(h=f?.style)==null?void 0:h.lineHeight;if(m){/^[0-9.]+$/.test(m)&&(p=parseFloat(m));break}}if(p!=null){if(i&&!(i instanceof I))return null;let f=u?this.parsePlusLayoutUnitAdj(u.fontSize):this.context.rootFontSize;if(i instanceof I){let m=To(i,f,this.context).num;return typeof m!="number"||isNaN(m)?null:p*m}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 I){let l=To(i,a,this.context).num;if(typeof l=="number"&&!isNaN(l))return l}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=kt(s,"_pseudos");if(!o||(s=o[i],!s))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",s,a);let l=a.content;Dt(l)&&(l.visit(new ts(n,this.context,l,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=O("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,l=[];for(;t.firstPseudo===r;)l.push(t),t=t.parent;let h=l.pop(),u=h.shadowSibling;return n.loop(()=>{for(;l.length>0;){h=l.pop(),t=new Pn(h.sourceNode,t,a),l.length==0&&(t.offsetInNode=s,t.after=o),t.shadowType=h.shadowType,t.shadowContext=h.shadowContext,t.nodeShadow=h.nodeShadow,t.shadowSibling=h.shadowSibling?h.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){let r={},s=kt(this.footnoteStyle,"_pseudos");if(t=this.computeStyle(t,i,this.footnoteStyle,r),s&&s.before){let o={},a=this.createElement("http://www.w3.org/1999/xhtml","span");Bo(a,"before"),n.appendChild(a),this.computeStyle(t,i,s.before,o),delete o.content,this.applyComputedStyles(a,o)}return delete r.content,this.applyComputedStyles(n,r),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 l=t.sourceNode.nextSibling,h=(n=Re(this.styler.getStyle(l,!1),"display"))==null?void 0:n.value.toString();o=h&&!Mt(h)||l.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(l.textContent)}let a=0;for(let l=s;l;l=l.parent){if(((r=l.viewNode)==null?void 0:r.nodeType)!==1)continue;let h=l.viewNode;if(h.style)if(l.inline){if(wt(h,"inline-end"),En(h)){let u=l.vertical?h.offsetWidth:h.offsetHeight;wt(h,"clone"),(l.vertical?h.offsetWidth:h.offsetHeight)>u&&this.fixClonedBoxDecorationOverflow(h)}}else{let u=this.nodeContext.vertical?"width":"height";if(ei(h,u)&&T(h,u,""),wt(h,"block-end"),!a++&&l!==s){let{textAlign:d}=this.viewport.window.getComputedStyle(h);if(d==="justify"&&!o){let p=this.createChildAnonymousBlockIfNeeded(h);p?p!==h?rc(p,["block-start","text-start","block-end","text-end","justify"]):(wt(h,"text-end"),wt(h,"justify")):wt(h,"text-end")}else wt(h,"text-end")}En(h)&&wt(h,"clone"),Vs(h,"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:l}=this.viewport.window.getComputedStyle(s);if(s.localName==="ruby"||Ci[s.localName])return!1;if(s.localName==="br")return!0;if((o==="inline"||o==="contents")&&s.hasChildNodes()){let h=s.lastElementChild;if(h&&(!h.nextSibling||h.nextSibling===s.lastChild&&$e(h.nextSibling))){let u=i(h);if(u||u===null)return u}for(let u=h?.previousElementSibling;u;u=u.previousElementSibling){let d=i(u);if(d||d===null)return null}return!1}if(o==="none"||a==="absolute"||a==="fixed"||l&&l!=="none"||s.hasAttribute(hn)){let h=s.previousElementSibling;return h&&(h.nextSibling===s||h.nextSibling===s.previousSibling&&$e(h.nextSibling))?i(h):!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&&$e(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(tf(s)){let o=i;for(;o&&o.nodeType!==1;)o=o.parentNode;let a=parseFloat(n.getElementComputedStyle(o)["font-size"]);return this.context,Fa(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&&Ji(n)===Ji(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!!Ji(t)}};c(ep,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var u0=ep,c0={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-policy":!0,"margin-break":!0,page:!0},d0=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}},cs=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")&&(T(this.root,"--viv-outputPixelRatio",`${i}`),T(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio),Gh){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&&T(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let l=o.nextElementSibling;l||(l=this.document.createElement("div"),l.setAttribute("data-vivliostyle-layout-box","true"),l.role="presentation",this.root.appendChild(l)),this.outerZoomBox=o,this.contentContainer=a,this.layoutBox=l,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 h={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=h.width),(!this.height||!s&&u)&&(this.height=h.height)}resetZoom(){T(this.outerZoomBox,"width",""),T(this.outerZoomBox,"height",""),T(this.contentContainer,"width",""),T(this.contentContainer,"height",""),T(this.contentContainer,"transform","")}zoom(e,t,i){T(this.root,"--viv-outputScale",`${i}`),T(this.outerZoomBox,"width",`${e*i}px`),T(this.outerZoomBox,"height",`${t*i}px`),T(this.contentContainer,"width",`${e}px`),T(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}},tp=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(Ut,"0")}doc(){return new np([this.document])}getElementOffset(e){let t=e.getAttribute(Ut);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(Ut,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 l=ai(a.length,h=>{let u=a[h];return this.getElementOffset(u)>e});if(l==0)break;i=a[l-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}},ia=(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))(ia||{});function Cr(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 p0(e){let t=e.contentType;if(t){let n=Object.keys(ia);for(let r=0;r<n.length;r++)if(ia[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 ip(e,t){let i=e.responseXML;if(!i){let r=new DOMParser,s=e.responseText;if(s){let o=p0(e);if(i=Cr(s,o||"application/xml",r),i&&!o){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Cr(s,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Cr(s,"image/svg+xml",r))}i||(i=Cr(s,"text/html",r))}}let n=i?new tp(t,e.url,i):null;return N(n)}function f0(){return new wa(ip,"document")}var g0=class na{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new na(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new na(n=>{if(!this.check(n))return!1;let r=new np([n]);return r=r.child(t),i&&(r=r.predicate(i)),r.size()>0})}},Eh=new g0(e=>!0),np=class ra{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 ra(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 ra(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)}},m0=new or(()=>{let e=O("uaStylesheetBase"),t=_d(),i=Pe("user-agent-base.css",ni),n=new Yn(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),lw(n.cascade),ba(Uu,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function w0(){return m0.get()}var y0=class extends In{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)||$.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},b0=class{constructor(e,t,i,n,r,s,o,a,l,h,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=l,this.pageProps=h,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,m=f.firstFlowChunkOfFlow(d);return p.matchPageSide(f.startSideOfFlow(d))&&f.hasContent(d,p.lookupOffset)&&!!m&&!p.flowChunkIsAfterParentFlowForcedBreak(m)}),this.pageScope.defineName("page-number",new ze(this.pageScope,function(){let d=this;return d.pageNumberOffset+d.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new ze(this.pageScope,function(){let d=this.currentLayoutPosition;return d?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let r=new io(this.rootScope,e,t,i),s=Am(r,this.viewportProps),o=s.width,a=s.height,l=s["text-zoom"],h=1;if(o&&a||l){let u=At.em;if((l?l.evaluate(r,"text-zoom"):null)===b.scale&&(h=u/i,i=u,e*=h,t*=h),o&&a){let d=et(o.evaluate(r,"width"),r),p=et(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}}},Ka=class extends io{constructor(e,t,i,n,r,s,o,a,l,h,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=l,this.documentURLTransformer=h,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,"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),this.lang=t.lang||i,this.faces=new bb(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new Tn(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!f;for(let m in e.flowProps){let g=e.flowProps[m],w=Re(g,"flow-consume");w&&(w.evaluate(this,"flow-consume")==b.all?this.primaryFlows[m]=!0:delete this.primaryFlows[m])}}init(){let e=O("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 ch(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=Xd(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new Eb(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 Ub(s,this.style.pageScope,this.rootPageBoxInstance,this,n);let o=[];for(let l of this.style.fontFaces){if(l.condition&&!l.condition.evaluate(this))continue;let h=yb(l.properties,this),u=new zd(h);o.push(u)}this.fontMapper.findOrLoadFonts(o,this.faces).then(()=>{s0(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let a=this.style.pageProps;return a[""]||(a[""]={}),Object.keys(a).forEach(l=>{let h=a[l];this.styler.cascade.applyVarFilter([h],this.styler,null),this.styler.cascade.applyCalcFilter(h,this.styler.context),this.styler.cascade.applyCmykFilter(h);let u=Sh(us(h),this);this.pageSheetSize[l]={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 io(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 ch(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 Qg,i.flowPositions[e.flowName]=n);let r=Kg(e.element),s=new ui(r),o=new Jg(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(l,h){n=!1}invalidPropertyValue(l,h){n=!1}simpleProperty(l,h,u){}}let s=new r,o=gn(this.style.rootScope,new Ft(t,null),"");return o?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,o,!1,s),n):!1}evalSupportsSelector(e){let t=new rp(null),i=new Ft(e+"{}",t);return new lr(Ae,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 l=this.xmldoc.getNodeOffset(r,s,o);l<t&&(t=l)}return t}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){$.debug("Location - page",this.currentLayoutPosition.page),$.debug(" current:",e),$.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)$.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new De(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=Ll(rt(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===qa)continue;let o=1;r.pageBox.pseudoName===Wa&&!(this.actualPageWidth&&this.actualPageHeight)&&(o=1/0);let a=r.getProp(this,"utilization");a&&a.isNum()&&(o=a.num);let l=this.queryUnitSize("em",!1),h=this.pageWidth()*this.pageHeight(),u=Math.ceil(o*h/(l*l)),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===b._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=ai(r.length,h=>r[h]>n)-1,o=r[s],a=this.layoutPositionAtPageStart.flowPositions[i],l=this.getConsumedOffset(a);return o<l?!1:l<o?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new Ta(null)),e.flowRootFormattingContext=i.formattingContext}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=a=>{if(a.floatReference!==Oe.PAGE)return!1;let l=this.layoutPositionAtPageStart.flowPositions.body,h=l&&this.getConsumedOffset(l),u=this.xmldoc.getNodeOffset(a.nodePosition.steps[0].node,0,!1);return u!=null&&h!=null&&u>h},r=O("layoutDeferredPageFloats"),s=!1,o=0;return r.loopWithFrame(a=>{if(o===i.length){a.breakLoop();return}let l=i[o++],h=l.float;if(n(h)){a.breakLoop();return}let u=new ln().findByFloat(h),d=u.findPageFloatFragment(h,t);if(d&&d.hasFloat(h)){a.continueLoop();return}else if(t.isForbidden(h)||t.hasPrecedingFloatsDeferredToNext(h)){t.deferPageFloat(l),a.breakLoop();return}e.layoutPageFloatInner(l,u,null,d).then(p=>{if(!p){a.breakLoop();return}let f=t.parent.isInvalidated();if(f){a.breakLoop();return}else t.isInvalidated()&&!f&&(s=!0,t.validate());a.continueLoop()})}).then(()=>{s&&t.invalidate(),r.finish(!0)}),r.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 ui(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=O("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 l=0;for(;s.includes(l);)l++;let h=i.positions[l];if(h.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(h.flowChunk))break;for(let p=l+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(h.flowChunk)&&(h=f,l=p)}let u=h.flowChunk,d=!0;if(e.layout(h.chunkPosition,o,i.breakAfter).then(p=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(o=!1,h.flowChunk.repeated&&(p===null||u.exclusive)&&r.push(l),u.exclusive){s.push(l),a.breakLoop();return}else{let f=!!p||!!e.pageBreakType,m=this.getLastAfterPositionIfDeferredFloatsExists(e,p);if(e.pageBreakType&&m?(h.chunkPosition=m,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(s.push(l),(p||m)&&(h.chunkPosition=p||m,r.push(l)),i.startBreakType=Ll(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((l,h)=>r.includes(h)||!s.includes(h)),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 Aw([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,r,s,o,a,l,h,u,d,p,f){let m=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,g=r.element,w=new Tn(a,Oe.COLUMN,null,o,null,null,null),v=this.currentLayoutPosition.clone(),y=O("createAndLayoutColumn"),C;return y.loopWithFrame(E=>{let A=this.createLayoutConstraint(w);if(l>1){let H=this.viewport.document.createElement("div");if(T(H,"position","absolute"),g.appendChild(H),C=new rs(H,p,this.clientLayout,A,w),C.forceNonfitting=f,C.vertical=r.vertical,C.rtl=r.rtl,C.snapHeight=r.snapHeight,C.snapWidth=r.snapWidth,r.vertical){let V=(r.rtl?l-s-1:s)*(u+h)+r.paddingTop,ie=parseFloat(g.style.width);C.setHorizontalPosition(r.paddingLeft+ie-r.width,r.width),C.setVerticalPosition(V,u)}else{let V=(r.rtl?l-s-1:s)*(u+h)+r.paddingLeft;C.setVerticalPosition(r.paddingTop,r.height),C.setHorizontalPosition(V,u)}C.originX=t,C.originY=i}else C=new rs(g,p,this.clientLayout,A,w),C.copyFrom(r);C.exclusions=m?[]:n.concat(),C.innerShape=d,w.setContainer(C),(C.vertical?C.height:C.width)>=0?this.layoutColumn(C,o).then(()=>{w.isInvalidated()||w.finish(),C.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(C.pageFloatLayoutContext.validate(),this.currentLayoutPosition=v.clone(),C.element!==g&&g.removeChild(C.element),E.continueLoop()):E.breakLoop()}):(w.finish(),E.breakLoop())}).then(()=>{y.finish(C)}),y.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof Kd||t instanceof Ga&&!(t instanceof sn))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof dn;let r=t.getProp(this,"writing-mode")||null,s=t.getProp(this,"direction")||null;return new Tn(e,Oe.REGION,i,n,null,r,s)}layoutFlowColumnsWithBalancing(e,t,i,n,r,s,o,a,l){let h=this.currentLayoutPosition.clone(),u=this.getRegionPageFloatLayoutContext(s,t,o,a),d=!0,p=()=>(this.currentLayoutPosition=h.clone(),this.layoutFlowColumns(e,t,i,n,r,s,u,o,a,l,d).thenAsync(f=>N(f?{columns:f,position:this.currentLayoutPosition}:null)));return p().thenAsync(f=>{if(!f)return N(null);if(l<=1)return N(f.columns);let m=t.getProp(this,"column-fill")||b.balance,g=this.currentLayoutPosition.flowPositions[a],w=yy(l,m,p,u,o,f.columns,g);return w?(d=!1,s.lock(),u.lock(),w.balanceColumns(f).thenAsync(v=>(s.unlock(),s.validate(),u.unlock(),this.currentLayoutPosition=v.position,N(v.columns)))):N(f.columns)})}layoutFlowColumns(e,t,i,n,r,s,o,a,l,h,u){let d=O("layoutFlowColumns"),p=this.currentLayoutPosition.clone(),f=t.getPropAsNumber(this,"column-gap"),m=h>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,g=t.getActiveRegions(this),w=t.getProp(this,"shape-inside"),v=Fu(w,0,0,a.width,a.height,this),y=new u0(l,this,this.viewport,this.styler,g,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer),C=0,E=null,A=[];return d.loopWithFrame(H=>{this.createAndLayoutColumn(t,i,n,r,a,C++,l,o,h,f,m,v,y,u).then(V=>{if(s.isInvalidated()){A=null,H.breakLoop();return}if((V.pageBreakType&&V.pageBreakType!=="column"||C===h)&&!o.isInvalidated()&&o.finish(),o.isInvalidated()){C=0,this.currentLayoutPosition=p.clone(),o.validate(),o.isLocked()?(A=null,H.breakLoop()):H.continueLoop();return}E=V,A[C-1]=E,E.pageBreakType&&E.pageBreakType!="column"&&(C=h,E.pageBreakType!="region"&&(this.pageBreaks[l]=!0)),C<h?H.continueLoop():H.breakLoop()})}).then(()=>{d.finish(A)}),d.result()}layoutContainer(e,t,i,n,r,s,o){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==b._true)return N(!0);let l=O("layoutContainer"),h=t.getProp(this,"wrap-flow")===b.auto,u=t.getProp(this,"flow-from"),d=this.viewport.document.createElement("div");d.role=t instanceof Zd?"complementary":"presentation";let p=t.getProp(this,"position");T(d,"position",p?p.name:"absolute");let f=t instanceof sn;t instanceof dn?i.appendChild(d):i.insertBefore(d,i.firstChild);let m=new fc(d);m.vertical=t.vertical,m.rtl=t.rtl,m.borderBoxSizing=t.borderBoxSizing,m.exclusions=s,t.prepareContainer(this,m,e,this.faces,this.clientLayout),t instanceof sn&&(m.width<=0||m.height<=0)&&$.warn("Negative or zero page area size"),m.originX=n,m.originY=r,n+=m.left+m.marginLeft+m.borderLeft,r+=m.top+m.marginTop+m.borderTop,this.setPagePageFloatLayoutContextContainer(o,t,m);let g,w=!1;if(!u||!u.isIdent()){let v=t.getProp(this,"content");if(v instanceof U&&v.expr instanceof ze&&v.expr.str.startsWith("running-element-"))v.visit(new ts(d,this,v,this.counterStore.getExprContentListener()));else if(Dt(v)){let y="span";v instanceof Qe&&(y="img");let C=this.viewport.document.createElement(y);v.visit(new ts(C,this,v,this.counterStore.getExprContentListener())),d.appendChild(C),y=="img"&&t.transferSingleUriContentProps(this,C,this.faces),t.transferContentProps(this,m,e,this.faces),y=="span"&&Sw(C,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,m,e,null,1,this.clientLayout,this.faces),g=N(!0)}else if(this.pageBreaks[u.toString()])o.isInvalidated()||t.finishContainer(this,m,e,null,1,this.clientLayout,this.faces),g=N(!0);else{let v=O("layoutContainer.inner"),y=u.toString(),C=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,r,s,o,m,y,C).then(E=>{if(!o.isInvalidated()){let A=E[0];A.element===d&&(m=A),m.computedBlockSize=Math.max.apply(null,E.map(V=>V.computedBlockSize)),t.finishContainer(this,m,e,A,C,this.clientLayout,this.faces);let H=this.currentLayoutPosition.flowPositions[y];H&&H.breakAfter==="region"&&(H.breakAfter=null)}v.finish(!0)}),g=v.result()}return g.then(()=>{if(o.isInvalidated()){l.finish(!0);return}if(!t.isAutoHeight||Math.floor(m.computedBlockSize)>0){if(!w&&!h){let y=t.getProp(this,"shape-outside"),C=m.getOuterShape(y,this);s.push(C)}}else if(t.children.length==0){i.removeChild(d),l.finish(!0);return}let v=f?0:t.children.length-1;l.loop(()=>{for(;v>=0&&v<t.children.length;){let y=t.children[f?v++:v--],C=this.layoutContainer(e,y,d,n,r,s,o);if(C.isPending())return C.thenAsync(()=>N(!o.isInvalidated()));if(o.isInvalidated())break}return N(!1)}).then(()=>{l.finish(!0)})}),l.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;let n=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new em,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let r=1e4;if(t.page>r)throw new Error(`Too many pages generated (over ${r} pages)`);let s=t.startSideOfFlow("body");t.isBlankPage=Xn(s)&&this.matchPageSide(s),e.isBlankPage=t.isBlankPage,t.page++;let o=this.styler.cascade.previousPageType;e.pageType==null&&(e.pageType=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType);let a=this.pageManager.pageCascadeInstance;e.pageType&&(o!==e.pageType&&(a.pageTypePageCounts[e.pageType]=0),a.pageTypePageCounts[e.pageType]=(a.pageTypePageCounts[e.pageType]||0)+1),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let l=n?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context),this.styler.cascade.applyCmykFilter(l),!n){let g=new De(this.style.pageScope,"left-page");e.side=g.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let h=this.selectPageMaster(l);if(!h)return N(null);let u=0;if(!n){e.setAutoPageWidth(h.pageBox.specified.width.value===rr),e.setAutoPageHeight(h.pageBox.specified.height.value===sr),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(l,this);let g=Sh(us(l),this);this.setPageSizeAndBleed(g,e),Bb(l,g,e,this),u=g.bleedOffset+g.bleed}let d=!n&&h.getProp(this,"writing-mode")||b.horizontal_tb;this.pageVertical=d!=b.horizontal_tb;let p=h.getProp(this,"direction")||b.ltr,f=new Tn(this.rootPageFloatLayoutContext,Oe.PAGE,null,null,null,d,p),m=O("layoutNextPage");return m.loopWithFrame(g=>{this.layoutContainer(e,h,e.bleedBox,u,u,[],f).then(()=>{f.isInvalidated()||f.finish(),f.isInvalidated()?(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),f.validate(),g.continueLoop()):g.breakLoop()})}).then(()=>{h.adjustPageLayout(this,e,this.clientLayout),n||(this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(w=>{let v=t.flowPositions[w],y=v.breakAfter;y&&(y==="page"||!this.matchPageSide(y))&&(v.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let g=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(g,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),m.finish(t)}),m.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`}},v0=class sa extends Yn{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 Dd(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new Tb(r.scope,this.masterHandler,r,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=Et(this.scope,this.condition,i)),this.masterHandler.pushHandler(new sa(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new fw(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new In(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new y0(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 In(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new In(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=ur(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new In(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new e0(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(Yn.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let t=`R${this.masterHandler.regionCount++}`;this.special("region-id",F(t)),this.endRule();let i=new sa(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},rp=class extends Cg{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 Qy),c(this,"footnoteProps",{}),c(this,"flowProps",{}),c(this,"viewportProps",[]),c(this,"pageProps",{}),this.rootScope=new to(null),this.pageScope=new to(this.rootScope),this.rootBox=new Sb(this.rootScope),this.cascadeParserHandler=new v0(this,null,null,null),this.slave=this.cascadeParserHandler}};function x0(e,t){return t.parseOPSResource(e)}var S0=class extends wa{constructor(e){super(x0,"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=O("OPSDocStore.init");return this.validatorSet=_d(),w0().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=Pe(jn(t),on)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Pe(jn(t),on)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=O("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return ip(e,this).then(r=>{var s;if(!r){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=Rt("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](r.document)}catch(m){$.warn("Error during single document preprocessing:",m)}}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],m=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),g=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),w=f.getAttribute("action"),v=f.getAttribute("ref");m&&g&&w&&v&&o.push({observer:m,event:g,action:w,ref:v})}this.triggersByDocURL[i]=o;let l=[];if(l.push({url:Pe("user-agent-page.css",ni),text:Hu,flavor:"UA",classes:null,media:null}),l.push({url:Pe("user-agent-counter-styles.css",ni),text:Gu,flavor:"UA",classes:null,media:null}),n)l.push({url:Pe("user-agent-toc.css",ni),text:$u,flavor:"UA",classes:null,media:null});else{let p=r.document.querySelectorAll("style, link, meta");for(let f of p){let m=f.namespaceURI,g=f.localName;if(m=="http://www.w3.org/1999/xhtml")if(g=="style"){let w=f.getAttribute("class"),v=f.getAttribute("media"),y=f.getAttribute("title");l.push({url:i,text:f.textContent,flavor:"Author",classes:y?w:null,media:v})}else if(g=="link"){let w=f.getAttribute("href"),v=(s=f.getAttribute("rel"))==null?void 0:s.split(/\s+/),y=f.getAttribute("class"),C=f.getAttribute("media");if(w&&v!=null&&v.includes("stylesheet")&&(!v.includes("alternate")||y)){let E=Pe(w,i),A=f.getAttribute("title");l.push({url:E,text:null,classes:A?y:null,media:C,flavor:"Author"})}}else g=="meta"&&f.getAttribute("name")=="viewport"&&l.push({url:i,text:this.processViewportMeta(f),flavor:"Author",classes:null,media:null})}for(let f=0;f<this.styleSheets.length;f++)l.push(this.styleSheets[f])}let h="";for(let p=0;p<l.length;p++)h+=l[p].url,h+="^",l[p].text&&(h+=l[p].text),h+="^";let u=this.styleByKey[h];if(u){this.styleByDocURL[i]=u,t.finish(r);return}let d=this.styleFetcherByKey[h];d||(d=new or(()=>{let p=O("fetchStylesheet"),f=0,m=new rp(this.validatorSet);return p.loop(()=>{if(f<l.length){let g=l[f++];return m.startStylesheet(g.flavor),g.text!==null?ba(g.text,m,g.url,g.classes,g.media).thenReturn(!0):Zu(g.url,m,g.classes,g.media)}return N(!1)}).then(()=>{let g=m.cascadeParserHandler.finish();u=new b0(this,m.rootScope,m.pageScope,g,m.rootBox,m.fontFaces,m.footnoteProps,m.flowProps,m.viewportProps,m.pageProps,m.counterStyles),this.styleByKey[h]=u,delete this.styleFetcherByKey[h],p.finish(u)}),p.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[h]=d,d.start()),d.get().then(p=>{this.styleByDocURL[i]=p,t.finish(r)})}),t.result()}processViewportMeta(e){return""}},Wn="\u25B8",Nh="\u25BE",C0="\u25B9";function Za(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 k0(e){let t=Za(e),i=[];for(let n of t)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var E0=class{constructor(e,t,i,n,r,s,o,a,l,h,u){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=r,this.rendererFactory=o,this.fallbackMap=a,this.documentURLTransformer=l,this.counterStore=h,this.cmykStore=u,c(this,"pref"),c(this,"page",null),c(this,"instance",null),this.pref=Qh(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;ei(n,"height","auto")!="auto"&&(T(n,"height","auto"),this.setAutoHeight(n,t)),ei(n,"position","static")=="absolute"&&(T(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=b.inherit,r["text-decoration"]=b.none;break;case"toc-node":r.display=b.block,r.margin=Ee,r.padding=Ee,r["padding-inline-start"]=new I(1.25,"em");break;case"toc-node-first-child":r.display=b.inline_block,r.margin=new I(.2,"em"),r["vertical-align"]=b.top,r.color=b.inherit,r["text-decoration"]=b.none;break;case"toc-container":r.padding=Ee;break}if(!s||s.toString()!="toc-node"&&s.toString()!="toc-container")return t(i,n,r);let o=i.firstChild;o&&o.nodeType!==1&&$e(o)&&i.replaceChild(i.ownerDocument.createComment(o.textContent),o);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let h=n.firstChild;h.textContent!=Wn&&(h.textContent=Wn,T(h,"cursor","pointer"),h.addEventListener("click",N0,!1),h.setAttribute("role","button"),h.setAttribute("aria-expanded","false"),n.setAttribute("aria-expanded","false"),n.style.height!=="0px"&&(h.tabIndex=0))}let l=n.ownerDocument.createElement("div");if(l.setAttribute("data-adapt-process-children","true"),s.toString()=="toc-node"){let h=n.ownerDocument.createElement("div");if(h.textContent=C0,T(h,"margin","0.2em 0 0 -1em"),T(h,"margin-inline-start","-1em"),T(h,"margin-inline-end","0"),T(h,"display","inline-block"),T(h,"width","1em"),T(h,"text-align","center"),T(h,"vertical-align","top"),T(h,"cursor","default"),T(h,"font-family","Menlo,sans-serif"),l.appendChild(h),T(l,"overflow","hidden"),l.setAttribute("data-adapt-class","toc-node"),l.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){T(l,"height","0px");let u=i.firstElementChild;u&&u.localName==="a"&&(u.tabIndex=-1)}else n.setAttribute("role","tree")}else a=="toc-node"&&(l.setAttribute("data-adapt-class","toc-container"),l.setAttribute("role","group"),l.setAttribute("aria-hidden","true"));return N(l)}}showTOC(e,t,i,n,r){if(this.page)return N(this.page);let s=O("showTOC"),o=new oc(e,e);this.page=o;let a=Wt(this.url)+"?viv-toc-box";return this.store.load(a).then(l=>{for(let f of Za(l.document))f.setAttribute("data-vivliostyle-role","doc-toc");let h=this.store.getStyleForDoc(l),u=h.sizeViewport(i,1e5,r);t=new cs(t.window,u.fontSize,0,e,u.width,u.height);let d=this.makeCustomRenderer(l),p=new Ka(h,l,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]"),l=e(a);return{id:s,title:o,children:l}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function N0(e){let t=e.target,i=t.textContent==Wn;t.textContent=i?Nh:Wn;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==Nh){a.textContent=Wn,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()}var Ph=class extends S0{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=f0(),this.jsonStore=bg()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,t,i){return this.plainXMLStore.load(e,t,i)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,t,i){return this.jsonStore.load(e,t,i)}loadPubDoc(e){let t=O("loadPubDoc");return ws(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}$.error(`Failed to fetch a source document from ${e} (${i.status}${i.statusText?" "+i.statusText:""})`),t.finish(null)});else if(!i.status&&!i.responseXML&&!i.responseText&&!i.responseBlob&&!i.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),i.contentType=="application/oebps-package+xml"||/\.opf(?:[#?]|$)/.test(e)){let[,n,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"||/\.json(?:ld)?(?:[#?]|$)/.test(e)?this.loadAsJSON(e,!0).then(n=>{if(!n){this.reportLoadError(e),t.finish(null);return}let r=new Gr(this,e);r.initWithWebPubManifest(n,void 0,e).then(()=>{t.finish(r)})}):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(r=>{if(r){t.finish(r);return}$.error(`Failed to load ${e}.`),t.finish(null)})})}),t.result()}loadEPUBDoc(e){let t=O("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=O("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(s=>{s?(n=new Gr(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=O("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,r=new Gr(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=la(n.getElementById(o.substr(1)).textContent);r.initWithWebPubManifest(a,n).then(()=>{t.finish(r)})}else{let a=Pe(s.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(l=>{r.initWithWebPubManifest(l,n,a).then(()=>{t.finish(r)})})}}else r.initWithWebPubManifest({},n).then(()=>{r.toc&&r.toc.src===i.url&&Za(n).length===0&&(r.toc=null),t.finish(r)})}}),t.result()}addDocument(e,t){let i=O("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(on)||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:")?$.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&on.startsWith("https:")?$.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?$.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):$.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=O("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""}},Th=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=Vp}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Pe(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=Xp(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 P0(e){return e.id}function T0(e){return t=>{let i=O("deobfuscator");return I0("SHA-1",e).then(n=>{let r=t.slice(0,1040),s=t.slice(1040,t.size);mg(r).then(o=>{let a=new DataView(o);for(let l=0;l<a.byteLength;l++){let h=a.getUint8(l);h^=n[l%20],a.setUint8(l,h)}i.finish(ju([a,s]))})}),i.result()}}function I0(e,t){let i=O("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(r=>{n.schedule(new Uint8Array(r))}),i.result()}var ii={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"},Ln="http://idpf.org/epub/vocab/package/meta/#",Me={language:`${ii.dcterms}language`,title:`${ii.dcterms}title`,creator:`${ii.dcterms}creator`,layout:`${ii.rendition}layout`,titleType:`${Ln}title-type`,displaySeq:`${Ln}display-seq`,alternateScript:`${Ln}alternate-script`,role:`${Ln}role`};function A0(e,t){let i={};return(n,r)=>{var s,o,a,l,h,u;let d,p,f=n.r||i,m=r.r||i;if(e==Me.title&&(d=((s=f[Me.titleType])==null?void 0:s[0].v)=="main",p=((o=m[Me.titleType])==null?void 0:o[0].v)=="main",d!=p))return d?-1:1;let g=parseInt((a=f[Me.displaySeq])==null?void 0:a[0].v,10);isNaN(g)&&(g=Number.MAX_VALUE);let w=parseInt((l=m[Me.displaySeq])==null?void 0:l[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),g!=w?g-w:e!=Me.language&&t&&(d=((h=f[Me.language]||f[Me.alternateScript])==null?void 0:h[0].v)==t,p=((u=m[Me.language]||m[Me.alternateScript])==null?void 0:u[0].v)==t,d!=p)?d?-1:1:n.o-r.o}}function R0(e,t){let i;if(!t)i=ii;else{i={};for(let p in ii)i[p]=ii[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]]:Ln;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:ii.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=Rs(s,d=>d.refines),a=d=>qp(d,(p,f)=>p.map(m=>{let g={v:m.value,o:m.order};m.scheme&&(g.s=m.scheme);let w=o[`#${m.id}`]||[];if(w.length||m.lang||m.role){m.lang&&w.push({name:Me.language,value:m.lang,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null}),m.role&&w.push({name:Me.role,value:m.role,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null});let v=Rs(w,y=>y.name);g.r=a(v)}return g})),l=a(Rs(s,d=>d.refines?null:d.name)),h=null;l[Me.language]&&(h=l[Me.language][0].v);let u=d=>{for(let p in d){let f=d[p];f.sort(A0(p,h));for(let m=0;m<f.length;m++){let g=f[m].r;g&&u(g)}}};return u(l),l}function F0(){let e=window.MathJax;return e?e.Hub:null}var Ih={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Zs="viv-id-",Gr=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 Zs+qh(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(l=>l.src===o))return`#${this.transformFragment(a,o)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(Zs)===0&&(n=n.substring(Zs.length));let r=jp(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=Pe("",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 l=e.getElement(`${e.url}#${n}`);l&&(this.uid=l.textContent.replace(/[ \n\r\t]/g,""))}let r={};this.items=i.child("manifest").child("item").asArray().map(l=>{let h=new Th,u=l;h.initWithElement(u,e.url);let d=u.getAttribute("fallback");return d&&!Ih[h.mediaType]&&(r[h.src]=d),!this.toc&&h.itemProperties.nav&&(this.toc=h),!this.cover&&h.itemProperties["cover-image"]&&(this.cover=h),h}),this.itemMap=ll(this.items,P0),this.itemMapByPath=ll(this.items,l=>this.getPathFromURL(l.src));for(let l in r){let h=l;for(;;){let u=this.itemMap[r[h]];if(!u)break;if(Ih[u.mediaType]){this.fallbackMap[l]=u.src;break}h=u.src}}this.spine=i.child("spine").child("itemref").asArray().map((l,h)=>{let u=l,d=u.getAttribute("idref"),p=this.itemMap[d];return p&&(p.itemRefElement=u,p.spineIndex=h),p});let s=i.child("spine").attribute("page-progression-direction")[0];s&&(this.pageProgression=Dh(s));let o=t?t.doc().child("encryption").child("EncryptedData").predicate(Eh.withChild("EncryptionMethod",Eh.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],a=i.child("bindings").child("mediaType").asArray();for(let l=0;l<a.length;l++){let h=a[l].getAttribute("handler"),u=a[l].getAttribute("media-type");u&&h&&this.itemMap[h]&&(this.bindings[u]=this.itemMap[h].src)}if(this.metadata=R0(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[Me.language]&&(this.lang=this.metadata[Me.language][0].v),this.metadata[Me.layout]&&(this.prePaginated=this.metadata[Me.layout][0].v==="pre-paginated"),o.length>0&&this.uid){let l=T0(this.uid);for(let h=0;h<o.length;h++)this.store.deobfuscators[this.pubURL+o[h]]=l}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=O("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,l=o.lang||this.lang;l&&l.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 tp(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let r=new Th;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[Me.title]=(Array.isArray(a)?a:[a]).map(g=>{var w;return{v:(w=g.value)!=null?w:g}}));let l=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(g=>g.content);l&&l.length!==0&&(this.metadata[Me.creator]=(Array.isArray(l)?l:[l]).map(g=>{var w;return{v:(w=g.name)!=null?w:g}}));let h=e.inLanguage||((o=e.metadata)==null?void 0:o.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");h&&(this.metadata[Me.language]=(Array.isArray(h)?h:[h]).map(g=>({v:g})));let u=this.getPathFromURL(this.pubURL);if(!e.readingOrder&&t&&u!==null){e.readingOrder=[encodeURI(u)];for(let g of k0(t)){let w=g.getAttribute("href");if(/^(https?:)?\/\//.test(w)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(w))continue;let v=Wt(Pe(w,this.pubURL)),y=this.getPathFromURL(v),C=y!==null?encodeURI(y):v;e.readingOrder.indexOf(C)==-1&&e.readingOrder.push(C)}}let d=[],p=0,f=-1;[e.readingOrder,e.resources].forEach(g=>{g instanceof Array&&g.forEach(w=>{let v=g===e.readingOrder,y=typeof w=="string"?w:w.url||w.href,C=typeof w=="string"?"":w.encodingFormat||w.href&&w.type||"";if(v||C==="text/html"||C==="application/xhtml+xml"||!C&&w.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(y)){let E=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,A={url:Pe(jn(y),E),index:p++,startPage:null,skipPagesBefore:null};w.rel==="contents"&&f===-1&&(f=A.index),d.push(A)}})});let m=O("initWithWebPubManifest");return this.initWithChapters(d).then(()=>{var g,w;f!==-1&&(this.toc=this.items[f]),this.toc||(this.toc=i?(g=this.items)==null?void 0:g[0]:this.itemMapByPath[u]);let v=(w=e.readingOrder)==null?void 0:w.length;v&&v<this.items.length&&this.items.splice(v),m.finish(!0)}),m.result()}getCFI(e,t){let i=this.spine[e],n=O("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),l=t-a,h=new fl;h.prependPathFromNode(s,l,!1,null),i.itemRefElement&&h.prependPathFromNode(i.itemRefElement,0,!1,null),o=h.toString()}n.finish(o)}),n.result()}resolveFragment(e){return an("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new fl;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)=>{$.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return an("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=ai(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)=>{$.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=O("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()}},kr=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),L0=class{constructor(e,t,i,n,r){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"),this.pref=Qh(n),this.clientLayout=new d0(t),this.counterStore=new Df(e.documentURLTransformer),this.cmykStore=new Nu}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=O("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)}renderSinglePage(e,t){let i=O("renderSinglePage"),n=e.pages[t?t.page:0],r=this.makePage(e,t);return n&&(r.pageType=n.pageType),e.instance.layoutNextPage(r,t).then(s=>{t=s;let o=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,r,o),this.counterStore.finishPage(r.spineIndex,o);let a=null;if(t){let l=e.layoutPositions[t.page];e.layoutPositions[t.page]=t,l&&e.pages[t.page]&&(t.isSamePosition(l)||(a=this.renderSinglePage(e,t)))}a||(a=N(!0)),a.then(()=>{let l=this.counterStore.getUnresolvedRefsToPage(r),h=0;i.loopWithFrame(u=>{if(h++,h>l.length){u.breakLoop();return}let d=l[h-1];if(d.refs=d.refs.filter(p=>!p.isResolved()),d.refs.length===0){u.continueLoop();return}this.getPageViewItem(d.spineIndex).then(p=>{if(!p){u.continueLoop();return}let{currentPageType:f,previousPageType:m}=p.instance.styler.cascade,g=p.instance.scopes;p.instance.scopes={},this.counterStore.pushPageCounters(d.pageCounters),this.counterStore.pushReferencesToSolve(d.refs);let w=p.layoutPositions[d.pageIndex];this.renderSinglePage(p,w).then(v=>{p.instance.styler.cascade.currentPageType=f,p.instance.styler.cascade.previousPageType=m,p.instance.scopes=g,this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve();let y=v.pageAndPosition.position;y.spineIndex===r.spineIndex&&y.pageIndex===o&&(r=v.pageAndPosition.page),u.continueLoop()})})}).then(()=>{r.container.parentElement||(r=e.pages[o]),r.isLastPage=!t&&e.item.spineIndex===this.opf.spine.length-1,r.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),r.container.setAttribute("data-vivliostyle-page-index",o),r.container.setAttribute("data-vivliostyle-spine-index",r.spineIndex),i.finish({pageAndPosition:kr(r,o),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,s=>t.instance.getPosition(t.layoutPositions[s],!0)>n);r===t.layoutPositions.length?t.complete?i=t.layoutPositions.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=O("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.layoutPositions.length-1,r=n.pages[s],o.breakLoop()):t?this.renderPage(a).then(l=>{l&&(r=l.page,s=l.position.pageIndex),o.breakLoop()}):i.sleep(100).then(()=>{o.continueLoop()})}).then(()=>{i.finish(kr(r,s))})})}),i.result()}renderPage(e){let t=O("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(kr(o,r));return}t.loopWithFrame(a=>{if(r<i.layoutPositions.length){a.breakLoop();return}if(i.complete){r=i.layoutPositions.length-1,a.breakLoop();return}let l=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,l).then(h=>{let u=h.pageAndPosition.page;if(l=h.nextLayoutPosition,l){if(s>=0&&i.instance.getPosition(l)>s){o=u,r=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else o=u,r=h.pageAndPosition.position.pageIndex,i.complete=!0,a.breakLoop()})}).then(()=>{o=o||i.pages[r];let a=i.layoutPositions[r];if(o){t.finish(kr(o,r));return}this.renderSinglePage(i,a).then(l=>{l.nextLayoutPosition||(i.complete=!0),t.finish(l.pageAndPosition)})})}),t.result()}renderAllPages(){let e=O("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=O("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 l={spineIndex:s,pageIndex:s===n?r:Number.POSITIVE_INFINITY,offsetInItem:s===n?e.offsetInItem:-1};this.renderPage(l).then(h=>{o=h,++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=O("nextPage");return this.getPageViewItem(i).then(s=>{if(!s){r.finish(null);return}if(s.complete&&n==s.layoutPositions.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],l=s.pages[s.pages.length-1];a&&l&&a.side==l.side&&(o.pages.forEach(h=>{h.container&&h.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=O("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),l=o&&o.page;l&&l.side===a.side&&(l=null),r?n.finish({left:a,right:l}):n.finish({left:l,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=O("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=O("navigateToCFI");return this.opf.resolveFragment(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}navigateTo(e,t,i){$.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=O("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);this.findPage({spineIndex:r.spineIndex,pageIndex:-1,offsetInItem:a?o.xmldoc.getElementOffset(a):0},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",Gn||(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 oc(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=eu(this.viewport.width,this.viewport.height,i.width,i.height),a=gn(null,new Ft(o,null),"");s.delayedItems.push(new xa(n,"transform",a))}return s}makeObjectView(e,t,i,n){let r=t.getAttribute("data"),s=null;if(r){r=Pe(r,e.url);let o=t.getAttribute("media-type");if(!o){let a=this.opf.getPathFromURL(r);if(a){let l=this.opf.itemMapByPath[a];l&&(o=l.mediaType)}}if(o){let a=this.opf.bindings[o];if(a){s=this.viewport.document.createElement("iframe"),s.style.border="none";let l=ol(r),h=ol(o),u=new oi;u.append(a),u.append("?src="),u.append(l),u.append("&type="),u.append(h);for(let f=t.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let m=f;if(m.localName=="param"&&m.namespaceURI=="http://www.w3.org/1999/xhtml"){let g=m.getAttribute("name"),w=m.getAttribute("value");g&&w&&(u.append("&"),u.append(encodeURIComponent(g)),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=F0();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 l=r.queue;l.Push(["Typeset",r,o]);let h=O("makeMathJaxView"),u=h.suspend();return l.Push(()=>{u.schedule(o)}),h.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=Pe(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=O("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 l=r.itemRefElement.getAttribute("properties");l&&o.root.setAttribute("data-vivliostyle-epub-spine-properties",l),r.title=o.document.title;let h=s.getStyleForDoc(o),u=this.makeCustomRenderer(o),d=this.viewport,p=h.sizeViewport(d.width,d.height,d.fontSize,this.pref);(p.width!=d.width||p.height!=d.height||p.fontSize!=d.fontSize)&&(d=new cs(d.window,p.fontSize,d.pixelRatio,d.root,p.width,p.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,m=this.spineItems[e-1],g,w;if(r.startPage!==null)g=r.startPage-1,w=g;else{if(e>0&&(!m||!m.complete))g=r.epage||e,!this.opf.prePaginated&&g%2==(f?1:0)&&g++,w=g;else{g=m?m.instance.pageNumberOffset+m.pages.length:0;let C=this.counterStore.currentPageCounters.page;w=!C||!C.length?g:C[C.length-1]}r.skipPagesBefore!==null&&(g+=r.skipPagesBefore,w+=r.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let v=new Ka(h,o,this.opf.lang,d,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,g,this.opf.documentURLTransformer,this.counterStore,this.cmykStore,this.opf.pageProgression,f);v.pref=this.pref;let y=this.opf.metadata&&this.opf.metadata[Me.title];v.pubTitle=y&&y[0]&&y[0].v||"",v.docTitle=r.title||"",v.init().then(()=>{!this.opf.pageProgression&&v.pageProgression&&(this.opf.pageProgression=v.pageProgression),t={item:r,xmldoc:o,instance:v,layoutPositions:[null],pages:[],complete:!1},this.spineItems[e]=t,i.finish(t),n.forEach(C=>{C.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=O("showTOC");this.tocView||(this.tocView=new E0(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),Gn||(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(l=>{a.style.visibility="visible",a.setAttribute("aria-hidden","false"),n.finish(l)}),n.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}},Ah="data-vivliostyle-viewer-status",O0="data-vivliostyle-spread-view",sp=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(sp||{}),B0=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");let r=t.ownerDocument,s=(o,a)=>{let l=r.getElementById(o);return l||(l=r.createElement("style"),l.id=o,a&&(l.textContent=a),r.head.appendChild(l)),l};s("vivliostyle-viewport-screen-css",_u),s("vivliostyle-viewport-css",zu),s("vivliostyle-polyfill-css",Wu),t.setAttribute("data-vivliostyle-viewer-viewport",!0),Gn&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(Ah,"loading"),this.fontMapper=new vb(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=Jh(),this.pageSizes=[],this.pixelRatioLimit=Gh==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=Uh;$.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),$.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),$.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),$.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){this.readyState!==e&&(this.readyState=e,this.viewportElement.setAttribute(Ah,e),this.callback({t:"readystatechange"}))}loadPublication(e){pt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,r=e.userStyleSheet;this.viewport=null;let s=O("loadPublication");return this.configure(e).then(()=>{let o=new Ph;o.init(n,r).then(()=>{let a=Pe(jn(t),this.window.location.href);this.packageURL=[a],o.loadPubDoc(a).then(l=>{l?(this.opf=l,this.render(i).then(()=>{s.finish(!0)})):s.finish(!1)})})}),s.result()}loadXML(e){pt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,r=e.authorStyleSheet,s=e.userStyleSheet;this.viewport=null;let o=O("loadXML");return this.configure(e).then(()=>{let a=new Ph;a.init(r,s).then(()=>{let l=t.map((h,u)=>({url:Pe(jn(h.url),this.window.location.href),index:u,startPage:h.startPage,skipPagesBefore:h.skipPagesBefore}));this.packageURL=l.map(h=>h.url),this.opf=new Gr(a,""),this.opf.initWithChapters(l,i).then(()=>{this.render(n).then(()=>{o.finish(!0)})})})}),o.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,N(!0))):t=N(!0),t.thenAsync(()=>(pt.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=At[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"&&(nl(e.userAgentRootURL.replace(/resources\/?$/,"")),rl(e.userAgentRootURL)),typeof e.rootURL=="string"&&(nl(e.rootURL),rl(`${on}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!==Yt&&(i0(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){Rt("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=>{T(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),T(e.container,"visibility","visible"),T(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=O("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?ms(i.fetchers):N(!0)).then(()=>{this.sendLocationNotification(i,t).thenFinish(e)})}),e.result()}createViewport(){let e=this.viewportElement;if(this.viewportSize){let t=this.viewportSize;return e.style.marginLeft=`${t.marginLeft}px`,e.style.marginRight=`${t.marginRight}px`,e.style.marginTop=`${t.marginTop}px`,e.style.marginBottom=`${t.marginBottom}px`,new cs(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new cs(this.window,this.fontSize,this.pixelRatio,e)}resolveSpreadView(e,t){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;case"autoSpread":default:return e!=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(O0,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(m){let g=m*.75;return Math.ceil(g)};var s=o;let a=Math.max(...this.pageSizes.map(m=>m.width)),l=Math.max(...this.pageSizes.map(m=>m.height)),h=o(a),u=o(l),d=h*((this.pixelRatio||1)-1)+2,p=u*((this.pixelRatio||1)-1)+2,f=`@page {size: ${h}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)}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 L0(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this)),e&&this.sendCommand({a:"toc",v:"show",autohide:t})}showCurrent(e,t){this.needRefresh=!1,this.removePageListeners();let i=this.resolveSpreadView(this.viewport,e.dimensions);return i!==this.pref.spreadView&&this.updateSpreadView(i),i?this.opfView.getSpread(this.pagePosition,t).thenAsync(n=>!n.left&&!n.right?N(null):n.left&&n.right&&(!this.resolveSpreadView(this.viewport,n.left.dimensions)||!this.resolveSpreadView(this.viewport,n.right.dimensions))?(this.updateSpreadView(!1),this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,N(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null))}setPageZoom(e){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 Rh),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return N(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=ho().getScheduler().run(()=>an("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,pt.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.currentPage.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(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),pt.registerEndTiming("render (resize)"),Yt&&Qd(this.window)?o0(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 Rh)pt.registerEndTiming("render (resize)"),$.debug(i.message);else throw i}));return N(!0)}sendLocationNotification(e,t){let i=O("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:e.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(r=>{n.epage=r,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(e){var t;let i;if(this.readyState!=="complete"&&e.where!=="next"&&this.setReadyState("loading"),typeof e.where=="string"){let 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=O("moveTo");return i.call(this.opfView).then(r=>{let s;if(r){this.pagePosition=r.position;let o=O("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=O("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 an("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):($.error("No such action:",t),i.finish(!0))},(i,n)=>{$.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=Fh(e),i=null,n=this;ug(()=>{let r=O("commandLoop"),s=ho().getScheduler();return n.hyperlinkListener=o=>{let a=o,l=a.href.charAt(0)==="#"||n.packageURL.some(h=>a.href.substr(0,h.length)==h);if(l){o.preventDefault();let h={t:"hyperlink",href:a.href,internal:l};s.run(()=>(n.callback(h),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=O("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=Fh(r),n.kick(),!0),this.window.adapt_command=n.sendCommand}},op=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(op||{}),Rh=class ap extends Error{constructor(){super(),c(this,"name","RenderingCanceledError"),c(this,"message","Page rendering has been canceled"),c(this,"stack"),Object.setPrototypeOf(this,ap.prototype),this.stack=new Error().stack}};function Fh(e){return typeof e=="string"?la(e):e}var Lh=aa;function M0(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function Oh(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 lp=class{constructor(e,t){this.settings=e,c(this,"initialized",!1),c(this,"adaptViewer_"),c(this,"options"),c(this,"eventTarget"),c(this,"readyState"),zh(e.debug),this.adaptViewer_=new B0(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=M0(),t&&this.setOptions(t),this.eventTarget=new ha,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},Oh(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(h){if(h)return h.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 l=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:_0(e)||t,document:r.documentObject,fragment:r.fragment,authorStyleSheet:o,userStyleSheet:a},Oh(this.options));this.initialized?this.adaptViewer_.sendCommand(l):(this.initialized=!0,this.adaptViewer_.initEmbed(l))}getCurrentPageProgression(){return this.adaptViewer_.getCurrentPageProgression()}resolveNavigation(e){switch(e){case"left":return this.getCurrentPageProgression()===Lh.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Lh.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 _0(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 hp=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(hp||{}),z0=op,D0=sp;pt.forceRegisterEndTiming("load_vivliostyle");var V0=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=`
1849
+ `),i.toString()}},Jb=class{constructor(e){this.deobfuscator=e,d(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(B(r)),i.push(n)}return new it(i)}else{let t=this.familyMap[e.stringValue()];return t?new it([B(t),e]):e}}},Qb=class{constructor(e,t,i){this.head=e,this.body=t,d(this,"srcURLMap",{}),d(this,"familyPrefix"),d(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=_("initFont"),r=e.src,o={};for(let l of vl(e.properties))o[l]=e.properties[l];let s=this.getViewFontFamily(e,i);o["font-family"]=B(s);let a=new _p(o),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(r,t),this.head.appendChild(h),G.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),G.debug("Found already-loaded font:",i)}):(r=new Er(()=>{let o=_("loadFont"),s=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(s):null;return a?qo(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){G.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return Cn(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=_("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?T(!0):T(!1))).thenFinish(i),i.result()}},e0=1,is=class{constructor(e,t,i,n,r){this.name=t,this.pseudoName=i,this.classes=n,this.parent=r,d(this,"specified",{}),d(this,"children",[]),d(this,"pageMaster",null),d(this,"index",0),d(this,"key"),d(this,"_scope"),this._scope=e,this.key=`p${e0++}`,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})}},t0=class extends is{constructor(e){super(e,null,null,[],null),this.specified.width=new V(xr,0),this.specified.height=new V(Sr,0)}},Gh=class extends Rs{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}}},Dp=class zp extends is{constructor(t,i,n,r,o,s,a){super(t,i,n,r,o),this.condition=s,this.specificity=a,d(this,"keyMap",{}),t instanceof Gh||(this._scope=new Gh(t,this)),this.pageMaster=this,this.specified.width=new V(xr,0),this.specified.height=new V(Sr,0),this.specified["wrap-flow"]=new V(y.auto,0),this.specified.position=new V(y.relative,0),this.specified.overflow=new V(y.visible,0)}createInstance(t){return new xl(t,this)}clone(t){let i=new zp(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}},Vp=class Up extends is{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(y.auto,0)}createInstance(t){return new o0(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}},Ar=class Hp extends is{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 In(t,this)}clone(t){let i=new Hp(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function i0(e,t,i){return!t||Z(t)?new Ke(e,i):t.toExpr(e,e.zero)}function ye(e,t,i){return!t||t===y.auto||Z(t)?null:t.toExpr(e,i)}function n0(e,t,i){return!t||t===y.normal||Z(t)?null:t.toExpr(e,i)}function bt(e,t,i){return!t||t===y.auto||Z(t)?e.zero:t.toExpr(e,i)}function jh(e,t,i){return!t||Z(t)?e.zero:t===y.auto?null:t.toExpr(e,i)}function Yt(e,t,i,n){return!t||i===y.none||Z(t)?e.zero:t.toExpr(e,n)}function $p(e,t,i){return!t||Z(t)?i:t===y._true?e._true:t===y._false?e._false:t.toExpr(e,e.zero)}var ns=class{constructor(e,t){this.parentInstance=e,this.pageBox=t,d(this,"cascaded",{}),d(this,"style",{}),d(this,"autoWidth",null),d(this,"autoHeight",null),d(this,"children",[]),d(this,"isAutoWidth",!1),d(this,"isAutoHeight",!1),d(this,"isTopDependentOnAutoHeight",!1),d(this,"isRightDependentOnAutoWidth",!1),d(this,"calculatedWidth",0),d(this,"calculatedHeight",0),d(this,"pageMasterInstance",null),d(this,"namedValues",{}),d(this,"namedFuncs",{}),d(this,"vertical",!1),d(this,"rtl",!1),d(this,"suppressEmptyBoxGeneration",!1),d(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?Cd:kd;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 Wu(i,0),r=this.resolveName("column-count"),o=this.resolveName("column-width"),s=this.resolveName("column-gap");t=fe(i,qr(i,new Kn(i,"min",[n,r]),ie(i,o,s)),s);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=$p(e,t.enabled,e._true),n=ye(e,t.page,e.zero);if(n){let s=new qe(e,"page-number");i=Rt(e,i,new Wa(e,n,s))}let r=ye(e,t["min-page-width"],e.zero);r&&(i=Rt(e,i,new Os(e,new qe(e,"page-width"),r)));let o=ye(e,t["min-page-height"],e.zero);o&&(i=Rt(e,i,new Os(e,new qe(e,"page-height"),o))),i=this.boxSpecificEnabled(i),t.enabled=new W(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=ye(e,t.left,i),r=ye(e,t["margin-left"],i),o=Yt(e,t["border-left-width"],t["border-left-style"],i),s=bt(e,t["padding-left"],i),a=ye(e,t.width,i),h=ye(e,t["max-width"],i),l=bt(e,t["padding-right"],i),u=Yt(e,t["border-right-width"],t["border-right-style"],i),c=ye(e,t["margin-right"],i),p=ye(e,t.right,i),f=ie(e,o,s),g=ie(e,o,l);if(n&&p&&a){let x=fe(e,i,ie(e,a,ie(e,ie(e,n,f),g)));r?c?p=fe(e,x,c):c=fe(e,x,ie(e,p,r)):(x=fe(e,x,p),c?r=fe(e,x,c):(r=qr(e,x,new Ke(e,.5)),c=r))}else{r||(r=e.zero),c||(c=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=fe(e,i,ie(e,ie(e,r,f),ie(e,c,g)));this.isAutoWidth&&(h||(h=fe(e,x,n||p)),!this.vertical&&(ye(e,t["column-width"],null)||ye(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?p||(p=fe(e,x,ie(e,n,a))):a=fe(e,x,ie(e,n,p)):n=fe(e,x,ie(e,p,a))}let m=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=bt(e,m,i);t.left=new W(n),t["margin-left"]=new W(r),t["border-left-width"]=new W(o),t["padding-left"]=new W(s),t.width=new W(a),t["max-width"]=new W(h||a),t["padding-right"]=new W(l),t["border-right-width"]=new W(u),t["margin-right"]=new W(c),t.right=new W(p),t["snap-width"]=new W(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=ye(e,t.top,n),o=ye(e,t["margin-top"],i),s=Yt(e,t["border-top-width"],t["border-top-style"],i),a=bt(e,t["padding-top"],i),h=ye(e,t.height,n),l=ye(e,t["max-height"],n),u=bt(e,t["padding-bottom"],i),c=Yt(e,t["border-bottom-width"],t["border-bottom-style"],i),p=ye(e,t["margin-bottom"],i),f=ye(e,t.bottom,n),g=ie(e,s,a),m=ie(e,c,u);if(r&&f&&h){let b=fe(e,n,ie(e,h,ie(e,ie(e,r,g),m)));o?p?f=fe(e,b,o):p=fe(e,b,ie(e,f,o)):(b=fe(e,b,f),p?o=fe(e,b,p):(o=qr(e,b,new Ke(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 b=fe(e,n,ie(e,ie(e,o,g),ie(e,p,m)));this.isAutoHeight&&(l||(l=fe(e,b,r||f)),this.vertical&&(ye(e,t["column-width"],null)||ye(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),r?h?f||(f=fe(e,b,ie(e,r,h))):h=fe(e,b,ie(e,f,r)):r=fe(e,b,ie(e,f,h))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),x=bt(e,w,i);t.top=new W(r),t["margin-top"]=new W(o),t["border-top-width"]=new W(s),t["padding-top"]=new W(a),t.height=new W(h),t["max-height"]=new W(l||h),t["padding-bottom"]=new W(u),t["border-bottom-width"]=new W(c),t["margin-bottom"]=new W(p),t.bottom=new W(f),t["snap-height"]=new W(x)}initColumns(){let e=this.pageBox.scope,t=this.style,i=ye(e,t[this.vertical?"height":"width"],null),n=ye(e,t["column-width"],i),r=ye(e,t["column-count"],null),o=n0(e,t["column-gap"],null);o||(o=new br(e,1,"em")),n&&!r&&(r=new Kn(e,"floor",[Bs(e,ie(e,i,o),ie(e,n,o))]),r=new Kn(e,"max",[e.one,r])),r||(r=e.one),n=fe(e,Bs(e,ie(e,i,o),r),o),t["column-width"]=new W(n),t["column-count"]=new W(r),t["column-gap"]=new W(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=ca(this.cascaded,e,r,!1,null);this.vertical=Wd(o,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=Gd(o,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=o["box-sizing"])==null?void 0:t.value)===y.border_box;let s=!!(e instanceof Pl&&e.currentLayoutPosition&&new qe(i,"left-page").evaluate(e));Xd(o,n,this.vertical,this.rtl,s,(a,h)=>h.value),this.autoWidth=new Fe(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new Fe(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&&fn(t)&&this.pageMasterInstance instanceof xn&&(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=Lo(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=Lo(e,r,t,o)}return st(r,e)}getSpecial(e,t){let i=Td(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()&&Lu(r.unit)&&(r=Ku(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),N(t,i,r.toString()))}propagateDelayedProperty(e,t,i,n){let r=this.getProp(e,i);r&&n.push(new el(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),N(t.element,"margin-left",`${n}px`),N(t.element,"padding-left",`${r}px`),N(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(N(t.element,"margin-right",`${r}px`),N(t.element,"padding-right",`${o}px`),N(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,N(t.element,"top",`${n}px`),N(t.element,"margin-top",`${r}px`),N(t.element,"padding-top",`${o}px`),N(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;N(t.element,"height",`${o}px`),N(t.element,"margin-bottom",`${i}px`),N(t.element,"padding-bottom",`${n}px`),N(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){N(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,N(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){N(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");N(t.element,"right",`${n}px`),N(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,r){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&N(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&N(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<Xh.length;o++)this.propagateProperty(e,t,Xh[o],n)}transferContentProps(e,t,i,n){for(let r=0;r<Yh.length;r++)this.propagateProperty(e,t,Yh[r],n);if(this.style["text-overflow"]){let r=t.element.firstElementChild;N(r,"text-overflow","inherit"),N(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!==y.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!==y.auto&&!Z(a)};for(let o=0;o<Zh.length;o++){let s=Zh[o];if(s==="width"||s==="height"){if(s==="width"&&!n()||s==="height"&&!r())continue;N(t,s,"100%");continue}this.propagatePropertyToElement(e,t,s,i)}}finishContainer(e,t,i,n,r,o,s){var a,h,l,u,c,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,b=(!this.vertical||!n)&&this.isAutoWidth,v=null;if(b||x){b&&N(t.element,"width","auto"),x&&N(t.element,"height","auto");let C=n&&Co(n);C&&Ko(n),v=o.getElementClientRect(n?n.element:t.element),C&&Ka(n),b&&(this.calculatedWidth=Math.ceil(v.right-v.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),x&&(this.calculatedHeight=v.bottom-v.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 C=this.getPropAsNumber(e,"column-rule-width"),S=this.getProp(e,"column-rule-style"),F=this.getProp(e,"column-rule-color");if(C>0&&S&&S!=y.none&&F!=y.transparent){let A=this.getPropAsNumber(e,"column-gap"),D=this.vertical?t.height:t.width,H=parseFloat(this.vertical?(a=n?.element.style.left)!=null?a:"":(h=n?.element.style.top)!=null?h:""),q=t.getPaddingRect(),Se=n,se=this.vertical?"border-top":"border-left";for(let k=1;k<r;k++){let M=this.vertical?(D+A)*k/r-A/2+t.paddingTop-C/2:(D+A)*k/r-A/2+t.paddingLeft-C/2,E=this.vertical?q.y1+M+C/2:q.x1+M+C/2,L=(c=(u=(l=Se.pageFloatLayoutContext)==null?void 0:l.parent)==null?void 0:u.getBlockEndEdgeOfBlockStartFloats)==null?void 0:c.call(u,E),P=(g=(f=(p=Se.pageFloatLayoutContext)==null?void 0:p.parent)==null?void 0:f.getBlockStartEdgeOfBlockEndFloats)==null?void 0:g.call(f,E),I=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:""),$=z>0?z:this.vertical?n.width:n.height,K=Math.max(H>0?H:0,0),J=K+$,Q=Math.max(K,isFinite(this.vertical?O:I)?Math.max(0,this.vertical?O:I):0),de=Math.min(J,isFinite(this.vertical?I:O)?Math.max(0,this.vertical?I:O):J),re=Math.max(0,de-Q),oe=t.element.ownerDocument.createElement("div");N(oe,"position","absolute"),N(oe,this.vertical?"left":"top",`${Q}px`),N(oe,this.vertical?"top":"left",`${M}px`),N(oe,this.vertical?"height":"width","0px"),N(oe,this.vertical?"width":"height",`${re}px`),N(oe,se,`${C}px ${S.toString()}${F?` ${F.toString()}`:""}`),t.element.insertBefore(oe,t.element.firstChild)}}}for(let C=0;C<qh.length;C++)this.propagateProperty(e,t,qh[C],s);for(let C=0;C<Kh.length;C++)this.propagateDelayedProperty(e,t,Kh[C],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let o in n)this instanceof xn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(o==="writing-mode"||o==="direction")||Mi(o)&&bi(i,o,ge(n,o));if(this.pageBox.pseudoName==bl)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 cr(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)}},Xh=["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"],qh=["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"],Yh=["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"],Zh=["width","height","image-resolution","object-fit","object-position"],Kh=["transform","transform-origin"],bl="background-host",r0=class extends ns{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)}},xl=class extends ns{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=Rt(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},o0=class extends ns{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},In=class extends ns{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof ce&&(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 ce){let s=Fs(n[o].name,"enabled"),a=new qe(r,s);i&&(a=new yi(r,a)),e=Rt(r,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=$p(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let r=i0(t,i["flow-from"],"body"),o=new Kn(t,"has-content",[r]);e=Rt(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=Rt(t,o,e),this.pageMasterInstance.style.enabled=new W(o)}return e}prepareContainer(e,t,i,n,r){var o;this.pageBox.pageMaster instanceof qp||(N(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(o=this.pageBox.name)!=null?o:"")),super.prepareContainer(e,t,i,n,r)}},Sl=class extends Gi{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?_c:Dc)}},Wp=class extends Sl{constructor(e,t,i,n){super(e,t,i,n)}},s0=class Gp extends Sl{constructor(t,i,n,r){super(t,i,n,r),n.specified.width=new V(Ul,0),n.specified.height=new V(Ul,0)}startPartitionRule(t,i,n){let r=new Ar(this.scope,t,i,n,this.target),o=new Wp(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,i,n){let r=new Vp(this.scope,t,i,n,this.target),o=new Gp(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}},a0=class extends Sl{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new Ar(this.scope,e,t,i,this.target),r=new Wp(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(e,t,i){let n=new Vp(this.scope,e,t,i,this.target),r=new s0(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}};function jp(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===y.vertical_lr||n!==y.vertical_rl&&r!==y.rtl?"ltr":"rtl"}var l0={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")}},h0=new R(.24,"pt"),Lx=new R(3,"mm"),u0=new R(10,"mm"),c0=new R(13,"mm");function Vo(e){let t={width:xr,height:Sr,bleed:Ae,bleedOffset:Ae,cropOffset:Ae},i=e.size;if(!(!i||i.value===y.auto)){let l=i.value,u,c;if(l.isSpaceList()?(u=l.values[0],c=l.values[1]):(u=l,c=null),u.isNumeric())t.width=u,t.height=c||u;else{let p=u.name&&l0[u.name.toLowerCase()];p&&(c&&c===y.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:y.none,s=r&&!Z(r.value)?r.value:y.auto;if(s===y.auto){if(o!==y.none){let l=!1;o.isSpaceList()?l=o.values.some(u=>u===y.crop):l=o===y.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:y.auto;return h===y.auto?o!==y.none&&(t.bleedOffset=c0):h.isNumeric()&&(t.cropOffset=h),t}function Jh(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===xr?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===Sr?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 Xp(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 sr(e,t,i,n){n=n||"polyline";let r=e.createElementNS("http://www.w3.org/2000/svg",n);return r.setAttribute("stroke",i===y.auto?"#010101":i.toString()),r.setAttribute("stroke-width",t),r.setAttribute("fill","none"),r}var Ia=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(Ia||{});function d0(e,t,i,n,r,o,s){let a=r;a<=o+2*zt.mm&&(a=o+r/2);let h=Math.max(r,a),l=o+h+i/2,u=Xp(e,l,l),c=[[0,o+r],[r,o+r],[r,o+r-a]],p=c.map(m=>[m[1],m[0]]);(t==="top right"||t==="bottom right")&&(c=c.map(m=>[o+h-m[0],m[1]]),p=p.map(m=>[o+h-m[0],m[1]])),(t==="bottom left"||t==="bottom right")&&(c=c.map(m=>[m[0],o+h-m[1]]),p=p.map(m=>[m[0],o+h-m[1]]));let f=sr(e,i,n);f.setAttribute("points",c.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=sr(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 mr=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(mr||{});function p0(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=Xp(e,a,h),u=sr(e,i,n);u.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(u);let c=sr(e,i,n);c.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(c);let p=sr(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(mr).forEach(g=>{let m=mr[g];m===t?l.style[m]=`${o}px`:m!==f&&(l.style[m]="0",l.style[`margin-${m}`]="auto")}),l}function f0(e,t,i,n){let r=!1,o=!1,s=e.marks;if(s){let m=s.value;m instanceof ee?m.values.forEach(w=>{w===y.crop?r=!0:w===y.cross&&(o=!0)}):m===y.crop?r=!0:m===y.cross&&(o=!0)}let a=t.bleed;if(!r&&!o)return;let h=i.container,l=h.ownerDocument,u=st(h0,n),c=Math.max(0,t.bleedOffset-st(u0,n)),p=t.bleedOffset-c,f=e["crop-marks-line-color"],g=f&&!Z(f.value)?f.value:y.auto;r&&Object.keys(Ia).forEach(m=>{let w=Ia[m],x=d0(l,w,u,g,p,a,c);h.appendChild(x)}),o&&Object.keys(mr).forEach(m=>{let w=mr[m],x=p0(l,w,u,g,p,c);h.appendChild(x)})}var Aa=(()=>{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})(),Cl={"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"}},g0=(()=>{let e=Cl;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),kl="vivliostyle-page-rule-master",wr="_marginBoxes",Uo="_footnoteArea",qp=class extends Dp{constructor(e,t,i){super(e,null,kl,[],t,null,0),d(this,"pageMarginBoxes",{});let n=Vo(i),r=new m0(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[wr];t&&g0.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new y0(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new V(y.relative,0),this.specified.width=new V(t.width,0),this.specified.height=new V(t.height,0);for(let i in e)!Aa[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new xn(e,this)}},m0=class extends Ar{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let r=new w0(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new V(y.auto,0),this.specified["z-index"]=new V(new ze(0),0),this.specified.position=new V(y.absolute,0),this.specified.overflow=new V(y.visible,0);for(let t in Aa)Aa.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new b0(e,this)}},w0=class extends Ar{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new V(B("body"),0)}createInstance(e){return new Yp(e,this)}},y0=class extends Ar{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[wr][this.marginBoxName];for(let i in e){let n=e[i],r=t[i];(Sd[i]||r&&r.value===y.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!==y.inherit&&n.value!==y.unset&&n.value!==y.revert&&(this.specified[i]=n)}}createInstance(e){return new Zp(e,this)}},xn=class extends xl{constructor(e,t){super(e,t),d(this,"pageAreaDimension",null),d(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=Ae,e["margin-left"]=Ae,e["border-left-width"]=Ae,e["padding-left"]=Ae,e["padding-right"]=Ae,e["border-right-width"]=Ae,e["margin-right"]=Ae,e.right=Ae}initVertical(){let e=this.style;e.top=Ae,e["margin-top"]=Ae,e["border-top-width"]=Ae,e["padding-top"]=Ae,e["padding-bottom"]=Ae,e["border-bottom-width"]=Ae,e["margin-bottom"]=Ae,e.bottom=Ae}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new W(e.borderBoxWidth),t.height=new W(e.borderBoxHeight),t["padding-left"]=new W(e.marginLeft),t["padding-right"]=new W(e.marginRight),t["padding-top"]=new W(e.marginTop),t["padding-bottom"]=new W(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={},c={};for(let v in e){let C=Cl[v];if(C){let S=e[v],F=this.pageMarginBoxInstances[v],A=new fo(S,F.style,t,h,r);l[C.positionAlongVariableDimension]=S,u[C.positionAlongVariableDimension]=F,c[C.positionAlongVariableDimension]=A}}let p={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(c,p.extent),g=!1,m={};Object.keys(l).forEach(v=>{let C=v,S=ye(h,u[C].style[t?"max-width":"max-height"],i.extent);if(S){let F=S.evaluate(n);if(f[C]>F){let A=c[C]=new Qh(l[C],u[C].style,t,h,r,F);m[C]=A.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(c,p.extent),g=!1,[o,s,a].forEach(v=>{var C;f[v]=(C=m[v])!=null?C:f[v]}));let w={};Object.keys(l).forEach(v=>{let C=v,S=ye(h,u[C].style[t?"min-width":"min-height"],i.extent);if(S){let F=S.evaluate(n);if(f[C]<F){let A=c[C]=new Qh(l[C],u[C].style,t,h,r,F);w[C]=A.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(c,p.extent),[o,s,a].forEach(v=>{f[v]=w[v]||f[v]}));let x=p.start+p.extent,b=p.start+(p.start+p.extent);[o,s,a].forEach(v=>{let C=f[v];if(C!=null){let S=l[v],F=0;switch(v){case o:F=t?S.left:S.top;break;case s:F=(b-C)/2;break;case a:F=x-C;break}t?S.setHorizontalPosition(F,C-S.getInsetLeft()-S.getInsetRight()):S.setVerticalPosition(F,C-S.getInsetTop()-S.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 v0(a),l=this.distributeAutoMarginBoxSizes(r,h,t);l.xSize!=null&&(s.center=l.xSize);let u=(i=l.xSize)!=null?i:r.getOuterSize(),c=Math.max((t-u)/2,0);n&&(s.start=n.hasAutoSize()?c:n.getOuterSize()),o&&(s.end=o.hasAutoSize()?c: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 fo&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof fo&&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)}},fo=class{constructor(e,t,i,n,r){this.container=e,this.isHorizontal=i,this.clientLayout=r,d(this,"hasAutoSize_"),d(this,"size",null),d(this,"minMaxFitContent",null);let o=t[i?"width":"height"];if(this.hasAutoSize_=!o||o===y.auto||Z(o),this.minMaxFitContent=o instanceof ce&&(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=Qa(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()}},v0=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}},Qh=class extends fo{constructor(e,t,i,n,r,o){super(e,t,i,n,r),d(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()}},b0=class extends In{constructor(e,t){super(e,t),d(this,"borderBoxWidth",null),d(this,"borderBoxHeight",null),d(this,"contentBoxWidth",null),d(this,"contentBoxHeight",null),d(this,"marginTop",null),d(this,"marginRight",null),d(this,"marginBottom",null),d(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=ye(n,t[s],a),l=ye(n,t[`margin-${r}`],a),u=ye(n,t[`margin-${o}`],a),c=bt(n,t[`padding-${r}`],a),p=bt(n,t[`padding-${o}`],a),f=Yt(n,t[`border-${r}-width`],t[`border-${r}-style`],a),g=Yt(n,t[`border-${o}-width`],t[`border-${o}-style`],a),m=ie(n,ie(n,f,c),ie(n,g,p)),w,x,b;return h?(this.borderBoxSizing?(x=h,b=fe(n,x,m)):(b=h,x=ie(n,b,m)),w=fe(n,a,x),!l&&!u?(l=qr(n,w,new Ke(n,.5)),u=l):l?u=fe(n,w,l):l=fe(n,w,u)):(l||(l=n.zero),u||(u=n.zero),w=ie(n,l,u),x=fe(n,a,w),b=fe(n,x,m),h=this.borderBoxSizing?x:b),t[r]=new W(l),t[o]=new W(u),t[`margin-${r}`]=Ae,t[`margin-${o}`]=Ae,t[`border-${r}-width`]=new W(f),t[`border-${o}-width`]=new W(g),t[`padding-${r}`]=new W(c),t[`padding-${o}`]=new W(p),t[s]=new W(h),t[`max-${s}`]=new W(h),{borderBoxExtent:x,contentBoxExtent:b,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 In{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 W(this.parentInstance.contentBoxWidth),e["margin-left"]=new W(new ln(i,t.left.toExpr(i,null))),e["margin-right"]=new W(new ln(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=y.solid,e["border-right-style"]=y.solid,e["border-left-color"]=y.transparent,e["border-right-color"]=y.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new W(this.parentInstance.contentBoxHeight),e["margin-top"]=new W(new ln(i,t.top.toExpr(i,null))),e["margin-bottom"]=new W(new ln(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=y.solid,e["border-bottom-style"]=y.solid,e["border-top-color"]=y.transparent,e["border-bottom-color"]=y.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}},Zp=class extends In{constructor(e,t){super(e,t),d(this,"boxInfo"),d(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=Cl[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){N(t,"display","flex"),N(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&&N(t,"justify-content",n);let r=this.getProp(e,"content");if(this.vertical||r instanceof ht||r instanceof W&&r.expr instanceof Fe&&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")),N(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=ye(n,i[s],h),u=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[r]=new W(u);else if(l){let c=bt(n,i[`margin-${r}`],h),p=bt(n,i[`margin-${o}`],h),f=bt(n,i[`padding-${r}`],h),g=bt(n,i[`padding-${o}`],h),m=Yt(n,i[`border-${r}-width`],i[`border-${r}-style`],h),w=Yt(n,i[`border-${o}-width`],i[`border-${o}-style`],h),x=ie(n,l,ie(n,this.borderBoxSizing?n.zero:ie(n,ie(n,f,g),ie(n,m,w)),ie(n,c,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[r]=new W(ie(n,u,Bs(n,fe(n,h,x),new Ke(n,2))));break;case"end":i[r]=new W(fe(n,ie(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=jh(n,i[`margin-${o}`],h),u=jh(n,i[`margin-${s}`],h),c=bt(n,i[`padding-${o}`],h),p=bt(n,i[`padding-${s}`],h),f=Yt(n,i[`border-${o}-width`],i[`border-${o}-style`],h),g=Yt(n,i[`border-${s}-width`],i[`border-${s}-style`],h),m=ye(n,i[a],h),w=null;function x(b){if(w)return w;w={extent:m?m.evaluate(b):null,marginInside:l?l.evaluate(b):null,marginOutside:u?u.evaluate(b):null};let v=h.evaluate(b),C=0;return r||[f,c,p,g].forEach(S=>{S&&(C+=S.evaluate(b))}),(w.marginInside===null||w.marginOutside===null)&&C+w.extent+w.marginInside+w.marginOutside>v&&(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=v-C-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=v-C-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=v-C-w.extent-w.marginInside:w.marginInside=w.marginOutside=(v-C-w.extent)/2),w}i[a]=new W(new Fe(n,function(){let b=x(this).extent;return b===null?"auto":b},a)),i[`margin-${o}`]=new W(new Fe(n,function(){let b=x(this).marginInside;return b===null?"auto":b},`margin-${o}`)),i[`margin-${s}`]=new W(new Fe(n,function(){let b=x(this).marginOutside;return b===null?"auto":b},`margin-${s}`)),o==="left"?i.left=new W(ie(n,t.marginLeft,t.borderBoxWidth)):o==="top"&&(i.top=new W(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,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,c=this.getProp(e,"width"),p=c instanceof ce&&(c.name==="min-content"||c.name==="max-content"||c.name==="fit-content")?c.name:null,f=this.getPropAsNumber(e,"min-width"),g=this.getPropAsNumber(e,"max-width");if(p||f||g){p&&N(t.element,"width",p),f&&N(t.element,"min-width",`${f}px`),g&&N(t.element,"max-width",`${g}px`);let v=this.getProp(e,"margin-left"),C=this.getProp(e,"margin-right");if(l.isInLeftColumn){let S=u.borderBoxWidth.evaluate(e)+u.marginRight.evaluate(e);N(t.element,"right",`${S}px`),(v===y.auto||C!==y.auto)&&N(t.element,"margin-left","auto"),C===y.auto&&N(t.element,"margin-right","auto")}else l.isInRightColumn&&(N(t.element,"right","0"),(C===y.auto||v!==y.auto)&&N(t.element,"margin-right","auto"),v===y.auto&&N(t.element,"margin-left","auto"))}let m=this.getProp(e,"height"),w=m instanceof ce&&(m.name==="min-content"||m.name==="max-content"||m.name==="fit-content")?m.name:null,x=this.getPropAsNumber(e,"min-height"),b=this.getPropAsNumber(e,"max-height");if(w||x||b){w&&N(t.element,"height",w),x&&N(t.element,"min-height",`${x}px`),b&&N(t.element,"max-height",`${b}px`);let v=this.getProp(e,"margin-top"),C=this.getProp(e,"margin-bottom");if(l.isInTopRow){let S=u.borderBoxHeight.evaluate(e)+u.marginBottom.evaluate(e);N(t.element,"bottom",`${S}px`),(v===y.auto||C!==y.auto)&&N(t.element,"margin-top","auto"),C===y.auto&&N(t.element,"margin-bottom","auto")}else l.isInBottomRow&&(N(t.element,"bottom","0"),(C===y.auto||v!==y.auto)&&N(t.element,"margin-bottom","auto"),v===y.auto&&N(t.element,"margin-top","auto"))}}},x0=class{constructor(e,t,i,n,r){this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=r,d(this,"pageMasterCache",{}),d(this,"pageCascadeInstance"),this.pageCascadeInstance=e,this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new qe(e,"page-number"),r=new Wa(e,new Vu(e,n,new Ke(e,2)),i?e.one:e.zero);e.defineName("recto-page",new yi(e,r)),e.defineName("verso-page",r),(t.pageProgression||jp(this.docElementStyle))==="ltr"?(e.defineName("left-page",r),e.defineName("right-page",new yi(e,r))):(e.defineName("left-page",new yi(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===bl?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 qp(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:kl}),n=i.specified,r=e.size;if(r&&!Z(r.value)){let s=Vo(e),a=r.priority;Ut(n,"width",new V(s.width,a),this.context),Ut(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}},S0=class extends xe{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}},C0=class extends xe{constructor(e){super(),this.scope=e}apply(e){new qe(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},k0=class extends xe{constructor(e){super(),this.scope=e}apply(e){new qe(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},E0=class extends xe{constructor(e){super(),this.scope=e}apply(e){new qe(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},P0=class extends xe{constructor(e){super(),this.scope=e}apply(e){new qe(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},N0=class extends xe{constructor(e){super(),this.scope=e}apply(e){new qe(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},T0=class extends xe{constructor(e){super(),this.scope=e}apply(e){new qe(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},I0=class extends ji{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}},A0=class extends ji{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}},F0=class extends hl{constructor(e,t){super(e,t,null,null,null)}apply(e){R0(e.context,e.currentStyle,this.style,this.specificity,e)}};function R0(e,t,i,n,r){Fo(e,t,i,n,null,null,null);let o=i[wr];if(o){let a=Kt(t,wr);for(let h in o)if(o.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l),Fo(e,l,o[h],n,null,null,null)}}let s=i[Uo];if(s){let a=Kt(t,Uo);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&&Ut(l,p,f)}let c=pt(u,"_pseudos");if(c){let p=Kt(l,"_pseudos");for(let f in c)if(c.hasOwnProperty(f)){let g=p[f];g||(g={},p[f]=g);let m=c[f];for(let w in m)if(m.hasOwnProperty(w)){let x=m[w];x instanceof V&&Ut(g,w,x)}}}}}}var L0=class extends dr{constructor(e,t,i,n,r){super(e,t,i?.condition,i,null,n,!1),this.pageProps=r,d(this,"currentPageSelectors",[]),d(this,"currentNamedPageSelector",""),d(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new S0(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 A0(this.scope,i,n,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new I0(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 C0(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new k0(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new E0(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new P0(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new N0(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new T0(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=ge(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(o=>{bi(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?Ut(l,e,a):(l=r[h]={},bi(l,e,a),o&&["bleed","marks"].forEach(u=>{o[u]&&bi(l,u,o[u])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new F0(this.elementStyle,e)}startFootnoteRule(e){let t=Kt(this.elementStyle,Uo),i=t.area;if(i||(i={},t.area=i),e){let r=Kt(i,"_pseudos"),o=r[e];o||(o={},r[e]=o),i=o}let n=new Kp(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}startPageMarginBoxRule(e){let t=Kt(this.elementStyle,wr),i=t[e];i||(i={},t[e]=i);let n=new O0(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},O0=class extends Gi{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);bi(this.boxStyle,e,r)}},Kp=class extends Gi{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);bi(this.areaStyle,e,r)}},ai=!0;function B0(e){ai=e}var Di=[];function eu(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Jp(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 El(e,t,i){if(!ai||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Jp(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(Qp(t)||(t.onload=null),l)return Di.some(c=>eu(c,e))||Di.push(e),T(!0);for(let c of t.document.head.getElementsByTagName("script"))c.hasAttribute("data-vivliostyle-scripting")&&eu(c,e)&&t.document.head.removeChild(c);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 c of e.attributes)["src","async","defer"].includes(c.name)||u.setAttribute(c.name,c.value);if(G.debug("script:",r),r){let c=Wt(u);return t.document.head.appendChild(u),Cn([c])}else return t.document.head.appendChild(u),T(!0)}function M0(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 hl)r(s.style);else if(s instanceof Ln||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 _0(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=M0(e,i),r.textContent=e.documentElement.textContent,t.document.body.appendChild(r),r}function D0(e,t,i){if(!ai)return T(!1);let n=Jp(e);if(n.length===0)return T(!1);let r=n.some(u=>!(u.async||u.defer||u.type==="module")),o=r?_0(e,t,i):null,s=t.document.fonts,a=t.$,h=!1,l=_("loadScripts");return l.loop(()=>{if(n.length===0)return r?l.sleep(20).thenAsync(()=>{var c,p;return s.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(c=t.FontJSON)!=null&&c.Font&&(p=t.ret)!=null&&p.readyState&&t.ret.readyState<4?T(!0):T(!1)}):T(!1);let u=n.shift();return El(u,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(Di.push(u),h=!0),n.length===0&&r&&(G.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),T(!0)))}).then(()=>{o&&o.remove(),l.finish(!0)}),l.result()}function z0(e){if(!ai)return T(!1);let t=_("loadScripts");return t.loop(()=>Di.length===0?T(!1):El(Di.shift(),e,{atEnd:!0}).thenReturn(Di.length>0)).then(()=>{G.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),G.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Qp(e){return ai?Di.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var V0=(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)}`),U0={};function H0(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 Fa=class Yn extends Va{constructor(t,i,n,r,o,s,a,h,l,u,c,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=c,this.fallbackMap=p,this.documentURLTransformer=f,this.pageProps=g,this.cascadedPageStyle=m,this.semanticFootnoteFirstRefOffsets=w,this.semanticFootnoteFirstRefOffsetsInitialized=x,d(this,"document"),d(this,"exprContentListener"),d(this,"computedStyleParentFontSizeOverride",null),d(this,"computedStyleParentLineHeightOverride",null),d(this,"nodeContext",null),d(this,"viewRoot",null),d(this,"isFootnote",!1),d(this,"sourceNode",null),d(this,"offsetInNode",0),d(this,"viewNode",null),this.document=n.document,this.exprContentListener=r.counterListener.getExprContentListener()}clone(){return new Yn(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"||!Lt(t)||!mh(t,this.xmldoc.url,r=>this.xmldoc.getElementOffset(r),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized))return;let i=t.getAttribute(tr);if(!i)return;let n=wd(t,this.xmldoc.url,r=>this.xmldoc.getElement(r));n&&n.setAttribute(tr,i)}createPseudoelementShadow(t,i,n,r,o,s,a,h){var l,u;let c=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,s);if(!c)return h;let p=[],f=Gn.createElementNS("http://www.pyroxy.com/ns/shadow","root"),g=f,m=Lt(t)&&!!c["footnote-call"]&&St((l=c["footnote-call"].content)==null?void 0:l.value);for(let b of tv){let v;if(b){if(!c[b])continue;let C=yt(t),S=t.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&t.localName==="include"&&t.classList.contains("-vivliostyle-footnote-content");if(b=="footnote-call"&&!Lt(t)||b=="footnote-marker"&&!(C||S||i&&this.isFootnote)&&!((u=this.nodeContext)!=null&&u.pluginProps.nestedFootnoteDetached))continue;if(b.match(/^first-/)){let F=r.display;if(!F||F===y.inline)continue;let A=t.firstElementChild;if(A&&Ve(A.previousSibling)){let D=o.getStyle(A,!1);if(D){let H=ge(D,"display");if(H!=null&&H.value&&H.value!==y.inline)continue}}}if(b==="before"||b==="after"||b==="footnote-call"||b==="footnote-marker"){let F=c[b].content,A=(b==="before"||b==="after")&&(r.float===y.footnote||C||S)&&!!F;if(!F||!St(F.value)&&!A)continue}p.push(b),v=Gn.createElementNS("http://www.w3.org/1999/xhtml","span"),nr(v,b)}else{if(m)continue;v=Gn.createElementNS("http://www.pyroxy.com/ns/shadow","content")}g.appendChild(v),b.match(/^first-/)&&(g=v)}if(!p.length)return h;let w=new xs(t,n,o,s,this.exprContentListener),x=new Zr(t,f,null,a,h,rt.ROOTLESS,w);return h||x}getPseudoMap(t,i,n,r,o){let s=pt(t,"_pseudos");if(!s)return null;let a={};for(let h in s){let l=a[h]={};ir(l,s[h],o),ua(l,o,s[h]),jd(s[h],i,n,(u,c)=>{ir(l,c,o),$d(c,p=>{ir(l,p,o)})})}return a}createRefShadow(t,i,n,r,o){let s=_("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 Zr(n,l,h,r,o,i,u)}}s.finish(o)}),s.result()}createShadows(t,i,n,r,o,s,a){let h=_("createShadows"),l=null,u=r.template,c;if(u instanceof ht||u===y.footnote)if(u!==y.footnote||mh(t,this.xmldoc.url,p=>this.xmldoc.getElementOffset(p),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)){let p=u instanceof ht?u.url:Ne("user-agent.xml#footnote",mi);c=this.createRefShadow(p,rt.ROOTLESS,t,a,l)}else c=T(l);else c=T(l);return c.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=yo(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===y.table_cell){let w=Ne("user-agent.xml#table-cell",mi);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=ca(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=Wd(a,s,t);let u=!h&&t!==l;i=Gd(a,s,i);let c=(x,b)=>{let v;u&&(t?/^(min-|max-)?(height|inline-size)$/.test(x)&&(v=s.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(x)&&(v=s.pageAreaWidth));let C=b.evaluate(s,x,v,t);return x=="font-family"&&(C=this.docFaces.filterFontFamily(C)),C},p=!!new qe(s.style.pageScope,"left-page").evaluate(s);if(Xd(a,r,t,i,p,c),u){let x=r[t?"height":"width"];(!x||x===y.auto)&&(r[t?"height":"width"]=y.max_content)}if(So(r.position))return r.position=y.fixed,r.visibility=y.hidden,t;let f=r.position,g=r.float,m=r.display||(this.sourceNode&&this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?y.inline:void 0),w=Hc(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&&Lt(w)){let x=w.getAttribute("href")||w.getAttributeNS("http://www.w3.org/1999/xlink","href");if(x){let b=yo(x,this.xmldoc.url),v=this.xmldoc.getElement(b);v&&yt(v)&&((n=v.parentNode)==null?void 0:n.nodeType)===1&&(r=v.parentNode,l=null)}}}let u=-1;for(;r&&r.nodeType==1;){let w=l&&l.root==r,x=!!w&&l.type==rt.ROOTED&&yt(r);if(!w||l.type==rt.ROOTLESS||x){let b=(l?l.styler:this.styler).getStyle(r,!1);o.push(b),s=s||As(r)}w&&!x?(r=l.owner,l=l.parentShadow):(r=r.parentNode,u++)}let c=new Set;if(o.length>0){let w=o[0],x=ca(w,this.context,this.regionIds,this.isFootnote,this.nodeContext);for(let b in x){if(!fn(b))continue;let v=x[b].evaluate(this.context,b);v&&v!==y.inherit&&v!==y.unset&&v!==y.revert&&v!==Y&&c.add(b)}}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 xt(this.context.pref.lineHeight),0));let m=new hy(g,this.context);for(let w=o.length-1;w>=0;--w){let x=o[w],b=[];for(let S in x)fn(S)&&b.push(S);b.sort($l);let v,C;for(let S of b){if(w>0&&h&&S.startsWith("--viv-marker-")||w>0&&c.has(S))continue;m.setPropName(S);let F=ge(x,S),A=F;if(F.value===y.initial)delete g[S];else if(!Z(F.value)){if(S==="font-size"&&w===o.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)A=new V(new R(this.context.rootFontSize,"px"),F.priority);else if(S==="line-height"&&w===o.length-1&&this.context.rootLineHeight&&F.value instanceof R&&(F.value.unit==="lh"||F.value.unit==="rlh"))A=new V(new R(this.context.rootLineHeight,"px"),F.priority);else if(w===0&&F.value instanceof R&&F.value.unit==="lh"){let D=this.getLineHeightUnitSize(S,v,C);D!=null&&(A=new V(new R(F.value.num*D,"px"),F.priority))}else Zt(S)||(A=F.filterValue(m));S==="font-size"?v=A.value:S==="line-height"&&(C=A.value),g[S]=A}}}for(let w in t)fn(w)||(g[w]=t[w]);return{lang:s,elementStyle:g}}resolveURL(t){return t=Ne(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=As(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=Jw().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===y.initial&&(n[r]=void 0);else if(o instanceof ze)n[r]=o.num;else if(o instanceof ce)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*zt[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=Ot("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=_("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 C=this.xmldoc.getElementOffset(a);Qo.registerFragmentIndex(C,this.nodeContext.fragmentIndex,0)}let u={},c={getStyle:C=>this.styler.getStyle(C,!1),getProp:(C,S)=>C?ge(C,S):null,getStyleMap:(C,S)=>pt(C,S),getMutableStyleMap:(C,S)=>Kt(C,S),createCascadeValue:(C,S)=>new V(C,S),filterFootnoteMarkerContent:(C,S)=>C.filterValue(new cr(this.styler.cascade,S,this.styler.cascade.counterResolver,"footnote-marker")).value};if(!this.nodeContext.parent){let C=this.inheritFromSourceParent(l);l=C.elementStyle,this.nodeContext.lang=C.lang}let p=l.position,f=l.float,g=l["float-reference"],m=f&&!Z(f.value)&&f.value!==y.none&&g&&!Z(g.value)?Lw(g.value.toString()):null,w=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===rt.ROOTED&&yt(a);if(this.nodeContext.parent&&(So(p?.value)||m&&vi(m)||w)){let C=this.inheritFromSourceParent(l);l=C.elementStyle,this.nodeContext.lang=C.lang}l=_w(a,l,this.nodeContext.shadowContext,this.xmldoc.url,C=>this.xmldoc.getElement(C),tr,c),l=Dw(a,l,this.nodeContext.shadowContext,this.context,c),this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,u),m&&vi(m)&&u.display===y.block&&(u.display=y.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(ai&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return El(a,this.viewport.window).thenFinish(s),s.result();let b=u.display;if(yt(a)&&!w&&a.hasAttribute(md)&&(b=u.display=y.none),Z(b)&&(b===y.initial||b===y.unset?b=y.inline:b===y.inherit?b=((n=this.nodeContext.parent)==null?void 0:n.display)&&B((r=this.nodeContext.parent)==null?void 0:r.display):b=null),b===y.none)return s.finish(!1),s.result();let v=this.nodeContext.parent==null;return this.nodeContext.flexContainer=b===y.flex,this.createShadows(a,v,l,u,h,this.context,this.nodeContext.shadowContext).then(C=>{var S;this.nodeContext.nodeShadow=C;let F=u.position,A=u.float,D=u.clear,H=this.nodeContext.vertical?y.vertical_rl:y.horizontal_tb,q=this.nodeContext.parent?this.nodeContext.parent.vertical?y.vertical_rl:y.horizontal_tb:H,Se=Zm(a),se=u["column-count"],k=u["column-width"],M=se&&se!==y.auto&&!Z(se)||k&&k!==y.auto&&!Z(k);this.nodeContext.establishesBFC=Jm(b,F,A,u.overflow,H,q,M||Se),this.nodeContext.containingBlockForAbsolute=Qm(F),this.nodeContext.isInsideBFC()&&A!==y.footnote&&!(m&&vi(m))&&(A=null,D=null);let E=null,L=!1,P=this.isFootnote&&(!((S=this.nodeContext)!=null&&S.parent)||this.nodeContext.pluginProps.nestedFootnoteDetached||w),I=zw(a,this.nodeContext.shadowContext,c);Vw(I.sourceStyle,u,this.context),E=I.footnoteDisplay;let O=A instanceof ee||A===y.left||A===y.right||A===y.top||A===y.bottom||A===y.inline_start||A===y.inline_end||A===y.block_start||A===y.block_end||A===y.snap_block||A===y.snap_inline||A===y.inside||A===y.outside||A===y.footnote;if(A&&(delete u.float,A===y.footnote))if(E=u["footnote-display"]||E,L=!!u["--viv-marker-content"],P){O=!1;let j=E?.toString();j&&(u["--viv-footnote-display"]=B(j)),b=L?B("list-item"):j==="inline"||j==="compact"?y.inline:y.block,u.display=b}else u.display=y.inline;if(P&&yt(a)){L=L||!!u["--viv-marker-content"];let j=E?.toString();j&&(u["--viv-footnote-display"]=B(j)),L&&(b=u.display=B("list-item")),!L&&(j==="inline"||j==="compact")&&(b=u.display=y.inline)}D&&(D===y.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(D=B(this.nodeContext.parent.clearSide)),(D===y.left||D===y.right||D===y.top||D===y.bottom||D===y.inline_start||D===y.inline_end||D===y.block_start||D===y.block_end||D===y.inside||D===y.outside||D===y.both||D===y.all||D===y.same||D===y.column||D===y.region||D===y.page)&&(delete u.clear,(O||u.display&&u.display!=y.inline)&&(this.nodeContext.clearSide=D.toString())));let z=$n(b)&&!!(u["ua-list-item-count"]||u["--viv-marker-content"]),$=u["break-inside"];(O||$&&!Z($)&&$!==y.auto)&&this.nodeContext.breakPenalty++,b&&b!==y.inline&&Dt(b)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!O&&!b||Dt(b)||Wc(b),this.nodeContext.display=b?b.toString():"inline",this.nodeContext.floatSide=O?A.toString():null,this.nodeContext.floatReference=m||Pe.INLINE;let K=u["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=K&&!Z(K)?K:null;let J=this.isInsideNonRootMultiColumn(),Q=u["column-span"];if(this.nodeContext.columnSpan=!J&&Q&&!Z(Q)?Q:null,!this.nodeContext.inline){let j=u["break-after"];j&&!Z(j)&&!(J&&j===y.column)&&(this.nodeContext.breakAfter=j.toString(),qs[this.nodeContext.breakAfter]&&(u["break-after"]=y.column));let Tt=u["break-before"];Tt&&!Z(Tt)&&!(J&&Tt===y.column)&&(this.nodeContext.breakBefore=Tt.toString(),qs[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete u["break-before"]:u["break-before"]=y.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let _t=u.page,Ct=_t&&!Z(_t)&&_t.toString();!Ct&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||b===y.table_header_group||b===y.table_footer_group)&&(Ct=this.styler.cascade.currentPageType),!Ct||Ct.toLowerCase()==="auto"?Ct=this.nodeContext.pageType:this.nodeContext.pageType=Ct,this.styler.cascade.currentPageType!==Ct&&!(!Ct&&u.position===y.fixed)&&(this.nodeContext.fragmentIndex===1&&!En(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),Ct!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=Ct)}this.nodeContext.captionSide=u["caption-side"]&&u["caption-side"].toString()||"top";let de=u["border-collapse"];if(!de||de===B("separate")){let j=u["border-spacing"],Tt,_t;j&&(j instanceof ee?(Tt=j.values[0],_t=j.values[1]):Tt=_t=j,Tt.isNumeric()&&(this.nodeContext.inlineBorderSpacing=st(Tt,this.context)),_t.isNumeric()&&(this.nodeContext.blockBorderSpacing=st(_t,this.context)))}let re=u["footnote-policy"]||I.footnotePolicy;re&&!Z(re)&&(u["--viv-footnote-policy"]=re),this.nodeContext.footnotePolicy=re&&!Z(re)?re:null;let oe=u["x-first-pseudo"];if(oe){let j=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Tw(j,oe.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,l,h,this.context);let Oe=u["white-space"];if(Oe){let j=rd(Oe.toString());j!==null&&(this.nodeContext.whitespace=j)}let Re=u["hyphenate-character"];Re&&Re instanceof X&&(this.nodeContext.hyphenateCharacter=Re.str);let pe=u["word-break"],Ce=u["line-break"],me=u["overflow-wrap"];(pe===y.break_all||Ce===y.anywhere||me===y.break_word||me===y.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,b,F,A,v),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 he=!1,ke=null,we=[],Te=a.namespaceURI,te=a.localName,Fr=te;Te=="http://www.w3.org/1999/xhtml"?(te=="html"||te=="body"||te=="script"||te=="link"||te=="meta"?te="div":te=="vide_"?te="video":te=="audi_"?te="audio":te=="object"&&(he=!!this.customRenderer),a.hasAttribute(pl)&&a.hasAttribute("src")&&u.content instanceof ht&&(te="img")):Te=="http://www.idpf.org/2007/ops"?(te="span",Te="http://www.w3.org/1999/xhtml"):Te=="http://www.pyroxy.com/ns/shadow"?(Te="http://www.w3.org/1999/xhtml",te=this.nodeContext.inline?"span":"div"):he=!!this.customRenderer,z?t?(te="li",u["--viv-marker-content"]&&(u["list-style-type"]=y.none,u["list-style-image"]=y.none)):(b=Dt(b)?y.inline:y.block,u.display=b,te="div"):te=="body"||te=="li"?te="div":te=="q"&&(te="span"),u.behavior&&u.behavior.toString()!="none"&&this.customRenderer&&(he=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(he=!0);let rs;if(he){let j=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;rs=this.customRenderer(a,j,u)}else rs=T(null);rs.then(j=>{var Tt,_t,Ct;if(j)he&&(o=j.getAttribute("data-adapt-process-children")=="true");else if(u.display===y.none){s.finish(!1);return}else j=this.createElement(Te,te);if(!v&&M&&u["column-fill"]===y.auto){let Je=this.nodeContext.vertical?u.width:u.height;(!Je||Je===y.auto||Z(Je))&&(j.setAttribute("data-viv-saved-column-fill","auto"),u["column-fill"]=y.balance)}te!=Fr&&(j.setAttribute("data-vivliostyle-original-tag",Fr),(Fr==="html"||Fr==="body")&&(j.role="presentation")),te=="a"&&j.addEventListener("click",this.page.hrefHandler,!1),ke&&(this.applyPseudoelementStyle(this.nodeContext,"inner",ke),j.appendChild(ke)),j.localName=="iframe"&&j.namespaceURI=="http://www.w3.org/1999/xhtml"&&H0(j);let Rr=this.nodeContext.inheritedProps["image-resolution"],os=[],ss=u.width,as=u.height,df=a.getAttribute("width"),pf=a.getAttribute("height"),ls=ss===y.auto||!ss&&!df,hs=as===y.auto||!as&&!pf,Tl=a.attributes,ff=Tl.length,Lr=null,Il=null;b===y.table_cell&&((Ct=(_t=(Tt=this.nodeContext.parent)==null?void 0:Tt.viewNode)==null?void 0:_t.lastElementChild)==null?void 0:Ct.localName)==="a"&&j.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let Je=0;Je<ff;Je++){let ft=Tl[Je],gt=ft.namespaceURI,le=ft.localName,Ge=ft.nodeValue;if(gt){if(gt=="http://www.w3.org/2000/xmlns/")continue;gt=="http://www.w3.org/1999/xlink"&&le=="href"&&(Ge=this.documentURLTransformer.transformURL(this.resolveURL(Ge),this.xmldoc.url))}else{if(!ai&&le.match(/^on/)||le=="style")continue;if((le=="id"||le=="name")&&t){let Qe=this.documentURLTransformer.transformFragment(Ge,this.xmldoc.url);j.setAttribute(le,Ge),j.setAttribute("data-vivliostyle-id",Qe);let Ci=j.ownerDocument.createElement("a");Ci.setAttribute(le,Qe),Ci.setAttribute(kn,"1"),Ci.style.position="absolute",j.appendChild(Ci),this.page.registerElementWithId(j,Qe);continue}if(le=="src"||le=="href"||le=="poster")Ge=this.resolveURL(Ge),le==="href"&&(Ge=this.documentURLTransformer.transformURL(Ge,this.xmldoc.url));else if(le=="srcset")Ge=Ge.split(",").map(Qe=>this.resolveURL(Qe.trim())).join(",");else if(le==="data"&&he&&te==="object"&&j.hasAttribute("data"))continue;if(le==="poster"&&te==="video"&&Te==="http://www.w3.org/1999/xhtml"&&ls&&hs){let Qe=new Image,Ci=Wt(Qe,Ge);we.push(Ci),os.push({image:Qe,element:j,fetcher:Ci})}}if(Te=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(le)&&(le=le.toLowerCase()),this.isSVGUrlAttribute(le)&&(Ge=V0(Ge,this.xmldoc.url,this.documentURLTransformer)),gt){let Qe=U0[gt];Qe&&(le=`${Qe}:${le}`)}if(le=="src"&&!gt&&(te=="img"||te=="input")&&Te=="http://www.w3.org/1999/xhtml")Lr=Ge;else if(le=="alt"&&!gt&&te=="img"&&Te=="http://www.w3.org/1999/xhtml")Il=Ge;else if(le=="href"&&te=="image"&&Te=="http://www.w3.org/2000/svg"&&gt=="http://www.w3.org/1999/xlink")this.page.fetchers.push(Wt(j,Ge));else if(gt)j.setAttributeNS(gt,le,Ge);else try{j.setAttribute(le,Ge)}catch(Qe){G.warn(Qe)}}if(Lr){let Je=te==="input"?new Image:j,ft=Wt(Je,Lr,Il);Je!==j&&(j.src=Lr);let gt=()=>{var le,Ge;if(u.position===y.fixed)return!0;for(let Qe=(le=this.nodeContext.parent)==null?void 0:le.viewNode;Qe&&Qe!==this.viewRoot;Qe=Qe.parentElement)if(((Ge=Qe.style)==null?void 0:Ge.position)==="fixed")return!0;return!1};!ls&&!hs&&!(()=>{let le=this.nodeContext.vertical?ss:as;return le instanceof R&&le.unit==="%"})()&&!gt()?this.page.fetchers.push(ft):(ls&&hs&&Rr&&Rr!==1&&os.push({image:Je,element:j,fetcher:ft}),we.push(ft))}delete u.content;let Or=u["--viv-marker-content"];if(Or){let Je=Or instanceof ee?Or.values:[Or];for(let ft of Je)ft instanceof ht&&ft.url&&we.push(Wt(new Image,ft.url))}if(this.preprocessElementStyle(u),this.applyComputedStyles(j,u),this.nodeContext.inline)t||(mt(j,"inline-start"),dn(j)&&mt(j,"clone"));else if(t){if(!Yo(u.position)){let Je=u["margin-break"],ft=this.getBreakTypeAt(this.nodeContext),gt=ft!==null,le=ft==="auto";(Je===y.discard&&gt||Je!==y.keep&&le&&!this.nodeContext.floatSide)&&ms(j,"block-start")}}else{let Je=this.nodeContext.vertical?"width":"height";pi(j,Je)&&N(j,Je,this.nodeContext.display==="table-row"?"0.01px":""),mt(j,"block-start"),dn(j)&&mt(j,"clone"),ms(j,"block-start")}z&&u["ua-list-item-count"]&&j.setAttribute("value",u["ua-list-item-count"].stringValue()),this.viewNode=j,we.length?Cn(we).then(()=>{Rr>0&&this.modifyElemDimensionWithImageResolution(os,Rr,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&&(Ve(r,n.parent.whitespace)||ci(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&&Jo(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(Xe(h.breakBefore))return h.breakBefore;if(h.fragmentIndex===1&&!h.parent)return h.sourceNode===h.sourceNode.ownerDocument.documentElement?"page":null;if((i=h.parent)!=null&&i.floatSide)return null;let l=(n=h.parent)==null?void 0:n.viewNode;if(l){let u=this.viewport.window.getComputedStyle(l),c=parseFloat(u.paddingBlockStart),p=parseFloat(u.borderBlockStartWidth);if(c||p)return null;let f=l?.firstChild;for(;f&&(Ve(f,h.parent.whitespace)||!h.floatSide&&ci(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 Xe(a)?a:"auto"}isInsideTable(t){for(let i=t;i&&!i.after;i=i.parent)if(i.display&&i.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(t,i,n,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 xs(t,i,n,r,this.exprContentListener);this.nodeContext.afterIfContinues=new nv(t,s)}}isSVGUrlAttribute(t){return Yn.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"]===y.border_box&&(n["border-left-style"]!==y.none&&(a+=st(n["border-left-width"],this.context)),n["border-right-style"]!==y.none&&(a+=st(n["border-right-width"],this.context)),n["border-top-style"]!==y.none&&(h+=st(n["border-top-width"],this.context)),n["border-bottom-style"]!==y.none&&(h+=st(n["border-bottom-width"],this.context))),i>1){let u=n["max-width"]||y.none,c=n["max-height"]||y.none;if(u===y.none&&c===y.none)N(l,"max-width",`${a}px`);else if(u!==y.none&&c===y.none)N(l,"width",`${a}px`);else if(u===y.none&&c!==y.none)N(l,"height",`${h}px`);else{u.isNumeric(),c.isNumeric();let p=u,f=c;p.unit!=="%"?N(l,"max-width",`${Math.min(a,st(p,this.context))}px`):f.unit!=="%"?N(l,"max-height",`${Math.min(h,st(f,this.context))}px`):r?N(l,"height",`${h}px`):N(l,"width",`${a}px`)}}else if(i<1){let u=n["min-width"]||Ae,c=n["min-height"]||Ae;u.isNumeric(),u.isNumeric();let p=u,f=c;p.num===0&&f.num===0?N(l,"min-width",`${a}px`):p.num!==0&&f.num===0?N(l,"width",`${a}px`):p.num===0&&f.num!==0?N(l,"height",`${h}px`):p.unit!=="%"?N(l,"min-width",`${Math.max(a,st(p,this.context))}px`):f.unit!=="%"?N(l,"min-height",`${Math.max(h,st(f,this.context))}px`):r?N(l,"height",`${h}px`):N(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){Ot("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 Ui&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let s=this.nodeContext.parent,a=s&&s.formattingContext;this.nodeContext.formattingContext=new Ui(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==y.none&&((i===y.auto||Z(i))&&(t.display===y.table_header_group?i=y.header:t.display===y.table_footer_group?i=y.footer:i=y.none),i&&i!==y.none)?i.toString():null}createTextNodeView(){let t=_("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=fh(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=_("preprocessTextContent"),r=Ot("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=mw(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=_("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=(c,p)=>c?.nodeType===1&&Xt(c)===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&&Ve(this.viewNode))&&!u.hasChildNodes()&&ed(u).includes("block-start")&&mt(u,"text-start"),u.appendChild(this.viewNode),nw(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 on(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 on(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 on(n,t,i));if(t.sourceNode.nodeType!=1){let r=fh(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 Xt(o)==="footnote-call"&&o.getAttribute(Yn.FOOTNOTE_CALL_OWNER_ATTR)===i.toString()?o:null}return null}return null}isSemanticFootnoteElement(t){let i=t.sourceNode;return i instanceof Element&&yt(i)}insertFootnoteCall(t){var i,n;let r=_("insertFootnoteCall"),o=Gn.createElementNS("http://www.w3.org/1999/xhtml","span");nr(o,"footnote-call");let s=this.xmldoc.getElementOffset(t.sourceNode);o.setAttribute(Yn.FOOTNOTE_CALL_OWNER_ATTR,s.toString());let a=new on(o,t.parent,t.boxOffset);a.inline=!0;let h=new xs(t.sourceNode,this.styler.getStyle(t.sourceNode,!1),this.styler,this.context,this.exprContentListener);return a.shadowContext=new Zr(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=_("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){if(t instanceof it){let i=t.values;for(let n=0;n<i.length;n++)this.addImageFetchers(i[n])}else if(t instanceof ht){let i=t.url;this.page.fetchers.push(Wt(new Image,i))}}applyComputedStyles(t,i){var n,r,o;let s=i["background-image"];s&&this.addImageFetchers(s);let a=i.position===y.relative,h=((n=this.nodeContext)==null?void 0:n.parent)===null&&((r=this.sourceNode)==null?void 0:r.parentElement)===null&&!!((o=this.viewRoot)!=null&&o.parentElement),l=Object.keys(i);l.sort($l);let u,c;for(let p of l){if(W0[p])continue;let f=i[p];if(!(!f||f===Y&&!Zt(p))){if(f=f.visit(new Bg(this.xmldoc.url,this.documentURLTransformer)),f instanceof R)if(f.unit==="em"){let g=this.getEmUnitSize(p,u);g!=null&&(f=new R(f.num*g,"px"))}else if(f.unit==="lh"){let g=this.getLineHeightUnitSize(p,u,c);g!=null&&(f=new R(f.num*g,"px"))}else Lu(f.unit)&&(f=Ku(f,this.context));if((p==="font-size"||p==="line-height")&&(p==="font-size"?u=f:c=f,this.viewport.layoutUnitAdj&&f instanceof R&&f.unit!=="%"&&f.unit!=="em"&&f.unit!=="lh"&&(f=new Ki(`calc(${f.toString()} - var(--viv-layoutUnitAdj))`))),vw[p]||a&&bw[p]){this.page.delayedItems.push(new el(t,p,f));continue}h&&this.page.pageAreaElement&&fn(p)?(N(this.page.pageAreaElement.parentElement.parentElement,p,f.toString()),p!=="writing-mode"&&p!=="direction"&&N(this.viewport.layoutBox,p,f.toString())):N(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}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 xt||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 c=this.context.queryUnitSize(n.unit,!1);if(c!=null)return n.num*c}return null}if(u==null)for(let c=(o=(r=this.nodeContext)==null?void 0:r.parent)==null?void 0:o.viewNode;c&&c.nodeType===1;c=c.parentNode){let p=(s=c?.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 c=h.fontSize;if(i instanceof R){let p=oa(i,c,this.context).num;return typeof p!="number"||isNaN(p)?null:u*p}else return c==null?null:u*c}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=oa(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=pt(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;St(h)&&(h.visit(new ur(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=_("peelOff"),r=t.firstPseudo,o=t.offsetInNode,s=t.after;if(i>0){let c=t.viewNode.textContent;t.viewNode.textContent=c.substr(0,i),o+=i}else if(!s&&t.viewNode&&o==0){let c=t.viewNode.parentNode;c&&c.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 on(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 c=this.setCurrent(t,!1);if(c.isPending())return c}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=pt(this.cascadedPageStyle,Uo);p&&p.area&&(a=p.area)}let h=pt(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,c=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=!!ge(f,"display"),m={},w=this.createElement("http://www.w3.org/1999/xhtml","span");nr(w,"before"),n.appendChild(w),this.computeStyle(t,i,f,m),g||(m.display=y.block);let x=ge(f,"content");if(x){let v=((r=this.sourceNode)==null?void 0:r.nodeType)===1?this.sourceNode:this.xmldoc.root;m.content=x.filterValue(new cr(this.styler.cascade,v,this.styler.cascade.counterResolver,"before")).evaluate(this.context,"content")}let b=m.content;if(St(b)){b.visit(new ur(w,this.context,b,this.exprContentListener));let v=w.querySelectorAll("img[src]");for(let S=0;S<v.length;S++){let F=v[S],A=F.getAttribute("src");if(!A)continue;let D=Wt(F,A);s.push(D),this.page.fetchers.push(D)}let C=w.getAttribute("src");if(C){let S=w.querySelector("img");S||(S=this.document.createElement("img"),S.setAttribute("src",C),w.appendChild(S));let F=Wt(S,C);s.push(F),this.page.fetchers.push(F)}}delete m.content,this.applyComputedStyles(w,m)}}finally{this.computedStyleParentFontSizeOverride=u,this.computedStyleParentLineHeightOverride=c}return s.length?Cn(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=ge(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();s=l&&!Dt(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(mt(l,"inline-end"),dn(l)){let u=h.vertical?l.offsetWidth:l.offsetHeight;mt(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>u&&this.fixClonedBoxDecorationOverflow(l)}}else{let u=this.nodeContext.vertical?"width":"height";if(pi(l,u)&&N(l,u,""),mt(l,"block-end"),!a++&&h!==o){let{textAlign:c}=this.viewport.window.getComputedStyle(l);if(c==="justify"&&!s){let p=this.createChildAnonymousBlockIfNeeded(l);p?p!==l?td(p,["block-start","text-start","block-end","text-end","justify"]):(mt(l,"text-end"),mt(l,"justify")):mt(l,"text-end")}else mt(l,"text-end")}dn(l)&&mt(l,"clone"),ms(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"||Bi[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&&Ve(l.nextSibling))){let u=i(l);if(u||u===null)return u}for(let u=l?.previousElementSibling;u;u=u.previousElementSibling){let c=i(u);if(c||c===null)return null}return!1}if(s==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||o.hasAttribute(kn)){let l=o.previousElementSibling;return l&&(l.nextSibling===o||l.nextSibling===o.previousSibling&&Ve(l.nextSibling))?i(l):!1}return!(!s||Dt(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&&Ve(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(Qf(o)){let s=i;for(;s&&s.nodeType!==1;)s=s.parentNode;let a=parseFloat(n.getElementComputedStyle(s)["font-size"]);return this.context,ll(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&&Xt(n)===Xt(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!!Xt(t)}};d(Fa,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),d(Fa,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var $0=Fa,W0={"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},G0=class{constructor(e){d(this,"layoutBox"),d(this,"window"),d(this,"pixelRatio"),d(this,"scaleRatio"),d(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}},Ho=class{constructor(e,t,i,n,r,o){if(this.window=e,this.fontSize=t,this.pixelRatio=i,d(this,"document"),d(this,"root"),d(this,"outerZoomBox"),d(this,"contentContainer"),d(this,"layoutBox"),d(this,"width"),d(this,"height"),d(this,"scaleRatio",1),d(this,"layoutUnitPerPixel",64),d(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")&&(N(this.root,"--viv-outputPixelRatio",`${i}`),N(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio),Da){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&&N(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(){N(this.outerZoomBox,"width",""),N(this.outerZoomBox,"height",""),N(this.contentContainer,"width",""),N(this.contentContainer,"height",""),N(this.contentContainer,"transform","")}zoom(e,t,i){N(this.root,"--viv-outputScale",`${i}`),N(this.outerZoomBox,"width",`${e*i}px`),N(this.outerZoomBox,"height",`${t*i}px`),N(this.contentContainer,"width",`${e}px`),N(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}},ef=class{constructor(e,t,i){this.store=e,this.url=t,this.document=i,d(this,"lang",null),d(this,"totalOffset",-1),d(this,"root"),d(this,"body"),d(this,"head"),d(this,"last"),d(this,"lastOffset",1),d(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(jt,"0")}doc(){return new nf([this.document])}getElementOffset(e){let t=e.getAttribute(jt);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(jt,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=oi(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}},Ra=(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))(Ra||{});function Wr(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 j0(e){let t=e.contentType;if(t){let n=Object.keys(Ra);for(let r=0;r<n.length;r++)if(Ra[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 tf(e,t){let i=e.responseXML;if(!i){let r=new DOMParser,o=e.responseText;if(o!=null){let s=j0(e);if(i=Wr(o,s||"application/xml",r),i&&!s){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Wr(o,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Wr(o,"image/svg+xml",r))}i||(i=Wr(o,"text/html",r))}}let n=i?new ef(t,e.url,i):null;return T(n)}function X0(){return new qa(tf,"document")}var q0=class La{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new La(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new La(n=>{if(!this.check(n))return!1;let r=new nf([n]);return r=r.child(t),i&&(r=r.predicate(i)),r.size()>0})}},tu=new q0(e=>!0),nf=class Oa{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 Oa(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 Oa(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)}},Y0=new Er(()=>{let e=_("uaStylesheetBase"),t=Mp(),i=Ne("user-agent-base.css",mi),n=new dr(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),Vy(n.cascade),Za(Fc,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function Z0(){return Y0.get()}var K0=class extends Qr{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)||G.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},J0=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,d(this,"fontDeobfuscator"),d(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(c){c=c;let p=this,f=p.currentLayoutPosition,g=f.firstFlowChunkOfFlow(c);return p.matchPageSide(f.startSideOfFlow(c))&&f.hasContent(c,p.lookupOffset)&&!!g&&!p.flowChunkIsAfterParentFlowForcedBreak(g)}),this.pageScope.defineName("page-number",new Fe(this.pageScope,function(){let c=this;return c.pageNumberOffset+c.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new Fe(this.pageScope,function(){let c=this.currentLayoutPosition;return c?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let r=new Ls(this.rootScope,e,t,i),o=ly(r,this.viewportProps),s=o.width,a=o.height,h=o["text-zoom"],l=1;if(s&&a||h){let u=zt.em;if((h?h.evaluate(r,"text-zoom"):null)===y.scale&&(l=u/i,i=u,e*=l,t*=l),s&&a){let c=st(s.evaluate(r,"width"),r),p=st(a.evaluate(r,"height"),r);if(c>0&&p>0)return{width:n&&n.spreadView?(c+n.pageBorder)*2:c,height:p,fontSize:i}}}}return{width:e,height:t,fontSize:i}}};function iu(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 nu(e){for(let[t,i]of e)i!==void 0&&t.restoreState(i)}var Pl=class extends Ls{constructor(e,t,i,n,r,o,s,a,h,l,u,c,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=c,d(this,"lang"),d(this,"primaryFlows",{body:!0}),d(this,"rootPageBoxInstance",null),d(this,"styler",null),d(this,"stylerMap",null),d(this,"currentLayoutPosition",null),d(this,"layoutPositionAtPageStart",null),d(this,"currentCascadedPageStyle",null),d(this,"lookupOffset",0),d(this,"faces"),d(this,"pageBoxInstances",{}),d(this,"pageManager",null),d(this,"rootPageFloatLayoutContext"),d(this,"pageBreaks",{}),d(this,"pageProgression",null),d(this,"isVersoFirstPage",!1),d(this,"blankPageAtStart",!1),d(this,"pageSheetSize",{}),d(this,"pageSheetHeight",0),d(this,"pageSheetWidth",0),d(this,"semanticFootnoteFirstRefOffsets",new Map),d(this,"semanticFootnoteFirstRefOffsetsInitialized",{value:!1}),d(this,"pageGroupPageCounts",Object.create(null)),d(this,"currentPageGroupDocument",null),this.lang=t.lang||i,this.faces=new Jb(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new sn(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=ge(m,"flow-consume");w&&(w.evaluate(this,"flow-consume")==y.all?this.primaryFlows[g]=!0:delete this.primaryFlows[g])}}init(){let e=_("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 Uh(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=jp(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new r0(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 x0(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=Kb(h.properties,this),u=new _p(l);s.push(u)}this.fontMapper.findOrLoadFonts(s,this.faces).then(()=>{D0(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=Jh(Vo(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 Ls(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 Uh(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 Aw,i.flowPositions[e.flowName]=n);let r=Nw(e.element),o=new Si(r),s=new Iw(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=Nr(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 rf{errorMsg(...s){}}let i=new t(null),n=gc(e),r=new Vt(n+"{}",i);return new Pr(_e,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 Xe(e)&&e!=="column"&&e!=="region"}hasForcedPageBreakBefore(e){let t=ge(e,"break-before");if(!t)return!1;let i=t.evaluate(this,"break-before").toString();return this.isForcedPageBreakValue(i)}getExplicitPageType(e){let t=ge(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=En(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 c=h;for(;c;){let p=this.getPageGroupPageType(c);if(p){let f=this.pageGroupPageCounts[p]||(this.pageGroupPageCounts[p]=new Map),g=f.get(c)||0;(g>0||s&&(u||this.shouldStartPageGroup(c,p,a)))&&(g+=1,f.set(c,g),(t.pageTypePageIndices[p]||(t.pageTypePageIndices[p]=[])).push(g))}if(c===this.xmldoc.root)break;c=c.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(!Ve(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)===y.none)return!1;let r=(t=n?.position)==null?void 0:t.evaluate(this.styler.context,"position"),o=r&&!Z(r)?r:y.static;if(So(o)||Yo(o))return!1;let s=(i=n?.float)==null?void 0:i.evaluate(this.styler.context,"float");return(s&&!Z(s)?s:y.none)===y.none}isInlineLevelElement(e){return Dt(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:y.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){G.debug("Location - page",this.currentLayoutPosition.page),G.debug(" current:",e),G.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)G.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new qe(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=ph(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===kl)continue;let s=1;r.pageBox.pseudoName===bl&&!(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)),c=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,u),this.styler.cascade.currentPageType=c,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let p=r.getProp(this,"enabled");if(!p||p===y._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=oi(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 rl(null)),e.flowRootFormattingContext=i.formattingContext}beginIsolatedRootPageFloatLayoutContext(){let e=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=new sn(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!==Pe.PAGE)return!1;let c=((u=(l=this.layoutPositionAtPageStart)==null?void 0:l.flowPositions)==null?void 0:u.body)||null,p=c?this.getConsumedOffset(c):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=_("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 c=new Pn().findByFloat(u),p=c.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,c,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 Si(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=_("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,c=!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=ph(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,c?c=!1:a.continueLoop()}),c){c=!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 c=u.floatFragments.filter(p=>"isFootnote"in p.area&&p.area.isFootnote);if(c.length>0&&!u.ignoreFootnoteAreaMaxHeight&&c.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 c){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 lv([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,r,o,s,a,h,l,u,c,p,f){let g=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,m=r.element,w=new sn(a,Pe.COLUMN,null,s,null,null,null),x=this.currentLayoutPosition.clone(),b=_("createAndLayoutColumn"),v;return b.loopWithFrame(C=>{let S=this.createLayoutConstraint(w);if(h>1){let F=this.viewport.document.createElement("div");if(N(F,"position","absolute"),m.appendChild(F),v=new Oo(F,p,this.clientLayout,S,w),v.isNonFirstColumn=o>0,v.forceNonfitting=f,v.vertical=r.vertical,v.rtl=r.rtl,v.snapHeight=r.snapHeight,v.snapWidth=r.snapWidth,r.vertical){let A=(r.rtl?h-o-1:o)*(u+l)+r.paddingTop,D=parseFloat(m.style.width);v.setHorizontalPosition(r.paddingLeft+D-r.width,r.width),v.setVerticalPosition(A,u)}else{let A=(r.rtl?h-o-1:o)*(u+l)+r.paddingLeft;v.setVerticalPosition(r.paddingTop,r.height),v.setHorizontalPosition(A,u)}v.originX=t,v.originY=i}else v=new Oo(m,p,this.clientLayout,S,w),v.isNonFirstColumn=!1,v.copyFrom(r);v.exclusions=g?[]:n.concat(),v.innerShape=c,w.setContainer(v),(v.vertical?v.height:v.width)>=0?this.layoutColumn(v,s).then(()=>{w.isInvalidated()||w.finish(),v.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(v.pageFloatLayoutContext.validate(),this.currentLayoutPosition=x.clone(),v.element!==m&&m.removeChild(v.element),C.continueLoop()):C.breakLoop()}):(w.finish(),C.breakLoop())}).then(()=>{b.finish(v)}),b.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof Yp||t instanceof xl&&!(t instanceof xn))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof In;let r=t.getProp(this,"writing-mode")||null,o=t.getProp(this,"direction")||null;return new sn(e,Pe.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),c=!0,p=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,r,o,u,s,a,h,c).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")||y.balance,m=this.currentLayoutPosition.flowPositions[a],w=Zv(h,g,p,u,s,f.columns,m);return w?(c=!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 c=_("layoutFlowColumns"),p=this.currentLayoutPosition.clone(),f=iu(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"),b=cc(x,0,0,a.width,a.height,this),v=new $0(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),C=0,S=null,F=[];return c.loopWithFrame(A=>{this.createAndLayoutColumn(t,i,n,r,a,C++,h,s,l,g,m,b,v,u).then(D=>{if(o.isInvalidated()){F=null,A.breakLoop();return}if((D.pageBreakType&&D.pageBreakType!=="column"||C===l)&&!s.isInvalidated()&&s.finish(),s.isInvalidated()){C=0,this.currentLayoutPosition=p.clone(),nu(f),s.validate(),s.isLocked()?(F=null,A.breakLoop()):A.continueLoop();return}S=D,F[C-1]=S,S.pageBreakType&&S.pageBreakType!="column"&&(C=l,S.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),C<l?A.continueLoop():A.breakLoop()})}).then(()=>{c.finish(F)}),c.result()}layoutContainer(e,t,i,n,r,o,s){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==y._true)return T(!0);let h=_("layoutContainer"),l=t.getProp(this,"wrap-flow")===y.auto,u=t.getProp(this,"flow-from"),c=this.viewport.document.createElement("div");c.role=t instanceof Zp?"complementary":"presentation";let p=t.getProp(this,"position");N(c,"position",p?p.name:"absolute");let f=t instanceof xn;t instanceof In?i.appendChild(c):i.insertBefore(c,i.firstChild);let g=new dd(c);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 xn&&(g.width<=0||g.height<=0)&&G.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=[],b=t.getProp(this,"content");if(b instanceof W&&b.expr instanceof Fe&&b.expr.str.startsWith("running-element-"))b.visit(new ur(c,this,b,this.counterStore.getExprContentListener()));else if(St(b)){let v="span";b instanceof ht&&(v="img");let C=this.viewport.document.createElement(v);b.visit(new ur(C,this,b,this.counterStore.getExprContentListener())),c.appendChild(C),v=="img"&&t.transferSingleUriContentProps(this,C,this.faces),t.transferContentProps(this,g,e,this.faces);let S=C.querySelectorAll("img[src]");for(let A=0;A<S.length;A++){let D=S[A],H=D.getAttribute("src");if(!H)continue;let q=Wt(D,H);x.push(q),e.fetchers.push(q)}let F=C.getAttribute("src");if(F){let A=C.querySelector("img");A||(A=C);let D=Wt(A,F);x.push(D),e.fetchers.push(D)}v=="span"&&ev(C,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(c),w=!0);w||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=x.length?Cn(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=_("layoutContainer.inner"),b=u.toString(),v=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,r,o,s,g,b,v).then(C=>{if(!s.isInvalidated()){let S=C[0];S.element===c&&(g=S),g.computedBlockSize=Math.max.apply(null,C.map(A=>A.computedBlockSize)),t.finishContainer(this,g,e,S,v,this.clientLayout,this.faces);let F=this.currentLayoutPosition.flowPositions[b];F&&F.breakAfter==="region"&&(F.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 b=t.getProp(this,"shape-outside"),v=g.getOuterShape(b,this);o.push(v)}}else if(t.children.length==0){i.removeChild(c),h.finish(!0);return}let x=f?0:t.children.length-1;h.loop(()=>{for(;x>=0&&x<t.children.length;){let b=t.children[f?x++:x--],v=this.layoutContainer(e,b,c,n,r,o,s);if(v.isPending())return v.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 Fw,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=En(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=iu(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 qe(this.style.pageScope,"left-page");e.side=x.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let c=this.selectPageMaster(u);if(!c)return T(null);let p=0;if(!s){e.setAutoPageWidth(c.pageBox.specified.width.value===xr),e.setAutoPageHeight(c.pageBox.specified.height.value===Sr);let{counterOffset:x,changeOffset:b}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(x)||(x=this.lookupOffset,b=this.lookupOffset),isFinite(x)&&this.styler.styleUntil(x,0);let v=this.styler.getCounterSnapshotAtOffset(x),C=b===x?v:this.styler.getCounterSnapshotAtOffset(b);v||(v=this.styler.getLastCounterSnapshot()),C||(C=v),this.counterStore.setCurrentPageDocCounters((r=v?.counters)!=null?r:null,(o=C?.changes)!=null?o:null,C?.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(u,this);let S=Jh(Vo(u),this);this.setPageSizeAndBleed(S,e),f0(u,S,e,this),p=S.bleedOffset+S.bleed}let f=!s&&c.getProp(this,"writing-mode")||y.horizontal_tb;this.pageVertical=f!=y.horizontal_tb;let g=c.getProp(this,"direction")||y.ltr,m=new sn(this.rootPageFloatLayoutContext,Pe.PAGE,null,null,null,f,g),w=_("layoutNextPage");return w.loopWithFrame(x=>{this.layoutContainer(e,c,e.bleedBox,p,p,[],m).then(()=>{if(m.isInvalidated()||m.finish(),m.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),nu(l),m.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);x.continueLoop()}else x.breakLoop()})}).then(()=>{c.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(b=>{let v=t.flowPositions[b],C=v.breakAfter;C&&(C==="page"||!this.matchPageSide(C))&&(v.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`}},Q0=class Ba extends dr{constructor(t,i,n,r){super(t.rootScope,t,i,n,r,t.validatorSet,!n),this.masterHandler=t,d(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let r=new Dp(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new a0(r.scope,this.masterHandler,r,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=Rt(this.scope,this.condition,i)),this.masterHandler.pushHandler(new Ba(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new jy(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new Qr(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new K0(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 Qr(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new Qr(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=Kt(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new Kp(this.scope,this.owner,this.masterHandler.validatorSet,i))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new L0(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(dr.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 Ba(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},rf=class extends Ws{constructor(e){super(),this.validatorSet=e,d(this,"rootScope"),d(this,"pageScope"),d(this,"rootBox"),d(this,"cascadeParserHandler"),d(this,"regionCount",0),d(this,"fontFaces",[]),d(this,"counterStyles",new Fb),d(this,"footnoteProps",{}),d(this,"flowProps",{}),d(this,"viewportProps",[]),d(this,"pageProps",{}),this.rootScope=new Rs(null),this.pageScope=new Rs(this.rootScope),this.rootBox=new t0(this.rootScope),this.cascadeParserHandler=new Q0(this,null,null,null),this.slave=this.cascadeParserHandler}};function ex(e,t){return t.parseOPSResource(e)}var tx=class extends qa{constructor(e){super(ex,"document"),this.fontDeobfuscator=e,d(this,"styleByKey",{}),d(this,"styleFetcherByKey",{}),d(this,"styleByDocURL",{}),d(this,"triggersByDocURL",{}),d(this,"validatorSet",null),d(this,"styleSheets",[]),d(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=_("OPSDocStore.init");return this.validatorSet=Mp(),Z0().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=Ne(mn(t),zi)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ne(mn(t),zi)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=_("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return tf(e,this).then(r=>{var o;if(!r){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=Ot("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](r.document)}catch(g){G.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:Ne("user-agent-page.css",mi),text:Ac,flavor:"UA",classes:null,media:null}),h.push({url:Ne("user-agent-counter-styles.css",mi),text:Oc,flavor:"UA",classes:null,media:null}),n)h.push({url:Ne("user-agent-toc.css",mi),text:Rc,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"),b=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:b?w:null,media:x})}else if(m=="link"){let w=f.getAttribute("href"),x=(o=f.getAttribute("rel"))==null?void 0:o.split(/\s+/),b=f.getAttribute("class"),v=f.getAttribute("media");if(w&&x!=null&&x.includes("stylesheet")&&(!x.includes("alternate")||b)){let C=Ne(w,i),S=f.getAttribute("title");h.push({url:C,text:null,classes:S?b:null,media:v,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 c=this.styleFetcherByKey[l];c||(c=new Er(()=>{let p=_("fetchStylesheet"),f=0,g=new rf(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):Uc(m.url,g,m.classes,m.media)}return T(!1)}).then(()=>{let m=g.cascadeParserHandler.finish();u=new J0(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]=c,c.start()),c.get().then(p=>{this.styleByDocURL[i]=p,t.finish(r)})}),t.result()}processViewportMeta(e){return""}},ar="\u25B8",ru="\u25BE",ix="\u25B9";function Nl(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 nx(e){let t=Nl(e),i=[];for(let n of t)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var rx=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,d(this,"pref"),d(this,"page",null),d(this,"instance",null),this.pref=Iu(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;pi(n,"height","auto")!="auto"&&(N(n,"height","auto"),this.setAutoHeight(n,t)),pi(n,"position","static")=="absolute"&&(N(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=y.inherit,r["text-decoration"]=y.none;break;case"toc-node":r.display=y.block,r.margin=Ae,r.padding=Ae,r["padding-inline-start"]=new R(1.25,"em");break;case"toc-node-first-child":r.display=y.inline_block,r.margin=new R(.2,"em"),r["vertical-align"]=y.top,r.color=y.inherit,r["text-decoration"]=y.none;break;case"toc-container":r.padding=Ae;break}if(!o||o.toString()!="toc-node"&&o.toString()!="toc-container")return t(i,n,r);let s=i.firstChild;s&&s.nodeType!==1&&Ve(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!=ar&&(l.textContent=ar,N(l,"cursor","pointer"),l.addEventListener("click",ox,!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=ix,N(l,"margin","0.2em 0 0 -1em"),N(l,"margin-inline-start","-1em"),N(l,"margin-inline-end","0"),N(l,"display","inline-block"),N(l,"width","1em"),N(l,"text-align","center"),N(l,"vertical-align","top"),N(l,"cursor","default"),N(l,"font-family","Menlo,sans-serif"),h.appendChild(l),N(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){N(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=_("showTOC"),s=new nd(e,e);this.page=s;let a=qt(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of Nl(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),u=l.sizeViewport(i,1e5,r);t=new Ho(t.window,u.fontSize,0,e,u.width,u.height);let c=this.makeCustomRenderer(h),p=new Pl(l,h,this.lang,t,this.clientLayout,this.fontMapper,c,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 ox(e){let t=e.target,i=t.textContent==ar;t.textContent=i?ru:ar;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==ru){a.textContent=ar,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 Gr(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function sx(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=new Map(e[i])}),t}var ou=class extends tx{constructor(){super(null),d(this,"plainXMLStore"),d(this,"jsonStore"),d(this,"opfByURL",{}),d(this,"primaryOPFByEPubURL",{}),d(this,"deobfuscators",{}),d(this,"documents",{}),this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=X0(),this.jsonStore=zm()}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 go(this,e);n.initWithWebPubManifest(i,void 0,e).then(()=>{t.finish(n)})})}loadPubDoc(e){let t=_("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)}):qo(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}G.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=_("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=_("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(o=>{o?(n=new go(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=_("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 go(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=za(n.getElementById(s.substr(1)).textContent);r.initWithWebPubManifest(a,n).then(()=>{t.finish(r)})}else{let a=Ne(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&&Nl(n).length===0&&(r.toc=null),t.finish(r)})}}),t.result()}addDocument(e,t){let i=_("EPUBDocStore.load"),n=qt(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(zi)||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:")?G.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&zi.startsWith("https:")&&!/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(?:[/?#]|$)/.test(e)?G.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?G.error(`Failed to load ${e}. This may be caused by network error, incorrect URL, or the server not allowing cross-origin resource sharing (CORS).`):G.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=qt(e),i=this.documents[t];if(i)return i.isPending()?i:T(i.get());{let n=_("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""}},su=class{constructor(){d(this,"id",null),d(this,"src",""),d(this,"mediaType",null),d(this,"title",null),d(this,"itemRefElement",null),d(this,"spineIndex",-1),d(this,"compressedSize",0),d(this,"compressed",null),d(this,"epage",0),d(this,"epageCount",0),d(this,"startPage",null),d(this,"skipPagesBefore",null),d(this,"itemProperties"),this.itemProperties=Vf}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Ne(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=Xf(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 ax(e){return e.id}function lx(e){return t=>{let i=_("deobfuscator");return hx("SHA-1",e).then(n=>{let r=t.slice(0,1040),o=t.slice(1040,t.size);Mm(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(Bc([a,o]))})}),i.result()}}function hx(e,t){let i=_("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(r=>{n.schedule(new Uint8Array(r))}),i.result()}var gi={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"},Zn="http://idpf.org/epub/vocab/package/meta/#",$e={language:`${gi.dcterms}language`,title:`${gi.dcterms}title`,creator:`${gi.dcterms}creator`,layout:`${gi.rendition}layout`,titleType:`${Zn}title-type`,displaySeq:`${Zn}display-seq`,alternateScript:`${Zn}alternate-script`,role:`${Zn}role`};function ux(e,t){let i={};return(n,r)=>{var o,s,a,h,l,u;let c,p,f=n.r||i,g=r.r||i;if(e==$e.title&&(c=((o=f[$e.titleType])==null?void 0:o[0].v)=="main",p=((s=g[$e.titleType])==null?void 0:s[0].v)=="main",c!=p))return c?-1:1;let m=parseInt((a=f[$e.displaySeq])==null?void 0:a[0].v,10);isNaN(m)&&(m=Number.MAX_VALUE);let w=parseInt((h=g[$e.displaySeq])==null?void 0:h[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),m!=w?m-w:e!=$e.language&&t&&(c=((l=f[$e.language]||f[$e.alternateScript])==null?void 0:l[0].v)==t,p=((u=g[$e.language]||g[$e.alternateScript])==null?void 0:u[0].v)==t,c!=p)?c?-1:1:n.o-r.o}}function cx(e,t){let i;if(!t)i=gi;else{i={};for(let p in gi)i[p]=gi[p];let c;for(;(c=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(c[0].length),i[c[1]]=c[2]}let n=c=>{if(c){let p=c.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(p){let f=p[2]?i[p[2]]:Zn;if(f)return f+p[3]}}return null},r=1,o=e.childElements().forEachNonNull(c=>{if(c.localName=="meta"){let p=n(c.getAttribute("property"));if(p)return{name:p,value:c.textContent,id:c.getAttribute("id"),order:r++,refines:c.getAttribute("refines"),lang:null,scheme:n(c.getAttribute("scheme")),role:null}}else if(c.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:gi.dcterms+c.localName,order:r++,lang:c.getAttribute("xml:lang"),value:c.textContent,id:c.getAttribute("id"),refines:null,scheme:null,role:c.getAttribute("role")||c.getAttribute("opf:role")};return null}),s=cs(o,c=>c.refines),a=c=>qf(c,(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:$e.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&w.push({name:$e.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let x=cs(w,b=>b.name);m.r=a(x)}return m})),h=a(cs(o,c=>c.refines?null:c.name)),l=null;h[$e.language]&&(l=h[$e.language][0].v);let u=c=>{for(let p in c){let f=c[p];f.sort(ux(p,l));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(h),h}function dx(){let e=window.MathJax;return e?e.Hub:null}var au={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Is="viv-id-",go=class{constructor(e,t){this.store=e,this.pubURL=t,d(this,"opfXML",null),d(this,"encXML",null),d(this,"items",null),d(this,"spine",null),d(this,"itemMap",null),d(this,"itemMapByPath",null),d(this,"uid",null),d(this,"bindings",{}),d(this,"lang",null),d(this,"epageCount",0),d(this,"prePaginated",!1),d(this,"epageIsRenderedPage",!0),d(this,"epageCountCallback",null),d(this,"metadata",{}),d(this,"toc",null),d(this,"cover",null),d(this,"fallbackMap",{}),d(this,"pageProgression",null),d(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,r){let o=r+(n?`#${n}`:"");return Is+Pu(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(Is)===0&&(n=n.substring(Is.length));let r=jf(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=Ne("",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 su,u=h;l.initWithElement(u,e.url);let c=u.getAttribute("fallback");return c&&!au[l.mediaType]&&(r[l.src]=c),!this.toc&&l.itemProperties.nav&&(this.toc=l),!this.cover&&l.itemProperties["cover-image"]&&(this.cover=l),l}),this.itemMap=_l(this.items,ax),this.itemMapByPath=_l(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(au[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,c=u.getAttribute("idref"),p=this.itemMap[c];return p&&(p.itemRefElement=u,p.spineIndex=l),p});let o=i.child("spine").attribute("page-progression-direction")[0];o&&(this.pageProgression=wu(o));let s=t?t.doc().child("encryption").child("EncryptedData").predicate(tu.withChild("EncryptionMethod",tu.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=cx(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[$e.language]&&(this.lang=this.metadata[$e.language][0].v),this.metadata[$e.layout]&&(this.prePaginated=this.metadata[$e.layout][0].v==="pre-paginated"),s.length>0&&this.uid){let h=lx(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=_("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 ef(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let r=new su;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[$e.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((o=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?o:[]).map(m=>m.content);h&&h.length!==0&&(this.metadata[$e.creator]=(Array.isArray(h)?h:[h]).map(m=>{var w;return{v:(w=m.name)!=null?w:m}}));let l=e.inLanguage||((s=e.metadata)==null?void 0:s.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[$e.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 nx(t)){let w=m.getAttribute("href");if(/^(https?:)?\/\//.test(w)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(w))continue;let x=qt(Ne(w,this.pubURL)),b=this.getPathFromURL(x),v=b!==null?encodeURI(b):x;e.readingOrder.indexOf(v)==-1&&e.readingOrder.push(v)}}let c=[],p=0,f=-1;[e.readingOrder,e.resources].forEach(m=>{m instanceof Array&&m.forEach(w=>{let x=m===e.readingOrder,b=typeof w=="string"?w:w.url||w.href,v=typeof w=="string"?"":w.encodingFormat||w.href&&w.type||"";if(x||v==="text/html"||v==="application/xhtml+xml"||!v&&w.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(b)){let C=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,S={url:Ne(mn(b),C),index:p++,startPage:null,skipPagesBefore:null};w.rel==="contents"&&f===-1&&(f=S.index),c.push(S)}})});let g=_("initWithWebPubManifest");return this.initWithChapters(c).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 x=(w=e.readingOrder)==null?void 0:w.length;x&&x<this.items.length&&this.items.splice(x),g.finish(!0)}),g.result()}getCFI(e,t){let i=this.spine[e],n=_("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 Zl;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 Sn("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Zl;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)=>{G.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return Sn("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=oi(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)=>{G.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=_("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()}},jr=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),px=class{constructor(e,t,i,n,r,o){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=r,d(this,"spineItems",[]),d(this,"spineItemLoadingContinuations",[]),d(this,"pref"),d(this,"clientLayout"),d(this,"counterStore"),d(this,"cmykStore"),d(this,"tocAutohide",!1),d(this,"tocVisible",!1),d(this,"tocView"),d(this,"paginationProgress",{totalOffsetsBySpine:[],renderedOffsetsBySpine:[],lastReportedPages:0,lastReportedFraction:0}),this.pref=Iu(n),this.clientLayout=new G0(t),this.counterStore=new Vg(e.documentURLTransformer),this.cmykStore=new nc,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=_("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=Ot("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 c={fraction:u,pages:this.paginationProgress.lastReportedPages};for(let p of i)try{p(c)}catch(f){G.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,c=s&&!u&&i>0&&h&&l;if(a=n.pageType!=null&&(c||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=Gr(n));let r=Gr(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=_("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 c=u.instance.styler.cascade,p=u.instance.pageManager.pageCascadeInstance,f={currentPageType:c.currentPageType,previousPageType:c.previousPageType},g={currentPageType:p.currentPageType,previousPageType:p.previousPageType},m=sx(u.instance.pageGroupPageCounts),w=u.instance.currentPageGroupDocument,x=u.instance.scopes;u.instance.scopes={};let b=l.pageIndex<u.pages.length-1,v=!!u.pages[l.pageIndex]&&b,C=v?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(F=>{v&&u.instance.endIsolatedRootPageFloatLayoutContext(C);let A=c.currentPageType;c.currentPageType=f.currentPageType,c.previousPageType=f.previousPageType,p.currentPageType=g.currentPageType,p.previousPageType=g.previousPageType,u.instance.pageGroupPageCounts=m,u.instance.currentPageGroupDocument=w,u.instance.scopes=x;let D=Gr(this.counterStore.currentPageCounters);this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve(),F.pageAndPosition.position.spineIndex===a.spineIndex&&F.pageAndPosition.position.pageIndex===i&&(a=F.pageAndPosition.page),a.pageType&&a.pageType!==f.currentPageType&&A!==F.pageAndPosition.page.pageType&&(c.currentPageType=a.pageType);let H=u!==e,q=u.pages.length,Se=u.layoutPositions[q],se=u.instance.hasActiveRootPageFloatLayoutContext();if(Se&&!se){let k=H?Gr(this.counterStore.currentPageCounters):null;H&&(this.counterStore.currentPageCounters=D);let M=q;this.renderSinglePage(u,Se).then(()=>{H&&this.markSpineItemCompleteIfReady(u);let E=u.pages.length-M;if(H&&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 I=this.spineItems[P];if(I){I.item.epage+=E;for(let O of I.pageCounterStarts)O!=null&&O.page&&(O.page=O.page.map(z=>z+E));this.counterStore.updatePageCounterNodesInPages(I.pages,I.pageCounterStarts)}}if(k){let P=k.page;P&&(k.page=P.map(I=>I+E))}}k&&(this.counterStore.currentPageCounters=k),h.continueLoop()});return}H&&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=_("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(c=>{i.finish({pageAndPosition:jr(c,u),nextLayoutPosition:t})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let r=oi(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=_("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(jr(r,o))})})}),i.result()}renderPage(e){let t=_("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(jr(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(jr(s,r));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||this.markSpineItemCompleteIfReady(i),t.finish(h.pageAndPosition)})})}),t.result()}renderAllPages(){let e=_("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=_("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=_("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=_("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=_("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=_("navigateToCFI");return this.opf.resolveFragment(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}resolveSemanticFootnoteNavigationOffset(e,t){if(!yt(t))return null;let i=t.getAttribute("id");if(!i)return null;let n=Ne(`#${i}`,e.xmldoc.url),r=e.xmldoc.document.getElementsByTagName("a");for(let o=0;o<r.length;o++){let s=r.item(o);if(!Lt(s))continue;let a=s.getAttribute("href")||s.getAttributeNS("http://www.w3.org/1999/xlink","href");if(a&&Ne(a,e.xmldoc.url)===n)return e.xmldoc.getElementOffset(s)}return null}navigateTo(e,t,i){G.debug("Navigate to",e);let n=this.opf.getPathFromURL(qt(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=_("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",lr||(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 nd(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=Au(this.viewport.width,this.viewport.height,i.width,i.height),a=Nr(null,new Vt(s,null),"");o.delayedItems.push(new el(n,"transform",a))}return o}makeObjectView(e,t,i,n){let r=t.getAttribute("data"),o=null;if(r){r=Ne(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=Bl(r),l=Bl(s),u=new ri;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 c=t.getAttribute("width");c&&o.setAttribute("width",c);let p=t.getAttribute("height");p&&o.setAttribute("height",p)}}}return o||(o=this.viewport.document.createElement("object"),r&&o.setAttribute("data",r),o.setAttribute("data-adapt-process-children","true")),T(o)}makeMathJaxView(e,t,i,n){let r=dx();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=_("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=Ne(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=_("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),c=this.viewport,p=l.sizeViewport(c.width,c.height,c.fontSize,this.pref);(p.width!=c.width||p.height!=c.height||p.fontSize!=c.fontSize)&&(c=new Ho(c.window,p.fontSize,c.pixelRatio,c.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 v=g&&g.pageCounterStarts[g.pages.length-1],C=v&&v.page;if(C&&C.length)w=C[C.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 x=new Pl(l,s,this.opf.lang,c,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 b=this.opf.metadata&&this.opf.metadata[$e.title];x.pubTitle=b&&b[0]&&b[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(v=>{v.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=_("showTOC");this.tocView||(this.tocView=new rx(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),lr||(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()}},lu="data-vivliostyle-viewer-status",fx="data-vivliostyle-spread-view",of=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(of||{}),gx=class{constructor(e,t,i,n){this.window=e,this.viewportElement=t,this.instanceId=i,this.callbackFn=n,d(this,"fontMapper"),d(this,"kick"),d(this,"sendCommand"),d(this,"resizeListener"),d(this,"hyperlinkListener"),d(this,"pageRuleStyleElement"),d(this,"pageSheetSizeAlreadySet",!1),d(this,"renderTask",null),d(this,"actions"),d(this,"readyState"),d(this,"packageURL"),d(this,"opf"),d(this,"touchActive"),d(this,"touchX"),d(this,"touchY"),d(this,"needResize"),d(this,"resized"),d(this,"needRefresh"),d(this,"viewportSize"),d(this,"currentPage"),d(this,"currentSpread"),d(this,"pagePosition"),d(this,"fontSize"),d(this,"zoom"),d(this,"fitToScreen"),d(this,"pageViewMode"),d(this,"waitForLoading"),d(this,"renderAllPages"),d(this,"pref"),d(this,"pageSizes"),d(this,"pixelRatio"),d(this,"pixelRatioLimit"),d(this,"viewport"),d(this,"opfView"),d(this,"cmykReserveMap"),d(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",Pc),o("vivliostyle-viewport-css",Nc),o("vivliostyle-polyfill-css",Lc),t.setAttribute("data-vivliostyle-viewer-viewport",!0),lr&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(lu,"loading"),this.fontMapper=new Qb(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=Tu(),this.pageSizes=[],this.pixelRatioLimit=Da==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=bu;G.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),G.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),G.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),G.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(lu,e);let t=this.getCurrentPageProgression();t&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",t),this.callback({t:"readystatechange"})}}loadPublication(e){vt.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=_("loadPublication");return this.configure(e).then(()=>{let s=new ou;s.init(n,r).then(()=>{let a=Ne(mn(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){vt.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=_("loadXML");return this.configure(e).then(()=>{let a=new ou;a.init(r,o).then(()=>{let h=t.map((l,u)=>({url:Ne(mn(l.url),this.window.location.href),index:u,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new go(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(()=>(vt.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=zt[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"&&(Rl(e.userAgentRootURL.replace(/resources\/?$/,"")),Ll(e.userAgentRootURL)),typeof e.rootURL=="string"&&(Rl(e.rootURL),Ll(`${zi}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!==ai&&(B0(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){Ot("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=>{N(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),N(e.container,"visibility","visible"),N(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=_("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?Cn(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 Ho(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new Ho(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(fx,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),c=l*((this.pixelRatio||1)-1)+2,p=u*((this.pixelRatio||1)-1)+2,f=`@page {size: ${l}pt ${u}pt; margin: 0 ${-c}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=Ne(mn(this.cmykReserveMapUrl),zi),i=_("loadCmykReserveMap");return e.loadAsJSON(t).then(n=>{gg(n)?this.cmykReserveMap=n:(G.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 px(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 hu),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return T(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Hs().getScheduler().run(()=>Sn("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,vt.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),vt.registerEndTiming("render (resize)"),ai&&Qp(this.window)?z0(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 hu)vt.registerEndTiming("render (resize)"),G.debug(i.message);else throw i}));return T(!0)}sendLocationNotification(e,t){let i=_("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=_("moveTo");return i.call(this.opfView).then(r=>{let o;if(r){this.pagePosition=r.position;let s=_("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=_("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 Sn("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(G.error("No such action:",t),i.finish(!0))},(i,n)=>{G.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=uu(e),i=null,n=this;Am(()=>{let r=_("commandLoop"),o=Hs().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=_("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=uu(r),n.kick(),!0),this.window.adapt_command=n.sendCommand}},sf=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(sf||{}),hu=class af extends Error{constructor(){super(),d(this,"name","RenderingCanceledError"),d(this,"message","Page rendering has been canceled"),d(this,"stack"),Object.setPrototypeOf(this,af.prototype),this.stack=new Error().stack}};function uu(e){return typeof e=="string"?za(e):e}var cu=_a;function mx(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function du(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 lf=class{constructor(e,t){this.settings=e,d(this,"initialized",!1),d(this,"adaptViewer_"),d(this,"options"),d(this,"eventTarget"),d(this,"readyState"),mu(e.debug),this.adaptViewer_=new gx(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=mx(),t&&this.setOptions(t),this.eventTarget=new Va,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},du(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:wx(e)||t,document:r.documentObject,fragment:r.fragment,authorStyleSheet:s,userStyleSheet:a,cmykReserveMapUrl:r.cmykReserveMapUrl},du(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()===cu.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===cu.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 wx(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 hf=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(hf||{}),yx=sf,vx=of;vt.forceRegisterEndTiming("load_vivliostyle");var bx=class{constructor(e,{title:t="",printCallback:i=s=>s.print(),errorCallback:n=null,hideIframe:r=!0,removeIframe:o=!0}){d(this,"htmlDoc"),d(this,"title"),d(this,"printCallback"),d(this,"errorCallback"),d(this,"hideIframe"),d(this,"removeIframe"),d(this,"iframe"),d(this,"iframeWin"),d(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=`
1800
1850
  <!DOCTYPE html>
1801
1851
  <html data-vivliostyle-paginated="true">
1802
1852
  <head>
@@ -1824,6 +1874,6 @@ span[data-viv-leader] {
1824
1874
  <body onload='parent.printInstance.runInIframe(window)'>
1825
1875
  <div id="vivliostyle-viewer-viewport"></div>
1826
1876
  </body>
1827
- </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 lp({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(`
1828
- `);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 H0(e,t){new V0(e,t).init()}});var U0=Sp(cp());var export_printHTML=U0.printHTML;export{export_printHTML as printHTML};
1877
+ </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 lf({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(`
1878
+ `);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 xx(e,t){new bx(e,t).init()}});var Sx=Sf(cf());var export_printHTML=Sx.printHTML;export{export_printHTML as printHTML};
1829
1879
  //# sourceMappingURL=index.es6.js.map