@vivliostyle/print 2.36.4 → 2.37.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.cjs.js +294 -21
- package/dist/index.cjs.js.map +4 -4
- package/dist/index.es6.js +294 -21
- package/dist/index.es6.js.map +4 -4
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var Nc=Object.create;var Rn=Object.defineProperty;var Tc=Object.getOwnPropertyDescriptor;var Ic=Object.getOwnPropertyNames;var Ac=Object.getPrototypeOf,Rc=Object.prototype.hasOwnProperty;var Lc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Fc=(e,t)=>{for(var i in t)Rn(e,i,{get:t[i],enumerable:!0})},_r=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ic(t))!Rc.call(e,s)&&s!==i&&Rn(e,s,{get:()=>t[s],enumerable:!(n=Tc(t,s))||n.enumerable});return e};var Oc=(e,t,i)=>(i=e!=null?Nc(Ac(e)):{},_r(t||!e||!e.__esModule?Rn(i,"default",{value:e,enumerable:!0}):i,e)),Bc=e=>_r(Rn({},"__esModule",{value:!0}),e);var Sc=Lc((Nb,xc)=>{"use strict";var _c=Object.create,bn=Object.defineProperty,Mc=Object.getOwnPropertyDescriptor,zc=Object.getOwnPropertyNames,Dc=Object.getPrototypeOf,Vc=Object.prototype.hasOwnProperty,Uc=(e,t,i)=>t in e?bn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Hc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),$c=(e,t)=>{for(var i in t)bn(e,i,{get:t[i],enumerable:!0})},cl=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of zc(t))!Vc.call(e,s)&&s!==i&&bn(e,s,{get:()=>t[s],enumerable:!(n=Mc(t,s))||n.enumerable});return e},Wc=(e,t,i)=>(i=e!=null?_c(Dc(e)):{},cl(t||!e||!e.__esModule?bn(i,"default",{value:e,enumerable:!0}):i,e)),Gc=e=>cl(bn({},"__esModule",{value:!0}),e),u=(e,t,i)=>Uc(e,typeof t!="symbol"?t+"":t,i),jc=Hc((e,t)=>{var i=-1,n=1,s=0;function o(x,O,S,N,E){if(x===O)return x?[[s,x]]:[];if(S!=null){var A=Je(x,O,S);if(A)return A}var L=l(x,O),M=x.substring(0,L);x=x.substring(L),O=O.substring(L),L=p(x,O);var U=x.substring(x.length-L);x=x.substring(0,x.length-L),O=O.substring(0,O.length-L);var j=r(x,O);return M&&j.unshift([s,M]),U&&j.push([s,U]),k(j,E),N&&f(j),j}function r(x,O){var S;if(!x)return[[n,O]];if(!O)return[[i,x]];var N=x.length>O.length?x:O,E=x.length>O.length?O:x,A=N.indexOf(E);if(A!==-1)return S=[[n,N.substring(0,A)],[s,E],[n,N.substring(A+E.length)]],x.length>O.length&&(S[0][0]=S[2][0]=i),S;if(E.length===1)return[[i,x],[n,O]];var L=d(x,O);if(L){var M=L[0],U=L[1],j=L[2],q=L[3],K=L[4],he=o(M,j),te=o(U,q);return he.concat([[s,K]],te)}return a(x,O)}function a(x,O){for(var S=x.length,N=O.length,E=Math.ceil((S+N)/2),A=E,L=2*E,M=new Array(L),U=new Array(L),j=0;j<L;j++)M[j]=-1,U[j]=-1;M[A+1]=0,U[A+1]=0;for(var q=S-N,K=q%2!==0,he=0,te=0,pe=0,ke=0,be=0;be<E;be++){for(var Q=-be+he;Q<=be-te;Q+=2){var re=A+Q,se;Q===-be||Q!==be&&M[re-1]<M[re+1]?se=M[re+1]:se=M[re-1]+1;for(var ee=se-Q;se<S&&ee<N&&x.charAt(se)===O.charAt(ee);)se++,ee++;if(M[re]=se,se>S)te+=2;else if(ee>N)he+=2;else if(K){var $=A+q-Q;if($>=0&&$<L&&U[$]!==-1){var ue=S-U[$];if(se>=ue)return h(x,O,se,ee)}}}for(var Ue=-be+pe;Ue<=be-ke;Ue+=2){var $=A+Ue,ue;Ue===-be||Ue!==be&&U[$-1]<U[$+1]?ue=U[$+1]:ue=U[$-1]+1;for(var D=ue-Ue;ue<S&&D<N&&x.charAt(S-ue-1)===O.charAt(N-D-1);)ue++,D++;if(U[$]=ue,ue>S)ke+=2;else if(D>N)pe+=2;else if(!K){var re=A+q-Ue;if(re>=0&&re<L&&M[re]!==-1){var se=M[re],ee=A+se-re;if(ue=S-ue,se>=ue)return h(x,O,se,ee)}}}}return[[i,x],[n,O]]}function h(x,O,S,N){var E=x.substring(0,S),A=O.substring(0,N),L=x.substring(S),M=O.substring(N),U=o(E,A),j=o(L,M);return U.concat(j)}function l(x,O){if(!x||!O||x.charAt(0)!==O.charAt(0))return 0;for(var S=0,N=Math.min(x.length,O.length),E=N,A=0;S<E;)x.substring(A,E)==O.substring(A,E)?(S=E,A=S):N=E,E=Math.floor((N-S)/2+S);return R(x.charCodeAt(E-1))&&E--,E}function c(x,O){var S=x.length,N=O.length;if(S==0||N==0)return 0;S>N?x=x.substring(S-N):S<N&&(O=O.substring(0,S));var E=Math.min(S,N);if(x==O)return E;for(var A=0,L=1;;){var M=x.substring(E-L),U=O.indexOf(M);if(U==-1)return A;L+=U,(U==0||x.substring(E-L)==O.substring(0,L))&&(A=L,L++)}}function p(x,O){if(!x||!O||x.slice(-1)!==O.slice(-1))return 0;for(var S=0,N=Math.min(x.length,O.length),E=N,A=0;S<E;)x.substring(x.length-E,x.length-A)==O.substring(O.length-E,O.length-A)?(S=E,A=S):N=E,E=Math.floor((N-S)/2+S);return _(x.charCodeAt(x.length-E))&&E--,E}function d(x,O){var S=x.length>O.length?x:O,N=x.length>O.length?O:x;if(S.length<4||N.length*2<S.length)return null;function E(te,pe,ke){for(var be=te.substring(ke,ke+Math.floor(te.length/4)),Q=-1,re="",se,ee,$,ue;(Q=pe.indexOf(be,Q+1))!==-1;){var Ue=l(te.substring(ke),pe.substring(Q)),D=p(te.substring(0,ke),pe.substring(0,Q));re.length<D+Ue&&(re=pe.substring(Q-D,Q)+pe.substring(Q,Q+Ue),se=te.substring(0,ke-D),ee=te.substring(ke+Ue),$=pe.substring(0,Q-D),ue=pe.substring(Q+Ue))}return re.length*2>=te.length?[se,ee,$,ue,re]:null}var A=E(S,N,Math.ceil(S.length/4)),L=E(S,N,Math.ceil(S.length/2)),M;if(!A&&!L)return null;L?A?M=A[4].length>L[4].length?A:L:M=L:M=A;var U,j,q,K;x.length>O.length?(U=M[0],j=M[1],q=M[2],K=M[3]):(q=M[0],K=M[1],U=M[2],j=M[3]);var he=M[4];return[U,j,q,K,he]}function f(x){for(var O=!1,S=[],N=0,E=null,A=0,L=0,M=0,U=0,j=0;A<x.length;)x[A][0]==s?(S[N++]=A,L=U,M=j,U=0,j=0,E=x[A][1]):(x[A][0]==n?U+=x[A][1].length:j+=x[A][1].length,E&&E.length<=Math.max(L,M)&&E.length<=Math.max(U,j)&&(x.splice(S[N-1],0,[i,E]),x[S[N-1]+1][0]=n,N--,N--,A=N>0?S[N-1]:-1,L=0,M=0,U=0,j=0,E=null,O=!0)),A++;for(O&&k(x),C(x),A=1;A<x.length;){if(x[A-1][0]==i&&x[A][0]==n){var q=x[A-1][1],K=x[A][1],he=c(q,K),te=c(K,q);he>=te?(he>=q.length/2||he>=K.length/2)&&(x.splice(A,0,[s,K.substring(0,he)]),x[A-1][1]=q.substring(0,q.length-he),x[A+1][1]=K.substring(he),A++):(te>=q.length/2||te>=K.length/2)&&(x.splice(A,0,[s,q.substring(0,te)]),x[A-1][0]=n,x[A-1][1]=K.substring(0,K.length-te),x[A+1][0]=i,x[A+1][1]=q.substring(te),A++),A++}A++}}var m=/[^a-zA-Z0-9]/,g=/\s/,w=/[\r\n]/,y=/\n\r?\n$/,b=/^\r?\n\r?\n/;function C(x){function O(te,pe){if(!te||!pe)return 6;var ke=te.charAt(te.length-1),be=pe.charAt(0),Q=ke.match(m),re=be.match(m),se=Q&&ke.match(g),ee=re&&be.match(g),$=se&&ke.match(w),ue=ee&&be.match(w),Ue=$&&te.match(y),D=ue&&pe.match(b);return Ue||D?5:$||ue?4:Q&&!se&&ee?3:se||ee?2:Q||re?1:0}for(var S=1;S<x.length-1;){if(x[S-1][0]==s&&x[S+1][0]==s){var N=x[S-1][1],E=x[S][1],A=x[S+1][1],L=p(N,E);if(L){var M=E.substring(E.length-L);N=N.substring(0,N.length-L),E=M+E.substring(0,E.length-L),A=M+A}for(var U=N,j=E,q=A,K=O(N,E)+O(E,A);E.charAt(0)===A.charAt(0);){N+=E.charAt(0),E=E.substring(1)+A.charAt(0),A=A.substring(1);var he=O(N,E)+O(E,A);he>=K&&(K=he,U=N,j=E,q=A)}x[S-1][1]!=U&&(U?x[S-1][1]=U:(x.splice(S-1,1),S--),x[S][1]=j,q?x[S+1][1]=q:(x.splice(S+1,1),S--))}S++}}function k(x,O){x.push([s,""]);for(var S=0,N=0,E=0,A="",L="",M;S<x.length;){if(S<x.length-1&&!x[S][1]){x.splice(S,1);continue}switch(x[S][0]){case n:E++,L+=x[S][1],S++;break;case i:N++,A+=x[S][1],S++;break;case s:var U=S-E-N-1;if(O){if(U>=0&&G(x[U][1])){var j=x[U][1].slice(-1);if(x[U][1]=x[U][1].slice(0,-1),A=j+A,L=j+L,!x[U][1]){x.splice(U,1),S--;var q=U-1;x[q]&&x[q][0]===n&&(E++,L=x[q][1]+L,q--),x[q]&&x[q][0]===i&&(N++,A=x[q][1]+A,q--),U=q}}if(z(x[S][1])){var j=x[S][1].charAt(0);x[S][1]=x[S][1].slice(1),A+=j,L+=j}}if(S<x.length-1&&!x[S][1]){x.splice(S,1);break}if(A.length>0||L.length>0){A.length>0&&L.length>0&&(M=l(L,A),M!==0&&(U>=0?x[U][1]+=L.substring(0,M):(x.splice(0,0,[s,L.substring(0,M)]),S++),L=L.substring(M),A=A.substring(M)),M=p(L,A),M!==0&&(x[S][1]=L.substring(L.length-M)+x[S][1],L=L.substring(0,L.length-M),A=A.substring(0,A.length-M)));var K=E+N;A.length===0&&L.length===0?(x.splice(S-K,K),S=S-K):A.length===0?(x.splice(S-K,K,[n,L]),S=S-K+1):L.length===0?(x.splice(S-K,K,[i,A]),S=S-K+1):(x.splice(S-K,K,[i,A],[n,L]),S=S-K+2)}S!==0&&x[S-1][0]===s?(x[S-1][1]+=x[S][1],x.splice(S,1)):S++,E=0,N=0,A="",L="";break}}x[x.length-1][1]===""&&x.pop();var he=!1;for(S=1;S<x.length-1;)x[S-1][0]===s&&x[S+1][0]===s&&(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),he=!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),he=!0)),S++;he&&k(x,O)}function R(x){return x>=55296&&x<=56319}function _(x){return x>=56320&&x<=57343}function z(x){return _(x.charCodeAt(0))}function G(x){return R(x.charCodeAt(x.length-1))}function X(x){for(var O=[],S=0;S<x.length;S++)x[S][1].length>0&&O.push(x[S]);return O}function Ze(x,O,S,N){return G(x)||z(N)?null:X([[s,x],[i,O],[n,S],[s,N]])}function Je(x,O,S){var N=typeof S=="number"?{index:S,length:0}:S.oldRange,E=typeof S=="number"?null:S.newRange,A=x.length,L=O.length;if(N.length===0&&(E===null||E.length===0)){var M=N.index,U=x.slice(0,M),j=x.slice(M),q=E?E.index:null;e:{var K=M+L-A;if(q!==null&&q!==K||K<0||K>L)break e;var he=O.slice(0,K),te=O.slice(K);if(te!==j)break e;var pe=Math.min(M,K),ke=U.slice(0,pe),be=he.slice(0,pe);if(ke!==be)break e;var Q=U.slice(pe),re=he.slice(pe);return Ze(ke,Q,re,j)}e:{if(q!==null&&q!==M)break e;var se=M,he=O.slice(0,se),te=O.slice(se);if(he!==U)break e;var ee=Math.min(A-se,L-se),$=j.slice(j.length-ee),ue=te.slice(te.length-ee);if($!==ue)break e;var Q=j.slice(0,j.length-ee),re=te.slice(0,te.length-ee);return Ze(U,Q,re,$)}}if(N.length>0&&E&&E.length===0)e:{var ke=x.slice(0,N.index),$=x.slice(N.index+N.length),pe=ke.length,ee=$.length;if(L<pe+ee)break e;var be=O.slice(0,pe),ue=O.slice(L-ee);if(ke!==be||$!==ue)break e;var Q=x.slice(pe,A-ee),re=O.slice(pe,L-ee);return Ze(ke,Q,re,$)}return null}function we(x,O,S,N){return o(x,O,S,N,!0)}we.INSERT=n,we.DELETE=i,we.EQUAL=s,t.exports=we}),dl={};$c(dl,{CoreViewer:()=>vc,HOOKS:()=>ds,Navigation:()=>yc,PageProgression:()=>Go,PageSide:()=>gl,PageViewMode:()=>wb,Profiler:()=>vl,ReadyState:()=>ml,UserAgentBaseCss:()=>ch,UserAgentPageCss:()=>uh,UserAgentTocCss:()=>dh,UserAgentXml:()=>hh,ValidationTxt:()=>lh,VivliostylePolyfillCss:()=>ph,VivliostyleViewportCss:()=>ah,VivliostyleViewportScreenCss:()=>rh,ZoomType:()=>mb,getHooksForName:()=>vt,isDebug:()=>ln,pageProgressionOf:()=>fl,plugin:()=>qc,printHTML:()=>vb,profile:()=>Jc,profiler:()=>tt,registerHook:()=>ft,removeHook:()=>bl,setDebug:()=>pl});xc.exports=Gc(dl);var ln=!1;function pl(e){ln=e}var Go=(e=>(e.LTR="ltr",e.RTL="rtl",e))(Go||{});function fl(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var gl=(e=>(e.LEFT="left",e.RIGHT="right",e))(gl||{}),ml=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(ml||{}),wl=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(wl||{}),Xc=class{constructor(e){this.opt_console=e,u(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=Ln(arguments);this.consoleDebug(Fn(t)),this.triggerListeners(1,t)}info(...e){let t=Ln(arguments);this.consoleInfo(Fn(t)),this.triggerListeners(2,t)}warn(...e){let t=Ln(arguments);this.consoleWarn(Fn(t)),this.triggerListeners(3,t)}error(...e){let t=Ln(arguments);this.consoleError(Fn(t)),this.triggerListeners(4,t)}};function Ln(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function Fn(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 Wd=Object.create;var Qn=Object.defineProperty;var Gd=Object.getOwnPropertyDescriptor;var jd=Object.getOwnPropertyNames;var Xd=Object.getPrototypeOf,qd=Object.prototype.hasOwnProperty;var Yd=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Kd=(e,t)=>{for(var i in t)Qn(e,i,{get:t[i],enumerable:!0})},za=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of jd(t))!qd.call(e,s)&&s!==i&&Qn(e,s,{get:()=>t[s],enumerable:!(n=Gd(t,s))||n.enumerable});return e};var Zd=(e,t,i)=>(i=e!=null?Wd(Xd(e)):{},za(t||!e||!e.__esModule?Qn(i,"default",{value:e,enumerable:!0}):i,e)),Jd=e=>za(Qn({},"__esModule",{value:!0}),e);var Dd=Yd((N0,zd)=>{"use strict";var Qd=Object.create,zn=Object.defineProperty,ep=Object.getOwnPropertyDescriptor,tp=Object.getOwnPropertyNames,ip=Object.getPrototypeOf,np=Object.prototype.hasOwnProperty,mh=e=>{throw TypeError(e)},sp=(e,t,i)=>t in e?zn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,rp=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),op=(e,t)=>{for(var i in t)zn(e,i,{get:t[i],enumerable:!0})},wh=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of tp(t))!np.call(e,s)&&s!==i&&zn(e,s,{get:()=>t[s],enumerable:!(n=ep(t,s))||n.enumerable});return e},ap=(e,t,i)=>(i=e!=null?Qd(ip(e)):{},wh(t||!e||!e.__esModule?zn(i,"default",{value:e,enumerable:!0}):i,e)),lp=e=>wh(zn({},"__esModule",{value:!0}),e),c=(e,t,i)=>sp(e,typeof t!="symbol"?t+"":t,i),Go=(e,t,i)=>t.has(e)||mh("Cannot "+i),X=(e,t,i)=>(Go(e,t,"read from private field"),i?i.call(e):t.get(e)),ue=(e,t,i)=>t.has(e)?mh("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),wt=(e,t,i,n)=>(Go(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),Ee=(e,t,i)=>(Go(e,t,"access private method"),i),hp=rp((e,t)=>{var i=-1,n=1,s=0;function r(x,O,S,P,k){if(x===O)return x?[[s,x]]:[];if(S!=null){var R=st(x,O,S);if(R)return R}var L=h(x,O),z=x.substring(0,L);x=x.substring(L),O=O.substring(L),L=d(x,O);var $=x.substring(x.length-L);x=x.substring(0,x.length-L),O=O.substring(0,O.length-L);var q=o(x,O);return z&&q.unshift([s,z]),$&&q.push([s,$]),E(q,k),P&&f(q),q}function o(x,O){var S;if(!x)return[[n,O]];if(!O)return[[i,x]];var P=x.length>O.length?x:O,k=x.length>O.length?O:x,R=P.indexOf(k);if(R!==-1)return S=[[n,P.substring(0,R)],[s,k],[n,P.substring(R+k.length)]],x.length>O.length&&(S[0][0]=S[2][0]=i),S;if(k.length===1)return[[i,x],[n,O]];var L=p(x,O);if(L){var z=L[0],$=L[1],q=L[2],K=L[3],Z=L[4],me=r(z,q),ee=r($,K);return me.concat([[s,Z]],ee)}return a(x,O)}function a(x,O){for(var S=x.length,P=O.length,k=Math.ceil((S+P)/2),R=k,L=2*k,z=new Array(L),$=new Array(L),q=0;q<L;q++)z[q]=-1,$[q]=-1;z[R+1]=0,$[R+1]=0;for(var K=S-P,Z=K%2!==0,me=0,ee=0,we=0,Se=0,le=0;le<k;le++){for(var W=-le+me;W<=le-ee;W+=2){var ce=R+W,de;W===-le||W!==le&&z[ce-1]<z[ce+1]?de=z[ce+1]:de=z[ce-1]+1;for(var _=de-W;de<S&&_<P&&x.charAt(de)===O.charAt(_);)de++,_++;if(z[ce]=de,de>S)ee+=2;else if(_>P)me+=2;else if(Z){var ie=R+K-W;if(ie>=0&&ie<L&&$[ie]!==-1){var ne=S-$[ie];if(de>=ne)return l(x,O,de,_)}}}for(var be=-le+we;be<=le-Se;be+=2){var ie=R+be,ne;be===-le||be!==le&&$[ie-1]<$[ie+1]?ne=$[ie+1]:ne=$[ie-1]+1;for(var at=ne-be;ne<S&&at<P&&x.charAt(S-ne-1)===O.charAt(P-at-1);)ne++,at++;if($[ie]=ne,ne>S)Se+=2;else if(at>P)we+=2;else if(!Z){var ce=R+K-be;if(ce>=0&&ce<L&&z[ce]!==-1){var de=z[ce],_=R+de-ce;if(ne=S-ne,de>=ne)return l(x,O,de,_)}}}}return[[i,x],[n,O]]}function l(x,O,S,P){var k=x.substring(0,S),R=O.substring(0,P),L=x.substring(S),z=O.substring(P),$=r(k,R),q=r(L,z);return $.concat(q)}function h(x,O){if(!x||!O||x.charAt(0)!==O.charAt(0))return 0;for(var S=0,P=Math.min(x.length,O.length),k=P,R=0;S<k;)x.substring(R,k)==O.substring(R,k)?(S=k,R=S):P=k,k=Math.floor((P-S)/2+S);return I(x.charCodeAt(k-1))&&k--,k}function u(x,O){var S=x.length,P=O.length;if(S==0||P==0)return 0;S>P?x=x.substring(S-P):S<P&&(O=O.substring(0,S));var k=Math.min(S,P);if(x==O)return k;for(var R=0,L=1;;){var z=x.substring(k-L),$=O.indexOf(z);if($==-1)return R;L+=$,($==0||x.substring(k-L)==O.substring(0,L))&&(R=L,L++)}}function d(x,O){if(!x||!O||x.slice(-1)!==O.slice(-1))return 0;for(var S=0,P=Math.min(x.length,O.length),k=P,R=0;S<k;)x.substring(x.length-k,x.length-R)==O.substring(O.length-k,O.length-R)?(S=k,R=S):P=k,k=Math.floor((P-S)/2+S);return V(x.charCodeAt(x.length-k))&&k--,k}function p(x,O){var S=x.length>O.length?x:O,P=x.length>O.length?O:x;if(S.length<4||P.length*2<S.length)return null;function k(ee,we,Se){for(var le=ee.substring(Se,Se+Math.floor(ee.length/4)),W=-1,ce="",de,_,ie,ne;(W=we.indexOf(le,W+1))!==-1;){var be=h(ee.substring(Se),we.substring(W)),at=d(ee.substring(0,Se),we.substring(0,W));ce.length<at+be&&(ce=we.substring(W-at,W)+we.substring(W,W+be),de=ee.substring(0,Se-at),_=ee.substring(Se+be),ie=we.substring(0,W-at),ne=we.substring(W+be))}return ce.length*2>=ee.length?[de,_,ie,ne,ce]:null}var R=k(S,P,Math.ceil(S.length/4)),L=k(S,P,Math.ceil(S.length/2)),z;if(!R&&!L)return null;L?R?z=R[4].length>L[4].length?R:L:z=L:z=R;var $,q,K,Z;x.length>O.length?($=z[0],q=z[1],K=z[2],Z=z[3]):(K=z[0],Z=z[1],$=z[2],q=z[3]);var me=z[4];return[$,q,K,Z,me]}function f(x){for(var O=!1,S=[],P=0,k=null,R=0,L=0,z=0,$=0,q=0;R<x.length;)x[R][0]==s?(S[P++]=R,L=$,z=q,$=0,q=0,k=x[R][1]):(x[R][0]==n?$+=x[R][1].length:q+=x[R][1].length,k&&k.length<=Math.max(L,z)&&k.length<=Math.max($,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,z=0,$=0,q=0,k=null,O=!0)),R++;for(O&&E(x),C(x),R=1;R<x.length;){if(x[R-1][0]==i&&x[R][0]==n){var K=x[R-1][1],Z=x[R][1],me=u(K,Z),ee=u(Z,K);me>=ee?(me>=K.length/2||me>=Z.length/2)&&(x.splice(R,0,[s,Z.substring(0,me)]),x[R-1][1]=K.substring(0,K.length-me),x[R+1][1]=Z.substring(me),R++):(ee>=K.length/2||ee>=Z.length/2)&&(x.splice(R,0,[s,K.substring(0,ee)]),x[R-1][0]=n,x[R-1][1]=Z.substring(0,Z.length-ee),x[R+1][0]=i,x[R+1][1]=K.substring(ee),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 O(ee,we){if(!ee||!we)return 6;var Se=ee.charAt(ee.length-1),le=we.charAt(0),W=Se.match(m),ce=le.match(m),de=W&&Se.match(g),_=ce&&le.match(g),ie=de&&Se.match(w),ne=_&&le.match(w),be=ie&&ee.match(v),at=ne&&we.match(y);return be||at?5:ie||ne?4:W&&!de&&_?3:de||_?2:W||ce?1:0}for(var S=1;S<x.length-1;){if(x[S-1][0]==s&&x[S+1][0]==s){var P=x[S-1][1],k=x[S][1],R=x[S+1][1],L=d(P,k);if(L){var z=k.substring(k.length-L);P=P.substring(0,P.length-L),k=z+k.substring(0,k.length-L),R=z+R}for(var $=P,q=k,K=R,Z=O(P,k)+O(k,R);k.charAt(0)===R.charAt(0);){P+=k.charAt(0),k=k.substring(1)+R.charAt(0),R=R.substring(1);var me=O(P,k)+O(k,R);me>=Z&&(Z=me,$=P,q=k,K=R)}x[S-1][1]!=$&&($?x[S-1][1]=$:(x.splice(S-1,1),S--),x[S][1]=q,K?x[S+1][1]=K:(x.splice(S+1,1),S--))}S++}}function E(x,O){x.push([s,""]);for(var S=0,P=0,k=0,R="",L="",z;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 s:var $=S-k-P-1;if(O){if($>=0&&te(x[$][1])){var q=x[$][1].slice(-1);if(x[$][1]=x[$][1].slice(0,-1),R=q+R,L=q+L,!x[$][1]){x.splice($,1),S--;var K=$-1;x[K]&&x[K][0]===n&&(k++,L=x[K][1]+L,K--),x[K]&&x[K][0]===i&&(P++,R=x[K][1]+R,K--),$=K}}if(D(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&&(z=h(L,R),z!==0&&($>=0?x[$][1]+=L.substring(0,z):(x.splice(0,0,[s,L.substring(0,z)]),S++),L=L.substring(z),R=R.substring(z)),z=d(L,R),z!==0&&(x[S][1]=L.substring(L.length-z)+x[S][1],L=L.substring(0,L.length-z),R=R.substring(0,R.length-z)));var Z=k+P;R.length===0&&L.length===0?(x.splice(S-Z,Z),S=S-Z):R.length===0?(x.splice(S-Z,Z,[n,L]),S=S-Z+1):L.length===0?(x.splice(S-Z,Z,[i,R]),S=S-Z+1):(x.splice(S-Z,Z,[i,R],[n,L]),S=S-Z+2)}S!==0&&x[S-1][0]===s?(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 me=!1;for(S=1;S<x.length-1;)x[S-1][0]===s&&x[S+1][0]===s&&(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),me=!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),me=!0)),S++;me&&E(x,O)}function I(x){return x>=55296&&x<=56319}function V(x){return x>=56320&&x<=57343}function D(x){return V(x.charCodeAt(0))}function te(x){return I(x.charCodeAt(x.length-1))}function re(x){for(var O=[],S=0;S<x.length;S++)x[S][1].length>0&&O.push(x[S]);return O}function nt(x,O,S,P){return te(x)||D(P)?null:re([[s,x],[i,O],[n,S],[s,P]])}function st(x,O,S){var P=typeof S=="number"?{index:S,length:0}:S.oldRange,k=typeof S=="number"?null:S.newRange,R=x.length,L=O.length;if(P.length===0&&(k===null||k.length===0)){var z=P.index,$=x.slice(0,z),q=x.slice(z),K=k?k.index:null;e:{var Z=z+L-R;if(K!==null&&K!==Z||Z<0||Z>L)break e;var me=O.slice(0,Z),ee=O.slice(Z);if(ee!==q)break e;var we=Math.min(z,Z),Se=$.slice(0,we),le=me.slice(0,we);if(Se!==le)break e;var W=$.slice(we),ce=me.slice(we);return nt(Se,W,ce,q)}e:{if(K!==null&&K!==z)break e;var de=z,me=O.slice(0,de),ee=O.slice(de);if(me!==$)break e;var _=Math.min(R-de,L-de),ie=q.slice(q.length-_),ne=ee.slice(ee.length-_);if(ie!==ne)break e;var W=q.slice(0,q.length-_),ce=ee.slice(0,ee.length-_);return nt($,W,ce,ie)}}if(P.length>0&&k&&k.length===0)e:{var Se=x.slice(0,P.index),ie=x.slice(P.index+P.length),we=Se.length,_=ie.length;if(L<we+_)break e;var le=O.slice(0,we),ne=O.slice(L-_);if(Se!==le||ie!==ne)break e;var W=x.slice(we,R-_),ce=O.slice(we,L-_);return nt(Se,W,ce,ie)}return null}function xe(x,O,S,P){return r(x,O,S,P,!0)}xe.INSERT=n,xe.DELETE=i,xe.EQUAL=s,t.exports=xe}),bh={};op(bh,{CoreViewer:()=>_d,HOOKS:()=>qs,Navigation:()=>Md,PageProgression:()=>jo,PageSide:()=>xh,PageViewMode:()=>c0,Profiler:()=>Eh,ReadyState:()=>Sh,UserAgentBaseCss:()=>wu,UserAgentCounterStylesCss:()=>vu,UserAgentPageCss:()=>mu,UserAgentTocCss:()=>bu,UserAgentXml:()=>gu,ValidationTxt:()=>fu,VivliostylePolyfillCss:()=>yu,VivliostyleViewportCss:()=>pu,VivliostyleViewportScreenCss:()=>du,ZoomType:()=>u0,getHooksForName:()=>At,isDebug:()=>Tn,pageProgressionOf:()=>vh,plugin:()=>cp,printHTML:()=>p0,profile:()=>gp,profiler:()=>ct,registerHook:()=>kt,removeHook:()=>kh,setDebug:()=>yh});zd.exports=lp(bh);var Tn=!1;function yh(e){Tn=e}var jo=(e=>(e.LTR="ltr",e.RTL="rtl",e))(jo||{});function vh(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var xh=(e=>(e.LEFT="left",e.RIGHT="right",e))(xh||{}),Sh=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(Sh||{}),Ch=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(Ch||{}),up=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=es(arguments);this.consoleDebug(ts(t)),this.triggerListeners(1,t)}info(...e){let t=es(arguments);this.consoleInfo(ts(t)),this.triggerListeners(2,t)}warn(...e){let t=es(arguments);this.consoleWarn(ts(t)),this.triggerListeners(3,t)}error(...e){let t=es(arguments);this.consoleError(ts(t)),this.triggerListeners(4,t)}};function es(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function ts(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 H=new
|
|
4
|
-
`}}),H.info(t)}disable(){this.registerTiming=ri,this.registerStartTiming=this.registerStartTiming=ri,this.registerEndTiming=this.registerEndTiming=ri}enable(){this.registerTiming=Rs,this.registerStartTiming=this.registerStartTiming=Mr,this.registerEndTiming=this.registerEndTiming=Yc}isEnabled(){return this.registerStartTiming===Mr}};function ri(){}function Rs(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let s,o=n.length;for(let r=o-1;r>=0&&(s=n[r],!(s&&!s[t]));r--)s=null;s||(s={},n.push(s)),s[t]=i}function Mr(e,t){this.registerTiming(e,"start",t)}function Yc(e,t){this.registerTiming(e,"end",t)}var Kc={now:Date.now},Zc=window&&window.performance,tt=new vl(Zc||Kc);tt.forceRegisterStartTiming("load_vivliostyle");var Jc={profiler:{registerStartTiming:tt.registerStartTiming,registerEndTiming:tt.registerEndTiming,printTimings:tt.printTimings,disable:tt.disable,enable:tt.enable}},yl=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",Zn=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,kt="data-adapt-eloff",Qc={};function jo(e){return JSON.parse(e)}function Nt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function ed(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var Pi=window.location.href;function zr(e){Pi=e}var ni=window.location.href;function Dr(e){ni=e}function Ee(e,t){if(/^data:/i.test(t))return e||t;if(!t||e.match(/^\w{2,}:/))return e.toLowerCase().match("^javascript:")?"#":(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`),e);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let i;if(e.match(/^\/\//))return i=t.match(/^(\w{2,}:)\/\//),i?i[1]+e:e;if(e.match(/^\//))return i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e;if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=ed(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let s=t.substr(0,n+1)+e,o="";for(i=s.match(/^([^?#]*)([?#].*)$/),i&&(s=i[1],o=i[2]);n=s.indexOf("/../"),!(n<=0);){let r=s.lastIndexOf("/",n-1);if(r<=0)break;s=s.substr(0,r)+s.substr(n+3)}return s.replace(/\/(\.\/)+/g,"/")+o}function hn(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 Vr(e){return e==null?e:e.toString()}var td=class{constructor(){u(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 s=n*2;if(s>=i)break;if(this.queue[s].compare(t)>0)s+1<i&&this.queue[s+1].compare(this.queue[s])>0&&s++;else if(s+1<i&&this.queue[s+1].compare(t)>0)s++;else break;this.queue[n]=this.queue[s],n=s}this.queue[n]=t}return e}},xl=["","-webkit-","-moz-"],li={};function Ls(e,t){return CSS.supports(e+t,"unset")}function id(e){let t=li[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return li[e]=null,null;case"text-combine-upright":if(Ls("-webkit-","text-combine")&&!Ls("","text-combine-upright"))return li[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of xl)if(Ls(i,e))return t=[i+e],li[e]=t,t;return H.warn("Property not supported by the browser: ",e),li[e]=null,null}function T(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let s=id(t);if(s)for(let o of s){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 _t(e,t,i){try{let n=li[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function Ys(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 It=class{constructor(){u(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 Sl(e){return`\\${e.charCodeAt(0).toString(16)} `}function Vt(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Sl)}function vn(e){return e.replace(/[\u0000-\u001F"\\]/g,Sl)}function Ur(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Hr(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function nd(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function Cl(e,t){function i(n){return nd(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function Bt(e){return Cl(e)}function sd(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function od(e,t){t=typeof t=="string"?t:"\\u";function i(s){return sd(s,t)}let n=new RegExp(`${Bt(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function Ht(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 s=i+n>>1;t(s)?n=s:i=s+1}}function El(e,t){return e-t}function $r(e,t){let i={};for(let n of e){let s=t(n);s&&!i[s]&&(i[s]=n)}return i}function rd(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function Fs(e,t){let i={};for(let n of e){let s=t(n);s&&(i[s]?i[s].push(n):i[s]=[n])}return i}function ad(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var Xo=class{constructor(){u(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 s=n.indexOf(t);s>=0&&n.splice(s,1)}}},Qt={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function kl(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function ld(e){return`^${e}`}function Wr(e){return e.replace(/[\[\]\(\),=;^]/g,ld)}function hd(e){return e.substr(1)}function Ks(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,hd)}function ud(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=Ks(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function Gr(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=ud(i[2]),e=e.substr(i[0].length)}return t}var jr=class{appendTo(e){e.append("!")}applyTo(e){return!1}},Xr=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,s,o=Math.floor(this.index/2)-1;if(o<0||n==0)s=t.firstChild,e.node=s||t;else{if(s=i[Math.min(o,n-1)],this.index&1){let r=s.nextSibling;!r||r.nodeType==1?e.after=!0:s=r}e.node=s}if(this.id&&(e.after||this.id!=kl(e.node))){let r=t.ownerDocument.getElementById(this.id);r?e.node=r:H.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},qr=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 s=i.nextSibling;if(3<=n&&n<=5){let o=i.textContent.length;if(t<=o)break;if(!s){t=o;break}t-=o}if(!s){t=0;break}i=s}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(Wr(this.textBefore)),e.append(","),this.textAfter&&e.append(Wr(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Yr=class Pl{constructor(){u(this,"steps",null)}fromString(t){let i=t.match(/^#?epubcfi\((.*)\)$/);if(!i)throw new Error("E_CFI_NOT_CFI");let n=decodeURIComponent(i[1]),s=0,o=[];for(;;){let r;switch(n.charAt(s)){case"/":{if(s++,i=n.substr(s).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");s+=i[0].length;let a=parseInt(i[1],10),h=i[3];r=Gr(i[4]),o.push(new Xr(a,h,Vr(r.s)));break}case":":{if(s++,i=n.substr(s).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");s+=i[0].length;let a=parseInt(i[1],10),h=i[4];h&&(h=Ks(h));let l=i[7];l&&(l=Ks(l)),r=Gr(i[10]),o.push(new qr(a,h,l,Vr(r.s)));break}case"!":s++,o.push(new jr);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 Pl,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,s){let o=[],r=t.parentNode,a="",h="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let l=t.textContent,c=l.length;n?(i+=c,a||(a=l)):(i>c&&(i=c),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 qr(i,a,h,s)),s=null);r&&!(!r||r.nodeType==9);){let l=n?null:kl(t),c=n?1:0;for(;t;)t.nodeType==1&&(c+=2),t=t.previousSibling;o.push(new Xr(c,l,s)),s=null,t=r,r=r.parentNode,n=!1}o.reverse(),this.steps?(o.push(new jr),this.steps=o.concat(this.steps)):this.steps=o}toString(){if(!this.steps)return"";let t=new It;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 Nl(){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 Tl(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 cd=Nl(),Kr={PENDING:{}};function Il(e,t,i,n){let s=Math.min((e-0)/i,(t-0)/n);return`matrix(${s},0,0,${s},0,0)`}function Os(e){return`"${vn(`${e}`)}"`}function dd(e){return Vt(`${e}`)}function Zs(e,t){return e?`${Vt(e)}.${Vt(t)}`:Vt(t)}var Al=0,Js=class{constructor(e,t){if(this.parent=e,this.resolver=t,u(this,"scopeKey"),u(this,"children",[]),u(this,"zero"),u(this,"one"),u(this,"_true"),u(this,"_false"),u(this,"values",{}),u(this,"funcs",{}),u(this,"builtIns",{}),this.scopeKey=`S${Al++}`,this.zero=new Oe(this,0),this.one=new Oe(this,1),this._true=new Oe(this,!0),this._false=new Oe(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=Il,i["css-string"]=Os,i["css-name"]=dd,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 Os(this.pubTitle?this.pubTitle:"")}),this.defineBuiltInName("doc-title",function(){return Os(this.docTitle?this.docTitle:"")})}}defineBuiltInName(e,t){this.values[e]=new Ie(this,t,e)}defineName(e,t){this.values[e]=t}defineFunc(e,t){this.funcs[e]=t}defineBuiltIn(e,t){this.builtIns[e]=t}};function pd(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function Rl(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 fd(e){switch(e?.toLowerCase()){case"em":case"ex":case"rem":case"lh":case"rlh":return!0;default:return!1}}function gd(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var ge={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,ex:8,lh:20,rlh:20,dppx:1,dpi:1/96,dpcm:2.54/96};function Ll(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 Qs=class{constructor(e,t,i,n){this.rootScope=e,this.viewportWidth=t,this.viewportHeight=i,u(this,"actualPageWidth",null),u(this,"pageWidth"),u(this,"actualPageHeight",null),u(this,"pageHeight"),u(this,"initialFontSize"),u(this,"rootFontSize",null),u(this,"isRelativeRootFontSize",null),u(this,"fontSize"),u(this,"rootLineHeight",null),u(this,"pref"),u(this,"scopes",{}),u(this,"pageAreaWidth",null),u(this,"pageAreaHeight",null),u(this,"pageVertical",null),u(this,"pubTitle",null),u(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=cd}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(Rl(e)){let n=this.pageWidth()/100,s=this.pageHeight()/100,o=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,r=this.pageAreaHeight!=null?this.pageAreaHeight/100:s,a=i??this.pageVertical;switch(e){case"vw":return o;case"vh":return r;case"vi":return a?r:o;case"vb":return a?o:r;case"vmin":return o<r?o:r;case"vmax":return o>r?o:r;case"pvw":return n;case"pvh":return s;case"pvi":return a?s:n;case"pvb":return a?n:s;case"pvmin":return n<s?n:s;case"pvmax":return n>s?n:s}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="ex"?ge.ex*(t?this.initialFontSize:this.fontSize())/ge.em:e=="lh"||e=="rlh"?this.rootLineHeight:ge[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 s=e.funcs[t];if(s||e.resolver&&(s=e.resolver.call(this,t,!0),s))return s;let o=e.builtIns[t];if(o){if(n)return e.zero;let r=Array(i.length);for(let a=0;a<i.length;a++)r[a]=i[a].evaluate(this);return new Oe(e,o.apply(this,r))}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 s=null,o=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(s=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&&s!=null)switch(i){case"min":return o>=Number(s);case"max":return o<=Number(s);default:return o==s}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}},gt=class{constructor(e){this.scope=e,u(this,"key"),this.scope=e,this.key=`_${Al++}`}toString(){let e=new It;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===Kr.PENDING?!1:n;{i[this.key]=Kr.PENDING;let s=this.dependCore(e,t,i);return i[this.key]=s,s}}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}},Fl=class extends gt{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 gt{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)}},Ol=class extends ps{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Ri=class extends ps{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},Bl=class extends ps{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},qo=class extends ps{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},Ut=class extends Fl{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},md=class extends Ut{constructor(e,t){super(e,t)}getOp(){return"not "}},fi=class extends Fl{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},Yo=class extends Ol{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},wd=class extends Yo{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},Ko=class extends Ol{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},bd=class extends Ko{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},vd=class extends Ko{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},yd=class extends Ri{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},xd=class extends Ri{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},Sd=class extends Ri{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},eo=class extends Ri{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Zo=class extends Ri{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},Cd=class extends Ri{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},_l=class extends Bl{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},Ml=class extends Bl{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},Jo=class extends qo{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},zl=class extends qo{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},Dl=class extends qo{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},yn=class extends gt{constructor(e,t,i){var n;super(e),this.num=t,u(this,"unit"),this.unit=(n=i?.toLowerCase())!=null?n:""}appendTo(e,t){e.append(this.num.toString()),e.append(Vt(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},Ae=class extends gt{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)}},Zr=class extends gt{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(Vt(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},Ie=class extends gt{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 Ed(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function kd(e,t,i){let n=t;for(let s=0;s<t.length;s++){let o=t[s].expand(e,i);if(t!==n)n[s]=o;else if(o!==t[s]){n=Array(t.length);for(let r=0;r<s;r++)n[r]=t[r];n[s]=o}}return n}var Ki=class Vl extends gt{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),Ed(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 s=0;s<this.params.length;s++)if(this.params[s].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=kd(t,this.params,i);return n===this.params?this:new Vl(this.scope,this.qualifiedName,n)}},Pd=class Ul extends gt{constructor(t,i,n,s){super(t),this.cond=i,this.ifTrue=n,this.ifFalse=s}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),s=this.ifTrue.expand(t,i),o=this.ifFalse.expand(t,i);return n===this.cond&&s===this.ifTrue&&o===this.ifFalse?this:new Ul(this.scope,n,s,o)}},Oe=class extends gt{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(vn(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Jr=class Hl extends gt{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(vn(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 Hl(this.scope,this.name,n)}},Nd=class extends gt{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)}},$l=class extends gt{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 dt(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 Yo(e,t,i)}function Y(e,t,i){return t===e.zero?i:i===e.zero?t:new _l(e,t,i)}function oe(e,t,i){return t===e.zero?new fi(e,i):i===e.zero?t:new Ml(e,t,i)}function Hn(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new Jo(e,t,i)}function to(e,t,i){return t===e.zero?e.zero:i===e.one?t:new zl(e,t,i)}var Ot=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}},Li=class extends Ot{constructor(){super(),u(this,"error",!1)}visitValues(e){let t=null;for(let i=0;i<e.length;i++){let n=e[i],s=n.visit(this);if(this.error)return[];if(t)t[i]=s;else if(n!==s){t=new Array(e.length);for(let o=0;o<i;o++)t[o]=e[o];t[i]=s}}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?W:t===e.values?e:new me(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?W:t===e.values?e:new qe(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?W:t===e.values?e:new Fi(e.name,t)}visitExpr(e){return e}},He=class{toString(){let e=new It;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new It;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}},Wl=class Gl extends He{static get instance(){return this.empty||(this.empty=new Gl),this.empty}constructor(){super()}toExpr(t,i){return new Oe(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};u(Wl,"empty");var Td=Wl,W=Td.instance,jl=class Xl extends He{static get instance(){return this.slash||(this.slash=new Xl),this.slash}constructor(){super()}toExpr(t,i){return new Oe(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};u(jl,"slash");var Id=jl,fs=Id.instance,Le=class extends He{constructor(e){super(),this.str=e}toExpr(e,t){return new Oe(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(vn(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},io={},nt=class extends He{constructor(e){if(super(),this.name=e,io[e])throw new Error("E_INVALID_CALL");io[e]=this}toExpr(e,t){return new Oe(e,this.name)}appendTo(e,t){t?e.append(Vt(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function B(e){let t=io[e];return t||(t=new nt(e)),t}var I=class extends He{constructor(e,t){var i;super(),this.num=e,u(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 Jo(e,t,new Oe(e,this.num/100)):new yn(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 He{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new Oe(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},si=class extends Xt{constructor(e){super(e)}visit(e){return e.visitInt(this)}},ql=class extends He{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},pt=class extends He{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(vn(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},Yl=class extends He{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function Qo(e,t,i,n){var s,o;let r=t.length;if(r>0){(s=t[0])==null||s.appendTo(e,n);for(let a=1;a<r;a++)e.append(i),(o=t[a])==null||o.appendTo(e,n)}}var me=class extends He{constructor(e){super(),this.values=e}appendTo(e,t){Qo(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},qe=class extends He{constructor(e){super(),this.values=e}appendTo(e,t){Qo(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},Fi=class extends He{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(Vt(this.name)),e.append("("),Qo(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},V=class extends He{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof Oe||this.expr instanceof yn?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}},hi=class extends He{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function We(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 Kl(e,t){return new I(We(e,t),"px")}var v={absolute:B("absolute"),all:B("all"),always:B("always"),anywhere:B("anywhere"),auto:B("auto"),avoid:B("avoid"),balance:B("balance"),balance_all:B("balance-all"),block:B("block"),block_end:B("block-end"),block_start:B("block-start"),both:B("both"),bottom:B("bottom"),border_box:B("border-box"),break_all:B("break-all"),break_word:B("break-word"),clip:B("clip"),crop:B("crop"),cross:B("cross"),column:B("column"),discard:B("discard"),exclusive:B("exclusive"),_false:B("false"),fixed:B("fixed"),flex:B("flex"),flow_root:B("flow-root"),footnote:B("footnote"),footer:B("footer"),grid:B("grid"),header:B("header"),hidden:B("hidden"),horizontal_tb:B("horizontal-tb"),inherit:B("inherit"),initial:B("initial"),inline:B("inline"),inline_block:B("inline-block"),inline_end:B("inline-end"),inline_start:B("inline-start"),inside:B("inside"),keep:B("keep"),landscape:B("landscape"),left:B("left"),line:B("line"),list_item:B("list-item"),ltr:B("ltr"),manual:B("manual"),max_content:B("max-content"),min_content:B("min-content"),none:B("none"),normal:B("normal"),oeb_page_foot:B("oeb-page-foot"),oeb_page_head:B("oeb-page-head"),outside:B("outside"),padding_box:B("padding-box"),page:B("page"),relative:B("relative"),revert:B("revert"),right:B("right"),same:B("same"),scale:B("scale"),snap_block:B("snap-block"),snap_inline:B("snap-inline"),solid:B("solid"),spread:B("spread"),_static:B("static"),rtl:B("rtl"),table:B("table"),table_caption:B("table-caption"),table_cell:B("table-cell"),table_footer_group:B("table-footer-group"),table_header_group:B("table-header-group"),table_row:B("table-row"),top:B("top"),transparent:B("transparent"),unset:B("unset"),vertical_lr:B("vertical-lr"),vertical_rl:B("vertical-rl"),visible:B("visible"),_true:B("true")},Qr=new I(100,"%"),xn=new I(100,"pvw"),Sn=new I(100,"pvh"),fe=new I(0,"px"),Sb=new Yl("U+0-10FFFF"),ea={"font-size":1,"line-height":2,color:3};function J(e){return e===v.inherit||e===v.initial||e===v.revert||e===v.unset}function ta(e,t){let i=ea[e]||Number.MAX_VALUE,n=ea[t]||Number.MAX_VALUE;return i-n}function At(e){return e?.length>2&&e.startsWith("--")}var at=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},Mt=class{constructor(e,t){this.x=e,this.y=t}},Bs=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},ia=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},Tt=class{constructor(e,t,i,n){this.y1=e,this.y2=t,this.x1=i,this.x2=n,u(this,"left",null),u(this,"right",null)}};function Ad(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var gs=class Zl{constructor(t){this.points=t}addSegments(t,i){let n=this.points,s=n.length,o=n[s-1];for(let r=0;r<s;r++){let a=n[r],h;o.y<a.y?h=new ia(o,a,1,i):h=new ia(a,o,-1,i),t.push(h),o=a}}withOffset(t,i){let n=[];for(let s of this.points)n.push(new Mt(s.x+t,s.y+i));return new Zl(n)}};function na(e,t,i,n){let s=[];for(let o=0;o<20;o++){let r=o*2*Math.PI/20;s.push(new Mt(e+i*Math.sin(r),t+n*Math.cos(r)))}return new gs(s)}function er(e,t,i,n){return new gs([new Mt(e,t),new Mt(i,t),new Mt(i,n),new Mt(e,n)])}var On=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function sa(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 Rd(e,t,i,n){let s,o,r,a;t.high.y<i&&H.warn("Error: inconsistent segment (1)"),t.low.y<=i?(s=sa(t,i),o=t.winding):(s=t.low.x,o=0),t.high.y>=n?(r=sa(t,n),a=t.winding):(r=t.high.x,a=0),s<r?(e.push(new On(s,o,t.shapeId,-1)),e.push(new On(r,a,t.shapeId,1))):(e.push(new On(r,a,t.shapeId,-1)),e.push(new On(s,o,t.shapeId,1)))}function Ld(e,t,i){let n=t+i,s=Array(n),o=Array(n),r;for(r=0;r<=n;r++)s[r]=0,o[r]=0;let a=[],h=!1,l=e.length;for(let c=0;c<l;c++){let p=e[c];s[p.shapeId]+=p.winding,o[p.shapeId]+=p.lowOrHigh;let d=!1;for(r=0;r<t;r++)if(s[r]&&!o[r]){d=!0;break}if(d){for(r=t;r<=n;r++)if(s[r]||o[r]){d=!1;break}}h!=d&&(a.push(p.x),h=d)}return a}function Fd(e,t){return t?Math.ceil(e/t)*t:e}function oa(e,t){return t?Math.floor(e/t)*t:e}function Od(e){return new Mt(e.y,-e.x)}function Jn(e){return new at(e.y1,-e.x2,e.y2,-e.x1)}function Jl(e){return new at(-e.y2,e.x1,-e.y1,e.x2)}function ra(e){return new gs(e.points.map(t=>Od(t)))}function Bd(e,t,i,n,s,o){o&&(e=Jn(e),t=t.map(b=>ra(b)),i=i.map(b=>ra(b)));let r=t.length,a=i?i.length:0,h=[],l=[],c,p,d;for(c=0;c<r;c++)t[c].addSegments(l,c);for(c=0;c<a;c++)i[c].addSegments(l,c+r);let f=l.length;l.sort(Ad);let m=0;for(;l[m].shapeId>=r;)m++;let g=l[m].low.y;g>e.y1&&h.push(new Tt(e.y1,g,e.x2,e.x2));let w=0,y=[];for(;w<f&&(d=l[w]).low.y<g;)d.high.y>g&&y.push(d),w++;for(;w<f||y.length>0;){let b=e.y2,C=Math.min(Fd(Math.ceil(g+n),s),e.y2);for(p=0;p<y.length&&b>C;p++)d=y[p],d.low.x==d.high.x?d.high.y<b&&(b=Math.max(oa(d.high.y,s),C)):d.low.x!=d.high.x&&(b=C);for(b>e.y2&&(b=e.y2);w<f&&(d=l[w]).low.y<b;){if(d.high.y<g){w++;continue}if(d.low.y<C)d.low.y==d.high.y&&d.low.y==g||(y.push(d),b=C),w++;else{let _=oa(d.low.y,s);_<b&&(b=_);break}}let k=[];for(p=0;p<y.length;p++)Rd(k,y[p],g,b);k.sort((_,z)=>_.x-z.x||_.lowOrHigh-z.lowOrHigh);let R=Ld(k,r,a);if(R.length==0)h.push(new Tt(g,b,e.x2,e.x2));else{let _=0,z=e.x1;for(p=0;p<R.length;p+=2){let G=Math.max(e.x1,R[p]),X=Math.min(e.x2,R[p+1])-G;X>_&&(_=X,z=G)}_==0?h.push(new Tt(g,b,e.x2,e.x2)):h.push(new Tt(g,b,Math.max(z,e.x1),Math.min(z+_,e.x2)))}if(b==e.y2)break;for(g=b,p=y.length-1;p>=0;p--)y[p].high.y<=b&&y.splice(p,1)}return Ql(e,h),h}function Ql(e,t){let i=t.length-1,n=new Tt(e.y2,e.y2,e.x1,e.x2);for(;i>=0;){let s=n;n=t[i],(n.y2-n.y1<1||n.x1==s.x1&&n.x2==s.x2)&&(s.y1=n.y1,t.splice(i,1),n=s),i--}}function eh(e,t){let i=0,n=e.length;for(;i<n;){let s=Math.floor((i+n)/2);t>=e[s].y2?i=s+1:n=s}return i}function _d(e,t){if(!e.length)return t;let i=t.y1,n,s;for(s=0;s<e.length&&(n=e[s],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));s++)i=Math.max(i,n.y2);let o=i;for(;s<e.length&&(n=e[s],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));s++)o=n.y2;return s===e.length?o=t.y2:o=Math.min(o,t.y2),o<=i?null:new at(t.x1,i,t.x2,o)}function Md(e,t){if(!e.length)return t;let i=t.y2,n,s;for(s=e.length-1;s>=0&&(n=e[s],!(s===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);s--)i=Math.min(i,n.y1);let o=Math.min(i,n.y2);for(;s>=0&&(n=e[s],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));s--)o=n.y1;return o=Math.max(o,t.y1),i<=o?null:new at(t.x1,o,t.x2,i)}function zd(e,t,i,n){let s=i.y1,o=i.x2-i.x1,r=i.y2-i.y1,a=eh(t,s);for(;;){let h=s+r;if(h>e.y2)return!1;let l=e.x1,c=e.x2;for(let p=a;p<t.length&&t[p].y1<h;p++){let d=t[p];d.x1>l&&(l=d.x1),d.x2<c&&(c=d.x2)}if(l+o<=c||a>=t.length)return n=="left"?(i.x1=l,i.x2=l+o):(i.x1=c-o,i.x2=c),i.y2+=s-i.y1,i.y1=s,!0;s=t[a].y2,a++}}function Dd(e,t,i,n,s){for(n||(n=[new Tt(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,r=t.length==0?e.y1:t[t.length-1].y2;r<e.y2&&t.push(new Tt(r,e.y2,e.x1,e.x2));let a=eh(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 Tt(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 Tt(h.y2,o.y2,o.x1,o.x2)),o.y2=h.y2),h.x1!=h.x2&&(s=="left"?o.x1=Math.min(h.x2,e.x2):o.x2=Math.max(h.x1,e.x1)),o.y2!=h.y2););}Ql(e,t)}var Vd=class extends Ot{constructor(){super(),u(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Ud(e){if(e){let t=new Vd;try{return e.visit(t),t.propSet}catch(i){H.warn(i,"toSet:")}}return{}}var Hd=class extends Ot{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function aa(e,t){if(e){let i=new Hd(t);try{return e.visit(i),i.value}catch(n){H.warn(n,"toInt: ")}}return t}var $d=class extends Ot{constructor(){super(),u(this,"collect",!1),u(this,"coords",[]),u(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,s){if(this.coords.length>0){let o=[];switch(this.coords.forEach((r,a)=>{if(r.unit=="%"){let h=a%2==0?i:n;a==3&&this.name=="circle"&&(h=Math.sqrt((i*i+n*n)/2)),o.push(r.num*h/100)}else o.push(r.num*s.queryUnitSize(r.unit,!1))}),this.name){case"polygon":if(o.length%2==0){let r=[];for(let a=0;a<o.length;a+=2)r.push(new Mt(e+o[a],t+o[a+1]));return new gs(r)}break;case"rectangle":if(o.length==4)return er(e+o[0],t+o[1],e+o[0]+o[2],t+o[1]+o[3]);break;case"ellipse":if(o.length==4)return na(e+o[0],t+o[1],o[2],o[3]);break;case"circle":if(o.length==3)return na(e+o[0],t+o[1],o[2],o[2]);break}}return null}};function th(e,t,i,n,s,o){if(e){let r=new $d;try{return e.visit(r),r.getShape(t,i,n,s,o)}catch(a){H.warn(a,"toShape:")}}return er(t,i,t+n,i+s)}var Wd=class extends Ot{constructor(e){super(),this.reset=e,u(this,"counters",{}),u(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 Zi(e,t){let i=new Wd(t);try{e.visit(i)}catch(n){H.warn(n,"toCounters:")}return i.counters}var Gd=class extends Li{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new pt(this.transformer.transformURL(e.url,this.baseUrl))}};function _s(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function Ji(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 jd=class{constructor(e,t){this.targetId=e,this.resolved=t,u(this,"pageCounters",null),u(this,"spineIndex",-1),u(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}},Xd=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()}},qd=class{constructor(e,t,i,n){this.counterStore=e,this.baseURL=t,this.rootScope=i,this.pageScope=n,u(this,"styler",null),u(this,"namedStringValues",{}),u(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(Ee(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 Ie(this.pageScope,()=>t(i()),`page-counter-${e}`),s=o=>t(o[o.length-1]);return this.counterStore.registerPageCounterExpr(e,s,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new Ie(this.pageScope,()=>t(i()),`page-counters-${e}`);return this.counterStore.registerPageCounterExpr(e,t,n),n}getTargetCounters(e,t,i){let n=this.counterStore.countersById[t];return!n&&i&&e&&(this.styler.styleUntilIdIsReached(e),n=this.counterStore.countersById[t]),n||null}getTargetPageCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageCounters:this.counterStore.pageCountersById[e]||null}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"?Ji(n,t):Ji(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),s=this.getTransformedId(e),o=this.getTargetCounters(n,s,!1);if(o&&o[t]){let a=o[t];return new Oe(this.rootScope,i(a[a.length-1]||null))}let r=new Ie(this.pageScope,()=>{if(o=this.getTargetCounters(n,s,!0),o)if(o[t]){let a=o[t];return i(a[a.length-1]||null)}else{let a=this.getTargetPageCounters(s);if(a)if(this.counterStore.resolveReference(s),a[t]){let h=a[t];return i(h[h.length-1]||null)}else return i(0);else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"},`target-counter-${t}-of-${e}`);return this.counterStore.registerTargetCounterExpr(t,i,r,s),r}getTargetCountersVal(e,t,i){let n=this.getFragment(e),s=this.getTransformedId(e);return new Ie(this.pageScope,()=>{let o=this.getTargetPageCounters(s);if(o){this.counterStore.resolveReference(s);let r=o[t]||[],a=this.getTargetCounters(n,s,!0)[t]||[];return i(r.concat(a))}else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"},`target-counters-${t}-of-${e}`)}getTargetTextVal(e,t){let i=this.getTransformedId(e),n=new Ie(this.pageScope,()=>{if(t==="first-letter"){let o=this.getTargetPageText(i,"before"),r=this.getTargetPageText(i,"content"),a=this.getTargetPageText(i,"after");if(o===null&&r===null&&a===null)return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??";let h=(o??"")+(r??"")+(a??"");this.counterStore.resolveReference(i);let l=h.match(Zn);return l?l[0]:""}let s=this.getTargetPageText(i,t);return s!==null?(this.counterStore.resolveReference(i),s):(this.counterStore.saveReferenceOfCurrentPage(i,!1),"??")},`target-text-${t}-of-${e}`);return this.counterStore.registerTargetTextExpr(t,n,i),n}getNamedStringVal(e,t){return new Ie(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new Ie(this.pageScope,()=>this.getRunningValue(this.runningElements,e,t),`running-element-${t}-${e}`)}getRunningValue(e,t,i){let n=e[t];if(!n)return"";let s=Object.keys(n).map(d=>parseInt(d,10)).sort(El),o=this.counterStore.currentPage,r=o.isBlankPage?o.offset-1:o.offset,a=o.isBlankPage?r:Math.max(r,...Array.from(o.container.querySelectorAll(`[${kt}]`)).map(d=>parseInt(d.getAttribute(kt),10))),h=-1,l=-1,c=-1,p=-1;for(let d=0;d<s.length;d++){let f=s[d],m=d>0?s[d-1]:-1,g=d<s.length-1?s[d+1]:-1;if(f>a)break;if(f>=r){if(h<0&&(h=f,p=-1),l<0)if(f===r)l=f;else{m<h&&(l=m);let w=o.container.querySelector(`[${kt}="${f}"]`);if(!w)l<0&&(l=f);else{let y=o.container.querySelector(`[${kt}="${r}"]`);if(y||(y=o.container.querySelector(`[${kt}="0"]`)),y){for(let b=y;b;b=b.firstElementChild)if(b===w){l=f;break}}}}c=f}else(g>a||g<0)&&(h=l=c=p=f)}return n[{first:h,start:l,last:c,"first-except":p}[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)}},Yd=class{constructor(e){this.documentURLTransformer=e,u(this,"countersById",{}),u(this,"pageCountersById",{}),u(this,"pageTextById",{}),u(this,"currentPageCounters",{}),u(this,"previousPageCounters",{}),u(this,"currentPageCountersStack",[]),u(this,"pageIndicesById",{}),u(this,"currentPage",null),u(this,"newReferencesOfCurrentPage",[]),u(this,"referencesToSolve",[]),u(this,"referencesToSolveStack",[]),u(this,"unresolvedReferences",{}),u(this,"resolvedReferences",{}),u(this,"pagesCounterExprs",[]),u(this,"pageCounterExprs",[]),u(this,"targetCounterExprs",[]),u(this,"targetTextExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new Xd(this,e)}createCounterResolver(e,t,i){return new qd(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=_s(this.currentPageCounters);let i,n=e["counter-reset"];if(n){let r=n.evaluate(t);r&&(i=Zi(r,!0))}if(i)for(let r in i)this.definePageCounter(r,i[r]);let s,o=e["counter-increment"];if(o){let r=o.evaluate(t);r&&(s=Zi(r,!1))}s?"page"in s||(s.page=1):(s={},s.page=1);for(let r in s){this.currentPageCounters[r]||this.definePageCounter(r,0);let a=this.currentPageCounters[r];a[a.length-1]+=s[r]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=_s(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 s=0;s<this.referencesToSolve.length;){let o=this.referencesToSolve[s];if(o.targetId===e){if(o.resolve(),this.referencesToSolve.splice(s,1),t){let r=t.indexOf(o);r>=0&&t.splice(r,1)}i.push(o),n=!0}else s++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new jd(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let o=_s(this.currentPageCounters);i.forEach(r=>{this.pageCountersById[r]=o;let a=this.currentPage.elementsById[r];if(a&&a.length>0){let l=a[0];this.pageTextById[r]={content:Ji(l,"content"),before:Ji(l,"before"),after:Ji(l,"after")}}let h=this.pageIndicesById[r];if(h&&h.pageIndex<t){let l=this.resolvedReferences[r];if(l){let c=this.unresolvedReferences[r];c||(c=this.unresolvedReferences[r]=[]);let p;for(;p=l.shift();)p.unresolve(),c.push(p)}}this.pageIndicesById[r]={spineIndex:e,pageIndex:t}})}let n=this.previousPageCounters,s;for(;s=this.newReferencesOfCurrentPage.shift();){s.pageCounters=n,s.spineIndex=e,s.pageIndex=t;let o;s.isResolved()?(o=this.resolvedReferences[s.targetId],o||(o=this.resolvedReferences[s.targetId]=[])):(o=this.unresolvedReferences[s.targetId],o||(o=this.unresolvedReferences[s.targetId]=[])),o.every(r=>!s.equals(r))&&o.push(s)}this.currentPage=null}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(s=>{let o=this.unresolvedReferences[s];o&&(t=t.concat(o))}),t.sort((s,o)=>s.spineIndex-o.spineIndex||s.pageIndex-o.pageIndex);let i=[],n=null;return t.forEach(s=>{!n||n.spineIndex!==s.spineIndex||n.pageIndex!==s.pageIndex?(n={spineIndex:s.spineIndex,pageIndex:s.pageIndex,pageCounters:s.pageCounters,refs:[s]},i.push(n)):n.refs.push(s)}),i}pushReferencesToSolve(e){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=e}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(e,t,i){e==="pages"?this.pagesCounterExprs.push({expr:i,format:t}):this.pageCounterExprs.push({expr:i,format:t})}registerTargetCounterExpr(e,t,i,n){this.targetCounterExprs.push({name:e,expr:i,format:t,transformedId:n})}registerTargetTextExpr(e,t,i){this.targetTextExprs.push({pseudoElement:e,expr:t,transformedId:i})}getExprContentListener(){return this.exprContentListener.bind(this)}exprContentListener(e,t,i){if(e instanceof Ie){if(e.str=="viv-leader"){let 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(`[${kt}="${t}"]`);if(!o||o.length===0)return null;let r=o[o.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(r),r.style.position="",r.style.visibility="",r}else if(e.str.startsWith("target-counter-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(Ds,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(Vs,e.key),o}}let n=this.pagesCounterExprs.findIndex(o=>o.expr===e)>=0,s=!n&&this.pageCounterExprs.findIndex(o=>o.expr===e)>=0;if(n||s){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(n?Ms:zs,e.key),o}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${zs}]`);for(let s of t){let o=s.getAttribute(zs),r=this.pageCounterExprs.find(c=>c.expr.key===o),a=(r?.expr).str,h=a?.replace(/^page-counters?-/,""),l=this.currentPageCounters[h];l&&(s.textContent=r.format(l))}let i=e.querySelectorAll(`[${Ds}]`);for(let s of i)s.setAttribute(la,!0);let n=e.querySelectorAll(`[${Vs}]`);for(let s of n)s.setAttribute(ha,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${Ms}]`),n=e.contentContainer.childElementCount;for(let r of i){let a=r.getAttribute(Ms),h=this.pagesCounterExprs.findIndex(l=>l.expr.key===a);h>=0,r.textContent=this.pagesCounterExprs[h].format([n])}let s=e.root.querySelectorAll(`[${la}]`);for(let r of s){let a=r.getAttribute(Ds),h=this.targetCounterExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageCountersById[h.transformedId];if(l){let c=l[h.name];c&&(r.textContent=h.format(c[c.length-1]))}}}let o=e.root.querySelectorAll(`[${ha}]`);for(let r of o){let a=r.getAttribute(Vs),h=this.targetTextExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageTextById[h.transformedId];l&&(r.textContent=(t=l[h.pseudoElement])!=null?t:"")}}}createLayoutConstraint(e){return new Kd(this,e)}},Ms="data-vivliostyle-pages-counter",zs="data-vivliostyle-page-counter",Ds="data-vivliostyle-target-counter",Vs="data-vivliostyle-target-text",la="data-vivliostyle-target-counter-in-running",ha="data-vivliostyle-target-text-in-running",Kd=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 Zd(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 Yt(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,Zd)}var Jd=class{constructor(){u(this,"type"),u(this,"precededBySpace",!1),u(this,"num",0),u(this,"text",""),u(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 Be(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 Et=[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];Et[NaN]=80;var St=[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];St[NaN]=43;var Qd=[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];St[NaN]=43;var ih=[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];ih[NaN]=35;var nh=[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];nh[NaN]=45;var no=[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];no[NaN]=37;var so=[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];so[NaN]=38;var Kt=Be(35,[61,36]),ep=Be(35,[58,77]),tp=Be(35,[61,36,124,50]),ip=Be(35,[38,51]),np=Be(35,[42,54]),sp=Be(39,[42,55]),op=Be(54,[42,55,47,56]),rp=Be(62,[62,82]),ap=Be(35,[61,36,33,70]),lp=Be(62,[45,71]),hp=Be(63,[45,81]),Us=Be(76,[10,72,13,72]),up=Be(39,[39,46,10,72,13,72,92,48]),cp=Be(39,[34,46,10,72,13,72,92,49]),dp=Be(39,[39,47,10,74,13,74,92,48]),pp=Be(39,[34,47,10,74,13,74,92,49]),ua=Be(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),fp=Be(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]),gp=Be(39,[39,68,10,74,13,74,92,75,NaN,67]),mp=Be(39,[34,68,10,74,13,74,92,75,NaN,67]),wp=Be(72,[9,39,10,39,13,39,32,39,41,69]),bp=15,yt=class{constructor(e,t){this.input=e,this.handler=t,u(this,"indexMask"),u(this,"buffer"),u(this,"tail",0),u(this,"curr",0),u(this,"position",0),this.indexMask=bp,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new Jd}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=Et,s=this.input,o=this.position,r=this.buffer,a=0,h=0,l="",c=0,p=!1,d=r[e],f=-9;for(;;){let m=s.charCodeAt(o);switch(n[m]||n[65]){case 72:l=s.substring(h,o),isNaN(m)?a=0:a=54,n=Et;break;case 1:o++,p=!0;continue;case 2:h=o++,n=no;continue;case 3:a=1,h=o++,n=St;continue;case 4:h=o++,a=31,n=Kt;continue;case 33:a=2,h=++o,n=up;continue;case 34:a=2,h=++o,n=cp;continue;case 6:h=++o,a=7,n=St;continue;case 7:h=o++,a=32,n=Kt;continue;case 8:h=o++,a=21;break;case 9:h=o++,a=32,n=ip;continue;case 10:h=o++,a=10;break;case 11:h=o++,a=11;break;case 12:h=o++,a=36,n=Kt;continue;case 13:h=o++,a=23;break;case 14:h=o++,a=16;break;case 15:a=24,h=o++,n=ih;continue;case 16:h=o++,n=Qd;continue;case 78:h=o++,a=9,n=St;continue;case 17:h=o++,a=19,n=np;continue;case 18:h=o++,a=18,n=ep;continue;case 77:o++,a=50;break;case 19:h=o++,a=17;break;case 20:h=o++,a=38,n=ap;continue;case 21:h=o++,a=39,n=Kt;continue;case 22:h=o++,a=37,n=Kt;continue;case 23:h=o++,a=22;break;case 24:h=++o,a=20,n=St;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=Us;continue;case 30:h=o++,a=33,n=Kt;continue;case 31:h=o++,a=34,n=tp;continue;case 32:h=o++,a=35,n=Kt;continue;case 35:break;case 36:o++,a=a+41-31;break;case 37:a=5,c=parseInt(s.substring(h,o),10);break;case 38:a=4,c=parseFloat(s.substring(h,o));break;case 39:o++;continue;case 40:a=3,c=parseFloat(s.substring(h,o)),h=o++,n=St;continue;case 41:a=3,c=parseFloat(s.substring(h,o)),l="%",h=o++;break;case 42:o++,n=so;continue;case 43:if(l=Yt(s.substring(h,o)),a===27&&m===63||a===1&&l.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(s.substring(o-1))){a=27,o++;continue}break;case 44:f=o++,n=Us;continue;case 45:l=Yt(s.substring(h,o));break;case 46:l=s.substring(h,o),o++;break;case 47:l=Yt(s.substring(h,o)),o++;break;case 48:f=o,o+=2,n=dp;continue;case 49:f=o,o+=2,n=pp;continue;case 50:o++,a=25;break;case 51:o++,a=26;break;case 52:if(l=s.substring(h,o),a==1){if(o++,l.toLowerCase()=="url"){n=ua;continue}a=6}break;case 53:if(l=Yt(s.substring(h,o)),a==1){if(o++,l.toLowerCase()=="url"){n=ua;continue}a=6}break;case 54:n=sp,o++;continue;case 55:n=op,o++;continue;case 56:n=Et,o++;continue;case 57:n=rp,o++,s[o]!==">"&&(a=1,n=St);continue;case 81:a=51,l=s.substring(h,++o),n=Et;break;case 82:a=52,l=s.substring(h,++o),n=Et;break;case 58:a=5,n=no,o++;continue;case 59:a=4,n=so,o++;continue;case 60:a=1,n=St,o++;continue;case 61:a=1,n=Us,f=o++;continue;case 62:o--;break;case 63:o-=2;break;case 64:h=o++,n=fp;continue;case 65:h=++o,n=gp;continue;case 66:h=++o,n=mp;continue;case 67:a=8,l=Yt(s.substring(h,o)),o++;break;case 69:o++;break;case 70:n=lp,o++;continue;case 71:n=hp,o++;continue;case 79:if(o-f<8&&s.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){o++;continue}case 68:a=8,l=Yt(s.substring(h,o)),o++,n=wp;continue;case 74:if(o++,o-f<9&&s.substring(f+1,o).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,l="E_CSS_UNEXPECTED_NEWLINE",n=Et;break;case 73:if(o-f<9&&s.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){o++,n=St;continue}l=Yt(s.substring(h,o));break;case 75:f=o++;continue;case 76:o++,n=nh;continue;default:if(n!==Et){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=o,a=0}if(d.type=a,d.precededBySpace=p,d.num=c,d.text=l,d.position=h,e++,e>=t)break;n=Et,p=!1,d=r[e&i]}this.position=o,this.tail=e&i}},Te=null,oo=null;function ro(){return Te}function F(e){if(!Te)throw new Error("E_TASK_NO_CONTEXT");Te.name||(Te.name=e);let t=Te,i=new ms(t,t.top,e);return t.top=i,i.state=1,i}function vp(e){return new Sp(e||new xp)}function P(e){return new ao(e)}function Ni(e,t,i){let n=F(e);n.handler=i;try{t(n)}catch(s){n.task.raise(s,n)}return n.result()}function yp(e,t){return(Te?Te.getScheduler():oo||vp()).run(e,t)}var xp=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Sp=class{constructor(e){this.timer=e,u(this,"timeout",1),u(this,"slice",25),u(this,"sliceOverTime",0),u(this,"queue"),u(this,"wakeupTime",null),u(this,"timeoutToken",null),u(this,"inTimeSlice",!1),u(this,"order",0),this.queue=new td,oo||(oo=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){H.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new Cp(this,t||"");i.top=new ms(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let s=()=>{i.running=!1;for(let o of i.callbacks)try{o()}catch(r){H.error(r)}};try{e().then(o=>{i.result=o,s()})}catch(o){i.raise(o),s()}});let n=Te;return Te=i,this.schedule(i.top.suspend("bootstrap")),Te=n,i}},sh=class{constructor(e){this.task=e,u(this,"scheduledTime",0),u(this,"order",0),u(this,"result",null),u(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=Te;return Te=e,e.top.finish(this.result),Te=t,!0}return!1}cancel(){this.canceled=!0}},Cp=class{constructor(e,t){this.scheduler=e,this.name=t,u(this,"callbacks",[]),u(this,"exception",null),u(this,"running",!0),u(this,"result",null),u(this,"waitTarget",null),u(this,"top",null),u(this,"continuation",null)}getName(){return this.name}interrupt(e){if(this.raise(e||new Error("E_TASK_INTERRUPT")),this!==Te&&this.continuation){this.continuation.cancel();let t=new sh(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=F("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&&H.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 H=new up,qs=(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))(qs||{}),Ts={};function kt(e,t,i){if(!qs[e])H.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=Ts[e];n||(n=Ts[e]=[]),i?n.unshift(t):n.push(t)}}function kh(e,t){if(!qs[e])H.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=Ts[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function At(e){return Ts[e]||[]}var cp={registerHook:kt,removeHook:kh},Eh=class{constructor(e){this.performanceInstance=e,c(this,"timestamps",{}),c(this,"registerTiming"),c(this,"registerStartTiming"),c(this,"registerEndTiming"),this.registerTiming=xi,this.registerStartTiming=this.registerStartTiming=xi,this.registerEndTiming=this.registerEndTiming=xi}forceRegisterStartTiming(e,t){pr.call(this,e,"start",t)}forceRegisterEndTiming(e,t){pr.call(this,e,"end",t)}printTimings(){let e=this.timestamps,t="";Object.keys(e).forEach(i=>{let n=e[i],s=n.length;for(let r=0;r<s;r++){let o=n[r];t+=i,s>1&&(t+=`(${r})`),t+=` => start: ${o.start}, end: ${o.end}, duration: ${o.end-o.start}
|
|
4
|
+
`}}),H.info(t)}disable(){this.registerTiming=xi,this.registerStartTiming=this.registerStartTiming=xi,this.registerEndTiming=this.registerEndTiming=xi}enable(){this.registerTiming=pr,this.registerStartTiming=this.registerStartTiming=Da,this.registerEndTiming=this.registerEndTiming=dp}isEnabled(){return this.registerStartTiming===Da}};function xi(){}function pr(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let s,r=n.length;for(let o=r-1;o>=0&&(s=n[o],!(s&&!s[t]));o--)s=null;s||(s={},n.push(s)),s[t]=i}function Da(e,t){this.registerTiming(e,"start",t)}function dp(e,t){this.registerTiming(e,"end",t)}var pp={now:Date.now},fp=window&&window.performance,ct=new Eh(fp||pp);ct.forceRegisterStartTiming("load_vivliostyle");var gp={profiler:{registerStartTiming:ct.registerStartTiming,registerEndTiming:ct.registerEndTiming,printTimings:ct.printTimings,disable:ct.disable,enable:ct.enable}},Nh=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",Is=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,Mt="data-adapt-eloff",mp={};function Xo(e){return JSON.parse(e)}function Dt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function wp(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var Wi=window.location.href;function Va(e){Wi=e}var Qt=window.location.href;function Ua(e){Qt=e}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(/^\//))return i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e;if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=wp(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let s=t.substr(0,n+1)+e,r="";for(i=s.match(/^([^?#]*)([?#].*)$/),i&&(s=i[1],r=i[2]);n=s.indexOf("/../"),!(n<=0);){let o=s.lastIndexOf("/",n-1);if(o<=0)break;s=s.substr(0,o)+s.substr(n+3)}return s.replace(/\/(\.\/)+/g,"/")+r}function In(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 Ha(e){return e==null?e:e.toString()}var bp=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 s=n*2;if(s>=i)break;if(this.queue[s].compare(t)>0)s+1<i&&this.queue[s+1].compare(this.queue[s])>0&&s++;else if(s+1<i&&this.queue[s+1].compare(t)>0)s++;else break;this.queue[n]=this.queue[s],n=s}this.queue[n]=t}return e}},Ph=["","-webkit-","-moz-"],Ci={};function fr(e,t){return CSS.supports(e+t,"unset")}function yp(e){let t=Ci[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return Ci[e]=null,null;case"text-combine-upright":if(fr("-webkit-","text-combine")&&!fr("","text-combine-upright"))return Ci[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of Ph)if(fr(i,e))return t=[i+e],Ci[e]=t,t;return H.warn("Property not supported by the browser: ",e),Ci[e]=null,null}function T(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let s=yp(t);if(s)for(let r of s){switch(r){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(r,i)}}function Kt(e,t,i){try{let n=Ci[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function _r(e){let t=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!t&&e.namespaceURI=="http://www.w3.org/1999/xhtml"&&(t=e.getAttribute("lang")),t}var ii=class{constructor(){c(this,"list",[])}append(e){return this.list.push(e),this}clear(){this.list=[]}toString(){let e=this.list.join("");return this.list=[e],e}};function Th(e){return`\\${e.charCodeAt(0).toString(16)} `}function ei(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Th)}function Dn(e){return e.replace(/[\u0000-\u001F"\\]/g,Th)}function $a(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Wa(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function vp(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function Ih(e,t){function i(n){return vp(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function qt(e){return Ih(e)}function xp(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function Sp(e,t){t=typeof t=="string"?t:"\\u";function i(s){return xp(s,t)}let n=new RegExp(`${qt(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function ni(e,t){let i=0,n=e;for(;;){if(i<=n,i==0||t(i-1),n==e||t(n),i==n)return i;let s=i+n>>1;t(s)?n=s:i=s+1}}function Ah(e,t){return e-t}function Ga(e,t){let i={};for(let n of e){let s=t(n);s&&!i[s]&&(i[s]=n)}return i}function Cp(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function gr(e,t){let i={};for(let n of e){let s=t(n);s&&(i[s]?i[s].push(n):i[s]=[n])}return i}function kp(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var qo=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 s=n.indexOf(t);s>=0&&n.splice(s,1)}}},gi={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function Rh(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function Ep(e){return`^${e}`}function ja(e){return e.replace(/[\[\]\(\),=;^]/g,Ep)}function Np(e){return e.substr(1)}function Mr(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,Np)}function Pp(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=Mr(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function Xa(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=Pp(i[2]),e=e.substr(i[0].length)}return t}var qa=class{appendTo(e){e.append("!")}applyTo(e){return!1}},Ya=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,s,r=Math.floor(this.index/2)-1;if(r<0||n==0)s=t.firstChild,e.node=s||t;else{if(s=i[Math.min(r,n-1)],this.index&1){let o=s.nextSibling;!o||o.nodeType==1?e.after=!0:s=o}e.node=s}if(this.id&&(e.after||this.id!=Rh(e.node))){let o=t.ownerDocument.getElementById(this.id);o?e.node=o:H.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},Ka=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 s=i.nextSibling;if(3<=n&&n<=5){let r=i.textContent.length;if(t<=r)break;if(!s){t=r;break}t-=r}if(!s){t=0;break}i=s}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(ja(this.textBefore)),e.append(","),this.textAfter&&e.append(ja(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Za=class Fh{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]),s=0,r=[];for(;;){let o;switch(n.charAt(s)){case"/":{if(s++,i=n.substr(s).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");s+=i[0].length;let a=parseInt(i[1],10),l=i[3];o=Xa(i[4]),r.push(new Ya(a,l,Ha(o.s)));break}case":":{if(s++,i=n.substr(s).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");s+=i[0].length;let a=parseInt(i[1],10),l=i[4];l&&(l=Mr(l));let h=i[7];h&&(h=Mr(h)),o=Xa(i[10]),r.push(new Ka(a,l,h,Ha(o.s)));break}case"!":s++,r.push(new qa);break;case"~":case"@":case"":this.steps=r;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 Fh,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,s){let r=[],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),r.push(new Ka(i,a,l,s)),s=null);o&&!(!o||o.nodeType==9);){let h=n?null:Rh(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;r.push(new Ya(u,h,s)),s=null,t=o,o=o.parentNode,n=!1}r.reverse(),this.steps?(r.push(new qa),this.steps=r.concat(this.steps)):this.steps=r}toString(){if(!this.steps)return"";let t=new ii;t.append("epubcfi(");for(let i=0;i<this.steps.length;i++)this.steps[i].appendTo(t);return t.append(")"),t.toString().replace(/%/g,"%25")}};function Lh(){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 Bh(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 Tp=Lh(),Ja={PENDING:{}};function Oh(e,t,i,n){let s=Math.min((e-0)/i,(t-0)/n);return`matrix(${s},0,0,${s},0,0)`}function mr(e){return`"${Dn(`${e}`)}"`}function Ip(e){return ei(`${e}`)}function zr(e,t){return e?`${ei(e)}.${ei(t)}`:ei(t)}var _h=0,Dr=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${_h++}`,this.zero=new He(this,0),this.one=new He(this,1),this._true=new He(this,!0),this._false=new He(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=Oh,i["css-string"]=mr,i["css-name"]=Ip,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 mr(this.pubTitle?this.pubTitle:"")}),this.defineBuiltInName("doc-title",function(){return mr(this.docTitle?this.docTitle:"")})}}defineBuiltInName(e,t){this.values[e]=new Me(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 Ap(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function Mh(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 Rp(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function Fp(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var Tt={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 zh(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 Vr=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=Tp}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(Mh(e)){let n=this.pageWidth()/100,s=this.pageHeight()/100,r=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,o=this.pageAreaHeight!=null?this.pageAreaHeight/100:s,a=i??this.pageVertical;switch(e){case"vw":return r;case"vh":return o;case"vi":return a?o:r;case"vb":return a?r:o;case"vmin":return r<o?r:o;case"vmax":return r>o?r:o;case"pvw":return n;case"pvh":return s;case"pvi":return a?s:n;case"pvb":return a?n:s;case"pvmin":return n<s?n:s;case"pvmax":return n>s?n:s}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="lh"||e=="rlh"?this.rootLineHeight:Tt[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 s=e.funcs[t];if(s||e.resolver&&(s=e.resolver.call(this,t,!0),s))return s;let r=e.builtIns[t];if(r){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 He(e,r.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 s=null,r=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(s=t.evaluate(this));break}switch(e){case"width":r=this.pageWidth();break;case"height":r=this.pageHeight();break;case"device-width":r=window.screen.availWidth;break;case"device-height":r=window.screen.availHeight;break;case"color":r=window.screen.pixelDepth;break}if(r!=null&&s!=null)switch(i){case"min":return r>=Number(s);case"max":return r<=Number(s);default:return r==s}else if(r!=null&&t==null)return r!==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}},Nt=class{constructor(e){this.scope=e,c(this,"key"),this.scope=e,this.key=`_${_h++}`}toString(){let e=new ii;return this.appendTo(e,0),e.toString()}appendTo(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){throw new Error("F_ABSTRACT")}expand(e,t){return this}dependCore(e,t,i){return e===this}dependOuter(e,t,i){let n=i[this.key];if(n!=null)return n===Ja.PENDING?!1:n;{i[this.key]=Ja.PENDING;let s=this.dependCore(e,t,i);return i[this.key]=s,s}}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}},Dh=class extends Nt{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)}},Ys=class extends Nt{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)}},Vh=class extends Ys{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Ki=class extends Ys{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},Uh=class extends Ys{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},Yo=class extends Ys{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},ti=class extends Dh{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},Lp=class extends ti{constructor(e,t){super(e,t)}getOp(){return"not "}},Ai=class extends Dh{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},Ko=class extends Vh{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},Bp=class extends Ko{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},Zo=class extends Vh{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},Op=class extends Zo{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},_p=class extends Zo{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},Mp=class extends Ki{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},zp=class extends Ki{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},Dp=class extends Ki{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},Ur=class extends Ki{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Jo=class extends Ki{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},Vp=class extends Ki{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},Hh=class extends Uh{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},$h=class extends Uh{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},Qo=class extends Yo{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},Wh=class extends Yo{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},Gh=class extends Yo{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},Vn=class extends Nt{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(ei(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},ze=class extends Nt{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)}},Qa=class extends Nt{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(ei(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},Me=class extends Nt{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 Up(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function Hp(e,t,i){let n=t;for(let s=0;s<t.length;s++){let r=t[s].expand(e,i);if(t!==n)n[s]=r;else if(r!==t[s]){n=Array(t.length);for(let o=0;o<s;o++)n[o]=t[o];n[s]=r}}return n}var wn=class jh extends Nt{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),Up(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 s=0;s<this.params.length;s++)if(this.params[s].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=Hp(t,this.params,i);return n===this.params?this:new jh(this.scope,this.qualifiedName,n)}},$p=class Xh extends Nt{constructor(t,i,n,s){super(t),this.cond=i,this.ifTrue=n,this.ifFalse=s}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),s=this.ifTrue.expand(t,i),r=this.ifFalse.expand(t,i);return n===this.cond&&s===this.ifTrue&&r===this.ifFalse?this:new Xh(this.scope,n,s,r)}},He=class extends Nt{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(Dn(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},el=class qh extends Nt{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(Dn(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 qh(this.scope,this.name,n)}},Wp=class extends Nt{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)}},Yh=class extends Nt{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 Ct(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 Ko(e,t,i)}function Y(e,t,i){return t===e.zero?i:i===e.zero?t:new Hh(e,t,i)}function pe(e,t,i){return t===e.zero?new Ai(e,i):i===e.zero?t:new $h(e,t,i)}function us(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new Qo(e,t,i)}function Hr(e,t,i){return t===e.zero?e.zero:i===e.one?t:new Wh(e,t,i)}var Xt=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}},Zi=class extends Xt{constructor(){super(),c(this,"error",!1)}visitValues(e){let t=null;for(let i=0;i<e.length;i++){let n=e[i],s=n.visit(this);if(this.error)return[];if(t)t[i]=s;else if(n!==s){t=new Array(e.length);for(let r=0;r<i;r++)t[r]=e[r];t[i]=s}}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?j:t===e.values?e:new Q(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?j:t===e.values?e:new qe(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?j:t===e.values?e:new Ji(e.name,t)}visitExpr(e){return e}},Ye=class{toString(){let e=new ii;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new ii;return this.appendTo(e,!1),e.toString()}toExpr(e,t){return null}appendTo(e,t){e.append("[error]")}isExpr(){return!1}isNumeric(){return!1}isNum(){return!1}isIdent(){return!1}isSpaceList(){return!1}visit(e){return this}},Kh=class Zh extends Ye{static get instance(){return this.empty||(this.empty=new Zh),this.empty}constructor(){super()}toExpr(t,i){return new He(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};c(Kh,"empty");var Gp=Kh,j=Gp.instance,Jh=class Qh extends Ye{static get instance(){return this.slash||(this.slash=new Qh),this.slash}constructor(){super()}toExpr(t,i){return new He(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};c(Jh,"slash");var jp=Jh,Ks=jp.instance,G=class extends Ye{constructor(e){super(),this.str=e}toExpr(e,t){return new He(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(Dn(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},$r={},ae=class extends Ye{constructor(e){if(super(),this.name=e,$r[e])throw new Error("E_INVALID_CALL");$r[e]=this}toExpr(e,t){return new He(e,this.name)}appendTo(e,t){t?e.append(ei(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function F(e){let t=$r[e];return t||(t=new ae(e)),t}var A=class extends Ye{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 Qo(e,t,new He(e,this.num/100)):new Vn(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}},Ht=class extends Ye{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new He(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},Re=class extends Ht{constructor(e){super(e)}visit(e){return e.visitInt(this)}},eu=class extends Ye{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},Ke=class extends Ye{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(Dn(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},tu=class extends Ye{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function ea(e,t,i,n){var s,r;let o=t.length;if(o>0){(s=t[0])==null||s.appendTo(e,n);for(let a=1;a<o;a++)e.append(i),(r=t[a])==null||r.appendTo(e,n)}}var Q=class extends Ye{constructor(e){super(),this.values=e}appendTo(e,t){ea(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},qe=class extends Ye{constructor(e){super(),this.values=e}appendTo(e,t){ea(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},Ji=class extends Ye{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(ei(this.name)),e.append("("),ea(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},U=class extends Ye{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof He||this.expr instanceof Vn?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 Ye{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function Je(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 iu(e,t){return new A(Je(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")},tl=new A(100,"%"),Un=new A(100,"pvw"),Hn=new A(100,"pvh"),ke=new A(0,"px"),m0=new tu("U+0-10FFFF"),il={"font-size":1,"line-height":2,color:3};function J(e){return e===b.inherit||e===b.initial||e===b.revert||e===b.unset}function nl(e,t){let i=il[e]||Number.MAX_VALUE,n=il[t]||Number.MAX_VALUE;return i-n}function $t(e){return e?.length>2&&e.startsWith("--")}var bt=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},Zt=class{constructor(e,t){this.x=e,this.y=t}},wr=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}},Vt=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 Xp(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var Zs=class nu{constructor(t){this.points=t}addSegments(t,i){let n=this.points,s=n.length,r=n[s-1];for(let o=0;o<s;o++){let a=n[o],l;r.y<a.y?l=new sl(r,a,1,i):l=new sl(a,r,-1,i),t.push(l),r=a}}withOffset(t,i){let n=[];for(let s of this.points)n.push(new Zt(s.x+t,s.y+i));return new nu(n)}};function rl(e,t,i,n){let s=[];for(let r=0;r<20;r++){let o=r*2*Math.PI/20;s.push(new Zt(e+i*Math.sin(o),t+n*Math.cos(o)))}return new Zs(s)}function ta(e,t,i,n){return new Zs([new Zt(e,t),new Zt(i,t),new Zt(i,n),new Zt(e,n)])}var is=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function ol(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 qp(e,t,i,n){let s,r,o,a;t.high.y<i&&H.warn("Error: inconsistent segment (1)"),t.low.y<=i?(s=ol(t,i),r=t.winding):(s=t.low.x,r=0),t.high.y>=n?(o=ol(t,n),a=t.winding):(o=t.high.x,a=0),s<o?(e.push(new is(s,r,t.shapeId,-1)),e.push(new is(o,a,t.shapeId,1))):(e.push(new is(o,a,t.shapeId,-1)),e.push(new is(s,r,t.shapeId,1)))}function Yp(e,t,i){let n=t+i,s=Array(n),r=Array(n),o;for(o=0;o<=n;o++)s[o]=0,r[o]=0;let a=[],l=!1,h=e.length;for(let u=0;u<h;u++){let d=e[u];s[d.shapeId]+=d.winding,r[d.shapeId]+=d.lowOrHigh;let p=!1;for(o=0;o<t;o++)if(s[o]&&!r[o]){p=!0;break}if(p){for(o=t;o<=n;o++)if(s[o]||r[o]){p=!1;break}}l!=p&&(a.push(d.x),l=p)}return a}function Kp(e,t){return t?Math.ceil(e/t)*t:e}function al(e,t){return t?Math.floor(e/t)*t:e}function Zp(e){return new Zt(e.y,-e.x)}function As(e){return new bt(e.y1,-e.x2,e.y2,-e.x1)}function su(e){return new bt(-e.y2,e.x1,-e.y1,e.x2)}function ll(e){return new Zs(e.points.map(t=>Zp(t)))}function Jp(e,t,i,n,s,r){r&&(e=As(e),t=t.map(y=>ll(y)),i=i.map(y=>ll(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(Xp);let m=0;for(;h[m].shapeId>=o;)m++;let g=h[m].low.y;g>e.y1&&l.push(new Vt(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(Kp(Math.ceil(g+n),s),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(al(p.high.y,s),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 V=al(p.low.y,s);V<y&&(y=V);break}}let E=[];for(d=0;d<v.length;d++)qp(E,v[d],g,y);E.sort((V,D)=>V.x-D.x||V.lowOrHigh-D.lowOrHigh);let I=Yp(E,o,a);if(I.length==0)l.push(new Vt(g,y,e.x2,e.x2));else{let V=0,D=e.x1;for(d=0;d<I.length;d+=2){let te=Math.max(e.x1,I[d]),re=Math.min(e.x2,I[d+1])-te;re>V&&(V=re,D=te)}V==0?l.push(new Vt(g,y,e.x2,e.x2)):l.push(new Vt(g,y,Math.max(D,e.x1),Math.min(D+V,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 ru(e,l),l}function ru(e,t){let i=t.length-1,n=new Vt(e.y2,e.y2,e.x1,e.x2);for(;i>=0;){let s=n;n=t[i],(n.y2-n.y1<1||n.x1==s.x1&&n.x2==s.x2)&&(s.y1=n.y1,t.splice(i,1),n=s),i--}}function ou(e,t){let i=0,n=e.length;for(;i<n;){let s=Math.floor((i+n)/2);t>=e[s].y2?i=s+1:n=s}return i}function Qp(e,t){if(!e.length)return t;let i=t.y1,n,s;for(s=0;s<e.length&&(n=e[s],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));s++)i=Math.max(i,n.y2);let r=i;for(;s<e.length&&(n=e[s],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));s++)r=n.y2;return s===e.length?r=t.y2:r=Math.min(r,t.y2),r<=i?null:new bt(t.x1,i,t.x2,r)}function ef(e,t){if(!e.length)return t;let i=t.y2,n,s;for(s=e.length-1;s>=0&&(n=e[s],!(s===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);s--)i=Math.min(i,n.y1);let r=Math.min(i,n.y2);for(;s>=0&&(n=e[s],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));s--)r=n.y1;return r=Math.max(r,t.y1),i<=r?null:new bt(t.x1,r,t.x2,i)}function tf(e,t,i,n){let s=i.y1,r=i.x2-i.x1,o=i.y2-i.y1,a=ou(t,s);for(;;){let l=s+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+r<=u||a>=t.length)return n=="left"?(i.x1=h,i.x2=h+r):(i.x1=u-r,i.x2=u),i.y2+=s-i.y1,i.y1=s,!0;s=t[a].y2,a++}}function nf(e,t,i,n,s){for(n||(n=[new Vt(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 r,o=t.length==0?e.y1:t[t.length-1].y2;o<e.y2&&t.push(new Vt(o,e.y2,e.x1,e.x2));let a=ou(t,n[0].y1);for(let l of n){if(a==t.length)break;for(t[a].y1<l.y1&&(r=t[a],a++,t.splice(a,0,new Vt(l.y1,r.y2,r.x1,r.x2)),r.y2=l.y1);a<t.length&&(r=t[a++],r.y2>l.y2&&(t.splice(a,0,new Vt(l.y2,r.y2,r.x1,r.x2)),r.y2=l.y2),l.x1!=l.x2&&(s=="left"?r.x1=Math.min(l.x2,e.x2):r.x2=Math.max(l.x1,e.x1)),r.y2!=l.y2););}ru(e,t)}var sf=class extends Xt{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 sf;try{return e.visit(t),t.propSet}catch(i){H.warn(i,"toSet:")}}return{}}var of=class extends Xt{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function hl(e,t){if(e){let i=new of(t);try{return e.visit(i),i.value}catch(n){H.warn(n,"toInt: ")}}return t}var af=class extends Xt{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 A(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,s){if(this.coords.length>0){let r=[];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)),r.push(o.num*l/100)}else r.push(o.num*s.queryUnitSize(o.unit,!1))}),this.name){case"polygon":if(r.length%2==0){let o=[];for(let a=0;a<r.length;a+=2)o.push(new Zt(e+r[a],t+r[a+1]));return new Zs(o)}break;case"rectangle":if(r.length==4)return ta(e+r[0],t+r[1],e+r[0]+r[2],t+r[1]+r[3]);break;case"ellipse":if(r.length==4)return rl(e+r[0],t+r[1],r[2],r[3]);break;case"circle":if(r.length==3)return rl(e+r[0],t+r[1],r[2],r[2]);break}}return null}};function au(e,t,i,n,s,r){if(e){let o=new af;try{return e.visit(o),o.getShape(t,i,n,s,r)}catch(a){H.warn(a,"toShape:")}}return ta(t,i,t+n,i+s)}var lf=class extends Xt{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 lf(t);try{e.visit(i)}catch(n){H.warn(n,"toCounters:")}return i.counters}var hf=class extends Zi{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new Ke(this.transformer.transformURL(e.url,this.baseUrl))}};function br(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function Ri(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 uf=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}},cf=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()}},df=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(Ne(e,this.baseURL),this.baseURL);return t.charAt(0)==="#"&&(t=t.substring(1)),t}getPageCounterVal(e,t){let i=()=>{let r=this.counterStore.currentPageCounters[e];return r&&r.length?r[r.length-1]:null},n=new Me(this.pageScope,()=>t(i()),`page-counter-${e}`),s=r=>t(r[r.length-1]);return this.counterStore.registerPageCounterExpr(e,s,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new Me(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"?Ri(n,t):Ri(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),s=this.getTransformedId(e),r=this.getTargetCounters(n,s,!1);if(r&&r[t]){let a=r[t];return new He(this.rootScope,i(a[a.length-1]||null))}let o=new Me(this.pageScope,()=>{if(r=this.getTargetCounters(n,s,!0),r)if(r[t]){let a=r[t];return i(a[a.length-1]||null)}else{let a=this.getTargetPageCounters(s);if(a)if(this.counterStore.resolveReference(s),a[t]){let l=a[t];return i(l[l.length-1]||null)}else return i(0);else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"},`target-counter-${t}-of-${e}`);return this.counterStore.registerTargetCounterExpr(t,i,o,s),o}getTargetCountersVal(e,t,i){let n=this.getFragment(e),s=this.getTransformedId(e);return new Me(this.pageScope,()=>{let r=this.getTargetPageCounters(s);if(r){this.counterStore.resolveReference(s);let o=r[t]||[],a=this.getTargetCounters(n,s,!0)[t]||[];return i(o.concat(a))}else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"},`target-counters-${t}-of-${e}`)}getTargetTextVal(e,t){let i=this.getTransformedId(e),n=new Me(this.pageScope,()=>{if(t==="first-letter"){let r=this.getTargetPageText(i,"before"),o=this.getTargetPageText(i,"content"),a=this.getTargetPageText(i,"after");if(r===null&&o===null&&a===null)return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??";let l=(r??"")+(o??"")+(a??"");this.counterStore.resolveReference(i);let h=l.match(Is);return h?h[0]:""}let s=this.getTargetPageText(i,t);return s!==null?(this.counterStore.resolveReference(i),s):(this.counterStore.saveReferenceOfCurrentPage(i,!1),"??")},`target-text-${t}-of-${e}`);return this.counterStore.registerTargetTextExpr(t,n,i),n}getNamedStringVal(e,t){return new Me(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new Me(this.pageScope,()=>this.getRunningValue(this.runningElements,e,t),`running-element-${t}-${e}`)}getRunningValue(e,t,i){let n=e[t];if(!n)return"";let s=Object.keys(n).map(p=>parseInt(p,10)).sort(Ah),r=this.counterStore.currentPage,o=r.isBlankPage?r.offset-1:r.offset,a=r.isBlankPage?o:Math.max(o,...Array.from(r.container.querySelectorAll(`[${Mt}]`)).map(p=>parseInt(p.getAttribute(Mt),10))),l=-1,h=-1,u=-1,d=-1;for(let p=0;p<s.length;p++){let f=s[p],m=p>0?s[p-1]:-1,g=p<s.length-1?s[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=r.container.querySelector(`[${Mt}="${f}"]`);if(!w)h<0&&(h=f);else{let v=r.container.querySelector(`[${Mt}="${o}"]`);if(v||(v=r.container.querySelector(`[${Mt}="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)}},pf=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 cf(this,e)}createCounterResolver(e,t,i){return new df(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=br(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 s,r=e["counter-increment"];if(r){let o=r.evaluate(t);o&&(s=bn(o,!1))}s?"page"in s||(s.page=1):(s={},s.page=1);for(let o in s){this.currentPageCounters[o]||this.definePageCounter(o,0);let a=this.currentPageCounters[o];a[a.length-1]+=s[o]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=br(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 s=0;s<this.referencesToSolve.length;){let r=this.referencesToSolve[s];if(r.targetId===e){if(r.resolve(),this.referencesToSolve.splice(s,1),t){let o=t.indexOf(r);o>=0&&t.splice(o,1)}i.push(r),n=!0}else s++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new uf(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let r=br(this.currentPageCounters);i.forEach(o=>{this.pageCountersById[o]=r;let a=this.currentPage.elementsById[o];if(a&&a.length>0){let h=a[0];this.pageTextById[o]={content:Ri(h,"content"),before:Ri(h,"before"),after:Ri(h,"after"),marker:Ri(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,s;for(;s=this.newReferencesOfCurrentPage.shift();){s.pageCounters=n,s.spineIndex=e,s.pageIndex=t;let r;s.isResolved()?(r=this.resolvedReferences[s.targetId],r||(r=this.resolvedReferences[s.targetId]=[])):(r=this.unresolvedReferences[s.targetId],r||(r=this.unresolvedReferences[s.targetId]=[])),r.every(o=>!s.equals(o))&&r.push(s)}this.currentPage=null}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(s=>{let r=this.unresolvedReferences[s];r&&(t=t.concat(r))}),t.sort((s,r)=>s.spineIndex-r.spineIndex||s.pageIndex-r.pageIndex);let i=[],n=null;return t.forEach(s=>{!n||n.spineIndex!==s.spineIndex||n.pageIndex!==s.pageIndex?(n={spineIndex:s.spineIndex,pageIndex:s.pageIndex,pageCounters:s.pageCounters,refs:[s]},i.push(n)):n.refs.push(s)}),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 Me){if(e.str=="viv-leader"){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute("data-viv-leader",e.key),r.setAttribute("data-viv-leader-value",t),r}else if(e.str.startsWith("running-element-")){let r=t&&i.querySelectorAll(`[${Mt}="${t}"]`);if(!r||r.length===0)return null;let o=r[r.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(o),o.style.position="",o.style.visibility="",o}else if(e.str.startsWith("target-counter-")){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute(xr,e.key),r}else if(e.str.startsWith("target-text-")){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute(Sr,e.key),r}}let n=this.pagesCounterExprs.findIndex(r=>r.expr===e)>=0,s=!n&&this.pageCounterExprs.findIndex(r=>r.expr===e)>=0;if(n||s){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute(n?yr:vr,e.key),r}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${vr}]`);for(let s of t){let r=s.getAttribute(vr),o=this.pageCounterExprs.find(u=>u.expr.key===r),a=(o?.expr).str,l=a?.replace(/^page-counters?-/,""),h=this.currentPageCounters[l];h&&(s.textContent=o.format(h))}let i=e.querySelectorAll(`[${xr}]`);for(let s of i)s.setAttribute(ul,!0);let n=e.querySelectorAll(`[${Sr}]`);for(let s of n)s.setAttribute(cl,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${yr}]`),n=e.contentContainer.childElementCount;for(let o of i){let a=o.getAttribute(yr),l=this.pagesCounterExprs.findIndex(h=>h.expr.key===a);l>=0,o.textContent=this.pagesCounterExprs[l].format([n])}let s=e.root.querySelectorAll(`[${ul}]`);for(let o of s){let a=o.getAttribute(xr),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 r=e.root.querySelectorAll(`[${cl}]`);for(let o of r){let a=o.getAttribute(Sr),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 ff(this,e)}},yr="data-vivliostyle-pages-counter",vr="data-vivliostyle-page-counter",xr="data-vivliostyle-target-counter",Sr="data-vivliostyle-target-text",ul="data-vivliostyle-target-counter-in-running",cl="data-vivliostyle-target-text-in-running",ff=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 gf(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 li(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,gf)}var mf=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 $e(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 _t=[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];_t[NaN]=80;var Ft=[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];Ft[NaN]=43;var wf=[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];Ft[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 hu=[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];hu[NaN]=45;var Wr=[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];Wr[NaN]=37;var Gr=[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];Gr[NaN]=38;var hi=$e(35,[61,36]),bf=$e(35,[58,77]),yf=$e(35,[61,36,124,50]),vf=$e(35,[38,51]),xf=$e(35,[42,54]),Sf=$e(39,[42,55]),Cf=$e(54,[42,55,47,56]),kf=$e(62,[62,82]),Ef=$e(35,[61,36,33,70]),Nf=$e(62,[45,71]),Pf=$e(63,[45,81]),Cr=$e(76,[10,72,13,72]),Tf=$e(39,[39,46,10,72,13,72,92,48]),If=$e(39,[34,46,10,72,13,72,92,49]),Af=$e(39,[39,47,10,74,13,74,92,48]),Rf=$e(39,[34,47,10,74,13,74,92,49]),dl=$e(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),Ff=$e(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]),Lf=$e(39,[39,68,10,74,13,74,92,75,NaN,67]),Bf=$e(39,[34,68,10,74,13,74,92,75,NaN,67]),Of=$e(72,[9,39,10,39,13,39,32,39,41,69]),_f=15,Rt=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=_f,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new mf}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=_t,s=this.input,r=this.position,o=this.buffer,a=0,l=0,h="",u=0,d=!1,p=o[e],f=-9;for(;;){let m=s.charCodeAt(r);switch(n[m]||n[65]){case 72:h=s.substring(l,r),isNaN(m)?a=0:a=54,n=_t;break;case 1:r++,d=!0;continue;case 2:l=r++,n=Wr;continue;case 3:a=1,l=r++,n=Ft;continue;case 4:l=r++,a=31,n=hi;continue;case 33:a=2,l=++r,n=Tf;continue;case 34:a=2,l=++r,n=If;continue;case 6:l=++r,a=7,n=Ft;continue;case 7:l=r++,a=32,n=hi;continue;case 8:l=r++,a=21;break;case 9:l=r++,a=32,n=vf;continue;case 10:l=r++,a=10;break;case 11:l=r++,a=11;break;case 12:l=r++,a=36,n=hi;continue;case 13:l=r++,a=23;break;case 14:l=r++,a=16;break;case 15:a=24,l=r++,n=lu;continue;case 16:l=r++,n=wf;continue;case 78:l=r++,a=9,n=Ft;continue;case 17:l=r++,a=19,n=xf;continue;case 18:l=r++,a=18,n=bf;continue;case 77:r++,a=50;break;case 19:l=r++,a=17;break;case 20:l=r++,a=38,n=Ef;continue;case 21:l=r++,a=39,n=hi;continue;case 22:l=r++,a=37,n=hi;continue;case 23:l=r++,a=22;break;case 24:l=++r,a=20,n=Ft;continue;case 25:l=r++,a=14;break;case 26:l=r++,a=15;break;case 27:l=r++,a=12;break;case 28:l=r++,a=13;break;case 29:l=r++,f=l,a=1,n=Cr;continue;case 30:l=r++,a=33,n=hi;continue;case 31:l=r++,a=34,n=yf;continue;case 32:l=r++,a=35,n=hi;continue;case 35:break;case 36:r++,a=a+41-31;break;case 37:a=5,u=parseInt(s.substring(l,r),10);break;case 38:a=4,u=parseFloat(s.substring(l,r));break;case 39:r++;continue;case 40:a=3,u=parseFloat(s.substring(l,r)),l=r++,n=Ft;continue;case 41:a=3,u=parseFloat(s.substring(l,r)),h="%",l=r++;break;case 42:r++,n=Gr;continue;case 43:if(h=li(s.substring(l,r)),a===27&&m===63||a===1&&h.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(s.substring(r-1))){a=27,r++;continue}break;case 44:f=r++,n=Cr;continue;case 45:h=li(s.substring(l,r));break;case 46:h=s.substring(l,r),r++;break;case 47:h=li(s.substring(l,r)),r++;break;case 48:f=r,r+=2,n=Af;continue;case 49:f=r,r+=2,n=Rf;continue;case 50:r++,a=25;break;case 51:r++,a=26;break;case 52:if(h=s.substring(l,r),a==1){if(r++,h.toLowerCase()=="url"){n=dl;continue}a=6}break;case 53:if(h=li(s.substring(l,r)),a==1){if(r++,h.toLowerCase()=="url"){n=dl;continue}a=6}break;case 54:n=Sf,r++;continue;case 55:n=Cf,r++;continue;case 56:n=_t,r++;continue;case 57:n=kf,r++,s[r]!==">"&&(a=1,n=Ft);continue;case 81:a=51,h=s.substring(l,++r),n=_t;break;case 82:a=52,h=s.substring(l,++r),n=_t;break;case 58:a=5,n=Wr,r++;continue;case 59:a=4,n=Gr,r++;continue;case 60:a=1,n=Ft,r++;continue;case 61:a=1,n=Cr,f=r++;continue;case 62:r--;break;case 63:r-=2;break;case 64:l=r++,n=Ff;continue;case 65:l=++r,n=Lf;continue;case 66:l=++r,n=Bf;continue;case 67:a=8,h=li(s.substring(l,r)),r++;break;case 69:r++;break;case 70:n=Nf,r++;continue;case 71:n=Pf,r++;continue;case 79:if(r-f<8&&s.substring(f+1,r+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){r++;continue}case 68:a=8,h=li(s.substring(l,r)),r++,n=Of;continue;case 74:if(r++,r-f<9&&s.substring(f+1,r).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,h="E_CSS_UNEXPECTED_NEWLINE",n=_t;break;case 73:if(r-f<9&&s.substring(f+1,r+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){r++,n=Ft;continue}h=li(s.substring(l,r));break;case 75:f=r++;continue;case 76:r++,n=hu;continue;default:if(n!==_t){a=54,h="E_CSS_UNEXPECTED_STATE";break}l=r,a=0}if(p.type=a,p.precededBySpace=d,p.num=u,p.text=h,p.position=l,e++,e>=t)break;n=_t,d=!1,p=o[e&i]}this.position=r,this.tail=e&i}},Oe=null,jr=null;function Xr(){return Oe}function B(e){if(!Oe)throw new Error("E_TASK_NO_CONTEXT");Oe.name||(Oe.name=e);let t=Oe,i=new Js(t,t.top,e);return t.top=i,i.state=1,i}function Mf(e){return new Vf(e||new Df)}function N(e){return new qr(e)}function Gi(e,t,i){let n=B(e);n.handler=i;try{t(n)}catch(s){n.task.raise(s,n)}return n.result()}function zf(e,t){return(Oe?Oe.getScheduler():jr||Mf()).run(e,t)}var Df=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Vf=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 bp,jr||(jr=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){H.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new Uf(this,t||"");i.top=new Js(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let s=()=>{i.running=!1;for(let r of i.callbacks)try{r()}catch(o){H.error(o)}};try{e().then(r=>{i.result=r,s()})}catch(r){i.raise(r),s()}});let n=Oe;return Oe=i,this.schedule(i.top.suspend("bootstrap")),Oe=n,i}},uu=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=Oe;return Oe=e,e.top.finish(this.result),Oe=t,!0}return!1}cancel(){this.canceled=!0}},Uf=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!==Oe&&this.continuation){this.continuation.cancel();let t=new uu(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=B("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&&H.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
5
|
---- async ---
|
|
6
6
|
`:"";for(let i=this.top;i;i=i.parent)t+=" ",t+=i.getName(),t+=`
|
|
7
|
-
`;e.frameTrace=t}}},
|
|
7
|
+
`;e.frameTrace=t}}},qr=class cu{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new cu(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},Hf=class{constructor(e){this.frame=e}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new Js(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 qr(e)):new qr(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}},Js=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(!Oe)throw new Error("F_TASK_NO_CONTEXT");if(this!==Oe.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new Hf(this)}finish(e){this.checkEnvironment(),Oe&&!Oe.exception&&(this.res=e),this.state=2;let t=this.parent;if(Oe&&(Oe.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=B("Frame.timeSlice");return e.getScheduler().isTimeSliceOver()?(H.debug("-- time slice --"),e.suspend().schedule(!0)):e.finish(!0),e.result()}sleep(e){let t=B("Frame.sleep");return t.suspend().schedule(!0,e),t.result()}loop(e){let t=B("Frame.loop"),i=n=>{try{for(;n;){let s=e();if(s.isPending()){s.then(i);return}else s.then(r=>{n=r})}t.finish(!0)}catch(s){t.task.raise(s,t)}};return i(!0),t.result()}loopWithFrame(e){let t=Oe;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new $f(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 uu(this.task);return this.task.continuation=t,Oe=null,this.task.waitTarget=e||null,t}},$f=class extends Js{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},$n=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=Xr().getScheduler().run(()=>{let e=B("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(s){H.error(s,"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}},Qs=e=>{if(e.length==0)return N(!0);if(e.length==1)return e[0].get().thenReturn(!0);let t=B("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()},du=`
|
|
8
8
|
@media screen {
|
|
9
9
|
[data-vivliostyle-viewer-viewport] {
|
|
10
10
|
background: #aaaaaa;
|
|
@@ -73,7 +73,7 @@ var Nc=Object.create;var Rn=Object.defineProperty;var Tc=Object.getOwnPropertyDe
|
|
|
73
73
|
transform-origin: center top;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
`,
|
|
76
|
+
`,pu=`
|
|
77
77
|
[data-vivliostyle-layout-box] {
|
|
78
78
|
position: absolute;
|
|
79
79
|
left: 0;
|
|
@@ -206,7 +206,7 @@ var Nc=Object.create;var Rn=Object.defineProperty;var Tc=Object.getOwnPropertyDe
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
`,
|
|
209
|
+
`,fu=`
|
|
210
210
|
/*
|
|
211
211
|
* Copyright 2013 Google, Inc.
|
|
212
212
|
* Copyright 2015 Daishinsha Inc.
|
|
@@ -280,11 +280,11 @@ CONTENT_LIST = [ STRING | URI | counter(IDENT LIST_STYLE_TYPE?) |
|
|
|
280
280
|
target-counter(ATTR IDENT LIST_STYLE_TYPE?) |
|
|
281
281
|
target-counters([ STRING | URI ] IDENT STRING LIST_STYLE_TYPE?) |
|
|
282
282
|
target-counters(ATTR IDENT STRING LIST_STYLE_TYPE?) |
|
|
283
|
-
target-text([ STRING | URI ] [content | before | after | first-letter]?) |
|
|
284
|
-
target-text(ATTR [content | before | after | first-letter]?) |
|
|
283
|
+
target-text([ STRING | URI ] [content | before | after | first-letter | marker]?) |
|
|
284
|
+
target-text(ATTR [content | before | after | first-letter | marker]?) |
|
|
285
285
|
leader([ dotted | solid | space ] | STRING ) |
|
|
286
286
|
open-quote | close-quote | no-open-quote | no-close-quote |
|
|
287
|
-
content([ text | before | after | first-letter ]?) |
|
|
287
|
+
content([ text | before | after | first-letter | marker ]?) |
|
|
288
288
|
string(IDENT [first | start | last | first-except]?) |
|
|
289
289
|
element(IDENT [first | start | last | first-except]?) ]+;
|
|
290
290
|
CONTENT = normal | none | CONTENT_LIST;
|
|
@@ -314,7 +314,7 @@ letter-spacing = normal | LENGTH_OR_NUM;
|
|
|
314
314
|
line-height = normal | POS_NUM | PPLENGTH;
|
|
315
315
|
list-style-image = IMAGE;
|
|
316
316
|
list-style-position = inside | outside;
|
|
317
|
-
list-style-type = LIST_STYLE_TYPE;
|
|
317
|
+
list-style-type = LIST_STYLE_TYPE | STRING | none;
|
|
318
318
|
margin-right = APLENGTH;
|
|
319
319
|
margin-left = APLENGTH;
|
|
320
320
|
margin-top = APLENGTH;
|
|
@@ -836,7 +836,7 @@ word-wrap = overflow-wrap;
|
|
|
836
836
|
[adapt,webkit]start = inline-start;
|
|
837
837
|
[adapt,webkit]end = inline-end;
|
|
838
838
|
|
|
839
|
-
`,
|
|
839
|
+
`,gu=`
|
|
840
840
|
<!DOCTYPE html>
|
|
841
841
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://www.pyroxy.com/ns/shadow">
|
|
842
842
|
<head>
|
|
@@ -859,7 +859,7 @@ word-wrap = overflow-wrap;
|
|
|
859
859
|
<s:template id="table-cell"><div data-vivliostyle-flow-root="true" class="-vivliostyle-table-cell-container"><s:content/></div></s:template>
|
|
860
860
|
|
|
861
861
|
</body>
|
|
862
|
-
</html>`,
|
|
862
|
+
</html>`,mu=`
|
|
863
863
|
@namespace "http://www.w3.org/1999/xhtml";
|
|
864
864
|
|
|
865
865
|
:root {
|
|
@@ -986,7 +986,7 @@ word-wrap = overflow-wrap;
|
|
|
986
986
|
margin: 10%;
|
|
987
987
|
}
|
|
988
988
|
}
|
|
989
|
-
`,
|
|
989
|
+
`,wu=`
|
|
990
990
|
@namespace "http://www.w3.org/1999/xhtml";
|
|
991
991
|
@namespace m "http://www.w3.org/1998/Math/MathML";
|
|
992
992
|
@namespace epub "http://www.idpf.org/2007/ops";
|
|
@@ -1229,6 +1229,29 @@ ul ul,
|
|
|
1229
1229
|
ol ol {
|
|
1230
1230
|
margin-block: 0;
|
|
1231
1231
|
}
|
|
1232
|
+
ul {
|
|
1233
|
+
list-style-type: disc;
|
|
1234
|
+
}
|
|
1235
|
+
ol ul,
|
|
1236
|
+
ul ul {
|
|
1237
|
+
list-style-type: circle;
|
|
1238
|
+
}
|
|
1239
|
+
ol ol ul,
|
|
1240
|
+
ol ul ul,
|
|
1241
|
+
ul ol ul,
|
|
1242
|
+
ul ul ul {
|
|
1243
|
+
list-style-type: square;
|
|
1244
|
+
}
|
|
1245
|
+
ol { list-style-type: decimal; }
|
|
1246
|
+
ol[type="1"], li[type="1"] { list-style-type: decimal; }
|
|
1247
|
+
ol[type=a], li[type=a] { list-style-type: lower-alpha; }
|
|
1248
|
+
ol[type=A], li[type=A] { list-style-type: upper-alpha; }
|
|
1249
|
+
ol[type=i], li[type=i] { list-style-type: lower-roman; }
|
|
1250
|
+
ol[type=I], li[type=I] { list-style-type: upper-roman; }
|
|
1251
|
+
ul[type=none], li[type=none] { list-style-type: none; }
|
|
1252
|
+
ul[type=disc], li[type=disc] { list-style-type: disc; }
|
|
1253
|
+
ul[type=circle], li[type=circle] { list-style-type: circle; }
|
|
1254
|
+
ul[type=square], li[type=square] { list-style-type: square; }
|
|
1232
1255
|
u,
|
|
1233
1256
|
ins {
|
|
1234
1257
|
text-decoration: underline;
|
|
@@ -1360,7 +1383,7 @@ epub|case[required-namespace::supported] ~ epub|case {
|
|
|
1360
1383
|
epub|case[required-namespace::supported] ~ epub|default {
|
|
1361
1384
|
display: none;
|
|
1362
1385
|
}
|
|
1363
|
-
`,
|
|
1386
|
+
`,bu=`
|
|
1364
1387
|
@namespace "http://www.w3.org/1999/xhtml";
|
|
1365
1388
|
|
|
1366
1389
|
*:not([data-vivliostyle-role=doc-toc],
|
|
@@ -1390,7 +1413,7 @@ epub|case[required-namespace::supported] ~ epub|default {
|
|
|
1390
1413
|
[data-vivliostyle-role=doc-toc]:is(ol,ul) {
|
|
1391
1414
|
-adapt-behavior: toc-container;
|
|
1392
1415
|
}
|
|
1393
|
-
`,
|
|
1416
|
+
`,yu=`
|
|
1394
1417
|
[data-viv-margin-discard~="block-start"] {
|
|
1395
1418
|
margin-block-start: 0 !important;
|
|
1396
1419
|
}
|
|
@@ -1509,12 +1532,262 @@ span[data-viv-leader] {
|
|
|
1509
1532
|
text-orientation: mixed;
|
|
1510
1533
|
white-space: pre;
|
|
1511
1534
|
}
|
|
1512
|
-
`;function bs(e,t,i){let n=F("fetchFromURL"),s={method:i||"GET",mode:"cors"},o=n.suspend(),r={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(e,s).then(a=>{var h;return r.status=a.status,r.url=a.url,r.statusText=a.statusText,r.contentType=(h=a.headers.get("Content-Type"))==null?void 0:h.replace(/;.*$/,"").toLowerCase(),a.ok?t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?(r.contentType="text/html",a.arrayBuffer().then(l=>new TextDecoder("Shift_JIS").decode(l))):(/^data:,(<|%3c)/i.test(e)&&(r.contentType="text/html"),a.text()):a.text()}).then(a=>{t==="blob"&&a instanceof Blob?r.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?r.responseBlob=fh([a]):t==="json"?r.responseText=JSON.stringify(a):typeof a=="string"&&(r.responseText=a),o.schedule(r)}).catch(a=>{H.warn(a,`Error fetching ${e}`),o.schedule(r)}),n.result()}function fh(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Pp(e){let t=F("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function Np(e){return URL.createObjectURL(e)}var tr=class{constructor(e,t){this.parser=e,this.type=t,u(this,"resources",{}),u(this,"fetchers",{})}load(e,t,i){e=Nt(e);let n=this.resources[e];return typeof n<"u"?P(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=F("fetch"),s=e.endsWith("?viv-toc-box");s&&(e=e.replace("?viv-toc-box",""));let o=Ee("user-agent.xml",ni),r=!s&&e===o;return r&&(e=`data:application/xml,${encodeURIComponent(hh)}`),bs(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:""})`);s?(e+="?viv-toc-box",a.url+="?viv-toc-box"):r&&(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=Nt(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new Cn(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[Nt(e)]}delete(e){delete this.resources[Nt(e)]}};function Tp(e,t){let i=e.responseText;return P(i?jo(i):null)}function Ip(){return new tr(Tp,"text")}function ui(e,t,i){let n=new Cn(()=>{let s=F("loadElement"),o=s.suspend(e),r=!1,a=null,h=l=>{r||(r=!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 s.result()},`loadElement ${t||e.localName}`);return n.start(),n}var ca=0,Ap=16777216,gh=33554432,mh=50331648,wh=67108864,Rp=83886080,Lp=100663296,ir=class{constructor(e){this.scope=e,u(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(){}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){}endFuncWithSelector(){}pushSelectorText(e){}getImportantSpecificity(){switch(this.flavor){case"UA":return ca;case"User":return Lp;default:return Rp}}getBaseSpecificity(){switch(this.flavor){case"UA":return ca;case"User":return Ap;default:return gh}}},Fp=class extends ir{constructor(){super(null),u(this,"stack",[]),u(this,"tokenizer",null),u(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;H.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()}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){this.slave.startFuncWithSelector(e)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},da=class extends ir{constructor(e,t,i){super(e),this.owner=t,this.topLevel=i,u(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()}},En=class extends da{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new da(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}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){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())}},Se=[],Qn=[],ce=[],xe=[],ut=[],et=[],ye=[],Fe=[],le=[],Me=[],Ge=[],_e=[],ve=[],ci=55,di=56,Bn=57;Se[1]=28,Se[36]=29,Se[7]=29,Se[9]=29,Se[14]=29,Se[18]=29,Se[50]=29,Se[20]=30,Se[13]=27,Se[0]=200,Qn[1]=46,Qn[0]=200,et[1]=2,et[36]=4,et[7]=6,et[9]=8,et[14]=10,et[18]=14,et[50]=42,ce[37]=11,ce[23]=12,ce[35]=56,ce[1]=1,ce[36]=3,ce[7]=5,ce[9]=7,ce[14]=9,ce[12]=13,ce[18]=55,ce[50]=58,ce[16]=41,xe[37]=11,xe[23]=12,xe[35]=56,xe[1]=1,xe[36]=3,xe[7]=5,xe[9]=7,xe[14]=9,xe[18]=55,ut[1]=2,ut[36]=4,ut[7]=6,ut[9]=8,ut[18]=14,ut[50]=42,ut[14]=10,ut[12]=13,ye[1]=15,ye[7]=16,ye[4]=17,ye[5]=18,ye[3]=19,ye[2]=20,ye[8]=21,ye[27]=57,ye[16]=22,ye[19]=23,ye[6]=24,ye[11]=25,ye[17]=26,ye[13]=48,ye[31]=47,ye[23]=54,ye[0]=44,Fe[1]=31,Fe[4]=32,Fe[5]=32,Fe[3]=33,Fe[2]=34,Fe[10]=40,Fe[6]=38,Fe[31]=36,Fe[24]=36,Fe[32]=35,le[1]=45,le[16]=37,le[37]=37,le[38]=37,le[47]=37,le[48]=37,le[39]=37,le[49]=37,le[41]=37,le[26]=37,le[25]=37,le[23]=37,le[24]=37,le[19]=37,le[21]=37,le[36]=37,le[18]=37,le[22]=37,le[11]=39,le[12]=43,le[17]=49,Me[0]=200,Me[12]=50,Me[13]=51,Me[14]=50,Me[15]=51,Me[10]=50,Me[11]=51,Me[17]=53,Ge[0]=200,Ge[12]=50,Ge[13]=52,Ge[14]=50,Ge[15]=51,Ge[10]=50,Ge[11]=51,Ge[17]=53,_e[0]=200,_e[12]=50,_e[13]=51,_e[14]=50,_e[15]=51,_e[10]=50,_e[11]=51,ve[11]=0,ve[16]=0,ve[22]=1,ve[18]=1,ve[26]=2,ve[25]=2,ve[38]=3,ve[37]=3,ve[48]=3,ve[47]=3,ve[39]=3,ve[49]=3,ve[41]=3,ve[23]=4,ve[24]=4,ve[36]=5,ve[19]=5,ve[21]=5,ve[0]=6,ve[ci]=2,ve[di]=2;var kn=class{constructor(e,t,i,n){this.actions=e,this.tokenizer=t,this.handler=i,this.baseURL=n,u(this,"valStack",[]),u(this,"namespacePrefixToURI",{}),u(this,"defaultNamespaceURI",null),u(this,"propName",null),u(this,"propImportant",!1),u(this,"exprContext"),u(this,"result",null),u(this,"importReady",!1),u(this,"importURL",null),u(this,"importCondition",null),u(this,"errorBrackets",[]),u(this,"ruleStack",[]),u(this,"regionRule",!1),u(this,"pageRule",!1),u(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(W)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,s=0,o;do if(o=i[--n],e===")"&&o instanceof hi){if(o.text===")")s++;else if(o.text==="("){if(s===0)return null;s--}}while(typeof o<"u"&&typeof o!="string");let r=i.length-(n+1);if(r>1&&i.splice(n+1,r,new me(i.slice(n+1,i.length))),e==",")return null;n++;do o=i[--n];while(typeof o<"u"&&(typeof o!="string"||o==","));if(r=i.length-(n+1),o=="("){e!=")"&&t.type!==0&&(this.handler.error("E_CSS_MISMATCHED_C_PAR",t),this.actions=Ge);let h=new Fi(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,r+2,h),h.name==="var"){let l=h.values[0]instanceof nt&&h.values[0].name;(!At(l)||l===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${h.toString()}`,t),this.actions=Ge)}return h}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=Ge,null;if(r>1)return new qe(this.extractVals(",",n+1));let a=i[0];return a instanceof He?a:a?new hi(a.toString()):W}exprError(e,t){this.actions=this.propName?Ge:Me,H.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,s=i.pop(),o;for(;;){let r=i.pop();if(e==11){let a=[s];for(;r==16;)a.unshift(i.pop()),r=i.pop();if(typeof r=="string"){if(r=="{"){for(;a.length>=2;){let h=a.shift(),l=a.shift(),c=new bd(n.getScope(),h,l);a.unshift(c)}return i.push(new V(a[0])),!0}else if(r=="("){let h=i.pop(),l=i.pop();s=new Ki(n.getScope(),Zs(l,h),a),e=0;continue}}if(r==10){s.isMediaName()&&(s=new Jr(n.getScope(),s,null)),e=0;continue}}else if(typeof r=="string"){i.push(r);break}if(r<0)if(r==-31)s=new Ut(n.getScope(),s);else if(r==-24)s=new fi(n.getScope(),s);else if(r==-Bn)s=new md(n.getScope(),s);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(ve[e]>ve[r]){i.push(r);break}switch(o=i.pop(),r){case 26:s=new Yo(n.getScope(),o,s);break;case ci:s=new wd(n.getScope(),o,s);break;case di:s=new vd(n.getScope(),o,s);break;case 25:s=new Ko(n.getScope(),o,s);break;case 38:s=new yd(n.getScope(),o,s);break;case 37:s=new Sd(n.getScope(),o,s);break;case 48:s=new xd(n.getScope(),o,s);break;case 47:s=new eo(n.getScope(),o,s);break;case 39:case 49:s=new Zo(n.getScope(),o,s);break;case 41:s=new Cd(n.getScope(),o,s);break;case 23:s=new _l(n.getScope(),o,s);break;case 24:s=new Ml(n.getScope(),o,s);break;case 36:s=new Jo(n.getScope(),o,s);break;case 19:s=new zl(n.getScope(),o,s);break;case 21:s=new Dl(n.getScope(),o,s);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),s=new Pd(n.getScope(),i.pop(),o,s);break;case 10:if(o.isMediaName())s=new Jr(n.getScope(),o,s);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(r),i.push(s),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(s),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,s;if(t)s=e.text,n=e.position+s.length+1;else if(e.type===10){let c=i.nthToken(1),p=i.nthToken(2);if(c.type===1&&p.type===18)i.consume(),i.consume(),s=c.text,n=p.position+1;else{if(c.type===10||c.type===6||c.type===1&&c.text.toLowerCase()==="not"&&(p.type===10||p.type===6))return null;n=e.position+1}}else return null;let o=0,r,a=0;for(;o>=0;)switch(i.consume(),r=i.token(),r.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",r),null}i.consume();let h=r.position,l=t&&s==="selector"&&a>0?"":i.input.substring(n,h).trim();return new Nd(this.handler.getScope(),s,l,t)}readPseudoParams(){let e=[];for(;;){let t=this.tokenizer.token();switch(t.type){case 1:e.push(t.text);break;case 23:e.push("+");break;case 4:case 5:e.push(t.num);break;default:return e}this.tokenizer.consume()}}readNthPseudoParams(){let e=!1,t=this.tokenizer.token();if(t.type===23)e=!0,this.tokenizer.consume(),t=this.tokenizer.token();else if(t.type===1&&(t.text==="even"||t.text==="odd"))return this.tokenizer.consume(),[2,t.text==="odd"?1:0];switch(t.type){case 3:if(e&&t.num<0)return null;case 1:if(e&&t.text.charAt(0)==="-")return null;if(t.text==="n"||t.text==="-n"){if(e&&t.precededBySpace)return null;let i=t.text==="-n"?-1:1;t.type===3&&(i=t.num);let n=0;this.tokenizer.consume(),t=this.tokenizer.token();let s=t.type===24,o=t.type===23||s;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,s&&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 s of n)switch(s){case"vertical":t=dt(i,t,new Ut(i,new Ae(i,"pref-horizontal")));break;case"horizontal":t=dt(i,t,new Ae(i,"pref-horizontal"));break;case"day":t=dt(i,t,new Ut(i,new Ae(i,"pref-night-mode")));break;case"night":t=dt(i,t,new Ae(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new V(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":return!0}return!1}runParser(e,t,i,n,s,o){let r=this.handler,a=this.tokenizer,h=this.valStack,l,c,p,d,f,m,g,w=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),s&&w===null&&(w=l.position-1,a.input[w]==="("&&w++),this.actions===ye&&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 hi(l.toString())),a.consume();continue}switch(this.actions[l.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(r.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=Ge):(this.actions=et,r.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=ye,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=Ge,r.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=ye,h.splice(0,h.length);continue;case 29:this.actions=et,r.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=_e,r.error("E_CSS_SPACE_EXPECTED",l);continue}r.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),p=this.namespacePrefixToURI[l.text],p!=null)switch(l=a.token(),l.type){case 1:r.tagSelector(p,l.text),s?this.actions=xe:this.actions=ce,a.consume();break;case 36:r.tagSelector(p,null),s?this.actions=xe:this.actions=ce,a.consume();break;default:this.actions=Me,r.error("E_CSS_NAMESPACE",l)}else this.actions=Me,r.error("E_CSS_UNDECLARED_PREFIX",l);else r.tagSelector(this.defaultNamespaceURI,l.text),s?this.actions=xe:this.actions=ce,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=_e,r.error("E_CSS_SPACE_EXPECTED",l);continue}r.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),l=a.token(),l.type){case 1:r.tagSelector(null,l.text),s?this.actions=xe:this.actions=ce,a.consume();break;case 36:r.tagSelector(null,null),s?this.actions=xe:this.actions=ce,a.consume();break;default:this.actions=Me,r.error("E_CSS_NAMESPACE",l)}else r.tagSelector(this.defaultNamespaceURI,null),s?this.actions=xe:this.actions=ce,a.consume();continue;case 5:l.precededBySpace&&r.descendantSelector();case 6:if(!l.text){r.error("E_CSS_SYNTAX",l),a.consume();continue}r.idSelector(l.text),s?this.actions=xe:this.actions=ce,a.consume();continue;case 7:l.precededBySpace&&r.descendantSelector();case 8:r.classSelector(l.text),s?this.actions=xe:this.actions=ce,a.consume();continue;case 55:l.precededBySpace&&r.descendantSelector();case 14:a.consume(),l=a.token();e:switch(l.type){case 1:r.pseudoclassSelector(l.text,null),a.consume(),s?this.actions=xe:this.actions=ce;continue;case 6:switch(d=l.text,a.consume(),d){case"is":case"not":case"where":case"has":this.actions=et,r.startFuncWithSelector(d),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,d==="has")?this.actions=ce:this.actions=_e;continue;case"lang":case"href-epub-type":if(l=a.token(),l.type===1){g=[l.text],a.consume(),d==="href-epub-type"&&a.token().type===16&&(a.consume(),l=a.token(),l.type===1&&(g.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(g=this.readNthPseudoParams(),g)break;break e;default:g=this.readPseudoParams()}if(l=a.token(),l.type==11){r.pseudoclassSelector(d,g),a.consume(),s?this.actions=xe:this.actions=ce;continue}break}r.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=Me;continue;case 58:l.precededBySpace&&r.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:r.pseudoelementSelector(l.text,null),s?this.actions=xe:this.actions=ce,a.consume();continue;case 6:if(d=l.text,a.consume(),d=="nth-fragment"){if(g=this.readNthPseudoParams(),g===null)break}else g=this.readPseudoParams();if(l=a.token(),l.type==11){r.pseudoelementSelector(d,g),s?this.actions=xe:this.actions=ce,a.consume();continue}break}r.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=Me;continue;case 9:l.precededBySpace&&r.descendantSelector();case 10:if(a.consume(),l=a.token(),l.type==1)d=l.text,a.consume();else if(l.type==36)d=null,a.consume();else if(l.type==34)d="";else{this.actions=_e,r.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(p=d&&this.namespacePrefixToURI[d],p===void 0){this.actions=_e,r.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=_e,r.error("E_CSS_ATTR_NAME_EXPECTED",l);continue}d=l.text,a.consume(),l=a.token()}else p="";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:r.attributeSelector(p,d,0,null),s?this.actions=xe:this.actions=ce,a.consume();continue;default:this.actions=_e,r.error("E_CSS_ATTR_OP_EXPECTED",l);continue}switch(l.type){case 1:case 2:r.attributeSelector(p,d,f,l.text),a.consume(),l=a.token();break;default:this.actions=_e,r.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=_e,r.error("E_CSS_ATTR",l);continue}s?this.actions=xe:this.actions=ce,a.consume();continue;case 11:r.childSelector(),this.actions=ut,a.consume();continue;case 12:r.adjacentSiblingSelector(),this.actions=ut,a.consume();continue;case 56:r.followingSiblingSelector(),this.actions=ut,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),r.startRuleBody(),this.actions=Se,a.consume();continue;case 41:r.nextSelector(),this.actions=et,a.consume();continue;case 15:h.push(B(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new ql(l.text)),a.consume();continue;case 17:h.push(new Xt(l.num)),a.consume();continue;case 18:h.push(new si(l.num)),a.consume();continue;case 19:h.push(new I(l.num,l.text)),a.consume();continue;case 20:h.push(new Le(l.text)),a.consume();continue;case 21:h.push(new pt(Ee(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new Yl(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(fs),a.consume();continue;case 24:d=l.text.toLowerCase(),d=="-epubx-expr"||d=="env"?(this.actions=Fe,this.exprContext=0,h.push("{")):(h.push(d),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(),c=a.nthToken(1),l.type==1&&l.text.toLowerCase()=="important"&&(c.type==17||c.type==0||c.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",l);continue;case 54:switch(c=a.nthToken(1),c.type){case 4:case 3:case 5:if(!c.precededBySpace){a.consume();continue}}h.push(new hi("+")),a.consume();continue;case 26:a.consume();case 48:m=this.valStackReduce(";",l),m&&this.propName&&r.property(this.propName,m,this.propImportant),this.actions=i?Qn:Se;continue;case 44:for(a.consume();h.length>0;){let y=h.length;if(m=this.valStackReduce(";",l),!m||h.length===y)break}return t?(this.result=m,!0):(this.propName&&m&&r.property(this.propName,m,this.propImportant),!0);case 31:if(c=a.nthToken(1),c.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(h.push(l.text,c.text,"("),a.consume()):(h.push(new Ae(r.getScope(),Zs(l.text,c.text))),this.actions=le),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new Zr(r.getScope(),!0,c.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=c),h.push(new Zr(r.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==ci&&h[h.length-1]!==di&&(c.type===10||c.type===6)){h.push(-Bn),a.consume();continue}else h.push(new Ae(r.getScope(),l.text));this.actions=le}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=le;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new Oe(r.getScope(),l.num)),a.consume(),this.actions=le;continue;case 33:d=l.text,d=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?d="vh":d="vw"),h.push(new yn(r.getScope(),l.num,d)),a.consume(),this.actions=le;continue;case 34:h.push(new Oe(r.getScope(),l.text)),a.consume(),this.actions=le;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new $l(r.getScope(),l.num)),a.consume(),this.actions=le);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=Fe,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==di&&h[h.length-2]!==-Bn?(this.actions=Fe,this.exprStackReduce(ci,l),h.push(ci),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==ci&&h[h.length-2]!==-Bn?(this.actions=Fe,this.exprStackReduce(di,l),h.push(di),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=ye),a.consume();continue;case 43:this.exprStackReduce(11,l)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",l):(this.exprContext==1?r.startWhenRule(h.pop()):r.startMediaRule(h.pop()),this.ruleStack.push("media"),r.startRuleBody(),this.actions=Se)),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=Se,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=Se,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let y=this.readSupportsTest(l);if(y){h.push(y),this.actions=le;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=Se,a.consume(),r.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(d=l.text.toLowerCase(),d){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=Fe,h.push("{");continue}r.error("E_CSS_IMPORT_SYNTAX",l),this.actions=Me;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(d=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[d]=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}r.error("E_CSS_NAMESPACE_SYNTAX",l),this.actions=Me;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){d=l.text.toLowerCase(),d!="utf-8"&&d!="utf-16"&&r.error(`E_CSS_UNEXPECTED_CHARSET ${d}`,l),a.consume(),a.consume();continue}r.error("E_CSS_CHARSET_SYNTAX",l),this.actions=Me;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(),d){case"font-face":r.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":r.startPageTemplateRule();break;case"-epubx-define":r.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":r.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(d),r.startRuleBody();continue}break;case"-adapt-footnote-area":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),r.startFootnoteRule(null),this.ruleStack.push(d),r.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){d=l.text,a.consume(),a.consume(),r.startFootnoteRule(d),this.ruleStack.push("-adapt-footnote-area"),r.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"-epubx-region":a.consume(),r.startRegionRule(),this.regionRule=!0,this.actions=et;continue;case"page":a.consume(),r.startPageRule(),this.pageRule=!0,this.actions=ut;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(),l=a.token(),l.type==12){a.consume(),r.startPageMarginBoxRule(d),this.ruleStack.push(d),r.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=Fe,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Fe,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Fe,h.push("{");continue;case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){r.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(d),r.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{a.consume(),l=a.token();let y=null,b=null,C=[];for(l.type==1&&(y=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;)C.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),l=a.token();if(l.type==12){switch(a.consume(),d){case"-epubx-page-master":r.startPageMasterRule(y,b,C);break;case"-epubx-partition":r.startPartitionRule(y,b,C);break;case"-epubx-partition-group":r.startPartitionGroupRule(y,b,C);break}this.ruleStack.push(d),r.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":r.error(`E_CSS_UNEXPECTED_AT${d}`,l),this.actions=_e;continue;default:r.error(`E_CSS_AT_UNKNOWN ${d}`,l),this.actions=Me;continue}r.error(`E_CSS_AT_SYNTAX ${d}`,l),this.actions=Me;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Se;continue}case 51:if(s&&this.errorBrackets.length==0&&l.type==11)return a.consume(),r.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=Se),a.consume();continue;case 53:this.errorBrackets.length==0&&(this.actions=Se),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,l)?(this.result=h.pop(),!0):!1;if(s){switch(l.type){case 16:case 11:if(this.actions===et)r.error("E_CSS_SYNTAX",l);else{let y=a.input.substring(w,l.position);r.pushSelectorText(y),w=l.position+1}if(l.type===16){r.nextSelector(),this.actions=et,a.consume();continue}else return r.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(o){this.actions=ce;continue}break;case 12:case 14:case 10:this.errorBrackets.push(l.type+1);break}r.error("E_CSS_SYNTAX",l),a.consume(),this.actions=_e;continue}if(this.actions!==Me&&this.actions!==_e&&this.actions!==Ge){if(l.type==54)r.error("E_CSS_SYNTAX",l);else if(this.actions===ye){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new hi(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==Fe&&h.length>0){r.startMediaRule(h.pop()),this.ruleStack.push("media"),r.startRuleBody(),this.actions=Se,a.consume();continue}else{if(l.type===17&&this.actions==Fe)return this.actions=Se,a.consume(),!1;r.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=Ge:this.actions=_e;continue}a.consume();continue}}return!1}},bh=class extends ir{constructor(e){super(null),this.scope=e}error(e,t){H.warn(e,t.toString())}getScope(){return this.scope}};function Op(e,t,i,n,s){let o=F("parseStylesheet"),r=new kn(Se,e,t,i),a=null;return s&&(a=_p(new yt(s,t),t,i)),a=r.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),o.loop(()=>{for(;!r.runParser(100,!1,!1,!1,!1);){if(r.importReady){let l=Ee(r.importURL,i);r.importCondition&&(t.startMediaRule(r.importCondition),t.startRuleBody());let c=F("parseStylesheet.import");return vh(l,t,null,null).then(()=>{r.importCondition&&t.endRule(),r.importReady=!1,r.importURL=null,r.importCondition=null,c.finish(!0)}),c.result()}let h=o.timeSlice();if(h.isPending)return h}return P(!1)}).then(()=>{a&&t.endRule(),o.finish(!0)}),o.result()}function nr(e,t,i,n,s){return Ni("parseStylesheetFromText",o=>{let r=new yt(e,t);Op(r,t,i,n,s).thenFinish(o)},(o,r)=>{H.warn(r,`Failed to parse stylesheet text: ${e}`),o.finish(!1)})}function vh(e,t,i,n){return Ni("parseStylesheetFromURL",s=>{bs(e).then(o=>{o.responseText?nr(o.responseText,t,e,i,n).then(r=>{r||H.warn(`Failed to parse stylesheet from ${e}`),s.finish(!0)}):s.finish(!0)})},(s,o)=>{H.warn(o,"Exception while fetching and parsing:",e),s.finish(!0)})}function Oi(e,t,i){let n=new kn(ye,t,new bh(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function Bp(e,t,i){new kn(Qn,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function _p(e,t,i){let n=new kn(Fe,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var Mp={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function zp(e){return!!Mp[e]}function Dp(e,t,i){if(t instanceof Ie&&t.str==="viv-leader")return new V(t);let n=t.evaluate(e);switch(typeof n){case"number":return zp(i)?n==Math.round(n)?new si(n):new Xt(n):new I(n,"px");case"string":return n?Oi(t.scope,new yt(n,null),""):W;case"boolean":return n?v._true:v._false;case"undefined":return W}throw new Error("E_UNEXPECTED")}function yh(e,t){let i={};return Object.keys(e).forEach(n=>{let s=i[n]={},o=e[n];Object.keys(o).forEach(r=>{s[r]=o[r].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 xh(e,t,i,n){let s=n[t];if(!s)throw new Error(`unknown writing-mode: ${t}`);let o=s[i||"ltr"];if(!o)throw new Error(`unknown direction: ${i}`);for(let r of o){let a=e.replace(r.regexp,r.to);if(a!==e)return a}return e}var Sh={"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"}]}},Vp=yh(Sh,!0);function Ch(e,t,i){return xh(e,t,i||null,Vp)}var Up=yh(Sh,!1);function Eh(e,t,i){return xh(e,t,i||null,Up)}var Hp={"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 $p(e,t){let i=Hp[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 sr(e,t,i){var n;let s=t,o={width:s.style.width,height:s.style.height};function r(d){return e.getElementComputedStyle(t).getPropertyValue(d)}let a=r("writing-mode")!=="horizontal-tb",h=a?"height":"width",l=a?"width":"height";function c(d,f){s.style[d]=f;let m=r(d);return s.style[d]=o[d],m}let p={};for(let d of i){let f;switch(d){case"max-content inline size":f=c(h,"max-content");break;case"min-content inline size":f=c(h,"min-content");break;case"fit-content inline size":f=c(h,"fit-content");break;case"max-content block size":f=c(l,"max-content");break;case"min-content block size":f=c(l,"min-content");break;case"fit-content block size":f=c(l,"fit-content");break;case"max-content width":f=c("width","max-content");break;case"max-content height":f=c("height","max-content");break;case"min-content width":f=c("width","min-content");break;case"min-content height":f=c("height","min-content");break;case"fit-content width":f=c("width","fit-content");break;case"fit-content height":f=c("height","fit-content");break}f==="0px"&&t.childNodes.length===1&&((n=t.firstElementChild)==null?void 0:n.localName)==="img"&&!t.firstElementChild.complete&&(f="1px"),p[d]=parseFloat(f)}return p}function Hi(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 kh(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function Ph(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function ot(e,t){let i=kh(e);i.includes(t)||(i.push(t),Ph(e,i))}function Wp(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function Gp(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function Hs(e,t){let i=Wp(e);i.includes(t)||(i.push(t),Gp(e,i))}function jp(e){let t=e.name,i=e.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:i===v.always?v.page:i,important:e.important};default:return e}}var lo={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function je(e){return!!lo[e]}var Xp={left:!0,right:!0,recto:!0,verso:!0};function un(e){return!!Xp[e]}var qp={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function es(e){return!!qp[e]}function Xe(e,t){if(e)if(t){if(un(t))return t;if(un(e))return e;{let i=je(e),n=je(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:es(t)?t:es(e)?e:t}}else return e;else return t}function pa(e){return je(e)?e:"auto"}ft("SIMPLE_PROPERTY",jp);var Qi=Wc(jc());function Yp(e,t){return(0,Qi.default)(e,t,0)}function fa(e){return e.reduce((t,i)=>i[0]===Qi.default.DELETE?t:t+i[1],"")}function Kp(e,t){return Nh(e,t,1)}function Zp(e,t){return Nh(e,t,-1)}function Nh(e,t,i){let n=0,s=0;return e.some(o=>{for(let r=0;r<o[1].length;r++){switch(o[0]*i){case Qi.default.INSERT:n++;break;case Qi.default.DELETE:n--,s++;break;case Qi.default.EQUAL:s++;break}if(s>t)return!0}return!1}),Math.max(Math.min(t,s-1)+n,0)}var ho;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(ho||(ho={}));var yi;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(yi||(yi={}));var ts;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(ts||(ts={}));var ei;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||$t.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||$t.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(ei||(ei={}));var $t;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})($t||($t={}));var Rt;(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={}))})(Rt||(Rt={}));var Jp={transform:!0,"transform-origin":!0},Qp={top:!0,bottom:!0,left:!0,right:!0},or=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},ef={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 tf(e,t){let i=ef[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var uo=class $i extends Xo{constructor(t,i){super(),this.container=t,this.bleedBox=i,u(this,"pageAreaElement",null),u(this,"delayedItems",[]),u(this,"hrefHandler"),u(this,"elementsById",{}),u(this,"dimensions",{width:0,height:0}),u(this,"isFirstPage",!1),u(this,"isLastPage",!1),u(this,"isBlankPage",!1),u(this,"isAutoPageWidth",!0),u(this,"isAutoPageHeight",!0),u(this,"spineIndex",0),u(this,"position",null),u(this,"offset",-1),u(this,"side",null),u(this,"fetchers",[]),u(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),u(this,"pageType",null),this.hrefHandler=n=>{let s=n.currentTarget,o=s.getAttribute("href")||s.getAttributeNS("http://www.w3.org/1999/xlink","href");if(o){let r={type:"hyperlink",target:null,currentTarget:null,anchorElement:s,href:o,preventDefault(){n.preventDefault()}};this.dispatchEvent(r)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute($i.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute($i.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute($i.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute($i.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 r=this.elementsById[o];for(let a=0;a<r.length;)this.container.contains(r[a])?a++:r.splice(a,1);r.length===0&&delete this.elementsById[o]});let n=this.delayedItems;for(let o=0;o<n.length;o++){let r=n[o];r.target===this.container&&r.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||T(r.target,r.name,r.value.toString())}let s=i.getElementClientRect(this.container);this.dimensions.width=s.width,this.dimensions.height=s.height;for(let o=0;o<t.length;o++){let r=t[o],a=this.elementsById[r.ref],h=this.elementsById[r.observer];if(a&&h){let l=tf(a,r.action);if(l)for(let c=0;c<h.length;c++)h[c].addEventListener(r.event,l,!1)}}}};u(uo,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),u(uo,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var Th=uo,Ke=Rt.Whitespace;function Ih(e){switch(e){case"normal":case"nowrap":return Ke.IGNORE;case"pre-line":return Ke.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return Ke.PRESERVE;default:return null}}function ze(e,t){if(!e)return!0;if(e.nodeType==1)return!1;let i=e.textContent;switch(t){case Ke.PRESERVE:return i.length==0;case Ke.NEWLINE:return!!i.match(/^[ \t]*$/);case Ke.IGNORE:default:return!!i.match(/^[ \t\r\n\f]*$/)}}var nf=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,u(this,"forcedBreakOffsets",[]),u(this,"formattingContext",null)}},sf=class{constructor(e,t,i,n,s,o,r,a,h){this.flowName=e,this.element=t,this.startOffset=i,this.priority=n,this.linger=s,this.exclusive=o,this.repeated=r,this.last=a,this.breakBefore=h,u(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function of(e,t){return e.top-t.top}function rf(e,t){return t.right-e.right}function Ah(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===Rt.ShadowType.ROOTLESS&&t.shadowType===Rt.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&po(e.shadowContext,t.shadowContext)&&po(e.nodeShadow,t.nodeShadow)&&Ah(e.shadowSibling,t.shadowSibling)}function Wt(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(!Ah(e.steps[i],t.steps[i]))return!1;return!0}function af(e){return{steps:[{node:e,shadowType:ht.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function is(e,t){return{steps:[{node:e.sourceNode,shadowType:ht.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function ns(e,t){let i=new Wi(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?ns(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var ht=Rt.ShadowType,co=class{constructor(e,t,i,n,s,o,r){this.owner=e,this.root=t,this.xmldoc=i,this.parentShadow=n,this.type=o,this.styler=r,u(this,"subShadow",null),s&&(s.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&po(this.parentShadow,e.parentShadow):!1}};function po(e,t){return e===t||!!e&&!!t&&e.equals(t)}var lf=class{constructor(e,t){this.outer=e,this.count=t}},Wi=class Rh{constructor(t,i,n){this.sourceNode=t,this.parent=i,this.boxOffset=n,u(this,"offsetInNode",0),u(this,"after",!1),u(this,"shadowType"),u(this,"shadowContext"),u(this,"nodeShadow",null),u(this,"shadowSibling",null),u(this,"shared",!1),u(this,"inline",!0),u(this,"overflow",!1),u(this,"breakPenalty"),u(this,"display",null),u(this,"floatReference"),u(this,"floatSide",null),u(this,"clearSide",null),u(this,"floatMinWrapBlock",null),u(this,"columnSpan",null),u(this,"verticalAlign","baseline"),u(this,"captionSide","top"),u(this,"inlineBorderSpacing",0),u(this,"blockBorderSpacing",0),u(this,"flexContainer",!1),u(this,"whitespace"),u(this,"hyphenateCharacter"),u(this,"breakWord"),u(this,"establishesBFC",!1),u(this,"containingBlockForAbsolute",!1),u(this,"breakBefore",null),u(this,"breakAfter",null),u(this,"viewNode",null),u(this,"clearSpacer",null),u(this,"inheritedProps"),u(this,"vertical"),u(this,"direction"),u(this,"firstPseudo"),u(this,"lang",null),u(this,"preprocessedTextContent",null),u(this,"formattingContext"),u(this,"repeatOnBreak",null),u(this,"pluginProps",{}),u(this,"fragmentIndex",1),u(this,"afterIfContinues",null),u(this,"footnotePolicy",null),u(this,"pageType"),this.shadowType=ht.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=yi.FloatReference.INLINE,this.whitespace=i?i.whitespace:Ke.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=yi.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:Ke.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 Rh(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 s=this,o=[];s.shadowType===Rt.ShadowType.ROOTLESS&&(s.floatReference!==yi.FloatReference.INLINE||s.floatSide==="footnote")&&(n=(i=(t=s.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(s=s.parent);do(!s.firstPseudo||!s.parent||s.parent.firstPseudo===s.firstPseudo)&&o.push(s.toNodePositionStep()),s=s.parent;while(s);let r=this.preprocessedTextContent?Zp(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:o,offsetInNode:r,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}},Gt=class Lh{constructor(t){this.primary=t,u(this,"floats",null)}clone(){let t=new Lh(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(!Wt(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(!Wt(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},hf=class Fh{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new Fh(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},uf=class Oh{constructor(){u(this,"positions",[]),u(this,"startBreakType",null),u(this,"breakAfter",null)}clone(){let t=new Oh,i=this.positions,n=t.positions;for(let s=0;s<i.length;s++)n[s]=i[s].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}},cf=class Bh{constructor(){u(this,"page",0),u(this,"flows",{}),u(this,"flowPositions",{}),u(this,"isBlankPage",!1),u(this,"highestSeenOffset",0),u(this,"highestSeenNode"),u(this,"lookupPositionOffset")}clone(){let t=new Bh;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 s of i)if(!this.flowPositions[s].isSamePosition(t.flowPositions[s]))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&&un(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},_h=class{constructor(e){this.element=e,u(this,"left",0),u(this,"top",0),u(this,"marginLeft",0),u(this,"marginRight",0),u(this,"marginTop",0),u(this,"marginBottom",0),u(this,"borderLeft",0),u(this,"borderRight",0),u(this,"borderTop",0),u(this,"borderBottom",0),u(this,"paddingLeft",0),u(this,"paddingRight",0),u(this,"paddingTop",0),u(this,"paddingBottom",0),u(this,"width",0),u(this,"height",0),u(this,"originX",0),u(this,"originY",0),u(this,"exclusions",null),u(this,"innerShape",null),u(this,"computedBlockSize",0),u(this,"snapWidth",0),u(this,"snapHeight",0),u(this,"snapOffsetX",0),u(this,"snapOffsetY",0),u(this,"vertical",!1),u(this,"rtl",!1),u(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):er(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 at(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 at(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return th(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 at(e,t,e+i,t+n)}},ss=class extends Ot{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.url)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 Ae&&(i=Oi(t.scope,new yt(i,null),"").stringValue()),this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof Ie&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function jt(e){return e!=null&&e!==W&&e!==v.normal&&e!==v.none&&!J(e)}var Ce=yi.FloatReference;function df(e){switch(e){case"inline":return Ce.INLINE;case"column":return Ce.COLUMN;case"region":return Ce.REGION;case"page":return Ce.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function xi(e){switch(e){case Ce.INLINE:return!1;case Ce.COLUMN:case Ce.REGION:case Ce.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function ga(e,t,i,n){let s=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=Eh(e,s,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let o=Ch(e,s,i),r=$p(o,s);r==="line-left"?e="left":r==="line-right"&&(e="right")}else e==="inside"?e=n==="left"?"right":"left":e==="outside"&&(e=n==="left"?"left":"right");return e!=="left"&&e!=="right"&&(H.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var Mh=class{constructor(e,t,i,n,s,o){this.nodePosition=e,this.floatReference=t,this.floatSide=i,this.clearSide=n,this.flowName=s,this.floatMinWrapBlock=o,u(this,"order",null),u(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}},pf=class{constructor(){u(this,"floats",[]),u(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(e){return`pf${e}`}addPageFloat(e){if(this.floats.findIndex(t=>Wt(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=>Wt(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}},zh=class{constructor(e,t,i,n,s,o){this.floatReference=e,this.floatSide=t,this.clearSide=i,this.continuations=n,this.area=s,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}},ma=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&Wt(this.nodePosition,e.nodePosition):!1}},Gi=class{constructor(e,t,i,n,s,o,r){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=s,u(this,"children",[]),u(this,"writingMode"),u(this,"direction"),u(this,"invalidated",!1),u(this,"floatStore"),u(this,"forbiddenFloats",[]),u(this,"floatFragments",[]),u(this,"stashedFloatFragments",[]),u(this,"floatAnchors",{}),u(this,"floatsDeferredToNext",[]),u(this,"floatsDeferredFromPrevious"),u(this,"layoutConstraints",[]),u(this,"locked",!1),e&&e.children.push(this),this.writingMode=o||e&&e.writingMode||v.horizontal_tb,this.direction=r||e&&e.direction||v.ltr,this.floatStore=e?e.floatStore:new pf;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 s=this.children.indexOf(e);s<0&&(s=this.children.length);for(let o=s-1;o>=0;o--){let r=this.children[o];if(r.floatReference===t&&r.flowName===i&&Wt(r.generatingNodePosition,n)||(r=r.getPreviousSiblingOf(null,t,i,n),r))return r}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 Ti().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,s)=>n.getOrder()-s.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 s=this.floatFragments.splice(n,1)[0],o=s.area&&s.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)}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(s=>{let o=s.float,r=o.getOrder();r>t&&(!i||r>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(s=>s.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===Ce.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(s=>s.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(s=>!i.isAllowedToPrecede(s)&&n>s.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let s=this.findPageFloatFragment(i);this.removePageFloatFragment(s)}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 Eh(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return Ch(e,t,i)}toLogicalFloatSides(e){let t=e.split(" "),i=[];for(let r of t){let a=this.toLogical(r);i.includes(a)||i.push(a)}let n=[],s=!1,o=!1;for(let r=0;r<i.length;r++){let a=i[r];a.includes("block")?s||(i.slice(r+1).some(h=>h.includes("block"))?(n.push("snap-block"),s=!0):n.push(a)):a.includes("inline")&&(o||(i.slice(r+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 s=this.floatFragments[n],o=this.toLogicalFloatSides(s.floatSide)[0];(o===i||i==="snap-block"&&o==="block-end"||i==="snap-inline"&&o==="inline-end")&&s.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(s),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,s){this.container;let o=this.toLogical(e),r=this.toPhysical(e),a=t&&this.toLogical(t),h=t&&this.toPhysical(t),l=this.getLimitValueInner(o,a,i,n,s);if(this.parent&&this.parent.container){let c=this.parent.getLimitValue(r,h,i,n,s);switch(r){case"top":return Math.max(l,c);case"left":return Math.max(l,c);case"bottom":return Math.min(l,c);case"right":return Math.min(l,c);default:}}return l}getLimitValueInner(e,t,i,n,s){this.container;let o=this.getLimitValuesInner(i,n,s,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,s){this.container;let o=this.container.originX,r=this.container.originY,a=this.container.getPaddingRect(),h={top:a.y1-r,left:a.x1-o,bottom:a.y2-r,right:a.x2-o,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};function l(p,d,f){return p.unit==="%"?f*p.num/100:e.convertLengthToPx(p,d,t)}let c=this.floatFragments;return c.length>0&&(h=c.reduce((p,d)=>{if(i&&!i(d,this))return p;let[f,m]=this.toLogicalFloatSides(d.floatSide);if(m&&(n&&m.includes("block")===n.includes("block")&&m!==n||s&&m.includes("block")===s.includes("block")&&m!==s))return p;let g=d.area,w=d.continuations[0].float.floatMinWrapBlock,y=p.top,b=p.left,C=p.bottom,k=p.right,R=p.floatMinWrapBlockStart,_=p.floatMinWrapBlockEnd;switch(f){case"inline-start":g.vertical?y=Math.max(y,g.top+g.height):b=Math.max(b,g.left+g.width);break;case"block-start":g.vertical?(w&&g.left<k&&(R=l(w,g.rootViewNodes[0],a.x2-a.x1)),k=Math.min(k,g.left)):(w&&g.top+g.height>y&&(R=l(w,g.rootViewNodes[0],a.y2-a.y1)),y=Math.max(y,g.top+g.height));break;case"inline-end":g.vertical?C=Math.min(C,g.top):k=Math.min(k,g.left);break;case"block-end":g.vertical?(w&&g.left+g.width>b&&(_=l(w,g.rootViewNodes[0],a.x2-a.x1)),b=Math.max(b,g.left+g.width)):(w&&g.top<C&&(_=l(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:y,left:b,bottom:C,right:k,floatMinWrapBlockStart:R,floatMinWrapBlockEnd:_}},h)),h.left+=o,h.right+=o,h.top+=r,h.bottom+=r,h}setFloatAreaDimensions(e,t,i,n,s,o,r){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,s,o,r);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!r["block-start"]&&!r["block-end"])return null}else if(a[0].includes("block")&&!r[a[0]])return null;e.clientLayout;let h=a.find(R=>R.includes("inline")&&r[R==="inline-start"?"inline-end":"inline-start"]),l=a.find(R=>R.includes("block")),c=this.getLimitValue("block-start",h,e.layoutContext,e.clientLayout),p=this.getLimitValue("block-end",h,e.layoutContext,e.clientLayout),d=this.getLimitValue("inline-start",l,e.layoutContext,e.clientLayout),f=this.getLimitValue("inline-end",l,e.layoutContext,e.clientLayout),m=e.vertical?e.originX:e.originY,g=e.vertical?e.originY:e.originX;c=e.vertical?Math.min(c,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+m):Math.max(c,e.top+m),p=e.vertical?Math.max(p,e.left+m):Math.min(p,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+m);function w(R,_){let z=R(e.bands,_);return z?(e.vertical&&(z=Jl(z)),c=e.vertical?Math.min(c,z.x2):Math.max(c,z.y1),p=e.vertical?Math.max(p,z.x1):Math.min(p,z.y2),!0):o}let y,b,C,k;if(s){let R=e.vertical?Jn(new at(p,d,c,f)):new at(d,c,f,p);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!w(_d,R)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(Md,R)||(C=(p-c)*e.getBoxDir(),y=C-e.getInsetBefore()-e.getInsetAfter(),k=(f-d)*e.getInlineDir(),b=k-e.getInsetStart()-e.getInsetEnd(),!o&&(y<=0||b<=0)))return null}else{y=e.computedBlockSize,C=y+e.getInsetBefore()+e.getInsetAfter();let R=(p-c)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let z=this.container.getPaddingRect(),G=this.container.getBoxDir()*(n-(this.container.vertical?z.x2:z.y1)),X=this.container.getBoxDir()*((this.container.vertical?z.x1:z.y2)-n-C);G<=X?a[0]="block-start":a[0]="block-end"}if(!r[a[0]])if(r["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(r["inline-start"])a[0]="inline-start";else if(r["inline-end"])a[0]="inline-end";else return null;if(!o&&R<C)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?b=sr(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?b=e.getContentInlineSize():b=e.vertical?e.height:e.width,k=b+e.getInsetStart()+e.getInsetEnd();let _=(f-d)*e.getInlineDir();if(!o&&_<k)return null}return c-=m,p-=m,d-=g,f-=g,a.some(R=>R==="inline-start"||R==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(d,b):(a.some(R=>R==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-k*e.getInlineDir(),b),a.some(R=>R==="block-start"||R==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(c,y):(a.some(R=>R==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(p-C*e.getBoxDir(),y),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(l){return c=>l.isAnchorAlreadyAppeared(c.float.getId())}function n(l,c){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(c))}let s=t.getPaddingRect(),o=t.vertical?s.x1:s.y2,r=this;for(;r;){if(r.floatsDeferredToNext.some(i(r)))return o;r=r.parent}function a(l){return l.floatFragments.some(c=>n(c,l))||l.children.some(c=>a(c))}if(e==="column"||e==="region"||e==="page"){for(r=this;r;r=r.parent)if(r.floatReference===e){if(a(r))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 s=this.toLogicalFloatSides(t)[0],o=this.toLogical(i),r;o==="all"?r=["block-start","block-end","inline-start","inline-end"]:o==="both"?r=["inline-start","inline-end"]:o==="same"?s==="snap-block"?r=["block-start","block-end"]:r=[s]:r=[o];let a=e.getOrder();function h(p){return d=>(!p||d.floatSide.includes(p))&&d.getOrder()<a}function l(p,d){return p.children.some(f=>f.floatFragments.some(h(d))||l(f,d))}function c(p,d){let f=p.parent;return!!f&&(f.floatFragments.some(h(d))||c(f,d))}if(i==="column"||i==="region"||i==="page"){for(let p=this;p;p=p.parent)if(p.floatReference===i){(p.floatFragments.some(h(null))||l(p,null))&&(n["block-start"]=!1,n["block-end"]=!1,n["inline-start"]=!1,n["inline-end"]=!1);break}return n}return r.forEach(p=>{switch(p){case"block-start":n[p]=!l(this,p);break;case"block-end":n[p]=!c(this,p);break;case"inline-start":case"inline-end":n[p]=!this.floatFragments.some(h(p));break;default:throw new Error(`Unexpected side: ${p}`)}}),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,s=null;for(;n&&n.container;){let r=n.getLimitValuesInner(t,i);s?e.vertical?(r.right<s.right&&(s.right=r.right,s.floatMinWrapBlockStart=r.floatMinWrapBlockStart),r.left>s.left&&(s.left=r.left,s.floatMinWrapBlockEnd=r.floatMinWrapBlockEnd)):(r.top>s.top&&(s.top=r.top,s.floatMinWrapBlockStart=r.floatMinWrapBlockStart),r.bottom<s.bottom&&(s.bottom=r.bottom,s.floatMinWrapBlockEnd=r.floatMinWrapBlockEnd)):s=r,n=n.parent}let o=Math.max(s.floatMinWrapBlockStart,s.floatMinWrapBlockEnd);return(e.vertical?s.right-s.left:s.bottom-s.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}},zi=[],Ti=class{static register(e){zi.push(e)}findByNodeContext(e){for(let t=zi.length-1;t>=0;t--){let i=zi[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=zi.length-1;t>=0;t--){let i=zi[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},ff=class{appliesToNodeContext(e){return xi(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let s=e.floatSide,o=e.toNodePosition();return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(r=>{n=r,t.flowName;let a=new Mh(o,n,s,e.clearSide,t.flowName,e.floatMinWrapBlock);return t.addPageFloat(a),P(a)})}createPageFloatFragment(e,t,i,n,s){let o=e[0].float;return new zh(o.floatReference,t,i,e,n,s)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){}forbid(e,t){}};Ti.register(new ff);var gf=zh,fo=class Dh extends Mh{constructor(t,i,n,s,o){super(t,i,"block-end",null,n,o),this.footnotePolicy=s}isAllowedToPrecede(t){return!(t instanceof Dh)}},wa=class extends gf{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof fo?!0:this.getOrder()<e.getOrder()}},mf=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.toNodePosition();return!Wt(t,this.footnote.nodePosition)}},wf=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof fo}createPageFloat(e,t,i){let n=Ce.REGION,s=t.getPageFloatLayoutContext(n);t.getPageFloatLayoutContext(Ce.PAGE).hasSameContainerAs(s)&&(n=Ce.PAGE);let o=e.toNodePosition();t.flowName;let r=new fo(o,n,t.flowName,e.footnotePolicy,e.floatMinWrapBlock);return t.addPageFloat(r),P(r)}createPageFloatFragment(e,t,i,n,s){let o=e[0].float;return new wa(o.floatReference,e,n,s)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof wa);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 v.line:{let n=new mf(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Ti.register(new wf);var bf="data-vivliostyle-flow-root";function vf(e){return e.getAttribute(bf)==="true"}function ba(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 B(i)}function rr(e){return e===v.absolute||e===v.fixed}function go(e){return e instanceof Fi&&e.name==="running"}function Vh(e,t,i,n){return e===v.none||(rr(t)?(i=v.none,e=ba(e)):(i&&i!==v.none&&!J(i)||n)&&(e=ba(e))),{display:e,position:t,float:i}}function Uh(e,t,i,n){return Vh(e,t,i,n).display===v.block}function zt(e){switch(e.toString()){case"inline":case"inline-block":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return!1}}function yf(e){switch(e.toString()){case"block":case"flex":case"grid":case"table":case"list-item":case"flow-root":return!0;default:return!1}}function Hh(e){switch(e.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function xf(e,t,i,n,s,o,r){return s=s||o||v.horizontal_tb,!!r||!!i&&i!==v.none&&!J(i)||rr(t)||e===v.inline_block||e===v.table_cell||e===v.table_caption||e==v.flex||e==v.grid||e==v.flow_root||(e===v.block||e===v.list_item)&&!!n&&n!==v.visible&&n!==v.clip&&!J(n)||!!o&&s!==o}function Sf(e){return e===v.relative||e===v.absolute||e===v.fixed}var rt=1e5;function ar(e){let t=e.element.style;t.columnGap=`${rt-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function $h(e){let t=e.element.style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function Wh(e){return e.element.style.columnCount==="1"}function Cf(e){e.element.setAttribute("data-vivliostyle-column","true")}function Ef(e){return e.element.hasAttribute("data-vivliostyle-column")}function os(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/rt)}function mo(e,t){let i=os(e,t);if(i===0)return 0;let n=t?e.top:Math.min(Math.abs(e.left),Math.abs(e.right)),s=Math.round(n/rt),o=s*rt,r=i*rt;return t?(e.top-=o,e.bottom-=r,e.bottom<e.top&&(e.bottom+=rt,r-=rt),e.right-=o,e.left-=r):e.left<-rt/2?(e.right+=o,e.left+=r,e.left>e.right&&(e.left-=rt,r+=rt),e.top+=o,e.bottom+=r):(e.left-=o,e.right-=r,e.right<e.left&&(e.right+=rt,r-=rt),e.top+=o,e.bottom+=r),e.width=e.right-e.left,e.height=e.bottom-e.top,s}function Gh(e,t){for(let i=0;i<e.length;i++)mo(e[i],t)}function wt(e,t,i){var n;let s=e.getElementClientRect(t),o=mo(s,i);if(o===1){let r=e.getElementComputedStyle(t);if(r.display==="table-cell"||t.className==="-vivliostyle-table-cell-container"&&(n=t.parentElement)!=null&&n.parentElement&&(r=e.getElementComputedStyle(t.parentElement.parentElement)).display==="table-cell"){let a=t.closest("[data-vivliostyle-column]"),h=a?.style,l=i?"width":"height",c=h&&parseFloat(h[l]);if(c){let p=c,d=o,f=parseFloat(r.paddingBlockEnd),m=parseFloat(r.borderBlockEndWidth),g=Math.ceil(f+m);for(;g-- >0&&d===o&&--p>0;){h[l]=`${p}px`;let w=e.getElementClientRect(t);if(d=mo(w,i),d<o||d===o&&(i?w.right>s.right:w.top<s.top))return a.setAttribute("data-vivliostyle-column-height-adjusted","true"),w}h[l]=`${c}px`}}}return s}function kf(e,t){var i,n;if(e.nodeType===1){let s=e;((i=s.style)==null?void 0:i.breakAfter)==="column"&&(s.style.breakAfter="")}if(t.nodeType===1){let s=t;((n=s.style)==null?void 0:n.breakBefore)==="column"&&(s.style.breakBefore="")}}function lr(e){for(let t=e.nodeType===1?e:e.parentElement;t;t=t.parentElement){let i=t.style;if(!i||t.hasAttribute("data-vivliostyle-column"))break;if(!isNaN(parseFloat(i.columnCount))||!isNaN(parseFloat(i.columnWidth)))return t;if(i.position==="absolute")break}return null}function Pf(e){var t;if(e.nodeType!==1)return;let i=e,n=i.style,s=n?.breakBefore==="column",o=i.previousElementSibling,r=o&&((t=o.style)==null?void 0:t.breakAfter)==="column";if(!s&&!r)return;let a=lr(i);if(!a)return;let h=a.ownerDocument.defaultView.getComputedStyle(a),{writingMode:l,direction:c,columnGap:p,fontSize:d}=h,f=l==="vertical-rl"||l==="vertical-lr",m=c==="rtl",g=(parseFloat(p)||parseFloat(d)||16)/2,w=a.getBoundingClientRect(),y=i.getBoundingClientRect();(f?y.top>w.bottom+g:m?y.right<w.left-g:y.left>w.right+g)&&(s&&(n.breakBefore=""),r&&o&&(o.style.breakAfter=""),n.marginBlockStart=`${rt}px`)}function pi(e,t,i,n){let s=e.viewNode;if(!s)return NaN;let o=s.nodeType===1?s:s.parentElement;if(o&&o.namespaceURI==="http://www.w3.org/1999/xhtml"){let r=o.style;if(o.localName==="br"||o.localName==="wbr"||r&&zt(r.display)&&/^([\d\.]|super|(text-)?top)/.test(r.verticalAlign))return NaN}if(s===o){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 r=wt(t,o,n);if(r.left===0&&r.top===0&&r.right===0&&r.bottom===0)return NaN;if(r.right>=r.left&&r.bottom>=r.top)return e.after?n?r.left:r.bottom:n?r.right:r.top}return NaN}else{let r=NaN,a=s.ownerDocument.createRange(),h=s.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(s,i),a.setEnd(s,i+1);let l=t.getRangeClientRects(a);return Gh(l,n),l=l.filter(c=>c.right>c.left&&c.bottom>c.top),l.length?(n?r=Math.min.apply(null,l.map(c=>c.left)):r=Math.max.apply(null,l.map(c=>c.bottom)),r):NaN}}function wo(e,t,i){let n=Wh(t);n&&$h(t);let s=t.clientLayout.getElementClientRect(e);n&&ar(t);let o=t.getComputedMargin(e);return i?s.width+o.left+o.right:s.height+o.top+o.bottom}function gi(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function jh(e,t){var i;if(e)for(let n=e.lastChild,s=n;n!==t;n=s)s=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 Ii="data-adapt-spec";function hr(e){return!!e.getAttribute(Ii)}function ji(e){var t;if(e?.nodeType!==1)return!1;let i=e;if(hr(i))return!0;let n=(t=i.style)==null?void 0:t.position;return n==="absolute"||n==="fixed"}function mi(e){let t=e?.viewNode;return t?.nodeType===1&&hr(t)}function Nf(e){return e!=="inline"&&(zt(e)||Hh(e))}function va(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))&&zt(i.display))return i;return null}var ur=class{calculateOffset(e){return Si(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function Si(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var Pn=class extends ur{constructor(e,t,i,n){super(),this.position=e,this.breakOnEdge=t,this.overflows=i,this.computedBlockSize=n,u(this,"overflowIfRepetitiveElementsDropped"),u(this,"isEdgeUpdated",!1),u(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(es(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=pi(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,s=n?.closest("table, [style*='display: table;']");if(s){let o=s.style.borderCollapse==="collapse",r=0,a=0;for(let h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===s&&!o)&&(r+=e.parseComputedLength(l.paddingBlockEnd)),h===s&&!o&&(r+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),o?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===s)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===s)break}this.edge+=(e.vertical?-1:1)*(r+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(!ei.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},Di=class{find(e){let t=vt("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()}`)}},wi=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 Pn(e.copy(),t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}clearOverflownViewNodes(e,t,i,n){var s;if(!i.viewNode||!i.viewNode.parentNode||i.shadowType===Rt.ShadowType.ROOTLESS&&mi(i))return;let o=i.viewNode;((s=o.parentElement)==null?void 0:s.localName)==="viv-ts-inner"&&(o=o.parentElement.parentElement);let r=o.parentNode;jh(r,o),n&&r.removeChild(o)}finishBreak(e,t,i,n){let s=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,s),n&&e.layoutContext.processFragmentedBlockEdge(t),P(!0)}},cr=class{constructor(e){this.parent=e,u(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},dr=new wi,Tf=ho.isInstanceOfBlockFormattingContext;ft("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,s,o)=>{let r=e.parent;return!r&&e.formattingContext||r&&e.formattingContext!==r.formattingContext?null:e.establishesBFC||!e.formattingContext&&Uh(i,n,s,o)?new cr(r?r.formattingContext:null):null});ft("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof cr?dr:null);var pr=class{constructor(){u(this,"initialBreakPositions",null),u(this,"initialStateOfFormattingContext",null),u(this,"initialPosition"),u(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=F("AbstractLayoutRetryer.tryLayout");this.saveState(e,t);let n=this.resolveLayoutMode(e);return n.doLayout(e,t).then(s=>{let o=n.accept(s,t);o=n.postLayout(s,this.initialPosition,t,o),o?i.finish(s):(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)}},If=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){}},bo=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=F("LayoutIterator");return n.loopWithFrame(s=>{let o;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?ze(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 r=(o&&o.isPending()?o:P(!0)).thenAsync(()=>i.break?P(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(r.isPending()){r.then(a=>{i.break?s.breakLoop():(i.nodeContext=a,s.continueLoop())});return}else if(i.break){s.breakLoop();return}else i.nodeContext=r.get()}t.finish(i),s.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},en=class extends If{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&&je(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,s=!t.allowLayout(n);return s&&(i.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),n=e.nodeContext=n.modify(),n.overflow=!0),s}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=Xe(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:P(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),P(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:P(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=Xe(e.breakAtTheEdge,e.nodeContext.breakAfter)),P(!0)))}},vo=[];function Af(){vo=[]}function Xh(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var Rf=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},Lf=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},qh=class $n{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let s=$n.fragmentIndices;(!s[t]||s[t].priority<=n)&&(s[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){$n.fragmentIndices={}}matches(){let t=$n.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&Xh(t.fragmentIndex,this.a,this.b)}};u(qh,"fragmentIndices",{});var vs=qh,_n=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new vs(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new Lf(e)}static buildAnyMatcher(e){return new Rf(e)}},Yh={"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},Ff=["image-resolution","orphans","widows"];function Of(){return vt("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(Ff))}var Bf={"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},yo=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],_f=["max-%","min-%","%"],ya=(()=>{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<yo.length;i++)for(let n=0;n<e.length;n++){let s=yo[i].replace("%",e[n]);t[s]=!0}return t})();function Bi(e,t){let i={};for(let n of yo)for(let s in e){let o=n.replace("%",s),r=n.replace("%",e[s]);i[o]=r,i[r]=o}for(let n of _f)for(let s in t){let o=n.replace("%",s),r=n.replace("%",t[s]);i[o]=r,i[r]=o}return i}var Kh=Bi({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),Zh=Bi({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),Mf=Bi({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),zf=Bi({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),Df=Bi({inside:"right",outside:"left"},{}),Vf=Bi({inside:"left",outside:"right"},{}),Z=class xo{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 xo(i,this.priority)}increaseSpecificity(t){return t==0?this:new xo(this.value,this.priority+t)}evaluate(t,i,n,s){return i&&At(i)?this.value:as(t,this.value,i,n,s)}isEnabled(t){return!0}},So=class Co extends Z{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new Z(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new Co(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new Co(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){H.warn(i)}return!1}};function Eo(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Lt(e,t,i,n){if(e)if(!i)delete e[t];else{let s=e[t];(!s||i.priority>=s.priority)&&(n?i.isEnabled(n)&&(e[t]=i.getBaseValue()):e[t]=i)}}var Jh={"region-id":!0,"fragment-selector-id":!0};function Uf(e){return!!Jh[e]}function ko(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Ci(e){return e.charAt(0)!=="_"&&!Jh[e]}function tn(e){return!!Yh[e]||At(e)}function Ve(e,t){return e[t]}function ti(e,t,i){i?e[t]=i:delete e[t]}function bt(e,t){return e[t]}function ys(e,t){let i=e[t];return i||(i={},e[t]=i),i}var Qh=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function eu(e,t){return e[t]}function tu(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function rs(e,t,i,n,s,o,r){var a,h;if([{id:s,styleKey:"_pseudos"},{id:o,styleKey:"_regions"}].forEach(l=>{if(l.id){let c=ys(t,l.styleKey);t=c[l.id],t||(t={},c[l.id]=t)}}),r){let l=Qh(t);t={},l.push({styles:t,matcher:r})}for(let l in i)if(!ko(l))if(Uf(l)){let c=eu(i,l),p=tu(t,l);Array.prototype.push.apply(p,c)}else{let c=Ve(i,l);if(!c.isEnabled(e))continue;let p=c.increaseSpecificity(n);Lt(t,l,p,e);let d=(h=(a=e.style)==null?void 0:a.validatorSet.shorthands[l])==null?void 0:h.propList;if(d)for(let f of d){let m=new Z(W,p.priority);Lt(t,f,m,e)}}}function Hf(e,t){let i={};for(let n=0;n<t.length;n++)rs(e,i,t[n],0,null,null,null);return i}function iu(e,t){if(e.length>0){e.sort((n,s)=>s.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 $f=class extends Li{constructor(e,t){super(),this.props=e,this.context=t,u(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=Ve(this.props,"font-size");if(!e.value.isNumeric())return ge.em;let t=e.value;if(!pd(t.unit))throw new Error("Unexpected state");return t.num*ge[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?Po(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="ex"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?fr(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?as(this.context,e,this.propName).visit(this):e}};function fr(e,t,i){let n=e.unit,s=e.num;if(n==="em"||n==="ex"){let o=ge[n]/ge.em;return new I(s*o*t,"px")}else return n==="rem"?new I(s*i.fontSize(),"px"):n==="rlh"?new I(s*i.rootLineHeight,"px"):e}function Po(e,t,i){e=fr(e,t,i);let n=e.unit,s=e.num;return n==="px"?e:n==="%"?new I(s/100*t,"px"):new I(s*i.queryUnitSize(n,!1),"px")}var _i=class{apply(e){}mergeWith(e){return new Wf([this,e])}clone(){return this}},Mn=class extends _i{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},Wf=class nu extends _i{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 nu([].concat(this.list))}},gr=class extends _i{constructor(e,t,i,n,s){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=s}apply(e){rs(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},de=class extends _i{constructor(){super(),u(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Gf=class extends de{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}},jf=class extends de{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}},xa=class extends de{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}},Xf=class extends de{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}},qf=class extends de{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 s=n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");s&&s.match(this.epubTypePatt)&&this.chained.apply(e)}}}},Yf=class extends de{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function xs(e,t,i,n){if(!e)return!1;if(t!==null)return n(e,t,i);for(let s of e.getAttributeNames())if((s===i||s.endsWith(`:${i}`))&&n(e,s===i?"":e.lookupNamespaceURI(s.split(":")[0]),i))return!0;return!1}var Sa=class extends de{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){xs(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},Kf=class extends de{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){xs(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}},Zf=class extends de{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){xs(e.currentElement,this.ns,this.name,(t,i,n)=>!!Bf[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Vi=class extends de{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){xs(e.currentElement,this.ns,this.name,(t,i,n)=>{var s;return!!((s=t.getAttributeNS(i,n))!=null&&s.match(this.regexp))})&&this.chained.apply(e)}},Jf=class extends de{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Ca=class extends de{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},Qf=class extends de{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},Nn=class extends de{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return Xh(e,this.a,this.b)}},eg=class extends Nn{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},No=class extends Nn{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}},To=class extends Nn{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}},Io=class extends Nn{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,s=i.localName,o=t[n];o||(o=t[n]={}),o[s]=(o[s]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},tg=class extends de{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}},ig=class extends de{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},ng=class extends de{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},sg=class extends de{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},$e=class extends de{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}},og=class su extends _i{constructor(){super(),u(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new su;return t.applied=this.applied,t}},mr=class extends de{constructor(e){super(),u(this,"checkAppliedAction"),u(this,"firstActions",[]),this.checkAppliedAction=new og;for(let t of e)this.firstActions.push(iu(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 de?e.getPriority():0))}positive(){return!0}relational(){return!1}},rg=class extends mr{positive(){return!1}},ag=class extends mr{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}},Ss=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)}},lg=class ou extends Ss{constructor(t,i,n){super(t,i,n)}fresh(t){return new ou(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}},hg=class ru extends Ss{constructor(t,i,n){super(t,i,n)}fresh(t){return new ru(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)}},ug=class au extends Ss{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new au(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)}},cg=class lu extends Ss{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new lu(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}},dg=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}},pg=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}},fg=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}},gg=class extends Li{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new pt(e):new pt("about:invalid");case"string":default:return e?new Le(e):new Le("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let t="string",i=null,n=null;if(e.values[0]instanceof me){let s=e.values[0].values;s.length>=2&&(t=s[1].stringValue()),i=s[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 nn(e){if(jt(e)){if(e instanceof Le)return e.stringValue();if(e instanceof me)return e.values.map(t=>nn(t)).join("")}return""}var Ao=class extends Li{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 s=i[2*Math.min(n,t.quoteDepth)];return t.quoteDepth++,s}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 Le("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new Le("")}return e}format(e,t){let i=!1,n=!1,s;(s=t.match(/^upper-(.*)/))!=null?(i=!0,t=s[1]):(s=t.match(/^lower-(.*)/))!=null&&(n=!0,t=s[1]);let o="";return Ea[t]?o=wg(Ea[t],e):ka[t]?o=vg(ka[t],e):Pa[t]!=null?o=Pa[t]:t=="decimal-leading-zero"?(o=`${e}`,o.length==1&&(o=`0${o}`)):t=="cjk-ideographic"||t=="trad-chinese-informal"?o=xg(e,yg):o=`${e}`,i?o.toUpperCase():n?o.toLowerCase():o}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 s=n&&n.length&&n[n.length-1]||0;return new Le(this.format(s,i))}else{let s=new V(this.counterResolver.getPageCounterVal(t,o=>this.format(o||0,i)));return new me([s])}}visitFuncCounters(e){let t=e[0].toString(),i=e[1].stringValue(),n=e.length>2?e[2].stringValue():"decimal",s=this.cascade.counters[t],o=new It;if(s&&s.length)for(let a=0;a<s.length;a++)a>0&&o.append(i),o.append(this.format(s[a],n));let r=new V(this.counterResolver.getPageCountersVal(t,a=>{let h=[];if(a.length)for(let c=0;c<a.length;c++)h.push(this.format(a[c],n));let l=o.toString();return l.length&&h.push(l),h.length?h.join(i):this.format(0,n)}));return new me([r])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof pt?i=t.url:i=t.stringValue();let n=e[1].toString(),s=e.length>2?e[2].stringValue():"decimal",o=new V(this.counterResolver.getTargetCounterVal(i,n,r=>this.format(r||0,s)));return new me([o])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof pt?i=t.url:i=t.stringValue();let n=e[1].toString(),s=e[2].stringValue(),o=e.length>3?e[3].stringValue():"decimal",r=new V(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,o));return h.length?h.join(s):this.format(0,o)}));return new me([r])}visitFuncTargetText(e){let t=e[0],i;t instanceof pt?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",s=new V(this.counterResolver.getTargetTextVal(i,n));return new me([s])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new V(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 V(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,s,o,r;let a=e.length>0?e[0].stringValue():"text",h="";switch(a){case"text":h=this.element.textContent;break;case"before":case"after":{let l=bt(this.cascade.currentStyle,"_pseudos"),c=(i=(t=l?.[a])==null?void 0:t.content)==null?void 0:i.value;h=nn(c)}break;case"first-letter":{let l=bt(this.cascade.currentStyle,"_pseudos"),c=(nn((s=(n=l?.before)==null?void 0:n.content)==null?void 0:s.value)||this.element.textContent||nn((r=(o=l?.after)==null?void 0:o.content)==null?void 0:r.value)).match(Zn);h=c?c[0]:""}break}return new Le(h)}visitFuncLeader(e){let t="";if(e[0]instanceof nt)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof Le&&(t=e[0].stringValue());return t.length==0?new Le(""):new V(new Ie(null,()=>t,"viv-leader"))}visitFunc(e){switch(e.name){case"counter":if(e.values.length<=2)return this.visitFuncCounter(e.values);break;case"counters":if(e.values.length<=3)return this.visitFuncCounters(e.values);break;case"target-counter":if(e.values.length<=3)return this.visitFuncTargetCounter(e.values);break;case"target-counters":if(e.values.length<=4)return this.visitFuncTargetCounters(e.values);break;case"target-text":if(e.values.length>=1&&e.values.length<=2)return this.visitFuncTargetText(e.values);break;case"string":if(e.values.length<=2)return this.visitFuncString(e.values);break;case"element":if(e.values.length<=2)return this.visitFuncElement(e.values);break;case"content":if(e.values.length<=1)return this.visitFuncContent(e.values);break;case"leader":if(e.values.length<=1)return this.visitFuncLeader(e.values);break}return e}};function $s(e,t,i){let n;if(e.nodeType===1)n=Array.from(e.getClientRects());else{let s=e.ownerDocument.createRange();s.selectNodeContents(e),n=t.getRangeClientRects(s)}return n.reduce((s,o)=>s+(i==="vertical-rl"||i==="vertical-lr"?o.height:o.width),0)}var mg=(e,t,i)=>{let n=t.filter(h=>h.after&&h.viewNode.nodeType===1&&h.viewNode.getAttribute("data-viv-leader"));for(let h of n){let l=function(E){C==="rtl"?m.textContent=(E.startsWith("\u200F")?"":"\u200F")+E+(E.endsWith("\u200F")?"":"\u200F"):m.textContent=E},c=function(){let E=i.clientLayout.getElementClientRect(g);return b==="vertical-rl"||b==="vertical-lr"?C==="rtl"?E.top-=x:E.bottom+=x:C==="rtl"?E.left-=x:E.right+=x,z.left>E.left||z.right<E.right||z.top>E.top||z.bottom<E.bottom},p=function(){let E,A,L=y.repeat(1e4);if(l(L),c())E=1,A=1e4;else return;for(let M=0;M<16;M++){let U="",j=Math.floor((E+A)/2);for(let q=0;q<j;q++)U+=y;if(l(U),c())A=j;else{if(E==j)return;E=j}}l(y)},d=function(E){let A=0,L=g.parentElement;for(;L&&L!==f.viewNode;)A+=i.getComputedInsets(L)[E],L=L.parentElement;return A};var s=l,o=c,r=p,a=d;let f=h.parent;for(;f&&f.inline;)f=f.parent;let m=h.viewNode,g=m.parentElement,w=g.getAttribute("data-adapt-pseudo"),y=m.getAttribute("data-viv-leader-value"),{writingMode:b,direction:C,marginInlineEnd:k}=i.clientLayout.getElementComputedStyle(g);m.style.marginInlineStart="1px",l(y),g.style.display="inline-block",g.style.textIndent="0";let R=lr(f.viewNode),_=R?.style.columnFill||null;R&&(R.style.columnFill="auto");let z=i.clientLayout.getElementClientRect(f.viewNode),G=i.clientLayout.getElementClientRect(g),X=i.parseComputedLength(k),Ze=[],Je=g.parentElement;for(;Je.parentElement&&Je.parentElement!==f.viewNode;)Je=Je.parentElement;let we=Je.nextSibling;for(;we;){if(we.nodeType===1){let E=we,{display:A,float:L,position:M}=i.clientLayout.getElementComputedStyle(E);if(L!=="none"||M==="absolute"||M==="fixed"){we=we.nextSibling;continue}if(zt(A))Ze.push(E);else if(yf(A))break}else if(we.nodeType===3){let E=we;E.length>0&&Ze.push(E)}we=we.nextSibling}let x=Ze.reduce((E,A)=>E+$s(A,i.clientLayout,b),0);if(w!=="after"){let E=$s(Je,i.clientLayout,b),A=$s(g,i.clientLayout,b);x+=E-A}b==="vertical-rl"||b==="vertical-lr"?(C==="rtl"?z.top+=X:z.bottom-=X,z.top=Math.min(G.top,z.top),z.bottom=Math.max(G.bottom,z.bottom)):(C==="rtl"?z.left+=X:z.right-=X,z.left=Math.min(G.left,z.left),z.right=Math.max(G.right,z.right)),p();let O=i.clientLayout.getElementClientRect(g);C=="rtl"?g.style.float="left":g.style.float="right";let S=i.clientLayout.getElementClientRect(g),N=0;C=="rtl"?b=="vertical-rl"||b=="vertical-lr"?N=O.top-S.top-d("top"):N=O.left-S.left-d("left"):b=="vertical-rl"||b=="vertical-lr"?N=S.bottom-O.bottom-d("bottom"):N=S.right-O.right-d("right"),N-=x,N=Math.max(0,N-.1),g.style.float="",m.style.marginInlineStart=`${N}px`,R&&(_?R.style.columnFill=_:R.style.removeProperty("column-fill"))}};ft("POST_LAYOUT_BLOCK",mg);var Ea={roman:[4999,1e3,"M",900,"CM",500,"D",400,"CD",100,"C",90,"XC",50,"L",40,"XL",10,"X",9,"IX",5,"V",4,"IV",1,"I"],armenian:[9999,9e3,"\u0584",8e3,"\u0583",7e3,"\u0582",6e3,"\u0581",5e3,"\u0580",4e3,"\u057F",3e3,"\u057E",2e3,"\u057D",1e3,"\u057C",900,"\u057B",800,"\u057A",700,"\u0579",600,"\u0578",500,"\u0577",400,"\u0576",300,"\u0575",200,"\u0574",100,"\u0573",90,"\u0572",80,"\u0571",70,"\u0570",60,"\u056F",50,"\u056E",40,"\u056D",30,"\u056C",20,"\u056B",10,"\u056A",9,"\u0569",8,"\u0568",7,"\u0567",6,"\u0566",5,"\u0565",4,"\u0564",3,"\u0563",2,"\u0562",1,"\u0561"],georgian:[19999,1e4,"\u10F5",9e3,"\u10F0",8e3,"\u10EF",7e3,"\u10F4",6e3,"\u10EE",5e3,"\u10ED",4e3,"\u10EC",3e3,"\u10EB",2e3,"\u10EA",1e3,"\u10E9",900,"\u10E8",800,"\u10E7",700,"\u10E6",600,"\u10E5",500,"\u10E4",400,"\u10F3",300,"\u10E2",200,"\u10E1",100,"\u10E0",90,"\u10DF",80,"\u10DE",70,"\u10DD",60,"\u10F2",50,"\u10DC",40,"\u10DB",30,"\u10DA",20,"\u10D9",10,"\u10D8",9,"\u10D7",8,"\u10F1",7,"\u10D6",6,"\u10D5",5,"\u10D4",4,"\u10D3",3,"\u10D2",2,"\u10D1",1,"\u10D0"],hebrew:[999,400,"\u05EA",300,"\u05E9",200,"\u05E8",100,"\u05E7",90,"\u05E6",80,"\u05E4",70,"\u05E2",60,"\u05E1",50,"\u05E0",40,"\u05DE",30,"\u05DC",20,"\u05DB",19,"\u05D9\u05D8",18,"\u05D9\u05D7",17,"\u05D9\u05D6",16,"\u05D8\u05D6",15,"\u05D8\u05D5",10,"\u05D9",9,"\u05D8",8,"\u05D7",7,"\u05D6",6,"\u05D5",5,"\u05D4",4,"\u05D3",3,"\u05D2",2,"\u05D1",1,"\u05D0"]},ka={latin:"a-z",alpha:"a-z",greek:"\u03B1-\u03C1\u03C3-\u03C9",russian:"\u0430-\u0438\u043A-\u0449\u044D-\u044F"},Pa={square:"\u25A0",disc:"\u2022",circle:"\u25E6",none:""};function wg(e,t){let i=e[0];if(t>i||t<=0||t!=Math.round(t))return"";let n="";for(let s=1;s<e.length;s+=2){let o=e[s],r=Math.floor(t/o);if(r>20)return"";for(t-=r*o;r>0;)n+=e[s+1],r--}return n}function bg(e){let t=[],i=0;for(;i<e.length;)if(e.substr(i+1,1)=="-"){let n=e.charCodeAt(i),s=e.charCodeAt(i+2);i+=3;for(let o=n;o<=s;o++)t.push(String.fromCharCode(o))}else t.push(e.substr(i++,1));return t}function vg(e,t){if(t<=0||t!=Math.round(t))return"";let i=bg(e),n="";do{t--;let s=t%i.length;n=i[s]+n,t=(t-s)/i.length}while(t>0);return n}var yg={formal:!1,digits:"\u96F6\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D",markers:"\u5341\u767E\u5343",negative:"\u8CA0"};function xg(e,t){if(e>9999||e<-9999)return`${e}`;if(e==0)return t.digits.charAt(0);let i=new It;if(e<0&&(i.append(t.negative),e=-e),e<10)i.append(t.digits.charAt(e));else if(!t.formal&&e<=19)i.append(t.markers.charAt(0)),e!=0&&i.append(t.digits.charAt(e-10));else{let n=Math.floor(e/1e3);n&&(i.append(t.digits.charAt(n)),i.append(t.markers.charAt(2)));let s=Math.floor(e/100)%10;s&&(i.append(t.digits.charAt(s)),i.append(t.markers.charAt(1)));let o=Math.floor(e/10)%10;o&&(i.append(t.digits.charAt(o)),i.append(t.markers.charAt(0)));let r=e%10;r&&i.append(t.digits.charAt(r))}return i.toString()}var wr=1/1048576;function ai(e,t){for(let i in e)t[i]=e[i].clone()}var Sg=class hu{constructor(){u(this,"nsCount",0),u(this,"nsPrefix",{}),u(this,"tags",{}),u(this,"nstags",{}),u(this,"epubtypes",{}),u(this,"classes",{}),u(this,"ids",{}),u(this,"pagetypes",{}),u(this,"order",0)}clone(){let t=new hu;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return ai(this.tags,t.tags),ai(this.nstags,t.nstags),ai(this.epubtypes,t.epubtypes),ai(this.classes,t.classes),ai(this.ids,t.ids),ai(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,i,n){let s=t[i];s&&(n=s.mergeWith(n)),t[i]=n}createInstance(t,i,n,s){return new Cg(this,t,i,n,s)}nextOrder(){return this.order+=wr}},Cg=class{constructor(e,t,i,n,s){this.context=t,this.counterListener=i,this.counterResolver=n,u(this,"code"),u(this,"stack",[[],[]]),u(this,"conditions",{}),u(this,"currentElement",null),u(this,"currentElementOffset",null),u(this,"currentStyle",null),u(this,"currentClassNames",null),u(this,"currentLocalName",""),u(this,"currentNamespace",""),u(this,"currentId",""),u(this,"currentXmlId",""),u(this,"currentNSTag",""),u(this,"currentEpubTypes",null),u(this,"currentPageType",null),u(this,"previousPageType",null),u(this,"firstPageType",null),u(this,"isFirst",!0),u(this,"isRoot",!0),u(this,"counters",{}),u(this,"counterScoping",[{}]),u(this,"quotes"),u(this,"quoteDepth",0),u(this,"lang",""),u(this,"siblingOrderStack",[0]),u(this,"currentSiblingOrder",0),u(this,"siblingTypeCountsStack",[{}]),u(this,"currentSiblingTypeCounts"),u(this,"currentFollowingSiblingOrder",null),u(this,"followingSiblingOrderStack"),u(this,"followingSiblingTypeCountsStack",[{}]),u(this,"currentFollowingSiblingTypeCounts"),u(this,"viewConditions",{}),u(this,"dependentConditions",[]),u(this,"elementStack"),this.code=e,this.quotes=[new Le("\u201C"),new Le("\u201D"),new Le("\u2018"),new Le("\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=_n.buildViewConditionMatcher(this.currentElementOffset,e));let i=this.dependentConditions.map(n=>{let s=this.viewConditions[n];return s&&s.length>0?s.length===1?s[0]:_n.buildAnyMatcher([].concat(s)):null}).filter(n=>n);return i.length<=0?t:t===null?i.length===1?i[0]:_n.buildAllMatcher(i):_n.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=Ws,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,s,o,r,a;let h=v.inline,l=e.display;if(l&&(h=l.evaluate(this.context)),h===v.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 c=v.inline,p=e.float;p&&(c=p.evaluate(this.context));let d=null,f=null,m=null,g=e["counter-reset"];if(g){let b=g.evaluate(this.context);b&&(d=Zi(b,!0))}let w=e["counter-set"];if(w){let b=w.evaluate(this.context);b&&(m=Zi(b,!1))}let y=e["counter-increment"];if(y){let b=y.evaluate(this.context);b&&(f=Zi(b,!1))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(d||(d={}),d["list-item"]=((i=(t=this.currentElement)==null?void 0:t.start)!=null?i:1)-1),h===v.list_item&&(f||(f={}),f["list-item"]=(n=f["list-item"])!=null?n:1,/^\s*[-+]?\d/.test((o=(s=this.currentElement)==null?void 0:s.getAttribute("value"))!=null?o:"")&&(m||(m={}),m["list-item"]=this.currentElement.value)),((r=this.currentElement)==null?void 0:r.parentNode.nodeType)===Node.DOCUMENT_NODE&&(d||(d={}),d.footnote===void 0&&(d.footnote=0)),c===v.footnote&&(f||(f={}),f.footnote===void 0)){let b=(a=this.currentStyle["counter-increment"])==null?void 0:a.value;(!b||!(b===v.footnote||b instanceof me&&b.values.includes(v.footnote)))&&(f.footnote=1)}if(d)for(let b in d)this.defineCounter(b,d[b]);if(f)for(let b in f){this.counters[b]||this.defineCounter(b,0);let C=this.counters[b];C[C.length-1]+=f[b]}if(m)for(let b in m)if(!this.counters[b])this.defineCounter(b,m[b]);else{let C=this.counters[b];C[C.length-1]=m[b]}if(h===v.list_item){let b=this.counters["list-item"],C=b[b.length-1];e["ua-list-item-count"]=new Z(new Xt(C),0)}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 Ao(this,this.currentElement,this.counterResolver));let i=t.value instanceof qe?t.value.values:[t.value];for(let n of i)if(n instanceof me){let s=n.values[0].stringValue(),o=n.values.slice(1).map(r=>nn(r)).join("");this.counterResolver.setNamedString(s,o,this.currentElementOffset)}delete e["string-set"]}setRunningElement(e){let t=e.position;if(t?.value instanceof Fi&&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 Ao(this,t,this.counterResolver))),this.popCounters()}pushElement(e,t,i,n){var s,o;this.currentPageType=null,this.currentElement=t,this.currentElementOffset=n,this.currentStyle=i,this.currentNamespace=t.namespaceURI,this.currentLocalName=t.localName;let r=this.code.nsPrefix[this.currentNamespace];r?this.currentNSTag=r+this.currentLocalName:this.currentNSTag="",this.currentId=t.getAttribute("id"),this.currentXmlId=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let a=t.getAttribute("class");a?this.currentClassNames=a.split(/\s+/):this.currentClassNames=Ws;let h=t.getAttributeNS("http://www.idpf.org/2007/ops","type");h?this.currentEpubTypes=h.split(/\s+/):this.currentEpubTypes=Ws;let l=Ys(t);l&&(this.stack[this.stack.length-1].push(new pg(this.lang)),this.lang=l.toLowerCase());let c=this.isRoot,p=this.siblingOrderStack;this.currentSiblingOrder=++p[p.length-1],p.push(0);let d=this.siblingTypeCountsStack,f=this.currentSiblingTypeCounts=d[d.length-1],m=f[this.currentNamespace];m||(m=f[this.currentNamespace]={}),m[this.currentLocalName]=(m[this.currentLocalName]||0)+1,d.push({});let g=this.followingSiblingOrderStack;g[g.length-1]!==null?this.currentFollowingSiblingOrder=--g[g.length-1]:this.currentFollowingSiblingOrder=null,g.push(null);let w=this.followingSiblingTypeCountsStack,y=this.currentFollowingSiblingTypeCounts=w[w.length-1];y&&y[this.currentNamespace]&&y[this.currentNamespace][this.currentLocalName]--,w.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],e,t),this.applyCalcFilter(this.currentStyle,this.context),this.applyAttrFilter(t);let b=i.quotes,C=null;if(b){let _=b.evaluate(this.context);_&&(C=new fg(this.quotes),_===v.none?this.quotes=[new Le(""),new Le("")]:_===v.auto||_===v.initial?this.quotes=[new Le("\u201C"),new Le("\u201D"),new Le("\u2018"),new Le("\u2019")]:_ instanceof me&&(this.quotes=_.values))}this.pushCounters(this.currentStyle);let k=this.currentId||this.currentXmlId||t.getAttribute("name")||"";if(c||k){let _={};Object.keys(this.counters).forEach(z=>{_[z]=Array.from(this.counters[z])}),this.counterListener.countersOfId(k,_)}let R=bt(this.currentStyle,"_pseudos");if(R){let _=!0;for(let z of Eg){z||(_=!1);let G=R[z];G&&((z==="before"||z==="after")&&!jt((s=G.content)==null?void 0:s.value)||(z==="footnote-call"||z==="footnote-marker")&&((o=Ve(this.currentStyle,"float"))==null?void 0:o.value)!==v.footnote?delete R[z]:_?this.processPseudoelementProps(G,t):this.stack[this.stack.length-2].push(new dg(G,t)))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),C&&this.stack[this.stack.length-2].push(C)}applyAttrFilterInner(e,t){for(let i in t)Ci(i)&&!At(i)&&(t[i]=t[i].filterValue(e))}applyAttrFilter(e){let t=new gg(e),i=this.currentStyle,n=bt(i,"_pseudos");for(let s in n)this.applyAttrFilterInner(t,n[s]);this.applyAttrFilterInner(t,i)}applyVarFilter(e,t,i){var n,s,o;let r=e[0],a=new Fg(e,t,i),h=32,l={};for(let c in r)if(ko(c)){let p=bt(r,c);for(let d in p)this.applyVarFilter([p[d],...e],t,i)}else if(Ci(c)){let p=Ve(r,c),d=p.value;for(let f=0;;f++){if(f>=h){d=W;break}let m=d.visit(a);if(a.error){d=W,a.error=!1;break}if(m===d)break;d=m}if(d!==p.value){let f=t.validatorSet,m=(n=f?.shorthands[c])==null?void 0:n.clone();if(m)if(J(d)){for(let g of m.propList){let w=new Z(d,p.priority),y=Ve(r,g);ti(l,g,Eo(this.context,y,w))}delete r[c]}else{let g=Oi(t.scope,new yt(d.toString(),null),"");if(g&&(g.visit(m),!m.error)){for(let w of m.propList){let y=new Z((o=(s=m.values[w])!=null?s:f.defaultValues[w])!=null?o:v.initial,p.priority),b=Ve(r,w);ti(l,w,Eo(this.context,b,y))}delete r[c]}}else r[c]=new Z(d,p.priority)}if(l[c]){let f=Ve(r,c);f&&f.value!==W&&Lt(l,c,f,this.context)}}for(let c in l)r[c]=l[c]}applyCalcFilter(e,t){let i=new wu(t);for(let n in e)if(ko(n)){let s=bt(e,n);for(let o in s)this.applyCalcFilter(s[o],t)}else if(Ci(n)&&!At(n)){let s=Ve(e,n),o=s.value.visit(i);o!==s.value&&(e[n]=new Z(o,s.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()}},Ws=[],Eg=["before","transclusion-before","footnote-call","footnote-marker","inner","first-letter","first-line","","transclusion-after","after"],Ro=null;function kg(e){Ro=e}var cn=class extends En{constructor(e,t,i,n,s,o,r){super(e,t,r),this.condition=i,this.regionId=s,this.validatorSet=o,u(this,"chain",null),u(this,"specificity",0),u(this,"elementStyle",null),u(this,"conditionCount",0),u(this,"pseudoelement",null),u(this,"footnoteContent",!1),u(this,"cascade"),u(this,"state"),u(this,"viewConditionId",null),u(this,"insideSelectorRule"),u(this,"invalid",!1),this.cascade=n?n.cascade:Ro?Ro.clone():new Sg,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=iu(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 Xf(e,t.toLowerCase())):t?this.chain.push(new xa(t.toLowerCase())):this.chain.push(new Yf(e)))}invalidSelector(e){H.warn(e),this.chain.push(new $e("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof dn;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 Gf(e))}pseudoclassSelector(e,t){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new ig);break;case"disabled":this.chain.push(new ng);break;case"checked":this.chain.push(new sg);break;case"root":case"scope":this.chain.push(new Qf);break;case"link":this.chain.push(new xa("a")),this.chain.push(new Sa("","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)${Bt(i)}($|\\s)`),s=t[1];this.chain.push(new qf(n,s))}else this.chain.push(new $e(""));break;case"-adapt-footnote-content":case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new $e(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new Jf(new RegExp(`^${Bt(i.toLowerCase())}($|-)`)))}else this.chain.push(new $e(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=Pg[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new $e(""));break}case"first-child":this.chain.push(new Ca);break;case"last-child":this.chain.push(new To(0,1));break;case"first-of-type":this.chain.push(new No(0,1));break;case"last-of-type":this.chain.push(new Io(0,1));break;case"only-child":this.chain.push(new Ca),this.chain.push(new To(0,1));break;case"only-of-type":this.chain.push(new No(0,1)),this.chain.push(new Io(0,1));break;case"empty":this.chain.push(new tg);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"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 $e(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new $e(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}idSelector(e){this.specificity+=65536,this.chain.push(new jf(e))}attributeSelector(e,t,i,n){this.specificity+=256,t=t.toLowerCase(),n=n||"";let s;switch(i){case 0:s=new Sa(e,t);break;case 39:s=new Kf(e,t,n);break;case 45:!n||n.match(/\s/)?s=new $e(""):s=new Vi(e,t,new RegExp(`(^|\\s)${Bt(n)}($|\\s)`));break;case 44:s=new Vi(e,t,new RegExp(`^${Bt(n)}($|-)`));break;case 43:n?s=new Vi(e,t,new RegExp(`^${Bt(n)}`)):s=new $e("");break;case 42:n?s=new Vi(e,t,new RegExp(`${Bt(n)}$`)):s=new $e("");break;case 46:n?s=new Vi(e,t,new RegExp(Bt(n))):s=new $e("");break;case 50:if(n=="supported")s=new Zf(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(s)}descendantSelector(){let e=`d${zn++}`;this.processChain(new Mn(new lg(e,this.viewConditionId,null))),this.chain=[new $e(e)],this.viewConditionId=null}childSelector(){let e=`c${zn++}`;this.processChain(new Mn(new hg(e,this.viewConditionId,null))),this.chain=[new $e(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${zn++}`;this.processChain(new Mn(new ug(e,this.viewConditionId,null))),this.chain=[new $e(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${zn++}`;this.processChain(new Mn(new cg(e,this.viewConditionId,null))),this.chain=[new $e(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 gr(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new So(t,0,this.condition):i=new Z(t,0),tu(this.elementStyle,e).push(i)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){e=="display"&&(t===v.oeb_page_head||t===v.oeb_page_foot)&&(this.simpleProperty("flow-options",new me([v.exclusive,v._static]),i),this.simpleProperty("flow-into",t,i),t=v.block),vt("SIMPLE_PROPERTY").forEach(o=>{let r=o({name:e,value:t,important:i});e=r.name,t=r.value,i=r.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),s=this.condition?new So(t,n,this.condition):new Z(t,n);Lt(this.elementStyle,e,s)}finish(){return this.cascade}startFuncWithSelector(e){let t;switch(e){case"is":t=new dn(this);break;case"not":t=new Ng(this);break;case"where":t=new Tg(this);break;case"has":t=new Ig(this);break}t&&(t.startSelectorRule(),this.owner.pushHandler(t))}},Pg={"nth-child":eg,"nth-of-type":No,"nth-last-child":To,"nth-last-of-type":Io},zn=0,dn=class uu extends cn{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),this.parent=t,u(this,"parentChain"),u(this,"chains",[]),u(this,"maxSpecificity",0),u(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 ag(this.selectorTexts):this.positive()?new mr(this.chains):new rg(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new $e("")),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 s=this;s instanceof uu;s=s.parent)if(s.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}},Ng=class extends dn{positive(){return!1}forgiving(){return!1}},Tg=class extends dn{increasingSpecificity(){return!1}},Ig=class extends dn{relational(){return!0}},Ag=class extends En{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",s=new yn(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,s))}}},Dn=class extends En{constructor(e,t,i,n,s,o){super(e,t,!1),this.condition=i,this.elementStyle=n,this.validatorSet=s,this.ruleType=o,u(this,"order"),this.order=0}property(e,t,i){i?H.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){H.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){H.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=wr;let s=this.condition?new So(t,n,this.condition):new Z(t,n);Lt(this.elementStyle,e,s)}},Rg=class extends bh{constructor(e,t){super(e),this.validatorSet=t,u(this,"elementStyle",{}),u(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){H.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){H.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?wh:mh;n+=this.order,this.order+=wr;let s=new Z(t,n);Lt(this.elementStyle,e,s)}};function cu(e,t){let i=Qh(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function Lo(e,t,i){cu(i,n=>{sn(e,n,t)})}function Lg(e,t,i,n){let s=new Rg(e,t),o=new yt(n,s);try{Bp(o,s,i)}catch(r){H.warn(r,"Style attribute parse error:")}return s.elementStyle}function du(e,t,i){let n=e["writing-mode"];if(n){let s=n.evaluate(t,"writing-mode");if(s&&s!==v.inherit&&s!==v.revert&&s!==v.unset)return s===v.vertical_rl}return i}function pu(e,t,i){let n=e.direction;if(n){let s=n.evaluate(t,"direction");if(s&&s!==v.inherit&&s!==v.revert&&s!==v.unset)return s===v.rtl}return i}function fu(e,t,i,n,s){let o={};for(let r in e)Ci(r)&&(o[r]=Ve(e,r));return Lo(o,t,e),gu(e,i,n,(r,a)=>{sn(o,a,t),Lo(o,t,a)}),o}function gu(e,t,i,n){let s=bt(e,"_regions");if((t||i)&&s){if(i){let o=["footnote"];t?t=t.concat(o):t=o}for(let o of t){let r=s[o];r&&n(o,r)}}}function sn(e,t,i){for(let n in t)if(Ci(n)){let s=Ve(t,n),o=e[n];e[n]=Eo(i,o,s)}}var mu=(e,t,i,n,s,o)=>{var r,a;let h=i?n?Mf:Kh:n?zf:Zh,l=s?Df:Vf;for(let c in e){let p=e[c];if(!p)continue;let d=(r=h[c])!=null?r:h[l[c]],f=(a=l[c])!=null?a:l[h[c]],m=d??f,g;if(m){let w=e[m];if(w&&w.priority>p.priority||d&&f&&d!==f&&(m=f,w=e[m],w&&w.priority>p.priority))continue;g=ya[d]?d:ya[f]?f:c}else g=c,c.startsWith("text-align")&&(p.value===v.inside||p.value===v.outside)&&(p=new Z(s===(p.value===v.inside)?v.right:v.left,p.priority));t[g]=o(c,p)}},Fg=class extends Li{constructor(e,t,i){super(),this.elementStyles=e,this.styler=t,this.element=i}getVarValue(e){var t,i,n,s,o;let r=(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&&(r=this.element.parentElement)}for(;r;r=r.parentElement){let a=(o=(s=this.styler.getStyle(r,!1))==null?void 0:s[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 nt&&e.values[0].name;return!t||!At(t)?(this.error=!0,W):this.getVarValue(t)||(e.values.length<2?(this.error=!0,W):e.values.length===2?e.values[1]:new qe(e.values.slice(1)))}},wu=class extends Li{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=Oi(this.context.rootScope,new yt(i,null),"");if(n instanceof V)try{let s=n.expr.evaluate(this.context);typeof s=="number"&&!isNaN(s)&&(/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(i)?t=new I(s,"px"):/\d[a-z]/i.test(i)||(t=new Xt(s)))}catch(s){H.warn(s)}return t}visitNumeric(e){return this.resolveViewportUnit&&(Rl(e.unit)||gd(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 as(e,t,i,n,s){try{if(t instanceof V)return t.expr instanceof Ie&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:Dp(e,t.expr,i);if(t instanceof I||t instanceof Fi||t instanceof me||t instanceof qe)return t.visit(new wu(e,!0,n,s))}catch(o){return H.warn(o),W}return t}var Na={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Ta(e){let t=e instanceof He?e:typeof e=="string"?B(e):v.none;if(t===v.none)return Na;let i=t instanceof me?t.values:[t],n=Object.create(Na);for(let s of i)if(s instanceof nt)switch(s.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 Ia(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var Og={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},Aa={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},Ra={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function La(e){let t=e instanceof He?e:typeof e=="string"?B(e):v.normal;if(t===v.normal)return Aa;if(t===v.auto)return Ra;let i=t instanceof me?t.values:[t],n=Object.create(Aa);for(let s of i)if(s instanceof nt)switch(s.name){case"trim-both":case"trim-auto":return Ra;case"space-all":return Og;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 Gs={ideographAlpha:!1,ideographNumeric:!1},Bg={ideographAlpha:!0,ideographNumeric:!0};function Fa(e){let t=e instanceof He?e:typeof e=="string"?B(e):v.normal;if(t===v.normal||t===v.auto)return Bg;if(t===v.none)return Gs;let i=t instanceof me?t.values:[t],n=Object.create(Gs);for(let s of i)if(s instanceof nt)switch(s.name){case"no-autospace":return Gs;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Oa(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function Ba(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 _g=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 s=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(s.length>1){let o=s.length-1;for(let r=0;r<o;r++)n.parentNode.insertBefore(document.createTextNode(s[r]),n);n.textContent=s[o]}}}processGeneratedContent(e,t,i,n,s,o){s=Ba(s);let r=Fa(t),a=La(i),h=Ta(n);if(Ia(h)&&Oa(r,a))return;this.preprocessForTextSpacing(e);let l=e.style.whiteSpace;(o?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let c=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),p=null,d=null;for(let f=c.nextNode();f;f=d){d=c.nextNode();let m=!p,g=!p||/\n$/.test(p.textContent),w=!d||/^\n/.test(d.textContent),y=!d;this.processTextSpacing(f,m||g,m,g,w,y,p,d,r,a,h,s,o),p=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,s,o,r,a,h;let l=!e||e.fragmentIndex===1&&d(),c=l||f();function p(y){var b;if(y?.nodeType!==1)return!1;let C=y;if(C.hasAttribute(Ii))return!0;let{position:k,float:R}=(b=C.style)!=null?b:{};return k==="absolute"||k==="fixed"||R&&R!=="none"}function d(){let y=t[0];for(let b=y;;b=b.parent)if(!b||!b.inline){if(b?.fragmentIndex!==1)return!1;break}if(!y.inline)return!0;for(let b=y.viewNode.previousSibling;b;b=b.previousSibling)if(!ze(b,y.whitespace)&&!p(b))return!1;return!0}function f(){var y,b;let C=t[0],k;for(;C&&C.inline&&(k=(y=C.viewNode)==null?void 0:y.previousSibling,!(k&&(k.nodeType===3&&/^[ \t\r\n\f]*$/.test(k.textContent)&&C.whitespace!==Ke.PRESERVE&&(k=k.previousSibling),k)));)C=C.parent;for(;k;){if(k.nodeType===1){if(k.localName==="br")return!0;let R=(b=k.style)==null?void 0:b.display;if(R&&R!=="inline")return!/^(inline|ruby)\b/.test(R)}else if(k.nodeType===3){if(C.whitespace===Ke.PRESERVE){if(/\n$/.test(k.textContent))return!0}else if(C.whitespace===Ke.NEWLINE&&/\n[ \t\r\n\f]*$/.test(k.textContent))return!0}k=k.lastChild}return!1}let m=-1;for(let y=0;y<t.length;y++){let b=t[y];if(!b.after&&b.inline&&!b.display&&b.parent&&b.viewNode.parentNode&&b.viewNode.nodeType===Node.TEXT_NODE&&!ze(b.viewNode,b.whitespace)){let C=function(N){var E,A,L;if(((E=N.viewNode)==null?void 0:E.nodeType)===1)return N.viewNode.localName==="br";if(((A=N.viewNode)==null?void 0:A.nodeType)===3){if(N.whitespace===Ke.PRESERVE){if(/\n$/.test(N.viewNode.textContent))return!0}else if(N.whitespace===Ke.NEWLINE&&/\n[ \t\r\n\f]*$/.test(N.viewNode.textContent))return!0;if(((L=N.viewNode.previousElementSibling)==null?void 0:L.localName)==="br")return ze(N.viewNode,N.whitespace)}return!1},k=function(N){var E,A,L;if(((E=N.viewNode)==null?void 0:E.nodeType)===1)return N.viewNode.localName==="br";if(((A=N.viewNode)==null?void 0:A.nodeType)===3){if(N.whitespace===Ke.PRESERVE){if(/^\n/.test(N.viewNode.textContent))return!0}else if(N.whitespace===Ke.NEWLINE&&/^[ \t\r\n\f]*\n/.test(N.viewNode.textContent))return!0;if(((L=N.viewNode.nextElementSibling)==null?void 0:L.localName)==="br")return ze(N.viewNode,N.whitespace)}return!1};var g=C,w=k;let R=Ba((o=(n=(i=b.lang)!=null?i:b.parent.lang)!=null?n:e?.lang)!=null?o:(s=e?.parent)==null?void 0:s.lang),_=Fa(b.inheritedProps["text-autospace"]),z=La(b.inheritedProps["text-spacing-trim"]),G=Ta(b.inheritedProps["hanging-punctuation"]);if(Ia(G)&&Oa(_,z)||/\b(flex|grid)\b/.test(b.parent.display))continue;m<0&&(m=y);let X=null,Ze=null,Je=y===m,we=y===m&&l,x=y===m&&c,O=!1,S=!1;for(let N=y-1;N>=0;N--){let E=t[N];if(C(E)){x=!0;break}if(!E.display&&E.viewNode.nodeType===Node.TEXT_NODE&&E.viewNode.textContent.length>0){X=E.viewNode;break}if(E.display&&!/^(inline|ruby)\b/.test(E.display)||((r=E.viewNode)==null?void 0:r.nodeType)===1&&(E.viewNode.localName==="br"||Qt[E.viewNode.localName]))break;N===0&&(Je=!0,l&&(we=!0,x=!0))}for(let N=y+1;N<t.length;N++){let E=t[N];if(k(E)){O=!0;break}if(E.viewNode!==b.viewNode&&!E.display&&E.viewNode.nodeType===Node.TEXT_NODE&&E.viewNode.textContent.length>0){Ze=E.viewNode;break}if(E.display&&!/^(inline|ruby)\b/.test(E.display)||((a=E.viewNode)==null?void 0:a.nodeType)===1&&(E.viewNode.localName==="br"||Qt[E.viewNode.localName])){N===t.length-1&&p(E.viewNode)&&(S=!0);break}if(N===t.length-1){O=!0,S=!0;for(let A=E.viewNode.nextSibling;A;A=A.nextSibling)if(!p(A)){S=!1;break}}}if(((h=b.parent)==null?void 0:h.display)==="inline-block"){if(!we){let N=b.parent.viewNode.firstChild;for(;ze(N,b.whitespace);)N=N.nextSibling;b.viewNode===N&&(we=!0)}if(!S){let N=b.parent.viewNode.lastChild;for(;ze(N,b.whitespace);)N=N.previousSibling;b.viewNode===N&&(S=!0)}}if(this.processTextSpacing(b.viewNode,Je,we,x,O,S,X,Ze,_,z,G,R,b.vertical)>0)break}}}processTextSpacing(e,t,i,n,s,o,r,a,h,l,c,p,d){let f=e.textContent,m=e.ownerDocument,g=0,w,y,b;function C(){if(t)return!0;if(!r)return!1;w||(w=m.createRange(),w.selectNode(e));let S=w.getClientRects()[0];if(!S)return!1;y||(y=m.createRange(),y.selectNode(r));let N=y.getClientRects(),E=N[N.length-1];return E?(g||(g=os(E,d)),d?S.top<E.top+E.height-S.width||S.left+S.width<E.left+S.width/10||S.left>E.left+E.width-S.width/10:S.left<E.left+E.width-S.height||S.top>E.top+E.height-S.height/10||S.top+S.height<E.top+S.height/10):!1}function k(){if(!a)return!1;w||(w=m.createRange(),w.selectNode(e));let S=w.getClientRects()[0];if(!S)return!1;g||(g=os(S,d)),b||(b=m.createRange(),b.selectNode(a));let N=b.getClientRects()[0];return N?d?S.top+S.height>N.top+S.width||S.left>N.left+N.width-S.width/10||S.left+S.width<N.left+S.width/10:S.left+S.width>N.left+S.height||S.top+S.height<N.top+S.height/10||S.top>N.top+N.height-S.height/10:!1}let R=!1,_=!1,z=!1,G=!1,X;if(i&&c.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(X="viv-ts-open",R=!0,_=!0):o&&c.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(X="viv-ts-close",R=!0,z=!0):(c.forceEnd||c.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(X="viv-ts-close",R=!0,G=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(X="viv-ts-open",R=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||p==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||p!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(X="viv-ts-close",R=!0),R){let S=function(M){let U=parseFloat(m.defaultView.getComputedStyle(M).fontSize)*.7;return(d?M.offsetHeight:M.offsetWidth)>U},N=function(){return d?E.offsetLeft:E.offsetTop};var Ze=S,Je=N;if(e.parentElement.localName==="viv-ts-inner")return 0;let E=m.createElement(X),A=m.createElement("viv-ts-inner");E.appendChild(A),e.parentNode.insertBefore(E,e),A.appendChild(e);let L=S(A);if(L||_||z||G){if(X==="viv-ts-open"){if(_)E.className="viv-hang-first";else if(i||n)l.trimStart?E.className="viv-ts-trim":E.className="viv-ts-space";else if(!(l.trimStart||l.spaceFirst)&&C())E.className="viv-ts-space";else if(l.trimAdjacent&&r&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(r.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(r.textContent)||r.parentElement.localName==="viv-ts-inner"&&S(r.parentElement)))E.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&C()){let M=N();E.className="viv-ts-auto",M===N()&&!C()&&(E.className="viv-ts-trim")}}else if(X==="viv-ts-close"){if(z)E.className=L?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(o||s){let M=N();G?(E.className=L?c.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",c.allowEnd&&M===N()&&(l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-hang-end",M===N()&&(E.className="")):E.className="viv-ts-space")):l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-ts-auto",M===N()&&(E.className="")):E.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))L&&l.trimAdjacent&&(E.className="viv-ts-trim");else if(G){let M=k(),U=M&&c.allowEnd;U||(E.className=L?"viv-hang-end":"viv-hang-end viv-hang-hw"),L?U&&l.trimEnd?E.className="viv-ts-auto":!U&&!k()?E.className="":!M&&c.allowEnd&&(l.trimEnd?(E.className="viv-ts-auto",k()||(E.className="viv-hang-end")):(E.className="viv-ts-space",k()||(l.allowEnd?(E.className="viv-ts-auto",k()||(E.className="viv-hang-end")):E.className="viv-hang-end"))):!M&&!k()&&(E.className="")}else if(l.trimEnd||l.allowEnd)if(k())l.allowEnd?E.className="viv-ts-space":E.className="viv-ts-auto";else{let M=N();E.className="viv-ts-auto",M===N()&&(E.className="")}}}}let we=!1;function x(S){var N;let E=(N=S?.ownerDocument.defaultView)==null?void 0:N.getComputedStyle(S);return!!E&&(E.textOrientation==="upright"||E.textCombineUpright==="all"||E["-webkit-text-combine"]==="horizontal")}function O(S,N){if(S.nodeType===1){let L=m.defaultView.getComputedStyle(S);if(parseFloat(L.marginInlineEnd)||parseFloat(L.borderInlineEndWidth)||parseFloat(L.paddingInlineEnd))return!0}let E=S.parentElement;if(E&&!E.contains(N))return O(E,N);if(N.nodeType===1){let L=m.defaultView.getComputedStyle(N);if(parseFloat(L.marginInlineStart)||parseFloat(L.borderInlineStartWidth)||parseFloat(L.paddingInlineStart))return!0}let A=N.parentElement;return A&&!A.contains(S)?O(S,A):!1}return(h.ideographAlpha||h.ideographNumeric)&&(r&&/^(?!\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(r.textContent)||h.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(r.textContent))&&!(d&&x(r.parentElement))&&!O(r,e)&&(e.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),e),we=!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))&&!(d&&x(a.parentElement))&&!O(e,a)&&(e.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),e.nextSibling),we=!0)),g}registerHooks(){ft("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),ft("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),ft("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},br=new _g;br.registerHooks();function Mg(e){br.preprocessForTextSpacing(e)}function zg(e,t,i,n,s,o){br.processGeneratedContent(e,t,i,n,s,o)}var Wn=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),Dg=["footnote-marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],vr="data-adapt-pseudo";function bi(e){return e.getAttribute(vr)||""}function Fo(e,t){e.setAttribute(vr,t)}var _a=class{constructor(e,t,i,n,s){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=s,u(this,"contentProcessed",{})}getStyle(e,t){let i=bi(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=bt(this.style,"_pseudos")[i]||{};if(i.match(/^first-/)&&!n["x-first-pseudo"]){let s=1,o;i=="first-letter"?s=0:(o=i.match(/^first-([0-9]+)-lines$/))!=null&&(s=o[1]-0),n["x-first-pseudo"]=new Z(new si(s),0)}return n}processContent(e,t,i){let n=bi(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let s=t.content;s&&jt(s)&&(s.visit(new ss(e,this.context,s,this.exprContentListener)),Mg(e))}}},Cb=ts.isInstanceOfAfterIfContinuesLayoutConstraint,Vg=vs.registerFragmentIndex,Eb=vs.clearFragmentIndices,Ug=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new yr(e,i,t),s=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=s;let o=i.firstChild;return T(o,"display","block"),P(o)})}createNodePositionForPseudoElement(){let e=Wn.createElementNS("http://www.w3.org/1999/xhtml","div");Fo(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 Gt(i)}createShadowContext(e){return new co(this.sourceNode,e,null,null,null,Rt.ShadowType.ROOTED,this.styler)}},Hg=class bu{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,u(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,i,n){return!(i&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,i,n,s){}finishBreak(t,i){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(i,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),P(!0))):P(!0)}getRepetitiveElements(){return new $g(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof bu?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},$g=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 vu(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return P(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let s=Gg(e,t,n);return t.fragmentLayoutConstraints.push(new Hg(e,i,s)),P(e)})}function yu(e,t){return e.thenAsync(i=>vu(i,t))}function Wg(e,t){let i=F("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let s=vu(n,t);return n=n.parent,s.thenReturn(!0)}else return P(!1)}).then(()=>{i.finish(!0)}),i.result()}function Gg(e,t,i){let n=e.viewNode;n.appendChild(i);let s=wo(i,t,e.vertical);return n.removeChild(i),s}var jg=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},Gn=class extends ur{constructor(e,t){super(),this.checkPoints=e,this.penalty=t,u(this,"alreadyEvaluated",!1),u(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]}},ls=class xu extends _h{constructor(t,i,n,s,o){super(t),this.layoutContext=i,this.clientLayout=n,this.layoutConstraint=s,this.pageFloatLayoutContext=o,u(this,"last"),u(this,"viewDocument"),u(this,"flowRootFormattingContext",null),u(this,"isFloat",!1),u(this,"isFootnote",!1),u(this,"startEdge",0),u(this,"endEdge",0),u(this,"beforeEdge",0),u(this,"afterEdge",0),u(this,"footnoteEdge",0),u(this,"box",null),u(this,"chunkPositions",null),u(this,"bands",null),u(this,"overflown",!1),u(this,"breakPositions",null),u(this,"pageBreakType",null),u(this,"forceNonfitting",!0),u(this,"leftFloatEdge",0),u(this,"rightFloatEdge",0),u(this,"bottommostFloatTop",0),u(this,"stopAtOverflow",!0),u(this,"lastAfterPosition",null),u(this,"fragmentLayoutConstraints",[]),u(this,"pseudoParent",null),u(this,"nodeContextOverflowingDueToRepetitiveElements",null),u(this,"blockDistanceToBlockEndFloats",NaN),u(this,"breakAtTheEdgeBeforeFloat",null),new.target===xu&&Cf(this),this.last=t.lastChild,this.viewDocument=t.ownerDocument,o.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=F("openAllViews"),n=t.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let s=n.length-1,o=null;return i.loop(()=>{for(;s>=0;){let r=o,a=n[s];if(o=ns(a,r),s===n.length-1&&!o.formattingContext&&(o.formattingContext=this.flowRootFormattingContext),s==0&&(o.offsetInNode=this.calculateOffsetInNodeForNodeContext(t),o.after=t.after,o.preprocessedTextContent=t.preprocessedTextContent,o.after))break;let h=this.layoutContext.setCurrent(o,s==0&&o.offsetInNode==0);if(s--,h.isPending())return h}return P(!1)}).then(()=>{i.finish(o)}),i.result()}calculateOffsetInNodeForNodeContext(t){return t.preprocessedTextContent?Kp(t.preprocessedTextContent,t.offsetInNode):t.offsetInNode}maybePeelOff(t,i){var n,s;if(t.firstPseudo&&t.inline&&!t.after&&t.firstPseudo.count==0&&t.viewNode.nodeType!=1){let o=t.viewNode.textContent,r=o.match(Zn),a=r?r[0].length:0;if(!r&&((n=t.sourceNode)==null?void 0:n.nodeType)===3&&((s=t.sourceNode.nextSibling)==null?void 0:s.nodeType)===3&&o===t.sourceNode.textContent){let h=o+t.sourceNode.nextSibling.textContent,l=h.match(Zn);if(l){let c=l[0];a=c.length,t.sourceNode.textContent=c,t.viewNode.textContent=c,t.sourceNode.nextSibling.textContent=h.substr(a)}}return this.layoutContext.peelOff(t,a)}return P(t)}buildViewToNextBlockEdge(t,i){let n=!1,s=F("buildViewToNextBlockEdge");return s.loopWithFrame(o=>{var r;if(t.viewNode&&!mi(t)&&((r=t.viewNode.parentElement)==null?void 0:r.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,h=this.clientLayout.getElementClientRect(a);if(os(h,this.vertical)>=2){o.breakLoop();return}}this.maybePeelOff(t,0).then(a=>{let h=a;h!==t&&(t=h,mi(t)||i.push(t.copy())),this.nextInTree(t).then(l=>{if(t=l,!t){o.breakLoop();return}(n||!this.layoutConstraint.allowLayout(t))&&(n=!0,t=t.modify(),t.overflow=!0),this.isFloatNodeContext(t)&&(xi(t.floatReference)||t.floatSide==="footnote")?this.layoutFloatOrFootnote(t).then(c=>{if(t=c,this.pageFloatLayoutContext.isInvalidated()&&(t=null),!t){o.breakLoop();return}o.continueLoop()}):t.inline?o.continueLoop():o.breakLoop()})})}).then(()=>{s.finish(t)}),s.result()}nextInTree(t,i){let n=this.layoutContext.nextInTree(t,i);return yu(n,this)}buildDeepElementView(t){if(!t.viewNode)return P(t);let i=[],n=t.sourceNode,s=F("buildDeepElementView");return s.loopWithFrame(o=>{t.viewNode&&t.inline&&!mi(t)?i.push(t.copy()):(i.length>0&&this.postLayoutBlock(t,i),i=[]),this.maybePeelOff(t,0).then(r=>{let a=r;if(a!==t){let h=a;for(;h&&h.sourceNode!=n;)h=h.parent;if(h==null){t=a,o.breakLoop();return}mi(a)||i.push(a.copy())}this.nextInTree(a).then(h=>{t=h,!t||t.sourceNode==n?o.breakLoop():this.layoutConstraint.allowLayout(t)?o.continueLoop():(t=t.modify(),t.overflow=!0,this.stopAtOverflow?o.breakLoop():o.continueLoop())})})}).then(()=>{i.length>0&&this.postLayoutBlock(t,i),s.finish(t)}),s.result()}createFloat(t,i,n,s){let o=this.viewDocument.createElement("div");return this.vertical?(s>=this.height&&(s-=.1),s<1&&(s=0),T(o,"height",`${n}px`),T(o,"width",`${s}px`)):(n>=this.width&&(n-=.1),n<1&&(n=0),T(o,"width",`${n}px`),T(o,"height",`${s}px`)),T(o,"float",i),T(o,"clear",i),this.element.insertBefore(o,t),o}killFloats(){let t=this.element.firstChild;for(;t;){let i=t.nextSibling;if(t.nodeType==1){let n=t,s=n.style.cssFloat;if(s=="left"||s=="right"||s==="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(),s=this.vertical?this.getBottomEdge():this.getRightEdge(),o=null;for(let r of i){let a=r.y2-r.y1;r.left=this.createFloat(t,"left",r.x1-n,a),r.right=this.createFloat(t,"right",s-r.x2,a),r.x1<s&&r.x2>n?o=r:o||T(r.right,"float","none")}if(o){let r=i[i.length-1],a=this.vertical?-this.getLeftEdge():this.getBottomEdge();o!==r&&r.y2>=a&&(this.footnoteEdge=this.vertical?-o.y2:o.y2)}}calculateEdge(t,i,n,s){let o;if(t&&gi(t.viewNode))return NaN;if(t&&t.after&&!t.inline&&(o=pi(t,this.clientLayout,0,this.vertical),!isNaN(o)))return o;t=i[n];let r=s-t.boxOffset;for(;;){if(o=pi(t,this.clientLayout,r,this.vertical),!isNaN(o))return o;if(r>0){r--;continue}if(n--,n<0)return this.beforeEdge;t=i[n],t.viewNode.nodeType!=1&&(r=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 Bs(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 Bs(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 Bs(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=F("layoutFloat"),n=t.viewNode,s=ga(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(o=>{let r=wt(this.clientLayout,n,this.vertical),a=this.getComputedMargin(n),h=new at(r.left-a.left,r.top-a.top,r.right+a.right,r.bottom+a.bottom),l=this.rtl?this.endEdge:this.startEdge,c=this.rtl?this.startEdge:this.endEdge,p=t.parent;for(;p&&p.inline;)p=p.parent;if(p){let k=p.viewNode.ownerDocument.createElement("div");k.style.left="0px",k.style.top="0px",this.vertical?(k.style.bottom="0px",k.style.width="1px"):(k.style.right="0px",k.style.height="1px"),p.viewNode.appendChild(k);let R=wt(this.clientLayout,k,this.vertical);l=Math.max(this.rtl?this.getEndEdge(R):this.getStartEdge(R),l),c=Math.min(this.rtl?this.getStartEdge(R):this.getEndEdge(R),c),p.viewNode.removeChild(k);let _=this.vertical?h.y2-h.y1:h.x2-h.x1;s=="left"?c=Math.max(c,l+_):l=Math.min(l,c-_),p!==t.parent&&!t.firstPseudo&&(p.viewNode.appendChild(n),n.setAttribute("data-vivliostyle-float-box-moved","true"))}let d=new at(l,this.getBoxDir()*this.beforeEdge,c,this.getBoxDir()*this.afterEdge),f=h;this.vertical&&(f=Jn(h));let m=this.getBoxDir();if(f.y1<this.bottommostFloatTop*m){let k=f.y2-f.y1;f.y1=this.bottommostFloatTop*m,f.y2=f.y1+k}zd(d,this.bands,f,s),this.vertical&&(h=Jl(f));let g=this.getComputedInsets(n);T(n,"width",`${h.x2-h.x1-g.left-g.right}px`),T(n,"height",`${h.y2-h.y1-g.top-g.bottom}px`),T(n,"position","absolute"),t.display,T(n,"display",t.display);let w,y=null;if(p&&(p.containingBlockForAbsolute?y=p:y=p.getContainingBlockForAbsolute()),y){let k=y.viewNode.ownerDocument.createElement("div");k.style.position="absolute",y.vertical?k.style.right="0":k.style.left="0",k.style.top="0",y.viewNode.appendChild(k),w=wt(this.clientLayout,k,this.vertical),y.viewNode.removeChild(k)}else w={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};(y?y.vertical:this.vertical)?T(n,"right",`${w.right-h.x2}px`):T(n,"left",`${h.x1-w.left}px`),T(n,"top",`${h.y1-w.top}px`),t.clearSpacer&&(t.clearSpacer.parentNode.removeChild(t.clearSpacer),t.clearSpacer=null);let b=this.vertical?h.x1:h.y2,C=this.vertical?h.x2:h.y1;!this.isOverflown(b)||this.breakPositions.length==0?(this.killFloats(),d=new at(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(d=Jn(d)),Dd(d,this.bands,f,null,s),this.createFloats(),s=="left"?this.leftFloatEdge=b:this.rightFloatEdge=b,this.bottommostFloatTop=C,this.updateMaxReachedAfterEdge(b),i.finish(o)):(t=t.modify(),t.overflow=!0,i.finish(t))}),i.result()}setupFloatArea(t,i,n,s,o,r){let a=this.pageFloatLayoutContext,h=a.getContainer(i),l=t.element;h.element.parentNode.appendChild(l),t.isFloat=!0,t.originX=h.originX,t.originY=h.originY,t.vertical=h.vertical,t.rtl=h.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=(h.exclusions||[]).concat(),t.forceNonfitting=!a.hasFloatFragments(),t.innerShape=null;let c=h.getPaddingRect();t.setHorizontalPosition(c.x1-h.originX,c.x2-c.x1),t.setVerticalPosition(c.y1-h.originY,c.y2-c.y1),o.adjustPageFloatArea(t,h,this),t.init();let p=!!a.setFloatAreaDimensions(t,i,n,s,!0,!a.hasFloatFragments(),r);return p?(t.killFloats(),t.init()):h.element.parentNode.removeChild(l),p}createPageFloatArea(t,i,n,s,o){let r=this.element.ownerDocument.createElement("div");T(r,"position","absolute");let a=this.pageFloatLayoutContext.getPageFloatLayoutContext(t.floatReference),h=new Gi(null,Ce.COLUMN,null,this.pageFloatLayoutContext.flowName,t.nodePosition,null,null),l=a.getContainer(),c=new Yg(i,r,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,h,l);return h.setContainer(c),this.setupFloatArea(c,t.floatReference,i,n,s,o)?c:null}layoutSinglePageFloatFragment(t,i,n,s,o,r,a){let h=this.pageFloatLayoutContext;t=(a?a.continuations:[]).concat(t);let l=t[0].float,c=h.getPageFloatPlacementCondition(l,i,n),p=this.createPageFloatArea(l,i,r,o,c),d={floatArea:p,pageFloatFragment:null,newPosition:null};if(!p)return P(d);let f=F("layoutSinglePageFloatFragment"),m=!1,g=0;return f.loopWithFrame(w=>{if(g>=t.length){w.breakLoop();return}let y=t[g],b=new Gt(y.nodePosition);p.layout(b,!0).then(C=>{d.newPosition=C,!C||s?(g++,w.continueLoop()):(m=!0,w.breakLoop())})}).then(()=>{if(!m){let w=h.setFloatAreaDimensions(p,l.floatReference,i,r,!1,s,c);if(!w)m=!0;else{let y=o.createPageFloatFragment(t,w,n,p,!!d.newPosition);h.addPageFloatFragment(y,!0),d.pageFloatFragment=y}}f.finish(d)}),f.result()}layoutPageFloatInner(t,i,n,s){let o=this.pageFloatLayoutContext,r=t.float;o.stashEndFloatFragments(r);function a(l,c){c?o.removePageFloatFragment(c,!0):l&&l.element.parentNode.removeChild(l.element),o.restoreStashedFragments(r.floatReference),o.deferPageFloat(t)}let h=F("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([t],r.floatSide,r.clearSide,!o.hasFloatFragments(),i,n,s).then(l=>{let c=l.floatArea,p=l.pageFloatFragment,d=l.newPosition;p?this.layoutStashedPageFloats(r.floatReference,[s]).then(f=>{if(f){if(o.addPageFloatFragment(p),o.discardStashedFragments(r.floatReference),d){let m=new ma(r,d.primary);o.deferPageFloat(m)}h.finish(!0)}else a(c,p),h.finish(!1)}):(a(c,p),h.finish(!1))}),h.result()}layoutStashedPageFloats(t,i){let n=this.pageFloatLayoutContext,s=n.getStashedFloatFragments(t),o=[],r=[],a=!1,h=F("layoutStashedPageFloats"),l=0;return h.loopWithFrame(c=>{if(l>=s.length){c.breakLoop();return}let p=s[l];if(i.includes(p)){l++,c.continueLoop();return}let d=new Ti().findByFloat(p.continuations[0].float);this.layoutSinglePageFloatFragment(p.continuations,p.floatSide,p.clearSide,!1,d,null).then(f=>{let m=f.floatArea;m&&o.push(m);let g=f.pageFloatFragment;g?(r.push(g),l++,c.continueLoop()):(a=!0,c.breakLoop())})}).then(()=>{a?(r.forEach(c=>{n.removePageFloatFragment(c,!0)}),o.forEach(c=>{let p=c.element;p&&p.parentNode&&p.parentNode.removeChild(p)})):s.forEach(c=>{let p=c.area.element;p&&p.parentNode&&p.parentNode.removeChild(p)}),h.finish(!a)}),h.result()}setFloatAnchorViewNode(t){let i=t.viewNode.parentNode,n=i.ownerDocument.createElement("span");n.setAttribute(Ii,"1"),t.floatSide==="footnote"&&this.layoutContext.applyPseudoelementStyle(t,"footnote-call",n),i.appendChild(n),i.removeChild(t.viewNode);let s=t.modify();return s.after=!0,s.viewNode=n,s}resolveFloatReferenceFromColumnSpan(t,i,n){let s=F("resolveFloatReferenceFromColumnSpan"),o=this.pageFloatLayoutContext,r=o.getPageFloatLayoutContext(Ce.REGION);return o.getContainer().width<r.getContainer().width&&t===Ce.COLUMN?i===v.auto?this.buildDeepElementView(n.copy()).then(a=>{let h=a.viewNode,l=sr(this.clientLayout,h,["min-content inline size"])["min-content inline size"],c=this.getComputedMargin(h);this.vertical?l+=c.top+c.bottom:l+=c.left+c.right,l>this.width?s.finish(Ce.REGION):s.finish(t)}):i===v.all?s.finish(Ce.REGION):s.finish(t):s.finish(t),s.result()}layoutPageFloat(t){let i=this.pageFloatLayoutContext,n=new Ti().findByNodeContext(t),s,o=i.findPageFloatByNodePosition(t.toNodePosition());return o?s=P(o):s=n.createPageFloat(t,i,this),s.thenAsync(r=>{let a=is(t,0),h=this.setFloatAnchorViewNode(t),l=n.findPageFloatFragment(r,i),c=new ma(r,a);if(l&&l.hasFloat(r))return i.registerPageFloatAnchor(r,h.viewNode),P(h);if(i.isForbidden(r)||i.hasPrecedingFloatsDeferredToNext(r))return i.deferPageFloat(c),i.registerPageFloatAnchor(r,h.viewNode),P(h);if(this.nodeContextOverflowingDueToRepetitiveElements)return P(null);{let p=pi(h,this.clientLayout,0,this.vertical);return this.isOverflown(p)?P(h):this.layoutPageFloatInner(c,n,p,l).thenAsync(d=>d?P(null):(i.registerPageFloatAnchor(r,h.viewNode),P(h)))}})}processLineStyling(t,i,n){let s=F("processLineStyling"),o=n.concat([]);n.splice(0,n.length);let r=0,a=t.firstPseudo;return a.count==0&&(a=a.outer),s.loopWithFrame(h=>{if(!a){h.breakLoop();return}let l=this.findLinePositions(o),c=a.count-r;if(l.length<=c){h.breakLoop();return}let p=this.findAcceptableBreakInside(o,l[c-1],!0);if(p==null){h.breakLoop();return}this.finishBreak(p,!1,!1).then(()=>{r+=c,this.layoutContext.peelOff(p,0).then(d=>{t=d,a=t.firstPseudo,o=[],this.buildViewToNextBlockEdge(t,o).then(f=>{i=f,h.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(n,o),s.finish(i)}),s.result()}isLoneImage(t){return t.length!=2&&this.breakPositions.length>0?!1:t[0].sourceNode==t[1].sourceNode&&Qt[t[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(t){let i=0,n=0;for(let s=t.length-1;s>=0;s--){let o=t[s];if(!o.after||!o.viewNode||o.viewNode.nodeType!=1)break;let r=this.getComputedMargin(o.viewNode),a=this.vertical?-r.left:r.bottom;a>0?i=Math.max(i,a):n=Math.min(n,a)}return i+n}layoutBreakableBlock(t){let i=F("layoutBreakableBlock"),n=[];return this.buildViewToNextBlockEdge(t,n).then(s=>{let o=n.length-1;if(o<0){i.finish(s);return}this.postLayoutBlock(s,n);let r=this.calculateEdge(s,n,o,n[o].boxOffset),a=!1;if(!s||!gi(s.viewNode)){let l=Si(s,this.collectElementsOffset());a=this.isOverflown(r+(this.vertical?-1:1)*l.minimum),this.isOverflown(r+(this.vertical?-1:1)*l.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=s)}s==null&&(r+=this.getTrailingMarginEdgeAdjustment(n)),this.updateMaxReachedAfterEdge(r);let h;t.firstPseudo?h=this.processLineStyling(t,s,n):h=P(s),h.then(l=>{n.length>0&&(this.saveBoxBreakPosition(n),a&&!this.isLoneImage(n)&&l&&(l=l.modify(),l.overflow=!0)),i.finish(l)})}),i.result()}postLayoutBlock(t,i){vt("POST_LAYOUT_BLOCK").forEach(n=>{n(t,i,this)})}findEndOfLine(t,i,n){let s=this.vertical?t-1:t+1,o=0,r=i[0].boxOffset,a=o,h=i.length-1,l=i[h].boxOffset,c;for(;r<l;){c=r+Math.ceil((l-r)/2),a=o;let p=h;for(;a<p;){let f=a+Math.ceil((p-a)/2);i[f].boxOffset>c?p=f-1:a=f}let d=this.calculateEdge(null,i,a,c);if(this.vertical?d<=s:d>=s){for(l=c-1;i[a].boxOffset==c;)a--;h=a}else n&&this.updateMaxReachedAfterEdge(d),r=c,o=a}return{nodeContext:i[a],index:r,checkPointIndex:a}}findAcceptableBreakInside(t,i,n){var s,o,r;let a=this.findEndOfLine(i,t,!0),h=a.nodeContext;if(a.checkPointIndex===0&&a.index===h.boxOffset)return null;let l=h.viewNode;if(l.nodeType!=1&&((s=l.parentElement)==null?void 0:s.localName)!=="viv-ts-inner"){let c=l;h=this.resolveTextNodeBreaker(h).breakTextNode(c,h,a.index,t,a.checkPointIndex,n)}else{let c=va(h);if(c){if(((o=this.breakPositions)==null?void 0:o[0])instanceof Gn&&c!=null&&c.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(h=c;!h.after&&h.inline&&h.parent;){let p=(r=h.viewNode)==null?void 0:r.previousSibling;for(;p&&(ze(p,h.parent.whitespace)||ji(p));)p=p.previousSibling;if(p)break;h=h.parent}}}return this.clearOverflownViewNodes(h,!1),h}resolveTextNodeBreaker(t){return vt("RESOLVE_TEXT_NODE_BREAKER").reduce((i,n)=>n(t)||i,hs.instance)}getRangeBoxes(t,i){let n=[],s=t.ownerDocument.createRange(),o=!1,r=t,a=null,h=!1,l=!0;for(;l;){let c=!0;do{let p=null;r==i&&(i.nodeType===1?l=!(!i.firstChild||o):l=!1);let d=r.nodeType===1?r:null;d?o?o=!1:hr(d)?c=!h:!d.firstChild||Qt[d.localName]||/^r(uby|[bt]c?)$/.test(d.localName)||Nf(this.clientLayout.getElementComputedStyle(d).display)?(c=!h,c?(d.localName==="ruby"&&r.firstChild&&(r=r.firstChild),s.setStartBefore(r),h=!0,a=r):/^r(uby|tc?)$/.test(d.localName)||(a=r),r.contains(i)&&(l=!1)):p=r.firstChild:(h||(r.parentNode==null?l=!1:(s.setStartBefore(r),h=!0)),a=r),p||(p=r.nextSibling,p||(o=!0,p=r.parentNode)),r=p}while(c&&l);if(h){s.setEndAfter(a);let p=this.clientLayout.getRangeClientRects(s);Gh(p,this.vertical);for(let d=0;d<p.length;d++)n.push(p[d]);h=!1}}return n}findLinePositions(t){let i=[],n=this.getRangeBoxes(t[0].viewNode,t[t.length-1].viewNode);n.sort(this.vertical?rf:of);let s=0,o=0,r=0,a=0,h=0,l=this.getBoxDir();for(;;){if(h<n.length){let c=n[h],p=1;if(a>0){let d=Math.max(this.getBoxSize(c),1);l*this.getBeforeEdge(c)<l*s?p=l*(this.getAfterEdge(c)-s)/d:l*this.getAfterEdge(c)>l*o?p=l*(o-this.getBeforeEdge(c))/d:p=1}if(a==0||p>=.6||p>=.2&&this.getStartEdge(c)>=r-1){r=this.getEndEdge(c),this.vertical?(s=a==0?c.right:Math.max(s,c.right),o=a==0?c.left:Math.min(o,c.left)):(s=a==0?c.top:Math.min(s,c.top),o=a==0?c.bottom:Math.max(o,c.bottom)),a++,h++;continue}}if(a>0&&(i.push(o),a=0),h>=n.length)break}return i.sort(El),this.vertical&&i.reverse(),i}calculateClonedPaddingBorder(t){let i=0;for(let n=t;n;n=n.parent)if(!n.inline&&Hi(n.viewNode)){let s=this.getComputedPaddingBorder(n.viewNode);i+=n.vertical?-s.left:s.bottom,n.display==="table"&&(i+=(n.vertical?-1:1)*n.blockBorderSpacing)}return i}getOffsetByRepetitiveElements(t){let i;return t?i=t.calculateOffset(this):i=Si(null,this.collectElementsOffset()),i.current}findBoxBreakPosition(t,i){let n=this.element.parentNode,s=this.element.nextSibling;n.removeChild(this.element),n.insertBefore(this.element,s);let o=t.checkPoints,r=o[0];for(;r.parent&&r.inline;)r=r.parent;let a,h;i?(a=1,h=1):(a=Math.max((r.inheritedProps.widows||2)-0,1),h=Math.max((r.inheritedProps.orphans||2)-0,1));let l=this.calculateClonedPaddingBorder(r),c=this.findLinePositions(o),p=this.footnoteEdge-l,d=this.getBoxDir(),f=this.getOffsetByRepetitiveElements(t);p-=d*f;let m=this.findFirstOverflowingEdgeAndCheckPoint(o);isNaN(m.edge)&&(m.edge=d*(1/0));let g=Ht(c.length,C=>{let k=c[C];return this.vertical?k<p||k<=m.edge:k>p||k>=m.edge}),w=g<=0;w&&(g=Ht(c.length,C=>this.vertical?c[C]<p:c[C]>p));let y=o[o.length-1].viewNode;if(y?.parentElement.localName==="viv-ts-inner"&&(y=y.parentElement.parentElement),(g===c.length&&y.nextSibling||g>=c.length-1&&y.parentElement.querySelector(".MJXc-display"))&&(a=0),g=Math.min(c.length-a,g),g<h)return null;p=c[g-1];let b;if(w?b=m.checkPoint:b=this.findAcceptableBreakInside(t.checkPoints,p,i),b){let C=this.getAfterEdgeOfBlockContainer(b);!isNaN(C)&&d*(p-C)>0&&(p=C),this.computedBlockSize=d*(p-this.beforeEdge)+f}return b}getAfterEdgeOfBlockContainer(t){let i=t;do i=i.parent;while(i&&i.inline);return i?(i=i.copy().modify(),i.after=!0,pi(i,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(t){let i=t.findIndex(s=>s.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 s=new Di().find(t.formattingContext).finishBreak(this,t,i,n);return s||(s=dr.finishBreak(this,t,i,n)),s}findAcceptableBreakPosition(){let t=null,i=null,n=0,s=0;do{n=s,s=Number.MAX_VALUE;for(let o=this.breakPositions.length-1;o>=0&&!i;--o){t=this.breakPositions[o],i=t.findAcceptableBreak(this,n);let r=t.getMinBreakPenalty();r>n&&(s=Math.min(s,r))}}while(s>n&&!i&&this.forceNonfitting);return{breakPosition:i?t:null,nodeContext:i}}doFinishBreak(t,i,n,s){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!i)return P(t);let o=F("doFinishBreak"),r=!1;if(!t){if(this.forceNonfitting)return H.warn("Could not find any page breaks?!!"),this.skipTailEdges(i).then(a=>{a?(a=a.modify(),a.overflow=!1,this.finishBreak(a,r,!0).then(()=>{o.finish(a)})):o.finish(a)}),o.result();t=n,r=!0,this.computedBlockSize=s}return this.finishBreak(t,r,!0).then(()=>{o.finish(t)}),o.result()}isBreakable(t){for(let i=t;i;i=i.parent)if(ji(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 r=t;r;r=r.parent)if(ji(r.viewNode))return!1;if(gi(t.viewNode))return!1;let n=pi(t,this.clientLayout,0,this.vertical),s=Si(t,this.collectElementsOffset()),o=this.isOverflown(n+(this.vertical?-1:1)*s.minimum);if(this.isOverflown(n+(this.vertical?-1:1)*s.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=t;else if(i){let r=n+this.getTrailingMarginEdgeAdjustment(i),a=this.footnoteEdge-this.getBoxDir()*s.current;n=this.vertical?Math.min(n,Math.max(r,a)):Math.max(n,Math.min(r,a))}return this.updateMaxReachedAfterEdge(n),o}checkOverflowAndSaveEdgeAndBreakPosition(t,i,n,s){if(!t||gi(t.viewNode))return!1;let o=this.checkOverflowAndSaveEdge(t,i);return(n||!o)&&this.saveEdgeBreakPosition(t,s,o),o}applyClearance(t){if(!t.viewNode.parentNode||t.floatReference!==Ce.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 s=wt(this.clientLayout,n,this.vertical),o=this.getBeforeEdge(s),r=this.getBoxDir(),a=t.clearSide==="same"?t.floatSide:t.clearSide,h=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(a)?ga(a,t.vertical,t.direction,this.layoutContext.page.side):a,l=h==="left"||h==="right"?t.direction==="rtl"==(h==="left")?"inline-end":"inline-start":h,c=this.pageFloatLayoutContext.getPageFloatClearEdge(l,this);switch(h){case"left":c=r*Math.max(c*r,this.leftFloatEdge*r);break;case"right":c=r*Math.max(c*r,this.rightFloatEdge*r);break;default:c=r*Math.max(c*r,Math.max(this.rightFloatEdge*r,this.leftFloatEdge*r))}if(o*r>=c*r)return t.viewNode.parentNode.removeChild(n),!1;{let p=Math.max(1,(c-o)*r);this.vertical?n.style.width=`${p}px`:n.style.height=`${p}px`,s=wt(this.clientLayout,n,this.vertical);let d=this.getAfterEdge(s);if(!t.floatSide)if(this.vertical){let f=d-i.right-c;f>0==i.right>=0&&(f+=i.right),n.style.marginLeft=`${f}px`}else{let f=c-(d+i.top);f>0==i.top>=0&&(f+=i.top),n.style.marginBottom=`${f}px`}return t.clearSpacer=n,!0}}isBFC(t){return!!(Tf(t)||ei.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))}skipEdges(t,i,n){var s;let o=t.after?(s=t.parent)==null?void 0:s.formattingContext:t.formattingContext;if(o&&!this.isBFC(o))return P(t);let r=F("skipEdges"),a=!n&&i&&t&&t.after,h=n,l=null,c=[],p=[],d=!1;function f(){return!!n||!i&&je(h)&&!m()}function m(){var w;if(!l||t.floatSide)return!1;for(let y=l;y!=null&&y.parent;y=y.parent){let b=y.after?y.viewNode:(w=y.viewNode)==null?void 0:w.previousSibling;for(;b&&(ze(b,y.parent.whitespace)||ji(b));)b=b.previousSibling;if(b)return!1}return!0}let g=()=>{t=c[0]||t,t.viewNode.parentNode.removeChild(t.viewNode),this.pageBreakType=h};return r.loopWithFrame(w=>{for(var y;t;){t.formattingContext;let b=new Di().find(t.formattingContext);do{if(!t.viewNode)break;if(t.inline&&t.viewNode.nodeType!=1){if(ze(t.viewNode,t.whitespace))break;if(!t.after){f()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)?(t=(this.stopAtOverflow&&l||t).modify(),t.overflow=!0):(t=t.modify(),t.breakBefore=h),w.breakLoop();return}}if(!t.after){if(t.floatSide&&(this.breakAtTheEdgeBeforeFloat=es(h)?h:null),b&&b.startNonInlineElementNode(t))break;if(t.clearSide&&this.applyClearance(t)&&i&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(t.copy(),h,!1),!t.inline&&!t.repeatOnBreak&&(l?va(l):this.breakPositions[this.breakPositions.length-1]instanceof Gn)&&this.saveEdgeBreakPosition(t.copy(),h,!1),!this.isBFC(t.formattingContext)||ei.isInstanceOfRepetitiveElementsOwnerFormattingContext(t.formattingContext)||this.isFloatNodeContext(t)||t.flexContainer||!t.nodeShadow&&!t.sourceNode.firstElementChild&&ze(t.sourceNode.firstChild,t.whitespace)){c.push(t.copy()),h=Xe(h,t.breakBefore),f()?g():(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)||!this.layoutConstraint.allowLayout(t))&&(t=(this.stopAtOverflow&&l||t).modify(),t.overflow=!0),w.breakLoop();return}}if(t.viewNode.nodeType!=1)break;let k=t.viewNode,R=k.style;if(t.after){R.columnFill==="balance"&&k.getAttribute("data-vivliostyle-column-fill")==="auto"&&(R.columnFill="auto"),t.floatSide&&(h=h??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let _=t.sourceNode;if(_.localName==="svg"||_.localName==="math"||_.getAttribute("data-math-typeset")==="true"){d=!1,l=t.copy(),p.push(l),h=Xe(null,t.breakAfter),this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h);break}if(t.inline||b&&b.afterNonInlineElementNode(t,this.stopAtOverflow))break;if(d){if(f()){g(),w.breakLoop();return}c=[],i=!1,a=!1,h=null}d=!1,l=t.copy(),p.push(l),h=Xe(h,t.breakAfter),R&&!(this.zeroIndent(R.paddingBottom)&&this.zeroIndent(R.borderBottomWidth))&&(p=[l])}else{if(c.push(t.copy()),h=Xe(h,t.breakBefore),l&&je(h)&&kf(l.viewNode,t.viewNode),(t.pageType!=((y=t.parent)==null?void 0:y.pageType)||!je(h))&&!this.layoutConstraint.allowLayout(t)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h),t=t.modify(),t.overflow=!0,this.stopAtOverflow)){w.breakLoop();return}let _=t.viewNode.localName;if(Qt[_]){f()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)&&(t=(this.stopAtOverflow&&l||t).modify(),t.overflow=!0),w.breakLoop();return}R&&!(this.zeroIndent(R.paddingTop)&&this.zeroIndent(R.borderTopWidth))&&(a=!1,p=[]),d=!0}}while(!1);let C=this.nextInTree(t,a);if(C.isPending()){C.then(k=>{t=k,w.continueLoop()});return}else t=C.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(l,p,!this.stopAtOverflow,h)?l&&this.stopAtOverflow&&(t=l.modify(),t.overflow=!0):je(h)&&(this.pageBreakType=h),w.breakLoop()}).then(()=>{l&&(this.lastAfterPosition=l.toNodePosition()),r.finish(t)}),r.result()}skipTailEdges(t){let i=t.copy(),n=F("skipEdges"),s=null,o=!1;return n.loopWithFrame(r=>{for(;t;){do{if(!t.viewNode)break;if(t.inline&&t.viewNode.nodeType!=1){if(ze(t.viewNode,t.whitespace))break;if(!t.after){je(s)&&(this.pageBreakType=s),r.breakLoop();return}}if(!t.after&&(this.isFloatNodeContext(t)||t.flexContainer)){s=Xe(s,t.breakBefore),je(s)&&(this.pageBreakType=s),r.breakLoop();return}if(t.viewNode.nodeType!=1)break;let h=t.viewNode.style;if(t.after){if(o){if(je(s)){this.pageBreakType=s,r.breakLoop();return}s=null}o=!1,s=Xe(s,t.breakAfter)}else{s=Xe(s,t.breakBefore);let l=t.viewNode.localName;if(Qt[l]){je(s)&&(this.pageBreakType=s),r.breakLoop();return}if(h&&!(this.zeroIndent(h.paddingTop)&&this.zeroIndent(h.borderTopWidth))){r.breakLoop();return}}o=!0}while(!1);let a=this.layoutContext.nextInTree(t);if(a.isPending()){a.then(h=>{t=h,r.continueLoop()});return}else t=a.get()}i=null,r.breakLoop()}).then(()=>{n.finish(i)}),n.result()}layoutFloatOrFootnote(t){return xi(t.floatReference)||t.floatSide==="footnote"?this.layoutPageFloat(t):this.layoutFloat(t)}layoutNext(t,i,n){let s=F("layoutNext");return this.skipEdges(t,i,n||null).then(o=>{if(t=o,!t||this.pageBreakType||this.stopByOverflow(t))s.finish(t);else{let r=t.formattingContext;new Di().find(r).layout(t,this,i).thenFinish(s)}}),s.result()}clearOverflownViewNodes(t,i){if(t)for(let n=t.parent;t;t=n,n=n?n.parent:null){let s=(n||t).formattingContext;new Di().find(s).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(),s=this.originY+this.top+this.getInsetTop();this.box=new at(n,s,n+this.width,s+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=Bd(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 s=t.copy(),o=new Di().find(t.formattingContext),r=this.calculateClonedPaddingBorder(s),a=o.createEdgeBreakPosition(s,i,n,this.computedBlockSize+r);this.breakPositions.push(a)}saveBoxBreakPosition(t){let i=t[0].breakPenalty;if(i){let s=t[0];for(;s.parent&&s.inline;)s=s.parent;i=s.breakPenalty}let n=new Gn(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 P(t);if(this.isFullWithPageFloats())return t.primary.after&&t.primary.steps.length===1?P(null):P(t);Ef(this)&&ar(this);let s=F("layout");return this.openAllViews(t.primary).then(o=>{let r=null;if(o.viewNode)r=o.copy();else{let h=l=>{l.nodeContext.viewNode&&(r=l.nodeContext,this.layoutContext.removeEventListener("nextInTree",h))};this.layoutContext.addEventListener("nextInTree",h)}let a=new Xg(i,n);a.layout(o,this).then(h=>{this.doFinishBreak(h,a.context.overflownNodeContext,r,a.initialComputedBlockSize).then(l=>{let c=null;this.pseudoParent?c=P(null):c=this.doFinishBreakOfFragmentLayoutConstraints(l),c.then(()=>{if(this.pageFloatLayoutContext.isInvalidated()){s.finish(null);return}if(!l)s.finish(null);else{this.overflown=!0;let p=new Gt(l.toNodePosition());s.finish(p)}})})})}),s.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(t){let i=F("doFinishBreakOfFragmentLayoutConstraints"),n=[].concat(this.fragmentLayoutConstraints);n.sort((o,r)=>o.getPriorityOfFinishBreak()-r.getPriorityOfFinishBreak());let s=0;return i.loop(()=>s<n.length?n[s++].finishBreak(t,this).thenReturn(!0):P(!1)).then(()=>{i.finish(!0)}),i.result()}doLayout(t,i,n){let s=F("doLayout"),o=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,s.loopWithFrame(r=>{for(;t;){let a=!0;if(this.layoutNext(t,i,n||null).then(h=>{if(i=!1,n=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,t=this.nodeContextOverflowingDueToRepetitiveElements,t.overflow=!0):t=h,this.pageFloatLayoutContext.isInvalidated())r.breakLoop();else if(this.pageBreakType)r.breakLoop();else if(t&&this.stopByOverflow(t)){o=t;let l=this.findAcceptableBreakPosition();t=l.nodeContext,l.breakPosition&&l.breakPosition.breakPositionChosen(this),r.breakLoop()}else a?a=!1:r.continueLoop()}),a){a=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),r.breakLoop()}).then(()=>{s.finish({nodeContext:t,overflownNodeContext:o})}),s.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=F("redoLayout"),s=0,o=null,r=!0;return n.loopWithFrame(a=>{if(s<t.length){let h=t[s++];this.layout(h,r).then(l=>{r=!1,l?(o=l,a.breakLoop()):a.continueLoop()});return}a.breakLoop()}).then(()=>{n.finish(o)}),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(ei.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(n)){let s=n.getRepetitiveElements();t.push(s)}if(ts.isInstanceOfAfterIfContinuesLayoutConstraint(n)){let s=n.getRepetitiveElements();t.push(s)}$t.isInstanceOfTableRowLayoutConstraint(n)&&n.getElementsOffsetsForTableCell(this).forEach(s=>{t.push(s)})});return t}},yr=class{constructor(e,t,i){u(this,"startNodeContexts",[]),u(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 s=this;this.column.openAllViews=function(o){return ls.prototype.openAllViews.call(this,o).thenAsync(r=>(s.startNodeContexts.push(r.copy()),P(r)))}}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 Pn(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 Wt(e.toNodePosition(),this.column.lastAfterPosition)}getColumnElement(){return this.column.element}getColumn(){return this.column}},hs=class{breakTextNode(e,t,i,n,s,o){if(t.after)t.offsetInNode=e.length;else{let r=i-t.boxOffset,a=e.data;a.charCodeAt(r)==173?r=this.breakAfterSoftHyphen(e,a,r,t):r=this.breakAfterOtherCharacter(e,a,r,t),r>0&&(t=this.updateNodeContext(t,r,e))}return t}breakAfterSoftHyphen(e,t,i,n){let s=/[\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?"":s+Ma(n)),s){let o=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=o.slice(0,i+1)+s+o.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let s=t.charAt(i);i++;let o=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&Hr(s)&&Hr(o)?Ma(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};u(hs,"instance");hs.instance=new hs;function Ma(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var Xg=class extends pr{constructor(e,t){super(),this.leadingEdge=e,u(this,"breakAfter"),u(this,"initialPageBreakType",null),u(this,"initialComputedBlockSize",0),u(this,"initialOverflown",!1),u(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new qg(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||Af()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&jh(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}},qg=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=F("DefaultLayoutMode.doLayout");return Wg(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(s=>s.nextCandidate(e))),i.fragmentLayoutConstraints.forEach(s=>{s.postLayout(n,e,t,i)}),n}},Yg=class extends ls{constructor(e,t,i,n,s,o,r){super(t,i,n,s,o),this.floatSide=e,this.parentContainer=r,u(this,"rootViewNodes",[]),u(this,"floatMargins",[]),u(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),P(t)))}convertPercentageSizesToPx(e){let t=this.parentContainer.getPaddingRect(),i=t.x2-t.x1,n=t.y2-t.y1;function s(o,r){o.forEach(a=>{let h=_t(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),c=r*l/100;T(e,a,`${c}px`)}})}s(["width","max-width","min-width"],i),s(["height","max-height","min-height"],n),s(["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=>{_t(e,o)==="auto"&&T(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=_t(t,"height");n!==""&&n!=="auto"&&T(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=_t(t,"width");n!==""&&n!=="auto"&&T(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=wt(this.clientLayout,e,this.vertical),n=this.floatMargins[t];return this.vertical?n.top+i.height+n.bottom:n.left+i.width+n.right}))}},oi=class{constructor(e,t){this.parent=e,this.rootSourceNode=t,u(this,"formattingContextType","RepetitiveElementsOwner"),u(this,"isRoot",!1),u(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||vo.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new Kg(e,this.rootSourceNode),vo.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},Kg=class{constructor(e,t){this.vertical=e,this.ownerSourceNode=t,u(this,"headerSourceNode",null),u(this,"footerSourceNode",null),u(this,"headerViewNode",null),u(this,"footerViewNode",null),u(this,"headerNodePosition",null),u(this,"footerNodePosition",null),u(this,"headerHeight",0),u(this,"footerHeight",0),u(this,"isSkipHeader",!1),u(this,"isSkipFooter",!1),u(this,"enableSkippingFooter",!0),u(this,"enableSkippingHeader",!0),u(this,"doneInitialLayout",!1),u(this,"firstContentSourceNode",null),u(this,"lastContentSourceNode",null),u(this,"affectedNodeCache",[]),u(this,"afterLastContentNodeCache",[]),u(this,"allowInsert",!1),u(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=is(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=is(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=wo(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=wo(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?P(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?P(!0):this.appendElementToFragment(this.footerNodePosition,e,t,i)}appendElementToFragment(e,t,i,n){let s=t.viewNode.ownerDocument,o=t.viewNode,r=s.createElement("div");o.appendChild(r);let a=new yr(n,r,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new Gt(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,o.removeChild(r),this.moveChildren(r,o,i),a.getColumn().pageBreakType=h,P(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(Ii,"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(s=>s.nodeContext.sourceNode===e.sourceNode&&s.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let s=i(e);return t.push({nodeContext:e,result:s}),s}}isAfterNodeContextOf(e,t,i){let n=[];for(let s=e;s;s=s.parentNode){if(t.sourceNode===s)return t.after;n.push(s)}for(let s=t.sourceNode;s;s=s.parentNode){let o=n.indexOf(s);if(o>=0)return i?o===0:!1;for(let r=s;r;r=r.previousElementSibling)if(n.includes(r))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}},Su=class{constructor(e){this.formattingContext=e}accept(e,t){return!!e}postLayout(e,t,i,n){let s=this.formattingContext.getRepetitiveElements();return s&&(i.clientLayout,s.doneInitialLayout||(s.updateHeight(i),s.doneInitialLayout=!0)),n}},Cu=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},Zg=class extends Su{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},Jg=class extends Cu{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new xr(e)),this.processor.doLayout(e,t)}},xr=class Eu{constructor(t){u(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),u(this,"nodeContext");let i=Pt(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||gi(this.nodeContext.viewNode)||!s.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,s){let o=this.getRepetitiveElements();o&&t&&s.stopAtOverflow&&(i==null||o.isAfterLastContent(i))&&o.preventSkippingFooter()}finishBreak(t,i){let n=Pt(this.nodeContext.formattingContext),s=this.getRepetitiveElements();if(!s)return P(!0);let o=this.nodeContext;return nm(n,o,i).thenAsync(()=>sm(n,o,i).thenAsync(()=>(s.prepareLayoutFragment(),P(!0))))}getRepetitiveElements(){return Pt(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof Eu?Pt(this.nodeContext.formattingContext)===Pt(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},Qg=class extends pr{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 Zg(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new Jg(this.formattingContext,this.processor))}},em=class extends en{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),P(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),P(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return en.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"?P(!0):en.prototype.afterNonInlineElementNode.call(this,e)}},tm=class extends wi{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=Pt(e.formattingContext);return n.getRootViewNode(e)?(i&&ku(e.parent,t),e.belongsTo(n)?wi.prototype.layout.call(this,e,t,i):new Qg(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=om(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=Pt(e.formattingContext),n=F("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=Pt(e.formattingContext),n=new em(i,t);return new bo(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=Pt(e.formattingContext),n=F("doLayout"),s=t.layoutContext.nextInTree(e,!1);return yu(s,t).then(o=>{let r=o;n.loopWithFrame(a=>{for(;r;){let h=!0;if(t.layoutNext(r,!1).then(l=>{r=l,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||r&&t.stopByOverflow(r)||r&&r.after&&r.sourceNode==i.rootSourceNode?a.breakLoop():h?h=!1:a.continueLoop()}),h){h=!1;return}}a.breakLoop()}).then(()=>{n.finish(r)})}),n.result()}finishBreak(e,t,i,n){return wi.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){wi.prototype.clearOverflownViewNodes(e,t,i,n)}};function im(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof oi&&!i.belongsTo(n)&&t(n,i)}}function ku(e,t){e&&im(e.after?e.parent:e,(i,n)=>{$t.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new xr(n))})}function nm(e,t,i){let n=e.getRepetitiveElements();if(n){let s=e.getRootNodeContext(t);if(s.viewNode){let o=s.viewNode.firstChild;return n.appendHeaderToFragment(s,o,i)}}return P(!0)}function sm(e,t,i){let n=e.getRepetitiveElements();if(n&&!n.isSkipFooter){let s=e.getRootNodeContext(t);if(s.viewNode)return n.appendFooterToFragment(s,null,i)}return P(!0)}function om(e){let t=e.formattingContext;return!t||!(t instanceof oi)?null:t}function Pt(e){return e instanceof oi,e}var rm=new tm;ft("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof oi&&!$t.isInstanceOfTableFormattingContext(e)?rm:null);var Pu=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,u(this,"cells",[])}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},am=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,u(this,"viewElement"),u(this,"colSpan"),u(this,"rowSpan"),u(this,"height",0),u(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}},lm=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},hm=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,u(this,"pseudoColumn"),u(this,"empty",!1),this.pseudoColumn=new yr(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}},um=class{constructor(e,t){this.viewNode=e,this.side=t}},cm=class extends Pn{constructor(e,t,i,n){super(e,t,i,n),u(this,"formattingContext"),u(this,"acceptableCellBreakPositions",null),u(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)}},dm=class extends ur{constructor(e,t,i){super(),this.rowIndex=e,this.beforeNodeContext=t,this.formattingContext=i,u(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,t){if(this!==e.breakPositions[0]&&t<this.getMinBreakPenalty())return null;let i=this.getCellFragments(),n=this.getAcceptableCellBreakPositions(),s=n.every(o=>!!o.nodeContext)&&n.some((o,r)=>{let a=i[r].pseudoColumn,h=o.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(o=>o.nodeContext&&o.nodeContext.overflow),s?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 s=i.some((o,r)=>o.breakPosition instanceof Gn&&n[r].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((o,r)=>{let a=o.breakPosition.getMinBreakPenalty();s&&o.breakPosition instanceof Pn&&o.breakPosition.overflows&&a>=3&&(n[r].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)}},Ei=class extends oi{constructor(e,t){super(e,t),this.tableSourceNode=t,u(this,"formattingContextType","Table"),u(this,"vertical",!1),u(this,"columnCount",-1),u(this,"tableWidth",0),u(this,"captions",[]),u(this,"colGroups",null),u(this,"colWidths",null),u(this,"inlineBorderSpacing",0),u(this,"rows",[]),u(this,"slots",[]),u(this,"cellFragments",[]),u(this,"lastRowViewNode",null),u(this,"cellBreakPositions",[]),u(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 Pu(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,s=this.getRowSlots(e),o=0;for(;s[o];)o++;for(;e<n;e++){s=this.getRowSlots(e);for(let r=o;r<o+t.colSpan;r++){let a=s[r]=new lm(e,r,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=wt(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 s=this.slots[i][n];if(s.cell===t)return{rowIndex:s.rowIndex,columnIndex:s.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,s)=>{if(s>=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 s=e[n],o=this.getCellFragmentOfCell(i);!o||s.collected.includes(o)||(this.collectElementsOffsetFromColumn(o.pseudoColumn.getColumn(),s.elements),s.collected.push(o))})}),[new pm(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(ei.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}$t.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=e}},pm=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 s=Si(e,n);i=Math.max(i,t(s))}),i}};function ct(e){return e instanceof Ei,e}function fm(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function gm(e){return e==="table"||e==="inline-table"}function za(e){return fm(e)||gm(e)}function Nu(e,t,i){let n=e.nodeContext,s=n.display,o=n.parent?n.parent.display:null,r=!1;if(o==="inline-table"&&!(n.formattingContext instanceof Ei)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof Ei){r=a.formattingContext===t;break}}return r||s==="table-row"&&!za(o)||s==="table-cell"&&o!=="table-row"&&!za(o)||n.formattingContext instanceof Ei&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,P(!0))):null}var mm=class extends en{constructor(e,t){super(),this.formattingContext=e,this.column=t,u(this,"rowIndex",-1),u(this,"columnIndex",0),u(this,"inRow",!1),u(this,"checkPoints",[]),u(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=Nu(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=e.nodeContext,s=n.display,o=t.getRepetitiveElements();switch(s){case"table":t.inlineBorderSpacing=n.inlineBorderSpacing;break;case"table-caption":{let r=new um(n.viewNode,n.captionSide);t.captions.push(r);break}case"table-header-group":return o.isHeaderRegistered()||(this.inHeaderOrFooter=!0,o.setHeaderNodeContext(n)),P(!0);case"table-footer-group":return o.isFooterRegistered()||(this.inHeaderOrFooter=!0,o.setFooterNodeContext(n)),P(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,n.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new Pu(this.rowIndex,n.sourceNode)),o.firstContentSourceNode||(o.firstContentSourceNode=n.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,s=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let o=s.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,P(!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 o=i.viewNode;t.addCell(this.rowIndex,new am(this.rowIndex,this.columnIndex,o)),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&&!mi(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},Tu=class Iu extends en{constructor(t,i){super(!0),this.formattingContext=t,this.column=i,u(this,"inRow",!1),u(this,"currentRowIndex",-1),u(this,"currentColumnIndex",0),u(this,"originalStopAtOverflow"),u(this,"inHeader"),u(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 s=0;s<t.colSpan;s++)n+=i[t.anchorSlot.columnIndex+s];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let s=t.rowIndex,o=t.columnIndex,r=t.colSpan,a=i.viewNode,h=i.verticalAlign;r>1&&(T(a,"box-sizing","border-box"),T(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let l=a.ownerDocument.createElement("div");a.appendChild(l);let c=new hm(this.column,l,i);return this.formattingContext.addCellFragment(s,o,c),n.primary.steps.length===1&&n.primary.after&&(c.empty=!0),c.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 s=t[n],o=s.cell.rowIndex;if(o<this.currentRowIndex){let r=i[o];r||(r=i[o]=[]),r.push(s),t.splice(n,1)}else n++}while(n<t.length);return i}layoutRowSpanningCellsFromPreviousFragment(t){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),s=n.reduce(p=>p+1,0);if(s===0)return P(!0);let o=this.column.layoutContext,r=t.nodeContext;r.viewNode.parentNode.removeChild(r.viewNode);let a=F("layoutRowSpanningCellsFromPreviousFragment"),h=P(!0),l=0,c=[];return n.forEach(p=>{h=h.thenAsync(()=>{let d=ns(p[0].cellNodePosition.steps[1],r.parent);return o.setCurrent(d,!1).thenAsync(()=>{let f=P(!0),m=0;function g(w){for(;m<w;){if(!c.includes(m)){let y=d.viewNode.ownerDocument.createElement("td");T(y,"padding","0"),d.viewNode.appendChild(y)}m++}}return p.forEach(w=>{f=f.thenAsync(()=>{let y=w.cell;g(y.anchorSlot.columnIndex);let b=w.cellNodePosition,C=ns(b.steps[0],d);return C.offsetInNode=b.offsetInNode,C.after=b.after,C.fragmentIndex=b.steps[0].fragmentIndex+1,o.setCurrent(C,!1).thenAsync(()=>{let k=w.breakChunkPosition;for(let R=0;R<y.colSpan;R++)c.push(m+R);return m+=y.colSpan,this.layoutCell(y,C,k).thenAsync(()=>(C.viewNode.rowSpan=y.rowIndex+y.rowSpan-this.currentRowIndex+s-l,P(!0)))})})}),f.thenAsync(()=>(g(i.getColumnCount()),l++,P(!0)))})})}),h.then(()=>{o.setCurrent(r,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return P(!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),P(!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],s=this.column.layoutContext.xmldoc.getElementOffset(n.node);Vg(s,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return P(!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,P(!0);let s=i.copy().modify();s.after=!0,t.nodeContext=s;let o=F("startTableCell"),r;if(this.hasBrokenCellAtSlot(n.anchorSlot.columnIndex)){let a=this.formattingContext.cellBreakPositions.shift();i.fragmentIndex=a.cellNodePosition.steps[0].fragmentIndex+1,r=P(a.breakChunkPosition)}else r=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(a=>{a.viewNode&&i.viewNode.removeChild(a.viewNode);let h=is(a,0);return P(new Gt(h))});return r.then(a=>{this.layoutCell(n,i,a).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,o.finish(!0)})}),o.result()}startNonInlineBox(t){let i=Nu(t,ct(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,s=this.formattingContext.getRepetitiveElements(),o=n.display;return o==="table-header-group"&&s&&s.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,P(!0)):o==="table-footer-group"&&s&&s.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,P(!0)):o==="table-row"?this.startTableRow(t):o==="table-cell"?this.startTableCell(t):P(!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 s=new dm(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(s)}return P(!0)}afterNonInlineElementNode(t){let i=t.nodeContext,n=this.formattingContext.getRepetitiveElements(),s=i.display;if(s==="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"):s==="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")),s&&Iu.ignoreList[s])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 P(!0)}};u(Tu,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var wm=Tu,pn=[];function bm(e){let t=pn.findIndex(n=>n.root===e),i=pn[t];return i?i.tableLayoutOption:null}function vm(e){let t=pn.findIndex(i=>i.root===e);t>=0&&pn.splice(t,1)}var Au=class{layoutEntireTable(e,t){let i=ct(e.formattingContext),n=new mm(i,t);return new bo(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let s=e.ownerDocument,o=s.createElement("tr"),r=[];for(let h=0;h<t;h++){let l=s.createElement("td");o.appendChild(l),r.push(l)}e.parentNode.insertBefore(o,e.nextSibling);let a=r.map(h=>{let l=wt(n,h,i),c=i?l.height:l.width;return Math.ceil(c)});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 s=i.firstElementChild;for(;s;){if(s.localName==="col"){let o=s.span;for(s.removeAttribute("span"),n-=o;o-- >1;){let r=s.cloneNode(!0);i.insertBefore(r,s),t.push(r)}t.push(s)}s=s.nextElementSibling}for(;n-- >0;)s=i.ownerDocument.createElement("col"),i.appendChild(s),t.push(s)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let s=n.ownerDocument.createElement("colgroup");t.push(s);for(let o=e.length;o<i;o++){let r=n.ownerDocument.createElement("col");s.appendChild(r),e.push(r)}}}normalizeColGroups(e,t,i){let n=e.vertical,s=e.lastRowViewNode;if(!s)return;e.lastRowViewNode=null;let o=s.ownerDocument.createDocumentFragment(),r=e.getColumnCount();if(!(r>0)){e.colGroups=o;return}let a=e.colWidths=this.getColumnWidths(s,r,n,i.clientLayout),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,r,t),l.forEach((c,p)=>{T(c,n?"height":"width",`${a[p]}px`)}),h.forEach(c=>{o.appendChild(c.cloneNode(!0))}),e.colGroups=o}doInitialLayout(e,t){let i=ct(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=bm(e.sourceNode);vm(e.sourceNode);let s=F("TableLayoutProcessor.doInitialLayout"),o=e.copy();return this.layoutEntireTable(e,t).then(r=>{let a=r.viewNode,h=wt(t.clientLayout,a,t.vertical),l=t.vertical?h.left:h.bottom;if(l+=(t.vertical?-1:1)*Si(e,t.collectElementsOffset()).current,!t.isOverflown(l)&&(!n||!n.calculateBreakPositionsInside)){t.breakPositions.push(new Cm(o)),s.finish(r);return}this.normalizeColGroups(i,a,t),i.updateCellSizes(t.clientLayout),s.finish(null)}),s.result()}addCaptions(e,t,i){let n=e.captions;n.forEach((s,o)=>{s&&(t.insertBefore(s.viewNode,i),s.side==="top"&&(n[o]=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),s=n.firstChild;this.addCaptions(i,n,s),this.addColGroups(i,n,s);let o=new wm(i,t),r=new bo(o,t.layoutContext),a=F("TableFormattingContext.doLayout");return r.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=ct(e.formattingContext),s=n.getRootViewNode(e),o=F("TableFormattingContext.layout"),r;return s?(i&&ku(e.parent,t),r=new xm(n,this).layout(e,t)):r=t.buildDeepElementView(e),r.then(a=>{o.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"))}),o.result()}createEdgeBreakPosition(e,t,i,n){return new cm(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return js(e),!1}finishBreak(e,t,i,n){let s=ct(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let o=s.findRowIndexBySourceNode(t.sourceNode);s.cellBreakPositions=[];let r;if(t.after?r=s.getRowSpanningCellsOverflowingTheRow(o):r=s.getCellsFallingOnRow(o),r.length){let a=F("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===r.length){l.breakLoop();return}let c=r[h++],p=s.getCellFragmentOfCell(c),d=p.findAcceptableBreakPosition().nodeContext,f=p.cellNodeContext,m=f.toNodePosition(),g=new Gt(d.toNodePosition());s.cellBreakPositions.push({cellNodePosition:m,breakChunkPosition:g,cell:c});let w=f.viewNode;p.column.layoutContext.processFragmentedBlockEdge(p.cellNodeContext),o<c.rowIndex+c.rowSpan-1&&(w.rowSpan=o-c.rowIndex+1),p.empty?l.continueLoop():p.pseudoColumn.finishBreak(d,!1,!0).then(()=>{ym(p,s,d),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),js(t),s.finishFragment(),a.finish(!0)}),a.result()}}return js(t),s.finishFragment(),dr.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){wi.prototype.clearOverflownViewNodes(e,t,i,n)}};function ym(e,t,i){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let s=t.vertical,o=e.column,r=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,h=wt(o.clientLayout,a,s),l=o.getComputedPaddingBorder(a);if(s){let c=h.right-o.footnoteEdge-n.calculateOffset(i)-l.right;T(r,"max-width",`${c}px`)}else{let c=o.footnoteEdge-n.calculateOffset(i)-h.top-l.top;T(r,"max-height",`${c}px`)}}function js(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((p,d)=>{let f=d.getBoundingClientRect(),m=e.vertical?f.width:f.height;return p+m},0),s=i[i.length-1],o=Array.from(t.children).indexOf(s),r=Array.from(s.children).reduce((p,d)=>{let f=d.rowSpan;return f>1&&o+f<t.childElementCount?Math.max(p,f):p},0),a=r?t.children[o+r-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let p=a;p&&p!==t.lastElementChild;p=p.nextElementSibling)if(p.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=p;break}}let h=a.getBoundingClientRect(),l=e.vertical?h.width:h.height,c=n+l;T(a,e.vertical?"width":"height",`${c}px`)}var xm=class extends pr{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new Sm(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new km(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()}},Sm=class extends Su{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},Cm=class extends Pn{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 Em(this.position.sourceNode))}},Em=class Ru{constructor(t){this.tableRootNode=t,u(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,s){i.sourceNode,pn.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return P(!0)}equalsTo(t){return t instanceof Ru&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},km=class extends Cu{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new Pm(e);t.fragmentLayoutConstraints.some(s=>n.equalsTo(s))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},Pm=class Lu extends xr{constructor(t){super(t),u(this,"flagmentLayoutConstraintType","TableRow"),u(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||n.pseudoParent||gi(this.nodeContext.viewNode)||!s.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(s=>s.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,s){let o=ct(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,o),this.cellFragmentLayoutConstraints.forEach(r=>{r.constraints.forEach(a=>{a.postLayout(t,r.breakPosition,n,s)})}),!t){let r=o.getRootViewNode(this.nodeContext);new Au().removeColGroups(o,r),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,s)}finishBreak(t,i){let n=ct(this.nodeContext.formattingContext),s=F("finishBreak"),o=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.breakPosition}))),[]),r=0;return s.loop(()=>{if(r<o.length){let a=o[r++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return P(!1)}).then(()=>{s.finish(!0)}),s.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 s=[];for(let o=0;o<n;o++)i.cellFragments[o]&&i.cellFragments[o].forEach(r=>{r&&s.push({fragment:r,breakPosition:r.findAcceptableBreakPosition().nodeContext})});return s}getElementsOffsetsForTableCell(t){let i=ct(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof Lu?ct(this.nodeContext.formattingContext)===ct(t.nodeContext.formattingContext):!1}},Nm=new Au;function Tm(e,t,i,n,s,o){if(!t)return null;if(i===v.table){let r=e.parent;return new Ei(r?r.formattingContext:null,e.sourceNode)}return null}function Im(e){return e instanceof Ei?Nm:null}ft("RESOLVE_FORMATTING_CONTEXT",Tm);ft("RESOLVE_LAYOUT_PROCESSOR",Im);function Da(e){return e.reduce((t,i)=>t+i,0)/e.length}function Am(e){let t=Da(e);return Da(e.map(i=>{let n=i-t;return n*n}))}var Rm=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function fn(e){return e.vertical?e.width:e.height}function gn(e,t){e.vertical?e.width=t:e.height=t}var Fu=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,u(this,"originalContainerBlockSize"),this.originalContainerBlockSize=fn(e)}balanceColumns(e){let t=F("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(s=>{if(this.savePageFloatLayoutContexts(s),this.layoutContainer.clear(),!s){n.breakLoop();return}i.push(this.createTrialResult(s)),n.continueLoop()})}).then(()=>{let n=i.reduce((s,o)=>o.penalty<s.penalty?o:s,i[0]);this.restoreContents(n.layoutResult),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new Rm(e,t)}preBalance(e){}postBalance(){gn(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)}},Oo=1;function Ou(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,s=Math.max.apply(null,n.map(r=>r.computedBlockSize)),o=Math.max.apply(null,n.map(r=>r.getMaxBlockSizeOfPageFloats()));return s>o+Oo}function Bu(e,t){var i;let n=e[e.length-1].layoutResult.columns,s=Math.max.apply(null,n.map(o=>isNaN(o.blockDistanceToBlockEndFloats)?o.computedBlockSize:o.computedBlockSize-o.blockDistanceToBlockEndFloats+Oo))-Oo;if(s<fn(t)?gn(t,s):gn(t,fn(t)-1),t.vertical){let o=parseFloat((i=t.element.style)==null?void 0:i.width);t.originX=o-t.width}}var Lm=class extends Fu{constructor(e,t,i,n){super(i,e,t),this.columnCount=n,u(this,"originalPosition",null),u(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);gn(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 Va(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return Ou(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!Va(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):fn(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Bu(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,fn(this.layoutContainer)+this.originalContainerBlockSize*.1);gn(this.layoutContainer,t)}}};function Va(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(s=>t>s.computedBlockSize+n)}var Fm=class extends Fu{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 Am(t)}hasNextCandidate(e){return Ou(e)}updateCondition(e){Bu(e,this.layoutContainer)}};function Om(e,t,i,n,s,o,r){if(t===v.auto)return null;{let a=r.positions.length===0,h=o[o.length-1],l=!!(h&&h.pageBreakType);return a||l?new Lm(i,n,s,e):t===v.balance_all?new Fm(i,n,s):(v.balance,null)}}var Xs=class{constructor(e,t,i){u(this,"endStuckFixed"),u(this,"endFixed"),u(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},Bm=class{constructor(){u(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 Xs(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 Xs(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new Xs(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=Ht(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=Ht(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}},_m=class Bo{constructor(t,i,n,s,o,r,a,h){if(this.context=t,this.style=i,this.offset=n,this.isRoot=s,this.flowChunk=o,this.atBlockStart=r,this.atFlowStart=a,this.isParentBoxDisplayed=h,u(this,"flowName"),u(this,"isBlockValue",null),u(this,"hasBoxValue",null),u(this,"styleValues",{}),u(this,"beforeBox",null),u(this,"afterBox",null),u(this,"breakBefore",null),this.flowName=o.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let c=new Bo(t,l.before,n,!1,o,this.isBlock(),a,!0),p=c.styleValue("content");jt(p)&&(this.beforeBox=c,this.breakBefore=c.breakBefore)}}this.breakBefore=Xe(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&je(this.breakBefore)&&(o.breakBefore=Xe(o.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let s=this.style._pseudos;if(s&&s.after){let o=new Bo(this.context,s.after,t,!1,this.flowChunk,i,n,!0),r=o.styleValue("content");jt(r)&&(this.afterBox=o)}}}styleValue(t,i){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):i||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",v.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=Uh(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==v.none&&!go(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}},Mm=class{constructor(e){this.context=e,u(this,"stack",[]),u(this,"atBlockStart",!0),u(this,"atFlowStart",!0),u(this,"atStartStack",[])}empty(){return this.stack.length===0}lastBox(){return this.stack[this.stack.length-1]}lastFlowName(){let e=this.lastBox();return e?e.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(e=>e.displayValue()!==v.none)}push(e,t,i,n){let s=this.lastBox();n&&s&&n.flowName!==s.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let o=n||s.flowChunk,r=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),h=new _m(this.context,e,t,i,o,r||this.atBlockStart,r,a);return this.stack.push(h),this.atBlockStart=h.hasBox()?!h.beforeBox&&h.isBlock():this.atBlockStart,this.atFlowStart=h.hasBox()?!h.beforeBox&&r:this.atFlowStart,h}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",v.normal).toString(),n=Ih(i);n&&!ze(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=Xe(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!")}},Ua=class{constructor(e,t,i,n,s,o,r,a){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=s,this.validatorSet=o,this.counterListener=r,u(this,"root"),u(this,"cascadeHolder"),u(this,"last"),u(this,"rootStyle",{}),u(this,"styleMap",{}),u(this,"flows",{}),u(this,"flowChunks",[]),u(this,"flowListener",null),u(this,"flowToReach",null),u(this,"idToReach",null),u(this,"cascade"),u(this,"offsetMap"),u(this,"primary",!0),u(this,"primaryStack",[]),u(this,"rootBackgroundAssigned",!1),u(this,"rootLayoutAssigned",!1),u(this,"lastOffset"),u(this,"breakBeforeValues",{}),u(this,"boxStack"),u(this,"bodyReached",!0),this.root=e.root,this.cascadeHolder=t,this.last=this.root,this.cascade=t.createInstance(n,r,a,e.lang),this.offsetMap=new Bm;let h=e.getElementOffset(this.root);this.lastOffset=h,this.boxStack=new Mm(n),this.offsetMap.addStuckRange(h);let l=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,l,h),this.postprocessTopStyle(l,!1),this.root.namespaceURI){case"http://www.w3.org/1999/xhtml":this.bodyReached=!1;break}this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${h}`]=l,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 s=t[i];s&&(this.rootStyle[i]=new Z(s,gh))}}}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)tn(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,s=this.hasProp(e,this.validatorSet.backgroundProps,"background-image")?e["background-image"].evaluate(this.context):null;(n&&!J(n)||s&&!J(s))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<Ha.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,Ha[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],s=!0;if(n&&!J(n.value)){let a=n.evaluate(this.context);if(a instanceof I){let h=a.num;switch(a.unit){case"em":case"rem":h*=this.context.initialFontSize;break;case"ex":h*=this.context.initialFontSize*ge.ex/ge.em;break;case"%":h*=this.context.initialFontSize/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*ge.lh/ge.em;break;default:{let l=ge[a.unit];l&&(h*=l),s=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=s}}let o=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,r=e["line-height"];if(r&&!J(r.value)){let a=r.evaluate(this.context);if(a instanceof Xt)this.context.rootLineHeight=a.num*o;else if(a instanceof I){let h=a.num;switch(a.unit){case"em":case"rem":h*=o;break;case"ex":h*=o*ge.ex/ge.em;break;case"%":h*=o/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*ge.lh/ge.em;break;default:{let l=ge[a.unit];l&&(h*=l)}}this.context.rootLineHeight=h}}else this.context.rootLineHeight=this.context.fontSize()*ge.lh/ge.em}}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 Lg(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 o=this.getStyle(this.root,!1),r=Ve(o,"flow-into"),a=r?r.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),s=this.xmldoc.getNodeOffset(n,0,!1);if(!(s>=this.lastOffset))for(;;){if(n.nodeType!=1)s+=n.textContent.length;else{let r=n,a=this.getStyle(r,!1),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,a,r,s)}s++}if(s>=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 s=0,o=Number.POSITIVE_INFINITY,r=!1,a=!1,h=!1,l=t["flow-options"];if(l){let g=Ud(l.evaluate(this.context,"flow-options"));r=!!g.exclusive,a=!!g.static,h=!!g.last}let c=t["flow-linger"];c&&(o=aa(c.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let p=t["flow-priority"];p&&(s=aa(p.evaluate(this.context,"flow-priority"),0));let d=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let g=this.boxStack.lastFlowName();f=this.flows[e]=new nf(e,g)}let m=new sf(e,i,n,s,o,r,a,h,d);return this.flowChunks.push(m),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(m,f),m}registerForcedBreakOffset(e,t,i){if(je(e)){let s=this.flows[i].forcedBreakOffsets;(s.length===0||s[s.length-1]<t)&&s.push(t)}let n=this.breakBeforeValues[t];this.breakBeforeValues[t]=Xe(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 s=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 r=this.boxStack.pop(this.lastOffset),a=null;if(r.afterBox){let h=r.afterBox.getBreakValue("before");this.registerForcedBreakOffset(h,r.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(r):r.afterBox.offset,r.flowName),a=r.afterBox.getBreakValue("after")}a=Xe(a,r.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,r.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 r=this.last,a=this.getAttrStyle(r);this.primaryStack.push(this.primary),this.cascade.pushElement(this,r,a,this.lastOffset);let h=r.getAttribute("id")||r.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");h&&h===this.idToReach&&(this.idToReach=null),!this.bodyReached&&r.localName=="body"&&r.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let l,c=a["flow-into"];if(c){let d=c.evaluate(s,"flow-into").toString(),f=this.encounteredFlowElement(d,a,r,this.lastOffset);this.primary=!!this.primaryFlows[d],l=this.boxStack.push(a,this.lastOffset,r===this.root,f)}else l=this.boxStack.push(a,this.lastOffset,r===this.root),r===this.xmldoc.body&&(l.breakBefore=Xe(l.flowChunk.breakBefore,l.breakBefore));let p=this.boxStack.nearestBlockStartOffset(l);if(p===0){let d=a.page,f=d&&!J(d.value)&&d.value.toString();f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(l.breakBefore,p,l.flowName),l.beforeBox){let d=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(d,l.beforeBox.atBlockStart?p:l.offset,l.flowName)}if(this.primary&&l.displayValue()===v.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=a,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&p===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){}},Ha=["column-count","column-width","column-fill"],vi=class{constructor(e){this.validator=e,u(this,"success",null),u(this,"failure",null),u(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)}},Zt=class{constructor(e,t){this.where=e,this.success=t,u(this,"what",-1)}},Ui=class _u{constructor(){u(this,"nodes",[]),u(this,"connections",[]),u(this,"match",[]),u(this,"nomatch",[]),u(this,"error",[]),u(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 _u;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],s=new vi(n.validator);s.code=n.code,t.nodes.push(s)}for(let i=0;i<this.connections.length;i++){let n=this.connections[i],s=new Zt(n.where,n.success);s.what=n.what,t.connections.push(s)}return t.match.push(...this.match),t.nomatch.push(...this.nomatch),t.error.push(...this.error),t}addSpecialToArr(t,i,n){let s=this.nodes.length,o=new vi($a);n>=0?i?o.markAsStartAlternate(n):o.markAsEndAlternate(n):i?o.markAsStartGroup():o.markAsEndGroup(),this.nodes.push(o),this.connect(t,s);let r=new Zt(s,!0),a=new Zt(s,!1);t.push(this.connections.length),this.connections.push(a),t.push(this.connections.length),this.connections.push(r)}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 vi($a);i.markAsStartAlternate(t),this.nodes.push(i);let n=new Zt(0,!0),s=new Zt(0,!1);this.nomatch.push(this.connections.length),this.connections.push(s),this.match.push(this.connections.length),this.connections.push(n)}addPrimitive(t){let i=this.nodes.length;this.nodes.push(new vi(t));let n=new Zt(i,!0),s=new Zt(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(s),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 Pe}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 s=this.connections.length;for(let o=0;o<t.connections.length;o++){let r=t.connections[o];r.where+=n,r.what>=0&&(r.what+=n),this.connections.push(r)}for(let o=0;o<t.match.length;o++)this.match.push(t.match[o]+s);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]+s);else if(this.emptyHead){for(let o=0;o<t.nomatch.length;o++)this.nomatch.push(t.nomatch[o]+s);this.emptyHead=t.emptyHead}else for(let o=0;o<t.nomatch.length;o++)this.error.push(t.nomatch[o]+s);for(let o=0;o<t.error.length;o++)this.error.push(t.error[o]+s);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 s of this.connections)s.success?this.nodes[s.where].success=this.nodes[s.what]:this.nodes[s.where].failure=this.nodes[s.what];for(let s=0;s<n;s++)if(this.nodes[s].failure==null||this.nodes[s].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},zm=1,Mu=2,zu=4,Jt=8,jn=16,_o=32,Xn=64,Du=128,Xi=256,qi=512,Mo=1024,Vu=2048,Uu=4096,Hu=8192,$u=class extends Ot{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},Pe=class Wu extends $u{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&zm?t:null}visitSlash(t){return this.allowed&Vu?t:null}visitStr(t){return this.allowed&Mu?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&zu||this.allowed&Xn&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&qi)?t.unit=="%"&&this.allowed&Mo?t:null:t.num<0&&!(this.allowed&Xi)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&qi?t:null:t.num<=0&&!(this.allowed&Xi)?null:this.allowed&jn?t:null}visitInt(t){return t.num==0?this.allowed&qi?t:null:t.num<=0&&!(this.allowed&Xi)?null:this.allowed&(_o|jn)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&Xn&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&Du?t:null}visitURange(t){return this.allowed&Uu?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){return this.allowed&Xn&&CSS.supports("color",t.toString())||this.allowed&Hu&&CSS.supports("background-image",t.toString())||t.name==="calc"&&this.allowed&(Jt|jn|_o|Xi|qi|Mo)?t:null}visitExpr(t){return this.allowed&2046?t:null}combine(t){let i={},n={};for(let s in this.idents)i[s]=this.idents[s];for(let s in t.idents)i[s]=t.idents[s];for(let s in this.units)n[s]=this.units[s];for(let s in t.units)n[s]=t.units[s];return new Wu(this.allowed|t.allowed,i,n)}},ie={},$a=new Pe(0,ie,ie),Sr=class extends $u{constructor(e){super(),u(this,"successTerminal"),u(this,"failureTerminal"),u(this,"first"),this.successTerminal=new vi(null),this.failureTerminal=new vi(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,s=this.first,o=i,r=null,a=null;for(;s!==this.successTerminal&&s!==this.failureTerminal;){if(o>=e.length){s=s.failure;continue}let h=e[o],l=h;if(s.isSpecial()){let c=!0;s.isStartGroup()?(r?r.push(a):r=[a],a=[]):s.isEndGroup()?r.length>0?a=r.pop():a=null:s.isEndAlternate()?a[s.getAlternate()]="taken":c=a[s.getAlternate()]==null,s=c?s.success:s.failure}else{if(o==0&&!t&&s.validator instanceof on&&this instanceof on){if(l=new me(e).visit(s.validator),l){o=e.length,s=s.success;continue}}else if(o==0&&!t&&s.validator instanceof Cr&&this instanceof on){if(l=new qe(e).visit(s.validator),l){o=e.length,s=s.success;continue}}else l=h.visit(s.validator);if(!l){s=s.failure;continue}if(l!==h&&e===n){n=[];for(let c=0;c<o;c++)n[c]=e[c]}e!==n&&(n[o-i]=l),o++,s=s.success}}return s===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}},on=class extends Sr{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new me(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof Cr){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new qe(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},Cr=class extends Sr{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 qe(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}},Dm=class extends Sr{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 Fi(e.name,t):null}},Gu=class{tryParse(e,t,i){return t}success(e,t){}},ju=class extends Gu{constructor(e,t){super(),this.name=t,u(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 s=n.length,o=s>1?new me(n):n[0];return this.success(o,i),t+s}return t}success(e,t){t.values[this.name]=e}},Vm=class extends ju{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}},Um=class extends Gu{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==fs){if(++t==e.length)return n}else return n;let s=this.nodes[0].tryParse(e,t,i);if(s==t)return n;t=s;for(let o=1;o<this.nodes.length&&t<e.length&&(s=this.nodes[o].tryParse(e,t,i),s!=t);o++)t=s;return t}},Er=class extends Ot{constructor(){super(...arguments),u(this,"syntax",null),u(this,"propList",null),u(this,"error",!1),u(this,"values",{}),u(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new ju(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 s of this.propList)t.simpleProperty(s,(n=(i=this.values[s])!=null?i:this.validatorSet.defaultValues[s])!=null?n:v.initial,e);return!0}return!1}propagateDefaultingValue(e,t,i){for(let n of this.propList)i.simpleProperty(n,e,t)}validateList(e){return this.error=!0,0}validateSingle(e){return this.validateList([e]),null}visitEmpty(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitSpaceList(e){return this.validateList(e.values),null}visitCommaList(e){return this.error=!0,null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return this.validateSingle(e)}},Mi=class extends Er{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}},Xu=class extends Er{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 Vm(this.validatorSet,this.propList)}},Hm=class extends Er{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===fs){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 s;if(t+1<e.length)for(s=t+i+1;s>=e.length;)s=s-(s==t+2?1:2);else s=n;let o=[e[n],e[s]];if(this.syntax[i].tryParse(o,0,this)!=2)return this.error=!0,0}return e.length}},$m=class extends Mi{constructor(){super()}mergeIn(e,t){var i,n;for(let s of this.propList){let o=(n=(i=t[s])!=null?i:this.validatorSet.defaultValues[s])!=null?n:v.initial,r=e[s];r||(r=[],e[s]=r),r.push(o)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof qe?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 qe(t[i]);return null}},Wm=class extends Mi{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 s=this.validatorSet.validators;if(!e[t].visit(s["font-size"]))return this.error=!0,t;if(this.values["font-size"]=e[t++],e[t]===fs){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(s["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let o=t==e.length-1?e[t]:new me(e.slice(t,e.length));return o.visit(s["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 qe(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}},Gm=class extends Mi{validateList(e){if(e.length===1&&e[0]instanceof nt)switch(e[0].name.toLowerCase()){case"normal":e=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":e=[v.auto,v.auto];break;case"none":e=[B("no-autospace"),B("space-all")];break}return super.validateList(e)}},jm=["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"],Xm=class extends Mi{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)jm.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},Wa={SIMPLE:Mi,INSETS:Xu,INSETS_SLASH:Hm,COMMA:$m,FONT:Wm,TEXT_SPACING:Gm,ALL:Xm},qm=class{constructor(){u(this,"validators",{}),u(this,"prefixes",{}),u(this,"defaultValues",{}),u(this,"namedValidators",{}),u(this,"systemFonts",{}),u(this,"shorthands",{}),u(this,"layoutProps",{}),u(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 ql(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 s in n)n[s]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new Ui;if(e=="||"){for(let s=0;s<t.length;s++){let o=new Ui;o.startClause(s),o.addGroup(t[s],1),o.endClause(s),i.addGroup(o,s==0?1:4)}let n=new Ui;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 s=0;s<t.length;s++)i.addGroup(t[s],s==0?1:n);return i}}addCounts(e,t,i){let n=new Ui;for(let s=0;s<t;s++)n.addGroup(e.clone(),1);if(i==Number.POSITIVE_INFINITY)n.addGroup(e,3);else for(let s=t;s<i;s++)n.addGroup(e.clone(),2);return n}primitive(e){let t=new Ui;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new Cr(t);break;case"SPACE":i=new on(t);break;default:i=new Dm(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Pe(Xn,ie,ie)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Pe(Hu,ie,ie)),this.namedValidators.POS_INT=this.primitive(new Pe(_o,ie,ie)),this.namedValidators.POS_NUM=this.primitive(new Pe(jn,ie,ie)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Pe(Jt,ie,{"%":W})),this.namedValidators.NEGATIVE=this.primitive(new Pe(Xi,ie,ie)),this.namedValidators.ZERO=this.primitive(new Pe(qi,ie,ie)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Pe(Mo,ie,ie)),this.namedValidators.POS_LENGTH=this.primitive(new Pe(Jt,ie,{em:W,ex:W,ch:W,rem:W,lh:W,rlh:W,vw:W,vh:W,vi:W,vb:W,vmin:W,vmax:W,pvw:W,pvh:W,pvi:W,pvb:W,pvmin:W,pvmax:W,cm:W,mm:W,in:W,px:W,pt:W,pc:W,q:W})),this.namedValidators.POS_ANGLE=this.primitive(new Pe(Jt,ie,{deg:W,grad:W,rad:W,turn:W})),this.namedValidators.POS_TIME=this.primitive(new Pe(Jt,ie,{s:W,ms:W})),this.namedValidators.FREQUENCY=this.primitive(new Pe(Jt,ie,{Hz:W,kHz:W})),this.namedValidators.RESOLUTION=this.primitive(new Pe(Jt,ie,{dpi:W,dpcm:W,dppx:W})),this.namedValidators.URI=this.primitive(new Pe(Du,ie,ie)),this.namedValidators.URANGE=this.primitive(new Pe(Uu,ie,ie)),this.namedValidators.IDENT=this.primitive(new Pe(zu,ie,ie)),this.namedValidators.STRING=this.primitive(new Pe(Mu,ie,ie)),this.namedValidators.SLASH=this.primitive(new Pe(Vu,ie,ie));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 s=i.text;if(e.consume(),t!=2){if(e.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(s)||(this.prefixes[s]=n)}else if(e.token().type!=18)throw new Error("':' expected");return s}parseValidators(e){for(;;){let t=this.readNameAndPrefixes(e,1);if(!t)return;let i=[],n=[],s="",o,r=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(s,i)},h=c=>{if(r)throw new Error(`'${c}': unexpected`);if(s&&s!=c)throw new Error(`mixed operators: '${c}' and '${s}'`);s=c,r=!0},l=null;for(;!l;){e.consume();let c=e.token();switch(c.type){case 1:if(r||h(" "),this.isBuiltIn(c.text)){let p=this.namedValidators[c.text];if(!p)throw new Error(`'${c.text}' unexpected`);i.push(p.clone())}else{let p={};p[c.text.toLowerCase()]=B(c.text),i.push(this.primitive(new Pe(0,p,ie)))}r=!1;break;case 5:{let p={};p[`${c.num}`]=new si(c.num),i.push(this.primitive(new Pe(0,p,ie))),r=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:r||h(" "),n.push({vals:i,op:s,b:"["}),s="",i=[],r=!0;break;case 6:r||h(" "),n.push({vals:i,op:s,b:"(",fn:c.text}),s="",i=[],r=!0;break;case 15:{o=a();let p=n.pop();if(p.b!="[")throw new Error("']' unexpected");i=p.vals,i.push(o),s=p.op,r=!1;break}case 11:{o=a();let p=n.pop();if(p.b!="(")throw new Error("')' unexpected");i=p.vals,i.push(this.newFunc(p.fn,o)),s=p.op,r=!1;break}case 18:if(r)throw new Error("':' unexpected");e.consume(),i.push(this.addReplacement(i.pop(),e.token()));break;case 22:if(r)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(r)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(r)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(e.consume(),c=e.token(),c.type!=5)throw new Error("<int> expected");let p=c.num,d=p;if(e.consume(),c=e.token(),c.type==16){if(e.consume(),c=e.token(),c.type!=5)throw new Error("<int> expected");d=c.num,e.consume(),c=e.token()}if(c.type!=13)throw new Error("'}' expected");i.push(this.addCounts(i.pop(),p,d));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 on(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 si(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 me(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&Wa[i.text]?(n=new Wa[i.text],e.consume()):n=new Mi,n.setOwner(this);let s=!1,o=[],r=!1,a=[],h=[];for(;!s;)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 Xu){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||r)throw new Error("unexpected slash");r=!0;break;case 14:a.push({slash:r,syntax:o}),o=[],r=!1;break;case 15:{let l=new Um(o,r),c=a.pop();o=c.syntax,r=c.slash,o.push(l);break}case 17:s=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(o,h),this.shorthands[t]=n}}parse(e){let t=new yt(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 s=this.shorthands[n],o=s?s.propList:[n];for(let r of o)i[r]=(t=this.defaultValues[r])!=null?t:v.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){if(At(e)||n.ruleType==="font-face"||Km(t)){n.simpleProperty(e,t,i);return}let s="",o=e;e=e.toLowerCase();let r=e.match(/^-([a-z]+)-([-a-z0-9]+)$/);r&&(s=r[1],e=r[2]);let a=this.prefixes[e];if(!a||!a[s]){CSS.supports(o,t.toString())?n.simpleProperty(o,t,i):s&&!xl.includes(`-${s}-`)||n.unknownProperty(o,t);return}let h=this.validators[e];if(h){let l=J(t)||t.isExpr()?t:t.visit(h);l?n.simpleProperty(e,l,i):!s&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(o,t)}else{let l=this.shorthands[e].clone();J(t)?l.propagateDefaultingValue(t,i,n):(t.visit(l),l.finish(i,n)||n.invalidPropertyValue(o,t))}}};function qu(){let e=new qm;return e.initBuiltInValidators(),e.parse(lh),e}var Ym=class extends Ot{constructor(){super(...arguments),u(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function Km(e){let t=new Ym;return e.visit(t),t.varFound}var kb=`OTTO${new Date().valueOf()}`;function kr(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function Zm(e){let t=new It;for(let i of kr(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function Jm(e,t){let i={};for(let n in e)i[n]=Ve(e,n).evaluate(t,n);return i}var Yu=class{constructor(e){this.properties=e,u(this,"fontTraitKey"),u(this,"src"),u(this,"blobURLs",[]),u(this,"blobs",[]),u(this,"family"),this.fontTraitKey=Zm(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 It;i.append(`@font-face {
|
|
1535
|
+
|
|
1536
|
+
/* ::marker */
|
|
1537
|
+
/* Mozilla Bullet font (https://github.com/mozilla/gecko-dev/blob/master/layout/style/res/Mozilla_Bullet.woff2) */
|
|
1538
|
+
@font-face {
|
|
1539
|
+
font-family: "-viv-moz-bullet";
|
|
1540
|
+
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");
|
|
1541
|
+
}
|
|
1542
|
+
[data-adapt-pseudo="marker"] {
|
|
1543
|
+
unicode-bidi: isolate;
|
|
1544
|
+
font-variant-numeric: tabular-nums;
|
|
1545
|
+
white-space: pre;
|
|
1546
|
+
text-transform: none;
|
|
1547
|
+
}
|
|
1548
|
+
[data-adapt-pseudo="marker"]._viv-marker-bullet {
|
|
1549
|
+
font-family: "-viv-moz-bullet";
|
|
1550
|
+
font-style: normal;
|
|
1551
|
+
font-weight: normal;
|
|
1552
|
+
}
|
|
1553
|
+
[data-adapt-pseudo="marker"]._viv-marker-outside {
|
|
1554
|
+
position: absolute;
|
|
1555
|
+
text-indent: 0;
|
|
1556
|
+
}
|
|
1557
|
+
[data-adapt-pseudo="marker"] > ._viv-marker-outside-content {
|
|
1558
|
+
position: absolute;
|
|
1559
|
+
inset-inline-end: 0;
|
|
1560
|
+
}
|
|
1561
|
+
`,vu=String.raw`
|
|
1562
|
+
@counter-style decimal-leading-zero {
|
|
1563
|
+
system: extends decimal;
|
|
1564
|
+
pad: 2 '0';
|
|
1565
|
+
}
|
|
1566
|
+
@counter-style arabic-indic {
|
|
1567
|
+
system: numeric;
|
|
1568
|
+
symbols: ٠ ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩;
|
|
1569
|
+
}
|
|
1570
|
+
@counter-style armenian {
|
|
1571
|
+
system: additive;
|
|
1572
|
+
range: 1 9999;
|
|
1573
|
+
additive-symbols: 9000 Ք, 8000 Փ, 7000 Ւ, 6000 Ց, 5000 Ր, 4000 Տ, 3000 Վ, 2000 Ս, 1000 Ռ, 900 Ջ, 800 Պ, 700 Չ, 600 Ո, 500 Շ, 400 Ն, 300 Յ, 200 Մ, 100 Ճ, 90 Ղ, 80 Ձ, 70 Հ, 60 Կ, 50 Ծ, 40 Խ, 30 Լ, 20 Ի, 10 Ժ, 9 Թ, 8 Ը, 7 Է, 6 Զ, 5 Ե, 4 Դ, 3 Գ, 2 Բ, 1 Ա;
|
|
1574
|
+
}
|
|
1575
|
+
@counter-style upper-armenian {
|
|
1576
|
+
system: extends armenian;
|
|
1577
|
+
}
|
|
1578
|
+
@counter-style lower-armenian {
|
|
1579
|
+
system: additive;
|
|
1580
|
+
range: 1 9999;
|
|
1581
|
+
additive-symbols: 9000 ք, 8000 փ, 7000 ւ, 6000 ց, 5000 ր, 4000 տ, 3000 վ, 2000 ս, 1000 ռ, 900 ջ, 800 պ, 700 չ, 600 ո, 500 շ, 400 ն, 300 յ, 200 մ, 100 ճ, 90 ղ, 80 ձ, 70 հ, 60 կ, 50 ծ, 40 խ, 30 լ, 20 ի, 10 ժ, 9 թ, 8 ը, 7 է, 6 զ, 5 ե, 4 դ, 3 գ, 2 բ, 1 ա;
|
|
1582
|
+
}
|
|
1583
|
+
@counter-style bengali {
|
|
1584
|
+
system: numeric;
|
|
1585
|
+
symbols: ০ ১ ২ ৩ ৪ ৫ ৬ ৭ ৮ ৯;
|
|
1586
|
+
}
|
|
1587
|
+
@counter-style cambodian {
|
|
1588
|
+
system: numeric;
|
|
1589
|
+
symbols: ០ ១ ២ ៣ ៤ ៥ ៦ ៧ ៨ ៩;
|
|
1590
|
+
}
|
|
1591
|
+
@counter-style khmer {
|
|
1592
|
+
system: extends cambodian;
|
|
1593
|
+
}
|
|
1594
|
+
@counter-style cjk-decimal {
|
|
1595
|
+
system: numeric;
|
|
1596
|
+
range: 0 infinite;
|
|
1597
|
+
symbols: 〇 一 二 三 四 五 六 七 八 九;
|
|
1598
|
+
suffix: "、";
|
|
1599
|
+
}
|
|
1600
|
+
@counter-style devanagari {
|
|
1601
|
+
system: numeric;
|
|
1602
|
+
symbols: ० १ २ ३ ४ ५ ६ ७ ८ ९;
|
|
1603
|
+
}
|
|
1604
|
+
@counter-style georgian {
|
|
1605
|
+
system: additive;
|
|
1606
|
+
range: 1 19999;
|
|
1607
|
+
additive-symbols: 10000 ჵ, 9000 ჰ, 8000 ჯ, 7000 ჴ, 6000 ხ, 5000 ჭ, 4000 წ, 3000 ძ, 2000 ც, 1000 ჩ, 900 შ, 800 ყ, 700 ღ, 600 ქ, 500 ფ, 400 ჳ, 300 ტ, 200 ს, 100 რ, 90 ჟ, 80 პ, 70 ო, 60 ჲ, 50 ნ, 40 მ, 30 ლ, 20 კ, 10 ი, 9 თ, 8 ჱ, 7 ზ, 6 ვ, 5 ე, 4 დ, 3 გ, 2 ბ, 1 ა;
|
|
1608
|
+
}
|
|
1609
|
+
@counter-style gujarati {
|
|
1610
|
+
system: numeric;
|
|
1611
|
+
symbols: ૦ ૧ ૨ ૩ ૪ ૫ ૬ ૭ ૮ ૯;
|
|
1612
|
+
}
|
|
1613
|
+
@counter-style gurmukhi {
|
|
1614
|
+
system: numeric;
|
|
1615
|
+
symbols: ੦ ੧ ੨ ੩ ੪ ੫ ੬ ੭ ੮ ੯;
|
|
1616
|
+
}
|
|
1617
|
+
@counter-style hebrew {
|
|
1618
|
+
system: additive;
|
|
1619
|
+
range: 1 10999;
|
|
1620
|
+
additive-symbols: 10000 \5D9\5F3, 9000 \5D8\5F3, 8000 \5D7\5F3, 7000 \5D6\5F3, 6000 \5D5\5F3, 5000 \5D4\5F3, 4000 \5D3\5F3, 3000 \5D2\5F3, 2000 \5D1\5F3, 1000 \5D0\5F3, 400 \5EA, 300 \5E9, 200 \5E8, 100 \5E7, 90 \5E6, 80 \5E4, 70 \5E2, 60 \5E1, 50 \5E0, 40 \5DE, 30 \5DC, 20 \5DB, 19 \5D9\5D8, 18 \5D9\5D7, 17 \5D9\5D6, 16 \5D8\5D6, 15 \5D8\5D5, 10 \5D9, 9 \5D8, 8 \5D7, 7 \5D6, 6 \5D5, 5 \5D4, 4 \5D3, 3 \5D2, 2 \5D1, 1 \5D0;
|
|
1621
|
+
}
|
|
1622
|
+
@counter-style kannada {
|
|
1623
|
+
system: numeric;
|
|
1624
|
+
symbols: ೦ ೧ ೨ ೩ ೪ ೫ ೬ ೭ ೮ ೯;
|
|
1625
|
+
}
|
|
1626
|
+
@counter-style lao {
|
|
1627
|
+
system: numeric;
|
|
1628
|
+
symbols: ໐ ໑ ໒ ໓ ໔ ໕ ໖ ໗ ໘ ໙;
|
|
1629
|
+
}
|
|
1630
|
+
@counter-style malayalam {
|
|
1631
|
+
system: numeric;
|
|
1632
|
+
symbols: ൦ ൧ ൨ ൩ ൪ ൫ ൬ ൭ ൮ ൯;
|
|
1633
|
+
}
|
|
1634
|
+
@counter-style mongolian {
|
|
1635
|
+
system: numeric;
|
|
1636
|
+
symbols: ᠐ ᠑ ᠒ ᠓ ᠔ ᠕ ᠖ ᠗ ᠘ ᠙;
|
|
1637
|
+
}
|
|
1638
|
+
@counter-style myanmar {
|
|
1639
|
+
system: numeric;
|
|
1640
|
+
symbols: ၀ ၁ ၂ ၃ ၄ ၅ ၆ ၇ ၈ ၉;
|
|
1641
|
+
}
|
|
1642
|
+
@counter-style oriya {
|
|
1643
|
+
system: numeric;
|
|
1644
|
+
symbols: ୦ ୧ ୨ ୩ ୪ ୫ ୬ ୭ ୮ ୯;
|
|
1645
|
+
}
|
|
1646
|
+
@counter-style persian {
|
|
1647
|
+
system: numeric;
|
|
1648
|
+
symbols: ۰ ۱ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹;
|
|
1649
|
+
}
|
|
1650
|
+
@counter-style lower-roman {
|
|
1651
|
+
system: additive;
|
|
1652
|
+
range: 1 3999;
|
|
1653
|
+
additive-symbols: 1000 m, 900 cm, 500 d, 400 cd, 100 c, 90 xc, 50 l, 40 xl, 10 x, 9 ix, 5 v, 4 iv, 1 i;
|
|
1654
|
+
}
|
|
1655
|
+
@counter-style upper-roman {
|
|
1656
|
+
system: additive;
|
|
1657
|
+
range: 1 3999;
|
|
1658
|
+
additive-symbols: 1000 M, 900 CM, 500 D, 400 CD, 100 C, 90 XC, 50 L, 40 XL, 10 X, 9 IX, 5 V, 4 IV, 1 I;
|
|
1659
|
+
}
|
|
1660
|
+
@counter-style tamil {
|
|
1661
|
+
system: numeric;
|
|
1662
|
+
symbols: ௦ ௧ ௨ ௩ ௪ ௫ ௬ ௭ ௮ ௯;
|
|
1663
|
+
}
|
|
1664
|
+
@counter-style telugu {
|
|
1665
|
+
system: numeric;
|
|
1666
|
+
symbols: ౦ ౧ ౨ ౩ ౪ ౫ ౬ ౭ ౮ ౯;
|
|
1667
|
+
}
|
|
1668
|
+
@counter-style thai {
|
|
1669
|
+
system: numeric;
|
|
1670
|
+
symbols: ๐ ๑ ๒ ๓ ๔ ๕ ๖ ๗ ๘ ๙;
|
|
1671
|
+
}
|
|
1672
|
+
@counter-style tibetan {
|
|
1673
|
+
system: numeric;
|
|
1674
|
+
symbols: ༠ ༡ ༢ ༣ ༤ ༥ ༦ ༧ ༨ ༩;
|
|
1675
|
+
}
|
|
1676
|
+
@counter-style lower-alpha {
|
|
1677
|
+
system: alphabetic;
|
|
1678
|
+
symbols: a b c d e f g h i j k l m n o p q r s t u v w x y z;
|
|
1679
|
+
}
|
|
1680
|
+
@counter-style lower-latin {
|
|
1681
|
+
system: extends lower-alpha;
|
|
1682
|
+
}
|
|
1683
|
+
@counter-style upper-alpha {
|
|
1684
|
+
system: alphabetic;
|
|
1685
|
+
symbols: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z;
|
|
1686
|
+
}
|
|
1687
|
+
@counter-style upper-latin {
|
|
1688
|
+
system: extends upper-alpha;
|
|
1689
|
+
}
|
|
1690
|
+
@counter-style lower-greek {
|
|
1691
|
+
system: alphabetic;
|
|
1692
|
+
symbols: α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ φ χ ψ ω;
|
|
1693
|
+
}
|
|
1694
|
+
@counter-style hiragana {
|
|
1695
|
+
system: alphabetic;
|
|
1696
|
+
symbols: あ い う え お か き く け こ さ し す せ そ た ち つ て と な に ぬ ね の は ひ ふ へ ほ ま み む め も や ゆ よ ら り る れ ろ わ ゐ ゑ を ん;
|
|
1697
|
+
suffix: "、";
|
|
1698
|
+
}
|
|
1699
|
+
@counter-style hiragana-iroha {
|
|
1700
|
+
system: alphabetic;
|
|
1701
|
+
symbols: い ろ は に ほ へ と ち り ぬ る を わ か よ た れ そ つ ね な ら む う ゐ の お く や ま け ふ こ え て あ さ き ゆ め み し ゑ ひ も せ す;
|
|
1702
|
+
suffix: "、";
|
|
1703
|
+
}
|
|
1704
|
+
@counter-style katakana {
|
|
1705
|
+
system: alphabetic;
|
|
1706
|
+
symbols: ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヰ ヱ ヲ ン;
|
|
1707
|
+
suffix: "、";
|
|
1708
|
+
}
|
|
1709
|
+
@counter-style katakana-iroha {
|
|
1710
|
+
system: alphabetic;
|
|
1711
|
+
symbols: イ ロ ハ ニ ホ ヘ ト チ リ ヌ ル ヲ ワ カ ヨ タ レ ソ ツ ネ ナ ラ ム ウ ヰ ノ オ ク ヤ マ ケ フ コ エ テ ア サ キ ユ メ ミ シ ヱ ヒ モ セ ス;
|
|
1712
|
+
suffix: "、";
|
|
1713
|
+
}
|
|
1714
|
+
@counter-style cjk-earthly-branch {
|
|
1715
|
+
system: fixed;
|
|
1716
|
+
symbols: 子 丑 寅 卯 辰 巳 午 未 申 酉 戌 亥;
|
|
1717
|
+
suffix: "、";
|
|
1718
|
+
fallback: cjk-decimal;
|
|
1719
|
+
}
|
|
1720
|
+
@counter-style cjk-heavenly-stem {
|
|
1721
|
+
system: fixed;
|
|
1722
|
+
symbols: 甲 乙 丙 丁 戊 己 庚 辛 壬 癸;
|
|
1723
|
+
suffix: "、";
|
|
1724
|
+
fallback: cjk-decimal;
|
|
1725
|
+
}
|
|
1726
|
+
@counter-style japanese-informal {
|
|
1727
|
+
system: additive;
|
|
1728
|
+
range: -9999 9999;
|
|
1729
|
+
additive-symbols: 9000 九千, 8000 八千, 7000 七千, 6000 六千, 5000 五千, 4000 四千, 3000 三千, 2000 二千, 1000 千, 900 九百, 800 八百, 700 七百, 600 六百, 500 五百, 400 四百, 300 三百, 200 二百, 100 百, 90 九十, 80 八十, 70 七十, 60 六十, 50 五十, 40 四十, 30 三十, 20 二十, 10 十, 9 九, 8 八, 7 七, 6 六, 5 五, 4 四, 3 三, 2 二, 1 一, 0 〇;
|
|
1730
|
+
suffix: "、";
|
|
1731
|
+
negative: マイナス;
|
|
1732
|
+
fallback: cjk-decimal;
|
|
1733
|
+
}
|
|
1734
|
+
@counter-style japanese-formal {
|
|
1735
|
+
system: additive;
|
|
1736
|
+
range: -9999 9999;
|
|
1737
|
+
additive-symbols: 9000 九阡, 8000 八阡, 7000 七阡, 6000 六阡, 5000 伍阡, 4000 四阡, 3000 参阡, 2000 弐阡, 1000 壱阡, 900 九百, 800 八百, 700 七百, 600 六百, 500 伍百, 400 四百, 300 参百, 200 弐百, 100 壱百, 90 九拾, 80 八拾, 70 七拾, 60 六拾, 50 伍拾, 40 四拾, 30 参拾, 20 弐拾, 10 壱拾, 9 九, 8 八, 7 七, 6 六, 5 伍, 4 四, 3 参, 2 弐, 1 壱, 0 零;
|
|
1738
|
+
suffix: "、";
|
|
1739
|
+
negative: マイナス;
|
|
1740
|
+
fallback: cjk-decimal;
|
|
1741
|
+
}
|
|
1742
|
+
@counter-style korean-hangul-formal {
|
|
1743
|
+
system: additive;
|
|
1744
|
+
range: -9999 9999;
|
|
1745
|
+
additive-symbols: 9000 구천, 8000 팔천, 7000 칠천, 6000 육천, 5000 오천, 4000 사천, 3000 삼천, 2000 이천, 1000 일천, 900 구백, 800 팔백, 700 칠백, 600 육백, 500 오백, 400 사백, 300 삼백, 200 이백, 100 일백, 90 구십, 80 팔십, 70 칠십, 60 육십, 50 오십, 40 사십, 30 삼십, 20 이십, 10 일십, 9 구, 8 팔, 7 칠, 6 육, 5 오, 4 사, 3 삼, 2 이, 1 일, 0 영;
|
|
1746
|
+
suffix: ', ';
|
|
1747
|
+
negative: "마이너스 ";
|
|
1748
|
+
fallback: cjk-decimal;
|
|
1749
|
+
}
|
|
1750
|
+
@counter-style korean-hanja-informal {
|
|
1751
|
+
system: additive;
|
|
1752
|
+
range: -9999 9999;
|
|
1753
|
+
additive-symbols: 9000 九千, 8000 八千, 7000 七千, 6000 六千, 5000 五千, 4000 四千, 3000 三千, 2000 二千, 1000 千, 900 九百, 800 八百, 700 七百, 600 六百, 500 五百, 400 四百, 300 三百, 200 二百, 100 百, 90 九十, 80 八十, 70 七十, 60 六十, 50 五十, 40 四十, 30 三十, 20 二十, 10 十, 9 九, 8 八, 7 七, 6 六, 5 五, 4 四, 3 三, 2 二, 1 一, 0 零;
|
|
1754
|
+
suffix: ', ';
|
|
1755
|
+
negative: "마이너스 ";
|
|
1756
|
+
fallback: cjk-decimal;
|
|
1757
|
+
}
|
|
1758
|
+
@counter-style korean-hanja-formal {
|
|
1759
|
+
system: additive;
|
|
1760
|
+
range: -9999 9999;
|
|
1761
|
+
additive-symbols: 9000 九仟, 8000 八仟, 7000 七仟, 6000 六仟, 5000 五仟, 4000 四仟, 3000 參仟, 2000 貳仟, 1000 壹仟, 900 九百, 800 八百, 700 七百, 600 六百, 500 五百, 400 四百, 300 參百, 200 貳百, 100 壹百, 90 九拾, 80 八拾, 70 七拾, 60 六拾, 50 五拾, 40 四拾, 30 參拾, 20 貳拾, 10 壹拾, 9 九, 8 八, 7 七, 6 六, 5 五, 4 四, 3 參, 2 貳, 1 壹, 0 零;
|
|
1762
|
+
suffix: ', ';
|
|
1763
|
+
negative: "마이너스 ";
|
|
1764
|
+
fallback: cjk-decimal;
|
|
1765
|
+
}
|
|
1766
|
+
`+`
|
|
1767
|
+
@counter-style lower-armenian {
|
|
1768
|
+
system: additive;
|
|
1769
|
+
range: 1 9999;
|
|
1770
|
+
additive-symbols: 9000 \u0584, 8000 \u0583, 7000 \u0582, 6000 \u0581, 5000 \u0580, 4000 \u057F, 3000 \u057E, 2000 \u057D, 1000 \u057C, 900 \u057B, 800 \u057A, 700 \u0579, 600 \u0578, 500 \u0577, 400 \u0576, 300 \u0575, 200 \u0574, 100 \u0573, 90 \u0572, 80 \u0571, 70 \u0570, 60 \u056F, 50 \u056E, 40 \u056D, 30 \u056C, 20 \u056B, 10 \u056A, 9 \u0569, 8 \u0568, 7 \u0567, 6 \u0566, 5 \u0565, 4 \u0564, 3 \u0563, 2 \u0562, 1 \u0561;
|
|
1771
|
+
}
|
|
1772
|
+
@counter-style upper-armenian {
|
|
1773
|
+
system: additive;
|
|
1774
|
+
range: 1 9999;
|
|
1775
|
+
additive-symbols: 9000 \u0554, 8000 \u0553, 7000 \u0552, 6000 \u0551, 5000 \u0550, 4000 \u054F, 3000 \u054E, 2000 \u054D, 1000 \u054C, 900 \u054B, 800 \u054A, 700 \u0549, 600 \u0548, 500 \u0547, 400 \u0546, 300 \u0545, 200 \u0544, 100 \u0543, 90 \u0542, 80 \u0541, 70 \u0540, 60 \u053F, 50 \u053E, 40 \u053D, 30 \u053C, 20 \u053B, 10 \u053A, 9 \u0539, 8 \u0538, 7 \u0537, 6 \u0536, 5 \u0535, 4 \u0534, 3 \u0533, 2 \u0532, 1 \u0531;
|
|
1776
|
+
}
|
|
1777
|
+
@counter-style lower-russian {
|
|
1778
|
+
system: alphabetic;
|
|
1779
|
+
symbols: \u0430 \u0431 \u0432 \u0433 \u0434 \u0435 \u0436 \u0437 \u0438 \u043A \u043B \u043C \u043D \u043E \u043F \u0440 \u0441 \u0442 \u0443 \u0444 \u0445 \u0446 \u0447 \u0448 \u0449 \u044D \u044E \u044F;
|
|
1780
|
+
suffix: ') ';
|
|
1781
|
+
}
|
|
1782
|
+
@counter-style upper-russian {
|
|
1783
|
+
system: alphabetic;
|
|
1784
|
+
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;
|
|
1785
|
+
}`;function er(e,t,i){let n=B("fetchFromURL"),s={method:i||"GET",mode:"cors"},r=n.suspend(),o={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(e,s).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=xu([a]):t==="json"?o.responseText=JSON.stringify(a):typeof a=="string"&&(o.responseText=a),r.schedule(o)}).catch(a=>{H.warn(a,`Error fetching ${e}`),r.schedule(o)}),n.result()}function xu(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Wf(e){let t=B("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function Gf(e){return URL.createObjectURL(e)}var ia=class{constructor(e,t){this.parser=e,this.type=t,c(this,"resources",{}),c(this,"fetchers",{})}load(e,t,i){e=Dt(e);let n=this.resources[e];return typeof n<"u"?N(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=B("fetch"),s=e.endsWith("?viv-toc-box");s&&(e=e.replace("?viv-toc-box",""));let r=Ne("user-agent.xml",Qt),o=!s&&e===r;return o&&(e=`data:application/xml,${encodeURIComponent(gu)}`),er(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:""})`);s?(e+="?viv-toc-box",a.url+="?viv-toc-box"):o&&(a.url=e=r),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=Dt(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new $n(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[Dt(e)]}delete(e){delete this.resources[Dt(e)]}};function jf(e,t){let i=e.responseText;return N(i?Xo(i):null)}function Xf(){return new ia(jf,"text")}function Ei(e,t,i){let n=new $n(()=>{let s=B("loadElement"),r=s.suspend(e),o=!1,a=null,l=h=>{o||(o=!0,a!==null&&(clearTimeout(a),a=null),r.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 s.result()},`loadElement ${t||e.localName}`);return n.start(),n}var pl=0,qf=16777216,Su=33554432,Cu=50331648,ku=67108864,Yf=83886080,Kf=100663296,na=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){}endFuncWithSelector(){}pushSelectorText(e){}getImportantSpecificity(){switch(this.flavor){case"UA":return pl;case"User":return Kf;default:return Yf}}getBaseSpecificity(){switch(this.flavor){case"UA":return pl;case"User":return qf;default:return Su}}},Zf=class extends na{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;H.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){this.slave.startFuncWithSelector(e)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},fl=class extends na{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()}},Wn=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){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=[],Rs=[],ye=[],Ie=[],xt=[],ut=[],Te=[],Ve=[],ge=[],Ge=[],Qe=[],We=[],Pe=[],Ni=55,Pi=56,ns=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,Rs[1]=46,Rs[0]=200,ut[1]=2,ut[36]=4,ut[7]=6,ut[9]=8,ut[14]=10,ut[18]=14,ut[50]=42,ye[37]=11,ye[23]=12,ye[35]=56,ye[1]=1,ye[36]=3,ye[7]=5,ye[9]=7,ye[14]=9,ye[12]=13,ye[18]=55,ye[50]=58,ye[16]=41,Ie[37]=11,Ie[23]=12,Ie[35]=56,Ie[1]=1,Ie[36]=3,Ie[7]=5,Ie[9]=7,Ie[14]=9,Ie[18]=55,xt[1]=2,xt[36]=4,xt[7]=6,xt[9]=8,xt[18]=14,xt[50]=42,xt[14]=10,xt[12]=13,Te[1]=15,Te[7]=16,Te[4]=17,Te[5]=18,Te[3]=19,Te[2]=20,Te[8]=21,Te[27]=57,Te[16]=22,Te[19]=23,Te[6]=24,Te[11]=25,Te[17]=26,Te[13]=48,Te[31]=47,Te[23]=54,Te[0]=44,Ve[1]=31,Ve[4]=32,Ve[5]=32,Ve[3]=33,Ve[2]=34,Ve[10]=40,Ve[6]=38,Ve[31]=36,Ve[24]=36,Ve[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,Ge[0]=200,Ge[12]=50,Ge[13]=51,Ge[14]=50,Ge[15]=51,Ge[10]=50,Ge[11]=51,Ge[17]=53,Qe[0]=200,Qe[12]=50,Qe[13]=52,Qe[14]=50,Qe[15]=51,Qe[10]=50,Qe[11]=51,Qe[17]=53,We[0]=200,We[12]=50,We[13]=51,We[14]=50,We[15]=51,We[10]=50,We[11]=51,Pe[11]=0,Pe[16]=0,Pe[22]=1,Pe[18]=1,Pe[26]=2,Pe[25]=2,Pe[38]=3,Pe[37]=3,Pe[48]=3,Pe[47]=3,Pe[39]=3,Pe[49]=3,Pe[41]=3,Pe[23]=4,Pe[24]=4,Pe[36]=5,Pe[19]=5,Pe[21]=5,Pe[0]=6,Pe[Ni]=2,Pe[Pi]=2;var Gn=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(j)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,s=0,r;do if(r=i[--n],e===")"&&r instanceof ki){if(r.text===")")s++;else if(r.text==="("){if(s===0)return null;s--}}while(typeof r<"u"&&typeof r!="string");let o=i.length-(n+1);if(o>1&&i.splice(n+1,o,new Q(i.slice(n+1,i.length))),e==",")return null;n++;do r=i[--n];while(typeof r<"u"&&(typeof r!="string"||r==","));if(o=i.length-(n+1),r=="("){e!=")"&&t.type!==0&&(this.handler.error("E_CSS_MISMATCHED_C_PAR",t),this.actions=Qe);let l=new Ji(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,o+2,l),l.name==="var"){let h=l.values[0]instanceof ae&&l.values[0].name;(!$t(h)||h===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${l.toString()}`,t),this.actions=Qe)}return l}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=Qe,null;if(o>1)return new qe(this.extractVals(",",n+1));let a=i[0];return a instanceof Ye?a:a?new ki(a.toString()):j}exprError(e,t){this.actions=this.propName?Qe:Ge,H.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,s=i.pop(),r;for(;;){let o=i.pop();if(e==11){let a=[s];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 Op(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();s=new wn(n.getScope(),zr(h,l),a),e=0;continue}}if(o==10){s.isMediaName()&&(s=new el(n.getScope(),s,null)),e=0;continue}}else if(typeof o=="string"){i.push(o);break}if(o<0)if(o==-31)s=new ti(n.getScope(),s);else if(o==-24)s=new Ai(n.getScope(),s);else if(o==-ns)s=new Lp(n.getScope(),s);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(Pe[e]>Pe[o]){i.push(o);break}switch(r=i.pop(),o){case 26:s=new Ko(n.getScope(),r,s);break;case Ni:s=new Bp(n.getScope(),r,s);break;case Pi:s=new _p(n.getScope(),r,s);break;case 25:s=new Zo(n.getScope(),r,s);break;case 38:s=new Mp(n.getScope(),r,s);break;case 37:s=new Dp(n.getScope(),r,s);break;case 48:s=new zp(n.getScope(),r,s);break;case 47:s=new Ur(n.getScope(),r,s);break;case 39:case 49:s=new Jo(n.getScope(),r,s);break;case 41:s=new Vp(n.getScope(),r,s);break;case 23:s=new Hh(n.getScope(),r,s);break;case 24:s=new $h(n.getScope(),r,s);break;case 36:s=new Qo(n.getScope(),r,s);break;case 19:s=new Wh(n.getScope(),r,s);break;case 21:s=new Gh(n.getScope(),r,s);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),s=new $p(n.getScope(),i.pop(),r,s);break;case 10:if(r.isMediaName())s=new el(n.getScope(),r,s);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(r),i.push(o),i.push(s),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(s),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,s;if(t)s=e.text,n=e.position+s.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(),s=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 r=0,o,a=0;for(;r>=0;)switch(i.consume(),o=i.token(),o.type){case 11:r--;break;case 10:case 6:r++;break;case 16:r===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",o),null}i.consume();let l=o.position,h=t&&s==="selector"&&a>0?"":i.input.substring(n,l).trim();return new Wp(this.handler.getScope(),s,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 s=t.type===24,r=t.type===23||s;if(r&&(this.tokenizer.consume(),t=this.tokenizer.token()),t.type===5){if(n=t.num,1/n===-1/0){if(n=0,r)return null}else if(n<0){if(r)return null}else if(n>=0&&!r)return null;this.tokenizer.consume()}else if(r)return null;return[i,s&&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 s of n)switch(s){case"vertical":t=Ct(i,t,new ti(i,new ze(i,"pref-horizontal")));break;case"horizontal":t=Ct(i,t,new ze(i,"pref-horizontal"));break;case"day":t=Ct(i,t,new ti(i,new ze(i,"pref-night-mode")));break;case"night":t=Ct(i,t,new ze(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,s,r){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(),s&&w===null&&(w=h.position-1,a.input[w]==="("&&w++),this.actions===Te&&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 ki(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=Qe):(this.actions=ut,o.startSelectorRule());continue}this.propName=h.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Te,l.splice(0,l.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=Qe,o.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=h.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Te,l.splice(0,l.length);continue;case 29:this.actions=ut,o.startSelectorRule();continue;case 1:if(!h.precededBySpace){this.actions=We,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),s?this.actions=Ie:this.actions=ye,a.consume();break;case 36:o.tagSelector(d,null),s?this.actions=Ie:this.actions=ye,a.consume();break;default:this.actions=Ge,o.error("E_CSS_NAMESPACE",h)}else this.actions=Ge,o.error("E_CSS_UNDECLARED_PREFIX",h);else o.tagSelector(this.defaultNamespaceURI,h.text),s?this.actions=Ie:this.actions=ye,a.consume();continue;case 3:if(!h.precededBySpace){this.actions=We,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),s?this.actions=Ie:this.actions=ye,a.consume();break;case 36:o.tagSelector(null,null),s?this.actions=Ie:this.actions=ye,a.consume();break;default:this.actions=Ge,o.error("E_CSS_NAMESPACE",h)}else o.tagSelector(this.defaultNamespaceURI,null),s?this.actions=Ie:this.actions=ye,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),s?this.actions=Ie:this.actions=ye,a.consume();continue;case 7:h.precededBySpace&&o.descendantSelector();case 8:o.classSelector(h.text),s?this.actions=Ie:this.actions=ye,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(),s?this.actions=Ie:this.actions=ye;continue;case 6:switch(p=h.text,a.consume(),p){case"is":case"not":case"where":case"has":this.actions=ut,o.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=ye:this.actions=We;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)break;break e;default:g=this.readPseudoParams()}if(h=a.token(),h.type==11){o.pseudoclassSelector(p,g),a.consume(),s?this.actions=Ie:this.actions=ye;continue}break}o.error("E_CSS_PSEUDOCLASS_SYNTAX",h),this.actions=Ge;continue;case 58:h.precededBySpace&&o.descendantSelector();case 42:switch(a.consume(),h=a.token(),h.type){case 1:o.pseudoelementSelector(h.text,null),s?this.actions=Ie:this.actions=ye,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),s?this.actions=Ie:this.actions=ye,a.consume();continue}break}o.error("E_CSS_PSEUDOELEM_SYNTAX",h),this.actions=Ge;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=We,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=We,o.error("E_CSS_UNDECLARED_PREFIX",h),a.consume();continue}if(a.consume(),h=a.token(),h.type!=1){this.actions=We,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),s?this.actions=Ie:this.actions=ye,a.consume();continue;default:this.actions=We,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=We,o.error("E_CSS_ATTR_VAL_EXPECTED",h);continue}if(h.type!=15){this.actions=We,o.error("E_CSS_ATTR",h);continue}s?this.actions=Ie:this.actions=ye,a.consume();continue;case 11:o.childSelector(),this.actions=xt,a.consume();continue;case 12:o.adjacentSiblingSelector(),this.actions=xt,a.consume();continue;case 56:o.followingSiblingSelector(),this.actions=xt,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=ut,a.consume();continue;case 15:l.push(F(h.text)),a.consume();continue;case 16:f=parseInt(h.text,16),l.push(new eu(h.text)),a.consume();continue;case 17:l.push(new Ht(h.num)),a.consume();continue;case 18:l.push(new Re(h.num)),a.consume();continue;case 19:l.push(new A(h.num,h.text)),a.consume();continue;case 20:l.push(new G(h.text)),a.consume();continue;case 21:l.push(new Ke(Ne(h.text,this.baseURL))),a.consume();continue;case 57:l.push(new tu(h.text)),a.consume();continue;case 22:this.valStackReduce(",",h),l.push(","),a.consume();continue;case 23:l.push(Ks),a.consume();continue;case 24:p=h.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=Ve,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 ki("+")),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?Rs: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 ze(o.getScope(),zr(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 Qa(o.getScope(),!0,u.text))):(h.text.toLowerCase()=="only"&&(a.consume(),h=u),l.push(new Qa(o.getScope(),!1,h.text)));else if(this.exprContext===4&&h.text.toLowerCase()==="not"&&l[l.length-1]!==Ni&&l[l.length-1]!==Pi&&(u.type===10||u.type===6)){l.push(-ns),a.consume();continue}else l.push(new ze(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 He(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 Vn(o.getScope(),h.num,p)),a.consume(),this.actions=ge;continue;case 34:l.push(new He(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 Yh(o.getScope(),h.num)),a.consume(),this.actions=ge);continue;case 36:l.push(-h.type),a.consume();continue;case 37:this.actions=Ve,this.exprStackReduce(h.type,h),l.push(h.type),a.consume();continue;case 45:h.text.toLowerCase()==="and"&&l[l.length-2]!==Pi&&l[l.length-2]!==-ns?(this.actions=Ve,this.exprStackReduce(Ni,h),l.push(Ni),a.consume()):h.text.toLowerCase()==="or"&&l[l.length-2]!==Ni&&l[l.length-2]!==-ns?(this.actions=Ve,this.exprStackReduce(Pi,h),l.push(Pi),a.consume()):this.exprError("E_CSS_SYNTAX",h);continue;case 39:this.exprStackReduce(h.type,h)&&(this.actions=Te),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=Ve,l.push("{");continue}o.error("E_CSS_IMPORT_SYNTAX",h),this.actions=Ge;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=Ge;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=Ge;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=ut;continue;case"page":a.consume(),o.startPageRule(),this.pageRule=!0,this.actions=xt;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=Ve,l.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Ve,l.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Ve,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=We;continue;default:o.error(`E_CSS_AT_UNKNOWN ${p}`,h),this.actions=Ge;continue}o.error(`E_CSS_AT_SYNTAX ${p}`,h),this.actions=Ge;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(s&&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(s){switch(h.type){case 16:case 11:if(this.actions===ut)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=ut,a.consume();continue}else return o.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(r){this.actions=ye;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=We;continue}if(this.actions!==Ge&&this.actions!==We&&this.actions!==Qe){if(h.type==54)o.error("E_CSS_SYNTAX",h);else if(this.actions===Te){switch(h.type){case 10:case 12:case 14:this.errorBrackets.push(h.type+1);break}l.push(new ki(h.toString())),a.consume();continue}else if(h.type===12&&this.actions==Ve&&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==Ve)return this.actions=Ae,a.consume(),!1;o.error("E_CSS_SYNTAX",h)}this.isInsidePropertyOnlyRule()?this.actions=Qe:this.actions=We;continue}a.consume();continue}}return!1}},Eu=class extends na{constructor(e){super(null),this.scope=e}error(e,t){H.warn(e,t.toString())}getScope(){return this.scope}};function Jf(e,t,i,n,s){let r=B("parseStylesheet"),o=new Gn(Ae,e,t,i),a=null;return s&&(a=eg(new Rt(s,t),t,i)),a=o.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),r.loop(()=>{for(;!o.runParser(100,!1,!1,!1,!1);){if(o.importReady){let h=Ne(o.importURL,i);o.importCondition&&(t.startMediaRule(o.importCondition),t.startRuleBody());let u=B("parseStylesheet.import");return Nu(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=r.timeSlice();if(l.isPending)return l}return N(!1)}).then(()=>{a&&t.endRule(),r.finish(!0)}),r.result()}function sa(e,t,i,n,s){return Gi("parseStylesheetFromText",r=>{let o=new Rt(e,t);Jf(o,t,i,n,s).thenFinish(r)},(r,o)=>{H.warn(o,`Failed to parse stylesheet text: ${e}`),r.finish(!1)})}function Nu(e,t,i,n){return Gi("parseStylesheetFromURL",s=>{er(e).then(r=>{r.responseText?sa(r.responseText,t,e,i,n).then(o=>{o||H.warn(`Failed to parse stylesheet from ${e}`),s.finish(!0)}):s.finish(!0)})},(s,r)=>{H.warn(r,"Exception while fetching and parsing:",e),s.finish(!0)})}function Qi(e,t,i){let n=new Gn(Te,t,new Eu(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function Qf(e,t,i){new Gn(Rs,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function eg(e,t,i){let n=new Gn(Ve,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var tg={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function ig(e){return!!tg[e]}function ng(e,t,i){if(t instanceof Me&&t.str==="viv-leader")return new U(t);let n=t.evaluate(e);switch(typeof n){case"number":return ig(i)?n==Math.round(n)?new Re(n):new Ht(n):new A(n,"px");case"string":return n?Qi(t.scope,new Rt(n,null),""):j;case"boolean":return n?b._true:b._false;case"undefined":return j}throw new Error("E_UNEXPECTED")}function Pu(e,t){let i={};return Object.keys(e).forEach(n=>{let s=i[n]={},r=e[n];Object.keys(r).forEach(o=>{s[o]=r[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 Tu(e,t,i,n){let s=n[t];if(!s)throw new Error(`unknown writing-mode: ${t}`);let r=s[i||"ltr"];if(!r)throw new Error(`unknown direction: ${i}`);for(let o of r){let a=e.replace(o.regexp,o.to);if(a!==e)return a}return e}var Iu={"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"}]}},sg=Pu(Iu,!0);function Au(e,t,i){return Tu(e,t,i||null,sg)}var rg=Pu(Iu,!1);function Ru(e,t,i){return Tu(e,t,i||null,rg)}var og={"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 ag(e,t){let i=og[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 ra(e,t,i){var n;let s=t,r={width:s.style.width,height:s.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){s.style[p]=f;let m=o(p);return s.style[p]=r[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 ln(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 Fu(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function Lu(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function ft(e,t){let i=Fu(e);i.includes(t)||(i.push(t),Lu(e,i))}function lg(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function hg(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function kr(e,t){let i=lg(e);i.includes(t)||(i.push(t),hg(e,i))}function ug(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 Yr={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function et(e){return!!Yr[e]}var cg={left:!0,right:!0,recto:!0,verso:!0};function An(e){return!!cg[e]}var dg={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Fs(e){return!!dg[e]}function it(e,t){if(e)if(t){if(An(t))return t;if(An(e))return e;{let i=et(e),n=et(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:Fs(t)?t:Fs(e)?e:t}}else return e;else return t}function gl(e){return et(e)?e:"auto"}kt("SIMPLE_PROPERTY",ug);var yn=ap(hp());function pg(e,t){return(0,yn.default)(e,t,0)}function ml(e){return e.reduce((t,i)=>i[0]===yn.default.DELETE?t:t+i[1],"")}function fg(e,t){return Bu(e,t,1)}function gg(e,t){return Bu(e,t,-1)}function Bu(e,t,i){let n=0,s=0;return e.some(r=>{for(let o=0;o<r[1].length;o++){switch(r[0]*i){case yn.default.INSERT:n++;break;case yn.default.DELETE:n--,s++;break;case yn.default.EQUAL:s++;break}if(s>t)return!0}return!1}),Math.max(Math.min(t,s-1)+n,0)}var Kr;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(Kr||(Kr={}));var zi;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(zi||(zi={}));var Ls;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Ls||(Ls={}));var wi;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||si.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||si.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(wi||(wi={}));var si;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(si||(si={}));var Wt;(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={}))})(Wt||(Wt={}));var mg={transform:!0,"transform-origin":!0},wg={top:!0,bottom:!0,left:!0,right:!0},oa=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},bg={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 yg(e,t){let i=bg[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Zr=class hn extends qo{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 s=n.currentTarget,r=s.getAttribute("href")||s.getAttributeNS("http://www.w3.org/1999/xlink","href");if(r){let o={type:"hyperlink",target:null,currentTarget:null,anchorElement:s,href:r,preventDefault(){n.preventDefault()}};this.dispatchEvent(o)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute(hn.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(hn.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(hn.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(hn.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(r=>{let o=this.elementsById[r];for(let a=0;a<o.length;)this.container.contains(o[a])?a++:o.splice(a,1);o.length===0&&delete this.elementsById[r]});let n=this.delayedItems;for(let r=0;r<n.length;r++){let o=n[r];o.target===this.container&&o.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||T(o.target,o.name,o.value.toString())}let s=i.getElementClientRect(this.container);this.dimensions.width=s.width,this.dimensions.height=s.height;for(let r=0;r<t.length;r++){let o=t[r],a=this.elementsById[o.ref],l=this.elementsById[o.observer];if(a&&l){let h=yg(a,o.action);if(h)for(let u=0;u<l.length;u++)l[u].addEventListener(o.event,h,!1)}}}};c(Zr,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),c(Zr,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var Ou=Zr,ot=Wt.Whitespace;function _u(e){switch(e){case"normal":case"nowrap":return ot.IGNORE;case"pre-line":return ot.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return ot.PRESERVE;default:return null}}function Ue(e,t){if(!e)return!0;if(e.nodeType==1)return!1;let i=e.textContent;switch(t){case ot.PRESERVE:return i.length==0;case ot.NEWLINE:return!!i.match(/^[ \t]*$/);case ot.IGNORE:default:return!!i.match(/^[ \t\r\n\f]*$/)}}var vg=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,c(this,"forcedBreakOffsets",[]),c(this,"formattingContext",null)}},xg=class{constructor(e,t,i,n,s,r,o,a,l){this.flowName=e,this.element=t,this.startOffset=i,this.priority=n,this.linger=s,this.exclusive=r,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 Sg(e,t){return e.top-t.top}function Cg(e,t){return t.right-e.right}function Mu(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===Wt.ShadowType.ROOTLESS&&t.shadowType===Wt.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&Qr(e.shadowContext,t.shadowContext)&&Qr(e.nodeShadow,t.nodeShadow)&&Mu(e.shadowSibling,t.shadowSibling)}function ri(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(!Mu(e.steps[i],t.steps[i]))return!1;return!0}function kg(e){return{steps:[{node:e,shadowType:vt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function Bs(e,t){return{steps:[{node:e.sourceNode,shadowType:vt.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function Os(e,t){let i=new un(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?Os(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var vt=Wt.ShadowType,Jr=class{constructor(e,t,i,n,s,r,o){this.owner=e,this.root=t,this.xmldoc=i,this.parentShadow=n,this.type=r,this.styler=o,c(this,"subShadow",null),s&&(s.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&Qr(this.parentShadow,e.parentShadow):!1}};function Qr(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Eg=class{constructor(e,t){this.outer=e,this.count=t}},un=class zu{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=vt.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=zi.FloatReference.INLINE,this.whitespace=i?i.whitespace:ot.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=zi.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:ot.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 zu(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 s=this,r=[];s.shadowType===Wt.ShadowType.ROOTLESS&&(s.floatReference!==zi.FloatReference.INLINE||s.floatSide==="footnote")&&(n=(i=(t=s.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(s=s.parent);do(!s.firstPseudo||!s.parent||s.parent.firstPseudo===s.firstPseudo)&&r.push(s.toNodePositionStep()),s=s.parent;while(s);let o=this.preprocessedTextContent?gg(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:r,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}},oi=class Du{constructor(t){this.primary=t,c(this,"floats",null)}clone(){let t=new Du(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(!ri(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(!ri(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},Ng=class Vu{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new Vu(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Pg=class Uu{constructor(){c(this,"positions",[]),c(this,"startBreakType",null),c(this,"breakAfter",null)}clone(){let t=new Uu,i=this.positions,n=t.positions;for(let s=0;s<i.length;s++)n[s]=i[s].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}},Tg=class Hu{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 Hu;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 s of i)if(!this.flowPositions[s].isSamePosition(t.flowPositions[s]))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&&An(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},$u=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):ta(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 au(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)}},_s=class extends Xt{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 Ke)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 ze&&(i=Qi(t.scope,new Rt(i,null),"").stringValue()),this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof Me&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function Ot(e){return e!=null&&e!==j&&e!==b.normal&&e!==b.none&&!J(e)}var Fe=zi.FloatReference;function Ig(e){switch(e){case"inline":return Fe.INLINE;case"column":return Fe.COLUMN;case"region":return Fe.REGION;case"page":return Fe.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function Di(e){switch(e){case Fe.INLINE:return!1;case Fe.COLUMN:case Fe.REGION:case Fe.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function wl(e,t,i,n){let s=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=Ru(e,s,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let r=Au(e,s,i),o=ag(r,s);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"&&(H.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var Wu=class{constructor(e,t,i,n,s,r){this.nodePosition=e,this.floatReference=t,this.floatSide=i,this.clearSide=n,this.flowName=s,this.floatMinWrapBlock=r,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}},Ag=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=>ri(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=>ri(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}},Gu=class{constructor(e,t,i,n,s,r){this.floatReference=e,this.floatSide=t,this.clearSide=i,this.continuations=n,this.area=s,this.continues=r}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}},bl=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&ri(this.nodePosition,e.nodePosition):!1}},cn=class{constructor(e,t,i,n,s,r,o){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=s,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=r||e&&e.writingMode||b.horizontal_tb,this.direction=o||e&&e.direction||b.ltr,this.floatStore=e?e.floatStore:new Ag;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 s=this.children.indexOf(e);s<0&&(s=this.children.length);for(let r=s-1;r>=0;r--){let o=this.children[r];if(o.floatReference===t&&o.flowName===i&&ri(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 ji().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,s)=>n.getOrder()-s.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 s=this.floatFragments.splice(n,1)[0],r=s.area&&s.area.element;r&&r.parentNode&&r.parentNode.removeChild(r),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(s=>{let r=s.float,o=r.getOrder();o>t&&(!i||o>i.getOrder())&&(i=r)})}),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(s=>s.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===Fe.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(s=>s.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(s=>!i.isAllowedToPrecede(s)&&n>s.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let s=this.findPageFloatFragment(i);this.removePageFloatFragment(s)}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 Ru(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return Au(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=[],s=!1,r=!1;for(let o=0;o<i.length;o++){let a=i[o];a.includes("block")?s||(i.slice(o+1).some(l=>l.includes("block"))?(n.push("snap-block"),s=!0):n.push(a)):a.includes("inline")&&(r||(i.slice(o+1).some(l=>l.includes("inline"))?(n.push("snap-inline"),r=!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 s=this.floatFragments[n],r=this.toLogicalFloatSides(s.floatSide)[0];(r===i||i==="snap-block"&&r==="block-end"||i==="snap-inline"&&r==="inline-end")&&s.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(s),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,s){this.container;let r=this.toLogical(e),o=this.toPhysical(e),a=t&&this.toLogical(t),l=t&&this.toPhysical(t),h=this.getLimitValueInner(r,a,i,n,s);if(this.parent&&this.parent.container){let u=this.parent.getLimitValue(o,l,i,n,s);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,s){this.container;let r=this.getLimitValuesInner(i,n,s,e,t);switch(e){case"block-start":return this.container.vertical?r.right:r.top;case"block-end":return this.container.vertical?r.left:r.bottom;case"inline-start":return this.container.vertical?this.container.rtl?r.bottom:r.top:this.container.rtl?r.right:r.left;case"inline-end":return this.container.vertical?this.container.rtl?r.top:r.bottom:this.container.rtl?r.left:r.right;default:throw new Error(`Unknown logical side: ${e}`)}}getLimitValuesInner(e,t,i,n,s){this.container;let r=this.container.originX,o=this.container.originY,a=this.container.getPaddingRect(),l={top:a.y1-o,left:a.x1-r,bottom:a.y2-o,right:a.x2-r,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||s&&m.includes("block")===s.includes("block")&&m!==s))return d;let g=p.area,w=p.continuations[0].float.floatMinWrapBlock,v=d.top,y=d.left,C=d.bottom,E=d.right,I=d.floatMinWrapBlockStart,V=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&&(I=h(w,g.rootViewNodes[0],a.x2-a.x1)),E=Math.min(E,g.left)):(w&&g.top+g.height>v&&(I=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&&(V=h(w,g.rootViewNodes[0],a.x2-a.x1)),y=Math.max(y,g.left+g.width)):(w&&g.top<C&&(V=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:I,floatMinWrapBlockEnd:V}},l)),l.left+=r,l.right+=r,l.top+=o,l.bottom+=o,l}setFloatAreaDimensions(e,t,i,n,s,r,o){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,s,r,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(I=>I.includes("inline")&&o[I==="inline-start"?"inline-end":"inline-start"]),h=a.find(I=>I.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(I,V){let D=I(e.bands,V);return D?(e.vertical&&(D=su(D)),u=e.vertical?Math.min(u,D.x2):Math.max(u,D.y1),d=e.vertical?Math.max(d,D.x1):Math.min(d,D.y2),!0):r}let v,y,C,E;if(s){let I=e.vertical?As(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(Qp,I)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(ef,I)||(C=(d-u)*e.getBoxDir(),v=C-e.getInsetBefore()-e.getInsetAfter(),E=(f-p)*e.getInlineDir(),y=E-e.getInsetStart()-e.getInsetEnd(),!r&&(v<=0||y<=0)))return null}else{v=e.computedBlockSize,C=v+e.getInsetBefore()+e.getInsetAfter();let I=(d-u)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let D=this.container.getPaddingRect(),te=this.container.getBoxDir()*(n-(this.container.vertical?D.x2:D.y1)),re=this.container.getBoxDir()*((this.container.vertical?D.x1:D.y2)-n-C);te<=re?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(!r&&I<C)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?y=ra(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 V=(f-p)*e.getInlineDir();if(!r&&V<E)return null}return u-=m,d-=m,p-=g,f-=g,a.some(I=>I==="inline-start"||I==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(p,y):(a.some(I=>I==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-E*e.getInlineDir(),y),a.some(I=>I==="block-start"||I==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(u,v):(a.some(I=>I==="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 s=t.getPaddingRect(),r=t.vertical?s.x1:s.y2,o=this;for(;o;){if(o.floatsDeferredToNext.some(i(o)))return r;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 r;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()<r*t.getBoxDir()?r: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 s=this.toLogicalFloatSides(t)[0],r=this.toLogical(i),o;r==="all"?o=["block-start","block-end","inline-start","inline-end"]:r==="both"?o=["inline-start","inline-end"]:r==="same"?s==="snap-block"?o=["block-start","block-end"]:o=[s]:o=[r];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,s=null;for(;n&&n.container;){let o=n.getLimitValuesInner(t,i);s?e.vertical?(o.right<s.right&&(s.right=o.right,s.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.left>s.left&&(s.left=o.left,s.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):(o.top>s.top&&(s.top=o.top,s.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.bottom<s.bottom&&(s.bottom=o.bottom,s.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):s=o,n=n.parent}let r=Math.max(s.floatMinWrapBlockStart,s.floatMinWrapBlockEnd);return(e.vertical?s.right-s.left:s.bottom-s.top)<=r}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}},sn=[],ji=class{static register(e){sn.push(e)}findByNodeContext(e){for(let t=sn.length-1;t>=0;t--){let i=sn[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=sn.length-1;t>=0;t--){let i=sn[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},Rg=class{appliesToNodeContext(e){return Di(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let s=e.floatSide,r=e.toNodePosition();return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(o=>{n=o,t.flowName;let a=new Wu(r,n,s,e.clearSide,t.flowName,e.floatMinWrapBlock);return t.addPageFloat(a),N(a)})}createPageFloatFragment(e,t,i,n,s){let r=e[0].float;return new Gu(r.floatReference,t,i,e,n,s)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){}forbid(e,t){}};ji.register(new Rg);var Fg=Gu,eo=class ju extends Wu{constructor(t,i,n,s,r){super(t,i,"block-end",null,n,r),this.footnotePolicy=s}isAllowedToPrecede(t){return!(t instanceof ju)}},yl=class extends Fg{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof eo?!0:this.getOrder()<e.getOrder()}},Lg=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.toNodePosition();return!ri(t,this.footnote.nodePosition)}},Bg=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof eo}createPageFloat(e,t,i){let n=Fe.REGION,s=t.getPageFloatLayoutContext(n);t.getPageFloatLayoutContext(Fe.PAGE).hasSameContainerAs(s)&&(n=Fe.PAGE);let r=e.toNodePosition();t.flowName;let o=new eo(r,n,t.flowName,e.footnotePolicy,e.floatMinWrapBlock);return t.addPageFloat(o),N(o)}createPageFloatFragment(e,t,i,n,s){let r=e[0].float;return new yl(r.floatReference,e,n,s)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof yl);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 Lg(i);t.addLayoutConstraint(n,i.floatReference);break}}}};ji.register(new Bg);var Og="data-vivliostyle-flow-root";function _g(e){return e.getAttribute(Og)==="true"}function vl(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 aa(e){return e===b.absolute||e===b.fixed}function to(e){return e instanceof Ji&&e.name==="running"}function Xu(e,t,i,n){return e===b.none||(aa(t)?(i=b.none,e=vl(e)):(i&&i!==b.none&&!J(i)||n)&&(e=vl(e))),{display:e,position:t,float:i}}function qu(e,t,i,n){return Xu(e,t,i,n).display===b.block}function tr(e){return e instanceof ae||e instanceof Q||typeof e=="string"}function Lt(e){if(!tr(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 mi(e){return tr(e)?e.toString().includes("list-item"):!1}function Mg(e){if(!tr(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 Yu(e){if(!tr(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 zg(e,t,i,n,s,r,o){return s=s||r||b.horizontal_tb,!!o||!!i&&i!==b.none&&!J(i)||aa(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&&!J(n)||!!r&&s!==r}function Dg(e){return e===b.relative||e===b.absolute||e===b.fixed}var mt=1e5;function la(e){let t=e.element.style;t.columnGap=`${mt-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function Ku(e){let t=e.element.style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function Zu(e){return e.element.style.columnCount==="1"}function Vg(e){e.element.setAttribute("data-vivliostyle-column","true")}function Ug(e){return e.element.hasAttribute("data-vivliostyle-column")}function Ms(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/mt)}function io(e,t){let i=Ms(e,t);if(i===0)return 0;let n=t?e.top:Math.min(Math.abs(e.left),Math.abs(e.right)),s=Math.round(n/mt),r=s*mt,o=i*mt;return t?(e.top-=r,e.bottom-=o,e.bottom<e.top&&(e.bottom+=mt,o-=mt),e.right-=r,e.left-=o):e.left<-mt/2?(e.right+=r,e.left+=o,e.left>e.right&&(e.left-=mt,o+=mt),e.top+=r,e.bottom+=o):(e.left-=r,e.right-=o,e.right<e.left&&(e.right+=mt,o-=mt),e.top+=r,e.bottom+=o),e.width=e.right-e.left,e.height=e.bottom-e.top,s}function Ju(e,t){for(let i=0;i<e.length;i++)io(e[i],t)}function Pt(e,t,i){var n;let s=e.getElementClientRect(t),r=io(s,i);if(r===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=r,f=parseFloat(o.paddingBlockEnd),m=parseFloat(o.borderBlockEndWidth),g=Math.ceil(f+m);for(;g-- >0&&p===r&&--d>0;){l[h]=`${d}px`;let w=e.getElementClientRect(t);if(p=io(w,i),p<r||p===r&&(i?w.right>s.right:w.top<s.top))return a.setAttribute("data-vivliostyle-column-height-adjusted","true"),w}l[h]=`${u}px`}}}return s}function Hg(e,t){var i,n;if(e.nodeType===1){let s=e;((i=s.style)==null?void 0:i.breakAfter)==="column"&&(s.style.breakAfter="")}if(t.nodeType===1){let s=t;((n=s.style)==null?void 0:n.breakBefore)==="column"&&(s.style.breakBefore="")}}function ha(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 $g(e){var t;if(e.nodeType!==1)return;let i=e,n=i.style,s=n?.breakBefore==="column",r=i.previousElementSibling,o=r&&((t=r.style)==null?void 0:t.breakAfter)==="column";if(!s&&!o)return;let a=ha(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)&&(s&&(n.breakBefore=""),o&&r&&(r.style.breakAfter=""),n.marginBlockStart=`${mt}px`)}function Ti(e,t,i,n){let s=e.viewNode;if(!s)return NaN;let r=s.nodeType===1?s:s.parentElement;if(r&&r.namespaceURI==="http://www.w3.org/1999/xhtml"){let o=r.style;if(r.localName==="br"||r.localName==="wbr"||o&&Lt(o.display)&&/^([\d\.]|super|(text-)?top)/.test(o.verticalAlign))return NaN}if(s===r){if(e.after||!e.inline){if(e.after&&!e.inline&&r.querySelector("ruby")){let a=r.parentNode,l=r.nextSibling;a.removeChild(r),a.insertBefore(r,l)}let o=Pt(t,r,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=s.ownerDocument.createRange(),l=s.textContent.length;if(!l)return NaN;e.after&&(i+=l),i>=l&&(i=l-1),a.setStart(s,i),a.setEnd(s,i+1);let h=t.getRangeClientRects(a);return Ju(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 no(e,t,i){let n=Zu(t);n&&Ku(t);let s=t.clientLayout.getElementClientRect(e);n&&la(t);let r=t.getComputedMargin(e);return i?s.width+r.left+r.right:s.height+r.top+r.bottom}function Fi(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function Qu(e,t){var i;if(e)for(let n=e.lastChild,s=n;n!==t;n=s)s=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 Xi="data-adapt-spec";function ua(e){return!!e.getAttribute(Xi)}function Li(e){var t;if(e?.nodeType!==1)return!1;let i=e;if(ua(i))return!0;let n=(t=i.style)==null?void 0:t.position;return n==="absolute"||n==="fixed"}function Bi(e){let t=e?.viewNode;return t?.nodeType===1&&ua(t)}function Wg(e){return e!=="inline"&&(Lt(e)||Yu(e))}function xl(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))&&Lt(i.display))return i;return null}var ca=class{calculateOffset(e){return Vi(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function Vi(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var jn=class extends ca{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(Fs(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=Ti(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,s=n?.closest("table, [style*='display: table;']");if(s){let r=s.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===s&&!r)&&(o+=e.parseComputedLength(h.paddingBlockEnd)),l===s&&!r&&(o+=e.parseComputedLength(h.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),r?a=Math.max(a,e.parseComputedLength(h.borderBlockEndWidth)):(l===n||l===s)&&(a+=e.parseComputedLength(h.borderBlockEndWidth)),l===s)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(!wi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},rn=class{find(e){let t=At("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()}`)}},Oi=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 jn(e.copy(),t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}clearOverflownViewNodes(e,t,i,n){var s;if(!i.viewNode||!i.viewNode.parentNode||i.shadowType===Wt.ShadowType.ROOTLESS&&Bi(i))return;let r=i.viewNode;((s=r.parentElement)==null?void 0:s.localName)==="viv-ts-inner"&&(r=r.parentElement.parentElement);let o=r.parentNode;Qu(o,r),n&&o.removeChild(r)}finishBreak(e,t,i,n){let s=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,s),n&&e.layoutContext.processFragmentedBlockEdge(t),N(!0)}},da=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){}},pa=new Oi,Gg=Kr.isInstanceOfBlockFormattingContext;kt("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,s,r)=>{let o=e.parent;return!o&&e.formattingContext||o&&e.formattingContext!==o.formattingContext?null:e.establishesBFC||!e.formattingContext&&qu(i,n,s,r)?new da(o?o.formattingContext:null):null});kt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof da?pa:null);var fa=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=B("AbstractLayoutRetryer.tryLayout");this.saveState(e,t);let n=this.resolveLayoutMode(e);return n.doLayout(e,t).then(s=>{let r=n.accept(s,t);r=n.postLayout(s,this.initialPosition,t,r),r?i.finish(s):(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)}},jg=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){}},so=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=B("LayoutIterator");return n.loopWithFrame(s=>{let r;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Ue(i.nodeContext.viewNode,i.nodeContext.whitespace)?i.nodeContext.after?r=t.afterIgnoredTextNode(i):r=t.startIgnoredTextNode(i):i.nodeContext.after?r=t.afterNonElementNode(i):r=t.startNonElementNode(i):i.nodeContext.inline?i.nodeContext.after?r=t.afterInlineElementNode(i):r=t.startInlineElementNode(i):i.nodeContext.after?r=t.afterNonInlineElementNode(i):r=t.startNonInlineElementNode(i):i.nodeContext.after?r=t.afterNonDisplayableNode(i):r=t.startNonDisplayableNode(i);let o=(r&&r.isPending()?r:N(!0)).thenAsync(()=>i.break?N(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(o.isPending()){o.then(a=>{i.break?s.breakLoop():(i.nodeContext=a,s.continueLoop())});return}else if(i.break){s.breakLoop();return}else i.nodeContext=o.get()}t.finish(i),s.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},vn=class extends jg{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&&et(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,s=!t.allowLayout(n);return s&&(i.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),n=e.nodeContext=n.modify(),n.overflow=!0),s}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=it(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=it(e.breakAtTheEdge,e.nodeContext.breakAfter)),N(!0)))}},ro=[];function Xg(){ro=[]}function ec(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var qg=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},Yg=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},tc=class cs{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let s=cs.fragmentIndices;(!s[t]||s[t].priority<=n)&&(s[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){cs.fragmentIndices={}}matches(){let t=cs.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&ec(t.fragmentIndex,this.a,this.b)}};c(tc,"fragmentIndices",{});var ir=tc,ss=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new ir(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new Yg(e)}static buildAnyMatcher(e){return new qg(e)}},ic={"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},Kg=["image-resolution","orphans","widows"];function Zg(){return At("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(Kg))}var Jg={"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},oo=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],Qg=["max-%","min-%","%"],Sl=(()=>{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<oo.length;i++)for(let n=0;n<e.length;n++){let s=oo[i].replace("%",e[n]);t[s]=!0}return t})();function en(e,t){let i={};for(let n of oo)for(let s in e){let r=n.replace("%",s),o=n.replace("%",e[s]);i[r]=o,i[o]=r}for(let n of Qg)for(let s in t){let r=n.replace("%",s),o=n.replace("%",t[s]);i[r]=o,i[o]=r}return i}var nc=en({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),sc=en({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),em=en({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),tm=en({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),im=en({inside:"right",outside:"left"},{}),nm=en({inside:"left",outside:"right"},{}),M=class ao{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 ao(i,this.priority)}increaseSpecificity(t){return t==0?this:new ao(this.value,this.priority+t)}evaluate(t,i,n,s){return i&&$t(i)?this.value:Ds(t,this.value,i,n,s)}isEnabled(t){return!0}},lo=class ho extends M{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new M(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new ho(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new ho(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){H.warn(i)}return!1}};function uo(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Gt(e,t,i,n){if(e)if(!i)delete e[t];else{let s=e[t];(!s||i.priority>=s.priority)&&(n?i.isEnabled(n)&&(e[t]=i.getBaseValue()):e[t]=i)}}var rc={"region-id":!0,"fragment-selector-id":!0};function sm(e){return!!rc[e]}function co(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Ui(e){return e.charAt(0)!=="_"&&!rc[e]}function xn(e){return!!ic[e]||$t(e)}function _e(e,t){return e[t]}function bi(e,t,i){i?e[t]=i:delete e[t]}function It(e,t){return e[t]}function Xn(e,t){let i=e[t];return i||(i={},e[t]=i),i}var oc=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function ac(e,t){return e[t]}function lc(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function zs(e,t,i,n,s,r,o){var a,l;if([{id:s,styleKey:"_pseudos"},{id:r,styleKey:"_regions"}].forEach(h=>{if(h.id){let u=Xn(t,h.styleKey);t=u[h.id],t||(t={},u[h.id]=t)}}),o){let h=oc(t);t={},h.push({styles:t,matcher:o})}for(let h in i)if(!co(h))if(sm(h)){let u=ac(i,h),d=lc(t,h);Array.prototype.push.apply(d,u)}else{let u=_e(i,h);if(!u.isEnabled(e))continue;let d=u.increaseSpecificity(n);Gt(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 M(j,d.priority);Gt(t,f,m,e)}}}function rm(e,t){let i={};for(let n=0;n<t.length;n++)zs(e,i,t[n],0,null,null,null);return i}function hc(e,t){if(e.length>0){e.sort((n,s)=>s.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 om=class extends Zi{constructor(e,t){super(),this.props=e,this.context=t,c(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=_e(this.props,"font-size");if(!e.value.isNumeric())return Tt.em;let t=e.value;if(!Ap(t.unit))throw new Error("Unexpected state");return t.num*Tt[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?po(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?ga(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Ds(this.context,e,this.propName).visit(this):e}};function ga(e,t,i){let n=e.unit,s=e.num;return n==="em"?new A(s*t,"px"):n==="rem"?new A(s*i.fontSize(),"px"):n==="rlh"?new A(s*i.rootLineHeight,"px"):e}function po(e,t,i){e=ga(e,t,i);let n=e.unit,s=e.num;return n==="px"?e:n==="%"?new A(s/100*t,"px"):new A(s*i.queryUnitSize(n,!1),"px")}var tn=class{apply(e){}mergeWith(e){return new am([this,e])}clone(){return this}},rs=class extends tn{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},am=class uc extends tn{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 uc([].concat(this.list))}},ma=class extends tn{constructor(e,t,i,n,s){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=s}apply(e){zs(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},ve=class extends tn{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}},hm=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}},Cl=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}},um=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}},cm=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 s=n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");s&&s.match(this.epubTypePatt)&&this.chained.apply(e)}}}},dm=class extends ve{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function nr(e,t,i,n){if(!e)return!1;if(t!==null)return n(e,t,i);for(let s of e.getAttributeNames())if((s===i||s.endsWith(`:${i}`))&&n(e,s===i?"":e.lookupNamespaceURI(s.split(":")[0]),i))return!0;return!1}var kl=class extends ve{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){nr(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},pm=class extends ve{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){nr(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}},fm=class extends ve{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){nr(e.currentElement,this.ns,this.name,(t,i,n)=>!!Jg[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},on=class extends ve{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){nr(e.currentElement,this.ns,this.name,(t,i,n)=>{var s;return!!((s=t.getAttributeNS(i,n))!=null&&s.match(this.regexp))})&&this.chained.apply(e)}},gm=class extends ve{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},El=class extends ve{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},mm=class extends ve{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},qn=class extends ve{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return ec(e,this.a,this.b)}},wm=class extends qn{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},fo=class extends qn{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}},go=class extends qn{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}},mo=class extends qn{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,s=i.localName,r=t[n];r||(r=t[n]={}),r[s]=(r[s]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},bm=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}},ym=class extends ve{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},vm=class extends ve{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},xm=class extends ve{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},Ze=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}},Sm=class cc extends tn{constructor(){super(),c(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new cc;return t.applied=this.applied,t}},wa=class extends ve{constructor(e){super(),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new Sm;for(let t of e)this.firstActions.push(hc(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}},Cm=class extends wa{positive(){return!1}},km=class extends wa{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}},sr=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)}},Em=class dc extends sr{constructor(t,i,n){super(t,i,n)}fresh(t){return new dc(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}},Nm=class pc extends sr{constructor(t,i,n){super(t,i,n)}fresh(t){return new pc(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)}},Pm=class fc extends sr{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new fc(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)}},Tm=class gc extends sr{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new gc(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}},Im=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}},Am=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}},Rm=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}},Fm=class extends Zi{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new Ke(e):new Ke("about:invalid");case"string":default:return e?new G(e):new G("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let t="string",i=null,n=null;if(e.values[0]instanceof Q){let s=e.values[0].values;s.length>=2&&(t=s[1].stringValue()),i=s[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 Sn(e){if(Ot(e)){if(e instanceof G)return e.stringValue();if(e instanceof Q)return e.values.map(t=>Sn(t)).join("")}return""}var wo=class extends Zi{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 s=i[2*Math.min(n,t.quoteDepth)];return t.quoteDepth++,s}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 G("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new G("")}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 s=n&&n.length&&n[n.length-1]||0;return new G(this.format(s,i))}else{let s=new U(this.counterResolver.getPageCounterVal(t,r=>this.format(r||0,i)));return new Q([s])}}visitFuncCounters(e){let t=e[0].toString(),i=e[1].stringValue(),n=e.length>2?e[2].stringValue():"decimal",s=this.cascade.counters[t],r=new ii;if(s&&s.length)for(let a=0;a<s.length;a++)a>0&&r.append(i),r.append(this.format(s[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=r.toString();return h.length&&l.push(h),l.length?l.join(i):this.format(0,n)}));return new Q([o])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof Ke?i=t.url:i=t.stringValue();let n=e[1].toString(),s=e.length>2?e[2].stringValue():"decimal",r=new U(this.counterResolver.getTargetCounterVal(i,n,o=>this.format(o||0,s)));return new Q([r])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof Ke?i=t.url:i=t.stringValue();let n=e[1].toString(),s=e[2].stringValue(),r=e.length>3?e[3].stringValue():"decimal",o=new U(this.counterResolver.getTargetCountersVal(i,n,a=>{let l=a.map(h=>this.format(h,r));return l.length?l.join(s):this.format(0,r)}));return new Q([o])}visitFuncTargetText(e){let t=e[0],i;t instanceof Ke?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",s=new U(this.counterResolver.getTargetTextVal(i,n));return new Q([s])}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,s,r,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=It(this.cascade.currentStyle,"_pseudos"),u=(i=(t=h?.[a])==null?void 0:t.content)==null?void 0:i.value;l=Sn(u)}break;case"first-letter":{let h=It(this.cascade.currentStyle,"_pseudos"),u=(Sn((s=(n=h?.before)==null?void 0:n.content)==null?void 0:s.value)||this.element.textContent||Sn((o=(r=h?.after)==null?void 0:r.content)==null?void 0:o.value)).match(Is);l=u?u[0]:""}break}return new G(l)}visitFuncLeader(e){let t="";if(e[0]instanceof ae)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof G&&(t=e[0].stringValue());return t.length==0?new G(""):new U(new Me(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 Er(e,t,i){let n;if(e.nodeType===1)n=Array.from(e.getClientRects());else{let s=e.ownerDocument.createRange();s.selectNodeContents(e),n=t.getRangeClientRects(s)}return n.reduce((s,r)=>s+(i==="vertical-rl"||i==="vertical-lr"?r.height:r.width),0)}var Lm=(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,D.left>k.left||D.right<k.right||D.top>k.top||D.bottom<k.bottom},d=function(){let k,R,L=v.repeat(1e4);if(h(L),u())k=1,R=1e4;else return;for(let z=0;z<16;z++){let $="",q=Math.floor((k+R)/2);for(let K=0;K<q;K++)$+=v;if(h($),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 s=h,r=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 I=ha(f.viewNode),V=I?.style.columnFill||null;I&&(I.style.columnFill="auto");let D=i.clientLayout.getElementClientRect(f.viewNode),te=i.clientLayout.getElementClientRect(g),re=i.parseComputedLength(E),nt=[],st=g.parentElement;for(;st.parentElement&&st.parentElement!==f.viewNode;)st=st.parentElement;let xe=st.nextSibling;for(;xe;){if(xe.nodeType===1){let k=xe,{display:R,float:L,position:z}=i.clientLayout.getElementComputedStyle(k);if(L!=="none"||z==="absolute"||z==="fixed"){xe=xe.nextSibling;continue}if(Lt(R))nt.push(k);else if(Mg(R))break}else if(xe.nodeType===3){let k=xe;k.length>0&&nt.push(k)}xe=xe.nextSibling}let x=nt.reduce((k,R)=>k+Er(R,i.clientLayout,y),0);if(w!=="after"){let k=Er(st,i.clientLayout,y),R=Er(g,i.clientLayout,y);x+=k-R}y==="vertical-rl"||y==="vertical-lr"?(C==="rtl"?D.top+=re:D.bottom-=re,D.top=Math.min(te.top,D.top),D.bottom=Math.max(te.bottom,D.bottom)):(C==="rtl"?D.left+=re:D.right-=re,D.left=Math.min(te.left,D.left),D.right=Math.max(te.right,D.right)),d();let O=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=O.top-S.top-p("top"):P=O.left-S.left-p("left"):y=="vertical-rl"||y=="vertical-lr"?P=S.bottom-O.bottom-p("bottom"):P=S.right-O.right-p("right"),P-=x,P=Math.max(0,P-.1),g.style.float="",m.style.marginInlineStart=`${P}px`,I&&(V?I.style.columnFill=V:I.style.removeProperty("column-fill"))}};kt("POST_LAYOUT_BLOCK",Lm);var ba=1/1048576;function Si(e,t){for(let i in e)t[i]=e[i].clone()}var Bm=class mc{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 mc;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return Si(this.tags,t.tags),Si(this.nstags,t.nstags),Si(this.epubtypes,t.epubtypes),Si(this.classes,t.classes),Si(this.ids,t.ids),Si(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,i,n){let s=t[i];s&&(n=s.mergeWith(n)),t[i]=n}createInstance(t,i,n,s,r){return new Om(this,t,i,n,s,r)}nextOrder(){return this.order+=ba}},Om=class{constructor(e,t,i,n,s,r){this.context=t,this.counterListener=i,this.counterResolver=n,this.counterStyleStore=r,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,"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 G("\u201C"),new G("\u201D"),new G("\u2018"),new G("\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=ss.buildViewConditionMatcher(this.currentElementOffset,e));let i=this.dependentConditions.map(n=>{let s=this.viewConditions[n];return s&&s.length>0?s.length===1?s[0]:ss.buildAnyMatcher([].concat(s)):null}).filter(n=>n);return i.length<=0?t:t===null?i.length===1?i[0]:ss.buildAllMatcher(i):ss.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=Nr,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,s,r,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),mi(l)&&(f||(f={}),f["list-item"]=(n=f["list-item"])!=null?n:1,/^\s*[-+]?\d/.test((r=(s=this.currentElement)==null?void 0:s.getAttribute("value"))!=null?r:"")&&(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 Q&&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(mi(l)){let y=this.counters["list-item"],C=y[y.length-1];e["ua-list-item-count"]=new M(new Ht(C),0);let E=Xn(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 wo(this,this.currentElement,this.counterResolver));let i=t.value instanceof qe?t.value.values:[t.value];for(let n of i)if(n instanceof Q){let s=n.values[0].stringValue(),r=n.values.slice(1).map(o=>Sn(o)).join("");this.counterResolver.setNamedString(s,r,this.currentElementOffset)}delete e["string-set"]}setRunningElement(e){let t=e.position;if(t?.value instanceof Ji&&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 wo(this,t,this.counterResolver))),this.popCounters()}pushElement(e,t,i,n){var s,r,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=Nr;let h=t.getAttributeNS("http://www.idpf.org/2007/ops","type");h?this.currentEpubTypes=h.split(/\s+/):this.currentEpubTypes=Nr;let u=_r(t);u&&(this.stack[this.stack.length-1].push(new Am(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.applyAttrFilter(t);let C=i.quotes,E=null;if(C){let D=C.evaluate(this.context);D&&(E=new Rm(this.quotes),D===b.none?this.quotes=[new G(""),new G("")]:D===b.auto||D===b.initial?this.quotes=[new G("\u201C"),new G("\u201D"),new G("\u2018"),new G("\u2019")]:D instanceof Q&&(this.quotes=D.values))}this.pushCounters(this.currentStyle);let I=this.currentId||this.currentXmlId||t.getAttribute("name")||"";if(d||I){let D={};Object.keys(this.counters).forEach(te=>{D[te]=Array.from(this.counters[te])}),this.counterListener.countersOfId(I,D)}let V=It(this.currentStyle,"_pseudos");if(V){let D=!0;for(let te of _m){te||(D=!1);let re=V[te];re&&((te==="before"||te==="after")&&!Ot((s=re.content)==null?void 0:s.value)||te==="marker"&&!mi((r=_e(this.currentStyle,"display"))==null?void 0:r.value)||(te==="footnote-call"||te==="footnote-marker")&&((o=_e(this.currentStyle,"float"))==null?void 0:o.value)!==b.footnote?delete V[te]:D?(this.processPseudoelementProps(re,t),te==="marker"&&this.processMarkerPseudoelementProps(re,t,e)):this.stack[this.stack.length-2].push(new Im(re,t)))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),E&&this.stack[this.stack.length-2].push(E)}processMarkerPseudoelementProps(e,t,i){var n,s,r,o,a;if(!Ot((n=e.content)==null?void 0:n.value)&&mi((s=this.currentStyle.display)==null?void 0:s.value)){let l=this.getInheritedPropertyValue("list-style-type",i,t),h=this.getInheritedPropertyValue("list-style-image",i,t);if(h instanceof Ke)e.content=new M(new Q([h,new G(" ")]),0);else if(l instanceof G)e.content=new M(l,0);else if(l instanceof ae&&l!==b.none){let u=(o=(r=this.currentStyle["ua-list-item-count"])==null?void 0:r.value)==null?void 0:o.num;u!=null&&(e.content=new M(new G(this.counterStyleStore.formatMarker(l.name,u)),0)),e["list-style-type"]=new M(l,0)}}if(!Lt((a=_e(this.currentStyle,"display"))==null?void 0:a.value)){let l=this.getInheritedPropertyValue("list-style-position",i,t);l&&(e["list-style-position"]=new M(l,0))}}getInheritedPropertyValue(e,t,i){var n;for(let r=i;r;r=r.parentElement){let o=(r===this.currentElement?this.currentStyle:t.getStyle(r,!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 s=t.validatorSet;return(n=s?.defaultValues[e])!=null?n:null}applyAttrFilterInner(e,t){for(let i in t)Ui(i)&&!$t(i)&&(t[i]=t[i].filterValue(e))}applyAttrFilter(e){let t=new Fm(e),i=this.currentStyle,n=It(i,"_pseudos");for(let s in n)this.applyAttrFilterInner(t,n[s]);this.applyAttrFilterInner(t,i)}applyVarFilter(e,t,i){var n,s,r;let o=e[0],a=new Gm(e,t,i),l=32,h={};for(let u in o)if(co(u)){let d=It(o,u);for(let p in d)this.applyVarFilter([d[p],...e],t,i)}else if(Ui(u)){let d=_e(o,u),p=d.value;for(let f=0;;f++){if(f>=l){p=j;break}let m=p.visit(a);if(a.error){p=j,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(J(p)){for(let g of m.propList){let w=new M(p,d.priority),v=_e(o,g);bi(h,g,uo(this.context,v,w))}delete o[u]}else{let g=Qi(t.scope,new Rt(p.toString(),null),"");if(g&&(g.visit(m),!m.error)){for(let w of m.propList){let v=new M((r=(s=m.values[w])!=null?s:f.defaultValues[w])!=null?r:b.initial,d.priority),y=_e(o,w);bi(h,w,uo(this.context,y,v))}delete o[u]}}else o[u]=new M(p,d.priority)}if(h[u]){let f=_e(o,u);f&&f.value!==j&&Gt(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(co(n)){let s=It(e,n);for(let r in s)this.applyCalcFilter(s[r],t)}else if(Ui(n)&&!$t(n)){let s=_e(e,n),r=s.value.visit(i);r!==s.value&&(e[n]=new M(r,s.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()}},Nr=[],_m=["before","transclusion-before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","transclusion-after","after"],bo=null;function Mm(e){bo=e}var Rn=class extends Wn{constructor(e,t,i,n,s,r,o){super(e,t,o),this.condition=i,this.regionId=s,this.validatorSet=r,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:bo?bo.clone():new Bm,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=hc(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 um(e,t.toLowerCase())):t?this.chain.push(new Cl(t.toLowerCase())):this.chain.push(new dm(e)))}invalidSelector(e){H.warn(e),this.chain.push(new Ze("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof Fn;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 ym);break;case"disabled":this.chain.push(new vm);break;case"checked":this.chain.push(new xm);break;case"root":case"scope":this.chain.push(new mm);break;case"link":this.chain.push(new Cl("a")),this.chain.push(new kl("","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)${qt(i)}($|\\s)`),s=t[1];this.chain.push(new cm(n,s))}else this.chain.push(new Ze(""));break;case"-adapt-footnote-content":case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new Ze(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new gm(new RegExp(`^${qt(i.toLowerCase())}($|-)`)))}else this.chain.push(new Ze(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=zm[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new Ze(""));break}case"first-child":this.chain.push(new El);break;case"last-child":this.chain.push(new go(0,1));break;case"first-of-type":this.chain.push(new fo(0,1));break;case"last-of-type":this.chain.push(new mo(0,1));break;case"only-child":this.chain.push(new El),this.chain.push(new go(0,1));break;case"only-of-type":this.chain.push(new fo(0,1)),this.chain.push(new mo(0,1));break;case"empty":this.chain.push(new bm);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 Ze(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new Ze(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}idSelector(e){this.specificity+=65536,this.chain.push(new hm(e))}attributeSelector(e,t,i,n){this.specificity+=256,t=t.toLowerCase(),n=n||"";let s;switch(i){case 0:s=new kl(e,t);break;case 39:s=new pm(e,t,n);break;case 45:!n||n.match(/\s/)?s=new Ze(""):s=new on(e,t,new RegExp(`(^|\\s)${qt(n)}($|\\s)`));break;case 44:s=new on(e,t,new RegExp(`^${qt(n)}($|-)`));break;case 43:n?s=new on(e,t,new RegExp(`^${qt(n)}`)):s=new Ze("");break;case 42:n?s=new on(e,t,new RegExp(`${qt(n)}$`)):s=new Ze("");break;case 46:n?s=new on(e,t,new RegExp(qt(n))):s=new Ze("");break;case 50:if(n=="supported")s=new fm(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(s)}descendantSelector(){let e=`d${os++}`;this.processChain(new rs(new Em(e,this.viewConditionId,null))),this.chain=[new Ze(e)],this.viewConditionId=null}childSelector(){let e=`c${os++}`;this.processChain(new rs(new Nm(e,this.viewConditionId,null))),this.chain=[new Ze(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${os++}`;this.processChain(new rs(new Pm(e,this.viewConditionId,null))),this.chain=[new Ze(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${os++}`;this.processChain(new rs(new Tm(e,this.viewConditionId,null))),this.chain=[new Ze(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 ma(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new lo(t,0,this.condition):i=new M(t,0),lc(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 Q([b.exclusive,b._static]),i),this.simpleProperty("flow-into",t,i),t=b.block),At("SIMPLE_PROPERTY").forEach(r=>{let o=r({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(),s=this.condition?new lo(t,n,this.condition):new M(t,n);Gt(this.elementStyle,e,s)}finish(){return this.cascade}startFuncWithSelector(e){let t;switch(e){case"is":t=new Fn(this);break;case"not":t=new Dm(this);break;case"where":t=new Vm(this);break;case"has":t=new Um(this);break}t&&(t.startSelectorRule(),this.owner.pushHandler(t))}},zm={"nth-child":wm,"nth-of-type":fo,"nth-last-child":go,"nth-last-of-type":mo},os=0,Fn=class wc extends Rn{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 km(this.selectorTexts):this.positive()?new wa(this.chains):new Cm(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new Ze("")),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 s=this;s instanceof wc;s=s.parent)if(s.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}},Dm=class extends Fn{positive(){return!1}forgiving(){return!1}},Vm=class extends Fn{increasingSpecificity(){return!1}},Um=class extends Fn{relational(){return!0}},Hm=class extends Wn{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",s=new Vn(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,s))}}},dn=class extends Wn{constructor(e,t,i,n,s,r){super(e,t,!1),this.condition=i,this.elementStyle=n,this.validatorSet=s,this.ruleType=r,c(this,"order"),this.order=0}property(e,t,i){i?H.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){H.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){H.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 s=this.condition?new lo(t,n,this.condition):new M(t,n);Gt(this.elementStyle,e,s)}},$m=class extends Eu{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){H.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){H.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?ku:Cu;n+=this.order,this.order+=ba;let s=new M(t,n);Gt(this.elementStyle,e,s)}};function bc(e,t){let i=oc(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function yo(e,t,i){bc(i,n=>{Cn(e,n,t)})}function Wm(e,t,i,n){let s=new $m(e,t),r=new Rt(n,s);try{Qf(r,s,i)}catch(o){H.warn(o,"Style attribute parse error:")}return s.elementStyle}function yc(e,t,i){let n=e["writing-mode"];if(n){let s=n.evaluate(t,"writing-mode");if(s&&s!==b.inherit&&s!==b.revert&&s!==b.unset)return s===b.vertical_rl}return i}function vc(e,t,i){let n=e.direction;if(n){let s=n.evaluate(t,"direction");if(s&&s!==b.inherit&&s!==b.revert&&s!==b.unset)return s===b.rtl}return i}function xc(e,t,i,n,s){let r={};for(let o in e)Ui(o)&&(r[o]=_e(e,o));return yo(r,t,e),Sc(e,i,n,(o,a)=>{Cn(r,a,t),yo(r,t,a)}),r}function Sc(e,t,i,n){let s=It(e,"_regions");if((t||i)&&s){if(i){let r=["footnote"];t?t=t.concat(r):t=r}for(let r of t){let o=s[r];o&&n(r,o)}}}function Cn(e,t,i){for(let n in t)if(Ui(n)){let s=_e(t,n),r=e[n];e[n]=uo(i,r,s)}}var Cc=(e,t,i,n,s,r)=>{var o,a;let l=i?n?em:nc:n?tm:sc,h=s?im:nm;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=Sl[p]?p:Sl[f]?f:u}else g=u,u.startsWith("text-align")&&(d.value===b.inside||d.value===b.outside)&&(d=new M(s===(d.value===b.inside)?b.right:b.left,d.priority));t[g]=r(u,d)}},Gm=class extends Zi{constructor(e,t,i){super(),this.elementStyles=e,this.styler=t,this.element=i}getVarValue(e){var t,i,n,s,r;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=(r=(s=this.styler.getStyle(o,!1))==null?void 0:s[e])==null?void 0:r.value;if(a)return a}return null}visitFunc(e){if(e.name!=="var")return super.visitFunc(e);let t=e.values[0]instanceof ae&&e.values[0].name;return!t||!$t(t)?(this.error=!0,j):this.getVarValue(t)||(e.values.length<2?(this.error=!0,j):e.values.length===2?e.values[1]:new qe(e.values.slice(1)))}},kc=class extends Zi{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=Qi(this.context.rootScope,new Rt(i,null),"");if(n instanceof U)try{let s=n.expr.evaluate(this.context);typeof s=="number"&&!isNaN(s)&&(/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(i)?t=new A(s,"px"):/\d[a-z]/i.test(i)||(t=new Ht(s)))}catch(s){H.warn(s)}return t}visitNumeric(e){return this.resolveViewportUnit&&(Mh(e.unit)||Fp(e.unit))?new A(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new A(e.num*this.percentRef/100,"px"):e}};function Ds(e,t,i,n,s){try{if(t instanceof U)return t.expr instanceof Me&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:ng(e,t.expr,i);if(t instanceof A||t instanceof Ji||t instanceof Q||t instanceof qe)return t.visit(new kc(e,!0,n,s))}catch(r){return H.warn(r),j}return t}var Nl={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Pl(e){let t=e instanceof Ye?e:typeof e=="string"?F(e):b.none;if(t===b.none)return Nl;let i=t instanceof Q?t.values:[t],n=Object.create(Nl);for(let s of i)if(s instanceof ae)switch(s.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 Tl(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var jm={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},Il={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},Al={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Rl(e){let t=e instanceof Ye?e:typeof e=="string"?F(e):b.normal;if(t===b.normal)return Il;if(t===b.auto)return Al;let i=t instanceof Q?t.values:[t],n=Object.create(Il);for(let s of i)if(s instanceof ae)switch(s.name){case"trim-both":case"trim-auto":return Al;case"space-all":return jm;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 Pr={ideographAlpha:!1,ideographNumeric:!1},Xm={ideographAlpha:!0,ideographNumeric:!0};function Fl(e){let t=e instanceof Ye?e:typeof e=="string"?F(e):b.normal;if(t===b.normal||t===b.auto)return Xm;if(t===b.none)return Pr;let i=t instanceof Q?t.values:[t],n=Object.create(Pr);for(let s of i)if(s instanceof ae)switch(s.name){case"no-autospace":return Pr;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Ll(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function Bl(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 qm=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 s=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(s.length>1){let r=s.length-1;for(let o=0;o<r;o++)n.parentNode.insertBefore(document.createTextNode(s[o]),n);n.textContent=s[r]}}}processGeneratedContent(e,t,i,n,s,r){s=Bl(s);let o=Fl(t),a=Rl(i),l=Pl(n);if(Tl(l)&&Ll(o,a))return;this.preprocessForTextSpacing(e);let h=e.style.whiteSpace;(r?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,s,r),d=f}e.style.whiteSpace=h}postLayoutBlock(e,t){var i,n,s,r,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(Xi))return!0;let{position:E,float:I}=(y=C.style)!=null?y:{};return E==="absolute"||E==="fixed"||I&&I!=="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(!Ue(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!==ot.PRESERVE&&(E=E.previousSibling),E)));)C=C.parent;for(;E;){if(E.nodeType===1){if(E.localName==="br")return!0;let I=(y=E.style)==null?void 0:y.display;if(I&&I!=="inline")return!/^(inline|ruby)\b/.test(I)}else if(E.nodeType===3){if(C.whitespace===ot.PRESERVE){if(/\n$/.test(E.textContent))return!0}else if(C.whitespace===ot.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&&!Ue(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===ot.PRESERVE){if(/\n$/.test(P.viewNode.textContent))return!0}else if(P.whitespace===ot.NEWLINE&&/\n[ \t\r\n\f]*$/.test(P.viewNode.textContent))return!0;if(((L=P.viewNode.previousElementSibling)==null?void 0:L.localName)==="br")return Ue(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===ot.PRESERVE){if(/^\n/.test(P.viewNode.textContent))return!0}else if(P.whitespace===ot.NEWLINE&&/^[ \t\r\n\f]*\n/.test(P.viewNode.textContent))return!0;if(((L=P.viewNode.nextElementSibling)==null?void 0:L.localName)==="br")return Ue(P.viewNode,P.whitespace)}return!1};var g=C,w=E;let I=Bl((r=(n=(i=y.lang)!=null?i:y.parent.lang)!=null?n:e?.lang)!=null?r:(s=e?.parent)==null?void 0:s.lang),V=Fl(y.inheritedProps["text-autospace"]),D=Rl(y.inheritedProps["text-spacing-trim"]),te=Pl(y.inheritedProps["hanging-punctuation"]);if(Tl(te)&&Ll(V,D)||/\b(flex|grid)\b/.test(y.parent.display))continue;m<0&&(m=v);let re=null,nt=null,st=v===m,xe=v===m&&h,x=v===m&&u,O=!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){re=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"||gi[k.viewNode.localName]))break;P===0&&(st=!0,h&&(xe=!0,x=!0))}for(let P=v+1;P<t.length;P++){let k=t[P];if(E(k)){O=!0;break}if(k.viewNode!==y.viewNode&&!k.display&&k.viewNode.nodeType===Node.TEXT_NODE&&k.viewNode.textContent.length>0){nt=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"||gi[k.viewNode.localName])){P===t.length-1&&d(k.viewNode)&&(S=!0);break}if(P===t.length-1){O=!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(;Ue(P,y.whitespace);)P=P.nextSibling;y.viewNode===P&&(xe=!0)}if(!S){let P=y.parent.viewNode.lastChild;for(;Ue(P,y.whitespace);)P=P.previousSibling;y.viewNode===P&&(S=!0)}}if(this.processTextSpacing(y.viewNode,st,xe,x,O,S,re,nt,V,D,te,I,y.vertical)>0)break}}}processTextSpacing(e,t,i,n,s,r,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=Ms(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=Ms(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 I=!1,V=!1,D=!1,te=!1,re;if(i&&u.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(re="viv-ts-open",I=!0,V=!0):r&&u.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(re="viv-ts-close",I=!0,D=!0):(u.forceEnd||u.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(re="viv-ts-close",I=!0,te=!0):(h.trimStart||h.spaceFirst||h.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(re="viv-ts-open",I=!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))&&(re="viv-ts-close",I=!0),I){let S=function(z){let $=parseFloat(m.defaultView.getComputedStyle(z).fontSize)*.7;return(p?z.offsetHeight:z.offsetWidth)>$},P=function(){return p?k.offsetLeft:k.offsetTop};var nt=S,st=P;if(e.parentElement.localName==="viv-ts-inner")return 0;let k=m.createElement(re),R=m.createElement("viv-ts-inner");k.appendChild(R),e.parentNode.insertBefore(k,e),R.appendChild(e);let L=S(R);if(L||V||D||te){if(re==="viv-ts-open"){if(V)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 z=P();k.className="viv-ts-auto",z===P()&&!C()&&(k.className="viv-ts-trim")}}else if(re==="viv-ts-close"){if(D)k.className=L?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(r||s){let z=P();te?(k.className=L?u.allowEnd&&h.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",u.allowEnd&&z===P()&&(h.trimEnd?k.className="viv-ts-trim":h.allowEnd?(k.className="viv-hang-end",z===P()&&(k.className="")):k.className="viv-ts-space")):h.trimEnd?k.className="viv-ts-trim":h.allowEnd?(k.className="viv-ts-auto",z===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(te){let z=E(),$=z&&u.allowEnd;$||(k.className=L?"viv-hang-end":"viv-hang-end viv-hang-hw"),L?$&&h.trimEnd?k.className="viv-ts-auto":!$&&!E()?k.className="":!z&&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"))):!z&&!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 z=P();k.className="viv-ts-auto",z===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 O(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 O(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)?O(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))&&!O(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))&&!O(e,a)&&(e.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),e.nextSibling),xe=!0)),g}registerHooks(){kt("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),kt("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),kt("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},ya=new qm;ya.registerHooks();function Ym(e){ya.preprocessForTextSpacing(e)}function Km(e,t,i,n,s,r){ya.processGeneratedContent(e,t,i,n,s,r)}var ds=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),Zm=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],va="data-adapt-pseudo";function _i(e){return e.getAttribute(va)||""}function vo(e,t){e.setAttribute(va,t)}var Ol=class{constructor(e,t,i,n,s){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=s,c(this,"contentProcessed",{})}getStyle(e,t){let i=_i(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=It(this.style,"_pseudos"),s=n?.[i]||{};if(i.match(/^first-/)&&!s["x-first-pseudo"]){let r=1,o;i=="first-letter"?r=0:(o=i.match(/^first-([0-9]+)-lines$/))!=null&&(r=o[1]-0),s["x-first-pseudo"]=new M(new Re(r),0)}return s}processContent(e,t,i){let n=_i(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0,n==="marker"&&this.processMarker(e,t,i);let s=t.content;Ot(s)&&(s.visit(new _s(e.classList.contains("_viv-marker-outside")&&e.firstElementChild||e,this.context,s,this.exprContentListener)),Ym(e))}}processMarker(e,t,i){let n=t.content,s=t["list-style-position"],r=t["list-style-type"];if(Ot(n)){if(n instanceof Ke)t.content=new Q([n]);else if(n instanceof G&&r instanceof ae){let o=r.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 G(o==="disclosure-open"?l?"\u25C2 ":"\u25BE ":l?a?"\u25B4 ":"\u25BE ":a?"\u25C2 ":"\u25B8 ")}}}if(s===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"]}},w0=Ls.isInstanceOfAfterIfContinuesLayoutConstraint,Jm=ir.registerFragmentIndex,b0=ir.clearFragmentIndices,Qm=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new xa(e,i,t),s=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=s;let r=i.firstChild;return T(r,"display","block"),N(r)})}createNodePositionForPseudoElement(){let e=ds.createElementNS("http://www.w3.org/1999/xhtml","div");vo(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 oi(i)}createShadowContext(e){return new Jr(this.sourceNode,e,null,null,null,Wt.ShadowType.ROOTED,this.styler)}},ew=class Ec{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,s){}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 tw(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof Ec?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},tw=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 Nc(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 s=nw(e,t,n);return t.fragmentLayoutConstraints.push(new ew(e,i,s)),N(e)})}function Pc(e,t){return e.thenAsync(i=>Nc(i,t))}function iw(e,t){let i=B("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let s=Nc(n,t);return n=n.parent,s.thenReturn(!0)}else return N(!1)}).then(()=>{i.finish(!0)}),i.result()}function nw(e,t,i){let n=e.viewNode;n.appendChild(i);let s=no(i,t,e.vertical);return n.removeChild(i),s}var sw=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},ps=class extends ca{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]}},Vs=class Tc extends $u{constructor(t,i,n,s,r){super(t),this.layoutContext=i,this.clientLayout=n,this.layoutConstraint=s,this.pageFloatLayoutContext=r,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===Tc&&Vg(this),this.last=t.lastChild,this.viewDocument=t.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(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=B("openAllViews"),n=t.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let s=n.length-1,r=null;return i.loop(()=>{for(;s>=0;){let o=r,a=n[s];if(r=Os(a,o),s===n.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),s==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(t),r.after=t.after,r.preprocessedTextContent=t.preprocessedTextContent,r.after))break;let l=this.layoutContext.setCurrent(r,s==0&&r.offsetInNode==0);if(s--,l.isPending())return l}return N(!1)}).then(()=>{i.finish(r)}),i.result()}calculateOffsetInNodeForNodeContext(t){return t.preprocessedTextContent?fg(t.preprocessedTextContent,t.offsetInNode):t.offsetInNode}maybePeelOff(t,i){var n,s;if(t.firstPseudo&&t.inline&&!t.after&&t.firstPseudo.count==0&&t.viewNode.nodeType!=1){let r=t.viewNode.textContent,o=r.match(Is),a=o?o[0].length:0;if(!o&&((n=t.sourceNode)==null?void 0:n.nodeType)===3&&((s=t.sourceNode.nextSibling)==null?void 0:s.nodeType)===3&&r===t.sourceNode.textContent){let l=r+t.sourceNode.nextSibling.textContent,h=l.match(Is);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,s=B("buildViewToNextBlockEdge");return s.loopWithFrame(r=>{var o;if(t.viewNode&&!Bi(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(Ms(l,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(t,0).then(a=>{let l=a;l!==t&&(t=l,Bi(t)||i.push(t.copy())),this.nextInTree(t).then(h=>{if(t=h,!t){r.breakLoop();return}(n||!this.layoutConstraint.allowLayout(t))&&(n=!0,t=t.modify(),t.overflow=!0),this.isFloatNodeContext(t)&&(Di(t.floatReference)||t.floatSide==="footnote")?this.layoutFloatOrFootnote(t).then(u=>{if(t=u,this.pageFloatLayoutContext.isInvalidated()&&(t=null),!t){r.breakLoop();return}r.continueLoop()}):t.inline?r.continueLoop():r.breakLoop()})})}).then(()=>{s.finish(t)}),s.result()}nextInTree(t,i){let n=this.layoutContext.nextInTree(t,i);return Pc(n,this)}buildDeepElementView(t){if(!t.viewNode)return N(t);let i=[],n=t.sourceNode,s=B("buildDeepElementView");return s.loopWithFrame(r=>{t.viewNode&&t.inline&&!Bi(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,r.breakLoop();return}Bi(a)||i.push(a.copy())}this.nextInTree(a).then(l=>{t=l,!t||t.sourceNode==n?r.breakLoop():this.layoutConstraint.allowLayout(t)?r.continueLoop():(t=t.modify(),t.overflow=!0,this.stopAtOverflow?r.breakLoop():r.continueLoop())})})}).then(()=>{i.length>0&&this.postLayoutBlock(t,i),s.finish(t)}),s.result()}createFloat(t,i,n,s){let r=this.viewDocument.createElement("div");return this.vertical?(s>=this.height&&(s-=.1),s<1&&(s=0),T(r,"height",`${n}px`),T(r,"width",`${s}px`)):(n>=this.width&&(n-=.1),n<1&&(n=0),T(r,"width",`${n}px`),T(r,"height",`${s}px`)),T(r,"float",i),T(r,"clear",i),this.element.insertBefore(r,t),r}killFloats(){let t=this.element.firstChild;for(;t;){let i=t.nextSibling;if(t.nodeType==1){let n=t,s=n.style.cssFloat;if(s=="left"||s=="right"||s==="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(),s=this.vertical?this.getBottomEdge():this.getRightEdge(),r=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",s-o.x2,a),o.x1<s&&o.x2>n?r=o:r||T(o.right,"float","none")}if(r){let o=i[i.length-1],a=this.vertical?-this.getLeftEdge():this.getBottomEdge();r!==o&&o.y2>=a&&(this.footnoteEdge=this.vertical?-r.y2:r.y2)}}calculateEdge(t,i,n,s){let r;if(t&&Fi(t.viewNode))return NaN;if(t&&t.after&&!t.inline&&(r=Ti(t,this.clientLayout,0,this.vertical),!isNaN(r)))return r;t=i[n];let o=s-t.boxOffset;for(;;){if(r=Ti(t,this.clientLayout,o,this.vertical),!isNaN(r))return r;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 wr(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 wr(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 wr(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=B("layoutFloat"),n=t.viewNode,s=wl(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(r=>{let o=Pt(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 I=Pt(this.clientLayout,E,this.vertical);h=Math.max(this.rtl?this.getEndEdge(I):this.getStartEdge(I),h),u=Math.min(this.rtl?this.getStartEdge(I):this.getEndEdge(I),u),d.viewNode.removeChild(E);let V=this.vertical?l.y2-l.y1:l.x2-l.x1;s=="left"?u=Math.max(u,h+V):h=Math.min(h,u-V),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=As(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,s),this.vertical&&(l=su(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=Pt(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=As(p)),nf(p,this.bands,f,null,s),this.createFloats(),s=="left"?this.leftFloatEdge=y:this.rightFloatEdge=y,this.bottommostFloatTop=C,this.updateMaxReachedAfterEdge(y),i.finish(r)):(t=t.modify(),t.overflow=!0,i.finish(t))}),i.result()}setupFloatArea(t,i,n,s,r,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),r.adjustPageFloatArea(t,l,this),t.init();let d=!!a.setFloatAreaDimensions(t,i,n,s,!0,!a.hasFloatFragments(),o);return d?(t.killFloats(),t.init()):l.element.parentNode.removeChild(h),d}createPageFloatArea(t,i,n,s,r){let o=this.element.ownerDocument.createElement("div");T(o,"position","absolute");let a=this.pageFloatLayoutContext.getPageFloatLayoutContext(t.floatReference),l=new cn(null,Fe.COLUMN,null,this.pageFloatLayoutContext.flowName,t.nodePosition,null,null),h=a.getContainer(),u=new aw(i,o,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,l,h);return l.setContainer(u),this.setupFloatArea(u,t.floatReference,i,n,s,r)?u:null}layoutSinglePageFloatFragment(t,i,n,s,r,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,r,u),p={floatArea:d,pageFloatFragment:null,newPosition:null};if(!d)return N(p);let f=B("layoutSinglePageFloatFragment"),m=!1,g=0;return f.loopWithFrame(w=>{if(g>=t.length){w.breakLoop();return}let v=t[g],y=new oi(v.nodePosition);d.layout(y,!0).then(C=>{p.newPosition=C,!C||s?(g++,w.continueLoop()):(m=!0,w.breakLoop())})}).then(()=>{if(!m){let w=l.setFloatAreaDimensions(d,h.floatReference,i,o,!1,s,u);if(!w)m=!0;else{let v=r.createPageFloatFragment(t,w,n,d,!!p.newPosition);l.addPageFloatFragment(v,!0),p.pageFloatFragment=v}}f.finish(p)}),f.result()}layoutPageFloatInner(t,i,n,s){let r=this.pageFloatLayoutContext,o=t.float;r.stashEndFloatFragments(o);function a(h,u){u?r.removePageFloatFragment(u,!0):h&&h.element.parentNode.removeChild(h.element),r.restoreStashedFragments(o.floatReference),r.deferPageFloat(t)}let l=B("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([t],o.floatSide,o.clearSide,!r.hasFloatFragments(),i,n,s).then(h=>{let u=h.floatArea,d=h.pageFloatFragment,p=h.newPosition;d?this.layoutStashedPageFloats(o.floatReference,[s]).then(f=>{if(f){if(r.addPageFloatFragment(d),r.discardStashedFragments(o.floatReference),p){let m=new bl(o,p.primary);r.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,s=n.getStashedFloatFragments(t),r=[],o=[],a=!1,l=B("layoutStashedPageFloats"),h=0;return l.loopWithFrame(u=>{if(h>=s.length){u.breakLoop();return}let d=s[h];if(i.includes(d)){h++,u.continueLoop();return}let p=new ji().findByFloat(d.continuations[0].float);this.layoutSinglePageFloatFragment(d.continuations,d.floatSide,d.clearSide,!1,p,null).then(f=>{let m=f.floatArea;m&&r.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)}),r.forEach(u=>{let d=u.element;d&&d.parentNode&&d.parentNode.removeChild(d)})):s.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(Xi,"1"),t.floatSide==="footnote"&&this.layoutContext.applyPseudoelementStyle(t,"footnote-call",n),i.appendChild(n),i.removeChild(t.viewNode);let s=t.modify();return s.after=!0,s.viewNode=n,s}resolveFloatReferenceFromColumnSpan(t,i,n){let s=B("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,o=r.getPageFloatLayoutContext(Fe.REGION);return r.getContainer().width<o.getContainer().width&&t===Fe.COLUMN?i===b.auto?this.buildDeepElementView(n.copy()).then(a=>{let l=a.viewNode,h=ra(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?s.finish(Fe.REGION):s.finish(t)}):i===b.all?s.finish(Fe.REGION):s.finish(t):s.finish(t),s.result()}layoutPageFloat(t){let i=this.pageFloatLayoutContext,n=new ji().findByNodeContext(t),s,r=i.findPageFloatByNodePosition(t.toNodePosition());return r?s=N(r):s=n.createPageFloat(t,i,this),s.thenAsync(o=>{let a=Bs(t,0),l=this.setFloatAnchorViewNode(t),h=n.findPageFloatFragment(o,i),u=new bl(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=Ti(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 s=B("processLineStyling"),r=n.concat([]);n.splice(0,n.length);let o=0,a=t.firstPseudo;return a.count==0&&(a=a.outer),s.loopWithFrame(l=>{if(!a){l.breakLoop();return}let h=this.findLinePositions(r),u=a.count-o;if(h.length<=u){l.breakLoop();return}let d=this.findAcceptableBreakInside(r,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,r=[],this.buildViewToNextBlockEdge(t,r).then(f=>{i=f,l.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(n,r),s.finish(i)}),s.result()}isLoneImage(t){return t.length!=2&&this.breakPositions.length>0?!1:t[0].sourceNode==t[1].sourceNode&&gi[t[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(t){let i=0,n=0;for(let s=t.length-1;s>=0;s--){let r=t[s];if(!r.after||!r.viewNode||r.viewNode.nodeType!=1)break;let o=this.getComputedMargin(r.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=B("layoutBreakableBlock"),n=[];return this.buildViewToNextBlockEdge(t,n).then(s=>{let r=n.length-1;if(r<0){i.finish(s);return}this.postLayoutBlock(s,n);let o=this.calculateEdge(s,n,r,n[r].boxOffset),a=!1;if(!s||!Fi(s.viewNode)){let h=Vi(s,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=s)}s==null&&(o+=this.getTrailingMarginEdgeAdjustment(n)),this.updateMaxReachedAfterEdge(o);let l;t.firstPseudo?l=this.processLineStyling(t,s,n):l=N(s),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){At("POST_LAYOUT_BLOCK").forEach(n=>{n(t,i,this)})}findEndOfLine(t,i,n){let s=this.vertical?t-1:t+1,r=0,o=i[0].boxOffset,a=r,l=i.length-1,h=i[l].boxOffset,u;for(;o<h;){u=o+Math.ceil((h-o)/2),a=r;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<=s:p>=s){for(h=u-1;i[a].boxOffset==u;)a--;l=a}else n&&this.updateMaxReachedAfterEdge(p),o=u,r=a}return{nodeContext:i[a],index:o,checkPointIndex:a}}findAcceptableBreakInside(t,i,n){var s,r,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&&((s=h.parentElement)==null?void 0:s.localName)!=="viv-ts-inner"){let u=h;l=this.resolveTextNodeBreaker(l).breakTextNode(u,l,a.index,t,a.checkPointIndex,n)}else{let u=xl(l);if(u){if(((r=this.breakPositions)==null?void 0:r[0])instanceof ps&&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&&(Ue(d,l.parent.whitespace)||Li(d));)d=d.previousSibling;if(d)break;l=l.parent}}}return this.clearOverflownViewNodes(l,!1),l}resolveTextNodeBreaker(t){return At("RESOLVE_TEXT_NODE_BREAKER").reduce((i,n)=>n(t)||i,Us.instance)}getRangeBoxes(t,i){let n=[],s=t.ownerDocument.createRange(),r=!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||r):h=!1);let p=o.nodeType===1?o:null;p?r?r=!1:ua(p)?u=!l:!p.firstChild||gi[p.localName]||/^r(uby|[bt]c?)$/.test(p.localName)||Wg(this.clientLayout.getElementComputedStyle(p).display)?(u=!l,u?(p.localName==="ruby"&&o.firstChild&&(o=o.firstChild),s.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:(s.setStartBefore(o),l=!0)),a=o),d||(d=o.nextSibling,d||(r=!0,d=o.parentNode)),o=d}while(u&&h);if(l){s.setEndAfter(a);let d=this.clientLayout.getRangeClientRects(s);Ju(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?Cg:Sg);let s=0,r=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*s?d=h*(this.getAfterEdge(u)-s)/p:h*this.getAfterEdge(u)>h*r?d=h*(r-this.getBeforeEdge(u))/p:d=1}if(a==0||d>=.6||d>=.2&&this.getStartEdge(u)>=o-1){o=this.getEndEdge(u),this.vertical?(s=a==0?u.right:Math.max(s,u.right),r=a==0?u.left:Math.min(r,u.left)):(s=a==0?u.top:Math.min(s,u.top),r=a==0?u.bottom:Math.max(r,u.bottom)),a++,l++;continue}}if(a>0&&(i.push(r),a=0),l>=n.length)break}return i.sort(Ah),this.vertical&&i.reverse(),i}calculateClonedPaddingBorder(t){let i=0;for(let n=t;n;n=n.parent)if(!n.inline&&ln(n.viewNode)){let s=this.getComputedPaddingBorder(n.viewNode);i+=n.vertical?-s.left:s.bottom,n.display==="table"&&(i+=(n.vertical?-1:1)*n.blockBorderSpacing)}return i}getOffsetByRepetitiveElements(t){let i;return t?i=t.calculateOffset(this):i=Vi(null,this.collectElementsOffset()),i.current}findBoxBreakPosition(t,i){let n=this.element.parentNode,s=this.element.nextSibling;n.removeChild(this.element),n.insertBefore(this.element,s);let r=t.checkPoints,o=r[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(r),d=this.footnoteEdge-h,p=this.getBoxDir(),f=this.getOffsetByRepetitiveElements(t);d-=p*f;let m=this.findFirstOverflowingEdgeAndCheckPoint(r);isNaN(m.edge)&&(m.edge=p*(1/0));let g=ni(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=ni(u.length,C=>this.vertical?u[C]<d:u[C]>d));let v=r[r.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,Ti(i,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(t){let i=t.findIndex(s=>s.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 s=new rn().find(t.formattingContext).finishBreak(this,t,i,n);return s||(s=pa.finishBreak(this,t,i,n)),s}findAcceptableBreakPosition(){let t=null,i=null,n=0,s=0;do{n=s,s=Number.MAX_VALUE;for(let r=this.breakPositions.length-1;r>=0&&!i;--r){t=this.breakPositions[r],i=t.findAcceptableBreak(this,n);let o=t.getMinBreakPenalty();o>n&&(s=Math.min(s,o))}}while(s>n&&!i&&this.forceNonfitting);return{breakPosition:i?t:null,nodeContext:i}}doFinishBreak(t,i,n,s){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!i)return N(t);let r=B("doFinishBreak"),o=!1;if(!t){if(this.forceNonfitting)return H.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(()=>{r.finish(a)})):r.finish(a)}),r.result();t=n,o=!0,this.computedBlockSize=s}return this.finishBreak(t,o,!0).then(()=>{r.finish(t)}),r.result()}isBreakable(t){for(let i=t;i;i=i.parent)if(Li(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(Li(o.viewNode))return!1;if(Fi(t.viewNode))return!1;let n=Ti(t,this.clientLayout,0,this.vertical),s=Vi(t,this.collectElementsOffset()),r=this.isOverflown(n+(this.vertical?-1:1)*s.minimum);if(this.isOverflown(n+(this.vertical?-1:1)*s.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=t;else if(i){let o=n+this.getTrailingMarginEdgeAdjustment(i),a=this.footnoteEdge-this.getBoxDir()*s.current;n=this.vertical?Math.min(n,Math.max(o,a)):Math.max(n,Math.min(o,a))}return this.updateMaxReachedAfterEdge(n),r}checkOverflowAndSaveEdgeAndBreakPosition(t,i,n,s){if(!t||Fi(t.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(t,i);return(n||!r)&&this.saveEdgeBreakPosition(t,s,r),r}applyClearance(t){if(!t.viewNode.parentNode||t.floatReference!==Fe.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 s=Pt(this.clientLayout,n,this.vertical),r=this.getBeforeEdge(s),o=this.getBoxDir(),a=t.clearSide==="same"?t.floatSide:t.clearSide,l=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(a)?wl(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(r*o+d>u*o)return t.viewNode.parentNode.removeChild(n),!1;{let p=Math.max(1,(u-r)*o);this.vertical?n.style.width=`${p}px`:n.style.height=`${p}px`,s=Pt(this.clientLayout,n,this.vertical);let f=this.getAfterEdge(s);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!!(Gg(t)||wi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))}skipEdges(t,i,n){var s;let r=t.after?(s=t.parent)==null?void 0:s.formattingContext:t.formattingContext;if(r&&!this.isBFC(r))return N(t);let o=B("skipEdges"),a=!n&&i&&t&&t.after,l=n,h=null,u=[],d=[],p=!1;function f(){return!!n||!i&&et(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&&(Ue(y,v.parent.whitespace)||Li(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 rn().find(t.formattingContext);do{if(!t.viewNode)break;if(t.inline&&t.viewNode.nodeType!=1){if(Ue(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=Fs(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?xl(h):this.breakPositions[this.breakPositions.length-1]instanceof ps)&&this.saveEdgeBreakPosition(t.copy(),l,!1),!this.isBFC(t.formattingContext)||wi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t.formattingContext)||this.isFloatNodeContext(t)||t.flexContainer||!t.nodeShadow&&!t.sourceNode.firstElementChild&&Ue(t.sourceNode.firstChild,t.whitespace)){u.push(t.copy()),l=it(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,I=E.style;if(t.after){I.columnFill==="balance"&&E.getAttribute("data-vivliostyle-column-fill")==="auto"&&(I.columnFill="auto"),t.floatSide&&(l=l??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let V=t.sourceNode;if(V.localName==="svg"||V.localName==="math"||V.getAttribute("data-math-typeset")==="true"){p=!1,h=t.copy(),d.push(h),l=it(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=it(l,t.breakAfter),I&&!(this.zeroIndent(I.paddingBottom)&&this.zeroIndent(I.borderBottomWidth))&&(d=[h])}else{if(u.push(t.copy()),l=it(l,t.breakBefore),h&&et(l)&&Hg(h.viewNode,t.viewNode),(t.pageType!=((v=t.parent)==null?void 0:v.pageType)||!et(l))&&!this.layoutConstraint.allowLayout(t)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,l),t=t.modify(),t.overflow=!0,this.stopAtOverflow)){w.breakLoop();return}let V=t.viewNode.localName;if(gi[V]){f()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,l)&&(t=(this.stopAtOverflow&&h||t).modify(),t.overflow=!0),w.breakLoop();return}I&&!(this.zeroIndent(I.paddingTop)&&this.zeroIndent(I.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):et(l)&&(this.pageBreakType=l),w.breakLoop()}).then(()=>{h&&(this.lastAfterPosition=h.toNodePosition()),o.finish(t)}),o.result()}skipTailEdges(t){let i=t.copy(),n=B("skipEdges"),s=null,r=!1;return n.loopWithFrame(o=>{for(;t;){do{if(!t.viewNode)break;if(t.inline&&t.viewNode.nodeType!=1){if(Ue(t.viewNode,t.whitespace))break;if(!t.after){et(s)&&(this.pageBreakType=s),o.breakLoop();return}}if(!t.after&&(this.isFloatNodeContext(t)||t.flexContainer)){s=it(s,t.breakBefore),et(s)&&(this.pageBreakType=s),o.breakLoop();return}if(t.viewNode.nodeType!=1)break;let l=t.viewNode.style;if(t.after){if(r){if(et(s)){this.pageBreakType=s,o.breakLoop();return}s=null}r=!1,s=it(s,t.breakAfter)}else{s=it(s,t.breakBefore);let h=t.viewNode.localName;if(gi[h]){et(s)&&(this.pageBreakType=s),o.breakLoop();return}if(l&&!(this.zeroIndent(l.paddingTop)&&this.zeroIndent(l.borderTopWidth))){o.breakLoop();return}}r=!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 Di(t.floatReference)||t.floatSide==="footnote"?this.layoutPageFloat(t):this.layoutFloat(t)}layoutNext(t,i,n){let s=B("layoutNext");return this.skipEdges(t,i,n||null).then(r=>{if(t=r,!t||this.pageBreakType||this.stopByOverflow(t))s.finish(t);else{let o=t.formattingContext;new rn().find(o).layout(t,this,i).thenFinish(s)}}),s.result()}clearOverflownViewNodes(t,i){if(t)for(let n=t.parent;t;t=n,n=n?n.parent:null){let s=(n||t).formattingContext;new rn().find(s).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(),s=this.originY+this.top+this.getInsetTop();this.box=new bt(n,s,n+this.width,s+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=Jp(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 s=t.copy(),r=new rn().find(t.formattingContext),o=this.calculateClonedPaddingBorder(s),a=r.createEdgeBreakPosition(s,i,n,this.computedBlockSize+o);this.breakPositions.push(a)}saveBoxBreakPosition(t){let i=t[0].breakPenalty;if(i){let s=t[0];for(;s.parent&&s.inline;)s=s.parent;i=s.breakPenalty}let n=new ps(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);Ug(this)&&la(this);let s=B("layout");return this.openAllViews(t.primary).then(r=>{let o=null;if(r.viewNode)o=r.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(r,this).then(l=>{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()){s.finish(null);return}if(!h)s.finish(null);else{this.overflown=!0;let d=new oi(h.toNodePosition());s.finish(d)}})})})}),s.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(t){let i=B("doFinishBreakOfFragmentLayoutConstraints"),n=[].concat(this.fragmentLayoutConstraints);n.sort((r,o)=>r.getPriorityOfFinishBreak()-o.getPriorityOfFinishBreak());let s=0;return i.loop(()=>s<n.length?n[s++].finishBreak(t,this).thenReturn(!0):N(!1)).then(()=>{i.finish(!0)}),i.result()}doLayout(t,i,n){let s=B("doLayout"),r=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,s.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)){r=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(()=>{s.finish({nodeContext:t,overflownNodeContext:r})}),s.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=B("redoLayout"),s=0,r=null,o=!0;return n.loopWithFrame(a=>{if(s<t.length){let l=t[s++];this.layout(l,o).then(h=>{o=!1,h?(r=h,a.breakLoop()):a.continueLoop()});return}a.breakLoop()}).then(()=>{n.finish(r)}),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(wi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(n)){let s=n.getRepetitiveElements();t.push(s)}if(Ls.isInstanceOfAfterIfContinuesLayoutConstraint(n)){let s=n.getRepetitiveElements();t.push(s)}si.isInstanceOfTableRowLayoutConstraint(n)&&n.getElementsOffsetsForTableCell(this).forEach(s=>{t.push(s)})});return t}},xa=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 s=this;this.column.openAllViews=function(r){return Vs.prototype.openAllViews.call(this,r).thenAsync(o=>(s.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 jn(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 ri(e.toNodePosition(),this.column.lastAfterPosition)}getColumnElement(){return this.column.element}getColumn(){return this.column}},Us=class{breakTextNode(e,t,i,n,s,r){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 s=/[\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?"":s+_l(n)),s){let r=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=r.slice(0,i+1)+s+r.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let s=t.charAt(i);i++;let r=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&Wa(s)&&Wa(r)?_l(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};c(Us,"instance");Us.instance=new Us;function _l(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var rw=class extends fa{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 ow(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||Xg()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Qu(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}},ow=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=B("DefaultLayoutMode.doLayout");return iw(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(s=>s.nextCandidate(e))),i.fragmentLayoutConstraints.forEach(s=>{s.postLayout(n,e,t,i)}),n}},aw=class extends Vs{constructor(e,t,i,n,s,r,o){super(t,i,n,s,r),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 s(r,o){r.forEach(a=>{let l=Kt(e,a);if(l&&l.charAt(l.length-1)==="%"){let h=parseFloat(l),u=o*h/100;T(e,a,`${u}px`)}})}s(["width","max-width","min-width"],i),s(["height","max-height","min-height"],n),s(["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(r=>{Kt(e,r)==="auto"&&T(e,r,"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=Kt(t,"height");n!==""&&n!=="auto"&&T(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=Kt(t,"width");n!==""&&n!=="auto"&&T(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=Pt(this.clientLayout,e,this.vertical),n=this.floatMargins[t];return this.vertical?n.top+i.height+n.bottom:n.left+i.width+n.right}))}},vi=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||ro.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new lw(e,this.rootSourceNode),ro.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},lw=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=Bs(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=Bs(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=no(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=no(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 s=t.viewNode.ownerDocument,r=t.viewNode,o=s.createElement("div");r.appendChild(o);let a=new xa(n,o,t),l=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new oi(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,r.removeChild(o),this.moveChildren(o,r,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(Xi,"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(s=>s.nodeContext.sourceNode===e.sourceNode&&s.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let s=i(e);return t.push({nodeContext:e,result:s}),s}}isAfterNodeContextOf(e,t,i){let n=[];for(let s=e;s;s=s.parentNode){if(t.sourceNode===s)return t.after;n.push(s)}for(let s=t.sourceNode;s;s=s.parentNode){let r=n.indexOf(s);if(r>=0)return i?r===0:!1;for(let o=s;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}},Ic=class{constructor(e){this.formattingContext=e}accept(e,t){return!!e}postLayout(e,t,i,n){let s=this.formattingContext.getRepetitiveElements();return s&&(i.clientLayout,s.doneInitialLayout||(s.updateHeight(i),s.doneInitialLayout=!0)),n}},Ac=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},hw=class extends Ic{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},uw=class extends Ac{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new Sa(e)),this.processor.doLayout(e,t)}},Sa=class Rc{constructor(t){c(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),c(this,"nodeContext");let i=zt(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||Fi(this.nodeContext.viewNode)||!s.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,s){let r=this.getRepetitiveElements();r&&t&&s.stopAtOverflow&&(i==null||r.isAfterLastContent(i))&&r.preventSkippingFooter()}finishBreak(t,i){let n=zt(this.nodeContext.formattingContext),s=this.getRepetitiveElements();if(!s)return N(!0);let r=this.nodeContext;return gw(n,r,i).thenAsync(()=>mw(n,r,i).thenAsync(()=>(s.prepareLayoutFragment(),N(!0))))}getRepetitiveElements(){return zt(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof Rc?zt(this.nodeContext.formattingContext)===zt(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},cw=class extends fa{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 hw(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new uw(this.formattingContext,this.processor))}},dw=class extends vn{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 vn.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):vn.prototype.afterNonInlineElementNode.call(this,e)}},pw=class extends Oi{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=zt(e.formattingContext);return n.getRootViewNode(e)?(i&&Fc(e.parent,t),e.belongsTo(n)?Oi.prototype.layout.call(this,e,t,i):new cw(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=ww(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=zt(e.formattingContext),n=B("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=zt(e.formattingContext),n=new dw(i,t);return new so(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=zt(e.formattingContext),n=B("doLayout"),s=t.layoutContext.nextInTree(e,!1);return Pc(s,t).then(r=>{let o=r;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 Oi.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){Oi.prototype.clearOverflownViewNodes(e,t,i,n)}};function fw(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof vi&&!i.belongsTo(n)&&t(n,i)}}function Fc(e,t){e&&fw(e.after?e.parent:e,(i,n)=>{si.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new Sa(n))})}function gw(e,t,i){let n=e.getRepetitiveElements();if(n){let s=e.getRootNodeContext(t);if(s.viewNode){let r=s.viewNode.firstChild;return n.appendHeaderToFragment(s,r,i)}}return N(!0)}function mw(e,t,i){let n=e.getRepetitiveElements();if(n&&!n.isSkipFooter){let s=e.getRootNodeContext(t);if(s.viewNode)return n.appendFooterToFragment(s,null,i)}return N(!0)}function ww(e){let t=e.formattingContext;return!t||!(t instanceof vi)?null:t}function zt(e){return e instanceof vi,e}var bw=new pw;kt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof vi&&!si.isInstanceOfTableFormattingContext(e)?bw:null);var Lc=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))}},yw=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}},vw=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 xa(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}},Sw=class{constructor(e,t){this.viewNode=e,this.side=t}},Cw=class extends jn{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 ca{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(),s=n.every(r=>!!r.nodeContext)&&n.some((r,o)=>{let a=i[o].pseudoColumn,l=r.nodeContext;return!a.isStartNodeContext(l)&&!a.isLastAfterNodeContext(l)});return this.beforeNodeContext.overflow=n.some(r=>r.nodeContext&&r.nodeContext.overflow),s?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(r=>r.cellNodeContext.breakPenalty));let s=i.some((r,o)=>r.breakPosition instanceof ps&&n[o].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((r,o)=>{let a=r.breakPosition.getMinBreakPenalty();s&&r.breakPosition instanceof jn&&r.breakPosition.overflows&&a>=3&&(n[o].column.checkOverflowAndSaveEdge(r.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)}},Hi=class extends vi{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 Lc(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,s=this.getRowSlots(e),r=0;for(;s[r];)r++;for(;e<n;e++){s=this.getRowSlots(e);for(let o=r;o<r+t.colSpan;o++){let a=s[o]=new vw(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=Pt(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 s=this.slots[i][n];if(s.cell===t)return{rowIndex:s.rowIndex,columnIndex:s.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,s)=>{if(s>=e.rowIndex)return i;let r=n[e.columnIndex]&&this.getCellFragmentOfCell(n[e.columnIndex].cell);return!r||t.includes(r)||(this.collectElementsOffsetFromColumn(r.pseudoColumn.getColumn(),i),t.push(r)),i},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(t=>{t.cells.forEach((i,n)=>{e[n]||(e[n]={collected:[],elements:[]});let s=e[n],r=this.getCellFragmentOfCell(i);!r||s.collected.includes(r)||(this.collectElementsOffsetFromColumn(r.pseudoColumn.getColumn(),s.elements),s.collected.push(r))})}),[new Ew(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(wi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}si.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=e}},Ew=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 s=Vi(e,n);i=Math.max(i,t(s))}),i}};function St(e){return e instanceof Hi,e}function Nw(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Pw(e){return e==="table"||e==="inline-table"}function Ml(e){return Nw(e)||Pw(e)}function Bc(e,t,i){let n=e.nodeContext,s=n.display,r=n.parent?n.parent.display:null,o=!1;if(r==="inline-table"&&!(n.formattingContext instanceof Hi)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof Hi){o=a.formattingContext===t;break}}return o||s==="table-row"&&!Ml(r)||s==="table-cell"&&r!=="table-row"&&!Ml(r)||n.formattingContext instanceof Hi&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,N(!0))):null}var Tw=class extends vn{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=Bc(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=e.nodeContext,s=n.display,r=t.getRepetitiveElements();switch(s){case"table":t.inlineBorderSpacing=n.inlineBorderSpacing;break;case"table-caption":{let o=new Sw(n.viewNode,n.captionSide);t.captions.push(o);break}case"table-header-group":return r.isHeaderRegistered()||(this.inHeaderOrFooter=!0,r.setHeaderNodeContext(n)),N(!0);case"table-footer-group":return r.isFooterRegistered()||(this.inHeaderOrFooter=!0,r.setFooterNodeContext(n)),N(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,n.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new Lc(this.rowIndex,n.sourceNode)),r.firstContentSourceNode||(r.firstContentSourceNode=n.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,s=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let r=s.getElementComputedStyle(t.getRootViewNode(i));t.tableWidth=parseFloat(r[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 r=i.viewNode;t.addCell(this.rowIndex,new yw(this.rowIndex,this.columnIndex,r)),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&&!Bi(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},Oc=class _c extends vn{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 s=0;s<t.colSpan;s++)n+=i[t.anchorSlot.columnIndex+s];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let s=t.rowIndex,r=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(s,r,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 s=t[n],r=s.cell.rowIndex;if(r<this.currentRowIndex){let o=i[r];o||(o=i[r]=[]),o.push(s),t.splice(n,1)}else n++}while(n<t.length);return i}layoutRowSpanningCellsFromPreviousFragment(t){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),s=n.reduce(d=>d+1,0);if(s===0)return N(!0);let r=this.column.layoutContext,o=t.nodeContext;o.viewNode.parentNode.removeChild(o.viewNode);let a=B("layoutRowSpanningCellsFromPreviousFragment"),l=N(!0),h=0,u=[];return n.forEach(d=>{l=l.thenAsync(()=>{let p=Os(d[0].cellNodePosition.steps[1],o.parent);return r.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=Os(y.steps[0],p);return C.offsetInNode=y.offsetInNode,C.after=y.after,C.fragmentIndex=y.steps[0].fragmentIndex+1,r.setCurrent(C,!1).thenAsync(()=>{let E=w.breakChunkPosition;for(let I=0;I<v.colSpan;I++)u.push(m+I);return m+=v.colSpan,this.layoutCell(v,C,E).thenAsync(()=>(C.viewNode.rowSpan=v.rowIndex+v.rowSpan-this.currentRowIndex+s-h,N(!0)))})})}),f.thenAsync(()=>(g(i.getColumnCount()),h++,N(!0)))})})}),l.then(()=>{r.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],s=this.column.layoutContext.xmldoc.getElementOffset(n.node);Jm(s,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 s=i.copy().modify();s.after=!0,t.nodeContext=s;let r=B("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=Bs(a,0);return N(new oi(l))});return o.then(a=>{this.layoutCell(n,i,a).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,r.finish(!0)})}),r.result()}startNonInlineBox(t){let i=Bc(t,St(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,s=this.formattingContext.getRepetitiveElements(),r=n.display;return r==="table-header-group"&&s&&s.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,N(!0)):r==="table-footer-group"&&s&&s.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,N(!0)):r==="table-row"?this.startTableRow(t):r==="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 s=new kw(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(s)}return N(!0)}afterNonInlineElementNode(t){let i=t.nodeContext,n=this.formattingContext.getRepetitiveElements(),s=i.display;if(s==="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"):s==="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")),s&&_c.ignoreList[s])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(Oc,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Iw=Oc,Ln=[];function Aw(e){let t=Ln.findIndex(n=>n.root===e),i=Ln[t];return i?i.tableLayoutOption:null}function Rw(e){let t=Ln.findIndex(i=>i.root===e);t>=0&&Ln.splice(t,1)}var Mc=class{layoutEntireTable(e,t){let i=St(e.formattingContext),n=new Tw(i,t);return new so(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let s=e.ownerDocument,r=s.createElement("tr"),o=[];for(let l=0;l<t;l++){let h=s.createElement("td");r.appendChild(h),o.push(h)}e.parentNode.insertBefore(r,e.nextSibling);let a=o.map(l=>{let h=Pt(n,l,i),u=i?h.height:h.width;return Math.ceil(u)});return e.parentNode.removeChild(r),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 s=i.firstElementChild;for(;s;){if(s.localName==="col"){let r=s.span;for(s.removeAttribute("span"),n-=r;r-- >1;){let o=s.cloneNode(!0);i.insertBefore(o,s),t.push(o)}t.push(s)}s=s.nextElementSibling}for(;n-- >0;)s=i.ownerDocument.createElement("col"),i.appendChild(s),t.push(s)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let s=n.ownerDocument.createElement("colgroup");t.push(s);for(let r=e.length;r<i;r++){let o=n.ownerDocument.createElement("col");s.appendChild(o),e.push(o)}}}normalizeColGroups(e,t,i){let n=e.vertical,s=e.lastRowViewNode;if(!s)return;e.lastRowViewNode=null;let r=s.ownerDocument.createDocumentFragment(),o=e.getColumnCount();if(!(o>0)){e.colGroups=r;return}let a=e.colWidths=this.getColumnWidths(s,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=>{r.appendChild(u.cloneNode(!0))}),e.colGroups=r}doInitialLayout(e,t){let i=St(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=Aw(e.sourceNode);Rw(e.sourceNode);let s=B("TableLayoutProcessor.doInitialLayout"),r=e.copy();return this.layoutEntireTable(e,t).then(o=>{let a=o.viewNode,l=Pt(t.clientLayout,a,t.vertical),h=t.vertical?l.left:l.bottom;if(h+=(t.vertical?-1:1)*Vi(e,t.collectElementsOffset()).current,!t.isOverflown(h)&&(!n||!n.calculateBreakPositionsInside)){t.breakPositions.push(new Ow(r)),s.finish(o);return}this.normalizeColGroups(i,a,t),i.updateCellSizes(t.clientLayout),s.finish(null)}),s.result()}addCaptions(e,t,i){let n=e.captions;n.forEach((s,r)=>{s&&(t.insertBefore(s.viewNode,i),s.side==="top"&&(n[r]=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=St(e.formattingContext),n=i.getRootViewNode(e),s=n.firstChild;this.addCaptions(i,n,s),this.addColGroups(i,n,s);let r=new Iw(i,t),o=new so(r,t.layoutContext),a=B("TableFormattingContext.doLayout");return o.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=St(e.formattingContext),s=n.getRootViewNode(e),r=B("TableFormattingContext.layout"),o;return s?(i&&Fc(e.parent,t),o=new Lw(n,this).layout(e,t)):o=t.buildDeepElementView(e),o.then(a=>{r.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"))}),r.result()}createEdgeBreakPosition(e,t,i,n){return new Cw(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return Tr(e),!1}finishBreak(e,t,i,n){let s=St(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let r=s.findRowIndexBySourceNode(t.sourceNode);s.cellBreakPositions=[];let o;if(t.after?o=s.getRowSpanningCellsOverflowingTheRow(r):o=s.getCellsFallingOnRow(r),o.length){let a=B("TableLayoutProcessor.finishBreak"),l=0;return a.loopWithFrame(h=>{if(l===o.length){h.breakLoop();return}let u=o[l++],d=s.getCellFragmentOfCell(u),p=d.findAcceptableBreakPosition().nodeContext,f=d.cellNodeContext,m=f.toNodePosition(),g=new oi(p.toNodePosition());s.cellBreakPositions.push({cellNodePosition:m,breakChunkPosition:g,cell:u});let w=f.viewNode;d.column.layoutContext.processFragmentedBlockEdge(d.cellNodeContext),r<u.rowIndex+u.rowSpan-1&&(w.rowSpan=r-u.rowIndex+1),d.empty?h.continueLoop():d.pseudoColumn.finishBreak(p,!1,!0).then(()=>{Fw(d,s,p),h.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),Tr(t),s.finishFragment(),a.finish(!0)}),a.result()}}return Tr(t),s.finishFragment(),pa.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){Oi.prototype.clearOverflownViewNodes(e,t,i,n)}};function Fw(e,t,i){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let s=t.vertical,r=e.column,o=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,l=Pt(r.clientLayout,a,s),h=r.getComputedPaddingBorder(a);if(s){let u=l.right-r.footnoteEdge-n.calculateOffset(i)-h.right;T(o,"max-width",`${u}px`)}else{let u=r.footnoteEdge-n.calculateOffset(i)-l.top-h.top;T(o,"max-height",`${u}px`)}}function Tr(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),s=i[i.length-1],r=Array.from(t.children).indexOf(s),o=Array.from(s.children).reduce((d,p)=>{let f=p.rowSpan;return f>1&&r+f<t.childElementCount?Math.max(d,f):d},0),a=o?t.children[r+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 Lw=class extends fa{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new Bw(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new Mw(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()}},Bw=class extends Ic{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},Ow=class extends jn{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 _w(this.position.sourceNode))}},_w=class zc{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,s){i.sourceNode,Ln.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return N(!0)}equalsTo(t){return t instanceof zc&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},Mw=class extends Ac{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new zw(e);t.fragmentLayoutConstraints.some(s=>n.equalsTo(s))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},zw=class Dc extends Sa{constructor(t){super(t),c(this,"flagmentLayoutConstraintType","TableRow"),c(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||n.pseudoParent||Fi(this.nodeContext.viewNode)||!s.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=St(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(t,i).some(n=>n.constraints.some(s=>s.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,s){let r=St(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,r),this.cellFragmentLayoutConstraints.forEach(o=>{o.constraints.forEach(a=>{a.postLayout(t,o.breakPosition,n,s)})}),!t){let o=r.getRootViewNode(this.nodeContext);new Mc().removeColGroups(r,o),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,s)}finishBreak(t,i){let n=St(this.nodeContext.formattingContext),s=B("finishBreak"),r=this.cellFragmentLayoutConstraints.reduce((a,l)=>a.concat(l.constraints.map(h=>({constraint:h,breakPosition:l.breakPosition}))),[]),o=0;return s.loop(()=>{if(o<r.length){let a=r[o++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return N(!1)}).then(()=>{s.finish(!0)}),s.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 s=[];for(let r=0;r<n;r++)i.cellFragments[r]&&i.cellFragments[r].forEach(o=>{o&&s.push({fragment:o,breakPosition:o.findAcceptableBreakPosition().nodeContext})});return s}getElementsOffsetsForTableCell(t){let i=St(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof Dc?St(this.nodeContext.formattingContext)===St(t.nodeContext.formattingContext):!1}},Dw=new Mc;function Vw(e,t,i,n,s,r){if(!t)return null;if(i===b.table){let o=e.parent;return new Hi(o?o.formattingContext:null,e.sourceNode)}return null}function Uw(e){return e instanceof Hi?Dw:null}kt("RESOLVE_FORMATTING_CONTEXT",Vw);kt("RESOLVE_LAYOUT_PROCESSOR",Uw);function zl(e){return e.reduce((t,i)=>t+i,0)/e.length}function Hw(e){let t=zl(e);return zl(e.map(i=>{let n=i-t;return n*n}))}var $w=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function Bn(e){return e.vertical?e.width:e.height}function On(e,t){e.vertical?e.width=t:e.height=t}var Vc=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,c(this,"originalContainerBlockSize"),this.originalContainerBlockSize=Bn(e)}balanceColumns(e){let t=B("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(s=>{if(this.savePageFloatLayoutContexts(s),this.layoutContainer.clear(),!s){n.breakLoop();return}i.push(this.createTrialResult(s)),n.continueLoop()})}).then(()=>{let n=i.reduce((s,r)=>r.penalty<s.penalty?r:s,i[0]);this.restoreContents(n.layoutResult),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new $w(e,t)}preBalance(e){}postBalance(){On(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)}},xo=1;function Uc(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,s=Math.max.apply(null,n.map(o=>o.computedBlockSize)),r=Math.max.apply(null,n.map(o=>o.getMaxBlockSizeOfPageFloats()));return s>r+xo}function Hc(e,t){var i;let n=e[e.length-1].layoutResult.columns,s=Math.max.apply(null,n.map(r=>isNaN(r.blockDistanceToBlockEndFloats)?r.computedBlockSize:r.computedBlockSize-r.blockDistanceToBlockEndFloats+xo))-xo;if(s<Bn(t)?On(t,s):On(t,Bn(t)-1),t.vertical){let r=parseFloat((i=t.element.style)==null?void 0:i.width);t.originX=r-t.width}}var Ww=class extends Vc{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);On(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 Dl(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return Uc(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!Dl(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):Bn(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Hc(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,Bn(this.layoutContainer)+this.originalContainerBlockSize*.1);On(this.layoutContainer,t)}}};function Dl(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(s=>t>s.computedBlockSize+n)}var Gw=class extends Vc{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 Hw(t)}hasNextCandidate(e){return Uc(e)}updateCondition(e){Hc(e,this.layoutContainer)}};function jw(e,t,i,n,s,r,o){if(t===b.auto)return null;{let a=o.positions.length===0,l=r[r.length-1],h=!!(l&&l.pageBreakType);return a||h?new Ww(i,n,s,e):t===b.balance_all?new Gw(i,n,s):(b.balance,null)}}var Xw=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],qw=new Set(Xw);function Yw(e){return!(e.toLowerCase()==="none"||qw.has(e))}var Kw=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],Zw=new Set(Kw),Jw=["fixed","extends"],Qw=new Set(Jw),y0=Symbol();function Yn(e){return e instanceof ae&&e.name.toLowerCase()!=="none"}function $c(e){return e.name}function eb(e){if(e instanceof ae)return Zw.has(e.name);if(e instanceof Q&&e.values.length===2){let t=e.values[0],i=e.values[1];if(t instanceof ae){let n=t.name;return Qw.has(n)&&(n==="fixed"&&i instanceof Re||n==="extends"&&Yn(i))}}return!1}function tb(e){let t=tt(e,"system");return t instanceof ae&&t.name==="cyclic"}function ib(e){let t=tt(e,"system");if(t instanceof ae&&t.name==="fixed")return!0;if(t instanceof Q&&t.values.length===2){let[i,n]=t.values;return i instanceof ae&&i.name==="fixed"&&n instanceof Re}return!1}function nb(e){let t=tt(e,"system");return t instanceof ae?1:t.values[1].num}function sb(e){let t=tt(e,"system");return t instanceof ae&&t.name==="alphabetic"}function rb(e){let t=tt(e,"system");return t instanceof ae&&t.name==="numeric"}function ob(e){let t=tt(e,"system");return t instanceof ae&&t.name==="additive"}function ab(e){let t=tt(e,"system");if(t instanceof Q&&t.values.length===2){let[i,n]=t.values;return i instanceof ae&&i.name==="extends"&&Yn(n)}return!1}function lb(e){let t=tt(e,"system");return $c(t.values[1])}function Et(e){return e instanceof G||e instanceof ae}function Ut(e){return e instanceof G?e.str:e.name}function Wc(e){if(Et(e))return!0;if(e instanceof Q&&e.values.length===2){let t=e.values[0],i=e.values[1];return Et(t)&&Et(i)}return!1}function hb(e){if(Et(e))return{prefix:Ut(e),suffix:null};{let t=e.values[0],i=e.values[1];return{prefix:Ut(t),suffix:Ut(i)}}}function Vl(e){return e instanceof Re||e instanceof ae&&e.name==="infinite"}function Hs(e,t){return e instanceof Re?e.num:t?-1/0:1/0}var v0=Symbol();function So(e){if(!(e instanceof Q&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(Vl(t)&&Vl(i)))return!1;let n=Hs(t,!0),s=Hs(i,!1);return!(n>s)}function ub(e){return{lower:Hs(e.values[0],!0),upper:Hs(e.values[1],!1)}}function Gc(e){return e instanceof ae&&e.name==="auto"||So(e)||e instanceof qe&&e.values.length>=1&&e.values.every(t=>So(t))}function cb(e){return e instanceof ae?null:(So(e)?[e]:e.values).map(t=>ub(t))}var x0=Symbol();function $s(e){if(!(e instanceof Q&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];return t instanceof Re&&t.num>=0&&Et(i)||Et(t)&&i instanceof Re&&i.num>=0}function Ws(e){let[t,i]=e.values;return t instanceof Re?[t.num,Ut(i)]:[i.num,Ut(t)]}function jc(e){return $s(e)}function db(e){let[t,i]=Ws(e);return{minLength:t,symbol:i}}function Xc(e){return Et(e)||e instanceof Q&&e.values.length>=1&&e.values.every(t=>Et(t))}function pb(e){return Et(e)?[Ut(e)]:e.values.map(t=>Ut(t))}var S0=Symbol();function qc(e){if($s(e))return!0;if(e instanceof qe&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!$s(i))return!1;let[n]=Ws(i);if(n>=t)return!1;t=n}return!0}return!1}function fb(e){if($s(e)){let[t,i]=Ws(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=Ws(t);return{weight:i,symbol:n}})}var gb=["auto","bullets","numbers","words","spell-out"],mb=new Set(gb);function wb(e){return e instanceof ae&&mb.has(e.name)||Yn(e)}function bb(e,t){switch(e){case"system":return eb(t);case"negative":return Wc(t);case"prefix":case"suffix":return Et(t);case"range":return Gc(t);case"pad":return jc(t);case"fallback":return Yn(t);case"symbols":return Xc(t);case"additive-symbols":return qc(t);case"speak-as":return wb(t);default:return!0}}function tt(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function yb(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function qi(e){let t=e.get("decimal");return t||(t=he.createDecimal(e),e.set("decimal",t)),t}var fs,gs,ms,ws,bs,ys,vs,xs,Co,ko,Eo,No,Po,To,Io,rt,Ir,Yc,Kc,Ul,Hl,Ar,$l,pn,Yt=class di{constructor(t,i){ue(this,rt),c(this,"_store"),ue(this,fs),ue(this,gs),ue(this,ms),ue(this,ws),ue(this,bs),ue(this,ys),ue(this,vs),ue(this,xs),this._store=t;let n=tt(i,"negative");wt(this,fs,n&&Wc(n)?hb(n):null);let s=tt(i,"prefix");wt(this,gs,s&&Et(s)?Ut(s):null);let r=tt(i,"suffix");wt(this,ms,r&&Et(r)?Ut(r):null);let o=tt(i,"range");wt(this,ws,o&&Gc(o)?cb(o):null);let a=tt(i,"pad");wt(this,bs,a&&jc(a)?db(a):null);let l=tt(i,"fallback");wt(this,ys,l&&Yn(l)?$c(l):null);let h=tt(i,"symbols");wt(this,vs,h&&Xc(h)?pb(h):null);let u=tt(i,"additive-symbols");wt(this,xs,u&&qc(u)?fb(u):null)}static create(t,i){return tb(i)?new ui(t,i):ib(i)?new vb(t,i):sb(i)?new Sb(t,i):rb(i)?new Wl(t,i):ob(i)?new Cb(t,i):ab(i)?new kb(t,i):new xb(t,i)}static createDecimal(t){return new Wl(t,X(di,Co))}static createDisc(t){return new ui(t,X(di,ko))}static createSquare(t){return new ui(t,X(di,Eo))}static createCircle(t){return new ui(t,X(di,No))}static createDisclosureOpen(t){return new ui(t,X(di,Po))}static createDisclosureClosed(t){return new ui(t,X(this,To))}static createNone(t){return new ui(t,X(di,Io))}static get CHINESE_LONGHAND_NAMES(){return Gl.NAMES}static createChineseLonghand(t,i){return new Gl(t,i)}static createEthiopicNumeric(t){return new Nb(t)}_getNegative(){return X(this,fs)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return X(this,gs)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return X(this,ms)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return X(this,ws)}static _getRangeFrom(t){return t._getRange()}_getPad(){return X(this,bs)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(X(this,ys)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return X(this,vs)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return X(this,xs)}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,rt,pn).call(this,t,new Set)}formatMarker(t){return Ee(this,rt,Yc).call(this)+this.format(t)+Ee(this,rt,Kc).call(this)}};fs=new WeakMap,gs=new WeakMap,ms=new WeakMap,ws=new WeakMap,bs=new WeakMap,ys=new WeakMap,vs=new WeakMap,xs=new WeakMap,Co=new WeakMap,ko=new WeakMap,Eo=new WeakMap,No=new WeakMap,Po=new WeakMap,To=new WeakMap,Io=new WeakMap,rt=new WeakSet,Ir=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},Yc=function(){var e;return(e=this._getPrefix())!=null?e:""},Kc=function(){var e;return(e=this._getSuffix())!=null?e:". "},Ul=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},Hl=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},Ar=function(){var e;return(e=this._getFallback())!=null?e:qi(this._store)},$l=function(e,t){let{minLength:i,symbol:n}=Ee(this,rt,Hl).call(this);if(i===0||n==="")return e;let{prefix:s,suffix:r}=Ee(this,rt,Ir).call(this),o=t?[...s].length+(r?[...r].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},pn=function(e,t){var i,n,s;if(t.has(this))return Ee(i=qi(this._store),rt,pn).call(i,e,new Set);if(t.add(this),!yb(e,Ee(this,rt,Ul).call(this))){let h=Ee(this,rt,Ar).call(this);return Ee(n=h,rt,pn).call(n,e,t)}let r=this._usesNegativeSign(e),o=r?Math.abs(e):e,a=this._generateInitialRepresentation(o);if(a===null){let h=Ee(this,rt,Ar).call(this);return Ee(s=h,rt,pn).call(s,e,t)}let l=Ee(this,rt,$l).call(this,a,r);if(r){let{prefix:h,suffix:u}=Ee(this,rt,Ir).call(this);l=h+l+(u??"")}return l},ue(Yt,Co,{system:new M(F("numeric"),0),symbols:new M(new Q([new G("0"),new G("1"),new G("2"),new G("3"),new G("4"),new G("5"),new G("6"),new G("7"),new G("8"),new G("9")]),0)}),ue(Yt,ko,{system:new M(F("cyclic"),0),symbols:new M(new G("\u2022"),0),suffix:new M(new G(" "),0)}),ue(Yt,Eo,{system:new M(F("cyclic"),0),symbols:new M(new G("\u25AA"),0),suffix:new M(new G(" "),0)}),ue(Yt,No,{system:new M(F("cyclic"),0),symbols:new M(new G("\u25E6"),0),suffix:new M(new G(" "),0)}),ue(Yt,Po,{system:new M(F("cyclic"),0),symbols:new M(new G("\u25BE"),0),suffix:new M(new G(" "),0)}),ue(Yt,To,{system:new M(F("cyclic"),0),symbols:new M(new G("\u25B8"),0),suffix:new M(new G(" "),0)}),ue(Yt,Io,{system:new M(F("cyclic"),0),symbols:new M(new G(""),0),suffix:new M(new G(""),0)});var he=Yt,ui=class extends he{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]}},Ss,vb=class extends he{constructor(e,t){super(e,t),ue(this,Ss),wt(this,Ss,nb(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-X(this,Ss);return(t=i[n])!=null?t:null}};Ss=new WeakMap;var xb=class extends he{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],s=Math.ceil(e/i);return n.repeat(s)}},Sb=class extends he{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="",s=e;for(;s!==0;)s=s-1,n=t[s%i]+n,s=Math.floor(s/i);return n}},Wl=class extends he{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="",s=e;for(;s!==0;)n=t[s%i]+n,s=Math.floor(s/i);return n}},Cb=class extends he{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 s=t.find(r=>r.weight===0);return s?s.symbol:null}let n=e;for(let s of t){let{weight:r,symbol:o}=s;if(r===0||r>n)continue;let a=Math.floor(n/r);if(i+=o.repeat(a),n-=r*a,n===0)return i}return null}},kn,ht,gt,Zc=class extends he{constructor(t,i){super(t,i),ue(this,ht),ue(this,kn);let n=lb(i),s=n.toLowerCase();s==="disc"||s==="circle"||s==="square"||s==="disclosure-open"||s==="disclosure-closed"?wt(this,kn,s):wt(this,kn,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:he._getNegativeFrom(Ee(this,ht,gt).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:he._getPrefixFrom(Ee(this,ht,gt).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:he._getSuffixFrom(Ee(this,ht,gt).call(this))}_getAutoRange(){return he._getAutoRangeFrom(Ee(this,ht,gt).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:he._getRangeFrom(Ee(this,ht,gt).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:he._getPadFrom(Ee(this,ht,gt).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:he._getFallbackFrom(Ee(this,ht,gt).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:he._getSymbolsFrom(Ee(this,ht,gt).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:he._getAdditiveSymbolsFrom(Ee(this,ht,gt).call(this))}_usesNegativeSign(t){return he._useNegativeSignFrom(Ee(this,ht,gt).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:he._generateInitialRepresentationFrom(Ee(this,ht,gt).call(this),t)}};kn=new WeakMap,ht=new WeakSet,gt=function(e=new Set){var t;if(e.has(this))return qi(this._store);e.add(this);let i=this._store.get(X(this,kn));return i?i instanceof Zc?Ee(t=i,ht,gt).call(t,e):i:qi(this._store)};var kb=Zc,Eb=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],Rr,Fr,as,Lr,Ao,Cs,yt=class Jc extends he{constructor(t,i){let{chars:n,descriptors:s}=X(Jc,Ao).get(i);super(t,s),ue(this,Cs),wt(this,Cs,n)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=X(this,Cs);if(t===0)return i.digits[0];let n=[],s=0,r=t;for(;r>0;)n.unshift({digit:r%10,position:s}),r=Math.floor(r/10),s++;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}};Rr=new WeakMap,Fr=new WeakMap,as=new WeakMap,Lr=new WeakMap,Ao=new WeakMap,Cs=new WeakMap,ue(yt,Rr,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new M(new G("\u3001"),0),fallback:new M(F("cjk-decimal"),0),range:new M(new Q([new Re(-9999),new Re(9999)]),0),negative:new M(new G("\u8D1F"),0)}}),ue(yt,Fr,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new M(new G("\u3001"),0),fallback:new M(F("cjk-decimal"),0),range:new M(new Q([new Re(-9999),new Re(9999)]),0),negative:new M(new G("\u8D1F"),0)}}),ue(yt,as,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new M(new G("\u3001"),0),fallback:new M(F("cjk-decimal"),0),range:new M(new Q([new Re(-9999),new Re(9999)]),0),negative:new M(new G("\u8CA0"),0)}}),ue(yt,Lr,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new M(new G("\u3001"),0),fallback:new M(F("cjk-decimal"),0),range:new M(new Q([new Re(-9999),new Re(9999)]),0),negative:new M(new G("\u8CA0"),0)}}),c(yt,"NAMES",new Set(Eb)),ue(yt,Ao,new Map([["simp-chinese-informal",X(yt,Rr)],["simp-chinese-formal",X(yt,Fr)],["trad-chinese-informal",X(yt,as)],["trad-chinese-formal",X(yt,Lr)],["cjk-ideographic",X(yt,as)]]));var Gl=yt,Ro,Fo,Gs,Lo,Bo,Ii=class pi extends he{constructor(t){super(t,X(pi,Ro))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return X(pi,Gs)[1];let i=[],n=t;for(;n>0;)i.push(n%100),n=Math.floor(n/100);let s=i.length,r="";for(let o=s-1;o>=0;o--){let a=i[o],l=o%2===1,h=o===s-1;if(!(a===0||h&&a===1||l&&a===1)){let u=Math.floor(a/10),d=a%10;r+=X(pi,Fo)[u]+X(pi,Gs)[d]}l?a!==0&&(r+=X(pi,Lo)):o!==0&&(r+=X(pi,Bo))}return r}};Ro=new WeakMap,Fo=new WeakMap,Gs=new WeakMap,Lo=new WeakMap,Bo=new WeakMap,ue(Ii,Ro,{range:new M(new Q([new Re(1),F("infinite")]),0),suffix:new M(new G("/ "),0)}),ue(Ii,Fo,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ue(Ii,Gs,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ue(Ii,Lo,"\u137B"),ue(Ii,Bo,"\u137C");var Nb=Ii,Ce,Pb=class{constructor(){ue(this,Ce),wt(this,Ce,new Map),X(this,Ce).set("none",he.createNone(X(this,Ce))),X(this,Ce).set("decimal",he.createDecimal(X(this,Ce))),X(this,Ce).set("disc",he.createDisc(X(this,Ce))),X(this,Ce).set("square",he.createSquare(X(this,Ce))),X(this,Ce).set("circle",he.createCircle(X(this,Ce))),X(this,Ce).set("disclosure-open",he.createDisclosureOpen(X(this,Ce))),X(this,Ce).set("disclosure-closed",he.createDisclosureClosed(X(this,Ce)));for(let e of he.CHINESE_LONGHAND_NAMES)X(this,Ce).set(e,he.createChineseLonghand(X(this,Ce),e));X(this,Ce).set("ethiopic-numeric",he.createEthiopicNumeric(X(this,Ce)))}define(e,t){if(!Yw(e))return null;let i=he.create(X(this,Ce),t);return X(this,Ce).set(e,i),i}getStyle(e){var t;return(t=X(this,Ce).get(e))!=null?t:null}format(e,t){var i;return((i=this.getStyle(e))!=null?i:qi(X(this,Ce))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:qi(X(this,Ce))).formatMarker(t)}};Ce=new WeakMap;var Br=class{constructor(e,t,i){c(this,"endStuckFixed"),c(this,"endFixed"),c(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},Tb=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 Br(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 Br(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new Br(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=ni(this.map.length,n=>e<=this.map[n].endFixed),i=this.map[t];return i.endSlipped-Math.max(0,i.endStuckFixed-e)}fixedBySlipped(e){let t=ni(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}},Ib=class Oo{constructor(t,i,n,s,r,o,a,l){if(this.context=t,this.style=i,this.offset=n,this.isRoot=s,this.flowChunk=r,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=r.flowName,this.hasBox()){let h=i._pseudos;if(h&&h.before){let u=new Oo(t,h.before,n,!1,r,this.isBlock(),a,!0),d=u.styleValue("content");Ot(d)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=it(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&et(this.breakBefore)&&(r.breakBefore=it(r.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let s=this.style._pseudos;if(s&&s.after){let r=new Oo(this.context,s.after,t,!1,this.flowChunk,i,n,!0),o=r.styleValue("content");Ot(o)&&(this.afterBox=r)}}}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=qu(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==b.none&&!to(this.styleValue("position"))),this.hasBoxValue}getBreakValue(t){let i=null;if(this.isBlock()){let n=this.styleValue(`break-${t}`);n&&(i=n.toString())}return i}},Ab=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 s=this.lastBox();n&&s&&n.flowName!==s.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let r=n||s.flowChunk,o=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),l=new Ib(this.context,e,t,i,r,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=_u(i);n&&!Ue(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=it(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!")}},jl=class{constructor(e,t,i,n,s,r,o,a,l){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=s,this.validatorSet=r,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),this.offsetMap=new Tb;let h=e.getElementOffset(this.root);this.lastOffset=h,this.boxStack=new Ab(n),this.offsetMap.addStuckRange(h);let u=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,u,h),this.postprocessTopStyle(u,!1),this.root.namespaceURI){case"http://www.w3.org/1999/xhtml":this.bodyReached=!1;break}this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${h}`]=u,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 s=t[i];s&&(this.rootStyle[i]=new M(s,Su))}}}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)xn(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,s=this.hasProp(e,this.validatorSet.backgroundProps,"background-image")?e["background-image"].evaluate(this.context):null;(n&&!J(n)||s&&!J(s))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<Xl.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,Xl[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],s=!0;if(n&&!J(n.value)){let a=n.evaluate(this.context);if(a instanceof A){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*Tt.lh/Tt.em;break;default:{let h=Tt[a.unit];h&&(l*=h),s=!1}}this.context.rootFontSize=l,this.context.isRelativeRootFontSize=s}}let r=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,o=e["line-height"];if(o&&!J(o.value)){let a=o.evaluate(this.context);if(a instanceof Ht)this.context.rootLineHeight=a.num*r;else if(a instanceof A){let l=a.num;switch(a.unit){case"em":case"rem":l*=r;break;case"%":l*=r/100;break;case"lh":case"rlh":l*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let h=Tt[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 Wm(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 r=this.getStyle(this.root,!1),o=_e(r,"flow-into"),a=o?o.evaluate(t,"flow-into").toString():"body",l=this.encounteredFlowElement(a,r,this.root,i);this.boxStack.empty()&&this.boxStack.push(r,i,!0,l)}let n=this.xmldoc.getNodeByOffset(e),s=this.xmldoc.getNodeOffset(n,0,!1);if(!(s>=this.lastOffset))for(;;){if(n.nodeType!=1)s+=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,s)}s++}if(s>=this.lastOffset)break;let r=n.firstChild;if(r==null){for(;r=n.nextSibling,!r;)if(n=n.parentNode,n===this.root)return}n=r}}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 s=0,r=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&&(r=hl(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let d=t["flow-priority"];d&&(s=hl(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 vg(e,g)}let m=new xg(e,i,n,s,r,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(et(e)){let s=this.flows[i].forcedBreakOffsets;(s.length===0||s[s.length-1]<t)&&s.push(t)}let n=this.breakBeforeValues[t];this.breakBeforeValues[t]=it(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 s=this.context;for(;;){let r=this.last.firstChild;if(r==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=it(a,o.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,o.flowName)}if(r=this.last.nextSibling,r)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=r,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(s,"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=it(h.flowChunk.breakBefore,h.breakBefore));let d=this.boxStack.nearestBlockStartOffset(h);if(d===0){let p=a.page,f=p&&!J(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){}},Xl=["column-count","column-width","column-fill"],Mi=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)}},ci=class{constructor(e,t){this.where=e,this.success=t,c(this,"what",-1)}},an=class Qc{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 Qc;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],s=new Mi(n.validator);s.code=n.code,t.nodes.push(s)}for(let i=0;i<this.connections.length;i++){let n=this.connections[i],s=new ci(n.where,n.success);s.what=n.what,t.connections.push(s)}return t.match.push(...this.match),t.nomatch.push(...this.nomatch),t.error.push(...this.error),t}addSpecialToArr(t,i,n){let s=this.nodes.length,r=new Mi(ql);n>=0?i?r.markAsStartAlternate(n):r.markAsEndAlternate(n):i?r.markAsStartGroup():r.markAsEndGroup(),this.nodes.push(r),this.connect(t,s);let o=new ci(s,!0),a=new ci(s,!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 Mi(ql);i.markAsStartAlternate(t),this.nodes.push(i);let n=new ci(0,!0),s=new ci(0,!1);this.nomatch.push(this.connections.length),this.connections.push(s),this.match.push(this.connections.length),this.connections.push(n)}addPrimitive(t){let i=this.nodes.length;this.nodes.push(new Mi(t));let n=new ci(i,!0),s=new ci(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(s),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 Le}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 r=0;r<t.nodes.length;r++)this.nodes.push(t.nodes[r]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let s=this.connections.length;for(let r=0;r<t.connections.length;r++){let o=t.connections[r];o.where+=n,o.what>=0&&(o.what+=n),this.connections.push(o)}for(let r=0;r<t.match.length;r++)this.match.push(t.match[r]+s);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let r=0;r<t.nomatch.length;r++)this.match.push(t.nomatch[r]+s);else if(this.emptyHead){for(let r=0;r<t.nomatch.length;r++)this.nomatch.push(t.nomatch[r]+s);this.emptyHead=t.emptyHead}else for(let r=0;r<t.nomatch.length;r++)this.error.push(t.nomatch[r]+s);for(let r=0;r<t.error.length;r++)this.error.push(t.error[r]+s);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 s of this.connections)s.success?this.nodes[s.where].success=this.nodes[s.what]:this.nodes[s.where].failure=this.nodes[s.what];for(let s=0;s<n;s++)if(this.nodes[s].failure==null||this.nodes[s].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},Rb=1,ed=2,td=4,fi=8,ks=16,_o=32,Es=64,id=128,fn=256,gn=512,Mo=1024,nd=2048,sd=4096,rd=8192,od=class extends Xt{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},Le=class ad extends od{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&Rb?t:null}visitSlash(t){return this.allowed&nd?t:null}visitStr(t){return this.allowed&ed?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&td||this.allowed&Es&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&gn)?t.unit=="%"&&this.allowed&Mo?t:null:t.num<0&&!(this.allowed&fn)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&gn?t:null:t.num<=0&&!(this.allowed&fn)?null:this.allowed&ks?t:null}visitInt(t){return t.num==0?this.allowed&gn?t:null:t.num<=0&&!(this.allowed&fn)?null:this.allowed&(_o|ks)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&Es&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&id?t:null}visitURange(t){return this.allowed&sd?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){return this.allowed&Es&&CSS.supports("color",t.toString())||this.allowed&rd&&CSS.supports("background-image",t.toString())||t.name==="calc"&&this.allowed&(fi|ks|_o|fn|gn|Mo)?t:null}visitExpr(t){return this.allowed&2046?t:null}combine(t){let i={},n={};for(let s in this.idents)i[s]=this.idents[s];for(let s in t.idents)i[s]=t.idents[s];for(let s in this.units)n[s]=this.units[s];for(let s in t.units)n[s]=t.units[s];return new ad(this.allowed|t.allowed,i,n)}},se={},ql=new Le(0,se,se),Ca=class extends od{constructor(e){super(),c(this,"successTerminal"),c(this,"failureTerminal"),c(this,"first"),this.successTerminal=new Mi(null),this.failureTerminal=new Mi(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,s=this.first,r=i,o=null,a=null;for(;s!==this.successTerminal&&s!==this.failureTerminal;){if(r>=e.length){s=s.failure;continue}let l=e[r],h=l;if(s.isSpecial()){let u=!0;s.isStartGroup()?(o?o.push(a):o=[a],a=[]):s.isEndGroup()?o.length>0?a=o.pop():a=null:s.isEndAlternate()?a[s.getAlternate()]="taken":u=a[s.getAlternate()]==null,s=u?s.success:s.failure}else{if(r==0&&!t&&s.validator instanceof En&&this instanceof En){if(h=new Q(e).visit(s.validator),h){r=e.length,s=s.success;continue}}else if(r==0&&!t&&s.validator instanceof ka&&this instanceof En){if(h=new qe(e).visit(s.validator),h){r=e.length,s=s.success;continue}}else h=l.visit(s.validator);if(!h){s=s.failure;continue}if(h!==l&&e===n){n=[];for(let u=0;u<r;u++)n[u]=e[u]}e!==n&&(n[r-i]=h),r++,s=s.success}}return s===this.successTerminal&&(t?n.length>0:r==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}},En=class extends Ca{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new Q(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof ka){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new qe(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},ka=class extends Ca{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 qe(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}},Fb=class extends Ca{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 Ji(e.name,t):null}},ld=class{tryParse(e,t,i){return t}success(e,t){}},hd=class extends ld{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 s=n.length,r=s>1?new Q(n):n[0];return this.success(r,i),t+s}return t}success(e,t){t.values[this.name]=e}},Lb=class extends hd{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}},Bb=class extends ld{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==Ks){if(++t==e.length)return n}else return n;let s=this.nodes[0].tryParse(e,t,i);if(s==t)return n;t=s;for(let r=1;r<this.nodes.length&&t<e.length&&(s=this.nodes[r].tryParse(e,t,i),s!=t);r++)t=s;return t}},Ea=class extends Xt{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 hd(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 s of this.propList)t.simpleProperty(s,(n=(i=this.values[s])!=null?i:this.validatorSet.defaultValues[s])!=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)}},nn=class extends Ea{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}},ud=class extends Ea{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 Lb(this.validatorSet,this.propList)}},Ob=class extends Ea{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===Ks){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 s;if(t+1<e.length)for(s=t+i+1;s>=e.length;)s=s-(s==t+2?1:2);else s=n;let r=[e[n],e[s]];if(this.syntax[i].tryParse(r,0,this)!=2)return this.error=!0,0}return e.length}},_b=class extends nn{constructor(){super()}mergeIn(e,t){var i,n;for(let s of this.propList){let r=(n=(i=t[s])!=null?i:this.validatorSet.defaultValues[s])!=null?n:b.initial,o=e[s];o||(o=[],e[s]=o),o.push(r)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof qe?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 qe(t[i]);return null}},Mb=class extends nn{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 s=this.validatorSet.validators;if(!e[t].visit(s["font-size"]))return this.error=!0,t;if(this.values["font-size"]=e[t++],e[t]===Ks){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(s["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let r=t==e.length-1?e[t]:new Q(e.slice(t,e.length));return r.visit(s["font-family"])?(this.values["font-family"]=r,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 qe(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}},zb=class extends nn{validateList(e){if(e.length===1&&e[0]instanceof ae)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)}},Db=["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"],Vb=class extends nn{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)Db.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},Yl={SIMPLE:nn,INSETS:ud,INSETS_SLASH:Ob,COMMA:_b,FONT:Mb,TEXT_SPACING:zb,ALL:Vb},Ub=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 A(t.num,t.text);else if(t.type==7)i=new eu(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 s in n)n[s]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new an;if(e=="||"){for(let s=0;s<t.length;s++){let r=new an;r.startClause(s),r.addGroup(t[s],1),r.endClause(s),i.addGroup(r,s==0?1:4)}let n=new an;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 s=0;s<t.length;s++)i.addGroup(t[s],s==0?1:n);return i}}addCounts(e,t,i){let n=new an;for(let s=0;s<t;s++)n.addGroup(e.clone(),1);if(i==Number.POSITIVE_INFINITY)n.addGroup(e,3);else for(let s=t;s<i;s++)n.addGroup(e.clone(),2);return n}primitive(e){let t=new an;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new ka(t);break;case"SPACE":i=new En(t);break;default:i=new Fb(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Le(Es,se,se)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Le(rd,se,se)),this.namedValidators.POS_INT=this.primitive(new Le(_o,se,se)),this.namedValidators.POS_NUM=this.primitive(new Le(ks,se,se)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Le(fi,se,{"%":j})),this.namedValidators.NEGATIVE=this.primitive(new Le(fn,se,se)),this.namedValidators.ZERO=this.primitive(new Le(gn,se,se)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Le(Mo,se,se)),this.namedValidators.POS_LENGTH=this.primitive(new Le(fi,se,{em:j,ex:j,ch:j,rem:j,lh:j,rlh:j,vw:j,vh:j,vi:j,vb:j,vmin:j,vmax:j,pvw:j,pvh:j,pvi:j,pvb:j,pvmin:j,pvmax:j,cm:j,mm:j,in:j,px:j,pt:j,pc:j,q:j})),this.namedValidators.POS_ANGLE=this.primitive(new Le(fi,se,{deg:j,grad:j,rad:j,turn:j})),this.namedValidators.POS_TIME=this.primitive(new Le(fi,se,{s:j,ms:j})),this.namedValidators.FREQUENCY=this.primitive(new Le(fi,se,{Hz:j,kHz:j})),this.namedValidators.RESOLUTION=this.primitive(new Le(fi,se,{dpi:j,dpcm:j,dppx:j})),this.namedValidators.URI=this.primitive(new Le(id,se,se)),this.namedValidators.URANGE=this.primitive(new Le(sd,se,se)),this.namedValidators.IDENT=this.primitive(new Le(td,se,se)),this.namedValidators.STRING=this.primitive(new Le(ed,se,se)),this.namedValidators.SLASH=this.primitive(new Le(nd,se,se));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 s=i.text;if(e.consume(),t!=2){if(e.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(s)||(this.prefixes[s]=n)}else if(e.token().type!=18)throw new Error("':' expected");return s}parseValidators(e){for(;;){let t=this.readNameAndPrefixes(e,1);if(!t)return;let i=[],n=[],s="",r,o=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(s,i)},l=u=>{if(o)throw new Error(`'${u}': unexpected`);if(s&&s!=u)throw new Error(`mixed operators: '${u}' and '${s}'`);s=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 Le(0,d,se)))}o=!1;break;case 5:{let d={};d[`${u.num}`]=new Re(u.num),i.push(this.primitive(new Le(0,d,se))),o=!1;break}case 34:l("|");break;case 25:l("||");break;case 14:o||l(" "),n.push({vals:i,op:s,b:"["}),s="",i=[],o=!0;break;case 6:o||l(" "),n.push({vals:i,op:s,b:"(",fn:u.text}),s="",i=[],o=!0;break;case 15:{r=a();let d=n.pop();if(d.b!="[")throw new Error("']' unexpected");i=d.vals,i.push(r),s=d.op,o=!1;break}case 11:{r=a();let d=n.pop();if(d.b!="(")throw new Error("')' unexpected");i=d.vals,i.push(this.newFunc(d.fn,r)),s=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 En(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 Ht(n.num));break;case 5:i.push(new Re(n.num));break;case 3:i.push(new A(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new Q(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&Yl[i.text]?(n=new Yl[i.text],e.consume()):n=new nn,n.setOwner(this);let s=!1,r=[],o=!1,a=[],l=[];for(;!s;)switch(e.consume(),i=e.token(),i.type){case 1:if(this.validators[i.text])r.push(n.syntaxNodeForProperty(i.text)),i.text.includes("_")||l.push(i.text);else if(this.shorthands[i.text]instanceof ud){let h=this.shorthands[i.text];r.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(r.length>0||o)throw new Error("unexpected slash");o=!0;break;case 14:a.push({slash:o,syntax:r}),r=[],o=!1;break;case 15:{let h=new Bb(r,o),u=a.pop();r=u.syntax,o=u.slash,r.push(h);break}case 17:s=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(r,l),this.shorthands[t]=n}}parse(e){let t=new Rt(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 s=this.shorthands[n],r=s?s.propList:[n];for(let o of r)i[o]=(t=this.defaultValues[o])!=null?t:b.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){let s=n.ruleType;if($t(e)||s==="font-face"||$b(t)){n.simpleProperty(e,t,i);return}if(s==="counter-style"){bb(e,t)?n.simpleProperty(e,t,i):n.invalidPropertyValue(e,t);return}let r="",o=e;e=e.toLowerCase();let a=e.match(/^-([a-z]+)-([-a-z0-9]+)$/);a&&(r=a[1],e=a[2]);let l=this.prefixes[e];if(!l||!l[r]){CSS.supports(o,t.toString())?n.simpleProperty(o,t,i):r&&!Ph.includes(`-${r}-`)||n.unknownProperty(o,t);return}let h=this.validators[e];if(h){let u=J(t)||t.isExpr()?t:t.visit(h);u?n.simpleProperty(e,u,i):!r&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(o,t)}else{let u=this.shorthands[e].clone();J(t)?u.propagateDefaultingValue(t,i,n):(t.visit(u),u.finish(i,n)||n.invalidPropertyValue(o,t))}}};function cd(){let e=new Ub;return e.initBuiltInValidators(),e.parse(fu),e}var Hb=class extends Xt{constructor(){super(...arguments),c(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function $b(e){let t=new Hb;return e.visit(t),t.varFound}var k0=`OTTO${new Date().valueOf()}`;function Na(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function Wb(e){let t=new ii;for(let i of Na(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function Gb(e,t){let i={};for(let n in e)i[n]=_e(e,n).evaluate(t,n);return i}var dd=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 ii;i.append(`@font-face {
|
|
1513
1786
|
font-family: `),i.append(this.family),i.append(`;
|
|
1514
|
-
`);for(let n of
|
|
1515
|
-
`);if(t){i.append('src: url("');let n=
|
|
1787
|
+
`);for(let n of Na(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
|
|
1788
|
+
`);if(t){i.append('src: url("');let n=Gf(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
|
|
1516
1789
|
}
|
|
1517
|
-
`),i.toString()}},Qm=class{constructor(e){this.deobfuscator=e,u(this,"familyMap",{})}registerFamily(e,t){let i=e.family,n=this.familyMap[i],s=t.family;if(n){if(n!=s)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${e.family}`)}else this.familyMap[i]=s}filterFontFamily(e){if(e instanceof qe){let t=e.values,i=[];for(let n of t){let s=this.familyMap[n.stringValue()];s&&i.push(B(s)),i.push(n)}return new qe(i)}else{let t=this.familyMap[e.stringValue()];return t?new qe([B(t),e]):e}}},ew=class{constructor(e,t,i){this.head=e,this.body=t,u(this,"srcURLMap",{}),u(this,"familyPrefix"),u(this,"familyCounter",0),this.familyPrefix=i||"Fnt_"}getViewFontFamily(e,t){let i=e.family,n=t.familyMap[i];return n||(n=this.familyPrefix+ ++this.familyCounter,t.familyMap[i]=n,n)}initFont(e,t,i){let n=F("initFont"),s=e.src,o={};for(let l of kr(e.properties))o[l]=e.properties[l];let r=this.getViewFontFamily(e,i);o["font-family"]=B(r);let a=new Yu(o),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(s,t),this.head.appendChild(h),H.debug("Load font:",s),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i,s=this.srcURLMap[n];return s?s.piggyback(o=>{let r=o;r.traitsEqual(e)?(t.registerFamily(e,r),H.debug("Found already-loaded font:",i)):H.warn("E_FONT_FACE_INCOMPATIBLE",e.src)}):(s=new Cn(()=>{let o=F("loadFont"),r=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(r):null;return a?bs(r,"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]=s,s.start()),s}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){H.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return ws(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(s=>{}))}),t===0)return P(!0);let i=F("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?P(!0):P(!1))).thenFinish(i),i.result()}},tw=1,Cs=class{constructor(e,t,i,n,s){this.name=t,this.pseudoName=i,this.classes=n,this.parent=s,u(this,"specified",{}),u(this,"children",[]),u(this,"pageMaster",null),u(this,"index",0),u(this,"key"),u(this,"_scope"),this._scope=e,this.key=`p${tw++}`,s&&(this.index=s.children.length,s.children.push(this))}get scope(){return this._scope}createInstance(e){throw new Error("E_UNEXPECTED_CALL")}clone(e){throw new Error("E_UNEXPECTED_CALL")}copySpecified(e){let t=this.specified,i=e.specified;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n])}cloneChildren(e){for(let t=0;t<this.children.length;t++)this.children[t].clone({parent:e})}},iw=class extends Cs{constructor(e){super(e,null,null,[],null),this.specified.width=new Z(xn,0),this.specified.height=new Z(Sn,0)}},Ga=class extends Js{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(s,o){let r=s.match(/^([^.]+)\.([^.]+)$/);if(r){let a=i.pageMaster.keyMap[r[1]];if(a){let h=this.lookupInstance(a);if(h)return o?h.resolveFunc(r[2]):h.resolveName(r[2])}}return null}}},Ku=class Zu extends Cs{constructor(t,i,n,s,o,r,a){super(t,i,n,s,o),this.condition=r,this.specificity=a,u(this,"keyMap",{}),t instanceof Ga||(this._scope=new Ga(t,this)),this.pageMaster=this,this.specified.width=new Z(xn,0),this.specified.height=new Z(Sn,0),this.specified["wrap-flow"]=new Z(v.auto,0),this.specified.position=new Z(v.relative,0),this.specified.overflow=new Z(v.visible,0)}createInstance(t){return new Nr(t,this)}clone(t){let i=new Zu(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}},Ju=class Qu extends Cs{constructor(t,i,n,s,o){super(t,i,n,s,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new Z(v.auto,0)}createInstance(t){return new rw(t,this)}clone(t){let i=new Qu(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},Tn=class ec extends Cs{constructor(t,i,n,s,o){super(t,i,n,s,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new Ai(t,this)}clone(t){let i=new ec(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function nw(e,t,i){return!t||J(t)?new Oe(e,i):t.toExpr(e,e.zero)}function ae(e,t,i){return!t||t===v.auto||J(t)?null:t.toExpr(e,i)}function sw(e,t,i){return!t||t===v.normal||J(t)?null:t.toExpr(e,i)}function it(e,t,i){return!t||t===v.auto||J(t)?e.zero:t.toExpr(e,i)}function ja(e,t,i){return!t||J(t)?e.zero:t===v.auto?null:t.toExpr(e,i)}function Ct(e,t,i,n){return!t||i===v.none||J(t)?e.zero:t.toExpr(e,n)}function tc(e,t,i){return!t||J(t)?i:t===v._true?e._true:t===v._false?e._false:t.toExpr(e,e.zero)}var Es=class{constructor(e,t){this.parentInstance=e,this.pageBox=t,u(this,"cascaded",{}),u(this,"style",{}),u(this,"autoWidth",null),u(this,"autoHeight",null),u(this,"children",[]),u(this,"isAutoWidth",!1),u(this,"isAutoHeight",!1),u(this,"isTopDependentOnAutoHeight",!1),u(this,"isRightDependentOnAutoWidth",!1),u(this,"calculatedWidth",0),u(this,"calculatedHeight",0),u(this,"pageMasterInstance",null),u(this,"namedValues",{}),u(this,"namedFuncs",{}),u(this,"vertical",!1),u(this,"rtl",!1),u(this,"suppressEmptyBoxGeneration",!1),u(this,"borderBoxSizing",!1),e&&e.children.push(this)}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(e,t){let i=this.resolveName(e),n=this.resolveName(t);if(!i||!n)throw new Error("E_INTERNAL");return 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 s=this.vertical?Kh:Zh;n=e;for(let o in s)n=n.replace(o,s[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 $l(i,0),s=this.resolveName("column-count"),o=this.resolveName("column-width"),r=this.resolveName("column-gap");t=oe(i,Hn(i,new Ki(i,"min",[n,s]),Y(i,o,r)),r);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=tc(e,t.enabled,e._true),n=ae(e,t.page,e.zero);if(n){let r=new Ae(e,"page-number");i=dt(e,i,new Zo(e,n,r))}let s=ae(e,t["min-page-width"],e.zero);s&&(i=dt(e,i,new eo(e,new Ae(e,"page-width"),s)));let o=ae(e,t["min-page-height"],e.zero);o&&(i=dt(e,i,new eo(e,new Ae(e,"page-height"),o))),i=this.boxSpecificEnabled(i),t.enabled=new V(i)}boxSpecificEnabled(e){return e}initHorizontal(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=ae(e,t.left,i),s=ae(e,t["margin-left"],i),o=Ct(e,t["border-left-width"],t["border-left-style"],i),r=it(e,t["padding-left"],i),a=ae(e,t.width,i),h=ae(e,t["max-width"],i),l=it(e,t["padding-right"],i),c=Ct(e,t["border-right-width"],t["border-right-style"],i),p=ae(e,t["margin-right"],i),d=ae(e,t.right,i),f=Y(e,o,r),m=Y(e,o,l);if(n&&d&&a){let y=oe(e,i,Y(e,a,Y(e,Y(e,n,f),m)));s?p?d=oe(e,y,p):p=oe(e,y,Y(e,d,s)):(y=oe(e,y,d),p?s=oe(e,y,p):(s=Hn(e,y,new Oe(e,.5)),p=s))}else{s||(s=e.zero),p||(p=e.zero),!n&&!d&&!a&&(n=e.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!d?n=e.zero:!a&&!d&&(a=this.autoWidth,this.isAutoWidth=!0);let y=oe(e,i,Y(e,Y(e,s,f),Y(e,p,m)));this.isAutoWidth&&(h||(h=oe(e,y,n||d)),!this.vertical&&(ae(e,t["column-width"],null)||ae(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?d||(d=oe(e,y,Y(e,n,a))):a=oe(e,y,Y(e,n,d)):n=oe(e,y,Y(e,d,a))}let g=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=it(e,g,i);t.left=new V(n),t["margin-left"]=new V(s),t["border-left-width"]=new V(o),t["padding-left"]=new V(r),t.width=new V(a),t["max-width"]=new V(h||a),t["padding-right"]=new V(l),t["border-right-width"]=new V(c),t["margin-right"]=new V(p),t.right=new V(d),t["snap-width"]=new V(w)}initVertical(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(e,null):null,s=ae(e,t.top,n),o=ae(e,t["margin-top"],i),r=Ct(e,t["border-top-width"],t["border-top-style"],i),a=it(e,t["padding-top"],i),h=ae(e,t.height,n),l=ae(e,t["max-height"],n),c=it(e,t["padding-bottom"],i),p=Ct(e,t["border-bottom-width"],t["border-bottom-style"],i),d=ae(e,t["margin-bottom"],i),f=ae(e,t.bottom,n),m=Y(e,r,a),g=Y(e,p,c);if(s&&f&&h){let b=oe(e,n,Y(e,h,Y(e,Y(e,s,m),g)));o?d?f=oe(e,b,o):d=oe(e,b,Y(e,f,o)):(b=oe(e,b,f),d?o=oe(e,b,d):(o=Hn(e,b,new Oe(e,.5)),d=o))}else{o||(o=e.zero),d||(d=e.zero),!s&&!f&&!h&&(s=e.zero),!s&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!s&&!f?s=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let b=oe(e,n,Y(e,Y(e,o,m),Y(e,d,g)));this.isAutoHeight&&(l||(l=oe(e,b,s||f)),this.vertical&&(ae(e,t["column-width"],null)||ae(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),s?h?f||(f=oe(e,b,Y(e,s,h))):h=oe(e,b,Y(e,f,s)):s=oe(e,b,Y(e,f,h))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),y=it(e,w,i);t.top=new V(s),t["margin-top"]=new V(o),t["border-top-width"]=new V(r),t["padding-top"]=new V(a),t.height=new V(h),t["max-height"]=new V(l||h),t["padding-bottom"]=new V(c),t["border-bottom-width"]=new V(p),t["margin-bottom"]=new V(d),t.bottom=new V(f),t["snap-height"]=new V(y)}initColumns(){let e=this.pageBox.scope,t=this.style,i=ae(e,t[this.vertical?"height":"width"],null),n=ae(e,t["column-width"],i),s=ae(e,t["column-count"],null),o=sw(e,t["column-gap"],null);o||(o=new yn(e,1,"em")),n&&!s&&(s=new Ki(e,"floor",[to(e,Y(e,i,o),Y(e,n,o))]),s=new Ki(e,"max",[e.one,s])),s||(s=e.one),n=oe(e,to(e,Y(e,i,o),s),o),t["column-width"]=new V(n),t["column-count"]=new V(s),t["column-gap"]=new V(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,s=this.parentInstance?this.parentInstance.getActiveRegions(e):null,o=fu(this.cascaded,e,s,!1,null);this.vertical=du(o,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=pu(o,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=o["box-sizing"])==null?void 0:t.value)===v.border_box;let r=!!(e instanceof Lr&&e.currentLayoutPosition&&new Ae(i,"left-page").evaluate(e));mu(o,n,this.vertical,this.rtl,r,(a,h)=>h.value),this.autoWidth=new Ie(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new Ie(i,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(e,t){var i,n;let s=this.style[t];return!s&&tn(t)&&this.pageMasterInstance instanceof ki&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?s=new I(e.rootFontSize,"px"):s=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),s&&(s=as(e,s,t)),s}getPropAsNumber(e,t){var i,n;let s=this.style[t];if(s){let o=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();s=as(e,s,t,o)}return We(s,e)}getSpecial(e,t){let i=eu(this.cascaded,t);if(i){let n=[];for(let s=0;s<i.length;s++){let o=i[s].evaluate(e,"");o&&o!==W&&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 s=this.getProp(e,i);s&&(s.isNumeric()&&Ll(s.unit)&&(s=Kl(s,e)),i==="font-family"&&(s=n.filterFontFamily(s)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),T(t,i,s.toString()))}propagateDelayedProperty(e,t,i,n){let s=this.getProp(e,i);s&&n.push(new or(t.element,i,s))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),s=this.getPropAsNumber(e,"padding-left"),o=this.getPropAsNumber(e,"border-left-width"),r=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,r),T(t.element,"margin-left",`${n}px`),T(t.element,"padding-left",`${s}px`),T(t.element,"border-left-width",`${o}px`),t.marginLeft=n,t.borderLeft=o,t.paddingLeft=s}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),s=this.getPropAsNumber(e,"margin-right"),o=this.getPropAsNumber(e,"padding-right"),r=this.getPropAsNumber(e,"border-right-width");if(T(t.element,"margin-right",`${s}px`),T(t.element,"padding-right",`${o}px`),T(t.element,"border-right-width",`${r}px`),t.marginRight=s,t.borderRight=r,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"),s=this.getPropAsNumber(e,"margin-top"),o=this.getPropAsNumber(e,"padding-top"),r=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=s,t.borderTop=r,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,T(t.element,"top",`${n}px`),T(t.element,"margin-top",`${s}px`),T(t.element,"padding-top",`${o}px`),T(t.element,"border-top-width",`${r}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),s=this.getPropAsNumber(e,"border-bottom-width"),o=this.getPropAsNumber(e,"height")-t.snapOffsetY;T(t.element,"height",`${o}px`),T(t.element,"margin-bottom",`${i}px`),T(t.element,"padding-bottom",`${n}px`),T(t.element,"border-bottom-width",`${s}px`),t.height=o-t.snapOffsetY,t.marginBottom=i,t.borderBottom=s,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){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,s){(!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 o=0;o<Xa.length;o++)this.propagateProperty(e,t,Xa[o],n)}transferContentProps(e,t,i,n){for(let s=0;s<Ya.length;s++)this.propagateProperty(e,t,Ya[s],n);if(this.style["text-overflow"]){let s=t.element.firstElementChild;T(s,"text-overflow","inherit"),T(s,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var o,r;let a=(r=(o=this.cascaded.width)!=null?o:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:r.value;return!!a&&a!==v.auto&&!J(a)},s=()=>{var o,r;let a=(r=(o=this.cascaded.height)!=null?o:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:r.value;return!!a&&a!==v.auto&&!J(a)};for(let o=0;o<Ka.length;o++){let r=Ka[o];if(r==="width"||r==="height"){if(r==="width"&&!n()||r==="height"&&!s())continue;T(t,r,"100%");continue}this.propagatePropertyToElement(e,t,r,i)}}finishContainer(e,t,i,n,s,o,r){this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let a=(this.vertical||!n)&&this.isAutoHeight,h=(!this.vertical||!n)&&this.isAutoWidth,l=null;if(h||a){h&&T(t.element,"width","auto"),a&&T(t.element,"height","auto");let c=n&&Wh(n);c&&$h(n),l=o.getElementClientRect(n?n.element:t.element),c&&ar(n),h&&(this.calculatedWidth=Math.ceil(l.right-l.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),a&&(this.calculatedHeight=l.bottom-l.top-t.paddingTop-t.borderTop-t.paddingBottom-t.borderBottom,this.vertical||(this.calculatedHeight+=t.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(e,t),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),s>1){let c=this.getPropAsNumber(e,"column-rule-width"),p=this.getProp(e,"column-rule-style"),d=this.getProp(e,"column-rule-color");if(c>0&&p&&p!=v.none&&d!=v.transparent){let f=this.getPropAsNumber(e,"column-gap"),m=this.vertical?t.height:t.width,g=this.vertical?"border-top":"border-left";for(let w=1;w<s;w++){let y=this.vertical?(m+f)*w/s-f/2+t.paddingTop-c/2:(m+f)*w/s-f/2+t.paddingLeft-c/2,b=this.vertical?t.width+t.paddingLeft+t.paddingRight:t.height+t.paddingTop+t.paddingBottom,C=t.element.ownerDocument.createElement("div");T(C,"position","absolute"),T(C,this.vertical?"left":"top","0px"),T(C,this.vertical?"top":"left",`${y}px`),T(C,this.vertical?"height":"width","0px"),T(C,this.vertical?"width":"height",`${b}px`),T(C,g,`${c}px ${p.toString()}${d?` ${d.toString()}`:""}`),t.element.insertBefore(C,t.element.firstChild)}}}for(let c=0;c<qa.length;c++)this.propagateProperty(e,t,qa[c],r);for(let c=0;c<Za.length;c++)this.propagateDelayedProperty(e,t,Za[c],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let o in n)this instanceof ki&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(o==="writing-mode"||o==="direction")||Ci(o)&&ti(i,o,Ve(n,o));if(this.pageBox.pseudoName==Pr)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 s=i.content;s&&(i.content=s.filterValue(new Ao(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)}},Xa=["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"],qa=["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"],Ya=["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"],Ka=["width","height","image-resolution","object-fit","object-position"],Za=["transform","transform-origin"],Pr="background-host",ow=class extends Es{constructor(e){super(null,e)}applyCascadeAndInit(e,t){super.applyCascadeAndInit(e,t),this.children.sort((i,n)=>n.pageBox.specificity-i.pageBox.specificity||i.pageBox.index-n.pageBox.index)}},Nr=class extends Es{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=dt(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},rw=class extends Es{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},Ai=class extends Es{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof nt&&(n=[t]),t instanceof qe&&(n=t.values),n){let s=this.pageBox.scope;for(let o=0;o<n.length;o++)if(n[o]instanceof nt){let r=Zs(n[o].name,"enabled"),a=new Ae(s,r);i&&(a=new Ut(s,a)),e=dt(s,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=tc(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let s=nw(t,i["flow-from"],"body"),o=new Ki(t,"has-content",[s]);e=dt(t,e,o)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let s=this.pageMasterInstance.style.enabled,o=s?s.toExpr(t,null):t._true;o=dt(t,o,e),this.pageMasterInstance.style.enabled=new V(o)}return e}prepareContainer(e,t,i,n,s){var o;this.pageBox.pageMaster instanceof rc||(T(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(o=this.pageBox.name)!=null?o:"")),super.prepareContainer(e,t,i,n,s)}},Tr=class extends En{constructor(e,t,i,n){super(e,t,!1),this.target=i,this.validatorSet=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}simpleProperty(e,t,i){this.target.specified[e]=new Z(t,i?mh:wh)}},ic=class extends Tr{constructor(e,t,i,n){super(e,t,i,n)}},aw=class nc extends Tr{constructor(t,i,n,s){super(t,i,n,s),n.specified.width=new Z(Qr,0),n.specified.height=new Z(Qr,0)}startPartitionRule(t,i,n){let s=new Tn(this.scope,t,i,n,this.target),o=new ic(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,i,n){let s=new Ju(this.scope,t,i,n,this.target),o=new nc(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}},lw=class extends Tr{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new Tn(this.scope,e,t,i,this.target),s=new ic(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(e,t,i){let n=new Ju(this.scope,e,t,i,this.target),s=new aw(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}};function sc(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,s=(i=e.direction)==null?void 0:i.value;return n===v.vertical_lr||n!==v.vertical_rl&&s!==v.rtl?"ltr":"rtl"}var hw={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")}},uw=new I(.24,"pt"),Pb=new I(3,"mm"),cw=new I(10,"mm"),dw=new I(13,"mm");function us(e){let t={width:xn,height:Sn,bleed:fe,bleedOffset:fe,cropOffset:fe},i=e.size;if(!(!i||i.value===v.auto)){let l=i.value,c,p;if(l.isSpaceList()?(c=l.values[0],p=l.values[1]):(c=l,p=null),c.isNumeric())t.width=c,t.height=p||c;else{let d=c.name&&hw[c.name.toLowerCase()];d&&(p&&p===v.landscape?(t.width=d.height,t.height=d.width):(t.width=d.width,t.height=d.height))}}let n=e.marks,s=e.bleed,o=n&&!J(n.value)?n.value:v.none,r=s&&!J(s.value)?s.value:v.auto;if(r===v.auto){if(o!==v.none){let l=!1;o.isSpaceList()?l=o.values.some(c=>c===v.crop):l=o===v.crop,l&&(t.bleed=new I(6,"pt"))}}else r.isNumeric()&&(t.bleed=r);let a=e["crop-offset"],h=a&&!J(a.value)?a.value:v.auto;return h===v.auto?o!==v.none&&(t.bleedOffset=dw):h.isNumeric()&&(t.cropOffset=h),t}function Ja(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),s=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),o=n+s,r=e.width;r===xn?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-o*2:i.pageWidth=r.num*t.queryUnitSize(r.unit,!1);let a=e.height;return a===Sn?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-o*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=s,i.cropOffset=o,i}function oc(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 rn(e,t,i,n){n=n||"polyline";let s=e.createElementNS("http://www.w3.org/2000/svg",n);return s.setAttribute("stroke",i===v.auto?"#010101":i.toString()),s.setAttribute("stroke-width",t),s.setAttribute("fill","none"),s}var zo=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(zo||{});function pw(e,t,i,n,s,o,r){let a=s;a<=o+2*ge.mm&&(a=o+s/2);let h=Math.max(s,a),l=o+h+i/2,c=oc(e,l,l),p=[[0,o+s],[s,o+s],[s,o+s-a]],d=p.map(g=>[g[1],g[0]]);(t==="top right"||t==="bottom right")&&(p=p.map(g=>[o+h-g[0],g[1]]),d=d.map(g=>[o+h-g[0],g[1]])),(t==="bottom left"||t==="bottom right")&&(p=p.map(g=>[g[0],o+h-g[1]]),d=d.map(g=>[g[0],o+h-g[1]]));let f=rn(e,i,n);f.setAttribute("points",p.map(g=>g.join(",")).join(" ")),c.appendChild(f);let m=rn(e,i,n);return m.setAttribute("points",d.map(g=>g.join(",")).join(" ")),c.appendChild(m),t.split(" ").forEach(g=>{c.style[g]=`${r}px`}),c}var mn=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(mn||{});function fw(e,t,i,n,s,o){let r=s*2,a,h;t==="top"||t==="bottom"?(a=r,h=s):(a=s,h=r);let l=oc(e,a,h),c=rn(e,i,n);c.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(c);let p=rn(e,i,n);p.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(p);let d=rn(e,i,n,"circle");d.setAttribute("cx",a/2),d.setAttribute("cy",h/2),d.setAttribute("r",s/4),l.appendChild(d);let f;switch(t){case"top":f="bottom";break;case"bottom":f="top";break;case"left":f="right";break;case"right":f="left";break}return Object.keys(mn).forEach(m=>{let g=mn[m];g===t?l.style[g]=`${o}px`:g!==f&&(l.style[g]="0",l.style[`margin-${g}`]="auto")}),l}function gw(e,t,i,n){let s=!1,o=!1,r=e.marks;if(r){let g=r.value;g instanceof me?g.values.forEach(w=>{w===v.crop?s=!0:w===v.cross&&(o=!0)}):g===v.crop?s=!0:g===v.cross&&(o=!0)}let a=t.bleed;if(!s&&!o)return;let h=i.container,l=h.ownerDocument,c=We(uw,n),p=Math.max(0,t.bleedOffset-We(cw,n)),d=t.bleedOffset-p,f=e["crop-marks-line-color"],m=f&&!J(f.value)?f.value:v.auto;s&&Object.keys(zo).forEach(g=>{let w=zo[g],y=pw(l,w,c,m,d,a,p);h.appendChild(y)}),o&&Object.keys(mn).forEach(g=>{let w=mn[g],y=fw(l,w,c,m,d,p);h.appendChild(y)})}var Do=(()=>{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})(),Ir={"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"}},mw=(()=>{let e=Ir;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),Ar="vivliostyle-page-rule-master",wn="_marginBoxes",rc=class extends Ku{constructor(e,t,i){super(e,null,Ar,[],t,null,0),u(this,"pageMarginBoxes",{});let n=us(i),s=new ww(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[wn];t&&mw.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new vw(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new Z(v.relative,0),this.specified.width=new Z(t.width,0),this.specified.height=new Z(t.height,0);for(let i in e)!Do[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new ki(e,this)}},ww=class extends Tn{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let s=new bw(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new Z(v.auto,0),this.specified["z-index"]=new Z(new si(0),0),this.specified.position=new Z(v.absolute,0),this.specified.overflow=new Z(v.visible,0);for(let t in Do)Do.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new xw(e,this)}},bw=class extends Tn{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new Z(B("body"),0)}createInstance(e){return new ac(e,this)}},vw=class extends Tn{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[wn][this.marginBoxName];for(let i in e){let n=e[i],s=t[i];(Yh[i]||s&&s.value===v.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==W&&n.value!==v.inherit&&n.value!==v.unset&&n.value!==v.revert&&(this.specified[i]=n)}}createInstance(e){return new lc(e,this)}},ki=class extends Nr{constructor(e,t){super(e,t),u(this,"pageAreaDimension",null),u(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,t){let i=this.cascaded;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n))switch(n){case"writing-mode":case"direction":i[n]=t[n]}super.applyCascadeAndInit(e,t)}initHorizontal(){let e=this.style;e.left=fe,e["margin-left"]=fe,e["border-left-width"]=fe,e["padding-left"]=fe,e["padding-right"]=fe,e["border-right-width"]=fe,e["margin-right"]=fe,e.right=fe}initVertical(){let e=this.style;e.top=fe,e["margin-top"]=fe,e["border-top-width"]=fe,e["padding-top"]=fe,e["padding-bottom"]=fe,e["border-bottom-width"]=fe,e["margin-bottom"]=fe,e.bottom=fe}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new V(e.borderBoxWidth),t.height=new V(e.borderBoxHeight),t["padding-left"]=new V(e.marginLeft),t["padding-right"]=new V(e.marginRight),t["padding-top"]=new V(e.marginTop),t["padding-bottom"]=new V(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,s={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,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,o,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,o,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,s){let o="start",r="center",a="end",h=this.pageBox.scope,l={},c={},p={};for(let C in e){let k=Ir[C];if(k){let R=e[C],_=this.pageMarginBoxInstances[C],z=new qn(R,_.style,t,h,s);l[k.positionAlongVariableDimension]=R,c[k.positionAlongVariableDimension]=_,p[k.positionAlongVariableDimension]=z}}let d={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),m=!1,g={};Object.keys(l).forEach(C=>{let k=C,R=ae(h,c[k].style[t?"max-width":"max-height"],i.extent);if(R){let _=R.evaluate(n);if(f[k]>_){let z=p[k]=new Qa(l[k],c[k].style,t,h,s,_);g[k]=z.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),m=!1,[o,r,a].forEach(C=>{var k;f[C]=(k=g[C])!=null?k:f[C]}));let w={};Object.keys(l).forEach(C=>{let k=C,R=ae(h,c[k].style[t?"min-width":"min-height"],i.extent);if(R){let _=R.evaluate(n);if(f[k]<_){let z=p[k]=new Qa(l[k],c[k].style,t,h,s,_);w[k]=z.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),[o,r,a].forEach(C=>{f[C]=w[C]||f[C]}));let y=d.start+d.extent,b=d.start+(d.start+d.extent);[o,r,a].forEach(C=>{let k=f[C];if(k!=null){let R=l[C],_=0;switch(C){case o:_=t?R.left:R.top;break;case r:_=(b-k)/2;break;case a:_=y-k;break}t?R.setHorizontalPosition(_,k-R.getInsetLeft()-R.getInsetRight()):R.setVerticalPosition(_,k-R.getInsetTop()-R.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,s=e.center,o=e.end,r={};if(s){let a=[n,o],h=new yw(a),l=this.distributeAutoMarginBoxSizes(s,h,t);l.xSize!=null&&(r.center=l.xSize);let c=(i=l.xSize)!=null?i:s.getOuterSize(),p=Math.max((t-c)/2,0);n&&(r.start=n.hasAutoSize()?p:n.getOuterSize()),o&&(r.end=o.hasAutoSize()?p:o.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,o,t);a.xSize!=null&&(r.start=a.xSize),a.ySize!=null&&(r.end=a.ySize)}return r}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e instanceof qn&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof qn&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let s=e.getOuterMaxContentSize(),o=t.getOuterMaxContentSize();if(s>0&&o>0){let r=s+o;if(r<i)n.xSize=i*s/r;else{let a=e.getOuterMinContentSize(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(s-a)/(r-l):l>0&&(n.xSize=i*a/l)}n.xSize>0&&(n.ySize=i-n.xSize)}else s>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,s){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,s)}},qn=class{constructor(e,t,i,n,s){this.container=e,this.isHorizontal=i,this.clientLayout=s,u(this,"hasAutoSize_"),u(this,"size",null),u(this,"minMaxFitContent",null);let o=t[i?"width":"height"];if(this.hasAutoSize_=!o||o===v.auto||J(o),this.minMaxFitContent=o instanceof nt&&(o.name==="min-content"||o.name==="max-content"||o.name==="fit-content")?o.name:null,this.minMaxFitContent){let r=this.getSize();if(this.isHorizontal){let a=r[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=r[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=sr(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()}},yw=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}},Qa=class extends qn{constructor(e,t,i,n,s,o){super(e,t,i,n,s),u(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()}},xw=class extends Ai{constructor(e,t){super(e,t),u(this,"borderBoxWidth",null),u(this,"borderBoxHeight",null),u(this,"contentBoxWidth",null),u(this,"contentBoxHeight",null),u(this,"marginTop",null),u(this,"marginRight",null),u(this,"marginBottom",null),u(this,"marginLeft",null)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^background-/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,t),this.parentInstance.setPageAreaDimension({borderBoxWidth:this.borderBoxWidth,borderBoxHeight:this.borderBoxHeight,marginTop:this.marginTop,marginRight:this.marginRight,marginBottom:this.marginBottom,marginLeft:this.marginLeft})}initHorizontal(){let e=this.resolvePageBoxDimensions({start:"left",end:"right",extent:"width"});this.borderBoxWidth=e.borderBoxExtent,this.contentBoxWidth=e.contentBoxExtent,this.marginLeft=e.marginStart,this.marginRight=e.marginEnd}initVertical(){let e=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.borderBoxHeight=e.borderBoxExtent,this.contentBoxHeight=e.contentBoxExtent,this.marginTop=e.marginStart,this.marginBottom=e.marginEnd}resolvePageBoxDimensions(e){let t=this.style,i=this.pageBox.pageSize,n=this.pageBox.scope,s=e.start,o=e.end,r=e.extent,a=i[r].toExpr(n,null),h=ae(n,t[r],a),l=ae(n,t[`margin-${s}`],a),c=ae(n,t[`margin-${o}`],a),p=it(n,t[`padding-${s}`],a),d=it(n,t[`padding-${o}`],a),f=Ct(n,t[`border-${s}-width`],t[`border-${s}-style`],a),m=Ct(n,t[`border-${o}-width`],t[`border-${o}-style`],a),g=Y(n,Y(n,f,p),Y(n,m,d)),w,y,b;return h?(this.borderBoxSizing?(y=h,b=oe(n,y,g)):(b=h,y=Y(n,b,g)),w=oe(n,a,y),!l&&!c?(l=Hn(n,w,new Oe(n,.5)),c=l):l?c=oe(n,w,l):l=oe(n,w,c)):(l||(l=n.zero),c||(c=n.zero),w=Y(n,l,c),y=oe(n,a,w),b=oe(n,y,g),h=this.borderBoxSizing?y:b),t[s]=new V(l),t[o]=new V(c),t[`margin-${s}`]=fe,t[`margin-${o}`]=fe,t[`border-${s}-width`]=new V(f),t[`border-${o}-width`]=new V(m),t[`padding-${s}`]=new V(p),t[`padding-${o}`]=new V(d),t[r]=new V(h),t[`max-${r}`]=new V(h),{borderBoxExtent:y,contentBoxExtent:b,marginStart:l,marginEnd:c}}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,s)}},ac=class extends Ai{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 V(this.parentInstance.contentBoxWidth),e["margin-left"]=new V(new fi(i,t.left.toExpr(i,null))),e["margin-right"]=new V(new fi(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=v.solid,e["border-right-style"]=v.solid,e["border-left-color"]=v.transparent,e["border-right-color"]=v.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new V(this.parentInstance.contentBoxHeight),e["margin-top"]=new V(new fi(i,t.top.toExpr(i,null))),e["margin-bottom"]=new V(new fi(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=v.solid,e["border-bottom-style"]=v.solid,e["border-top-color"]=v.transparent,e["border-bottom-color"]=v.transparent}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,s),e.pageAreaWidth=t.width,e.pageAreaHeight=t.height}},lc=class extends Ai{constructor(e,t){super(e,t),u(this,"boxInfo"),u(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=Ir[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,s)}applyVerticalAlign(e,t){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===B("middle")?n="center":i===B("top")?n="flex-start":i===B("bottom")&&(n="flex-end"),n&&T(t,"justify-content",n);let s=this.getProp(e,"content");if(this.vertical||s instanceof pt||s instanceof V&&s.expr instanceof Ie&&s.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")),T(t,"align-items",o)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,s=e.start,o=e.end,r=e.extent,a=s==="left",h=a?t.borderBoxWidth:t.borderBoxHeight,l=ae(n,i[r],h),c=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[s]=new V(c);else if(l){let p=it(n,i[`margin-${s}`],h),d=it(n,i[`margin-${o}`],h),f=it(n,i[`padding-${s}`],h),m=it(n,i[`padding-${o}`],h),g=Ct(n,i[`border-${s}-width`],i[`border-${s}-style`],h),w=Ct(n,i[`border-${o}-width`],i[`border-${o}-style`],h),y=Y(n,l,Y(n,this.borderBoxSizing?n.zero:Y(n,Y(n,f,m),Y(n,g,w)),Y(n,p,d)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[s]=new V(Y(n,c,to(n,oe(n,h,y),new Oe(n,2))));break;case"end":i[s]=new V(oe(n,Y(n,c,h),y));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,s=this.borderBoxSizing,o=e.inside,r=e.outside,a=e.extent,h=t[`margin${r.charAt(0).toUpperCase()}${r.substring(1)}`],l=ja(n,i[`margin-${o}`],h),c=ja(n,i[`margin-${r}`],h),p=it(n,i[`padding-${o}`],h),d=it(n,i[`padding-${r}`],h),f=Ct(n,i[`border-${o}-width`],i[`border-${o}-style`],h),m=Ct(n,i[`border-${r}-width`],i[`border-${r}-style`],h),g=ae(n,i[a],h),w=null;function y(b){if(w)return w;w={extent:g?g.evaluate(b):null,marginInside:l?l.evaluate(b):null,marginOutside:c?c.evaluate(b):null};let C=h.evaluate(b),k=0;return s||[f,p,d,m].forEach(R=>{R&&(k+=R.evaluate(b))}),(w.marginInside===null||w.marginOutside===null)&&k+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-k-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-k-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=C-k-w.extent-w.marginInside:w.marginInside=w.marginOutside=(C-k-w.extent)/2),w}i[a]=new V(new Ie(n,function(){let b=y(this).extent;return b===null?"auto":b},a)),i[`margin-${o}`]=new V(new Ie(n,function(){let b=y(this).marginInside;return b===null?"auto":b},`margin-${o}`)),i[`margin-${r}`]=new V(new Ie(n,function(){let b=y(this).marginOutside;return b===null?"auto":b},`margin-${r}`)),o==="left"?i.left=new V(Y(n,t.marginLeft,t.borderBoxWidth)):o==="top"&&(i.top=new V(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,s,o,r){super.finishContainer(e,t,i,n,s,o,r);let a=i.marginBoxes,h=this.pageBox.marginBoxName,l=this.boxInfo;!l.isInLeftColumn&&!l.isInRightColumn?l.isInTopRow?a.top[h]=t:l.isInBottomRow&&(a.bottom[h]=t):!l.isInTopRow&&!l.isInBottomRow&&(l.isInLeftColumn?a.left[h]=t:l.isInRightColumn&&(a.right[h]=t));let c=this.parentInstance.pageAreaDimension,p=this.getProp(e,"width"),d=p instanceof nt&&(p.name==="min-content"||p.name==="max-content"||p.name==="fit-content")?p.name:null,f=this.getPropAsNumber(e,"min-width"),m=this.getPropAsNumber(e,"max-width");if(d||f||m){d&&T(t.element,"width",d),f&&T(t.element,"min-width",`${f}px`),m&&T(t.element,"max-width",`${m}px`);let C=this.getProp(e,"margin-left"),k=this.getProp(e,"margin-right");if(l.isInLeftColumn){let R=c.borderBoxWidth.evaluate(e)+c.marginRight.evaluate(e);T(t.element,"right",`${R}px`),(C===v.auto||k!==v.auto)&&T(t.element,"margin-left","auto"),k===v.auto&&T(t.element,"margin-right","auto")}else l.isInRightColumn&&(T(t.element,"right","0"),(k===v.auto||C!==v.auto)&&T(t.element,"margin-right","auto"),C===v.auto&&T(t.element,"margin-left","auto"))}let g=this.getProp(e,"height"),w=g instanceof nt&&(g.name==="min-content"||g.name==="max-content"||g.name==="fit-content")?g.name:null,y=this.getPropAsNumber(e,"min-height"),b=this.getPropAsNumber(e,"max-height");if(w||y||b){w&&T(t.element,"height",w),y&&T(t.element,"min-height",`${y}px`),b&&T(t.element,"max-height",`${b}px`);let C=this.getProp(e,"margin-top"),k=this.getProp(e,"margin-bottom");if(l.isInTopRow){let R=c.borderBoxHeight.evaluate(e)+c.marginBottom.evaluate(e);T(t.element,"bottom",`${R}px`),(C===v.auto||k!==v.auto)&&T(t.element,"margin-top","auto"),k===v.auto&&T(t.element,"margin-bottom","auto")}else l.isInBottomRow&&(T(t.element,"bottom","0"),(k===v.auto||C!==v.auto)&&T(t.element,"margin-bottom","auto"),C===v.auto&&T(t.element,"margin-top","auto"))}}},Sw=class{constructor(e,t,i,n,s){this.cascadeInstance=e,this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=s,u(this,"pageMasterCache",{}),this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new Ae(e,"page-number"),s=new Zo(e,new Dl(e,n,new Oe(e,2)),i?e.one:e.zero);e.defineName("recto-page",new Ut(e,s)),e.defineName("verso-page",s),(t.pageProgression||sc(this.docElementStyle))==="ltr"?(e.defineName("left-page",s),e.defineName("right-page",new Ut(e,s))):(e.defineName("left-page",new Ut(e,s)),e.defineName("right-page",s))}getCascadedPageStyle(e){let t={};return this.cascadeInstance.pushRule([],e,t),this.cascadeInstance.popRule(),t}getPageRulePageMaster(e,t){let i=e.pageBox;if(Object.keys(t).length===0)return i.resetScope(),e;let n=this.makeCacheKey(t,i),s=this.pageMasterCache[n];return s||(i.pseudoName===Pr?s=this.generatePageRuleMaster(t):s=this.generateCascadedPageMaster(t,i),this.pageMasterCache[n]=s),s.pageBox.resetScope(),s}makeCacheKey(e,t){var i;let n=this.makeCascadeValueObjectKey(e),s=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${t.key}^${n}^${s}`}makeCascadeValueObjectKey(e){let t=[];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],s;n instanceof Z?s=`${n.value}`:s=this.makeCascadeValueObjectKey(n),t.push(i+s+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new rc(this.pageScope,this.rootPageBoxInstance.pageBox,e).createInstance(this.rootPageBoxInstance);return t.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),t.resolveAutoSizing(this.context),t}generateCascadedPageMaster(e,t){let i=t.clone({pseudoName:Ar}),n=i.specified,s=e.size;if(s&&!J(s.value)){let r=us(e),a=s.priority;Lt(n,"width",new Z(r.width,a),this.context),Lt(n,"height",new Z(r.height,a),this.context)}["counter-reset","counter-increment"].forEach(r=>{n[r]&&(e[r]=n[r])});let o=i.createInstance(this.rootPageBoxInstance);return o.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),o.resolveAutoSizing(this.context),o}},Cw=class extends de{constructor(e){super(),this.pageType=e}apply(e){e.currentPageType===this.pageType&&this.chained.apply(e)}getPriority(){return 3}makePrimary(e){return this.chained&&e.insertInTable(e.pagetypes,this.pageType,this.chained),!0}},Ew=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ae(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},kw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ae(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},Pw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ae(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Nw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ae(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Tw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ae(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Iw=class extends de{constructor(e){super(),this.scope=e}apply(e){new Ae(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Aw=class extends Nn{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}},Rw=class extends gr{constructor(e,t){super(e,t,null,null,null)}apply(e){Lw(e.context,e.currentStyle,this.style,this.specificity,e)}};function Lw(e,t,i,n,s){rs(e,t,i,n,null,null,null);let o=i[wn];if(o){let r=ys(t,wn);for(let a in o)if(o.hasOwnProperty(a)){let h=r[a];h||(h={},r[a]=h),rs(e,h,o[a],n,null,null,null)}}}var Fw=class extends cn{constructor(e,t,i,n,s){super(e,t,i?.condition,i,null,n,!1),this.pageProps=s,u(this,"currentPageSelectors",[]),u(this,"currentNamedPageSelector",""),u(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new Cw(t)),this.specificity+=65536)}pseudoclassSelector(e,t){if(e=e.toLowerCase(),t)switch(e){case"nth":{let[i,n]=t;this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new Aw(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 Ew(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new kw(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new Pw(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new Nw(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new Tw(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Iw(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=Ve(this.elementStyle,e),s=this.pageProps;if(e==="bleed"||e==="marks")s[""]||(s[""]={}),Object.keys(s).forEach(o=>{ti(s[o],e,n)});else if(e==="size"){let o=s[""];this.currentPageSelectors.forEach(r=>{let a=new Z(n.value,n.priority+r.specificity),h=r.selectors?r.selectors.join(""):"",l=s[h];l?Lt(l,e,a):(l=s[h]={},ti(l,e,a),o&&["bleed","marks"].forEach(c=>{o[c]&&ti(l,c,o[c])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new Rw(this.elementStyle,e)}startPageMarginBoxRule(e){let t=ys(this.elementStyle,wn),i=t[e];i||(i={},t[e]=i);let n=new Ow(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},Ow=class extends En{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.boxStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),s=new Z(t,n);ti(this.boxStyle,e,s)}},Ft=!0;function Bw(e){Ft=e}var ii=[];function el(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function hc(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 Rr(e,t,i){var n,s;if(!Ft||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&hc(e.ownerDocument).includes(e))return P(!1);let o=e.textContent,r=e.src,a=e.type==="module",h=(a||r)&&e.async,l=a&&!h||r&&e.defer,c=!(i!=null&&i.atEnd)&&(i?.forceDefer||l||h);if(uc(t)||(t.onload=null),c)return ii.some(d=>el(d,e))||ii.push(e),P(!0);if(r.includes("/mathjax")){let d=t.document.head.querySelector("script[src*='MathJax.js']:not([data-vivliostyle-scripting])");if(d){if(r.includes("/mathjax@3"))t.document.head.removeChild(d),(s=(n=t.MathJax)==null?void 0:n.version)!=null&&s.startsWith("2.")&&delete t.MathJax;else if(r.includes("/MathJax.js"))return P(!0)}}for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&el(d,e)&&t.document.head.removeChild(d);let p=t.document.createElement("script");p.textContent=o,r&&(p.src=r),p.async=h,p.defer=l,p.setAttribute("data-vivliostyle-scripting","true");for(let d of e.attributes)["src","async","defer"].includes(d.name)||p.setAttribute(d.name,d.value);if(H.debug("script:",r),r){let d=ui(p);return t.document.head.appendChild(p),ws([d])}else return t.document.head.appendChild(p),P(!0)}function _w(e,t){var i;let n={},s=r=>{var a;let h=(a=r["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let c of h.values)n[c.stringValue()]=!0;else n[h.stringValue()]=!0;let l=r._marginBoxes;if(l)for(let c of Object.values(l))s(c)},o=r=>{if(r instanceof gr)s(r.style);else if(r instanceof _i||Array.isArray(r))for(let a of Object.values(r))o(a)};for(let r of Object.values(t.cascade.code))for(let a of Object.values(r??{}))o(a);for(let r of e.querySelectorAll("[style]"))(i=r.style)!=null&&i.fontFamily&&(n[r.style.fontFamily]=!0);return Object.keys(n).join(",")}function Mw(e,t,i){var n;let s=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return s.style.position="fixed",s.style.fontSize="0",s.setAttribute("data-vivliostyle-textcontent","true"),s.setAttribute("aria-hidden","true"),s.style.fontFamily=_w(e,i),s.textContent=e.documentElement.textContent,t.document.body.appendChild(s),s}function zw(e,t,i){if(!Ft)return P(!1);let n=hc(e);if(n.length===0)return P(!1);let s=n.some(c=>!(c.async||c.defer||c.type==="module")),o=s?Mw(e,t,i):null,r=t.document.fonts,a=t.$,h=!1,l=F("loadScripts");return l.loop(()=>{if(n.length===0)return s?l.sleep(20).thenAsync(()=>{var p,d;return r.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(p=t.FontJSON)!=null&&p.Font&&(d=t.ret)!=null&&d.readyState&&t.ret.readyState<4?P(!0):P(!1)}):P(!1);let c=n.shift();return Rr(c,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(ii.push(c),h=!0),n.length===0&&s&&(H.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),P(!0)))}).then(()=>{o&&o.remove(),l.finish(!0)}),l.result()}function Dw(e){if(!Ft)return P(!1);let t=F("loadScripts");return t.loop(()=>ii.length===0?P(!1):Rr(ii.shift(),e,{atEnd:!0}).thenReturn(ii.length>0)).then(()=>{H.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),H.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function uc(e){return Ft?ii.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var Vw=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,s)=>`url("${i.transformURL(s,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,s)=>`url('${i.transformURL(s,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,s)=>`url(${i.transformURL(s,t)}`),Uw={};function Hw(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 cc=class Vo extends Xo{constructor(t,i,n,s,o,r,a,h,l,c,p,d,f){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=s,this.regionIds=o,this.xmldoc=r,this.docFaces=a,this.footnoteStyle=h,this.stylerProducer=l,this.page=c,this.customRenderer=p,this.fallbackMap=d,this.documentURLTransformer=f,u(this,"document"),u(this,"exprContentListener"),u(this,"nodeContext",null),u(this,"viewRoot",null),u(this,"isFootnote",!1),u(this,"sourceNode",null),u(this,"offsetInNode",0),u(this,"viewNode",null),this.document=n.document,this.exprContentListener=s.counterListener.getExprContentListener()}clone(){return new Vo(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer)}createPseudoelementShadow(t,i,n,s,o,r,a,h){let l=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,r);if(!l)return h;let c=[],p=Wn.createElementNS("http://www.pyroxy.com/ns/shadow","root"),d=p;for(let m of Dg){let g;if(m){if(!l[m]||m=="footnote-marker"&&!(i&&this.isFootnote))continue;if(m.match(/^first-/)){let w=s.display;if(!w||w===v.inline)continue;let y=t.firstElementChild;if(y&&ze(y.previousSibling)){let b=o.getStyle(y,!1);if(b){let C=Ve(b,"display");if(C!=null&&C.value&&C.value!==v.inline)continue}}}if(m==="before"||m==="after"){let w=l[m].content;if(!w||!jt(w.value))continue}c.push(m),g=Wn.createElementNS("http://www.w3.org/1999/xhtml","span"),Fo(g,m)}else g=Wn.createElementNS("http://www.pyroxy.com/ns/shadow","content");d.appendChild(g),m.match(/^first-/)&&(d=g)}if(!c.length)return h;let f=new _a(t,n,o,r,this.exprContentListener);return new co(t,p,null,a,h,ht.ROOTLESS,f)}getPseudoMap(t,i,n,s,o){let r=bt(t,"_pseudos");if(!r)return null;let a={};for(let h in r){let l=a[h]={};sn(l,r[h],o),Lo(l,o,r[h]),gu(r[h],i,n,(c,p)=>{sn(l,p,o),cu(p,d=>{sn(l,d,o)})})}return a}createRefShadow(t,i,n,s,o){let r=F("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let h=a;if(h){let l=h.getElement(t);if(l){let c=this.stylerProducer.getStylerForDoc(h);o=new co(n,l,h,s,o,i,c)}}r.finish(o)}),r.result()}createShadows(t,i,n,s,o,r,a){let h=F("createShadows"),l=null,c=s.template,p;if(c instanceof pt||c===v.footnote){let d=c instanceof pt?c.url:Ee("user-agent.xml#footnote",ni);p=this.createRefShadow(d,ht.ROOTLESS,t,a,l)}else p=P(l);return p.then(d=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let g=t.getAttribute("href"),w=null;g?w=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?g=a.owner.getAttribute("href"):g=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),w=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),g&&(g=Ee(g,w.url),f=this.createRefShadow(g,ht.ROOTED,t,a,d))}f==null&&(f=P(d));let m=null;f.then(g=>{if(s.display===v.table_cell){let w=Ee("user-agent.xml#table-cell",ni);m=this.createRefShadow(w,ht.ROOTLESS,t,a,g)}else m=P(g);m.then(w=>{w=this.createPseudoelementShadow(t,i,n,s,o,r,a,w),h.finish(w)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,s){var o;let r=this.context,a=fu(n,r,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=du(a,r,t);let c=!h&&t!==l;i=pu(a,r,i);let p=(y,b)=>{let C;c&&(t?/^(min-|max-)?(height|inline-size)$/.test(y)&&(C=r.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(y)&&(C=r.pageAreaWidth));let k=b.evaluate(r,y,C,t);return y=="font-family"&&(k=this.docFaces.filterFontFamily(k)),k},d=!!new Ae(r.style.pageScope,"left-page").evaluate(r);if(mu(a,s,t,i,d,p),c){let y=s[t?"height":"width"];(!y||y===v.auto)&&(s[t?"height":"width"]=v.max_content)}if(go(s.position))return s.position=v.fixed,s.visibility=v.hidden,t;let f=s.position,m=s.float,g=s.display||(this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?v.inline:void 0),w=Vh(g,f,m,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(y=>{w[y]&&(s[y]=w[y])}),t}inheritFromSourceParent(t){let i=this.nodeContext.sourceNode,n=[],s=null,o=this.nodeContext.shadowContext,r=-1;for(;i&&i.nodeType==1;){let p=o&&o.root==i;if(!p||o.type==ht.ROOTLESS){let d=(o?o.styler:this.styler).getStyle(i,!1);n.push(d),s=s||Ys(i)}p?(i=o.owner,o=o.parentShadow):(i=i.parentNode,r++)}let a=r===0,h=this.context.queryUnitSize("em",a),l={"font-size":new Z(new I(h,"px"),0)},c=new $f(l,this.context);for(let p=n.length-1;p>=0;--p){let d=n[p],f=[];for(let w in d)tn(w)&&f.push(w);f.sort(ta);let m,g;for(let w of f){c.setPropName(w);let y=Ve(d,w),b=y;if(!J(y.value)){if(w==="font-size"&&p===n.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)b=new Z(new I(this.context.rootFontSize,"px"),y.priority);else if(w==="line-height"&&p===n.length-1&&this.context.rootLineHeight&&y.value instanceof I&&(y.value.unit==="lh"||y.value.unit==="rlh"))b=new Z(new I(this.context.rootLineHeight,"px"),y.priority);else if(p===0&&y.value instanceof I&&y.value.unit==="lh"){let C=this.getLineHeightUnitSize(w,m,g);C!=null&&(b=new Z(new I(y.value.num*C,"px"),y.priority))}else At(w)||(b=y.filterValue(c));w==="font-size"?m=b.value:w==="line-height"&&(g=b.value),l[w]=b}}}for(let p in t)tn(p)||(l[p]=t[p]);return{lang:s,elementStyle:l}}resolveURL(t){return t=Ee(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=Ys(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=Of().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let s in this.nodeContext.parent.inheritedProps)n[s]=this.nodeContext.parent.inheritedProps[s]}i.forEach(s=>{let o=t[s];if(o){if(J(o))o===v.initial&&(n[s]=void 0);else if(o instanceof si)n[s]=o.num;else if(o instanceof nt)n[s]=o.name;else if(o instanceof I){let r=o;switch(r.unit){case"dpi":case"dpcm":case"dppx":n[s]=r.num*ge[r.unit];break;default:n[s]=o}}else n[s]=o;["widows","orphans"].includes(s)||delete t[s]}})}}resolveFormattingContext(t,i,n,s,o,r){let a=vt("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,s,o,r);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,s,o,r;let a=!0,h=F("createElementView"),l=this.sourceNode,c=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,p=c.getStyle(l,!1);if(!this.nodeContext.shadowContext){let k=this.xmldoc.getElementOffset(l);vs.registerFragmentIndex(k,this.nodeContext.fragmentIndex,0)}let d={};if(!this.nodeContext.parent){let k=this.inheritFromSourceParent(p);p=k.elementStyle,this.nodeContext.lang=k.lang}let f=p.position,m=p.float,g=p["float-reference"],w=m&&!J(m.value)&&m.value!==v.none&&g&&!J(g.value)?df(g.value.toString()):null;if(this.nodeContext.parent&&(go(f?.value)||w&&xi(w))){let k=this.inheritFromSourceParent(p);p=k.elementStyle,this.nodeContext.lang=k.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",p,d),w&&xi(w)&&d.display===v.block&&(d.display=v.flow_root),c.processContent(l,d,(s=this.nodeContext.viewNode)!=null?s:(n=this.nodeContext.parent)==null?void 0:n.viewNode),this.transferPolyfilledInheritedProps(d),this.inheritLangAttribute(),d.direction&&(this.nodeContext.direction=d.direction.toString());let y=d["flow-into"];if(y&&y.toString()!=this.flowName)return h.finish(!1),h.result();if(Ft&&l.localName==="script"&&l.namespaceURI==="http://www.w3.org/1999/xhtml")return Rr(l,this.viewport.window).thenFinish(h),h.result();let b=d.display;if(J(b)&&(b===v.initial||b===v.unset?b=v.inline:b===v.inherit?b=((o=this.nodeContext.parent)==null?void 0:o.display)&&B((r=this.nodeContext.parent)==null?void 0:r.display):b=null),b===v.none)return h.finish(!1),h.result();let C=this.nodeContext.parent==null;return this.nodeContext.flexContainer=b===v.flex,this.createShadows(l,C,p,d,c,this.context,this.nodeContext.shadowContext).then(k=>{var R,_;this.nodeContext.nodeShadow=k;let z=d.position,G=d.float,X=d.clear,Ze=this.nodeContext.vertical?v.vertical_rl:v.horizontal_tb,Je=this.nodeContext.parent?this.nodeContext.parent.vertical?v.vertical_rl:v.horizontal_tb:Ze,we=vf(l),x=d["column-count"],O=d["column-width"],S=x&&x!==v.auto&&!J(x)||O&&O!==v.auto&&!J(O);this.nodeContext.establishesBFC=xf(b,z,G,d.overflow,Ze,Je,S||we),this.nodeContext.containingBlockForAbsolute=Sf(z),this.nodeContext.isInsideBFC()&&G!==v.footnote&&!(w&&xi(w))&&(G=null,X=null);let N=G instanceof me||G===v.left||G===v.right||G===v.top||G===v.bottom||G===v.inline_start||G===v.inline_end||G===v.block_start||G===v.block_end||G===v.snap_block||G===v.snap_inline||G===v.inside||G===v.outside||G===v.footnote;G&&(delete d.float,G===v.footnote&&(this.isFootnote?(N=!1,d.display=v.block):d.display=v.inline)),X&&(X===v.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(X=B(this.nodeContext.parent.clearSide)),(X===v.left||X===v.right||X===v.top||X===v.bottom||X===v.inline_start||X===v.inline_end||X===v.block_start||X===v.block_end||X===v.inside||X===v.outside||X===v.both||X===v.all||X===v.same||X===v.column||X===v.region||X===v.page)&&(delete d.clear,d.display&&d.display!=v.inline&&(this.nodeContext.clearSide=X.toString())));let E=b===v.list_item&&d["ua-list-item-count"],A=d["break-inside"];(N||A&&!J(A)&&A!==v.auto)&&this.nodeContext.breakPenalty++,b&&b!==v.inline&&zt(b)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!N&&!b||zt(b)||Hh(b),this.nodeContext.display=b?b.toString():"inline",this.nodeContext.floatSide=N?G.toString():null,this.nodeContext.floatReference=w||Ce.INLINE;let L=d["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=L&&!J(L)?L:null;let M=this.isInsideNonRootMultiColumn(),U=d["column-span"];if(this.nodeContext.columnSpan=!M&&U&&!J(U)?U:null,!this.nodeContext.inline){let D=d["break-after"];D&&!J(D)&&!(M&&D===v.column)&&(this.nodeContext.breakAfter=D.toString(),lo[this.nodeContext.breakAfter]&&(d["break-after"]=v.column));let lt=d["break-before"];lt&&!J(lt)&&!(M&<===v.column)&&(this.nodeContext.breakBefore=lt.toString(),lo[this.nodeContext.breakBefore]&&(d["break-before"]=v.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let mt=d.page,st=mt&&!J(mt)&&mt.toString();!st&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||b===v.table_header_group||b===v.table_footer_group)&&(st=this.styler.cascade.currentPageType),!st||st.toLowerCase()==="auto"?st=this.nodeContext.pageType:this.nodeContext.pageType=st,this.styler.cascade.currentPageType!==st&&!(!st&&d.position===v.fixed)&&(this.nodeContext.fragmentIndex===1&&!un(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),st!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=st)}this.nodeContext.verticalAlign=d["vertical-align"]&&d["vertical-align"].toString()||"baseline",this.nodeContext.captionSide=d["caption-side"]&&d["caption-side"].toString()||"top";let j=d["border-collapse"];if(!j||j===B("separate")){let D=d["border-spacing"],lt,mt;D&&(D instanceof me?(lt=D.values[0],mt=D.values[1]):lt=mt=D,lt.isNumeric()&&(this.nodeContext.inlineBorderSpacing=We(lt,this.context)),mt.isNumeric()&&(this.nodeContext.blockBorderSpacing=We(mt,this.context)))}let q=d["footnote-policy"];this.nodeContext.footnotePolicy=q&&!J(q)?q:null;let K=d["x-first-pseudo"];if(K){let D=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new lf(D,K.num)}this.nodeContext.inline||this.processAfterIfcontinues(l,p,c,this.context);let he=d["white-space"];if(he){let D=Ih(he.toString());D!==null&&(this.nodeContext.whitespace=D)}let te=d["hyphenate-character"];te&&te instanceof Le&&(this.nodeContext.hyphenateCharacter=te.str);let pe=d["word-break"],ke=d["line-break"],be=d["overflow-wrap"];(pe===v.break_all||ke===v.anywhere||be===v.break_word||be===v.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,b,z,G,C),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(t=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,t)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(d),this.findAndProcessRepeatingElements(l,c));let Q=!1,re=null,se=[],ee=l.namespaceURI,$=l.localName,ue=$;if(ee=="http://www.w3.org/1999/xhtml"?($=="html"||$=="body"||$=="script"||$=="link"||$=="meta"?$="div":$=="vide_"?$="video":$=="audi_"?$="audio":$=="object"&&(Q=!!this.customRenderer),l.getAttribute(vr)&&(_=(R=p.content)==null?void 0:R.value)!=null&&_.url&&($="img")):ee=="http://www.idpf.org/2007/ops"?($="span",ee="http://www.w3.org/1999/xhtml"):ee=="http://www.pyroxy.com/ns/shadow"?(ee="http://www.w3.org/1999/xhtml",$=this.nodeContext.inline?"span":"div"):Q=!!this.customRenderer,E)t?$="li":($="div",b=v.block,d.display=b);else if($=="body"||$=="li")$="div";else if($=="q")$="span";else if($=="a"){let D=d["hyperlink-processing"];D&&D.toString()!="normal"&&($="span")}d.behavior&&d.behavior.toString()!="none"&&this.customRenderer&&(Q=!0),l.dataset&&l.getAttribute("data-math-typeset")==="true"&&(Q=!0);let Ue;if(Q){let D=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;Ue=this.customRenderer(l,D,d)}else Ue=P(null);Ue.then(D=>{var lt,mt,st;if(D)Q&&(a=D.getAttribute("data-adapt-process-children")=="true");else if(d.display===v.none){h.finish(!1);return}else D=this.createElement(ee,$);!C&&S&&d["column-fill"]===v.auto&&(D.setAttribute("data-vivliostyle-column-fill","auto"),d["column-fill"]=v.balance),$!=ue&&(D.setAttribute("data-vivliostyle-original-tag",ue),(ue==="html"||ue==="body")&&(D.role="presentation")),$=="a"&&D.addEventListener("click",this.page.hrefHandler,!1),re&&(this.applyPseudoelementStyle(this.nodeContext,"inner",re),D.appendChild(re)),D.localName=="iframe"&&D.namespaceURI=="http://www.w3.org/1999/xhtml"&&Hw(D);let In=this.nodeContext.inheritedProps["image-resolution"],ks=[],Ps=d.width,Ns=d.height,Ec=l.getAttribute("width"),kc=l.getAttribute("height"),Ts=Ps===v.auto||!Ps&&!Ec,Is=Ns===v.auto||!Ns&&!kc,Or=l.attributes,Pc=Or.length,An=null,Br=null;b===v.table_cell&&((st=(mt=(lt=this.nodeContext.parent)==null?void 0:lt.viewNode)==null?void 0:mt.lastElementChild)==null?void 0:st.localName)==="a"&&D.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let Ye=0;Ye<Pc;Ye++){let xt=Or[Ye],Qe=xt.namespaceURI,ne=xt.localName,Re=xt.nodeValue;if(Qe){if(Qe=="http://www.w3.org/2000/xmlns/")continue;Qe=="http://www.w3.org/1999/xlink"&&ne=="href"&&(Re=this.documentURLTransformer.transformURL(this.resolveURL(Re),this.xmldoc.url))}else{if(!Ft&&ne.match(/^on/)||ne=="style")continue;if((ne=="id"||ne=="name")&&t){let De=this.documentURLTransformer.transformFragment(Re,this.xmldoc.url);D.setAttribute(ne,Re),D.setAttribute("data-vivliostyle-id",De);let qt=D.ownerDocument.createElement("a");qt.setAttribute(ne,De),qt.setAttribute(Ii,"1"),qt.style.position="absolute",D.appendChild(qt),this.page.registerElementWithId(D,De);continue}if(ne=="src"||ne=="href"||ne=="poster")Re=this.resolveURL(Re),ne==="href"&&(Re=this.documentURLTransformer.transformURL(Re,this.xmldoc.url));else if(ne=="srcset")Re=Re.split(",").map(De=>this.resolveURL(De.trim())).join(",");else if(ne==="data"&&Q&&$==="object"&&D.hasAttribute("data"))continue;if(ne==="poster"&&$==="video"&&ee==="http://www.w3.org/1999/xhtml"&&Ts&&Is){let De=new Image,qt=ui(De,Re);se.push(qt),ks.push({image:De,element:D,fetcher:qt})}}if(ee=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ne)&&(ne=ne.toLowerCase()),this.isSVGUrlAttribute(ne)&&(Re=Vw(Re,this.xmldoc.url,this.documentURLTransformer)),Qe){let De=Uw[Qe];De&&(ne=`${De}:${ne}`)}if(ne=="src"&&!Qe&&($=="img"||$=="input")&&ee=="http://www.w3.org/1999/xhtml")An=Re;else if(ne=="alt"&&!Qe&&$=="img"&&ee=="http://www.w3.org/1999/xhtml")Br=Re;else if(ne=="href"&&$=="image"&&ee=="http://www.w3.org/2000/svg"&&Qe=="http://www.w3.org/1999/xlink")this.page.fetchers.push(ui(D,Re));else if(Qe)D.setAttributeNS(Qe,ne,Re);else try{D.setAttribute(ne,Re)}catch(De){H.warn(De)}}if(An){let Ye=$==="input"?new Image:D,xt=ui(Ye,An,Br);Ye!==D&&(D.src=An);let Qe=()=>{var ne,Re;if(d.position===v.fixed)return!0;for(let De=(ne=this.nodeContext.parent)==null?void 0:ne.viewNode;De&&De!==this.viewRoot;De=De.parentElement)if(((Re=De.style)==null?void 0:Re.position)==="fixed")return!0;return!1};!Ts&&!Is&&!(()=>{let ne=this.nodeContext.vertical?Ps:Ns;return ne instanceof I&&ne.unit==="%"})()&&!Qe()?this.page.fetchers.push(xt):(Ts&&Is&&In&&In!==1&&ks.push({image:Ye,element:D,fetcher:xt}),se.push(xt))}delete d.content;let As=d["list-style-image"];if(As&&As instanceof pt){let Ye=As.url;se.push(ui(new Image,Ye))}if(this.preprocessElementStyle(d),this.applyComputedStyles(D,d),this.nodeContext.inline)t||(ot(D,"inline-start"),Hi(D)&&ot(D,"clone"));else if(t){if(!rr(d.position)){let Ye=d["margin-break"],xt=this.getBreakTypeAt(this.nodeContext),Qe=xt!==null,ne=xt==="auto";(Ye===v.discard&&Qe||Ye!==v.keep&&ne&&!this.nodeContext.floatSide)&&Hs(D,"block-start")}}else{let Ye=this.nodeContext.vertical?"width":"height";_t(D,Ye)&&T(D,Ye,this.nodeContext.display==="table-row"?"0.01px":""),ot(D,"block-start"),Hi(D)&&ot(D,"clone"),Hs(D,"block-start")}E&&D.setAttribute("value",d["ua-list-item-count"].stringValue()),this.viewNode=D,se.length?ws(se).then(()=>{In>0&&this.modifyElemDimensionWithImageResolution(ks,In,d,this.nodeContext.vertical),h.finish(a)}):h.timeSlice().then(()=>{h.finish(a)})})}),h.result()}isInsideNonRootMultiColumn(){var t;let i=(t=this.nodeContext.parent)==null?void 0:t.viewNode;return!!(i&&lr(i))}getBreakTypeAt(t){var i,n,s,o,r;if(this.isInsideTable(t))return null;for(let h=t;h&&!h.after;h=h.parent){if(je(h.breakBefore))return h.breakBefore;if(h.fragmentIndex===1&&!h.parent)return h.sourceNode===h.sourceNode.ownerDocument.documentElement?"page":null;if((i=h.parent)!=null&&i.floatSide)return null;let l=(n=h.parent)==null?void 0:n.viewNode;if(l){let c=this.viewport.window.getComputedStyle(l),p=parseFloat(c.paddingBlockStart),d=parseFloat(c.borderBlockStartWidth);if(p||d)return null;let f=l?.firstChild;for(;f&&(ze(f,h.parent.whitespace)||!h.floatSide&&ji(f));)f=f.nextSibling;if(f&&f!==h.viewNode)return null}}let a=(r=(o=(s=this.context)==null?void 0:s.currentLayoutPosition)==null?void 0:o.flowPositions[this.flowName])==null?void 0:r.startBreakType;return je(a)?a:"auto"}isInsideTable(t){for(let i=t;i&&!i.after;i=i.parent)if(i.display&&i.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(t,i,n,s){let o=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,s);if(o&&o["after-if-continues"]&&o["after-if-continues"].content){let r=new _a(t,i,n,s,this.exprContentListener);this.nodeContext.afterIfContinues=new Ug(t,r)}}isSVGUrlAttribute(t){return Vo.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,s){t.forEach(o=>{if(o.fetcher.get().get()==="load"){let r=o.image,a=r.width/i,h=r.height/i,l=o.element;if(a>0&&h>0){if(n["box-sizing"]===v.border_box&&(n["border-left-style"]!==v.none&&(a+=We(n["border-left-width"],this.context)),n["border-right-style"]!==v.none&&(a+=We(n["border-right-width"],this.context)),n["border-top-style"]!==v.none&&(h+=We(n["border-top-width"],this.context)),n["border-bottom-style"]!==v.none&&(h+=We(n["border-bottom-width"],this.context))),i>1){let c=n["max-width"]||v.none,p=n["max-height"]||v.none;if(c===v.none&&p===v.none)T(l,"max-width",`${a}px`);else if(c!==v.none&&p===v.none)T(l,"width",`${a}px`);else if(c===v.none&&p!==v.none)T(l,"height",`${h}px`);else{c.isNumeric(),p.isNumeric();let d=c,f=p;d.unit!=="%"?T(l,"max-width",`${Math.min(a,We(d,this.context))}px`):f.unit!=="%"?T(l,"max-height",`${Math.min(h,We(f,this.context))}px`):s?T(l,"height",`${h}px`):T(l,"width",`${a}px`)}}else if(i<1){let c=n["min-width"]||fe,p=n["min-height"]||fe;c.isNumeric(),c.isNumeric();let d=c,f=p;d.num===0&&f.num===0?T(l,"min-width",`${a}px`):d.num!==0&&f.num===0?T(l,"width",`${a}px`):d.num===0&&f.num!==0?T(l,"height",`${h}px`):d.unit!=="%"?T(l,"min-width",`${Math.max(a,We(d,this.context))}px`):f.unit!=="%"?T(l,"min-height",`${Math.max(h,We(f,this.context))}px`):s?T(l,"height",`${h}px`):T(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){vt("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let s={},o=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",o,s),!this.processRepeatOnBreak(s))continue;if(this.nodeContext.formattingContext instanceof oi&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let r=this.nodeContext.parent,a=r&&r.formattingContext;this.nodeContext.formattingContext=new oi(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==v.none&&((i===v.auto||J(i))&&(t.display===v.table_header_group?i=v.header:t.display===v.table_footer_group?i=v.footer:i=v.none),i&&i!==v.none)?i.toString():null}createTextNodeView(){let t=F("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=fa(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return P(!0);let t,i=t=this.sourceNode.textContent,n=F("preprocessTextContent"),s=vt("PREPROCESS_TEXT_CONTENT"),o=0;return n.loop(()=>o>=s.length?P(!1):s[o++](this.nodeContext,i).thenAsync(r=>(i=r,P(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Yp(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=F("createNodeView"),s,o=!0;return this.sourceNode.nodeType==1?s=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,s=P(!0)):s=this.createTextNodeView(),s.then(r=>{var a;if(o=r,this.nodeContext.viewNode=this.viewNode,this.viewNode){let h=(p,d)=>p?.nodeType===1&&bi(p)===d,l=this.nodeContext.parent,c=l?h(this.viewNode,"after")&&h(l.viewNode,"first-letter")&&(a=l.viewNode)!=null&&a.hasChildNodes()?l.parent.viewNode:l.viewNode:this.viewRoot;c&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&ze(this.viewNode))&&!c.hasChildNodes()&&kh(c).includes("block-start")&&ot(c,"text-start"),c.appendChild(this.viewNode),Pf(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):P(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,s=t.parent,o,r,a=n.subShadow||n.parentShadow;n.subShadow?(o=n.root,r=n.type,r==ht.ROOTLESS&&(o=o.firstChild)):(o=n.owner.firstChild,r=ht.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 Wi(o,s,i);return l.shadowContext=a,l.shadowType=r,l.shadowSibling=t,l}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=ht.ROOTED){let n=t.sourceNode.nextSibling;if(n)return t=t.modify(),t.boxOffset=i,t.sourceNode=n,t.resetView(),this.processShadowContent(t)}return t.shadowSibling?(t=t.shadowSibling.modify(),t.boxOffset=i,t):(t=t.parent.modify(),t.boxOffset=i,t.after=!0,t)}else{if(t.nodeShadow){let s=t.nodeShadow.root;if(t.nodeShadow.type==ht.ROOTLESS&&(s=s.firstChild),s){let o=new Wi(s,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 Wi(n,t,i));if(t.sourceNode.nodeType!=1){let s=fa(t.preprocessedTextContent);i+=s.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}isTransclusion(t,i,n){let s=Ve(i,"hyperlink-processing");if(!s)return!1;let o=s.evaluate(this.context,"hyperlink-processing");return o?o.toString()==n:!1}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return P(n);let s=F("nextInTree");return this.setCurrent(n,!0,i).then(o=>{(!n.viewNode||!o)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),this.dispatchEvent({type:"nextInTree",nodeContext:n}),s.finish(n)}),s.result()}addImageFetchers(t){if(t instanceof qe){let i=t.values;for(let n=0;n<i.length;n++)this.addImageFetchers(i[n])}else if(t instanceof pt){let i=t.url;this.page.fetchers.push(ui(new Image,i))}}applyComputedStyles(t,i){var n,s,o;let r=i["background-image"];r&&this.addImageFetchers(r);let a=i.position===v.relative,h=((n=this.nodeContext)==null?void 0:n.parent)===null&&((s=this.sourceNode)==null?void 0:s.parentElement)===null&&!!((o=this.viewRoot)!=null&&o.parentElement),l=Object.keys(i);l.sort(ta);let c,p;for(let d of l){if(Ww[d])continue;let f=i[d];if(!(!f||f===W&&!At(d))){if(f=f.visit(new Gd(this.xmldoc.url,this.documentURLTransformer)),f instanceof I)if(f.unit==="em"){let m=this.getEmUnitSize(d,c);m!=null&&(f=new I(f.num*m,"px"))}else if(f.unit==="lh"){let m=this.getLineHeightUnitSize(d,c,p);m!=null&&(f=new I(f.num*m,"px"))}else Ll(f.unit)&&(f=Kl(f,this.context));if((d==="font-size"||d==="line-height")&&(d==="font-size"?c=f:p=f,this.viewport.layoutUnitAdj&&f instanceof I&&f.unit!=="%"&&f.unit!=="em"&&f.unit!=="lh"&&(f=new hi(`calc(${f.toString()} - var(--viv-layoutUnitAdj))`))),Jp[d]||a&&Qp[d]){this.page.delayedItems.push(new or(t,d,f));continue}h&&this.page.pageAreaElement&&tn(d)?T(this.page.pageAreaElement.parentElement.parentElement,d,f.toString()):T(t,d,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 s,o,r,a,h,l;let c=((r=(o=(s=this.nodeContext)==null?void 0:s.parent)==null?void 0:o.viewNode)==null?void 0:r.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,p=c?this.parsePlusLayoutUnitAdj(c.lineHeight):this.context.rootLineHeight;if(t==="line-height"||t==="font-size")return p;let d=null;if(n)if(n instanceof Xt||n instanceof I&&(n.unit==="em"||n.unit==="%"))d=n instanceof I&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof I&&n.unit!=="lh"){let f=this.context.queryUnitSize(n.unit,!1);if(f!=null)return n.num*f}return null}if(d==null)for(let f=(h=(a=this.nodeContext)==null?void 0:a.parent)==null?void 0:h.viewNode;f&&f.nodeType===1;f=f.parentNode){let m=(l=f?.style)==null?void 0:l.lineHeight;if(m){/^[0-9.]+$/.test(m)&&(d=parseFloat(m));break}}if(d!=null){if(i&&!(i instanceof I))return null;let f=c?this.parsePlusLayoutUnitAdj(c.fontSize):this.context.rootFontSize;if(i instanceof I){let m=Po(i,f,this.context).num;return typeof m!="number"||isNaN(m)?null:d*m}else return f==null?null:d*f}return p}getEmUnitSize(t,i){var n,s,o;let r=((o=(s=(n=this.nodeContext)==null?void 0:n.parent)==null?void 0:s.viewNode)==null?void 0:o.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,a=r?this.parsePlusLayoutUnitAdj(r.fontSize):this.context.rootFontSize;if(t==="font-size"||i==null)return a;if(i instanceof I){let h=Po(i,a,this.context).num;if(typeof h=="number"&&!isNaN(h))return h}return null}applyPseudoelementStyle(t,i,n){if(t.after)return;let s=this.sourceNode,o=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(s,!1),r=bt(o,"_pseudos");if(!r||(o=r[i],!o))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",o,a);let h=a.content;jt(h)&&(h.visit(new ss(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=F("peelOff"),s=t.firstPseudo,o=t.offsetInNode,r=t.after;if(i>0){let p=t.viewNode.textContent;t.viewNode.textContent=p.substr(0,i),o+=i}else if(!r&&t.viewNode&&o==0){let p=t.viewNode.parentNode;p&&p.removeChild(t.viewNode)}let a=t.boxOffset+i,h=[];for(;t.firstPseudo===s;)h.push(t),t=t.parent;let l=h.pop(),c=l.shadowSibling;return n.loop(()=>{for(;h.length>0;){l=h.pop(),t=new Wi(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=o,t.after=r),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.shadowSibling:c,c=null;let p=this.setCurrent(t,!1);if(p.isPending())return p}return P(!1)}).then(()=>{n.finish(t)}),n.result()}createElement(t,i){return t=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(t,i)}applyFootnoteStyle(t,i,n){let s={},o=bt(this.footnoteStyle,"_pseudos");if(t=this.computeStyle(t,i,this.footnoteStyle,s),o&&o.before){let r={},a=this.createElement("http://www.w3.org/1999/xhtml","span");Fo(a,"before"),n.appendChild(a),this.computeStyle(t,i,o.before,r),delete r.content,this.applyComputedStyles(a,r)}return delete s.content,this.applyComputedStyles(n,s),t}processFragmentedBlockEdge(t){var i,n,s;let o=!t.inline&&t.after?t.parent:t,r=!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=Ve(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();r=l&&!zt(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=o;h;h=h.parent){if(((s=h.viewNode)==null?void 0:s.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(ot(l,"inline-end"),Hi(l)){let c=h.vertical?l.offsetWidth:l.offsetHeight;ot(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>c&&this.fixClonedBoxDecorationOverflow(l)}}else{let c=this.nodeContext.vertical?"width":"height";if(_t(l,c)&&T(l,c,""),ot(l,"block-end"),!a++&&h!==o){let{textAlign:p}=this.viewport.window.getComputedStyle(l);if(p==="justify"&&!r){let d=this.createChildAnonymousBlockIfNeeded(l);d?d!==l?Ph(d,["block-start","text-start","block-end","text-end","justify"]):(ot(l,"text-end"),ot(l,"justify")):ot(l,"text-end")}else ot(l,"text-end")}Hi(l)&&ot(l,"clone"),Hs(l,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),s=parseFloat(i.borderInlineEndWidth),o=-(n+s);isNaN(o)||(t.style.marginInlineEnd=`${o}px`)}createChildAnonymousBlockIfNeeded(t){let i=o=>{let{display:r,position:a,float:h}=this.viewport.window.getComputedStyle(o);if(o.localName==="ruby"||Qt[o.localName])return!1;if(o.localName==="br")return!0;if((r==="inline"||r==="contents")&&o.hasChildNodes()){let l=o.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===o.lastChild&&ze(l.nextSibling))){let c=i(l);if(c||c===null)return c}for(let c=l?.previousElementSibling;c;c=c.previousElementSibling){let p=i(c);if(p||p===null)return null}return!1}if(r==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||o.hasAttribute(Ii)){let l=o.previousElementSibling;return l&&(l.nextSibling===o||l.nextSibling===o.previousSibling&&ze(l.nextSibling))?i(l):!1}return!(!r||zt(r))},n=null;for(let o=t.lastElementChild;o;o=o.previousElementSibling){let r=i(o);if(r){n=o;break}if(r===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&ze(n.nextSibling)))return null;let s=t.ownerDocument.createElement("span");s.className="viv-anonymous-block";for(let o=n.nextSibling,r=null;o;o=r)r=o.nextSibling,s.appendChild(o);return t.appendChild(s),s}convertLengthToPx(t,i,n){let s=t.num,o=t.unit;if(fd(o)){let r=i;for(;r&&r.nodeType!==1;)r=r.parentNode;let a=parseFloat(n.getElementComputedStyle(r)["font-size"]);return this.context,fr(t,a,this.context).num}else{let r=this.context.queryUnitSize(o,!1);return r?s*r:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,s=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&bi(n)===bi(s)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,s)=>{let o=i.steps[s];return this.isSameNodePositionStep(n,o)})}isPseudoelement(t){return!!bi(t)}};u(cc,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var $w=cc,Ww={"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},Gw=class{constructor(e){u(this,"layoutBox"),u(this,"window"),u(this,"scaleRatio"),u(this,"layoutUnitPerPixel"),this.layoutBox=e.layoutBox,this.window=e.window,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,s,o){this.window=e,this.fontSize=t,this.pixelRatio=i,u(this,"document"),u(this,"root"),u(this,"outerZoomBox"),u(this,"contentContainer"),u(this,"layoutBox"),u(this,"width"),u(this,"height"),u(this,"scaleRatio",1),u(this,"layoutUnitPerPixel"),u(this,"layoutUnitAdj",0),this.document=e.document,this.root=n||this.document.body;let r=this.root.firstElementChild;r||(r=this.document.createElement("div"),r.setAttribute("data-vivliostyle-outer-zoom-box","true"),r.role="presentation",this.root.appendChild(r));let a=r.firstElementChild;switch(a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),a.role="presentation",r.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),yl){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 h=r.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),h.role="presentation",this.root.appendChild(h)),this.outerZoomBox=r,this.contentContainer=a,this.layoutBox=h,this.width=s||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},c=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!s&&c)&&(this.width=l.width),(!this.height||!o&&c)&&(this.height=l.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)}},dc=class{constructor(e,t,i){this.store=e,this.url=t,this.document=i,u(this,"lang",null),u(this,"totalOffset",-1),u(this,"root"),u(this,"body"),u(this,"head"),u(this,"last"),u(this,"lastOffset",1),u(this,"idMap"),this.root=i.documentElement;let n=null,s=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let o=this.root.firstChild;o;o=o.nextSibling){if(o.nodeType!=1)continue;let r=o;if(r.namespaceURI=="http://www.w3.org/1999/xhtml")switch(r.localName){case"head":s=r;break;case"body":n=r;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=s,this.last=this.root,this.last.setAttribute(kt,"0")}doc(){return new fc([this.document])}getElementOffset(e){let t=e.getAttribute(kt);if(t)return parseInt(t,10);let i=this.lastOffset,n=this.last;for(;n!=e;){let s=n.firstChild;if(!s){for(;s=n.nextSibling,!s;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=s,s.nodeType==1?(s.setAttribute(kt,i.toString()),++i):i+=s.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,s=e,o=null;if(s.nodeType==1){if(!i)return this.getElementOffset(s)}else{if(n=t,o=s.previousSibling,!o)return s=s.parentNode,n+=1,this.getElementOffset(s)+n;s=o}for(;;){for(;s.lastChild;)s=s.lastChild;if(s.nodeType==1)break;if(n+=s.textContent.length,o=s.previousSibling,!o){s=s.parentNode;break}s=o}return n+=1,this.getElementOffset(s)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let h=Ht(a.length,l=>{let c=a[l];return this.getElementOffset(c)>e});if(h==0)break;i=a[h-1]}let n=t+1,s=i,o=s.firstChild||s.nextSibling,r=null;for(;;){if(o){if(o.nodeType==1||(s=o,r=s,n+=o.textContent.length,n>e&&!/^\s*$/.test(o.textContent)))break}else if(s=s.parentNode,!s)break;o=s.nextSibling}return o&&r&&/^\s*$/.test(r.textContent)&&(r=o),r||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}},Uo=(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))(Uo||{});function Vn(e,t,i){let n=i||new DOMParser,s;try{s=n.parseFromString(e,t)}catch{}if(s){let o=s.documentElement,r="parsererror";if(o.localName===r)return null;for(let a=o.firstElementChild;a;a=a.nextElementSibling)if(a.localName===r)return null}else return null;return s}function jw(e){let t=e.contentType;if(t){let n=Object.keys(Uo);for(let s=0;s<n.length;s++)if(Uo[n[s]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let i=e.url.match(/\.([^./#?]+)([#?]|$)/);if(i)switch(i[1]){case"html":case"htm":return"text/html";case"xhtml":case"xht":return"application/xhtml+xml";case"svg":case"svgz":return"image/svg+xml";case"opf":case"xml":return"application/xml"}return null}function pc(e,t){let i=e.responseXML;if(!i){let s=new DOMParser,o=e.responseText;if(o){let r=jw(e);if(i=Vn(o,r||"application/xml",s),i&&!r){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Vn(o,"text/html",s):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Vn(o,"image/svg+xml",s))}i||(i=Vn(o,"text/html",s))}}let n=i?new dc(t,e.url,i):null;return P(n)}function Xw(){return new tr(pc,"document")}var qw=class Ho{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new Ho(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new Ho(n=>{if(!this.check(n))return!1;let s=new fc([n]);return s=s.child(t),i&&(s=s.predicate(i)),s.size()>0})}},tl=new qw(e=>!0),fc=class $o{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 $o(i)}forEachNode(t){let i=[],n=s=>{i.push(s)};for(let s=0;s<this.nodes.length;s++)t(this.nodes[s],n);return new $o(i)}forEach(t){let i=[];for(let n=0;n<this.nodes.length;n++)i.push(t(this.nodes[n]));return i}forEachNonNull(t){let i=[];for(let n=0;n<this.nodes.length;n++){let s=t(this.nodes[n]);s!=null&&i.push(s)}return i}child(t){return this.forEachNode((i,n)=>{for(let s=i.firstChild;s;s=s.nextSibling)s.nodeType==1&&s.localName==t&&n(s)})}childElements(){return this.forEachNode((t,i)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&i(n)})}attribute(t){return this.forEachNonNull(i=>i.nodeType==1?i.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}},Yw=new Cn(()=>{let e=F("uaStylesheetBase"),t=qu(),i=Ee("user-agent-base.css",ni),n=new cn(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),kg(n.cascade),nr(ch,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function Kw(){return Yw.get()}var Zw=class{constructor(e,t,i,n,s,o,r,a,h,l){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=s,this.fontFaces=o,this.footnoteProps=r,this.flowProps=a,this.viewportProps=h,this.pageProps=l,u(this,"fontDeobfuscator"),u(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(c){c=c;let p=this,d=p.currentLayoutPosition,f=d.firstFlowChunkOfFlow(c);return p.matchPageSide(d.startSideOfFlow(c))&&d.hasContent(c,p.lookupOffset)&&!!f&&!p.flowChunkIsAfterParentFlowForcedBreak(f)}),this.pageScope.defineName("page-number",new Ie(this.pageScope,function(){let c=this;return c.pageNumberOffset+c.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new Ie(this.pageScope,function(){let c=this.currentLayoutPosition;return c?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let s=new Qs(this.rootScope,e,t,i),o=Hf(s,this.viewportProps),r=o.width,a=o.height,h=o["text-zoom"],l=1;if(r&&a||h){let c=ge.em;if((h?h.evaluate(s,"text-zoom"):null)===v.scale&&(l=c/i,i=c,e*=l,t*=l),r&&a){let p=We(r.evaluate(s,"width"),s),d=We(a.evaluate(s,"height"),s);if(p>0&&d>0)return{width:n&&n.spreadView?(p+n.pageBorder)*2:p,height:d,fontSize:i}}}}return{width:e,height:t,fontSize:i}}},Lr=class extends Qs{constructor(e,t,i,n,s,o,r,a,h,l,c,p,d){super(e.rootScope,n.width,n.height,n.fontSize),this.style=e,this.xmldoc=t,this.viewport=n,this.clientLayout=s,this.fontMapper=o,this.customRenderer=r,this.fallbackMap=a,this.pageNumberOffset=h,this.documentURLTransformer=l,this.counterStore=c,u(this,"lang"),u(this,"primaryFlows",{body:!0}),u(this,"rootPageBoxInstance",null),u(this,"styler",null),u(this,"stylerMap",null),u(this,"currentLayoutPosition",null),u(this,"layoutPositionAtPageStart",null),u(this,"lookupOffset",0),u(this,"faces"),u(this,"pageBoxInstances",{}),u(this,"pageManager",null),u(this,"rootPageFloatLayoutContext"),u(this,"pageBreaks",{}),u(this,"pageProgression",null),u(this,"isVersoFirstPage",!1),u(this,"blankPageAtStart",!1),u(this,"pageSheetSize",{}),u(this,"pageSheetHeight",0),u(this,"pageSheetWidth",0),this.lang=t.lang||i,this.faces=new Qm(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new Gi(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!d;for(let f in e.flowProps){let m=e.flowProps[f],g=Ve(m,"flow-consume");g&&(g.evaluate(this,"flow-consume")==v.all?this.primaryFlows[f]=!0:delete this.primaryFlows[f])}}init(){let e=F("StyleInstance.init"),t=this.counterStore.createCounterListener(this.xmldoc.url),i=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new Ua(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,t,i),i.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let n=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=sc(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let s=this.style.rootBox;this.rootPageBoxInstance=new ow(s);let o=this.style.cascade.createInstance(this,t,i,this.lang);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(o,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new Sw(o,this.style.pageScope,this.rootPageBoxInstance,this,n);let r=[];for(let h of this.style.fontFaces){if(h.condition&&!h.condition.evaluate(this))continue;let l=Jm(h.properties,this),c=new Yu(l);r.push(c)}this.fontMapper.findOrLoadFonts(r,this.faces).then(()=>{zw(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let a=this.style.pageProps;return a[""]||(a[""]={}),Object.keys(a).forEach(h=>{let l=a[h];this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context);let c=Ja(us(l),this);this.pageSheetSize[h]={width:c.pageWidth+c.cropOffset*2,height:c.pageHeight+c.cropOffset*2}}),e.result()}matchStartPageSide(e){let t=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),i=this.pageProgression=="ltr";switch(e){case"left":return t!==i;case"right":return t===i;case"recto":return t;case"verso":return!t;default:return!0}}getStylerForDoc(e){let t=this.stylerMap[e.url];if(!t){let i=this.style.store.getStyleForDoc(e),n=new Qs(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),s=this.counterStore.createCounterListener(e.url),o=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new Ua(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,s,o),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 uf,i.flowPositions[e.flowName]=n);let s=af(e.element),o=new Gt(s),r=new hf(o,e);n.positions.push(r)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;let n=!0;class s{unknownProperty(h,l){n=!1}invalidPropertyValue(h,l){n=!1}simpleProperty(h,l,c){}}let o=new s,r=Oi(this.style.rootScope,new yt(t,null),"");return r?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,r,!1,o),n):!1}evalSupportsSelector(e){let t=new gc(null),i=new yt(e+"{}",t);return new kn(Se,i,t,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!t.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let t=Number.POSITIVE_INFINITY;for(let i=0;i<e.positions.length;i++){let n=e.positions[i].chunkPosition.primary,s=n.steps[0].node,o=n.offsetInNode,r=n.after,a=0;for(;s.ownerDocument!=this.xmldoc.document;)a++,s=n.steps[a].node,r=!1,o=0;let h=this.xmldoc.getNodeOffset(s,o,r);h<t&&(t=h)}return t}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let s=e.flowPositions[n];if(!t&&(!s||s.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),s=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&s&&(s=s.clone(),e.flowPositions[n]=s)),s){let o=this.getConsumedOffset(s);o<i&&(i=o)}}return i}dumpLocation(e){H.debug("Location - page",this.currentLayoutPosition.page),H.debug(" current:",e),H.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)H.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new Ae(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let t in e.flowPositions){let i=e.flowPositions[t];if(i&&i.positions.length>0){let n=i.positions[0].flowChunk;if(this.getConsumedOffset(i)===n.startOffset){let s=i.positions[0].flowChunk.breakBefore,o=i.startBreakType;i.startBreakType=pa(Xe(o,s))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,s;for(let o=0;o<n.length;o++){if(s=n[o],s.pageBox.pseudoName===Ar)continue;let r=1;s.pageBox.pseudoName===Pr&&!(this.actualPageWidth&&this.actualPageHeight)&&(r=1/0);let a=s.getProp(this,"utilization");a&&a.isNum()&&(r=a.num);let h=this.queryUnitSize("em",!1),l=this.pageWidth()*this.pageHeight(),c=Math.ceil(r*l/(h*h)),p=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,c),this.styler.cascade.currentPageType=p,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let d=s.getProp(this,"enabled");if(!d||d===v._true){if(t.page===1&&this.blankPageAtStart){s.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(s,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,s=t[i].forcedBreakOffsets;if(!s.length||n<s[0])return!1;let o=Ht(s.length,l=>s[l]>n)-1,r=s[o],a=this.layoutPositionAtPageStart.flowPositions[i],h=this.getConsumedOffset(a);return r<h?!1:h<r?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new cr(null)),e.flowRootFormattingContext=i.formattingContext}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=a=>{if(a.floatReference!==Ce.PAGE)return!1;let h=this.layoutPositionAtPageStart.flowPositions.body,l=h&&this.getConsumedOffset(h),c=this.xmldoc.getNodeOffset(a.nodePosition.steps[0].node,0,!1);return c!=null&&l!=null&&c>l},s=F("layoutDeferredPageFloats"),o=!1,r=0;return s.loopWithFrame(a=>{if(r===i.length){a.breakLoop();return}let h=i[r++],l=h.float;if(n(l)){a.breakLoop();return}let c=new Ti().findByFloat(l),p=c.findPageFloatFragment(l,t);if(p&&p.hasFloat(l)){a.continueLoop();return}else if(t.isForbidden(l)||t.hasPrecedingFloatsDeferredToNext(l)){t.deferPageFloat(h),a.breakLoop();return}e.layoutPageFloatInner(h,c,null,p).then(d=>{if(!d){a.breakLoop();return}let f=t.parent.isInvalidated();if(f){a.breakLoop();return}else t.isInvalidated()&&!f&&(o=!0,t.validate());a.continueLoop()})}).then(()=>{o&&t.invalidate(),s.finish(!0)}),s.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new Gt(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 P(!0);this.setFormattingContextToColumn(e,t),e.init(),this.primaryFlows[t]&&e.bands.length>0&&(e.forceNonfitting=!1);let n=F("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let s=[],o=[],r=!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 d=h+1;d<i.positions.length;d++){if(o.includes(d))continue;let f=i.positions[d];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(l.flowChunk)&&(l=f,h=d)}let c=l.flowChunk,p=!0;if(e.layout(l.chunkPosition,r,i.breakAfter).then(d=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(r=!1,l.flowChunk.repeated&&(d===null||c.exclusive)&&s.push(h),c.exclusive){o.push(h),a.breakLoop();return}else{let f=!!d||!!e.pageBreakType,m=this.getLastAfterPositionIfDeferredFloatsExists(e,d);if(e.pageBreakType&&m?(l.chunkPosition=m,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(o.push(h),(d||m)&&(l.chunkPosition=d||m,s.push(h)),i.startBreakType=pa(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,p?p=!1:a.continueLoop()}),p){p=!1;return}}a.breakLoop()}).then(()=>{if(!e.pageFloatLayoutContext.isInvalidated()){i.positions=i.positions.filter((h,l)=>s.includes(l)||!o.includes(l)),i.breakAfter==="column"&&(i.breakAfter=null),e.saveDistanceToBlockEndFloats();let a=e.pageFloatLayoutContext.getMaxReachedAfterEdge();e.updateMaxReachedAfterEdge(a)}n.finish(!0)})}),n.result()}createLayoutConstraint(e){let t=this.currentLayoutPosition.page-1,i=this.counterStore.createLayoutConstraint(t);return new jg([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,s,o,r,a,h,l,c,p,d,f){let m=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,g=s.element,w=new Gi(a,Ce.COLUMN,null,r,null,null,null),y=this.currentLayoutPosition.clone(),b=F("createAndLayoutColumn"),C;return b.loopWithFrame(k=>{let R=this.createLayoutConstraint(w);if(h>1){let _=this.viewport.document.createElement("div");if(T(_,"position","absolute"),g.appendChild(_),C=new ls(_,d,this.clientLayout,R,w),C.forceNonfitting=f,C.vertical=s.vertical,C.rtl=s.rtl,C.snapHeight=s.snapHeight,C.snapWidth=s.snapWidth,s.vertical){let z=(s.rtl?h-o-1:o)*(c+l)+s.paddingTop,G=parseFloat(g.style.width);C.setHorizontalPosition(s.paddingLeft+G-s.width,s.width),C.setVerticalPosition(z,c)}else{let z=(s.rtl?h-o-1:o)*(c+l)+s.paddingLeft;C.setVerticalPosition(s.paddingTop,s.height),C.setHorizontalPosition(z,c)}C.originX=t,C.originY=i}else C=new ls(g,d,this.clientLayout,R,w),C.copyFrom(s);C.exclusions=m?[]:n.concat(),C.innerShape=p,w.setContainer(C),(C.vertical?C.height:C.width)>=0?this.layoutColumn(C,r).then(()=>{w.isInvalidated()||w.finish(),C.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(C.pageFloatLayoutContext.validate(),this.currentLayoutPosition=y.clone(),C.element!==g&&g.removeChild(C.element),k.continueLoop()):k.breakLoop()}):(w.finish(),k.breakLoop())}).then(()=>{b.finish(C)}),b.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof ac||t instanceof Nr&&!(t instanceof ki))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof Ai;let s=t.getProp(this,"writing-mode")||null,o=t.getProp(this,"direction")||null;return new Gi(e,Ce.REGION,i,n,null,s,o)}layoutFlowColumnsWithBalancing(e,t,i,n,s,o,r,a,h){let l=this.currentLayoutPosition.clone(),c=this.getRegionPageFloatLayoutContext(o,t,r,a),p=!0,d=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,s,o,c,r,a,h,p).thenAsync(f=>P(f?{columns:f,position:this.currentLayoutPosition}:null)));return d().thenAsync(f=>{if(!f)return P(null);if(h<=1)return P(f.columns);let m=t.getProp(this,"column-fill")||v.balance,g=this.currentLayoutPosition.flowPositions[a],w=Om(h,m,d,c,r,f.columns,g);return w?(p=!1,o.lock(),c.lock(),w.balanceColumns(f).thenAsync(y=>(o.unlock(),o.validate(),c.unlock(),this.currentLayoutPosition=y.position,P(y.columns)))):P(f.columns)})}layoutFlowColumns(e,t,i,n,s,o,r,a,h,l,c){let p=F("layoutFlowColumns"),d=this.currentLayoutPosition.clone(),f=t.getPropAsNumber(this,"column-gap"),m=l>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,g=t.getActiveRegions(this),w=t.getProp(this,"shape-inside"),y=th(w,0,0,a.width,a.height,this),b=new $w(h,this,this.viewport,this.styler,g,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer),C=0,k=null,R=[];return p.loopWithFrame(_=>{this.createAndLayoutColumn(t,i,n,s,a,C++,h,r,l,f,m,y,b,c).then(z=>{if(o.isInvalidated()){R=null,_.breakLoop();return}if((z.pageBreakType&&z.pageBreakType!=="column"||C===l)&&!r.isInvalidated()&&r.finish(),r.isInvalidated()){C=0,this.currentLayoutPosition=d.clone(),r.validate(),r.isLocked()?(R=null,_.breakLoop()):_.continueLoop();return}k=z,R[C-1]=k,k.pageBreakType&&k.pageBreakType!="column"&&(C=l,k.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),C<l?_.continueLoop():_.breakLoop()})}).then(()=>{p.finish(R)}),p.result()}layoutContainer(e,t,i,n,s,o,r){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==v._true)return P(!0);let h=F("layoutContainer"),l=t.getProp(this,"wrap-flow")===v.auto,c=t.getProp(this,"flow-from"),p=this.viewport.document.createElement("div");p.role=t instanceof lc?"complementary":"presentation";let d=t.getProp(this,"position");T(p,"position",d?d.name:"absolute");let f=t instanceof ki;t instanceof Ai?i.appendChild(p):i.insertBefore(p,i.firstChild);let m=new _h(p);m.vertical=t.vertical,m.rtl=t.rtl,m.borderBoxSizing=t.borderBoxSizing,m.exclusions=o,t.prepareContainer(this,m,e,this.faces,this.clientLayout),t instanceof ki&&(m.width<=0||m.height<=0)&&H.warn("Negative or zero page area size"),m.originX=n,m.originY=s,n+=m.left+m.marginLeft+m.borderLeft,s+=m.top+m.marginTop+m.borderTop,this.setPagePageFloatLayoutContextContainer(r,t,m);let g,w=!1;if(!c||!c.isIdent()){let y=t.getProp(this,"content");if(y instanceof V&&y.expr instanceof Ie&&y.expr.str.startsWith("running-element-"))y.visit(new ss(p,this,y,this.counterStore.getExprContentListener()));else if(y&&jt(y)){let b="span";y.url&&(b="img");let C=this.viewport.document.createElement(b);y.visit(new ss(C,this,y,this.counterStore.getExprContentListener())),p.appendChild(C),b=="img"&&t.transferSingleUriContentProps(this,C,this.faces),t.transferContentProps(this,m,e,this.faces),b=="span"&&zg(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(p),w=!0);w||t.finishContainer(this,m,e,null,1,this.clientLayout,this.faces),g=P(!0)}else if(this.pageBreaks[c.toString()])r.isInvalidated()||t.finishContainer(this,m,e,null,1,this.clientLayout,this.faces),g=P(!0);else{let y=F("layoutContainer.inner"),b=c.toString(),C=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,s,o,r,m,b,C).then(k=>{if(!r.isInvalidated()){let R=k[0];R.element===p&&(m=R),m.computedBlockSize=Math.max.apply(null,k.map(z=>z.computedBlockSize)),t.finishContainer(this,m,e,R,C,this.clientLayout,this.faces);let _=this.currentLayoutPosition.flowPositions[b];_&&_.breakAfter==="region"&&(_.breakAfter=null)}y.finish(!0)}),g=y.result()}return g.then(()=>{if(r.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(m.computedBlockSize)>0){if(!w&&!l){let b=t.getProp(this,"shape-outside"),C=m.getOuterShape(b,this);o.push(C)}}else if(t.children.length==0){i.removeChild(p),h.finish(!0);return}let y=f?0:t.children.length-1;h.loop(()=>{for(;y>=0&&y<t.children.length;){let b=t.children[f?y++:y--],C=this.layoutContainer(e,b,p,n,s,o,r);if(C.isPending())return C.thenAsync(()=>P(!r.isInvalidated()));if(r.isInvalidated())break}return P(!1)}).then(()=>{h.finish(!0)})}),h.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let s=i.positions[n];s.flowChunk.startPage>=0&&s.flowChunk.startPage+s.flowChunk.linger-1<=e&&i.positions.splice(n,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let s=i.positions[n];s.flowChunk.startPage<0&&s.flowChunk.startOffset<this.lookupOffset&&(s.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let t in this.primaryFlows){let i=e.flowPositions[t];if(i&&i.positions.length>0)return!1}return!0}layoutNextPage(e,t){var i;let n=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new cf,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let s=1e4;if(t.page>s)throw new Error(`Too many pages generated (over ${s} pages)`);let o=t.startSideOfFlow("body");t.isBlankPage=un(o)&&this.matchPageSide(o),e.isBlankPage=t.isBlankPage,t.page++,e.pageType==null&&(e.pageType=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let r=n?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.styler.cascade.applyVarFilter([r],this.styler,null),this.styler.cascade.applyCalcFilter(r,this.styler.context),!n){let f=new Ae(this.style.pageScope,"left-page");e.side=f.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let a=this.selectPageMaster(r);if(!a)return P(null);let h=0;if(!n){e.setAutoPageWidth(a.pageBox.specified.width.value===xn),e.setAutoPageHeight(a.pageBox.specified.height.value===Sn),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(r,this);let f=Ja(us(r),this);this.setPageSizeAndBleed(f,e),gw(r,f,e,this),h=f.bleedOffset+f.bleed}let l=!n&&a.getProp(this,"writing-mode")||v.horizontal_tb;this.pageVertical=l!=v.horizontal_tb;let c=a.getProp(this,"direction")||v.ltr,p=new Gi(this.rootPageFloatLayoutContext,Ce.PAGE,null,null,null,l,c),d=F("layoutNextPage");return d.loopWithFrame(f=>{this.layoutContainer(e,a,e.bleedBox,h,h,[],p).then(()=>{p.isInvalidated()||p.finish(),p.isInvalidated()?(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),p.validate(),f.continueLoop()):f.breakLoop()})}).then(()=>{a.adjustPageLayout(this,e,this.clientLayout),n||(this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(m=>{let g=t.flowPositions[m],w=g.breakAfter;w&&(w==="page"||!this.matchPageSide(w))&&(g.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let f=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(f,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),d.finish(t)}),d.result()}setPageSizeAndBleed(e,t){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,t.container.style.width=`${this.pageSheetWidth}px`,t.container.style.height=`${this.pageSheetHeight}px`,t.bleedBox.style.left=`${e.bleedOffset}px`,t.bleedBox.style.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`}},Jw=class Wo extends cn{constructor(t,i,n,s){super(t.rootScope,t,i,n,s,t.validatorSet,!n),this.masterHandler=t,u(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let s=new Ku(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new lw(s.scope,this.masterHandler,s,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=dt(this.scope,this.condition,i)),this.masterHandler.pushHandler(new Wo(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new Ag(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new Dn(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startFlowRule(t){let i=this.masterHandler.flowProps[t];i||(i={},this.masterHandler.flowProps[t]=i),this.masterHandler.pushHandler(new Dn(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new Dn(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=ys(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new Dn(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new Fw(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(cn.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let t=`R${this.masterHandler.regionCount++}`;this.special("region-id",B(t)),this.endRule();let i=new Wo(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},gc=class extends Fp{constructor(e){super(),this.validatorSet=e,u(this,"rootScope"),u(this,"pageScope"),u(this,"rootBox"),u(this,"cascadeParserHandler"),u(this,"regionCount",0),u(this,"fontFaces",[]),u(this,"footnoteProps",{}),u(this,"flowProps",{}),u(this,"viewportProps",[]),u(this,"pageProps",{}),this.rootScope=new Js(null),this.pageScope=new Js(this.rootScope),this.rootBox=new iw(this.rootScope),this.cascadeParserHandler=new Jw(this,null,null,null),this.slave=this.cascadeParserHandler}};function Qw(e,t){return t.parseOPSResource(e)}var eb=class extends tr{constructor(e){super(Qw,"document"),this.fontDeobfuscator=e,u(this,"styleByKey",{}),u(this,"styleFetcherByKey",{}),u(this,"styleByDocURL",{}),u(this,"triggersByDocURL",{}),u(this,"validatorSet",null),u(this,"styleSheets",[]),u(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=F("OPSDocStore.init");return this.validatorSet=qu(),Kw().then(()=>{this.triggerSingleDocumentPreprocessing=!0,i.finish(!0)}),i.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,t){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),t&&t.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let t=e.url;t&&(t=Ee(hn(t),Pi)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ee(hn(t),Pi)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=F("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return pc(e,this).then(s=>{var o;if(!s){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let d=vt("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<d.length;f++)try{d[f](s.document)}catch(m){H.warn("Error during single document preprocessing:",m)}}let r=[],a=s.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let d=0;d<a.length;d++){let f=a[d],m=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),g=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),w=f.getAttribute("action"),y=f.getAttribute("ref");m&&g&&w&&y&&r.push({observer:m,event:g,action:w,ref:y})}this.triggersByDocURL[i]=r;let h=[];if(h.push({url:Ee("user-agent-page.css",ni),text:uh,flavor:"UA",classes:null,media:null}),n)h.push({url:Ee("user-agent-toc.css",ni),text:dh,flavor:"UA",classes:null,media:null});else{let d=s.document.querySelectorAll("style, link, meta");for(let f of d){let m=f.namespaceURI,g=f.localName;if(m=="http://www.w3.org/1999/xhtml")if(g=="style"){let w=f.getAttribute("class"),y=f.getAttribute("media"),b=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:b?w:null,media:y})}else if(g=="link"){let w=f.getAttribute("href"),y=(o=f.getAttribute("rel"))==null?void 0:o.split(/\s+/),b=f.getAttribute("class"),C=f.getAttribute("media");if(w&&y!=null&&y.includes("stylesheet")&&(!y.includes("alternate")||b)){let k=Ee(w,i),R=f.getAttribute("title");h.push({url:k,text:null,classes:R?b:null,media:C,flavor:"Author"})}}else g=="meta"&&f.getAttribute("name")=="viewport"&&h.push({url:i,text:this.processViewportMeta(f),flavor:"Author",classes:null,media:null})}for(let f=0;f<this.styleSheets.length;f++)h.push(this.styleSheets[f])}let l="";for(let d=0;d<h.length;d++)l+=h[d].url,l+="^",h[d].text&&(l+=h[d].text),l+="^";let c=this.styleByKey[l];if(c){this.styleByDocURL[i]=c,t.finish(s);return}let p=this.styleFetcherByKey[l];p||(p=new Cn(()=>{let d=F("fetchStylesheet"),f=0,m=new gc(this.validatorSet);return d.loop(()=>{if(f<h.length){let g=h[f++];return m.startStylesheet(g.flavor),g.text!==null?nr(g.text,m,g.url,g.classes,g.media).thenReturn(!0):vh(g.url,m,g.classes,g.media)}return P(!1)}).then(()=>{let g=m.cascadeParserHandler.finish();c=new Zw(this,m.rootScope,m.pageScope,g,m.rootBox,m.fontFaces,m.footnoteProps,m.flowProps,m.viewportProps,m.pageProps),this.styleByKey[l]=c,delete this.styleFetcherByKey[l],d.finish(c)}),d.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[l]=p,p.start()),p.get().then(d=>{this.styleByDocURL[i]=d,t.finish(s)})}),t.result()}processViewportMeta(e){return""}},an="\u25B8",il="\u25BE",tb="\u25B9";function Fr(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 s=n;/^h[1-6]$/.test(s.localName)&&(s.previousElementSibling?s=s.nextElementSibling:s=s.parentElement),s&&s.querySelector("li a[href]")&&t.push(s)}return t}function ib(e){let t=Fr(e),i=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))i.push(s);return i}var nb=class{constructor(e,t,i,n,s,o,r,a,h,l){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=s,this.rendererFactory=r,this.fallbackMap=a,this.documentURLTransformer=h,this.counterStore=l,u(this,"pref"),u(this,"page",null),u(this,"instance",null),this.pref=Tl(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;_t(n,"height","auto")!="auto"&&(T(n,"height","auto"),this.setAutoHeight(n,t)),_t(n,"position","static")=="absolute"&&(T(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,s)=>{let o=s.behavior;if(o)switch(o.toString()){case"toc-node-anchor":s.color=v.inherit,s["text-decoration"]=v.none;break;case"toc-node":s.display=v.block,s.margin=fe,s.padding=fe,s["padding-inline-start"]=new I(1.25,"em");break;case"toc-node-first-child":s.display=v.inline_block,s.margin=new I(.2,"em"),s["vertical-align"]=v.top,s.color=v.inherit,s["text-decoration"]=v.none;break;case"toc-container":s.padding=fe;break}if(!o||o.toString()!="toc-node"&&o.toString()!="toc-container")return t(i,n,s);let r=i.firstChild;r&&r.nodeType!==1&&ze(r)&&i.replaceChild(i.ownerDocument.createComment(r.textContent),r);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=an&&(l.textContent=an,T(l,"cursor","pointer"),l.addEventListener("click",sb,!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=tb,T(l,"margin","0.2em 0 0 -1em"),T(l,"margin-inline-start","-1em"),T(l,"margin-inline-end","0"),T(l,"display","inline-block"),T(l,"width","1em"),T(l,"text-align","center"),T(l,"vertical-align","top"),T(l,"cursor","default"),T(l,"font-family","Menlo,sans-serif"),h.appendChild(l),T(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){T(h,"height","0px");let c=i.firstElementChild;c&&c.localName==="a"&&(c.tabIndex=-1)}else n.setAttribute("role","tree")}else a=="toc-node"&&(h.setAttribute("data-adapt-class","toc-container"),h.setAttribute("role","group"),h.setAttribute("aria-hidden","true"));return P(h)}}showTOC(e,t,i,n,s){if(this.page)return P(this.page);let o=F("showTOC"),r=new Th(e,e);this.page=r;let a=Nt(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of Fr(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),c=l.sizeViewport(i,1e5,s);t=new cs(t.window,c.fontSize,0,t.root,c.width,c.height);let p=this.makeCustomRenderer(h),d=new Lr(l,h,this.lang,t,this.clientLayout,this.fontMapper,p,this.fallbackMap,0,this.documentURLTransformer,this.counterStore);this.instance=d,d.pref=this.pref,d.init().then(()=>{d.layoutNextPage(r,null).then(()=>{this.setAutoHeight(e,2),o.finish(r)})})}),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 s=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(s).map(t)}function t(n){let s=new URL(n.href),[,o]=s.hash.match(/^#?(.*)$/),r=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=e(a);return{id:o,title:r,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function sb(e){let t=e.target,i=t.textContent==an;t.textContent=i?il:an;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let s=n.firstChild;for(;s;){if(s.nodeType===1){let o=s,r=o.getAttribute("data-adapt-class");if(r==="toc-container"){if(o.setAttribute("aria-hidden",i?"false":"true"),o.firstChild){s=o.firstChild;continue}}else if(r==="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==il){a.textContent=an,a.setAttribute("aria-expanded","false"),o.setAttribute("aria-expanded","false"),s=o.children[2];continue}}}for(;!s.nextSibling&&s.parentNode!==n;)s=s.parentNode;s=s.nextSibling}e.stopPropagation()}var nl=class extends eb{constructor(){super(null),u(this,"plainXMLStore"),u(this,"jsonStore"),u(this,"opfByURL",{}),u(this,"primaryOPFByEPubURL",{}),u(this,"deobfuscators",{}),u(this,"documents",{}),this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=Xw(),this.jsonStore=Ip()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,t,i){return this.plainXMLStore.load(e,t,i)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,t,i){return this.jsonStore.load(e,t,i)}loadPubDoc(e){let t=F("loadPubDoc");return bs(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}H.error(`Failed to fetch a source document from ${e} (${i.status}${i.statusText?" "+i.statusText:""})`),t.finish(null)});else if(!i.status&&!i.responseXML&&!i.responseText&&!i.responseBlob&&!i.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),i.contentType=="application/oebps-package+xml"||/\.opf(?:[#?]|$)/.test(e)){let[,n,s]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,s).thenFinish(t)}else i.contentType=="application/ld+json"||i.contentType=="application/webpub+json"||i.contentType=="application/audiobook+json"||i.contentType=="application/json"||/\.json(?:ld)?(?:[#?]|$)/.test(e)?this.loadAsJSON(e,!0).then(n=>{if(!n){this.reportLoadError(e),t.finish(null);return}let s=new Yn(this,e);s.initWithWebPubManifest(n,void 0,e).then(()=>{t.finish(s)})}):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(s=>{if(s){t.finish(s);return}H.error(`Failed to load ${e}.`),t.finish(null)})})}),t.result()}loadEPUBDoc(e){let t=F("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let i=e+"META-INF/container.xml";return this.loadAsPlainXML(i).then(n=>{if(n){let s=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let o of s)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 P(n);let s=F("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(o=>{o?(n=new Yn(this,e),this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(r=>{n.initWithXMLDoc(o,r).then(()=>{s.finish(n)})}):n.initWithXMLDoc(o,null).then(()=>{s.finish(n)})):this.reportLoadError(i)}),s.result()}loadWebPub(e){let t=F("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,s=new Yn(this,e),o=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(o){let r=o.getAttribute("href");if(/^#/.test(r)){let a=jo(n.getElementById(r.substr(1)).textContent);s.initWithWebPubManifest(a,n).then(()=>{t.finish(s)})}else{let a=Ee(o.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{s.initWithWebPubManifest(h,n,a).then(()=>{t.finish(s)})})}}else s.initWithWebPubManifest({},n).then(()=>{s.toc&&s.toc.src===i.url&&Fr(n).length===0&&(s.toc=null),t.finish(s)})}}),t.result()}addDocument(e,t){let i=F("EPUBDocStore.load"),n=Nt(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(Pi)||Object.keys(this.resources).find(s=>this.resources[s]&&t(s)===n)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?H.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&Pi.startsWith("https:")?H.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?H.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):H.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Nt(e),i=this.documents[t];if(i)return i.isPending()?i:P(i.get());{let n=F("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(s=>{s?n.finish(s):this.reportLoadError(t)}),n.result()}}processViewportMeta(e){let t=e.getAttribute("content");if(!t)return"";let i={},n;for(;(n=t.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)t=t.substr(n[0].length),i[n[1]]=n[2];let s=i.width-0,o=i.height-0;if(s&&o){let r=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${s}px;height:${o}px;}`+(r?`@page{size:${s}px ${o}px;margin:0;}`:"@page{margin:0;}")}return""}},sl=class{constructor(){u(this,"id",null),u(this,"src",""),u(this,"mediaType",null),u(this,"title",null),u(this,"itemRefElement",null),u(this,"spineIndex",-1),u(this,"compressedSize",0),u(this,"compressed",null),u(this,"epage",0),u(this,"epageCount",0),u(this,"startPage",null),u(this,"skipPagesBefore",null),u(this,"itemProperties"),this.itemProperties=Qc}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Ee(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=rd(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 ob(e){return e.id}function rb(e){return t=>{let i=F("deobfuscator");return ab("SHA-1",e).then(n=>{let s=t.slice(0,1040),o=t.slice(1040,t.size);Pp(s).then(r=>{let a=new DataView(r);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(fh([a,o]))})}),i.result()}}function ab(e,t){let i=F("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(s=>{n.schedule(new Uint8Array(s))}),i.result()}var Dt={dcterms:"http://purl.org/dc/terms/",marc:"http://id.loc.gov/vocabulary/",media:"http://www.idpf.org/epub/vocab/overlays/#",rendition:"http://www.idpf.org/vocab/rendition/#",onix:"http://www.editeur.org/ONIX/book/codelists/current.html#",xsd:"http://www.w3.org/2001/XMLSchema#",opf:"http://www.idpf.org/2007/opf"},Yi="http://idpf.org/epub/vocab/package/meta/#",Ne={language:`${Dt.dcterms}language`,title:`${Dt.dcterms}title`,creator:`${Dt.dcterms}creator`,layout:`${Dt.rendition}layout`,titleType:`${Yi}title-type`,displaySeq:`${Yi}display-seq`,alternateScript:`${Yi}alternate-script`,role:`${Yi}role`};function lb(e,t){let i={};return(n,s)=>{var o,r,a,h,l,c;let p,d,f=n.r||i,m=s.r||i;if(e==Ne.title&&(p=((o=f[Ne.titleType])==null?void 0:o[0].v)=="main",d=((r=m[Ne.titleType])==null?void 0:r[0].v)=="main",p!=d))return p?-1:1;let g=parseInt((a=f[Ne.displaySeq])==null?void 0:a[0].v,10);isNaN(g)&&(g=Number.MAX_VALUE);let w=parseInt((h=m[Ne.displaySeq])==null?void 0:h[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),g!=w?g-w:e!=Ne.language&&t&&(p=((l=f[Ne.language]||f[Ne.alternateScript])==null?void 0:l[0].v)==t,d=((c=m[Ne.language]||m[Ne.alternateScript])==null?void 0:c[0].v)==t,p!=d)?p?-1:1:n.o-s.o}}function hb(e,t){let i;if(!t)i=Dt;else{i={};for(let d in Dt)i[d]=Dt[d];let p;for(;(p=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(p[0].length),i[p[1]]=p[2]}let n=p=>{if(p){let d=p.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(d){let f=d[2]?i[d[2]]:Yi;if(f)return f+d[3]}}return null},s=1,o=e.childElements().forEachNonNull(p=>{if(p.localName=="meta"){let d=n(p.getAttribute("property"));if(d)return{name:d,value:p.textContent,id:p.getAttribute("id"),order:s++,refines:p.getAttribute("refines"),lang:null,scheme:n(p.getAttribute("scheme")),role:null}}else if(p.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:Dt.dcterms+p.localName,order:s++,lang:p.getAttribute("xml:lang"),value:p.textContent,id:p.getAttribute("id"),refines:null,scheme:null,role:p.getAttribute("role")||p.getAttribute("opf:role")};return null}),r=Fs(o,p=>p.refines),a=p=>ad(p,(d,f)=>d.map(m=>{let g={v:m.value,o:m.order};m.scheme&&(g.s=m.scheme);let w=r[`#${m.id}`]||[];if(w.length||m.lang||m.role){m.lang&&w.push({name:Ne.language,value:m.lang,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null}),m.role&&w.push({name:Ne.role,value:m.role,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null});let y=Fs(w,b=>b.name);g.r=a(y)}return g})),h=a(Fs(o,p=>p.refines?null:p.name)),l=null;h[Ne.language]&&(l=h[Ne.language][0].v);let c=p=>{for(let d in p){let f=p[d];f.sort(lb(d,l));for(let m=0;m<f.length;m++){let g=f[m].r;g&&c(g)}}};return c(h),h}function ub(){let e=window.MathJax;return e?e.Hub:null}var ol={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},qs="viv-id-",Yn=class{constructor(e,t){this.store=e,this.pubURL=t,u(this,"opfXML",null),u(this,"encXML",null),u(this,"items",null),u(this,"spine",null),u(this,"itemMap",null),u(this,"itemMapByPath",null),u(this,"uid",null),u(this,"bindings",{}),u(this,"lang",null),u(this,"epageCount",0),u(this,"prePaginated",!1),u(this,"epageIsRenderedPage",!0),u(this,"epageCountCallback",null),u(this,"metadata",{}),u(this,"toc",null),u(this,"cover",null),u(this,"fallbackMap",{}),u(this,"pageProgression",null),u(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,s){let o=s+(n?`#${n}`:"");return qs+Cl(o,":")}transformURL(n,s){let o=n.match(/^([^#]*)#?(.*)$/);if(o){let r=o[1]||s.replace(/\?viv-toc-box$/,""),a=decodeURIComponent(o[2]);if(r&&e.spine.some(h=>h.src===r))return`#${this.transformFragment(a,r)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(qs)===0&&(n=n.substring(qs.length));let s=od(n,":").match(/^([^#]*)#?(.*)$/);return s?[s[1],s[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=Ee("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let h=e.getElement(`${e.url}#${n}`);h&&(this.uid=h.textContent.replace(/[ \n\r\t]/g,""))}let s={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new sl,c=h;l.initWithElement(c,e.url);let p=c.getAttribute("fallback");return p&&!ol[l.mediaType]&&(s[l.src]=p),!this.toc&&l.itemProperties.nav&&(this.toc=l),!this.cover&&l.itemProperties["cover-image"]&&(this.cover=l),l}),this.itemMap=$r(this.items,ob),this.itemMapByPath=$r(this.items,h=>this.getPathFromURL(h.src));for(let h in s){let l=h;for(;;){let c=this.itemMap[s[l]];if(!c)break;if(ol[c.mediaType]){this.fallbackMap[h]=c.src;break}l=c.src}}this.spine=i.child("spine").child("itemref").asArray().map((h,l)=>{let c=h,p=c.getAttribute("idref"),d=this.itemMap[p];return d&&(d.itemRefElement=c,d.spineIndex=l),d});let o=i.child("spine").attribute("page-progression-direction")[0];o&&(this.pageProgression=fl(o));let r=t?t.doc().child("encryption").child("EncryptedData").predicate(tl.withChild("EncryptionMethod",tl.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],a=i.child("bindings").child("mediaType").asArray();for(let h=0;h<a.length;h++){let l=a[h].getAttribute("handler"),c=a[h].getAttribute("media-type");c&&l&&this.itemMap[l]&&(this.bindings[c]=this.itemMap[l].src)}if(this.metadata=hb(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[Ne.language]&&(this.lang=this.metadata[Ne.language][0].v),this.metadata[Ne.layout]&&(this.prePaginated=this.metadata[Ne.layout][0].v==="pre-paginated"),r.length>0&&this.uid){let h=rb(this.uid);for(let l=0;l<r.length;l++)this.store.deobfuscators[this.pubURL+r[l]]=h}return this.prePaginated&&this.assignAutoPages(),P(!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(),P(!0);let t=0,i=0,n=F("countEPages");return n.loopWithFrame(s=>{if(i===this.spine.length){s.breakLoop();return}let o=this.spine[i++];o.epage=t,this.store.load(o.src).then(r=>{let a=1800,h=r.lang||this.lang;h&&h.match(/^(ja|ko|zh)/)&&(a/=3),o.epageCount=Math.ceil(r.getTotalOffset()/a),t+=o.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),s.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new dc(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let s=new sl;s.initWithParam(n),s.id;let o=i.document.createElement("itemref");o.setAttribute("idref",s.id),i.root.appendChild(o),s.itemRefElement=o,this.itemMap[s.id]=s;let r=this.getPathFromURL(n.url);r==null&&(r=n.url),this.itemMapByPath[r]=s,this.items.push(s)}),t?this.store.addDocument(e[0].url,t):P(null)}initWithWebPubManifest(e,t,i){var n,s,o,r;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[Ne.title]=(Array.isArray(a)?a:[a]).map(g=>{var w;return{v:(w=g.value)!=null?w:g}}));let h=e.author||e.creator||((s=e.metadata)==null?void 0:s.author)||Array.from((o=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?o:[]).map(g=>g.content);h&&h.length!==0&&(this.metadata[Ne.creator]=(Array.isArray(h)?h:[h]).map(g=>{var w;return{v:(w=g.name)!=null?w:g}}));let l=e.inLanguage||((r=e.metadata)==null?void 0:r.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[Ne.language]=(Array.isArray(l)?l:[l]).map(g=>({v:g})));let c=this.getPathFromURL(this.pubURL);if(!e.readingOrder&&t&&c!==null){e.readingOrder=[encodeURI(c)];for(let g of ib(t)){let w=g.getAttribute("href");if(/^(https?:)?\/\//.test(w)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(w))continue;let y=Nt(Ee(w,this.pubURL)),b=this.getPathFromURL(y),C=b!==null?encodeURI(b):y;e.readingOrder.indexOf(C)==-1&&e.readingOrder.push(C)}}let p=[],d=0,f=-1;[e.readingOrder,e.resources].forEach(g=>{g instanceof Array&&g.forEach(w=>{let y=g===e.readingOrder,b=typeof w=="string"?w:w.url||w.href,C=typeof w=="string"?"":w.encodingFormat||w.href&&w.type||"";if(y||C==="text/html"||C==="application/xhtml+xml"||!C&&w.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(b)){let k=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,R={url:Ee(hn(b),k),index:d++,startPage:null,skipPagesBefore:null};w.rel==="contents"&&f===-1&&(f=R.index),p.push(R)}})});let m=F("initWithWebPubManifest");return this.initWithChapters(p).then(()=>{var g,w;f!==-1&&(this.toc=this.items[f]),this.toc||(this.toc=i?(g=this.items)==null?void 0:g[0]:this.itemMapByPath[c]);let y=(w=e.readingOrder)==null?void 0:w.length;y&&y<this.items.length&&this.items.splice(y),m.finish(!0)}),m.result()}getCFI(e,t){let i=this.spine[e],n=F("getCFI");return this.store.load(i.src).then(s=>{let o=s.getNodeByOffset(t),r=null;if(o){let a=s.getNodeOffset(o,0,!1),h=t-a,l=new Yr;l.prependPathFromNode(o,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),r=l.toString()}n.finish(r)}),n.result()}resolveFragment(e){return Ni("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Yr;i.fromString(e);let n;if(this.opfXML){let s=i.navigate(this.opfXML.document);if(s.node.nodeType!=1||s.after||!s.ref){t.finish(null);return}let o=s.node,r=o.getAttribute("idref");if(o.localName!="itemref"||!r||!this.itemMap[r]){t.finish(null);return}n=this.itemMap[r],i=s.ref}else n=this.spine[0];this.store.load(n.src).then(s=>{let o=i.navigate(s.document),r=s.getNodeOffset(o.node,o.offset,o.after);t.finish({spineIndex:n.spineIndex,offsetInItem:r,pageIndex:-1})})},(t,i)=>{H.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return Ni("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let s=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);s==-1&&(s=this.spine.length-1);let o=this.spine[s];(!o||o.epageCount==0)&&(o=this.spine[--s]);let r=Math.floor(e-o.epage);t.finish({spineIndex:s,offsetInItem:-1,pageIndex:r});return}let i=Ht(this.spine.length,s=>{let o=this.spine[s];return o.epage+o.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(s=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let o=0;if(e>0){let r=s.getTotalOffset();o=Math.round(r*e/n.epageCount),o==r&&o--}t.finish({spineIndex:i,offsetInItem:o,pageIndex:-1})})},(t,i)=>{H.warn(i,"Cannot resolve epage:",e),t.finish(null)})}getEPageFromPosition(e){let t=this.spine[e.spineIndex];if(this.epageIsRenderedPage){let n=t.epage+e.pageIndex;return P(n)}if(e.offsetInItem<=0)return P(t.epage);let i=F("getEPage");return this.store.load(t.src).then(n=>{let s=n.getTotalOffset(),o=Math.min(s,e.offsetInItem);i.finish(t.epage+o*t.epageCount/s)}),i.result()}},Un=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),cb=class{constructor(e,t,i,n,s){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=s,u(this,"spineItems",[]),u(this,"spineItemLoadingContinuations",[]),u(this,"pref"),u(this,"clientLayout"),u(this,"counterStore"),u(this,"tocAutohide",!1),u(this,"tocVisible",!1),u(this,"tocView"),this.pref=Tl(n),this.clientLayout=new Gw(t),this.counterStore=new Yd(e.documentURLTransformer)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let s=this.opf.spine[e.item.spineIndex-1];e.item.epage=s.epage+s.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((s,o)=>s+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 s=null;if(i>0)s=e.pages[i-1].container.nextElementSibling;else for(let o=e.item.spineIndex+1;o<this.spineItems.length;o++){let r=this.spineItems[o];if(r&&r.pages[0]){s=r.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,s)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}renderSinglePage(e,t){let i=F("renderSinglePage"),n=e.pages[t?t.page:0],s=this.makePage(e,t);return n&&(s.pageType=n.pageType),e.instance.layoutNextPage(s,t).then(o=>{t=o;let r=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,s,r),this.counterStore.finishPage(s.spineIndex,r);let a=null;if(t){let h=e.layoutPositions[t.page];e.layoutPositions[t.page]=t,h&&e.pages[t.page]&&(t.isSamePosition(h)||(a=this.renderSinglePage(e,t)))}a||(a=P(!0)),a.then(()=>{let h=this.counterStore.getUnresolvedRefsToPage(s),l=0;i.loopWithFrame(c=>{if(l++,l>h.length){c.breakLoop();return}let p=h[l-1];if(p.refs=p.refs.filter(d=>!d.isResolved()),p.refs.length===0){c.continueLoop();return}this.getPageViewItem(p.spineIndex).then(d=>{if(!d){c.continueLoop();return}let{currentPageType:f,previousPageType:m}=d.instance.styler.cascade,g=d.instance.scopes;d.instance.scopes={},this.counterStore.pushPageCounters(p.pageCounters),this.counterStore.pushReferencesToSolve(p.refs);let w=d.layoutPositions[p.pageIndex];this.renderSinglePage(d,w).then(y=>{d.instance.styler.cascade.currentPageType=f,d.instance.styler.cascade.previousPageType=m,d.instance.scopes=g,this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve();let b=y.pageAndPosition.position;b.spineIndex===s.spineIndex&&b.pageIndex===r&&(s=y.pageAndPosition.page),c.continueLoop()})})}).then(()=>{s.container.parentElement||(s=e.pages[r]),s.isLastPage=!t&&e.item.spineIndex===this.opf.spine.length-1,s.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),s.container.setAttribute("data-vivliostyle-page-index",r),s.container.setAttribute("data-vivliostyle-spine-index",s.spineIndex),i.finish({pageAndPosition:Un(s,r),nextLayoutPosition:t})})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let s=Ht(t.layoutPositions.length,o=>t.instance.getPosition(t.layoutPositions[o],!0)>n);s===t.layoutPositions.length?t.complete?i=t.layoutPositions.length-1:i=Number.POSITIVE_INFINITY:i=s-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=F("findPage");return this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let s=null,o;i.loopWithFrame(r=>{let a=this.normalizeSeekPosition(e,n);o=a.pageIndex,s=n.pages[o],s?r.breakLoop():n.complete?(o=n.layoutPositions.length-1,s=n.pages[o],r.breakLoop()):t?this.renderPage(a).then(h=>{h&&(s=h.page,o=h.position.pageIndex),r.breakLoop()}):i.sleep(100).then(()=>{r.continueLoop()})}).then(()=>{i.finish(Un(s,o))})}),i.result()}renderPage(e){let t=F("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),s=n.pageIndex,o=n.offsetInItem,r=i.pages[s];if(r){t.finish(Un(r,s));return}t.loopWithFrame(a=>{if(s<i.layoutPositions.length){a.breakLoop();return}if(i.complete){s=i.layoutPositions.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let c=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(o>=0&&i.instance.getPosition(h)>o){r=c,s=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else r=c,s=l.pageAndPosition.position.pageIndex,i.complete=!0,a.breakLoop()})}).then(()=>{r=r||i.pages[s];let a=i.layoutPositions[s];if(r){t.finish(Un(r,s));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||(i.complete=!0),t.finish(h.pageAndPosition)})})}),t.result()}renderAllPages(){let e=F("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(t=>{e.loopWithFrame(i=>{this.spineItems.some(n=>n?.pages.some(s=>s?.fetchers.some(o=>!o.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=F("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,s=e.pageIndex,o=0;t&&(o=n);let r;return i.loopWithFrame(a=>{let h={spineIndex:o,pageIndex:o===n?s:Number.POSITIVE_INFINITY,offsetInItem:o===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{r=l,++o>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(r)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,s=F("nextPage");return this.getPageViewItem(i).then(o=>{if(!o){s.finish(null);return}if(o.complete&&n==o.layoutPositions.length-1){if(i>=this.opf.spine.length-1){s.finish(null);return}i++,n=0;let r=this.spineItems[i],a=r&&r.pages[0],h=o.pages[o.pages.length-1];a&&h&&a.side==h.side&&(r.pages.forEach(l=>{l.container&&l.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(s)}),s.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return P(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 P({left:null,right:null});let n=F("getSpread"),s=i.side==="left",o;return this.isRectoPage(i,e)?o=this.previousPage(e,t):o=this.nextPage(e,t),o.then(r=>{let a=this.getPage(e),h=r&&r.page;h&&h.side===a.side&&(h=null),s?n.finish({left:a,right:h}):n.finish({left:h,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return P(null);let n=this.isRectoPage(i,e),s=this.nextPage(e,t);return n?s:s.thenAsync(o=>{if(o){if(o.page.side===i.side)return s;let r=this.nextPage(o.position,t);return r.thenAsync(a=>a?r:s)}else return P(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return P(null);let n=this.isRectoPage(i,e),s=this.previousPage(e,t),o=i.container.previousElementSibling;return n?s.thenAsync(r=>r?r.page.side===i.side||r.page.container!==o?s:this.previousPage(r.position,t):P(null)):s}navigateToEPage(e,t,i){let n=F("navigateToEPage");return this.opf.resolveEPage(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(e,t,i){let n=F("navigateToCFI");return this.opf.resolveFragment(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateTo(e,t,i){H.debug("Navigate to",e);let n=this.opf.getPathFromURL(Nt(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let r=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(r[0]),n==null&&(n=r[0])):n=r[0],e=r[0]+(r[1]?`#${r[1]}`:"")}if(n==null)return P(null)}let s=this.opf.itemMapByPath[n];if(!s){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let r=e.indexOf("#");if(r>=0)return this.navigateToFragment(e.substr(r+1),t,i)}return P(null)}let o=F("navigateTo");return this.getPageViewItem(s.spineIndex).then(r=>{if(!r){o.finish(null);return}let a=r.xmldoc.getElement(e);this.findPage({spineIndex:s.spineIndex,pageIndex:-1,offsetInItem:a?r.xmldoc.getElementOffset(a):0},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",ln||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let s=i.document.createElement("div");s.setAttribute("data-vivliostyle-bleed-box","true"),s.role="presentation",n.appendChild(s);let o=new Th(n,s);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 r=this.opf.documentURLTransformer.transformFragment("",e.item.src);s.setAttribute("id",r),o.registerElementWithId(s,r)}if(i!==this.viewport){let r=Il(this.viewport.width,this.viewport.height,i.width,i.height),a=Oi(null,new yt(r,null),"");o.delayedItems.push(new or(n,"transform",a))}return o}makeObjectView(e,t,i,n){let s=t.getAttribute("data"),o=null;if(s){s=Ee(s,e.url);let r=t.getAttribute("media-type");if(!r){let a=this.opf.getPathFromURL(s);if(a){let h=this.opf.itemMapByPath[a];h&&(r=h.mediaType)}}if(r){let a=this.opf.bindings[r];if(a){o=this.viewport.document.createElement("iframe"),o.style.border="none";let h=Ur(s),l=Ur(r),c=new It;c.append(a),c.append("?src="),c.append(h),c.append("&type="),c.append(l);for(let f=t.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let m=f;if(m.localName=="param"&&m.namespaceURI=="http://www.w3.org/1999/xhtml"){let g=m.getAttribute("name"),w=m.getAttribute("value");g&&w&&(c.append("&"),c.append(encodeURIComponent(g)),c.append("="),c.append(encodeURIComponent(w)))}}o.setAttribute("src",c.toString());let p=t.getAttribute("width");p&&o.setAttribute("width",p);let d=t.getAttribute("height");d&&o.setAttribute("height",d)}}}return o||(o=this.viewport.document.createElement("object"),s&&o.setAttribute("data",s),o.setAttribute("data-adapt-process-children","true")),P(o)}makeMathJaxView(e,t,i,n){let s=ub();if(s){let o=i.ownerDocument,r=o.createElement("span");i.appendChild(r);let a=o.importNode(t,!0);this.resolveURLsInMathML(a,e),r.appendChild(a);let h=s.queue;h.Push(["Typeset",s,r]);let l=F("makeMathJaxView"),c=l.suspend();return h.Push(()=>{c.schedule(r)}),l.result()}return P(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let s=Ee(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,s):e.setAttribute(n.name,s)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):P(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return P(null);let t=this.spineItems[e];if(t)return P(t);let i=F("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let r=i.suspend();return n.push(r),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let s=this.opf.spine[e],o=this.opf.store;return o.load(s.src).then(r=>{var a;let h=s.itemRefElement.getAttribute("properties");h&&r.root.setAttribute("data-vivliostyle-epub-spine-properties",h),s.title=r.document.title;let l=o.getStyleForDoc(r),c=this.makeCustomRenderer(r),p=this.viewport,d=l.sizeViewport(p.width,p.height,p.fontSize,this.pref);(d.width!=p.width||d.height!=p.height||d.fontSize!=p.fontSize)&&(p=new cs(p.window,d.fontSize,p.pixelRatio,p.root,d.width,d.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,m=this.spineItems[e-1],g,w;if(s.startPage!==null)g=s.startPage-1,w=g;else{if(e>0&&(!m||!m.complete))g=s.epage||e,!this.opf.prePaginated&&g%2==(f?1:0)&&g++,w=g;else{g=m?m.instance.pageNumberOffset+m.pages.length:0;let C=this.counterStore.currentPageCounters.page;w=!C||!C.length?g:C[C.length-1]}s.skipPagesBefore!==null&&(g+=s.skipPagesBefore,w+=s.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let y=new Lr(l,r,this.opf.lang,p,this.clientLayout,this.fontMapper,c,this.opf.fallbackMap,g,this.opf.documentURLTransformer,this.counterStore,this.opf.pageProgression,f);y.pref=this.pref;let b=this.opf.metadata&&this.opf.metadata[Ne.title];y.pubTitle=b&&b[0]&&b[0].v||"",y.docTitle=s.title||"",y.init().then(()=>{!this.opf.pageProgression&&y.pageProgression&&(this.opf.pageProgression=y.pageProgression),t={item:s,xmldoc:r,instance:y,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 P(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"),P(this.tocView.page);let n=F("showTOC");this.tocView||(this.tocView=new nb(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore));let s=this.viewport,o=Math.min(344,Math.round(.67*s.width)-16),r=s.height-6,a=s.document.createElement("div");return s.root.appendChild(a),ln||(a.style.visibility="hidden"),a.style.width=`${o+16}px`,a.style.maxHeight=`${r}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,s,o,r,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()}},rl="data-vivliostyle-viewer-status",db="data-vivliostyle-spread-view",mc=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(mc||{}),pb=class{constructor(e,t,i,n){this.window=e,this.viewportElement=t,this.instanceId=i,this.callbackFn=n,u(this,"fontMapper"),u(this,"kick"),u(this,"sendCommand"),u(this,"resizeListener"),u(this,"hyperlinkListener"),u(this,"pageRuleStyleElement"),u(this,"pageSheetSizeAlreadySet",!1),u(this,"renderTask",null),u(this,"actions"),u(this,"readyState"),u(this,"packageURL"),u(this,"opf"),u(this,"touchActive"),u(this,"touchX"),u(this,"touchY"),u(this,"needResize"),u(this,"resized"),u(this,"needRefresh"),u(this,"viewportSize"),u(this,"currentPage"),u(this,"currentSpread"),u(this,"pagePosition"),u(this,"fontSize"),u(this,"zoom"),u(this,"fitToScreen"),u(this,"pageViewMode"),u(this,"waitForLoading"),u(this,"renderAllPages"),u(this,"pref"),u(this,"pageSizes"),u(this,"pixelRatio"),u(this,"pixelRatioLimit"),u(this,"viewport"),u(this,"opfView");let s=t.ownerDocument,o=(r,a)=>{let h=s.getElementById(r);return h||(h=s.createElement("style"),h.id=r,a&&(h.textContent=a),s.head.appendChild(h)),h};o("vivliostyle-viewport-screen-css",rh),o("vivliostyle-viewport-css",ah),o("vivliostyle-polyfill-css",ph),t.setAttribute("data-vivliostyle-viewer-viewport",!0),ln&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(rl,"loading"),this.fontMapper=new ew(s.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=r=>{},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=Nl(),this.pageSizes=[],this.pixelRatioLimit=yl==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=wl;H.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),H.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),H.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),H.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){this.readyState!==e&&(this.readyState=e,this.viewportElement.setAttribute(rl,e),this.callback({t:"readystatechange"}))}loadPublication(e){tt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,s=e.userStyleSheet;this.viewport=null;let o=F("loadPublication");return this.configure(e).then(()=>{let r=new nl;r.init(n,s).then(()=>{let a=Ee(hn(t),this.window.location.href);this.packageURL=[a],r.loadPubDoc(a).then(h=>{h?(this.opf=h,this.render(i).then(()=>{o.finish(!0)})):o.finish(!1)})})}),o.result()}loadXML(e){tt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,s=e.authorStyleSheet,o=e.userStyleSheet;this.viewport=null;let r=F("loadXML");return this.configure(e).then(()=>{let a=new nl;a.init(s,o).then(()=>{let h=t.map((l,c)=>({url:Ee(hn(l.url),this.window.location.href),index:c,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new Yn(a,""),this.opf.initWithChapters(h,i).then(()=>{this.render(n).then(()=>{r.finish(!0)})})})}),r.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,P(!0))):t=P(!0),t.thenAsync(()=>(tt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let s=n[0];if(s==="em"||s==="rem")return t*this.fontSize;if(s==="ex")return t*ge.ex*this.fontSize/ge.em;let o=ge[s];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"&&(zr(e.userAgentRootURL.replace(/resources\/?$/,"")),Dr(e.userAgentRootURL)),typeof e.rootURL=="string"&&(zr(e.rootURL),Dr(`${Pi}resources/`)),typeof e.pageViewMode=="string"&&e.pageViewMode!==this.pageViewMode&&(this.pageViewMode=e.pageViewMode,this.needResize=!0),typeof e.pageBorder=="number"&&e.pageBorder!==this.pref.pageBorder&&(this.viewport=null,this.pref.pageBorder=e.pageBorder,this.needResize=!0),typeof e.zoom=="number"&&e.zoom!==this.zoom&&(this.zoom=e.zoom,this.needRefresh=!0),typeof e.fitToScreen=="boolean"&&e.fitToScreen!==this.fitToScreen&&(this.fitToScreen=e.fitToScreen,this.needRefresh=!0),typeof e.defaultPaperSize=="object"&&typeof e.defaultPaperSize.width=="number"&&typeof e.defaultPaperSize.height=="number"&&(this.viewport=null,this.pref.defaultPaperSize=e.defaultPaperSize,this.needResize=!0),typeof e.allowScripts=="boolean"&&e.allowScripts!==Ft&&(Bw(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),P(!0)}configurePlugins(e){vt("CONFIGURATION").forEach(t=>{let i=t(e);this.needResize=i.needResize||this.needResize,this.needRefresh=i.needRefresh||this.needRefresh})}pageReplacedListener(e){let t=this.currentPage,i=this.currentSpread,n=e.target;i?(i.left===n||i.right===n)&&this.showCurrent(e.newPage):t===e.target&&this.showCurrent(e.newPage)}forCurrentPages(e){let t=[];this.currentPage&&t.push(this.currentPage),this.currentSpread&&(t.push(this.currentSpread.left),t.push(this.currentSpread.right)),t.forEach(i=>{i&&e(i)})}removePageListeners(){this.forCurrentPages(e=>{e.removeEventListener("hyperlink",this.hyperlinkListener,!1),e.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(e=>{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=F("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(t=>{let i=this.currentPage;(this.waitForLoading&&i.fetchers.length>0?ws(i.fetchers):P(!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(db,e.toString())}sizeIsGood(){var e;let t=this.createViewport(),i=((e=this.opfView)==null?void 0:e.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&i?this.pageSizes[0]:null);this.resized=!1;let s=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!s&&t.width==this.viewport.width&&t.height==this.viewport.height||!s&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,s;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((s=this.pageSizes[i-1])==null?void 0:s.height))){let r=function(m){let g=m*.75;return Math.ceil(g)};var o=r;let a=Math.max(...this.pageSizes.map(m=>m.width)),h=Math.max(...this.pageSizes.map(m=>m.height)),l=r(a),c=r(h),p=l*((this.pixelRatio||1)-1)+2,d=c*((this.pixelRatio||1)-1)+2,f=`@page {size: ${l}pt ${c}pt; margin: 0 ${-p}pt ${-d}pt 0;}`;this.pageRuleStyleElement.textContent=f,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}reset(){let e=!1,t=!1;this.opfView&&(e=this.opfView.tocVisible,t=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new cb(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?P(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,P(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,P(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,P(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 al),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return P(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=ro().getScheduler().run(()=>Ni("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,tt.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let s={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.currentPage.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(s.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(s)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():P(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),tt.registerEndTiming("render (resize)"),Ft&&uc(this.window)?Dw(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 al)tt.registerEndTiming("render (resize)"),H.debug(i.message);else throw i}));return P(!0)}sendLocationNotification(e,t){let i=F("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:e.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(s=>{n.epage=s,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(e){var t;let i;if(this.readyState!=="complete"&&e.where!=="next"&&this.setReadyState("loading"),typeof e.where=="string"){let s;switch(e.where){case"next":s=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":s=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":s=this.opfView.lastPage;break;case"first":s=this.opfView.firstPage;break;default:return P(!0)}s&&(i=()=>s.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let s=e.epage;i=()=>this.opfView.navigateToEPage(s,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let s=e.url;i=()=>this.opfView.navigateTo(s,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let s=e.position;i=()=>this.opfView.findPage(s,!this.renderAllPages)}else return P(!0);if(!this.opfView)return P(!0);let n=F("moveTo");return i.call(this.opfView).then(s=>{let o;if(s){this.pagePosition=s.position;let r=F("moveTo.showCurrent");o=r.result(),this.showCurrent(s.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(r)})}else o=P(!0);o.then(r=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(r)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),s=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!s)return P(!0)}else if(i=="hide")return P(!0);if(n&&i!="show")return this.opfView.hideTOC(),P(!0);{let o=F("showTOC");return this.opfView.showTOC(t).then(r=>{if(r){if(s&&(r.listeners={}),t){let a=()=>{this.opfView.hideTOC()};r.addEventListener("hyperlink",a,!1)}r.addEventListener("hyperlink",this.hyperlinkListener,!1)}o.finish(!0)}),o.result()}}runCommand(e){let t=e.a||"";return Ni("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(H.error("No such action:",t),i.finish(!0))},(i,n)=>{H.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=ll(e),i=null,n=this;yp(()=>{let s=F("commandLoop"),o=ro().getScheduler();return n.hyperlinkListener=r=>{let a=r,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){r.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};o.run(()=>(n.callback(l),P(!0)))}},s.loopWithFrame(r=>{if(n.needResize)n.resize().then(()=>{r.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{r.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{r.continueLoop()})}else{let a=F("waitForCommand");i=a.suspend(this),a.result().then(()=>{r.continueLoop()})}}).thenFinish(s),s.result()}),n.kick=()=>{let s=i;s&&(i=null,s.schedule(!0))},n.sendCommand=s=>t?!1:(t=ll(s),n.kick(),!0),this.window.adapt_command=n.sendCommand}},wc=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(wc||{}),al=class bc extends Error{constructor(){super(),u(this,"name","RenderingCanceledError"),u(this,"message","Page rendering has been canceled"),u(this,"stack"),Object.setPrototypeOf(this,bc.prototype),this.stack=new Error().stack}};function ll(e){return typeof e=="string"?jo(e):e}var hl=Go;function fb(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function ul(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 vc=class{constructor(e,t){this.settings=e,u(this,"initialized",!1),u(this,"adaptViewer_"),u(this,"options"),u(this,"eventTarget"),u(this,"readyState"),pl(e.debug),this.adaptViewer_=new pb(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=fb(),t&&this.setOptions(t),this.eventTarget=new Xo,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},ul(e));this.adaptViewer_.sendCommand(t),Object.assign(this.options,e)}dispatcher(e){let t={type:e.t},i=e;Object.keys(i).forEach(n=>{n!=="t"&&(t[n]=i[n])}),this.eventTarget.dispatchEvent(t)}addListener(e,t){this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){this.eventTarget.removeEventListener(e,t,!1)}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let s=i||{};function o(l){if(l)return l.map(c=>({url:c.url||null,text:c.text||null}))}let r=o(s.authorStyleSheet),a=o(s.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:gb(e)||t,document:s.documentObject,fragment:s.fragment,authorStyleSheet:r,userStyleSheet:a},ul(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()===hl.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===hl.LTR?"next":"previous";default:return e}}navigateToPage(e,t){e==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:t}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(e)})}navigateToInternalUrl(e){this.adaptViewer_.sendCommand({a:"moveTo",url:e})}navigateToPosition(e){var t,i;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:e.spineIndex,pageIndex:(t=e.pageIndex)!=null?t:-1,offsetInItem:(i=e.offsetInItem)!=null?i:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(e,t){let i=e==null?"toggle":e?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:i,autohide:t})}queryZoomFactor(e){return this.adaptViewer_.queryZoomFactor(e)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var e,t;return(t=(e=this.adaptViewer_.opfView)==null?void 0:e.tocView)==null?void 0:t.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}};function gb(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 yc=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(yc||{}),mb=wc,wb=mc;tt.forceRegisterEndTiming("load_vivliostyle");var bb=class{constructor(e,{title:t="",printCallback:i=r=>r.print(),errorCallback:n=null,hideIframe:s=!0,removeIframe:o=!0}){u(this,"htmlDoc"),u(this,"title"),u(this,"printCallback"),u(this,"errorCallback"),u(this,"hideIframe"),u(this,"removeIframe"),u(this,"iframe"),u(this,"iframeWin"),u(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=s,this.removeIframe=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=`
|
|
1790
|
+
`),i.toString()}},jb=class{constructor(e){this.deobfuscator=e,c(this,"familyMap",{})}registerFamily(e,t){let i=e.family,n=this.familyMap[i],s=t.family;if(n){if(n!=s)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${e.family}`)}else this.familyMap[i]=s}filterFontFamily(e){if(e instanceof qe){let t=e.values,i=[];for(let n of t){let s=this.familyMap[n.stringValue()];s&&i.push(F(s)),i.push(n)}return new qe(i)}else{let t=this.familyMap[e.stringValue()];return t?new qe([F(t),e]):e}}},Xb=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=B("initFont"),s=e.src,r={};for(let h of Na(e.properties))r[h]=e.properties[h];let o=this.getViewFontFamily(e,i);r["font-family"]=F(o);let a=new dd(r),l=this.head.ownerDocument.createElement("style");return l.textContent=a.makeAtRule(s,t),this.head.appendChild(l),H.debug("Load font:",s),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i,s=this.srcURLMap[n];return s?s.piggyback(r=>{let o=r;o.traitsEqual(e)?(t.registerFamily(e,o),H.debug("Found already-loaded font:",i)):H.warn("E_FONT_FACE_INCOMPATIBLE",e.src)}):(s=new $n(()=>{let r=B("loadFont"),o=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(o):null;return a?er(o,"blob").then(l=>{if(!l.responseBlob){r.finish(null);return}a(l.responseBlob).then(h=>{this.initFont(e,h,t).thenFinish(r)})}):this.initFont(e,null,t).thenFinish(r),r.result()},`loadFont ${i}`),this.srcURLMap[n]=s,s.start()),s}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){H.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return Qs(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(s=>{}))}),t===0)return N(!0);let i=B("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?N(!0):N(!1))).thenFinish(i),i.result()}},qb=1,rr=class{constructor(e,t,i,n,s){this.name=t,this.pseudoName=i,this.classes=n,this.parent=s,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${qb++}`,s&&(this.index=s.children.length,s.children.push(this))}get scope(){return this._scope}createInstance(e){throw new Error("E_UNEXPECTED_CALL")}clone(e){throw new Error("E_UNEXPECTED_CALL")}copySpecified(e){let t=this.specified,i=e.specified;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n])}cloneChildren(e){for(let t=0;t<this.children.length;t++)this.children[t].clone({parent:e})}},Yb=class extends rr{constructor(e){super(e,null,null,[],null),this.specified.width=new M(Un,0),this.specified.height=new M(Hn,0)}},Kl=class extends Dr{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(s,r){let o=s.match(/^([^.]+)\.([^.]+)$/);if(o){let a=i.pageMaster.keyMap[o[1]];if(a){let l=this.lookupInstance(a);if(l)return r?l.resolveFunc(o[2]):l.resolveName(o[2])}}return null}}},pd=class fd extends rr{constructor(t,i,n,s,r,o,a){super(t,i,n,s,r),this.condition=o,this.specificity=a,c(this,"keyMap",{}),t instanceof Kl||(this._scope=new Kl(t,this)),this.pageMaster=this,this.specified.width=new M(Un,0),this.specified.height=new M(Hn,0),this.specified["wrap-flow"]=new M(b.auto,0),this.specified.position=new M(b.relative,0),this.specified.overflow=new M(b.visible,0)}createInstance(t){return new Ta(t,this)}clone(t){let i=new fd(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}},gd=class md extends rr{constructor(t,i,n,s,r){super(t,i,n,s,r),this.pageMaster=r.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new M(b.auto,0)}createInstance(t){return new Qb(t,this)}clone(t){let i=new md(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},Kn=class wd extends rr{constructor(t,i,n,s,r){super(t,i,n,s,r),this.pageMaster=r.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new Yi(t,this)}clone(t){let i=new wd(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function Kb(e,t,i){return!t||J(t)?new He(e,i):t.toExpr(e,e.zero)}function fe(e,t,i){return!t||t===b.auto||J(t)?null:t.toExpr(e,i)}function Zb(e,t,i){return!t||t===b.normal||J(t)?null:t.toExpr(e,i)}function dt(e,t,i){return!t||t===b.auto||J(t)?e.zero:t.toExpr(e,i)}function Zl(e,t,i){return!t||J(t)?e.zero:t===b.auto?null:t.toExpr(e,i)}function Bt(e,t,i,n){return!t||i===b.none||J(t)?e.zero:t.toExpr(e,n)}function bd(e,t,i){return!t||J(t)?i:t===b._true?e._true:t===b._false?e._false:t.toExpr(e,e.zero)}var or=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 s=this.vertical?nc:sc;n=e;for(let r in s)n=n.replace(r,s[r])}n!=e&&(t=this.resolveName(n))}return t&&(this.namedValues[e]=t),t}resolveFunc(e){let t=this.namedFuncs[e];if(t)return t;switch(e){case"columns":{let i=this.pageBox.scope,n=new Yh(i,0),s=this.resolveName("column-count"),r=this.resolveName("column-width"),o=this.resolveName("column-gap");t=pe(i,us(i,new wn(i,"min",[n,s]),Y(i,r,o)),o);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=bd(e,t.enabled,e._true),n=fe(e,t.page,e.zero);if(n){let o=new ze(e,"page-number");i=Ct(e,i,new Jo(e,n,o))}let s=fe(e,t["min-page-width"],e.zero);s&&(i=Ct(e,i,new Ur(e,new ze(e,"page-width"),s)));let r=fe(e,t["min-page-height"],e.zero);r&&(i=Ct(e,i,new Ur(e,new ze(e,"page-height"),r))),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),s=fe(e,t["margin-left"],i),r=Bt(e,t["border-left-width"],t["border-left-style"],i),o=dt(e,t["padding-left"],i),a=fe(e,t.width,i),l=fe(e,t["max-width"],i),h=dt(e,t["padding-right"],i),u=Bt(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,r,o),m=Y(e,r,h);if(n&&p&&a){let v=pe(e,i,Y(e,a,Y(e,Y(e,n,f),m)));s?d?p=pe(e,v,d):d=pe(e,v,Y(e,p,s)):(v=pe(e,v,p),d?s=pe(e,v,d):(s=us(e,v,new He(e,.5)),d=s))}else{s||(s=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,s,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=dt(e,g,i);t.left=new U(n),t["margin-left"]=new U(s),t["border-left-width"]=new U(r),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,s=fe(e,t.top,n),r=fe(e,t["margin-top"],i),o=Bt(e,t["border-top-width"],t["border-top-style"],i),a=dt(e,t["padding-top"],i),l=fe(e,t.height,n),h=fe(e,t["max-height"],n),u=dt(e,t["padding-bottom"],i),d=Bt(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(s&&f&&l){let y=pe(e,n,Y(e,l,Y(e,Y(e,s,m),g)));r?p?f=pe(e,y,r):p=pe(e,y,Y(e,f,r)):(y=pe(e,y,f),p?r=pe(e,y,p):(r=us(e,y,new He(e,.5)),p=r))}else{r||(r=e.zero),p||(p=e.zero),!s&&!f&&!l&&(s=e.zero),!s&&!l?(l=this.autoHeight,this.isAutoHeight=!0):!s&&!f?s=e.zero:!l&&!f&&(l=this.autoHeight,this.isAutoHeight=!0);let y=pe(e,n,Y(e,Y(e,r,m),Y(e,p,g)));this.isAutoHeight&&(h||(h=pe(e,y,s||f)),this.vertical&&(fe(e,t["column-width"],null)||fe(e,t["column-count"],null))&&(l=h,this.isAutoHeight=!1)),s?l?f||(f=pe(e,y,Y(e,s,l))):l=pe(e,y,Y(e,f,s)):s=pe(e,y,Y(e,f,l))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),v=dt(e,w,i);t.top=new U(s),t["margin-top"]=new U(r),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),s=fe(e,t["column-count"],null),r=Zb(e,t["column-gap"],null);r||(r=new Vn(e,1,"em")),n&&!s&&(s=new wn(e,"floor",[Hr(e,Y(e,i,r),Y(e,n,r))]),s=new wn(e,"max",[e.one,s])),s||(s=e.one),n=pe(e,Hr(e,Y(e,i,r),s),r),t["column-width"]=new U(n),t["column-count"]=new U(s),t["column-gap"]=new U(r)}depends(e,t,i){return this.style[e].toExpr(this.pageBox.scope,null).depend(t,i)}init(e){var t;e.registerInstance(this.pageBox.key,this);let i=this.pageBox.scope,n=this.style,s=this.parentInstance?this.parentInstance.getActiveRegions(e):null,r=xc(this.cascaded,e,s,!1,null);this.vertical=yc(r,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=vc(r,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=r["box-sizing"])==null?void 0:t.value)===b.border_box;let o=!!(e instanceof La&&e.currentLayoutPosition&&new ze(i,"left-page").evaluate(e));Cc(r,n,this.vertical,this.rtl,o,(a,l)=>l.value),this.autoWidth=new Me(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new Me(i,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(e,t){var i,n;let s=this.style[t];return!s&&xn(t)&&this.pageMasterInstance instanceof $i&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?s=new A(e.rootFontSize,"px"):s=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),s&&(s=Ds(e,s,t)),s}getPropAsNumber(e,t){var i,n;let s=this.style[t];if(s){let r=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();s=Ds(e,s,t,r)}return Je(s,e)}getSpecial(e,t){let i=ac(this.cascaded,t);if(i){let n=[];for(let s=0;s<i.length;s++){let r=i[s].evaluate(e,"");r&&r!==j&&n.push(r)}if(n.length)return n}return null}getActiveRegions(e){let t=this.getSpecial(e,"region-id");if(t){let i=[];for(let n=0;n<t.length;n++)i[n]=t[n].toString();return i}return null}propagateProperty(e,t,i,n){this.propagatePropertyToElement(e,t.element,i,n)}propagatePropertyToElement(e,t,i,n){let s=this.getProp(e,i);s&&(s.isNumeric()&&zh(s.unit)&&(s=iu(s,e)),i==="font-family"&&(s=n.filterFontFamily(s)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),T(t,i,s.toString()))}propagateDelayedProperty(e,t,i,n){let s=this.getProp(e,i);s&&n.push(new oa(t.element,i,s))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),s=this.getPropAsNumber(e,"padding-left"),r=this.getPropAsNumber(e,"border-left-width"),o=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,o),T(t.element,"margin-left",`${n}px`),T(t.element,"padding-left",`${s}px`),T(t.element,"border-left-width",`${r}px`),t.marginLeft=n,t.borderLeft=r,t.paddingLeft=s}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),s=this.getPropAsNumber(e,"margin-right"),r=this.getPropAsNumber(e,"padding-right"),o=this.getPropAsNumber(e,"border-right-width");if(T(t.element,"margin-right",`${s}px`),T(t.element,"padding-right",`${r}px`),T(t.element,"border-right-width",`${o}px`),t.marginRight=s,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,r+=t.snapOffsetX)}t.paddingRight=r,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),s=this.getPropAsNumber(e,"margin-top"),r=this.getPropAsNumber(e,"padding-top"),o=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=s,t.borderTop=o,t.snapHeight=i,!this.vertical&&i>0){let a=n+t.getInsetTop(),l=a-Math.floor(a/i)*i;l>0&&(t.snapOffsetY=i-l,r+=t.snapOffsetY)}t.paddingTop=r,T(t.element,"top",`${n}px`),T(t.element,"margin-top",`${s}px`),T(t.element,"padding-top",`${r}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"),s=this.getPropAsNumber(e,"border-bottom-width"),r=this.getPropAsNumber(e,"height")-t.snapOffsetY;T(t.element,"height",`${r}px`),T(t.element,"margin-bottom",`${i}px`),T(t.element,"padding-bottom",`${n}px`),T(t.element,"border-bottom-width",`${s}px`),t.height=r-t.snapOffsetY,t.marginBottom=i,t.borderBottom=s,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){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,s){(!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 r=0;r<Jl.length;r++)this.propagateProperty(e,t,Jl[r],n)}transferContentProps(e,t,i,n){for(let s=0;s<eh.length;s++)this.propagateProperty(e,t,eh[s],n);if(this.style["text-overflow"]){let s=t.element.firstElementChild;T(s,"text-overflow","inherit"),T(s,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var r,o;let a=(o=(r=this.cascaded.width)!=null?r:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:o.value;return!!a&&a!==b.auto&&!J(a)},s=()=>{var r,o;let a=(o=(r=this.cascaded.height)!=null?r:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:o.value;return!!a&&a!==b.auto&&!J(a)};for(let r=0;r<th.length;r++){let o=th[r];if(o==="width"||o==="height"){if(o==="width"&&!n()||o==="height"&&!s())continue;T(t,o,"100%");continue}this.propagatePropertyToElement(e,t,o,i)}}finishContainer(e,t,i,n,s,r,o){this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let a=(this.vertical||!n)&&this.isAutoHeight,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&&Zu(n);u&&Ku(n),h=r.getElementClientRect(n?n.element:t.element),u&&la(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)),s>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<s;w++){let v=this.vertical?(m+f)*w/s-f/2+t.paddingTop-u/2:(m+f)*w/s-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<Ql.length;u++)this.propagateProperty(e,t,Ql[u],o);for(let u=0;u<ih.length;u++)this.propagateDelayedProperty(e,t,ih[u],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let r in n)this instanceof $i&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(r==="writing-mode"||r==="direction")||Ui(r)&&bi(i,r,_e(n,r));if(this.pageBox.pseudoName==Pa)for(let r in t)(r.match(/^background-/)||r=="writing-mode")&&(i[r]=t[r]);if(this.pageBox.pseudoName=="layout-host")for(let r in t)!r.match(/^background-/)&&r!="writing-mode"&&(i[r]=t[r]);e.pushRule(this.pageBox.classes,null,i);let s=i.content;s&&(i.content=s.filterValue(new wo(e,null,e.counterResolver))),this.init(e.context);for(let r of this.pageBox.children)r.createInstance(this).applyCascadeAndInit(e,t);e.popRule()}resolveAutoSizing(e){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,e)||this.depends("margin-right",this.autoWidth,e)||this.depends("border-right-width",this.autoWidth,e)||this.depends("padding-right",this.autoWidth,e)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,e)||this.depends("margin-top",this.autoHeight,e)||this.depends("border-top-width",this.autoHeight,e)||this.depends("padding-top",this.autoHeight,e));for(let t of this.children)t.resolveAutoSizing(e)}},Jl=["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"],Ql=["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"],eh=["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"],th=["width","height","image-resolution","object-fit","object-position"],ih=["transform","transform-origin"],Pa="background-host",Jb=class extends or{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)}},Ta=class extends or{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=Ct(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},Qb=class extends or{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},Yi=class extends or{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof ae&&(n=[t]),t instanceof qe&&(n=t.values),n){let s=this.pageBox.scope;for(let r=0;r<n.length;r++)if(n[r]instanceof ae){let o=zr(n[r].name,"enabled"),a=new ze(s,o);i&&(a=new ti(s,a)),e=Ct(s,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=bd(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let s=Kb(t,i["flow-from"],"body"),r=new wn(t,"has-content",[s]);e=Ct(t,e,r)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let s=this.pageMasterInstance.style.enabled,r=s?s.toExpr(t,null):t._true;r=Ct(t,r,e),this.pageMasterInstance.style.enabled=new U(r)}return e}prepareContainer(e,t,i,n,s){var r;this.pageBox.pageMaster instanceof Cd||(T(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(r=this.pageBox.name)!=null?r:"")),super.prepareContainer(e,t,i,n,s)}},Ia=class extends Wn{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 M(t,i?Cu:ku)}},yd=class extends Ia{constructor(e,t,i,n){super(e,t,i,n)}},ey=class vd extends Ia{constructor(t,i,n,s){super(t,i,n,s),n.specified.width=new M(tl,0),n.specified.height=new M(tl,0)}startPartitionRule(t,i,n){let s=new Kn(this.scope,t,i,n,this.target),r=new yd(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(t,i,n){let s=new gd(this.scope,t,i,n,this.target),r=new vd(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}},ty=class extends Ia{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new Kn(this.scope,e,t,i,this.target),s=new yd(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(e,t,i){let n=new gd(this.scope,e,t,i,this.target),s=new ey(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}};function xd(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,s=(i=e.direction)==null?void 0:i.value;return n===b.vertical_lr||n!==b.vertical_rl&&s!==b.rtl?"ltr":"rtl"}var iy={a10:{width:new A(26,"mm"),height:new A(37,"mm")},a9:{width:new A(37,"mm"),height:new A(52,"mm")},a8:{width:new A(52,"mm"),height:new A(74,"mm")},a7:{width:new A(74,"mm"),height:new A(105,"mm")},a6:{width:new A(105,"mm"),height:new A(148,"mm")},a5:{width:new A(148,"mm"),height:new A(210,"mm")},a4:{width:new A(210,"mm"),height:new A(297,"mm")},a3:{width:new A(297,"mm"),height:new A(420,"mm")},a2:{width:new A(420,"mm"),height:new A(594,"mm")},a1:{width:new A(594,"mm"),height:new A(841,"mm")},a0:{width:new A(841,"mm"),height:new A(1189,"mm")},b10:{width:new A(31,"mm"),height:new A(44,"mm")},b9:{width:new A(44,"mm"),height:new A(62,"mm")},b8:{width:new A(62,"mm"),height:new A(88,"mm")},b7:{width:new A(88,"mm"),height:new A(125,"mm")},b6:{width:new A(125,"mm"),height:new A(176,"mm")},b5:{width:new A(176,"mm"),height:new A(250,"mm")},b4:{width:new A(250,"mm"),height:new A(353,"mm")},b3:{width:new A(353,"mm"),height:new A(500,"mm")},b2:{width:new A(500,"mm"),height:new A(707,"mm")},b1:{width:new A(707,"mm"),height:new A(1e3,"mm")},b0:{width:new A(1e3,"mm"),height:new A(1414,"mm")},c10:{width:new A(28,"mm"),height:new A(40,"mm")},c9:{width:new A(40,"mm"),height:new A(57,"mm")},c8:{width:new A(57,"mm"),height:new A(81,"mm")},c7:{width:new A(81,"mm"),height:new A(114,"mm")},c6:{width:new A(114,"mm"),height:new A(162,"mm")},c5:{width:new A(162,"mm"),height:new A(229,"mm")},c4:{width:new A(229,"mm"),height:new A(324,"mm")},c3:{width:new A(324,"mm"),height:new A(458,"mm")},c2:{width:new A(458,"mm"),height:new A(648,"mm")},c1:{width:new A(648,"mm"),height:new A(917,"mm")},c0:{width:new A(917,"mm"),height:new A(1297,"mm")},"jis-b10":{width:new A(32,"mm"),height:new A(45,"mm")},"jis-b9":{width:new A(45,"mm"),height:new A(64,"mm")},"jis-b8":{width:new A(64,"mm"),height:new A(91,"mm")},"jis-b7":{width:new A(91,"mm"),height:new A(128,"mm")},"jis-b6":{width:new A(128,"mm"),height:new A(182,"mm")},"jis-b5":{width:new A(182,"mm"),height:new A(257,"mm")},"jis-b4":{width:new A(257,"mm"),height:new A(364,"mm")},"jis-b3":{width:new A(364,"mm"),height:new A(515,"mm")},"jis-b2":{width:new A(515,"mm"),height:new A(728,"mm")},"jis-b1":{width:new A(728,"mm"),height:new A(1030,"mm")},"jis-b0":{width:new A(1030,"mm"),height:new A(1456,"mm")},letter:{width:new A(8.5,"in"),height:new A(11,"in")},legal:{width:new A(8.5,"in"),height:new A(14,"in")},ledger:{width:new A(11,"in"),height:new A(17,"in")}},ny=new A(.24,"pt"),E0=new A(3,"mm"),sy=new A(10,"mm"),ry=new A(13,"mm");function js(e){let t={width:Un,height:Hn,bleed:ke,bleedOffset:ke,cropOffset:ke},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&&iy[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,s=e.bleed,r=n&&!J(n.value)?n.value:b.none,o=s&&!J(s.value)?s.value:b.auto;if(o===b.auto){if(r!==b.none){let h=!1;r.isSpaceList()?h=r.values.some(u=>u===b.crop):h=r===b.crop,h&&(t.bleed=new A(6,"pt"))}}else o.isNumeric()&&(t.bleed=o);let a=e["crop-offset"],l=a&&!J(a.value)?a.value:b.auto;return l===b.auto?r!==b.none&&(t.bleedOffset=ry):l.isNumeric()&&(t.cropOffset=l),t}function nh(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),s=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),r=n+s,o=e.width;o===Un?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-r*2:i.pageWidth=o.num*t.queryUnitSize(o.unit,!1);let a=e.height;return a===Hn?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-r*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=s,i.cropOffset=r,i}function Sd(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 Nn(e,t,i,n){n=n||"polyline";let s=e.createElementNS("http://www.w3.org/2000/svg",n);return s.setAttribute("stroke",i===b.auto?"#010101":i.toString()),s.setAttribute("stroke-width",t),s.setAttribute("fill","none"),s}var zo=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(zo||{});function oy(e,t,i,n,s,r,o){let a=s;a<=r+2*Tt.mm&&(a=r+s/2);let l=Math.max(s,a),h=r+l+i/2,u=Sd(e,h,h),d=[[0,r+s],[s,r+s],[s,r+s-a]],p=d.map(g=>[g[1],g[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(g=>[r+l-g[0],g[1]]),p=p.map(g=>[r+l-g[0],g[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(g=>[g[0],r+l-g[1]]),p=p.map(g=>[g[0],r+l-g[1]]));let f=Nn(e,i,n);f.setAttribute("points",d.map(g=>g.join(",")).join(" ")),u.appendChild(f);let m=Nn(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 _n=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(_n||{});function ay(e,t,i,n,s,r){let o=s*2,a,l;t==="top"||t==="bottom"?(a=o,l=s):(a=s,l=o);let h=Sd(e,a,l),u=Nn(e,i,n);u.setAttribute("points",`0,${l/2} ${a},${l/2}`),h.appendChild(u);let d=Nn(e,i,n);d.setAttribute("points",`${a/2},0 ${a/2},${l}`),h.appendChild(d);let p=Nn(e,i,n,"circle");p.setAttribute("cx",a/2),p.setAttribute("cy",l/2),p.setAttribute("r",s/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(_n).forEach(m=>{let g=_n[m];g===t?h.style[g]=`${r}px`:g!==f&&(h.style[g]="0",h.style[`margin-${g}`]="auto")}),h}function ly(e,t,i,n){let s=!1,r=!1,o=e.marks;if(o){let g=o.value;g instanceof Q?g.values.forEach(w=>{w===b.crop?s=!0:w===b.cross&&(r=!0)}):g===b.crop?s=!0:g===b.cross&&(r=!0)}let a=t.bleed;if(!s&&!r)return;let l=i.container,h=l.ownerDocument,u=Je(ny,n),d=Math.max(0,t.bleedOffset-Je(sy,n)),p=t.bleedOffset-d,f=e["crop-marks-line-color"],m=f&&!J(f.value)?f.value:b.auto;s&&Object.keys(zo).forEach(g=>{let w=zo[g],v=oy(h,w,u,m,p,a,d);l.appendChild(v)}),r&&Object.keys(_n).forEach(g=>{let w=_n[g],v=ay(h,w,u,m,p,d);l.appendChild(v)})}var Do=(()=>{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})(),Aa={"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"}},hy=(()=>{let e=Aa;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),Ra="vivliostyle-page-rule-master",Mn="_marginBoxes",Cd=class extends pd{constructor(e,t,i){super(e,null,Ra,[],t,null,0),c(this,"pageMarginBoxes",{});let n=js(i),s=new uy(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[Mn];t&&hy.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new dy(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new M(b.relative,0),this.specified.width=new M(t.width,0),this.specified.height=new M(t.height,0);for(let i in e)!Do[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new $i(e,this)}},uy=class extends Kn{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let s=new cy(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new M(b.auto,0),this.specified["z-index"]=new M(new Re(0),0),this.specified.position=new M(b.absolute,0),this.specified.overflow=new M(b.visible,0);for(let t in Do)Do.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new fy(e,this)}},cy=class extends Kn{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new M(F("body"),0)}createInstance(e){return new kd(e,this)}},dy=class extends Kn{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[Mn][this.marginBoxName];for(let i in e){let n=e[i],s=t[i];(ic[i]||s&&s.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!==j&&n.value!==b.inherit&&n.value!==b.unset&&n.value!==b.revert&&(this.specified[i]=n)}}createInstance(e){return new Ed(e,this)}},$i=class extends Ta{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=ke,e["margin-left"]=ke,e["border-left-width"]=ke,e["padding-left"]=ke,e["padding-right"]=ke,e["border-right-width"]=ke,e["margin-right"]=ke,e.right=ke}initVertical(){let e=this.style;e.top=ke,e["margin-top"]=ke,e["border-top-width"]=ke,e["padding-top"]=ke,e["padding-bottom"]=ke,e["border-bottom-width"]=ke,e["margin-bottom"]=ke,e.bottom=ke}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,s={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},r={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,r,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,s){let r="start",o="center",a="end",l=this.pageBox.scope,h={},u={},d={};for(let C in e){let E=Aa[C];if(E){let I=e[C],V=this.pageMarginBoxInstances[C],D=new Ns(I,V.style,t,l,s);h[E.positionAlongVariableDimension]=I,u[E.positionAlongVariableDimension]=V,d[E.positionAlongVariableDimension]=D}}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,I=fe(l,u[E].style[t?"max-width":"max-height"],i.extent);if(I){let V=I.evaluate(n);if(f[E]>V){let D=d[E]=new sh(h[E],u[E].style,t,l,s,V);g[E]=D.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),m=!1,[r,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,I=fe(l,u[E].style[t?"min-width":"min-height"],i.extent);if(I){let V=I.evaluate(n);if(f[E]<V){let D=d[E]=new sh(h[E],u[E].style,t,l,s,V);w[E]=D.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),[r,o,a].forEach(C=>{f[C]=w[C]||f[C]}));let v=p.start+p.extent,y=p.start+(p.start+p.extent);[r,o,a].forEach(C=>{let E=f[C];if(E!=null){let I=h[C],V=0;switch(C){case r:V=t?I.left:I.top;break;case o:V=(y-E)/2;break;case a:V=v-E;break}t?I.setHorizontalPosition(V,E-I.getInsetLeft()-I.getInsetRight()):I.setVerticalPosition(V,E-I.getInsetTop()-I.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,s=e.center,r=e.end,o={};if(s){let a=[n,r],l=new py(a),h=this.distributeAutoMarginBoxSizes(s,l,t);h.xSize!=null&&(o.center=h.xSize);let u=(i=h.xSize)!=null?i:s.getOuterSize(),d=Math.max((t-u)/2,0);n&&(o.start=n.hasAutoSize()?d:n.getOuterSize()),r&&(o.end=r.hasAutoSize()?d:r.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,r,t);a.xSize!=null&&(o.start=a.xSize),a.ySize!=null&&(o.end=a.ySize)}return o}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e instanceof Ns&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof Ns&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let s=e.getOuterMaxContentSize(),r=t.getOuterMaxContentSize();if(s>0&&r>0){let o=s+r;if(o<i)n.xSize=i*s/o;else{let a=e.getOuterMinContentSize(),l=t.getOuterMinContentSize(),h=a+l;h<i?n.xSize=a+(i-h)*(s-a)/(o-h):h>0&&(n.xSize=i*a/h)}n.xSize>0&&(n.ySize=i-n.xSize)}else s>0?n.xSize=i:r>0&&(n.ySize=i)}else e.hasAutoSize()?n.xSize=Math.max(i-t.getOuterSize(),0):t.hasAutoSize()&&(n.ySize=Math.max(i-e.getOuterSize(),0));else e?e.hasAutoSize()&&(n.xSize=i):t&&t.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,s)}},Ns=class{constructor(e,t,i,n,s){this.container=e,this.isHorizontal=i,this.clientLayout=s,c(this,"hasAutoSize_"),c(this,"size",null),c(this,"minMaxFitContent",null);let r=t[i?"width":"height"];if(this.hasAutoSize_=!r||r===b.auto||J(r),this.minMaxFitContent=r instanceof ae&&(r.name==="min-content"||r.name==="max-content"||r.name==="fit-content")?r.name:null,this.minMaxFitContent){let o=this.getSize();if(this.isHorizontal){let a=o[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,a)}else{let a=o[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,a)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let e=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=ra(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()}},py=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}},sh=class extends Ns{constructor(e,t,i,n,s,r){super(e,t,i,n,s),c(this,"fixedSize"),this.fixedSize=r}hasAutoSize(){return!1}getOuterMaxContentSize(){return this.getOuterSize()}getOuterMinContentSize(){return this.getOuterSize()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.fixedSize+this.container.getInsetRight():this.container.getInsetTop()+this.fixedSize+this.container.getInsetBottom()}},fy=class extends Yi{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,s=e.start,r=e.end,o=e.extent,a=i[o].toExpr(n,null),l=fe(n,t[o],a),h=fe(n,t[`margin-${s}`],a),u=fe(n,t[`margin-${r}`],a),d=dt(n,t[`padding-${s}`],a),p=dt(n,t[`padding-${r}`],a),f=Bt(n,t[`border-${s}-width`],t[`border-${s}-style`],a),m=Bt(n,t[`border-${r}-width`],t[`border-${r}-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=us(n,w,new He(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[s]=new U(h),t[r]=new U(u),t[`margin-${s}`]=ke,t[`margin-${r}`]=ke,t[`border-${s}-width`]=new U(f),t[`border-${r}-width`]=new U(m),t[`padding-${s}`]=new U(d),t[`padding-${r}`]=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,s){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,s)}},kd=class extends Yi{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 Ai(i,t.left.toExpr(i,null))),e["margin-right"]=new U(new Ai(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 Ai(i,t.top.toExpr(i,null))),e["margin-bottom"]=new U(new Ai(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,s){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,s),e.pageAreaWidth=t.width,e.pageAreaHeight=t.height}},Ed=class extends Yi{constructor(e,t){super(e,t),c(this,"boxInfo"),c(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=Aa[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,s)}applyVerticalAlign(e,t){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 s=this.getProp(e,"content");if(this.vertical||s instanceof Ke||s instanceof U&&s.expr instanceof Me&&s.expr.str.startsWith("running-element-")){let r="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?r=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(r=this.vertical||this.rtl?"end":"start")),T(t,"align-items",r)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,s=e.start,r=e.end,o=e.extent,a=s==="left",l=a?t.borderBoxWidth:t.borderBoxHeight,h=fe(n,i[o],l),u=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[s]=new U(u);else if(h){let d=dt(n,i[`margin-${s}`],l),p=dt(n,i[`margin-${r}`],l),f=dt(n,i[`padding-${s}`],l),m=dt(n,i[`padding-${r}`],l),g=Bt(n,i[`border-${s}-width`],i[`border-${s}-style`],l),w=Bt(n,i[`border-${r}-width`],i[`border-${r}-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[s]=new U(Y(n,u,Hr(n,pe(n,l,v),new He(n,2))));break;case"end":i[s]=new U(pe(n,Y(n,u,l),v));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,s=this.borderBoxSizing,r=e.inside,o=e.outside,a=e.extent,l=t[`margin${o.charAt(0).toUpperCase()}${o.substring(1)}`],h=Zl(n,i[`margin-${r}`],l),u=Zl(n,i[`margin-${o}`],l),d=dt(n,i[`padding-${r}`],l),p=dt(n,i[`padding-${o}`],l),f=Bt(n,i[`border-${r}-width`],i[`border-${r}-style`],l),m=Bt(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 s||[f,d,p,m].forEach(I=>{I&&(E+=I.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 Me(n,function(){let y=v(this).extent;return y===null?"auto":y},a)),i[`margin-${r}`]=new U(new Me(n,function(){let y=v(this).marginInside;return y===null?"auto":y},`margin-${r}`)),i[`margin-${o}`]=new U(new Me(n,function(){let y=v(this).marginOutside;return y===null?"auto":y},`margin-${o}`)),r==="left"?i.left=new U(Y(n,t.marginLeft,t.borderBoxWidth)):r==="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,s,r,o){super.finishContainer(e,t,i,n,s,r,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 ae&&(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 I=u.borderBoxWidth.evaluate(e)+u.marginRight.evaluate(e);T(t.element,"right",`${I}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 ae&&(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 I=u.borderBoxHeight.evaluate(e)+u.marginBottom.evaluate(e);T(t.element,"bottom",`${I}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"))}}},gy=class{constructor(e,t,i,n,s){this.cascadeInstance=e,this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=s,c(this,"pageMasterCache",{}),this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new ze(e,"page-number"),s=new Jo(e,new Gh(e,n,new He(e,2)),i?e.one:e.zero);e.defineName("recto-page",new ti(e,s)),e.defineName("verso-page",s),(t.pageProgression||xd(this.docElementStyle))==="ltr"?(e.defineName("left-page",s),e.defineName("right-page",new ti(e,s))):(e.defineName("left-page",new ti(e,s)),e.defineName("right-page",s))}getCascadedPageStyle(e){let t={};return this.cascadeInstance.pushRule([],e,t),this.cascadeInstance.popRule(),t}getPageRulePageMaster(e,t){let i=e.pageBox;if(Object.keys(t).length===0)return i.resetScope(),e;let n=this.makeCacheKey(t,i),s=this.pageMasterCache[n];return s||(i.pseudoName===Pa?s=this.generatePageRuleMaster(t):s=this.generateCascadedPageMaster(t,i),this.pageMasterCache[n]=s),s.pageBox.resetScope(),s}makeCacheKey(e,t){var i;let n=this.makeCascadeValueObjectKey(e),s=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${t.key}^${n}^${s}`}makeCascadeValueObjectKey(e){let t=[];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],s;n instanceof M?s=`${n.value}`:s=this.makeCascadeValueObjectKey(n),t.push(i+s+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new Cd(this.pageScope,this.rootPageBoxInstance.pageBox,e).createInstance(this.rootPageBoxInstance);return t.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),t.resolveAutoSizing(this.context),t}generateCascadedPageMaster(e,t){let i=t.clone({pseudoName:Ra}),n=i.specified,s=e.size;if(s&&!J(s.value)){let o=js(e),a=s.priority;Gt(n,"width",new M(o.width,a),this.context),Gt(n,"height",new M(o.height,a),this.context)}["counter-reset","counter-increment"].forEach(o=>{n[o]&&(e[o]=n[o])});let r=i.createInstance(this.rootPageBoxInstance);return r.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),r.resolveAutoSizing(this.context),r}},my=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}},wy=class extends ve{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},by=class extends ve{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},yy=class extends ve{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},vy=class extends ve{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},xy=class extends ve{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Sy=class extends ve{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Cy=class extends qn{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}},ky=class extends ma{constructor(e,t){super(e,t,null,null,null)}apply(e){Ey(e.context,e.currentStyle,this.style,this.specificity,e)}};function Ey(e,t,i,n,s){zs(e,t,i,n,null,null,null);let r=i[Mn];if(r){let o=Xn(t,Mn);for(let a in r)if(r.hasOwnProperty(a)){let l=o[a];l||(l={},o[a]=l),zs(e,l,r[a],n,null,null,null)}}}var Ny=class extends Rn{constructor(e,t,i,n,s){super(e,t,i?.condition,i,null,n,!1),this.pageProps=s,c(this,"currentPageSelectors",[]),c(this,"currentNamedPageSelector",""),c(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new my(t)),this.specificity+=65536)}pseudoclassSelector(e,t){if(e=e.toLowerCase(),t)switch(e){case"nth":{let[i,n]=t;this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new Cy(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 wy(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new by(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new yy(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new vy(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new xy(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Sy(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}`);break}}finishSelector(){let e;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?e=null:e=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:e,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(e,t,i){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(r=>r.selectors===null))return;super.simpleProperty(e,t,i);let n=_e(this.elementStyle,e),s=this.pageProps;if(e==="bleed"||e==="marks")s[""]||(s[""]={}),Object.keys(s).forEach(r=>{bi(s[r],e,n)});else if(e==="size"){let r=s[""];this.currentPageSelectors.forEach(o=>{let a=new M(n.value,n.priority+o.specificity),l=o.selectors?o.selectors.join(""):"",h=s[l];h?Gt(h,e,a):(h=s[l]={},bi(h,e,a),r&&["bleed","marks"].forEach(u=>{r[u]&&bi(h,u,r[u])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new ky(this.elementStyle,e)}startPageMarginBoxRule(e){let t=Xn(this.elementStyle,Mn),i=t[e];i||(i={},t[e]=i);let n=new Py(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},Py=class extends Wn{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.boxStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),s=new M(t,n);bi(this.boxStyle,e,s)}},jt=!0;function Ty(e){jt=e}var yi=[];function rh(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Nd(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 Fa(e,t,i){if(!jt||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Nd(e.ownerDocument).includes(e))return N(!1);let n=e.textContent,s=e.src,r=e.type==="module",o=s&&s.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=(r||s)&&e.async&&!o,l=(r&&!a||s&&e.defer)&&!o,h=!(i!=null&&i.atEnd)&&(i?.forceDefer||l||a);if(Pd(t)||(t.onload=null),h)return yi.some(d=>rh(d,e))||yi.push(e),N(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&rh(d,e)&&t.document.head.removeChild(d);let u=t.document.createElement("script");u.textContent=n,s&&(u.src=s),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(H.debug("script:",s),s){let d=Ei(u);return t.document.head.appendChild(u),Qs([d])}else return t.document.head.appendChild(u),N(!0)}function Iy(e,t){var i;let n={},s=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))s(u)},r=o=>{if(o instanceof ma)s(o.style);else if(o instanceof tn||Array.isArray(o))for(let a of Object.values(o))r(a)};for(let o of Object.values(t.cascade.code))for(let a of Object.values(o??{}))r(a);for(let o of e.querySelectorAll("[style]"))(i=o.style)!=null&&i.fontFamily&&(n[o.style.fontFamily]=!0);return Object.keys(n).join(",")}function Ay(e,t,i){var n;let s=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return s.style.position="fixed",s.style.fontSize="0",s.setAttribute("data-vivliostyle-textcontent","true"),s.setAttribute("aria-hidden","true"),s.style.fontFamily=Iy(e,i),s.textContent=e.documentElement.textContent,t.document.body.appendChild(s),s}function Ry(e,t,i){if(!jt)return N(!1);let n=Nd(e);if(n.length===0)return N(!1);let s=n.some(u=>!(u.async||u.defer||u.type==="module")),r=s?Ay(e,t,i):null,o=t.document.fonts,a=t.$,l=!1,h=B("loadScripts");return h.loop(()=>{if(n.length===0)return s?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 Fa(u,t,{inHead:!0,forceDefer:l}).thenAsync(()=>(!l&&t.$!==a&&(yi.push(u),l=!0),n.length===0&&s&&(H.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),N(!0)))}).then(()=>{r&&r.remove(),h.finish(!0)}),h.result()}function Fy(e){if(!jt)return N(!1);let t=B("loadScripts");return t.loop(()=>yi.length===0?N(!1):Fa(yi.shift(),e,{atEnd:!0}).thenReturn(yi.length>0)).then(()=>{H.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),H.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Pd(e){return jt?yi.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var Ly=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,s)=>`url("${i.transformURL(s,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,s)=>`url('${i.transformURL(s,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,s)=>`url(${i.transformURL(s,t)}`),By={};function Oy(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 Td=class Vo extends qo{constructor(t,i,n,s,r,o,a,l,h,u,d,p,f){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=s,this.regionIds=r,this.xmldoc=o,this.docFaces=a,this.footnoteStyle=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=s.counterListener.getExprContentListener()}clone(){return new Vo(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer)}createPseudoelementShadow(t,i,n,s,r,o,a,l){var h;let u=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(!u)return l;let d=[],p=ds.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=p;for(let g of Zm){let w;if(g){if(!u[g]||g=="footnote-marker"&&!(i&&this.isFootnote))continue;if(g.match(/^first-/)){let v=s.display;if(!v||v===b.inline)continue;let y=t.firstElementChild;if(y&&Ue(y.previousSibling)){let C=r.getStyle(y,!1);if(C){let E=_e(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||!Ot(v.value)||g==="marker"&&(!mi(s.display)||((h=_e(n,"behavior"))==null?void 0:h.value)===F("toc-node")))continue}d.push(g),w=ds.createElementNS("http://www.w3.org/1999/xhtml","span"),vo(w,g)}else w=ds.createElementNS("http://www.pyroxy.com/ns/shadow","content");f.appendChild(w),g.match(/^first-/)&&(f=w)}if(!d.length)return l;let m=new Ol(t,n,r,o,this.exprContentListener);return new Jr(t,p,null,a,l,vt.ROOTLESS,m)}getPseudoMap(t,i,n,s,r){let o=It(t,"_pseudos");if(!o)return null;let a={};for(let l in o){let h=a[l]={};Cn(h,o[l],r),yo(h,r,o[l]),Sc(o[l],i,n,(u,d)=>{Cn(h,d,r),bc(d,p=>{Cn(h,p,r)})})}return a}createRefShadow(t,i,n,s,r){let o=B("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);r=new Jr(n,h,l,s,r,i,u)}}o.finish(r)}),o.result()}createShadows(t,i,n,s,r,o,a){let l=B("createShadows"),h=null,u=s.template,d;if(u instanceof Ke||u===b.footnote){let p=u instanceof Ke?u.url:Ne("user-agent.xml#footnote",Qt);d=this.createRefShadow(p,vt.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=Ne(g,w.url),f=this.createRefShadow(g,vt.ROOTED,t,a,p))}f==null&&(f=N(p));let m=null;f.then(g=>{if(s.display===b.table_cell){let w=Ne("user-agent.xml#table-cell",Qt);m=this.createRefShadow(w,vt.ROOTLESS,t,a,g)}else m=N(g);m.then(w=>{w=this.createPseudoelementShadow(t,i,n,s,r,o,a,w),l.finish(w)})})}),l.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,s){var r;let o=this.context,a=xc(n,o,this.regionIds,this.isFootnote,this.nodeContext),l=!((r=this.nodeContext)!=null&&r.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=yc(a,o,t);let u=!l&&t!==h;i=vc(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 ze(o.style.pageScope,"left-page").evaluate(o);if(Cc(a,s,t,i,p,d),u){let v=s[t?"height":"width"];(!v||v===b.auto)&&(s[t?"height":"width"]=b.max_content)}if(to(s.position))return s.position=b.fixed,s.visibility=b.hidden,t;let f=s.position,m=s.float,g=s.display||(this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?b.inline:void 0),w=Xu(g,f,m,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(v=>{w[v]&&(s[v]=w[v])}),t}inheritFromSourceParent(t){let i=this.nodeContext.sourceNode,n=[],s=null,r=this.nodeContext.shadowContext,o=-1;for(;i&&i.nodeType==1;){let d=r&&r.root==i;if(!d||r.type==vt.ROOTLESS){let p=(r?r.styler:this.styler).getStyle(i,!1);n.push(p),s=s||_r(i)}d?(i=r.owner,r=r.parentShadow):(i=i.parentNode,o++)}let a=o===0,l=this.context.queryUnitSize("em",a),h={"font-size":new M(new A(l,"px"),0)};a&&(h["line-height"]=new M(new Ht(this.context.pref.lineHeight),0));let u=new om(h,this.context);for(let d=n.length-1;d>=0;--d){let p=n[d],f=[];for(let w in p)xn(w)&&f.push(w);f.sort(nl);let m,g;for(let w of f){u.setPropName(w);let v=_e(p,w),y=v;if(!J(v.value)){if(w==="font-size"&&d===n.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)y=new M(new A(this.context.rootFontSize,"px"),v.priority);else if(w==="line-height"&&d===n.length-1&&this.context.rootLineHeight&&v.value instanceof A&&(v.value.unit==="lh"||v.value.unit==="rlh"))y=new M(new A(this.context.rootLineHeight,"px"),v.priority);else if(d===0&&v.value instanceof A&&v.value.unit==="lh"){let C=this.getLineHeightUnitSize(w,m,g);C!=null&&(y=new M(new A(v.value.num*C,"px"),v.priority))}else $t(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)xn(d)||(h[d]=t[d]);return{lang:s,elementStyle:h}}resolveURL(t){return t=Ne(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=_r(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=Zg().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let s in this.nodeContext.parent.inheritedProps)n[s]=this.nodeContext.parent.inheritedProps[s]}i.forEach(s=>{let r=t[s];if(r){if(J(r))r===b.initial&&(n[s]=void 0);else if(r instanceof Re)n[s]=r.num;else if(r instanceof ae)n[s]=r.name;else if(r instanceof A){let o=r;switch(o.unit){case"dpi":case"dpcm":case"dppx":n[s]=o.num*Tt[o.unit];break;default:n[s]=r}}else n[s]=r;["widows","orphans"].includes(s)||delete t[s]}})}}resolveFormattingContext(t,i,n,s,r,o){let a=At("RESOLVE_FORMATTING_CONTEXT");for(let l=0;l<a.length;l++){let h=a[l](t,i,n,s,r,o);if(h){t.formattingContext=h;return}}}createElementView(t,i){var n,s;let r=!0,o=B("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);ir.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&&!J(p.value)&&p.value!==b.none&&f&&!J(f.value)?Ig(f.value.toString()):null;if(this.nodeContext.parent&&(to(d?.value)||m&&Di(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&&Di(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(jt&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return Fa(a,this.viewport.window).thenFinish(o),o.result();let w=u.display;if(J(w)&&(w===b.initial||w===b.unset?w=b.inline:w===b.inherit?w=((n=this.nodeContext.parent)==null?void 0:n.display)&&F((s=this.nodeContext.parent)==null?void 0:s.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,I=u.clear,V=this.nodeContext.vertical?b.vertical_rl:b.horizontal_tb,D=this.nodeContext.parent?this.nodeContext.parent.vertical?b.vertical_rl:b.horizontal_tb:V,te=_g(a),re=u["column-count"],nt=u["column-width"],st=re&&re!==b.auto&&!J(re)||nt&&nt!==b.auto&&!J(nt);this.nodeContext.establishesBFC=zg(w,C,E,u.overflow,V,D,st||te),this.nodeContext.containingBlockForAbsolute=Dg(C),this.nodeContext.isInsideBFC()&&E!==b.footnote&&!(m&&Di(m))&&(E=null,I=null);let xe=E instanceof Q||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)),I&&(I===b.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(I=F(this.nodeContext.parent.clearSide)),(I===b.left||I===b.right||I===b.top||I===b.bottom||I===b.inline_start||I===b.inline_end||I===b.block_start||I===b.block_end||I===b.inside||I===b.outside||I===b.both||I===b.all||I===b.same||I===b.column||I===b.region||I===b.page)&&(delete u.clear,u.display&&u.display!=b.inline&&(this.nodeContext.clearSide=I.toString())));let x=mi(w)&&!!u["ua-list-item-count"],O=u["break-inside"];(xe||O&&!J(O)&&O!==b.auto)&&this.nodeContext.breakPenalty++,w&&w!==b.inline&&Lt(w)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!xe&&!w||Lt(w)||Yu(w),this.nodeContext.display=w?w.toString():"inline",this.nodeContext.floatSide=xe?E.toString():null,this.nodeContext.floatReference=m||Fe.INLINE;let S=u["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=S&&!J(S)?S:null;let P=this.isInsideNonRootMultiColumn(),k=u["column-span"];if(this.nodeContext.columnSpan=!P&&k&&!J(k)?k:null,!this.nodeContext.inline){let _=u["break-after"];_&&!J(_)&&!(P&&_===b.column)&&(this.nodeContext.breakAfter=_.toString(),Yr[this.nodeContext.breakAfter]&&(u["break-after"]=b.column));let ie=u["break-before"];ie&&!J(ie)&&!(P&&ie===b.column)&&(this.nodeContext.breakBefore=ie.toString(),Yr[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete u["break-before"]:u["break-before"]=b.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let ne=u.page,be=ne&&!J(ne)&&ne.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&&!An(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 _=u["border-spacing"],ie,ne;_&&(_ instanceof Q?(ie=_.values[0],ne=_.values[1]):ie=ne=_,ie.isNumeric()&&(this.nodeContext.inlineBorderSpacing=Je(ie,this.context)),ne.isNumeric()&&(this.nodeContext.blockBorderSpacing=Je(ne,this.context)))}let L=u["footnote-policy"];this.nodeContext.footnotePolicy=L&&!J(L)?L:null;let z=u["x-first-pseudo"];if(z){let _=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Eg(_,z.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,h,l,this.context);let $=u["white-space"];if($){let _=_u($.toString());_!==null&&(this.nodeContext.whitespace=_)}let q=u["hyphenate-character"];q&&q instanceof G&&(this.nodeContext.hyphenateCharacter=q.str);let K=u["word-break"],Z=u["line-break"],me=u["overflow-wrap"];(K===b.break_all||Z===b.anywhere||me===b.break_word||me===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 ee=!1,we=null,Se=[],le=a.namespaceURI,W=a.localName,ce=W;if(le=="http://www.w3.org/1999/xhtml"?(W=="html"||W=="body"||W=="script"||W=="link"||W=="meta"?W="div":W=="vide_"?W="video":W=="audi_"?W="audio":W=="object"&&(ee=!!this.customRenderer),a.hasAttribute(va)&&a.hasAttribute("src")&&u.content instanceof Ke&&(W="img")):le=="http://www.idpf.org/2007/ops"?(W="span",le="http://www.w3.org/1999/xhtml"):le=="http://www.pyroxy.com/ns/shadow"?(le="http://www.w3.org/1999/xhtml",W=this.nodeContext.inline?"span":"div"):ee=!!this.customRenderer,x)w=Lt(w)?b.inline:b.block,u.display=w,t?W="li":W="div";else if(W=="body"||W=="li")W="div";else if(W=="q")W="span";else if(W=="a"){let _=u["hyperlink-processing"];_&&_.toString()!="normal"&&(W="span")}u.behavior&&u.behavior.toString()!="none"&&this.customRenderer&&(ee=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(ee=!0);let de;if(ee){let _=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;de=this.customRenderer(a,_,u)}else de=N(null);de.then(_=>{var ie,ne,be,at,Oa;if(_)ee&&(r=_.getAttribute("data-adapt-process-children")=="true");else if(u.display===b.none){o.finish(!1);return}else _=this.createElement(le,W);!v&&st&&u["column-fill"]===b.auto&&(_.setAttribute("data-vivliostyle-column-fill","auto"),u["column-fill"]=b.balance),W!=ce&&(_.setAttribute("data-vivliostyle-original-tag",ce),(ce==="html"||ce==="body")&&(_.role="presentation")),W=="a"&&_.addEventListener("click",this.page.hrefHandler,!1),we&&(this.applyPseudoelementStyle(this.nodeContext,"inner",we),_.appendChild(we)),_.localName=="iframe"&&_.namespaceURI=="http://www.w3.org/1999/xhtml"&&Oy(_);let Zn=this.nodeContext.inheritedProps["image-resolution"],ar=[],lr=u.width,hr=u.height,Ud=a.getAttribute("width"),Hd=a.getAttribute("height"),ur=lr===b.auto||!lr&&!Ud,cr=hr===b.auto||!hr&&!Hd,_a=a.attributes,$d=_a.length,Jn=null,Ma=null;w===b.table_cell&&((be=(ne=(ie=this.nodeContext.parent)==null?void 0:ie.viewNode)==null?void 0:ne.lastElementChild)==null?void 0:be.localName)==="a"&&_.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let je=0;je<$d;je++){let pt=_a[je],lt=pt.namespaceURI,oe=pt.localName,De=pt.nodeValue;if(lt){if(lt=="http://www.w3.org/2000/xmlns/")continue;lt=="http://www.w3.org/1999/xlink"&&oe=="href"&&(De=this.documentURLTransformer.transformURL(this.resolveURL(De),this.xmldoc.url))}else{if(!jt&&oe.match(/^on/)||oe=="style")continue;if((oe=="id"||oe=="name")&&t){let Xe=this.documentURLTransformer.transformFragment(De,this.xmldoc.url);_.setAttribute(oe,De),_.setAttribute("data-vivliostyle-id",Xe);let ai=_.ownerDocument.createElement("a");ai.setAttribute(oe,Xe),ai.setAttribute(Xi,"1"),ai.style.position="absolute",_.appendChild(ai),this.page.registerElementWithId(_,Xe);continue}if(oe=="src"||oe=="href"||oe=="poster")De=this.resolveURL(De),oe==="href"&&(De=this.documentURLTransformer.transformURL(De,this.xmldoc.url));else if(oe=="srcset")De=De.split(",").map(Xe=>this.resolveURL(Xe.trim())).join(",");else if(oe==="data"&&ee&&W==="object"&&_.hasAttribute("data"))continue;if(oe==="poster"&&W==="video"&&le==="http://www.w3.org/1999/xhtml"&&ur&&cr){let Xe=new Image,ai=Ei(Xe,De);Se.push(ai),ar.push({image:Xe,element:_,fetcher:ai})}}if(le=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(oe)&&(oe=oe.toLowerCase()),this.isSVGUrlAttribute(oe)&&(De=Ly(De,this.xmldoc.url,this.documentURLTransformer)),lt){let Xe=By[lt];Xe&&(oe=`${Xe}:${oe}`)}if(oe=="src"&&!lt&&(W=="img"||W=="input")&&le=="http://www.w3.org/1999/xhtml")Jn=De;else if(oe=="alt"&&!lt&&W=="img"&&le=="http://www.w3.org/1999/xhtml")Ma=De;else if(oe=="href"&&W=="image"&&le=="http://www.w3.org/2000/svg"&<=="http://www.w3.org/1999/xlink")this.page.fetchers.push(Ei(_,De));else if(lt)_.setAttributeNS(lt,oe,De);else try{_.setAttribute(oe,De)}catch(Xe){H.warn(Xe)}}if(Jn){let je=W==="input"?new Image:_,pt=Ei(je,Jn,Ma);je!==_&&(_.src=Jn);let lt=()=>{var oe,De;if(u.position===b.fixed)return!0;for(let Xe=(oe=this.nodeContext.parent)==null?void 0:oe.viewNode;Xe&&Xe!==this.viewRoot;Xe=Xe.parentElement)if(((De=Xe.style)==null?void 0:De.position)==="fixed")return!0;return!1};!ur&&!cr&&!(()=>{let oe=this.nodeContext.vertical?lr:hr;return oe instanceof A&&oe.unit==="%"})()&&!lt()?this.page.fetchers.push(pt):(ur&&cr&&Zn&&Zn!==1&&ar.push({image:je,element:_,fetcher:pt}),Se.push(pt))}delete u.content;let dr=u["list-style-image"];if(dr&&dr instanceof Ke){let je=dr.url;Se.push(Ei(new Image,je))}if(this.preprocessElementStyle(u),this.applyComputedStyles(_,u),this.nodeContext.inline)t||(ft(_,"inline-start"),ln(_)&&ft(_,"clone"));else if(t){if(!aa(u.position)){let je=u["margin-break"],pt=this.getBreakTypeAt(this.nodeContext),lt=pt!==null,oe=pt==="auto";(je===b.discard&<||je!==b.keep&&oe&&!this.nodeContext.floatSide)&&kr(_,"block-start")}}else{let je=this.nodeContext.vertical?"width":"height";Kt(_,je)&&T(_,je,this.nodeContext.display==="table-row"?"0.01px":""),ft(_,"block-start"),ln(_)&&ft(_,"clone"),kr(_,"block-start")}if(x&&_.setAttribute("value",u["ua-list-item-count"].stringValue()),_.classList.contains("_viv-marker-outside-content")&&mi((Oa=(at=this.nodeContext.parent)==null?void 0:at.parent)==null?void 0:Oa.display)){let je=this.viewport.window.getComputedStyle(this.nodeContext.parent.parent.viewNode),pt=parseFloat(je.borderInlineStartWidth)+parseFloat(je.paddingInlineStart)+parseFloat(je.textIndent);pt&&(_.style.insetInlineEnd=`${pt}px`)}this.viewNode=_,Se.length?Qs(Se).then(()=>{Zn>0&&this.modifyElemDimensionWithImageResolution(ar,Zn,u,this.nodeContext.vertical),o.finish(r)}):o.timeSlice().then(()=>{o.finish(r)})})}),o.result()}isAtStartOfPage(){var t,i;for(let n=this.nodeContext;n!=null&&n.parent&&!n.after;n=n.parent){let s=n===this.nodeContext&&!n.viewNode?(t=n.parent.viewNode)==null?void 0:t.lastChild:(i=n.viewNode)==null?void 0:i.previousSibling;for(;s&&(Ue(s,n.parent.whitespace)||Li(s));)s=s.previousSibling;if(s)return!1}return!0}isInsideNonRootMultiColumn(){var t;let i=(t=this.nodeContext.parent)==null?void 0:t.viewNode;return!!(i&&ha(i))}getBreakTypeAt(t){var i,n,s,r,o;if(this.isInsideTable(t))return null;for(let l=t;l&&!l.after;l=l.parent){if(et(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&&(Ue(f,l.parent.whitespace)||!l.floatSide&&Li(f));)f=f.nextSibling;if(f&&f!==l.viewNode)return null}}let a=(o=(r=(s=this.context)==null?void 0:s.currentLayoutPosition)==null?void 0:r.flowPositions[this.flowName])==null?void 0:o.startBreakType;return et(a)?a:"auto"}isInsideTable(t){for(let i=t;i&&!i.after;i=i.parent)if(i.display&&i.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(t,i,n,s){let r=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,s);if(r&&r["after-if-continues"]&&r["after-if-continues"].content){let o=new Ol(t,i,n,s,this.exprContentListener);this.nodeContext.afterIfContinues=new Qm(t,o)}}isSVGUrlAttribute(t){return Vo.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,s){t.forEach(r=>{if(r.fetcher.get().get()==="load"){let o=r.image,a=o.width/i,l=o.height/i,h=r.element;if(a>0&&l>0){if(n["box-sizing"]===b.border_box&&(n["border-left-style"]!==b.none&&(a+=Je(n["border-left-width"],this.context)),n["border-right-style"]!==b.none&&(a+=Je(n["border-right-width"],this.context)),n["border-top-style"]!==b.none&&(l+=Je(n["border-top-width"],this.context)),n["border-bottom-style"]!==b.none&&(l+=Je(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,Je(p,this.context))}px`):f.unit!=="%"?T(h,"max-height",`${Math.min(l,Je(f,this.context))}px`):s?T(h,"height",`${l}px`):T(h,"width",`${a}px`)}}else if(i<1){let u=n["min-width"]||ke,d=n["min-height"]||ke;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,Je(p,this.context))}px`):f.unit!=="%"?T(h,"min-height",`${Math.max(l,Je(f,this.context))}px`):s?T(h,"height",`${l}px`):T(h,"width",`${a}px`)}}}})}preprocessElementStyle(t){At("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let s={},r=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",r,s),!this.processRepeatOnBreak(s))continue;if(this.nodeContext.formattingContext instanceof vi&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let o=this.nodeContext.parent,a=o&&o.formattingContext;this.nodeContext.formattingContext=new vi(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||J(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=B("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=ml(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=B("preprocessTextContent"),s=At("PREPROCESS_TEXT_CONTENT"),r=0;return n.loop(()=>r>=s.length?N(!1):s[r++](this.nodeContext,i).thenAsync(o=>(i=o,N(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=pg(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=B("createNodeView"),s,r=!0;return this.sourceNode.nodeType==1?s=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,s=N(!0)):s=this.createTextNodeView(),s.then(o=>{var a;if(r=o,this.nodeContext.viewNode=this.viewNode,this.viewNode){let l=(d,p)=>d?.nodeType===1&&_i(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&&Ue(this.viewNode))&&!u.hasChildNodes()&&Fu(u).includes("block-start")&&ft(u,"text-start"),u.appendChild(this.viewNode),$g(this.viewNode))}n.finish(r)}),n.result()}setCurrent(t,i,n){return this.nodeContext=t,t?(this.sourceNode=t.sourceNode,this.offsetInNode=t.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(i,!!n):N(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,s=t.parent,r,o,a=n.subShadow||n.parentShadow;n.subShadow?(r=n.root,o=n.type,o==vt.ROOTLESS&&(r=r.firstChild)):(r=n.owner.firstChild,o=vt.ROOTLESS);let l=t.sourceNode.nextSibling;if(l?(t.sourceNode=l,t.resetView()):t.shadowSibling?t=t.shadowSibling:r?t=null:(t=t.parent.modify(),t.after=!0),r){let h=new un(r,s,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!=vt.ROOTED){let n=t.sourceNode.nextSibling;if(n)return t=t.modify(),t.boxOffset=i,t.sourceNode=n,t.resetView(),this.processShadowContent(t)}return t.shadowSibling?(t=t.shadowSibling.modify(),t.boxOffset=i,t):(t=t.parent.modify(),t.boxOffset=i,t.after=!0,t)}else{if(t.nodeShadow){let s=t.nodeShadow.root;if(t.nodeShadow.type==vt.ROOTLESS&&(s=s.firstChild),s){let r=new un(s,t,i);return r.shadowContext=t.nodeShadow,r.shadowType=t.nodeShadow.type,this.processShadowContent(r)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new un(n,t,i));if(t.sourceNode.nodeType!=1){let s=ml(t.preprocessedTextContent);i+=s.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}isTransclusion(t,i,n){let s=_e(i,"hyperlink-processing");if(!s)return!1;let r=s.evaluate(this.context,"hyperlink-processing");return r?r.toString()==n:!1}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return N(n);let s=B("nextInTree");return this.setCurrent(n,!0,i).then(r=>{(!n.viewNode||!r)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),this.dispatchEvent({type:"nextInTree",nodeContext:n}),s.finish(n)}),s.result()}addImageFetchers(t){if(t instanceof qe){let i=t.values;for(let n=0;n<i.length;n++)this.addImageFetchers(i[n])}else if(t instanceof Ke){let i=t.url;this.page.fetchers.push(Ei(new Image,i))}}applyComputedStyles(t,i){var n,s,r;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&&((s=this.sourceNode)==null?void 0:s.parentElement)===null&&!!((r=this.viewRoot)!=null&&r.parentElement),h=Object.keys(i);h.sort(nl);let u,d;for(let p of h){if(My[p])continue;let f=i[p];if(!(!f||f===j&&!$t(p))){if(f=f.visit(new hf(this.xmldoc.url,this.documentURLTransformer)),f instanceof A)if(f.unit==="em"){let m=this.getEmUnitSize(p,u);m!=null&&(f=new A(f.num*m,"px"))}else if(f.unit==="lh"){let m=this.getLineHeightUnitSize(p,u,d);m!=null&&(f=new A(f.num*m,"px"))}else zh(f.unit)&&(f=iu(f,this.context));if((p==="font-size"||p==="line-height")&&(p==="font-size"?u=f:d=f,this.viewport.layoutUnitAdj&&f instanceof A&&f.unit!=="%"&&f.unit!=="em"&&f.unit!=="lh"&&(f=new ki(`calc(${f.toString()} - var(--viv-layoutUnitAdj))`))),mg[p]||a&&wg[p]){this.page.delayedItems.push(new oa(t,p,f));continue}l&&this.page.pageAreaElement&&xn(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 s,r,o,a,l,h;let u=((o=(r=(s=this.nodeContext)==null?void 0:s.parent)==null?void 0:r.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 Ht||n instanceof A&&(n.unit==="em"||n.unit==="%"))p=n instanceof A&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof A&&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 A))return null;let f=u?this.parsePlusLayoutUnitAdj(u.fontSize):this.context.rootFontSize;if(i instanceof A){let m=po(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,s,r;let o=((r=(s=(n=this.nodeContext)==null?void 0:n.parent)==null?void 0:s.viewNode)==null?void 0:r.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 A){let l=po(i,a,this.context).num;if(typeof l=="number"&&!isNaN(l))return l}return null}applyPseudoelementStyle(t,i,n){if(t.after)return;let s=this.sourceNode,r=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(s,!1),o=It(r,"_pseudos");if(!o||(r=o[i],!r))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",r,a);let l=a.content;Ot(l)&&(l.visit(new _s(n,this.context,l,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=B("peelOff"),s=t.firstPseudo,r=t.offsetInNode,o=t.after;if(i>0){let d=t.viewNode.textContent;t.viewNode.textContent=d.substr(0,i),r+=i}else if(!o&&t.viewNode&&r==0){let d=t.viewNode.parentNode;d&&d.removeChild(t.viewNode)}let a=t.boxOffset+i,l=[];for(;t.firstPseudo===s;)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 un(h.sourceNode,t,a),l.length==0&&(t.offsetInNode=r,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 s={},r=It(this.footnoteStyle,"_pseudos");if(t=this.computeStyle(t,i,this.footnoteStyle,s),r&&r.before){let o={},a=this.createElement("http://www.w3.org/1999/xhtml","span");vo(a,"before"),n.appendChild(a),this.computeStyle(t,i,r.before,o),delete o.content,this.applyComputedStyles(a,o)}return delete s.content,this.applyComputedStyles(n,s),t}processFragmentedBlockEdge(t){var i,n,s;let r=!t.inline&&t.after?t.parent:t,o=!1;if(t.inline&&t.after&&!t.shadowContext&&((i=t.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let l=t.sourceNode.nextSibling,h=(n=_e(this.styler.getStyle(l,!1),"display"))==null?void 0:n.value.toString();o=h&&!Lt(h)||l.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(l.textContent)}let a=0;for(let l=r;l;l=l.parent){if(((s=l.viewNode)==null?void 0:s.nodeType)!==1)continue;let h=l.viewNode;if(h.style)if(l.inline){if(ft(h,"inline-end"),ln(h)){let u=l.vertical?h.offsetWidth:h.offsetHeight;ft(h,"clone"),(l.vertical?h.offsetWidth:h.offsetHeight)>u&&this.fixClonedBoxDecorationOverflow(h)}}else{let u=this.nodeContext.vertical?"width":"height";if(Kt(h,u)&&T(h,u,""),ft(h,"block-end"),!a++&&l!==r){let{textAlign:d}=this.viewport.window.getComputedStyle(h);if(d==="justify"&&!o){let p=this.createChildAnonymousBlockIfNeeded(h);p?p!==h?Lu(p,["block-start","text-start","block-end","text-end","justify"]):(ft(h,"text-end"),ft(h,"justify")):ft(h,"text-end")}else ft(h,"text-end")}ln(h)&&ft(h,"clone"),kr(h,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),s=parseFloat(i.borderInlineEndWidth),r=-(n+s);isNaN(r)||(t.style.marginInlineEnd=`${r}px`)}createChildAnonymousBlockIfNeeded(t){let i=r=>{let{display:o,position:a,float:l}=this.viewport.window.getComputedStyle(r);if(r.localName==="ruby"||gi[r.localName])return!1;if(r.localName==="br")return!0;if((o==="inline"||o==="contents")&&r.hasChildNodes()){let h=r.lastElementChild;if(h&&(!h.nextSibling||h.nextSibling===r.lastChild&&Ue(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"||r.hasAttribute(Xi)){let h=r.previousElementSibling;return h&&(h.nextSibling===r||h.nextSibling===r.previousSibling&&Ue(h.nextSibling))?i(h):!1}return!(!o||Lt(o))},n=null;for(let r=t.lastElementChild;r;r=r.previousElementSibling){let o=i(r);if(o){n=r;break}if(o===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&Ue(n.nextSibling)))return null;let s=t.ownerDocument.createElement("span");s.className="viv-anonymous-block";for(let r=n.nextSibling,o=null;r;r=o)o=r.nextSibling,s.appendChild(r);return t.appendChild(s),s}convertLengthToPx(t,i,n){let s=t.num,r=t.unit;if(Rp(r)){let o=i;for(;o&&o.nodeType!==1;)o=o.parentNode;let a=parseFloat(n.getElementComputedStyle(o)["font-size"]);return this.context,ga(t,a,this.context).num}else{let o=this.context.queryUnitSize(r,!1);return o?s*o:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,s=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&_i(n)===_i(s)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,s)=>{let r=i.steps[s];return this.isSameNodePositionStep(n,r)})}isPseudoelement(t){return!!_i(t)}};c(Td,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var _y=Td,My={"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},zy=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}},Xs=class{constructor(e,t,i,n,s,r){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"),c(this,"layoutUnitAdj",0),this.document=e.document,this.root=n||this.document.body;let o=this.root.firstElementChild;o||(o=this.document.createElement("div"),o.setAttribute("data-vivliostyle-outer-zoom-box","true"),o.role="presentation",this.root.appendChild(o));let a=o.firstElementChild;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),Nh){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=s||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=r||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let h={width:794,height:1056},u=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!s&&u)&&(this.width=h.width),(!this.height||!r&&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)}},Id=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,s=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let r=this.root.firstChild;r;r=r.nextSibling){if(r.nodeType!=1)continue;let o=r;if(o.namespaceURI=="http://www.w3.org/1999/xhtml")switch(o.localName){case"head":s=o;break;case"body":n=o;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=s,this.last=this.root,this.last.setAttribute(Mt,"0")}doc(){return new Rd([this.document])}getElementOffset(e){let t=e.getAttribute(Mt);if(t)return parseInt(t,10);let i=this.lastOffset,n=this.last;for(;n!=e;){let s=n.firstChild;if(!s){for(;s=n.nextSibling,!s;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=s,s.nodeType==1?(s.setAttribute(Mt,i.toString()),++i):i+=s.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,s=e,r=null;if(s.nodeType==1){if(!i)return this.getElementOffset(s)}else{if(n=t,r=s.previousSibling,!r)return s=s.parentNode,n+=1,this.getElementOffset(s)+n;s=r}for(;;){for(;s.lastChild;)s=s.lastChild;if(s.nodeType==1)break;if(n+=s.textContent.length,r=s.previousSibling,!r){s=s.parentNode;break}s=r}return n+=1,this.getElementOffset(s)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let l=ni(a.length,h=>{let u=a[h];return this.getElementOffset(u)>e});if(l==0)break;i=a[l-1]}let n=t+1,s=i,r=s.firstChild||s.nextSibling,o=null;for(;;){if(r){if(r.nodeType==1||(s=r,o=s,n+=r.textContent.length,n>e&&!/^\s*$/.test(r.textContent)))break}else if(s=s.parentNode,!s)break;r=s.nextSibling}return r&&o&&/^\s*$/.test(o.textContent)&&(o=r),o||i}buildIdMap(e){let t=e.getAttribute("id");t&&!this.idMap[t]&&(this.idMap[t]=e);let i=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=e);for(let n=e.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(e){let t=e.match(/([^#]*)#(.+)$/);if(!t||t[1]&&t[1]!=this.url)return null;let i=t[2],n=this.document.getElementById(i);return!n&&this.document.getElementsByName&&(n=this.document.getElementsByName(i)[0]),n||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),n=this.idMap[i]),n}},Uo=(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))(Uo||{});function ls(e,t,i){let n=i||new DOMParser,s;try{s=n.parseFromString(e,t)}catch{}if(s){let r=s.documentElement,o="parsererror";if(r.localName===o)return null;for(let a=r.firstElementChild;a;a=a.nextElementSibling)if(a.localName===o)return null}else return null;return s}function Dy(e){let t=e.contentType;if(t){let n=Object.keys(Uo);for(let s=0;s<n.length;s++)if(Uo[n[s]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let i=e.url.match(/\.([^./#?]+)([#?]|$)/);if(i)switch(i[1]){case"html":case"htm":return"text/html";case"xhtml":case"xht":return"application/xhtml+xml";case"svg":case"svgz":return"image/svg+xml";case"opf":case"xml":return"application/xml"}return null}function Ad(e,t){let i=e.responseXML;if(!i){let s=new DOMParser,r=e.responseText;if(r){let o=Dy(e);if(i=ls(r,o||"application/xml",s),i&&!o){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=ls(r,"text/html",s):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=ls(r,"image/svg+xml",s))}i||(i=ls(r,"text/html",s))}}let n=i?new Id(t,e.url,i):null;return N(n)}function Vy(){return new ia(Ad,"document")}var Uy=class Ho{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new Ho(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new Ho(n=>{if(!this.check(n))return!1;let s=new Rd([n]);return s=s.child(t),i&&(s=s.predicate(i)),s.size()>0})}},oh=new Uy(e=>!0),Rd=class $o{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 $o(i)}forEachNode(t){let i=[],n=s=>{i.push(s)};for(let s=0;s<this.nodes.length;s++)t(this.nodes[s],n);return new $o(i)}forEach(t){let i=[];for(let n=0;n<this.nodes.length;n++)i.push(t(this.nodes[n]));return i}forEachNonNull(t){let i=[];for(let n=0;n<this.nodes.length;n++){let s=t(this.nodes[n]);s!=null&&i.push(s)}return i}child(t){return this.forEachNode((i,n)=>{for(let s=i.firstChild;s;s=s.nextSibling)s.nodeType==1&&s.localName==t&&n(s)})}childElements(){return this.forEachNode((t,i)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&i(n)})}attribute(t){return this.forEachNonNull(i=>i.nodeType==1?i.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}},Hy=new $n(()=>{let e=B("uaStylesheetBase"),t=cd(),i=Ne("user-agent-base.css",Qt),n=new Rn(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),Mm(n.cascade),sa(wu,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function $y(){return Hy.get()}var Wy=class extends dn{constructor(e,t,i,n,s,r){super(e,t,null,i,n,"counter-style"),this.counterStyleName=s,this.counterStyles=r}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||H.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},Gy=class{constructor(e,t,i,n,s,r,o,a,l,h,u){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=s,this.fontFaces=r,this.footnoteProps=o,this.flowProps=a,this.viewportProps=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 Me(this.pageScope,function(){let d=this;return d.pageNumberOffset+d.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new Me(this.pageScope,function(){let d=this.currentLayoutPosition;return d?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let s=new Vr(this.rootScope,e,t,i),r=rm(s,this.viewportProps),o=r.width,a=r.height,l=r["text-zoom"],h=1;if(o&&a||l){let u=Tt.em;if((l?l.evaluate(s,"text-zoom"):null)===b.scale&&(h=u/i,i=u,e*=h,t*=h),o&&a){let d=Je(o.evaluate(s,"width"),s),p=Je(a.evaluate(s,"height"),s);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}}},La=class extends Vr{constructor(e,t,i,n,s,r,o,a,l,h,u,d,p){super(e.rootScope,n.width,n.height,n.fontSize),this.style=e,this.xmldoc=t,this.viewport=n,this.clientLayout=s,this.fontMapper=r,this.customRenderer=o,this.fallbackMap=a,this.pageNumberOffset=l,this.documentURLTransformer=h,this.counterStore=u,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 jb(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new cn(null,null,null,null,null,null,null),this.pageProgression=d||null,this.isVersoFirstPage=!!p;for(let f in e.flowProps){let m=e.flowProps[f],g=_e(m,"flow-consume");g&&(g.evaluate(this,"flow-consume")==b.all?this.primaryFlows[f]=!0:delete this.primaryFlows[f])}}init(){let e=B("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 jl(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,t,i,this.style.counterStyleStore),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 s=this.style.rootBox;this.rootPageBoxInstance=new Jb(s);let r=this.style.cascade.createInstance(this,t,i,this.lang,this.style.counterStyleStore);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(r,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new gy(r,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=Gb(l.properties,this),u=new dd(h);o.push(u)}this.fontMapper.findOrLoadFonts(o,this.faces).then(()=>{Ry(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);let u=nh(js(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 Vr(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),s=this.counterStore.createCounterListener(e.url),r=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new jl(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,s,r,i.counterStyleStore),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 Pg,i.flowPositions[e.flowName]=n);let s=kg(e.element),r=new oi(s),o=new Ng(r,e);n.positions.push(o)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;let n=!0;class s{unknownProperty(l,h){n=!1}invalidPropertyValue(l,h){n=!1}simpleProperty(l,h,u){}}let r=new s,o=Qi(this.style.rootScope,new Rt(t,null),"");return o?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,o,!1,r),n):!1}evalSupportsSelector(e){let t=new Fd(null),i=new Rt(e+"{}",t);return new Gn(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,s=n.steps[0].node,r=n.offsetInNode,o=n.after,a=0;for(;s.ownerDocument!=this.xmldoc.document;)a++,s=n.steps[a].node,o=!1,r=0;let l=this.xmldoc.getNodeOffset(s,r,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 s=e.flowPositions[n];if(!t&&(!s||s.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),s=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&s&&(s=s.clone(),e.flowPositions[n]=s)),s){let r=this.getConsumedOffset(s);r<i&&(i=r)}}return i}dumpLocation(e){H.debug("Location - page",this.currentLayoutPosition.page),H.debug(" current:",e),H.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)H.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new ze(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let t in e.flowPositions){let i=e.flowPositions[t];if(i&&i.positions.length>0){let n=i.positions[0].flowChunk;if(this.getConsumedOffset(i)===n.startOffset){let s=i.positions[0].flowChunk.breakBefore,r=i.startBreakType;i.startBreakType=gl(it(r,s))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,s;for(let r=0;r<n.length;r++){if(s=n[r],s.pageBox.pseudoName===Ra)continue;let o=1;s.pageBox.pseudoName===Pa&&!(this.actualPageWidth&&this.actualPageHeight)&&(o=1/0);let a=s.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=s.getProp(this,"enabled");if(!p||p===b._true){if(t.page===1&&this.blankPageAtStart){s.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(s,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,s=t[i].forcedBreakOffsets;if(!s.length||n<s[0])return!1;let r=ni(s.length,h=>s[h]>n)-1,o=s[r],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 da(null)),e.flowRootFormattingContext=i.formattingContext}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=a=>{if(a.floatReference!==Fe.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},s=B("layoutDeferredPageFloats"),r=!1,o=0;return s.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 ji().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&&(r=!0,t.validate());a.continueLoop()})}).then(()=>{r&&t.invalidate(),s.finish(!0)}),s.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new oi(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=B("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let s=[],r=[],o=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-r.length>0;){let l=0;for(;r.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(r.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)&&s.push(l),u.exclusive){r.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):(r.push(l),(p||m)&&(h.chunkPosition=p||m,s.push(l)),i.startBreakType=gl(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)=>s.includes(h)||!r.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 sw([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,s,r,o,a,l,h,u,d,p,f){let m=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,g=s.element,w=new cn(a,Fe.COLUMN,null,o,null,null,null),v=this.currentLayoutPosition.clone(),y=B("createAndLayoutColumn"),C;return y.loopWithFrame(E=>{let I=this.createLayoutConstraint(w);if(l>1){let V=this.viewport.document.createElement("div");if(T(V,"position","absolute"),g.appendChild(V),C=new Vs(V,p,this.clientLayout,I,w),C.forceNonfitting=f,C.vertical=s.vertical,C.rtl=s.rtl,C.snapHeight=s.snapHeight,C.snapWidth=s.snapWidth,s.vertical){let D=(s.rtl?l-r-1:r)*(u+h)+s.paddingTop,te=parseFloat(g.style.width);C.setHorizontalPosition(s.paddingLeft+te-s.width,s.width),C.setVerticalPosition(D,u)}else{let D=(s.rtl?l-r-1:r)*(u+h)+s.paddingLeft;C.setVerticalPosition(s.paddingTop,s.height),C.setHorizontalPosition(D,u)}C.originX=t,C.originY=i}else C=new Vs(g,p,this.clientLayout,I,w),C.copyFrom(s);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 Ta&&!(t instanceof $i))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof Yi;let s=t.getProp(this,"writing-mode")||null,r=t.getProp(this,"direction")||null;return new cn(e,Fe.REGION,i,n,null,s,r)}layoutFlowColumnsWithBalancing(e,t,i,n,s,r,o,a,l){let h=this.currentLayoutPosition.clone(),u=this.getRegionPageFloatLayoutContext(r,t,o,a),d=!0,p=()=>(this.currentLayoutPosition=h.clone(),this.layoutFlowColumns(e,t,i,n,s,r,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=jw(l,m,p,u,o,f.columns,g);return w?(d=!1,r.lock(),u.lock(),w.balanceColumns(f).thenAsync(v=>(r.unlock(),r.validate(),u.unlock(),this.currentLayoutPosition=v.position,N(v.columns)))):N(f.columns)})}layoutFlowColumns(e,t,i,n,s,r,o,a,l,h,u){let d=B("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=au(w,0,0,a.width,a.height,this),y=new _y(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,I=[];return d.loopWithFrame(V=>{this.createAndLayoutColumn(t,i,n,s,a,C++,l,o,h,f,m,v,y,u).then(D=>{if(r.isInvalidated()){I=null,V.breakLoop();return}if((D.pageBreakType&&D.pageBreakType!=="column"||C===h)&&!o.isInvalidated()&&o.finish(),o.isInvalidated()){C=0,this.currentLayoutPosition=p.clone(),o.validate(),o.isLocked()?(I=null,V.breakLoop()):V.continueLoop();return}E=D,I[C-1]=E,E.pageBreakType&&E.pageBreakType!="column"&&(C=h,E.pageBreakType!="region"&&(this.pageBreaks[l]=!0)),C<h?V.continueLoop():V.breakLoop()})}).then(()=>{d.finish(I)}),d.result()}layoutContainer(e,t,i,n,s,r,o){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==b._true)return N(!0);let l=B("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 Ed?"complementary":"presentation";let p=t.getProp(this,"position");T(d,"position",p?p.name:"absolute");let f=t instanceof $i;t instanceof Yi?i.appendChild(d):i.insertBefore(d,i.firstChild);let m=new $u(d);m.vertical=t.vertical,m.rtl=t.rtl,m.borderBoxSizing=t.borderBoxSizing,m.exclusions=r,t.prepareContainer(this,m,e,this.faces,this.clientLayout),t instanceof $i&&(m.width<=0||m.height<=0)&&H.warn("Negative or zero page area size"),m.originX=n,m.originY=s,n+=m.left+m.marginLeft+m.borderLeft,s+=m.top+m.marginTop+m.borderTop,this.setPagePageFloatLayoutContextContainer(o,t,m);let g,w=!1;if(!u||!u.isIdent()){let v=t.getProp(this,"content");if(v instanceof U&&v.expr instanceof Me&&v.expr.str.startsWith("running-element-"))v.visit(new _s(d,this,v,this.counterStore.getExprContentListener()));else if(Ot(v)){let y="span";v instanceof Ke&&(y="img");let C=this.viewport.document.createElement(y);v.visit(new _s(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"&&Km(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=B("layoutContainer.inner"),y=u.toString(),C=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,s,r,o,m,y,C).then(E=>{if(!o.isInvalidated()){let I=E[0];I.element===d&&(m=I),m.computedBlockSize=Math.max.apply(null,E.map(D=>D.computedBlockSize)),t.finishContainer(this,m,e,I,C,this.clientLayout,this.faces);let V=this.currentLayoutPosition.flowPositions[y];V&&V.breakAfter==="region"&&(V.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);r.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,s,r,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 s=i.positions[n];s.flowChunk.startPage>=0&&s.flowChunk.startPage+s.flowChunk.linger-1<=e&&i.positions.splice(n,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let s=i.positions[n];s.flowChunk.startPage<0&&s.flowChunk.startOffset<this.lookupOffset&&(s.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let t in this.primaryFlows){let i=e.flowPositions[t];if(i&&i.positions.length>0)return!1}return!0}layoutNextPage(e,t){var i;let n=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new Tg,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let s=1e4;if(t.page>s)throw new Error(`Too many pages generated (over ${s} pages)`);let r=t.startSideOfFlow("body");t.isBlankPage=An(r)&&this.matchPageSide(r),e.isBlankPage=t.isBlankPage,t.page++,e.pageType==null&&(e.pageType=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let o=n?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.styler.cascade.applyVarFilter([o],this.styler,null),this.styler.cascade.applyCalcFilter(o,this.styler.context),!n){let f=new ze(this.style.pageScope,"left-page");e.side=f.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let a=this.selectPageMaster(o);if(!a)return N(null);let l=0;if(!n){e.setAutoPageWidth(a.pageBox.specified.width.value===Un),e.setAutoPageHeight(a.pageBox.specified.height.value===Hn),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(o,this);let f=nh(js(o),this);this.setPageSizeAndBleed(f,e),ly(o,f,e,this),l=f.bleedOffset+f.bleed}let h=!n&&a.getProp(this,"writing-mode")||b.horizontal_tb;this.pageVertical=h!=b.horizontal_tb;let u=a.getProp(this,"direction")||b.ltr,d=new cn(this.rootPageFloatLayoutContext,Fe.PAGE,null,null,null,h,u),p=B("layoutNextPage");return p.loopWithFrame(f=>{this.layoutContainer(e,a,e.bleedBox,l,l,[],d).then(()=>{d.isInvalidated()||d.finish(),d.isInvalidated()?(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),d.validate(),f.continueLoop()):f.breakLoop()})}).then(()=>{a.adjustPageLayout(this,e,this.clientLayout),n||(this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(m=>{let g=t.flowPositions[m],w=g.breakAfter;w&&(w==="page"||!this.matchPageSide(w))&&(g.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let f=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(f,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),p.finish(t)}),p.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`}},jy=class Wo extends Rn{constructor(t,i,n,s){super(t.rootScope,t,i,n,s,t.validatorSet,!n),this.masterHandler=t,c(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let s=new pd(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new ty(s.scope,this.masterHandler,s,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=Ct(this.scope,this.condition,i)),this.masterHandler.pushHandler(new Wo(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new Hm(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new dn(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new Wy(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 dn(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new dn(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=Xn(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new dn(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new Ny(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(Rn.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 Wo(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},Fd=class extends Zf{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 Pb),c(this,"footnoteProps",{}),c(this,"flowProps",{}),c(this,"viewportProps",[]),c(this,"pageProps",{}),this.rootScope=new Dr(null),this.pageScope=new Dr(this.rootScope),this.rootBox=new Yb(this.rootScope),this.cascadeParserHandler=new jy(this,null,null,null),this.slave=this.cascadeParserHandler}};function Xy(e,t){return t.parseOPSResource(e)}var qy=class extends ia{constructor(e){super(Xy,"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=B("OPSDocStore.init");return this.validatorSet=cd(),$y().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(In(t),Wi)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ne(In(t),Wi)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=B("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return Ad(e,this).then(s=>{var r;if(!s){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=At("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](s.document)}catch(m){H.warn("Error during single document preprocessing:",m)}}let o=[],a=s.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let 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:Ne("user-agent-page.css",Qt),text:mu,flavor:"UA",classes:null,media:null}),l.push({url:Ne("user-agent-counter-styles.css",Qt),text:vu,flavor:"UA",classes:null,media:null}),n)l.push({url:Ne("user-agent-toc.css",Qt),text:bu,flavor:"UA",classes:null,media:null});else{let p=s.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=(r=f.getAttribute("rel"))==null?void 0:r.split(/\s+/),y=f.getAttribute("class"),C=f.getAttribute("media");if(w&&v!=null&&v.includes("stylesheet")&&(!v.includes("alternate")||y)){let E=Ne(w,i),I=f.getAttribute("title");l.push({url:E,text:null,classes:I?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(s);return}let d=this.styleFetcherByKey[h];d||(d=new $n(()=>{let p=B("fetchStylesheet"),f=0,m=new Fd(this.validatorSet);return p.loop(()=>{if(f<l.length){let g=l[f++];return m.startStylesheet(g.flavor),g.text!==null?sa(g.text,m,g.url,g.classes,g.media).thenReturn(!0):Nu(g.url,m,g.classes,g.media)}return N(!1)}).then(()=>{let g=m.cascadeParserHandler.finish();u=new Gy(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(s)})}),t.result()}processViewportMeta(e){return""}},Pn="\u25B8",ah="\u25BE",Yy="\u25B9";function Ba(e){let t=Array.from(e.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(e.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of e.querySelectorAll(i)){if(t.find(r=>r.contains(n)))continue;let s=n;/^h[1-6]$/.test(s.localName)&&(s.previousElementSibling?s=s.nextElementSibling:s=s.parentElement),s&&s.querySelector("li a[href]")&&t.push(s)}return t}function Ky(e){let t=Ba(e),i=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))i.push(s);return i}var Zy=class{constructor(e,t,i,n,s,r,o,a,l,h){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=s,this.rendererFactory=o,this.fallbackMap=a,this.documentURLTransformer=l,this.counterStore=h,c(this,"pref"),c(this,"page",null),c(this,"instance",null),this.pref=Bh(r),this.pref.spreadView=!1}setAutoHeight(e,t){if(t--!=0){for(let i=e.firstChild;i;i=i.nextSibling)if(i.nodeType==1){let n=i;Kt(n,"height","auto")!="auto"&&(T(n,"height","auto"),this.setAutoHeight(n,t)),Kt(n,"position","static")=="absolute"&&(T(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,s)=>{let r=s.behavior;if(r)switch(r.toString()){case"toc-node-anchor":s.color=b.inherit,s["text-decoration"]=b.none;break;case"toc-node":s.display=b.block,s.margin=ke,s.padding=ke,s["padding-inline-start"]=new A(1.25,"em");break;case"toc-node-first-child":s.display=b.inline_block,s.margin=new A(.2,"em"),s["vertical-align"]=b.top,s.color=b.inherit,s["text-decoration"]=b.none;break;case"toc-container":s.padding=ke;break}if(!r||r.toString()!="toc-node"&&r.toString()!="toc-container")return t(i,n,s);let o=i.firstChild;o&&o.nodeType!==1&&Ue(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!=Pn&&(h.textContent=Pn,T(h,"cursor","pointer"),h.addEventListener("click",Jy,!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"),r.toString()=="toc-node"){let h=n.ownerDocument.createElement("div");if(h.textContent=Yy,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,s){if(this.page)return N(this.page);let r=B("showTOC"),o=new Ou(e,e);this.page=o;let a=Dt(this.url)+"?viv-toc-box";return this.store.load(a).then(l=>{for(let f of Ba(l.document))f.setAttribute("data-vivliostyle-role","doc-toc");let h=this.store.getStyleForDoc(l),u=h.sizeViewport(i,1e5,s);t=new Xs(t.window,u.fontSize,0,t.root,u.width,u.height);let d=this.makeCustomRenderer(l),p=new La(h,l,this.lang,t,this.clientLayout,this.fontMapper,d,this.fallbackMap,0,this.documentURLTransformer,this.counterStore);this.instance=p,p.pref=this.pref,p.init().then(()=>{p.layoutNextPage(o,null).then(()=>{this.setAutoHeight(e,2),r.finish(o)})})}),r.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function e(n){if(!n)return[];let s=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(s).map(t)}function t(n){let s=new URL(n.href),[,r]=s.hash.match(/^#?(.*)$/),o=n.innerText,a=n.parentElement.querySelector("[role=group]"),l=e(a);return{id:r,title:o,children:l}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function Jy(e){let t=e.target,i=t.textContent==Pn;t.textContent=i?ah:Pn;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let s=n.firstChild;for(;s;){if(s.nodeType===1){let r=s,o=r.getAttribute("data-adapt-class");if(o==="toc-container"){if(r.setAttribute("aria-hidden",i?"false":"true"),r.firstChild){s=r.firstChild;continue}}else if(o==="toc-node"&&(r.style.height=i?"auto":"0px",r.children.length>=2&&(r.children[1].tabIndex=i?0:-1),r.children.length>=3&&(r.children[0].tabIndex=i?0:-1,!i))){let a=r.children[0];if(a.textContent==ah){a.textContent=Pn,a.setAttribute("aria-expanded","false"),r.setAttribute("aria-expanded","false"),s=r.children[2];continue}}}for(;!s.nextSibling&&s.parentNode!==n;)s=s.parentNode;s=s.nextSibling}e.stopPropagation()}var lh=class extends qy{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=Vy(),this.jsonStore=Xf()}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=B("loadPubDoc");return er(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}H.error(`Failed to fetch a source document from ${e} (${i.status}${i.statusText?" "+i.statusText:""})`),t.finish(null)});else if(!i.status&&!i.responseXML&&!i.responseText&&!i.responseBlob&&!i.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),i.contentType=="application/oebps-package+xml"||/\.opf(?:[#?]|$)/.test(e)){let[,n,s]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,s).thenFinish(t)}else i.contentType=="application/ld+json"||i.contentType=="application/webpub+json"||i.contentType=="application/audiobook+json"||i.contentType=="application/json"||/\.json(?:ld)?(?:[#?]|$)/.test(e)?this.loadAsJSON(e,!0).then(n=>{if(!n){this.reportLoadError(e),t.finish(null);return}let s=new Ps(this,e);s.initWithWebPubManifest(n,void 0,e).then(()=>{t.finish(s)})}):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(s=>{if(s){t.finish(s);return}H.error(`Failed to load ${e}.`),t.finish(null)})})}),t.result()}loadEPUBDoc(e){let t=B("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let i=e+"META-INF/container.xml";return this.loadAsPlainXML(i).then(n=>{if(n){let s=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let r of s)if(r){this.loadOPF(e,r).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return N(n);let s=B("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(r=>{r?(n=new Ps(this,e),this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(o=>{n.initWithXMLDoc(r,o).then(()=>{s.finish(n)})}):n.initWithXMLDoc(r,null).then(()=>{s.finish(n)})):this.reportLoadError(i)}),s.result()}loadWebPub(e){let t=B("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,s=new Ps(this,e),r=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(r){let o=r.getAttribute("href");if(/^#/.test(o)){let a=Xo(n.getElementById(o.substr(1)).textContent);s.initWithWebPubManifest(a,n).then(()=>{t.finish(s)})}else{let a=Ne(r.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(l=>{s.initWithWebPubManifest(l,n,a).then(()=>{t.finish(s)})})}}else s.initWithWebPubManifest({},n).then(()=>{s.toc&&s.toc.src===i.url&&Ba(n).length===0&&(s.toc=null),t.finish(s)})}}),t.result()}addDocument(e,t){let i=B("EPUBDocStore.load"),n=Dt(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(Wi)||Object.keys(this.resources).find(s=>this.resources[s]&&t(s)===n)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?H.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&Wi.startsWith("https:")?H.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?H.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):H.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Dt(e),i=this.documents[t];if(i)return i.isPending()?i:N(i.get());{let n=B("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(s=>{s?n.finish(s):this.reportLoadError(t)}),n.result()}}processViewportMeta(e){let t=e.getAttribute("content");if(!t)return"";let i={},n;for(;(n=t.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)t=t.substr(n[0].length),i[n[1]]=n[2];let s=i.width-0,r=i.height-0;if(s&&r){let o=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${s}px;height:${r}px;}`+(o?`@page{size:${s}px ${r}px;margin:0;}`:"@page{margin:0;}")}return""}},hh=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=mp}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=Cp(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 Qy(e){return e.id}function e0(e){return t=>{let i=B("deobfuscator");return t0("SHA-1",e).then(n=>{let s=t.slice(0,1040),r=t.slice(1040,t.size);Wf(s).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(xu([a,r]))})}),i.result()}}function t0(e,t){let i=B("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(s=>{n.schedule(new Uint8Array(s))}),i.result()}var Jt={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"},mn="http://idpf.org/epub/vocab/package/meta/#",Be={language:`${Jt.dcterms}language`,title:`${Jt.dcterms}title`,creator:`${Jt.dcterms}creator`,layout:`${Jt.rendition}layout`,titleType:`${mn}title-type`,displaySeq:`${mn}display-seq`,alternateScript:`${mn}alternate-script`,role:`${mn}role`};function i0(e,t){let i={};return(n,s)=>{var r,o,a,l,h,u;let d,p,f=n.r||i,m=s.r||i;if(e==Be.title&&(d=((r=f[Be.titleType])==null?void 0:r[0].v)=="main",p=((o=m[Be.titleType])==null?void 0:o[0].v)=="main",d!=p))return d?-1:1;let g=parseInt((a=f[Be.displaySeq])==null?void 0:a[0].v,10);isNaN(g)&&(g=Number.MAX_VALUE);let w=parseInt((l=m[Be.displaySeq])==null?void 0:l[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),g!=w?g-w:e!=Be.language&&t&&(d=((h=f[Be.language]||f[Be.alternateScript])==null?void 0:h[0].v)==t,p=((u=m[Be.language]||m[Be.alternateScript])==null?void 0:u[0].v)==t,d!=p)?d?-1:1:n.o-s.o}}function n0(e,t){let i;if(!t)i=Jt;else{i={};for(let p in Jt)i[p]=Jt[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]]:mn;if(f)return f+p[3]}}return null},s=1,r=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:s++,refines:d.getAttribute("refines"),lang:null,scheme:n(d.getAttribute("scheme")),role:null}}else if(d.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:Jt.dcterms+d.localName,order:s++,lang:d.getAttribute("xml:lang"),value:d.textContent,id:d.getAttribute("id"),refines:null,scheme:null,role:d.getAttribute("role")||d.getAttribute("opf:role")};return null}),o=gr(r,d=>d.refines),a=d=>kp(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:Be.language,value:m.lang,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null}),m.role&&w.push({name:Be.role,value:m.role,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null});let v=gr(w,y=>y.name);g.r=a(v)}return g})),l=a(gr(r,d=>d.refines?null:d.name)),h=null;l[Be.language]&&(h=l[Be.language][0].v);let u=d=>{for(let p in d){let f=d[p];f.sort(i0(p,h));for(let m=0;m<f.length;m++){let g=f[m].r;g&&u(g)}}};return u(l),l}function s0(){let e=window.MathJax;return e?e.Hub:null}var uh={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Or="viv-id-",Ps=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,s){let r=s+(n?`#${n}`:"");return Or+Ih(r,":")}transformURL(n,s){let r=n.match(/^([^#]*)#?(.*)$/);if(r){let o=r[1]||s.replace(/\?viv-toc-box$/,""),a=decodeURIComponent(r[2]);if(o&&e.spine.some(l=>l.src===o))return`#${this.transformFragment(a,o)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(Or)===0&&(n=n.substring(Or.length));let s=Sp(n,":").match(/^([^#]*)#?(.*)$/);return s?[s[1],s[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=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 l=e.getElement(`${e.url}#${n}`);l&&(this.uid=l.textContent.replace(/[ \n\r\t]/g,""))}let s={};this.items=i.child("manifest").child("item").asArray().map(l=>{let h=new hh,u=l;h.initWithElement(u,e.url);let d=u.getAttribute("fallback");return d&&!uh[h.mediaType]&&(s[h.src]=d),!this.toc&&h.itemProperties.nav&&(this.toc=h),!this.cover&&h.itemProperties["cover-image"]&&(this.cover=h),h}),this.itemMap=Ga(this.items,Qy),this.itemMapByPath=Ga(this.items,l=>this.getPathFromURL(l.src));for(let l in s){let h=l;for(;;){let u=this.itemMap[s[h]];if(!u)break;if(uh[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 r=i.child("spine").attribute("page-progression-direction")[0];r&&(this.pageProgression=vh(r));let o=t?t.doc().child("encryption").child("EncryptedData").predicate(oh.withChild("EncryptionMethod",oh.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=n0(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[Be.language]&&(this.lang=this.metadata[Be.language][0].v),this.metadata[Be.layout]&&(this.prePaginated=this.metadata[Be.layout][0].v==="pre-paginated"),o.length>0&&this.uid){let l=e0(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=B("countEPages");return n.loopWithFrame(s=>{if(i===this.spine.length){s.breakLoop();return}let r=this.spine[i++];r.epage=t,this.store.load(r.src).then(o=>{let a=1800,l=o.lang||this.lang;l&&l.match(/^(ja|ko|zh)/)&&(a/=3),r.epageCount=Math.ceil(o.getTotalOffset()/a),t+=r.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),s.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new Id(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let s=new hh;s.initWithParam(n),s.id;let r=i.document.createElement("itemref");r.setAttribute("idref",s.id),i.root.appendChild(r),s.itemRefElement=r,this.itemMap[s.id]=s;let o=this.getPathFromURL(n.url);o==null&&(o=n.url),this.itemMapByPath[o]=s,this.items.push(s)}),t?this.store.addDocument(e[0].url,t):N(null)}initWithWebPubManifest(e,t,i){var n,s,r,o;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[Be.title]=(Array.isArray(a)?a:[a]).map(g=>{var w;return{v:(w=g.value)!=null?w:g}}));let l=e.author||e.creator||((s=e.metadata)==null?void 0:s.author)||Array.from((r=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?r:[]).map(g=>g.content);l&&l.length!==0&&(this.metadata[Be.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[Be.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 Ky(t)){let w=g.getAttribute("href");if(/^(https?:)?\/\//.test(w)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(w))continue;let v=Dt(Ne(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,I={url:Ne(In(y),E),index:p++,startPage:null,skipPagesBefore:null};w.rel==="contents"&&f===-1&&(f=I.index),d.push(I)}})});let m=B("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=B("getCFI");return this.store.load(i.src).then(s=>{let r=s.getNodeByOffset(t),o=null;if(r){let a=s.getNodeOffset(r,0,!1),l=t-a,h=new Za;h.prependPathFromNode(r,l,!1,null),i.itemRefElement&&h.prependPathFromNode(i.itemRefElement,0,!1,null),o=h.toString()}n.finish(o)}),n.result()}resolveFragment(e){return Gi("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Za;i.fromString(e);let n;if(this.opfXML){let s=i.navigate(this.opfXML.document);if(s.node.nodeType!=1||s.after||!s.ref){t.finish(null);return}let r=s.node,o=r.getAttribute("idref");if(r.localName!="itemref"||!o||!this.itemMap[o]){t.finish(null);return}n=this.itemMap[o],i=s.ref}else n=this.spine[0];this.store.load(n.src).then(s=>{let r=i.navigate(s.document),o=s.getNodeOffset(r.node,r.offset,r.after);t.finish({spineIndex:n.spineIndex,offsetInItem:o,pageIndex:-1})})},(t,i)=>{H.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return Gi("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let s=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);s==-1&&(s=this.spine.length-1);let r=this.spine[s];(!r||r.epageCount==0)&&(r=this.spine[--s]);let o=Math.floor(e-r.epage);t.finish({spineIndex:s,offsetInItem:-1,pageIndex:o});return}let i=ni(this.spine.length,s=>{let r=this.spine[s];return r.epage+r.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(s=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let r=0;if(e>0){let o=s.getTotalOffset();r=Math.round(o*e/n.epageCount),r==o&&r--}t.finish({spineIndex:i,offsetInItem:r,pageIndex:-1})})},(t,i)=>{H.warn(i,"Cannot resolve epage:",e),t.finish(null)})}getEPageFromPosition(e){let t=this.spine[e.spineIndex];if(this.epageIsRenderedPage){let n=t.epage+e.pageIndex;return N(n)}if(e.offsetInItem<=0)return N(t.epage);let i=B("getEPage");return this.store.load(t.src).then(n=>{let s=n.getTotalOffset(),r=Math.min(s,e.offsetInItem);i.finish(t.epage+r*t.epageCount/s)}),i.result()}},hs=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),r0=class{constructor(e,t,i,n,s){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=s,c(this,"spineItems",[]),c(this,"spineItemLoadingContinuations",[]),c(this,"pref"),c(this,"clientLayout"),c(this,"counterStore"),c(this,"tocAutohide",!1),c(this,"tocVisible",!1),c(this,"tocView"),this.pref=Bh(n),this.clientLayout=new zy(t),this.counterStore=new pf(e.documentURLTransformer)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let s=this.opf.spine[e.item.spineIndex-1];e.item.epage=s.epage+s.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((s,r)=>s+r.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)e.instance.viewport.contentContainer.replaceChild(t.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:t});else{let s=null;if(i>0)s=e.pages[i-1].container.nextElementSibling;else for(let r=e.item.spineIndex+1;r<this.spineItems.length;r++){let o=this.spineItems[r];if(o&&o.pages[0]){s=o.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,s)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}renderSinglePage(e,t){let i=B("renderSinglePage"),n=e.pages[t?t.page:0],s=this.makePage(e,t);return n&&(s.pageType=n.pageType),e.instance.layoutNextPage(s,t).then(r=>{t=r;let o=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,s,o),this.counterStore.finishPage(s.spineIndex,o);let a=null;if(t){let 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(s),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===s.spineIndex&&y.pageIndex===o&&(s=v.pageAndPosition.page),u.continueLoop()})})}).then(()=>{s.container.parentElement||(s=e.pages[o]),s.isLastPage=!t&&e.item.spineIndex===this.opf.spine.length-1,s.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),s.container.setAttribute("data-vivliostyle-page-index",o),s.container.setAttribute("data-vivliostyle-spine-index",s.spineIndex),i.finish({pageAndPosition:hs(s,o),nextLayoutPosition:t})})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let s=ni(t.layoutPositions.length,r=>t.instance.getPosition(t.layoutPositions[r],!0)>n);s===t.layoutPositions.length?t.complete?i=t.layoutPositions.length-1:i=Number.POSITIVE_INFINITY:i=s-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=B("findPage");return this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let s=null,r;i.loopWithFrame(o=>{let a=this.normalizeSeekPosition(e,n);r=a.pageIndex,s=n.pages[r],s?o.breakLoop():n.complete?(r=n.layoutPositions.length-1,s=n.pages[r],o.breakLoop()):t?this.renderPage(a).then(l=>{l&&(s=l.page,r=l.position.pageIndex),o.breakLoop()}):i.sleep(100).then(()=>{o.continueLoop()})}).then(()=>{i.finish(hs(s,r))})}),i.result()}renderPage(e){let t=B("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),s=n.pageIndex,r=n.offsetInItem,o=i.pages[s];if(o){t.finish(hs(o,s));return}t.loopWithFrame(a=>{if(s<i.layoutPositions.length){a.breakLoop();return}if(i.complete){s=i.layoutPositions.length-1,a.breakLoop();return}let l=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,l).then(h=>{let u=h.pageAndPosition.page;if(l=h.nextLayoutPosition,l){if(r>=0&&i.instance.getPosition(l)>r){o=u,s=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else o=u,s=h.pageAndPosition.position.pageIndex,i.complete=!0,a.breakLoop()})}).then(()=>{o=o||i.pages[s];let a=i.layoutPositions[s];if(o){t.finish(hs(o,s));return}this.renderSinglePage(i,a).then(l=>{l.nextLayoutPosition||(i.complete=!0),t.finish(l.pageAndPosition)})})}),t.result()}renderAllPages(){let e=B("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(t=>{e.loopWithFrame(i=>{this.spineItems.some(n=>n?.pages.some(s=>s?.fetchers.some(r=>!r.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=B("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,s=e.pageIndex,r=0;t&&(r=n);let o;return i.loopWithFrame(a=>{let l={spineIndex:r,pageIndex:r===n?s:Number.POSITIVE_INFINITY,offsetInItem:r===n?e.offsetInItem:-1};this.renderPage(l).then(h=>{o=h,++r>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(o)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,s=B("nextPage");return this.getPageViewItem(i).then(r=>{if(!r){s.finish(null);return}if(r.complete&&n==r.layoutPositions.length-1){if(i>=this.opf.spine.length-1){s.finish(null);return}i++,n=0;let o=this.spineItems[i],a=o&&o.pages[0],l=r.pages[r.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(s)}),s.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return N(null);i--,n=Number.POSITIVE_INFINITY}else n--;return this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t)}isRectoPage(e,t){let i=e.side==="left",n=this.getCurrentPageProgression(t)==="ltr";return!i&&n||i&&!n}getSpread(e,t){let i=this.getPage(e);if(!i)return N({left:null,right:null});let n=B("getSpread"),s=i.side==="left",r;return this.isRectoPage(i,e)?r=this.previousPage(e,t):r=this.nextPage(e,t),r.then(o=>{let a=this.getPage(e),l=o&&o.page;l&&l.side===a.side&&(l=null),s?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),s=this.nextPage(e,t);return n?s:s.thenAsync(r=>{if(r){if(r.page.side===i.side)return s;let o=this.nextPage(r.position,t);return o.thenAsync(a=>a?o:s)}else return N(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),s=this.previousPage(e,t),r=i.container.previousElementSibling;return n?s.thenAsync(o=>o?o.page.side===i.side||o.page.container!==r?s:this.previousPage(o.position,t):N(null)):s}navigateToEPage(e,t,i){let n=B("navigateToEPage");return this.opf.resolveEPage(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(e,t,i){let n=B("navigateToCFI");return this.opf.resolveFragment(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateTo(e,t,i){H.debug("Navigate to",e);let n=this.opf.getPathFromURL(Dt(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let o=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(o[0]),n==null&&(n=o[0])):n=o[0],e=o[0]+(o[1]?`#${o[1]}`:"")}if(n==null)return N(null)}let s=this.opf.itemMapByPath[n];if(!s){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let o=e.indexOf("#");if(o>=0)return this.navigateToFragment(e.substr(o+1),t,i)}return N(null)}let r=B("navigateTo");return this.getPageViewItem(s.spineIndex).then(o=>{if(!o){r.finish(null);return}let a=o.xmldoc.getElement(e);this.findPage({spineIndex:s.spineIndex,pageIndex:-1,offsetInItem:a?o.xmldoc.getElementOffset(a):0},i).thenFinish(r)}),r.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",Tn||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let s=i.document.createElement("div");s.setAttribute("data-vivliostyle-bleed-box","true"),s.role="presentation",n.appendChild(s);let r=new Ou(n,s);if(r.spineIndex=e.item.spineIndex,r.position=t,r.offset=e.instance.getPosition(t),r.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let o=this.opf.documentURLTransformer.transformFragment("",e.item.src);s.setAttribute("id",o),r.registerElementWithId(s,o)}if(i!==this.viewport){let o=Oh(this.viewport.width,this.viewport.height,i.width,i.height),a=Qi(null,new Rt(o,null),"");r.delayedItems.push(new oa(n,"transform",a))}return r}makeObjectView(e,t,i,n){let s=t.getAttribute("data"),r=null;if(s){s=Ne(s,e.url);let o=t.getAttribute("media-type");if(!o){let a=this.opf.getPathFromURL(s);if(a){let l=this.opf.itemMapByPath[a];l&&(o=l.mediaType)}}if(o){let a=this.opf.bindings[o];if(a){r=this.viewport.document.createElement("iframe"),r.style.border="none";let l=$a(s),h=$a(o),u=new ii;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)))}}r.setAttribute("src",u.toString());let d=t.getAttribute("width");d&&r.setAttribute("width",d);let p=t.getAttribute("height");p&&r.setAttribute("height",p)}}}return r||(r=this.viewport.document.createElement("object"),s&&r.setAttribute("data",s),r.setAttribute("data-adapt-process-children","true")),N(r)}makeMathJaxView(e,t,i,n){let s=s0();if(s){let r=i.ownerDocument,o=r.createElement("span");i.appendChild(o);let a=r.importNode(t,!0);this.resolveURLsInMathML(a,e),o.appendChild(a);let l=s.queue;l.Push(["Typeset",s,o]);let h=B("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 s=Ne(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,s):e.setAttribute(n.name,s)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):N(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return N(null);let t=this.spineItems[e];if(t)return N(t);let i=B("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let o=i.suspend();return n.push(o),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let s=this.opf.spine[e],r=this.opf.store;return r.load(s.src).then(o=>{var a;let l=s.itemRefElement.getAttribute("properties");l&&o.root.setAttribute("data-vivliostyle-epub-spine-properties",l),s.title=o.document.title;let h=r.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 Xs(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(s.startPage!==null)g=s.startPage-1,w=g;else{if(e>0&&(!m||!m.complete))g=s.epage||e,!this.opf.prePaginated&&g%2==(f?1:0)&&g++,w=g;else{g=m?m.instance.pageNumberOffset+m.pages.length:0;let C=this.counterStore.currentPageCounters.page;w=!C||!C.length?g:C[C.length-1]}s.skipPagesBefore!==null&&(g+=s.skipPagesBefore,w+=s.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let v=new La(h,o,this.opf.lang,d,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,g,this.opf.documentURLTransformer,this.counterStore,this.opf.pageProgression,f);v.pref=this.pref;let y=this.opf.metadata&&this.opf.metadata[Be.title];v.pubTitle=y&&y[0]&&y[0].v||"",v.docTitle=s.title||"",v.init().then(()=>{!this.opf.pageProgression&&v.pageProgression&&(this.opf.pageProgression=v.pageProgression),t={item:s,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=B("showTOC");this.tocView||(this.tocView=new Zy(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore));let s=this.viewport,r=Math.min(344,Math.round(.67*s.width)-16),o=s.height-6,a=s.document.createElement("div");return s.root.appendChild(a),Tn||(a.style.visibility="hidden"),a.style.width=`${r+16}px`,a.style.maxHeight=`${o}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,s,r,o,this.viewport.fontSize).then(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()}},ch="data-vivliostyle-viewer-status",o0="data-vivliostyle-spread-view",Ld=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(Ld||{}),a0=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 s=t.ownerDocument,r=(o,a)=>{let l=s.getElementById(o);return l||(l=s.createElement("style"),l.id=o,a&&(l.textContent=a),s.head.appendChild(l)),l};r("vivliostyle-viewport-screen-css",du),r("vivliostyle-viewport-css",pu),r("vivliostyle-polyfill-css",yu),t.setAttribute("data-vivliostyle-viewer-viewport",!0),Tn&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(ch,"loading"),this.fontMapper=new Xb(s.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=o=>{},this.pageRuleStyleElement=r("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}init(){this.readyState="loading",this.packageURL=[],this.opf=null,this.touchActive=!1,this.touchX=0,this.touchY=0,this.needResize=!1,this.resized=!1,this.needRefresh=!1,this.viewportSize=null,this.currentPage=null,this.currentSpread=null,this.pagePosition=null,this.fontSize=16,this.zoom=1,this.fitToScreen=!1,this.pageViewMode="singlePage",this.waitForLoading=!1,this.renderAllPages=!0,this.pref=Lh(),this.pageSizes=[],this.pixelRatioLimit=Nh==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=Ch;H.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),H.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),H.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),H.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){this.readyState!==e&&(this.readyState=e,this.viewportElement.setAttribute(ch,e),this.callback({t:"readystatechange"}))}loadPublication(e){ct.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,s=e.userStyleSheet;this.viewport=null;let r=B("loadPublication");return this.configure(e).then(()=>{let o=new lh;o.init(n,s).then(()=>{let a=Ne(In(t),this.window.location.href);this.packageURL=[a],o.loadPubDoc(a).then(l=>{l?(this.opf=l,this.render(i).then(()=>{r.finish(!0)})):r.finish(!1)})})}),r.result()}loadXML(e){ct.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,s=e.authorStyleSheet,r=e.userStyleSheet;this.viewport=null;let o=B("loadXML");return this.configure(e).then(()=>{let a=new lh;a.init(s,r).then(()=>{let l=t.map((h,u)=>({url:Ne(In(h.url),this.window.location.href),index:u,startPage:h.startPage,skipPagesBefore:h.skipPagesBefore}));this.packageURL=l.map(h=>h.url),this.opf=new Ps(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(()=>(ct.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let s=n[0];if(s==="em"||s==="rem")return t*this.fontSize;let r=Tt[s];if(r)return t*r}return t}configure(e){if(typeof e.autoresize=="boolean"&&(e.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof e.fontSize=="number"){let t=e.fontSize;t>=5&&t<=72&&this.fontSize!=t&&(this.fontSize=t,this.needResize=!0)}if(typeof e.viewport=="object"&&e.viewport){let t=e.viewport,i={marginLeft:this.resolveLength(t["margin-left"])||0,marginRight:this.resolveLength(t["margin-right"])||0,marginTop:this.resolveLength(t["margin-top"])||0,marginBottom:this.resolveLength(t["margin-bottom"])||0,width:this.resolveLength(t.width)||0,height:this.resolveLength(t.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof e.hyphenate=="boolean"&&(this.pref.hyphenate=e.hyphenate,this.needResize=!0),typeof e.horizontal=="boolean"&&(this.pref.horizontal=e.horizontal,this.needResize=!0),typeof e.nightMode=="boolean"&&(this.pref.nightMode=e.nightMode,this.needResize=!0),typeof e.lineHeight=="number"&&(this.pref.lineHeight=e.lineHeight,this.needResize=!0),typeof e.columnWidth=="number"&&(this.pref.columnWidth=e.columnWidth,this.needResize=!0),typeof e.fontFamily=="string"&&(this.pref.fontFamily=e.fontFamily,this.needResize=!0),typeof e.load=="boolean"&&(this.waitForLoading=e.load),typeof e.renderAllPages=="boolean"&&(this.renderAllPages=e.renderAllPages),typeof e.userAgentRootURL=="string"&&(Va(e.userAgentRootURL.replace(/resources\/?$/,"")),Ua(e.userAgentRootURL)),typeof e.rootURL=="string"&&(Va(e.rootURL),Ua(`${Wi}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!==jt&&(Ty(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){At("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=B("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?Qs(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 Xs(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new Xs(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 s=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!s&&t.width==this.viewport.width&&t.height==this.viewport.height||!s&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,s;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((s=this.pageSizes[i-1])==null?void 0:s.height))){let o=function(m){let g=m*.75;return Math.ceil(g)};var r=o;let a=Math.max(...this.pageSizes.map(m=>m.width)),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 r0(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 dh),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return N(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Xr().getScheduler().run(()=>Gi("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,ct.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let s={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.currentPage.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(s.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(s)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():N(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),ct.registerEndTiming("render (resize)"),jt&&Pd(this.window)?Fy(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 dh)ct.registerEndTiming("render (resize)"),H.debug(i.message);else throw i}));return N(!0)}sendLocationNotification(e,t){let i=B("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:e.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(s=>{n.epage=s,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(e){var t;let i;if(this.readyState!=="complete"&&e.where!=="next"&&this.setReadyState("loading"),typeof e.where=="string"){let s;switch(e.where){case"next":s=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":s=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":s=this.opfView.lastPage;break;case"first":s=this.opfView.firstPage;break;default:return N(!0)}s&&(i=()=>s.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let s=e.epage;i=()=>this.opfView.navigateToEPage(s,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let s=e.url;i=()=>this.opfView.navigateTo(s,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let s=e.position;i=()=>this.opfView.findPage(s,!this.renderAllPages)}else return N(!0);if(!this.opfView)return N(!0);let n=B("moveTo");return i.call(this.opfView).then(s=>{let r;if(s){this.pagePosition=s.position;let o=B("moveTo.showCurrent");r=o.result(),this.showCurrent(s.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(o)})}else r=N(!0);r.then(o=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(o)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),s=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!s)return N(!0)}else if(i=="hide")return N(!0);if(n&&i!="show")return this.opfView.hideTOC(),N(!0);{let r=B("showTOC");return this.opfView.showTOC(t).then(o=>{if(o){if(s&&(o.listeners={}),t){let a=()=>{this.opfView.hideTOC()};o.addEventListener("hyperlink",a,!1)}o.addEventListener("hyperlink",this.hyperlinkListener,!1)}r.finish(!0)}),r.result()}}runCommand(e){let t=e.a||"";return Gi("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(H.error("No such action:",t),i.finish(!0))},(i,n)=>{H.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=ph(e),i=null,n=this;zf(()=>{let s=B("commandLoop"),r=Xr().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};r.run(()=>(n.callback(h),N(!0)))}},s.loopWithFrame(o=>{if(n.needResize)n.resize().then(()=>{o.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{o.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{o.continueLoop()})}else{let a=B("waitForCommand");i=a.suspend(this),a.result().then(()=>{o.continueLoop()})}}).thenFinish(s),s.result()}),n.kick=()=>{let s=i;s&&(i=null,s.schedule(!0))},n.sendCommand=s=>t?!1:(t=ph(s),n.kick(),!0),this.window.adapt_command=n.sendCommand}},Bd=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(Bd||{}),dh=class Od extends Error{constructor(){super(),c(this,"name","RenderingCanceledError"),c(this,"message","Page rendering has been canceled"),c(this,"stack"),Object.setPrototypeOf(this,Od.prototype),this.stack=new Error().stack}};function ph(e){return typeof e=="string"?Xo(e):e}var fh=jo;function l0(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function gh(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 _d=class{constructor(e,t){this.settings=e,c(this,"initialized",!1),c(this,"adaptViewer_"),c(this,"options"),c(this,"eventTarget"),c(this,"readyState"),yh(e.debug),this.adaptViewer_=new a0(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=l0(),t&&this.setOptions(t),this.eventTarget=new qo,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},gh(e));this.adaptViewer_.sendCommand(t),Object.assign(this.options,e)}dispatcher(e){let t={type:e.t},i=e;Object.keys(i).forEach(n=>{n!=="t"&&(t[n]=i[n])}),this.eventTarget.dispatchEvent(t)}addListener(e,t){this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){this.eventTarget.removeEventListener(e,t,!1)}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let s=i||{};function r(h){if(h)return h.map(u=>({url:u.url||null,text:u.text||null}))}let o=r(s.authorStyleSheet),a=r(s.userStyleSheet);n&&Object.assign(this.options,n);let l=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:h0(e)||t,document:s.documentObject,fragment:s.fragment,authorStyleSheet:o,userStyleSheet:a},gh(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()===fh.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===fh.LTR?"next":"previous";default:return e}}navigateToPage(e,t){e==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:t}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(e)})}navigateToInternalUrl(e){this.adaptViewer_.sendCommand({a:"moveTo",url:e})}navigateToPosition(e){var t,i;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:e.spineIndex,pageIndex:(t=e.pageIndex)!=null?t:-1,offsetInItem:(i=e.offsetInItem)!=null?i:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(e,t){let i=e==null?"toggle":e?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:i,autohide:t})}queryZoomFactor(e){return this.adaptViewer_.queryZoomFactor(e)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var e,t;return(t=(e=this.adaptViewer_.opfView)==null?void 0:e.tocView)==null?void 0:t.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}};function h0(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 Md=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(Md||{}),u0=Bd,c0=Ld;ct.forceRegisterEndTiming("load_vivliostyle");var d0=class{constructor(e,{title:t="",printCallback:i=o=>o.print(),errorCallback:n=null,hideIframe:s=!0,removeIframe:r=!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=s,this.removeIframe=r}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
|
|
1518
1791
|
<!DOCTYPE html>
|
|
1519
1792
|
<html data-vivliostyle-paginated="true">
|
|
1520
1793
|
<head>
|
|
@@ -1542,6 +1815,6 @@ span[data-viv-leader] {
|
|
|
1542
1815
|
<body onload='parent.printInstance.runInIframe(window)'>
|
|
1543
1816
|
<div id="vivliostyle-viewer-viewport"></div>
|
|
1544
1817
|
</body>
|
|
1545
|
-
</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
|
|
1546
|
-
`);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
|
|
1818
|
+
</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 _d({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",s=>{var r,o;let a=(o=(r=s.content.error)==null?void 0:r.toString())!=null?o:s.content.messages.join(`
|
|
1819
|
+
`);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 p0(e,t){new d0(e,t).init()}});var f0={};Kd(f0,{printHTML:()=>Vd.printHTML});module.exports=Jd(f0);var Vd=Zd(Dd());
|
|
1547
1820
|
//# sourceMappingURL=index.cjs.js.map
|